/[classpath]/classpath/javax/swing/JTextField.java
ViewVC logotype

Diff of /classpath/javax/swing/JTextField.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.22 by langel, Fri Jul 29 14:57:15 2005 UTC revision 1.23 by abalkiss, Fri Sep 23 17:48:30 2005 UTC
# Line 92  public class JTextField extends JTextCom Line 92  public class JTextField extends JTextCom
92    public static final String notifyAction = "notify-field-accept";    public static final String notifyAction = "notify-field-accept";
93        
94    static    static
95    {      {
96      actions = new Action[1];        actions = new Action[1];
97      actions[0] = new TextAction(notifyAction)        actions[0] = new TextAction(notifyAction)
98        {        {
99          public void actionPerformed(ActionEvent event)          public void actionPerformed(ActionEvent event)
100          {          {
101            JTextField textField = (JTextField) event.getSource();            JTextField textField = (JTextField) event.getSource();
102            textField.fireActionPerformed();            textField.fireActionPerformed();
103          }          }
104        };        };
105    }      }
106        
107    private int columns;    private int columns;
108    private int align;    private int align;
# Line 172  public class JTextField extends JTextCom Line 172  public class JTextField extends JTextCom
172    {    {
173      if (columns < 0)      if (columns < 0)
174        throw new IllegalArgumentException();        throw new IllegalArgumentException();
175        
176      this.columns = columns;      this.columns = columns;
177        
178      setDocument(doc == null ? createDefaultModel() : doc);      setDocument(doc == null ? createDefaultModel() : doc);
179    
180      if (text != null)      if (text != null)
# Line 193  public class JTextField extends JTextCom Line 193  public class JTextField extends JTextCom
193    protected Document createDefaultModel()    protected Document createDefaultModel()
194    {    {
195      // subclassed to swallow newlines      // subclassed to swallow newlines
196      return new PlainDocument() {      return new PlainDocument()
197          public void insertString(int offset, String str, AttributeSet a)      {
198          public void insertString(int offset, String str, AttributeSet a)
199            throws BadLocationException            throws BadLocationException
200          {        {
201            if (str != null && str.indexOf('\n') == -1)          if (str != null && str.indexOf('\n') == -1)
202              super.insertString(offset, str, a);            super.insertString(offset, str, a);
203          }        }
204        };      };
205    }    }
206    
207    /**    /**
# Line 268  public class JTextField extends JTextCom Line 269  public class JTextField extends JTextCom
269      return columns;      return columns;
270    }    }
271    
272      /**
273       * Sets the number of columns and then invalidates the layout.
274       * @param columns the number of columns
275       * @throws IllegalArgumentException if columns < 0
276       */
277    public void setColumns(int columns)    public void setColumns(int columns)
278    {    {
279      if (columns < 0)      if (columns < 0)
# Line 275  public class JTextField extends JTextCom Line 281  public class JTextField extends JTextCom
281    
282      this.columns = columns;      this.columns = columns;
283      invalidate();      invalidate();
284        //FIXME: do we need this repaint call?
285      repaint();      repaint();
286    }    }
287    
288      /**
289       * Returns the horizontal alignment, which is one of: JTextField.LEFT,
290       * JTextField.CENTER, JTextField.RIGHT, JTextField.LEADING,
291       * JTextField.TRAILING.
292       * @return the horizontal alignment
293       */
294    public int getHorizontalAlignment()    public int getHorizontalAlignment()
295    {    {
296      return align;      return align;
297    }    }
298    
299      /**
300       * Sets the horizontal alignment of the text.  Calls invalidate and repaint
301       * and fires a property change event.
302       * @param newAlign must be one of: JTextField.LEFT, JTextField.CENTER,
303       * JTextField.RIGHT, JTextField.LEADING, JTextField.TRAILING.
304       * @throws IllegalArgumentException if newAlign is not one of the above.
305       */
306    public void setHorizontalAlignment(int newAlign)    public void setHorizontalAlignment(int newAlign)
307    {    {
308        //FIXME: should throw an IllegalArgumentException if newAlign is invalid
309      if (align == newAlign)      if (align == newAlign)
310        return;        return;
311    
# Line 295  public class JTextField extends JTextCom Line 316  public class JTextField extends JTextCom
316      repaint();      repaint();
317    }    }
318    
319      /**
320       * Sets the current font and revalidates so the font will take effect.
321       */
322    public void setFont(Font newFont)    public void setFont(Font newFont)
323    {    {
324      super.setFont(newFont);      super.setFont(newFont);
325      revalidate();      revalidate();
326    }    }
327    
328      /**
329       * Returns the preferred size.  If there is a non-zero number of columns,
330       * this is the number of columns multiplied by the column width, otherwise
331       * it returns super.getPreferredSize().
332       */
333    public Dimension getPreferredSize()    public Dimension getPreferredSize()
334    {    {
335      Dimension size = super.getPreferredSize();      Dimension size = super.getPreferredSize();
# Line 318  public class JTextField extends JTextCom Line 347  public class JTextField extends JTextCom
347     */     */
348    public int getScrollOffset()    public int getScrollOffset()
349    {    {
350        //FIXME: this should return horizontalVisibility's value
351      return scrollOffset;      return scrollOffset;
352    }    }
353    
# Line 328  public class JTextField extends JTextCom Line 358  public class JTextField extends JTextCom
358     */     */
359    public void setScrollOffset(int offset)    public void setScrollOffset(int offset)
360    {    {
361        //FIXME: this should actualy scroll the field if needed
362      scrollOffset = offset;      scrollOffset = offset;
363    }    }
364    
365      /**
366       * Returns the set of Actions that are commands for the editor.
367       * This is the actions supported by this editor plus the actions
368       * of the UI (returned by JTextComponent.getActions()).
369       */
370    public Action[] getActions()    public Action[] getActions()
371    {    {
372      return TextAction.augmentList(super.getActions(), actions);      return TextAction.augmentList(super.getActions(), actions);
# Line 364  public class JTextField extends JTextCom Line 400  public class JTextField extends JTextCom
400    
401      if (action != null)      if (action != null)
402        {        {
403          removeActionListener(action);          removeActionListener(action);
404          action.removePropertyChangeListener(actionPropertyChangeListener);          action.removePropertyChangeListener(actionPropertyChangeListener);
405          actionPropertyChangeListener = null;          actionPropertyChangeListener = null;
406        }        }
407        
408      Action oldAction = action;      Action oldAction = action;
409      action = newAction;      action = newAction;
410    
411      if (action != null)      if (action != null)
412        {        {
413          addActionListener(action);          addActionListener(action);
414          actionPropertyChangeListener =          actionPropertyChangeListener = createActionPropertyChangeListener(action);
415            createActionPropertyChangeListener(action);          action.addPropertyChangeListener(actionPropertyChangeListener);
         action.addPropertyChangeListener(actionPropertyChangeListener);  
416        }        }
417        
418        //FIXME: is this a hack?  The horizontal alignment hasn't changed
419      firePropertyChange("horizontalAlignment", oldAction, newAction);      firePropertyChange("horizontalAlignment", oldAction, newAction);
420    }    }
421    
422    /**    /**
423       * Sets the command string used in action events.
424     * @since 1.3     * @since 1.3
425     */     */
426    public void setActionCommand(String command)    public void setActionCommand(String command)
# Line 397  public class JTextField extends JTextCom Line 434  public class JTextField extends JTextCom
434    protected PropertyChangeListener createActionPropertyChangeListener(Action action)    protected PropertyChangeListener createActionPropertyChangeListener(Action action)
435    {    {
436      return new PropertyChangeListener()      return new PropertyChangeListener()
437        {
438          public void propertyChange(PropertyChangeEvent event)
439        {        {
440          public void propertyChange(PropertyChangeEvent event)          // Update properties "action" and "horizontalAlignment".
441          {          String name = event.getPropertyName();
442            // Update properties "action" and "horizontalAlignment".  
443            String name = event.getPropertyName();          if (name.equals("enabled"))
444              {
445            if (name.equals("enabled"))              boolean enabled = ((Boolean) event.getNewValue()).booleanValue();
446              {              JTextField.this.setEnabled(enabled);
447                boolean enabled = ((Boolean) event.getNewValue()).booleanValue();            }
448                JTextField.this.setEnabled(enabled);          else if (name.equals(Action.SHORT_DESCRIPTION))
449              }            {
450            else if (name.equals(Action.SHORT_DESCRIPTION))              JTextField.this.setToolTipText((String) event.getNewValue());
451              {            }
452                JTextField.this.setToolTipText((String) event.getNewValue());        }
453              }      };
         }  
       };  
454    }    }
455    
456    /**    /**
457       *
458     * @since 1.3     * @since 1.3
459     */     */
460    protected void configurePropertiesFromAction(Action action)    protected void configurePropertiesFromAction(Action action)
461    {    {
462      if (action != null)      if (action != null)
463        {        {
464          setEnabled(action.isEnabled());          setEnabled(action.isEnabled());
465          setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION));          setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION));
466        }        }
467      else      else
468        {        {
469          setEnabled(true);                setEnabled(true);
470          setToolTipText(null);          setToolTipText(null);
471        }        }
472    }    }
473    
474      /**
475       * Returns the column width, which is the width of the character m
476       * for the font in use.
477       * @return the width of the character m for the font in use.
478       */
479    protected int getColumnWidth()    protected int getColumnWidth()
480    {    {
481      FontMetrics metrics = getToolkit().getFontMetrics(getFont());      FontMetrics metrics = getToolkit().getFontMetrics(getFont());

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26