Index: javax/swing/JTextField.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JTextField.java,v retrieving revision 1.22 diff -u -r1.22 JTextField.java --- javax/swing/JTextField.java 29 Jul 2005 14:57:15 -0000 1.22 +++ javax/swing/JTextField.java 23 Sep 2005 17:46:26 -0000 @@ -92,17 +92,17 @@ public static final String notifyAction = "notify-field-accept"; static - { - actions = new Action[1]; - actions[0] = new TextAction(notifyAction) + { + actions = new Action[1]; + actions[0] = new TextAction(notifyAction) { - public void actionPerformed(ActionEvent event) - { - JTextField textField = (JTextField) event.getSource(); - textField.fireActionPerformed(); - } + public void actionPerformed(ActionEvent event) + { + JTextField textField = (JTextField) event.getSource(); + textField.fireActionPerformed(); + } }; - } + } private int columns; private int align; @@ -172,9 +172,9 @@ { if (columns < 0) throw new IllegalArgumentException(); - + this.columns = columns; - + setDocument(doc == null ? createDefaultModel() : doc); if (text != null) @@ -193,14 +193,15 @@ protected Document createDefaultModel() { // subclassed to swallow newlines - return new PlainDocument() { - public void insertString(int offset, String str, AttributeSet a) + return new PlainDocument() + { + public void insertString(int offset, String str, AttributeSet a) throws BadLocationException - { - if (str != null && str.indexOf('\n') == -1) - super.insertString(offset, str, a); - } - }; + { + if (str != null && str.indexOf('\n') == -1) + super.insertString(offset, str, a); + } + }; } /** @@ -268,6 +269,11 @@ return columns; } + /** + * Sets the number of columns and then invalidates the layout. + * @param columns the number of columns + * @throws IllegalArgumentException if columns < 0 + */ public void setColumns(int columns) { if (columns < 0) @@ -275,16 +281,31 @@ this.columns = columns; invalidate(); + //FIXME: do we need this repaint call? repaint(); } + /** + * Returns the horizontal alignment, which is one of: JTextField.LEFT, + * JTextField.CENTER, JTextField.RIGHT, JTextField.LEADING, + * JTextField.TRAILING. + * @return the horizontal alignment + */ public int getHorizontalAlignment() { return align; } + /** + * Sets the horizontal alignment of the text. Calls invalidate and repaint + * and fires a property change event. + * @param newAlign must be one of: JTextField.LEFT, JTextField.CENTER, + * JTextField.RIGHT, JTextField.LEADING, JTextField.TRAILING. + * @throws IllegalArgumentException if newAlign is not one of the above. + */ public void setHorizontalAlignment(int newAlign) { + //FIXME: should throw an IllegalArgumentException if newAlign is invalid if (align == newAlign) return; @@ -295,12 +316,20 @@ repaint(); } + /** + * Sets the current font and revalidates so the font will take effect. + */ public void setFont(Font newFont) { super.setFont(newFont); revalidate(); } + /** + * Returns the preferred size. If there is a non-zero number of columns, + * this is the number of columns multiplied by the column width, otherwise + * it returns super.getPreferredSize(). + */ public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); @@ -318,6 +347,7 @@ */ public int getScrollOffset() { + //FIXME: this should return horizontalVisibility's value return scrollOffset; } @@ -328,9 +358,15 @@ */ public void setScrollOffset(int offset) { + //FIXME: this should actualy scroll the field if needed scrollOffset = offset; } + /** + * Returns the set of Actions that are commands for the editor. + * This is the actions supported by this editor plus the actions + * of the UI (returned by JTextComponent.getActions()). + */ public Action[] getActions() { return TextAction.augmentList(super.getActions(), actions); @@ -364,26 +400,27 @@ if (action != null) { - removeActionListener(action); - action.removePropertyChangeListener(actionPropertyChangeListener); - actionPropertyChangeListener = null; + removeActionListener(action); + action.removePropertyChangeListener(actionPropertyChangeListener); + actionPropertyChangeListener = null; } - + Action oldAction = action; action = newAction; if (action != null) { - addActionListener(action); - actionPropertyChangeListener = - createActionPropertyChangeListener(action); - action.addPropertyChangeListener(actionPropertyChangeListener); + addActionListener(action); + actionPropertyChangeListener = createActionPropertyChangeListener(action); + action.addPropertyChangeListener(actionPropertyChangeListener); } - + + //FIXME: is this a hack? The horizontal alignment hasn't changed firePropertyChange("horizontalAlignment", oldAction, newAction); } /** + * Sets the command string used in action events. * @since 1.3 */ public void setActionCommand(String command) @@ -397,42 +434,48 @@ protected PropertyChangeListener createActionPropertyChangeListener(Action action) { return new PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent event) { - public void propertyChange(PropertyChangeEvent event) - { - // Update properties "action" and "horizontalAlignment". - String name = event.getPropertyName(); - - if (name.equals("enabled")) - { - boolean enabled = ((Boolean) event.getNewValue()).booleanValue(); - JTextField.this.setEnabled(enabled); - } - else if (name.equals(Action.SHORT_DESCRIPTION)) - { - JTextField.this.setToolTipText((String) event.getNewValue()); - } - } - }; + // Update properties "action" and "horizontalAlignment". + String name = event.getPropertyName(); + + if (name.equals("enabled")) + { + boolean enabled = ((Boolean) event.getNewValue()).booleanValue(); + JTextField.this.setEnabled(enabled); + } + else if (name.equals(Action.SHORT_DESCRIPTION)) + { + JTextField.this.setToolTipText((String) event.getNewValue()); + } + } + }; } /** + * * @since 1.3 */ protected void configurePropertiesFromAction(Action action) { if (action != null) { - setEnabled(action.isEnabled()); - setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); + setEnabled(action.isEnabled()); + setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); } else { - setEnabled(true); - setToolTipText(null); + setEnabled(true); + setToolTipText(null); } } + /** + * Returns the column width, which is the width of the character m + * for the font in use. + * @return the width of the character m for the font in use. + */ protected int getColumnWidth() { FontMetrics metrics = getToolkit().getFontMetrics(getFont()); Index: javax/swing/text/Utilities.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/Utilities.java,v retrieving revision 1.11 diff -u -r1.11 Utilities.java --- javax/swing/text/Utilities.java 22 Sep 2005 20:17:08 -0000 1.11 +++ javax/swing/text/Utilities.java 23 Sep 2005 17:46:26 -0000 @@ -394,4 +394,9 @@ wb.setText(text); return wb.following(offs); } + + public static final int getRowEnd (JTextComponent c, int offs) throws BadLocationException + { + return 0; + } }