This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: JPasswordField


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I just commited the attached patch to start implemented 
javax.swing.JPasswordField. It doesnt work yet as it e.g. paints 
wrongly but its a start.


Michael


2004-09-10  Michael Koch  <konqueror@gmx.de>

	* javax/swing/JPasswordField.java:
	Reformated. Implemented construtors.
	* javax/swing/plaf/basic/BasicPasswordFieldUI.java
	(create): New method.
	* javax/swing/text/PlainView.java
	(selectedColor): Made package-private to allow access from 
sub-classes
	in same package too.
	(unselectedColor): Likewise.
	(font): Likewise.
	(drawSelectedText): Make protected.
	(drawUnselectedText): Likewise.
	* javax/swing/text/PasswordView.java: New file.
	* Makefile.am: Added javax/swing/text/PasswordView.java.
	* Makefile.in: Regenerated.


- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBQgXqWSOgCCdjSDsRAut+AJ9YqwOoaOsx50zQY6r5Fbrxw+16BQCfeMAj
jFvWyvqJD3uYco/84YuiA/0=
=MqNM
-----END PGP SIGNATURE-----
Index: javax/swing/JPasswordField.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JPasswordField.java,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 JPasswordField.java
--- javax/swing/JPasswordField.java	8 Jun 2004 09:28:42 -0000	1.4.2.1
+++ javax/swing/JPasswordField.java	10 Sep 2004 19:42:43 -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: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicPasswordFieldUI.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 BasicPasswordFieldUI.java
--- javax/swing/plaf/basic/BasicPasswordFieldUI.java	11 Aug 2004 13:31:15 -0000	1.1.2.1
+++ javax/swing/plaf/basic/BasicPasswordFieldUI.java	10 Sep 2004 19:42:43 -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	10 Sep 2004 19:42:43 -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: /cvs/gcc/gcc/libjava/javax/swing/text/PlainView.java,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 PlainView.java
--- javax/swing/text/PlainView.java	30 Aug 2004 12:09:31 -0000	1.1.2.5
+++ javax/swing/text/PlainView.java	10 Sep 2004 19:42:43 -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);
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.361.2.43
diff -u -r1.361.2.43 Makefile.am
--- Makefile.am	2 Sep 2004 21:26:16 -0000	1.361.2.43
+++ Makefile.am	10 Sep 2004 19:42:44 -0000
@@ -1540,6 +1540,7 @@
 javax/swing/text/JTextComponent.java \
 javax/swing/text/Keymap.java \
 javax/swing/text/LayeredHighlighter.java \
+javax/swing/text/PasswordView.java \
 javax/swing/text/PlainDocument.java \
 javax/swing/text/PlainView.java \
 javax/swing/text/Position.java \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.385.2.43
diff -u -r1.385.2.43 Makefile.in
--- Makefile.in	2 Sep 2004 21:26:16 -0000	1.385.2.43
+++ Makefile.in	10 Sep 2004 19:42:46 -0000
@@ -1218,6 +1218,7 @@
 javax/swing/text/JTextComponent.java \
 javax/swing/text/Keymap.java \
 javax/swing/text/LayeredHighlighter.java \
+javax/swing/text/PasswordView.java \
 javax/swing/text/PlainDocument.java \
 javax/swing/text/PlainView.java \
 javax/swing/text/Position.java \
@@ -3314,7 +3315,7 @@
 javax/swing/text/Element.lo javax/swing/text/FieldView.lo \
 javax/swing/text/GapContent.lo javax/swing/text/Highlighter.lo \
 javax/swing/text/JTextComponent.lo javax/swing/text/Keymap.lo \
-javax/swing/text/LayeredHighlighter.lo \
+javax/swing/text/LayeredHighlighter.lo javax/swing/text/PasswordView.lo \
 javax/swing/text/PlainDocument.lo javax/swing/text/PlainView.lo \
 javax/swing/text/Position.lo javax/swing/text/Segment.lo \
 javax/swing/text/SimpleAttributeSet.lo javax/swing/text/Style.lo \
@@ -5429,6 +5430,7 @@
 .deps/javax/swing/text/LayeredHighlighter.P \
 .deps/javax/swing/text/MutableAttributeSet.P \
 .deps/javax/swing/text/NavigationFilter.P \
+.deps/javax/swing/text/PasswordView.P \
 .deps/javax/swing/text/PlainDocument.P \
 .deps/javax/swing/text/PlainView.P .deps/javax/swing/text/Position.P \
 .deps/javax/swing/text/Segment.P \

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]