This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[GUI] Patch: javax.swing - fixes overall
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Fri, 18 Jun 2004 12:28:42 +0200
- Subject: [GUI] Patch: javax.swing - fixes overall
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to fix little issues all over
swing.
Michael
2004-06-18 Michael Koch <konqueror@gmx.de>
* javax/swing/JButton.java: Reformatted.
* javax/swing/JFormattedTextField.java
(getUIClassID): Implemented.
* javax/swing/JRootPane.java
(serialVersionUID): New constant.
* javax/swing/JTextField.java
(align): New field.
(JTextField): Simplified.
(getUIClassID): New method.
(getActionListeners): Added @since tag.
(setColumns): Invalidate layout and repaint.
(getHorizontalAlignment): New method.
(setHorizontalAlignment): New method.
(selectAll): Removed.
* javax/swing/SwingUtilities.java
(getAncestorOfClass): Removed redundant @see tag.
(isLeftMouseButton): Fixed implementation.
(isMiddleMouseButton): Likewise.
(isRightMouseButton): Likewise.
* javax/swing/text/AbstractDocument.java
(AttributeContext.addAttribute): New method.
(AttributeContext.addAttributes): New method.
(AttributeContext.getEmptySet): New method.
(AttributeContext.reclaim): New method.
(AttributeContext.removeAttribute): New method.
(AttributeContext.removeAttributes): New method.
* javax/swing/text/Document.java
(createPosition): Throws BadLocationException.
(getText): Likewise.
(remove): Likewise.
* javax/swing/text/JTextComponent.java
(getText): Return null if no document is set. Catch
BadLocationException.
(getUI): Return ui.
(updateUI): Simplified.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA0sPeWSOgCCdjSDsRAoyaAJwPf64IdQ6pUWACMF/za2op6icehwCfTs7E
IaKGA27La2/Lwm51Rwt3NDk=
=gzkW
-----END PGP SIGNATURE-----
Index: javax/swing/JButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JButton.java,v
retrieving revision 1.4.2.1
diff -u -b -B -r1.4.2.1 JButton.java
--- javax/swing/JButton.java 9 Jun 2004 20:55:10 -0000 1.4.2.1
+++ javax/swing/JButton.java 18 Jun 2004 10:22:17 -0000
@@ -46,12 +47,12 @@
*
* @author Ronald Veldema (rveldema@cs.vu.nl)
*/
-public class JButton extends AbstractButton implements Accessible
+public class JButton extends AbstractButton
+ implements Accessible
{
private static final long serialVersionUID = -1907255238954382202L;
-
- boolean def, is_def;
-
+ boolean def;
+ boolean is_def;
public JButton()
{
@@ -125,11 +126,13 @@
}
public void setDefaultCapable(boolean defaultCapable)
- { def = defaultCapable; }
+ {
+ def = defaultCapable;
+ }
public void updateUI()
{
- ButtonUI b = (ButtonUI)UIManager.getUI(this);
+ ButtonUI b = (ButtonUI) UIManager.getUI(this);
setUI(b);
}
}
Index: javax/swing/JFormattedTextField.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JFormattedTextField.java,v
retrieving revision 1.3.2.1
diff -u -b -B -r1.3.2.1 JFormattedTextField.java
--- javax/swing/JFormattedTextField.java 7 Jun 2004 12:41:08 -0000 1.3.2.1
+++ javax/swing/JFormattedTextField.java 18 Jun 2004 10:22:17 -0000
@@ -189,7 +189,7 @@
public String getUIClassID ()
{
- throw new InternalError ("not implemented");
+ return "FormattedTextFieldUI";
}
public Object getValue ()
Index: javax/swing/JRootPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JRootPane.java,v
retrieving revision 1.4.2.5
diff -u -b -B -r1.4.2.5 JRootPane.java
--- javax/swing/JRootPane.java 11 Jun 2004 07:12:55 -0000 1.4.2.5
+++ javax/swing/JRootPane.java 18 Jun 2004 10:22:18 -0000
@@ -223,6 +223,8 @@
}
}
+ private static final long serialVersionUID = 8690748000348575668L;
+
protected Component glassPane;
protected JLayeredPane layeredPane;
protected JMenuBar menuBar;
Index: javax/swing/JTextField.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTextField.java,v
retrieving revision 1.2.18.4
diff -u -b -B -r1.2.18.4 JTextField.java
--- javax/swing/JTextField.java 16 Jun 2004 08:20:15 -0000 1.2.18.4
+++ javax/swing/JTextField.java 18 Jun 2004 10:22:18 -0000
@@ -79,6 +79,8 @@
private int columns;
+ private int align;
+
/**
* Creates a new instance of <code>JTextField</code>.
*/
@@ -133,10 +135,7 @@
*/
public JTextField(Document doc, String text, int columns)
{
- if (doc == null)
- doc = createDefaultModel();
-
- setDocument(doc);
+ setDocument(doc == null ? createDefaultModel() : doc);
setText(text);
setColumns(columns);
}
@@ -153,6 +152,16 @@
}
/**
+ * Returns the class ID for the UI.
+ *
+ * @return "TextFieldUI";
+ */
+ public String getUIClassID()
+ {
+ return "TextFieldUI";
+ }
+
+ /**
* Adds a new listener object to this text field.
*
* @param listener the listener to add
@@ -176,6 +185,8 @@
* Returns all registered <code>ActionListener</code> objects.
*
* @return an array of listeners
+ *
+ * @since 1.4
*/
public ActionListener[] getActionListeners()
{
@@ -211,10 +222,21 @@
throw new IllegalArgumentException();
this.columns = columns;
- // FIXME: Invalidate layout.
+ invalidate();
+ repaint();
+ }
+
+ public int getHorizontalAlignment()
+ {
+ return align;
}
- public void selectAll()
+ public void setHorizontalAlignment(int newAlign)
{
+ int oldAlign = align;
+ align = newAlign;
+ invalidate();
+ repaint();
+ firePropertyChange("horizontalAlignment", oldAlign, newAlign);
}
}
Index: javax/swing/SwingUtilities.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/SwingUtilities.java,v
retrieving revision 1.6.2.7
diff -u -b -B -r1.6.2.7 SwingUtilities.java
--- javax/swing/SwingUtilities.java 11 Jun 2004 06:57:24 -0000 1.6.2.7
+++ javax/swing/SwingUtilities.java 18 Jun 2004 10:22:18 -0000
@@ -197,8 +197,6 @@
*
* @see #getAncestorOfClass
* @see #windowForComponent
- * @see
- *
*/
public static Container getAncestorOfClass(Class c, Component comp)
{
@@ -859,8 +857,8 @@
*/
public static boolean isLeftMouseButton(MouseEvent event)
{
- return ((event.getModifiers() & InputEvent.BUTTON1_DOWN_MASK)
- == InputEvent.BUTTON1_DOWN_MASK);
+ return ((event.getModifiers() & InputEvent.BUTTON1_MASK)
+ == InputEvent.BUTTON1_MASK);
}
/**
@@ -872,8 +870,8 @@
*/
public static boolean isMiddleMouseButton(MouseEvent event)
{
- return ((event.getModifiers() & InputEvent.BUTTON2_DOWN_MASK)
- == InputEvent.BUTTON2_DOWN_MASK);
+ return ((event.getModifiers() & InputEvent.BUTTON2_MASK)
+ == InputEvent.BUTTON2_MASK);
}
/**
@@ -885,7 +883,7 @@
*/
public static boolean isRightMouseButton(MouseEvent event)
{
- return ((event.getModifiers() & InputEvent.BUTTON3_DOWN_MASK)
- == InputEvent.BUTTON3_DOWN_MASK);
+ return ((event.getModifiers() & InputEvent.BUTTON3_MASK)
+ == InputEvent.BUTTON3_MASK);
}
}
Index: javax/swing/text/AbstractDocument.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/AbstractDocument.java,v
retrieving revision 1.3.8.5
diff -u -b -B -r1.3.8.5 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java 16 Jun 2004 11:41:57 -0000 1.3.8.5
+++ javax/swing/text/AbstractDocument.java 18 Jun 2004 10:22:18 -0000
@@ -145,6 +145,13 @@
public interface AttributeContext
{
+ AttributeSet addAttribute(AttributeSet old, Object name, Object value);
+ AttributeSet addAttributes(AttributeSet old, AttributeSet attributes);
+ AttributeSet getEmptySet();
+ void reclaim(AttributeSet attributes);
+ AttributeSet removeAttribute(AttributeSet old, Object name);
+ AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes);
+ AttributeSet removeAttributes(AttributeSet old, Enumeration names);
}
public class BranchElement extends AbstractElement
Index: javax/swing/text/Document.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/Document.java,v
retrieving revision 1.4.8.2
diff -u -b -B -r1.4.8.2 Document.java
--- javax/swing/text/Document.java 16 Jun 2004 10:22:27 -0000 1.4.8.2
+++ javax/swing/text/Document.java 18 Jun 2004 10:22:18 -0000
@@ -50,7 +50,8 @@
void addUndoableEditListener(UndoableEditListener listener);
- Position createPosition(int offs);
+ Position createPosition(int offs)
+ throws BadLocationException;
Element getDefaultRootElement();
@@ -64,16 +65,19 @@
Position getStartPosition();
- String getText(int offset, int length);
+ String getText(int offset, int length)
+ throws BadLocationException;
- void getText(int offset, int length, Segment txt);
+ void getText(int offset, int length, Segment txt)
+ throws BadLocationException;
void insertString(int offset, String str, AttributeSet a)
throws BadLocationException;
void putProperty(Object key, Object value);
- void remove(int offs, int len);
+ void remove(int offs, int len)
+ throws BadLocationException;
void removeDocumentListener(DocumentListener listener);
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/JTextComponent.java,v
retrieving revision 1.4.2.7
diff -u -b -B -r1.4.2.7 JTextComponent.java
--- javax/swing/text/JTextComponent.java 16 Jun 2004 11:11:32 -0000 1.4.2.7
+++ javax/swing/text/JTextComponent.java 18 Jun 2004 10:22:18 -0000
@@ -351,7 +351,18 @@
*/
public String getText()
{
- return getDocument().getText(0, getDocument().getLength());
+ if (doc == null)
+ return null;
+
+ try
+ {
+ return doc.getText(0, doc.getLength());
+ }
+ catch (BadLocationException e)
+ {
+ // This should never happen.
+ return "";
+ }
}
/**
@@ -391,12 +402,14 @@
public TextUI getUI()
{
- return (TextUI) UIManager.getUI(this);
+ return (TextUI) ui;
}
public void updateUI()
{
- setUI(getUI());
+ setUI((TextUI) UIManager.getUI(this));
+ invalidate();
+ repaint();
}
public Dimension getPreferredScrollableViewportSize()