Index: javax/swing/JPasswordField.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JPasswordField.java,v retrieving revision 1.5 diff -u -r1.5 JPasswordField.java --- javax/swing/JPasswordField.java 26 Jun 2004 16:07:01 -0000 1.5 +++ javax/swing/JPasswordField.java 26 Sep 2004 13:15:25 -0000 @@ -44,6 +44,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; + /** * JPasswordField * @author Andrew Selkirk @@ -75,160 +76,160 @@ } } - /** - * uiClassID - */ - private static final String uiClassID = "PasswordFieldUI"; - - /** - * echoChar. Default is 0 - */ - private char echoChar = 0; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor JPasswordField - */ - public JPasswordField() { - // TODO - } // JPasswordField() - - /** - * Constructor JPasswordField - * @param text TODO - */ - public JPasswordField(String text) { - // TODO - } // JPasswordField() - - /** - * Constructor JPasswordField - * @param columns TODO - */ - public JPasswordField(int columns) { - // TODO - } // JPasswordField() - - /** - * Constructor JPasswordField - * @param text TODO - * @param columns TODO - */ - public JPasswordField(String text, int columns) { - // TODO - } // JPasswordField() - - /** - * Constructor JPasswordField - * @param document TODO - * @param text TODO - * @param columns TODO - */ - public JPasswordField(Document document, String text, int columns) { - // TODO - } // JPasswordField() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * writeObject - * @param stream TODO - * @exception IOException TODO - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - // TODO - } // writeObject() - - /** - * copy - */ - public void copy() { - // TODO - } // copy() - - /** - * getUIClassID - * @returns String - */ - public String getUIClassID() { - return uiClassID; - } // getUIClassID() - - /** - * getEchoChar - * @returns char - */ - public char getEchoChar() { - return echoChar; - } // getEchoChar() - - /** - * setEchoChar - * @param echo TODO - */ - public void setEchoChar(char echo) { - this.echoChar = echo; - // TODO - } // setEchoChar() - - /** - * echoCharIsSet - * @returns boolean - */ - public boolean echoCharIsSet() { - return (echoChar == 0); - } // echoCharIsSet() - - /** - * cut - */ - public void cut() { - // TODO - } // cut() - - /** - * getText - * @returns String - * @deprecated - */ - public String getText() { - return null; // TODO - } // getText() - - /** - * getText - * @param offset TODO - * @param length TODO - * @exception BadLocationException TODO - * @returns String - * @deprecated - */ - public String getText(int offset, int length) throws BadLocationException { - return null; // TODO - } // getText() - - /** - * getPassword - * @returns char[] - */ - public char[] getPassword() { - return null; // TODO - } // getPassword() - - /** - * paramString - * @returns String - */ - protected String paramString() { - return null; // TODO - } // paramString() + /** + * echoChar. Default is 0. + */ + private char echoChar = 0; + + /** + * Constructor JPasswordField + */ + public JPasswordField() + { + this(null, null, 0); + } + + /** + * Constructor JPasswordField + * @param text TODO + */ + public JPasswordField(String text) + { + this(null, text, 0); + } + + /** + * Constructor JPasswordField + * @param columns TODO + */ + public JPasswordField(int columns) + { + this(null, null, columns); + } + + /** + * Constructor JPasswordField + * @param text TODO + * @param columns TODO + */ + public JPasswordField(String text, int columns) + { + this(null, text, columns); + } + + /** + * Constructor JPasswordField + * @param document TODO + * @param text TODO + * @param columns TODO + */ + public JPasswordField(Document document, String text, int columns) + { + super(document, text, columns); + } + + /** + * writeObject + * @param stream TODO + * @exception IOException TODO + */ + private void writeObject(ObjectOutputStream stream) throws IOException + { + // TODO + } + + /** + * getUIClassID + * @return String + */ + public String getUIClassID() + { + return "PasswordFieldUI"; + } + + /** + * getEchoChar + * @return char + */ + public char getEchoChar() + { + return echoChar; + } + + /** + * setEchoChar + * @param echo TODO + */ + public void setEchoChar(char echo) + { + this.echoChar = echo; + } + + /** + * echoCharIsSet + * @return boolean + */ + public boolean echoCharIsSet() + { + return echoChar == 0; + } + + /** + * copy + */ + public void copy() + { + UIManager.getLookAndFeel().provideErrorFeedback(this); + } + + /** + * cut + */ + public void cut() + { + UIManager.getLookAndFeel().provideErrorFeedback(this); + } + + /** + * getText + * @return String + * @deprecated + */ + public String getText() + { + return null; // TODO + } + + /** + * getText + * @param offset TODO + * @param length TODO + * @return String + * @exception BadLocationException TODO + * @deprecated + */ + public String getText(int offset, int length) throws BadLocationException + { + return null; // TODO + } + + /** + * getPassword + * @return char[] + */ + public char[] getPassword() + { + return null; // TODO + } + + /** + * paramString + * @return String + */ + protected String paramString() + { + return null; // TODO + } /** * getAccessibleContext Index: javax/swing/plaf/basic/BasicPasswordFieldUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicPasswordFieldUI.java,v retrieving revision 1.1 diff -u -r1.1 BasicPasswordFieldUI.java --- javax/swing/plaf/basic/BasicPasswordFieldUI.java 4 Sep 2004 17:14:01 -0000 1.1 +++ javax/swing/plaf/basic/BasicPasswordFieldUI.java 26 Sep 2004 13:15:25 -0000 @@ -41,6 +41,7 @@ import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.text.Element; +import javax.swing.text.PasswordView; import javax.swing.text.View; public class BasicPasswordFieldUI extends BasicTextFieldUI @@ -49,6 +50,11 @@ { } + public View create(Element elem) + { + return new PasswordView(elem); + } + public static ComponentUI createUI(JComponent c) { return new BasicPasswordFieldUI(); Index: javax/swing/text/PasswordView.java =================================================================== RCS file: javax/swing/text/PasswordView.java diff -N javax/swing/text/PasswordView.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ javax/swing/text/PasswordView.java 26 Sep 2004 13:15:25 -0000 @@ -0,0 +1,136 @@ +/* PasswordView.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.text; + +import java.awt.Color; +import java.awt.Graphics; +import javax.swing.JPasswordField; + +public class PasswordView extends FieldView +{ + /** + * Buffer for putting the echo char into it and + * then using it to draw it into the view. + */ + private char[] oneCharBuffer = new char[1]; + + public PasswordView(Element elem) + { + super(elem); + } + + protected int drawEchoCharacter(Graphics g, int x, int y, char ch) + { + // Update font metrics. + updateMetrics(); + + // Draw character. + oneCharBuffer[0] = ch; + g.drawChars(oneCharBuffer, 0, 1, x, y); + + // Return new x position right of drawn character. + return x + metrics.charWidth(ch); + } + + private char getEchoChar() + { + char ch = ((JPasswordField) getContainer()).getEchoChar(); + + if (ch == 0) + ch = '*'; + + return ch; + } + + protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1) + throws BadLocationException + { + // FIXME: Throw BadLocationException somehow. + + // Update font metrics. + updateMetrics(); + + // Get echo character. + char ch = getEchoChar(); + + // Set color for selected text. + g.setColor(selectedColor); + g.setColor(Color.BLACK); + + // Initialize buffer for faster drawing of all characters. + int len = p1 - p0; + char[] buffer = new char[len]; + for (int index = 0; index < len; ++index) + buffer[index] = ch; + + // Draw echo charaters. + g.drawChars(buffer, 0, len, x, y); + + // Return new x position right of all drawn characters. + return x + len * metrics.charWidth(ch); + } + + protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) + throws BadLocationException + { + // FIXME: Throw BadLocationException somehow. + + // Update font metrics. + updateMetrics(); + + // Get echo character. + char ch = getEchoChar(); + + // Set color for unselected text. + g.setColor(unselectedColor); + g.setColor(Color.BLACK); + + // Initialize buffer for faster drawing of all characters. + int len = p1 - p0; + char[] buffer = new char[len]; + for (int index = 0; index < len; ++index) + buffer[index] = ch; + + // Draw echo charaters. + g.drawChars(buffer, 0, len, x, y); + + // Return new x position right of all drawn characters. + return x + len * metrics.charWidth(ch); + } +} + Index: javax/swing/text/PlainView.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v retrieving revision 1.2 diff -u -r1.2 PlainView.java --- javax/swing/text/PlainView.java 4 Sep 2004 17:14:01 -0000 1.2 +++ javax/swing/text/PlainView.java 26 Sep 2004 13:15:25 -0000 @@ -50,9 +50,9 @@ public class PlainView extends View implements TabExpander { - private Color selectedColor; - private Color unselectedColor; - private Font font; + Color selectedColor; + Color unselectedColor; + Font font; protected FontMetrics metrics; @@ -130,7 +130,7 @@ } } - public int drawSelectedText(Graphics g, int x, int y, int p0, int p1) + protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException { g.setColor(selectedColor); @@ -139,7 +139,7 @@ return Utilities.drawTabbedText(segment, x, y, g, this, 0); } - public int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) + protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException { g.setColor(unselectedColor);