< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextFieldUI.java

Print this page




  29 import java.awt.event.FocusEvent;
  30 import java.awt.event.InputEvent;
  31 import java.beans.PropertyChangeEvent;
  32 import java.io.Reader;
  33 import javax.swing.*;
  34 import javax.swing.border.*;
  35 import javax.swing.event.*;
  36 import javax.swing.text.*;
  37 import javax.swing.plaf.*;
  38 import sun.swing.DefaultLookup;
  39 
  40 /**
  41  * Basis of a look and feel for a JTextField.
  42  * <p>
  43  * <strong>Warning:</strong>
  44  * Serialized objects of this class will not be compatible with
  45  * future Swing releases. The current serialization support is
  46  * appropriate for short term storage or RMI between applications running
  47  * the same version of Swing.  As of 1.4, support for long term storage
  48  * of all JavaBeans&trade;
  49  * has been added to the <code>java.beans</code> package.
  50  * Please see {@link java.beans.XMLEncoder}.
  51  *
  52  * @author  Timothy Prinzing
  53  */
  54 @SuppressWarnings("serial") // Same-version serialization only
  55 public class BasicTextFieldUI extends BasicTextUI {
  56 
  57     /**
  58      * Creates a UI for a JTextField.
  59      *
  60      * @param c the text field
  61      * @return the UI
  62      */
  63     public static ComponentUI createUI(JComponent c) {
  64         return new BasicTextFieldUI();
  65     }
  66 
  67     /**
  68      * Creates a new BasicTextFieldUI.
  69      */


 166             JComponent c) {
 167         super.getBaselineResizeBehavior(c);
 168         return Component.BaselineResizeBehavior.CENTER_OFFSET;
 169     }
 170 
 171 
 172     /**
 173      * A field view that support bidirectional text via the
 174      * support provided by ParagraphView.
 175      */
 176     static class I18nFieldView extends ParagraphView {
 177 
 178         I18nFieldView(Element elem) {
 179             super(elem);
 180         }
 181 
 182         /**
 183          * Fetch the constraining span to flow against for
 184          * the given child index.  There is no limit for
 185          * a field since it scrolls, so this is implemented to
 186          * return <code>Integer.MAX_VALUE</code>.
 187          */
 188         public int getFlowSpan(int index) {
 189             return Integer.MAX_VALUE;
 190         }
 191 
 192         protected void setJustification(int j) {
 193             // Justification is done in adjustAllocation(), so disable
 194             // ParagraphView's justification handling by doing nothing here.
 195         }
 196 
 197         static boolean isLeftToRight( java.awt.Component c ) {
 198             return c.getComponentOrientation().isLeftToRight();
 199         }
 200 
 201         /**
 202          * Adjusts the allocation given to the view
 203          * to be a suitable allocation for a text field.
 204          * If the view has been allocated more than the
 205          * preferred span vertically, the allocation is
 206          * changed to be centered vertically.  Horizontally




  29 import java.awt.event.FocusEvent;
  30 import java.awt.event.InputEvent;
  31 import java.beans.PropertyChangeEvent;
  32 import java.io.Reader;
  33 import javax.swing.*;
  34 import javax.swing.border.*;
  35 import javax.swing.event.*;
  36 import javax.swing.text.*;
  37 import javax.swing.plaf.*;
  38 import sun.swing.DefaultLookup;
  39 
  40 /**
  41  * Basis of a look and feel for a JTextField.
  42  * <p>
  43  * <strong>Warning:</strong>
  44  * Serialized objects of this class will not be compatible with
  45  * future Swing releases. The current serialization support is
  46  * appropriate for short term storage or RMI between applications running
  47  * the same version of Swing.  As of 1.4, support for long term storage
  48  * of all JavaBeans&trade;
  49  * has been added to the {@code java.beans} package.
  50  * Please see {@link java.beans.XMLEncoder}.
  51  *
  52  * @author  Timothy Prinzing
  53  */
  54 @SuppressWarnings("serial") // Same-version serialization only
  55 public class BasicTextFieldUI extends BasicTextUI {
  56 
  57     /**
  58      * Creates a UI for a JTextField.
  59      *
  60      * @param c the text field
  61      * @return the UI
  62      */
  63     public static ComponentUI createUI(JComponent c) {
  64         return new BasicTextFieldUI();
  65     }
  66 
  67     /**
  68      * Creates a new BasicTextFieldUI.
  69      */


 166             JComponent c) {
 167         super.getBaselineResizeBehavior(c);
 168         return Component.BaselineResizeBehavior.CENTER_OFFSET;
 169     }
 170 
 171 
 172     /**
 173      * A field view that support bidirectional text via the
 174      * support provided by ParagraphView.
 175      */
 176     static class I18nFieldView extends ParagraphView {
 177 
 178         I18nFieldView(Element elem) {
 179             super(elem);
 180         }
 181 
 182         /**
 183          * Fetch the constraining span to flow against for
 184          * the given child index.  There is no limit for
 185          * a field since it scrolls, so this is implemented to
 186          * return {@code Integer.MAX_VALUE}.
 187          */
 188         public int getFlowSpan(int index) {
 189             return Integer.MAX_VALUE;
 190         }
 191 
 192         protected void setJustification(int j) {
 193             // Justification is done in adjustAllocation(), so disable
 194             // ParagraphView's justification handling by doing nothing here.
 195         }
 196 
 197         static boolean isLeftToRight( java.awt.Component c ) {
 198             return c.getComponentOrientation().isLeftToRight();
 199         }
 200 
 201         /**
 202          * Adjusts the allocation given to the view
 203          * to be a suitable allocation for a text field.
 204          * If the view has been allocated more than the
 205          * preferred span vertically, the allocation is
 206          * changed to be centered vertically.  Horizontally


< prev index next >