This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui] Patch: javax.swing - big cleanup
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Tue, 29 Jun 2004 12:03:50 +0200
- Subject: [gui] Patch: javax.swing - big cleanup
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to cleanup Swing a little bit more.
Michael
2004-06-29 Michael Koch <konqueror@gmx.de>
* javax/swing/ImageIcon.java
(file): Removed.
(description): Renamed from descr.
(ImageIcon): Added missing constructors.
(setParent): Removed.
(setImageObserver): New method.
(getImageObserver): New method.
(paintIcon): Handle observer = null.
* javax/swing/JButton.java
(removeNotify): Fixed javadoc.
(updateUI): Simplified.
* javax/swing/JRootPane.java
(serialVersionUID): New constant field.
* javax/swing/UIManager.java:
Fixed javadocs all over.
(setLookAndFeel): Throws UnsupportedLookAndFeelException.
* javax/swing/text/AbstractDocument.java
(createPosition): Throws BadLocationException.
(getText): Likewise.
(remove): Likewise.
* javax/swing/text/ComponentView.java
(modelToView): Likewise.
* javax/swing/text/DefaultEditorKit.java:
Made all public methods public.
(read): Throws BadLocationException and IOException.
(write): Likewise.
* javax/swing/text/EditorKit.java:
Made all public methods public.
(serialVersionUID): New constant field.
(clone): New method.
(read): Throws BadLocationException and IOException.
(write): Likewise.
* javax/swing/text/Segment.java
(array): Made public.
(count): Likewise.
(offset): Likewise.
(Segment): New constructors.
(clone): Reimplemented.
* javax/swing/text/StyledEditorKit.java
(serialVersionUID): New constant field.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA4T6JWSOgCCdjSDsRAvjuAJsHYf/vZvE6QEP+el9Ga8AOxwkgSwCfeC8e
YktfuMsUpWw4myLG+UfvZ6M=
=5PQj
-----END PGP SIGNATURE-----
Index: javax/swing/ImageIcon.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/ImageIcon.java,v
retrieving revision 1.2.18.7
diff -u -b -B -r1.2.18.7 ImageIcon.java
--- javax/swing/ImageIcon.java 29 Jun 2004 05:24:26 -0000 1.2.18.7
+++ javax/swing/ImageIcon.java 29 Jun 2004 09:56:55 -0000
@@ -41,6 +41,7 @@
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
+import java.awt.image.ImageObserver;
import java.io.Serializable;
import java.net.URL;
@@ -50,43 +51,62 @@
{
private static final long serialVersionUID = 532615968316031794L;
Image image;
- String file;
- String descr;
- Component observer;
+ String description;
+ ImageObserver observer;
- public ImageIcon(String s)
+ public ImageIcon()
{
- // if description is not specified, then file name becomes
- // desciption for this icon
- this(s, s);
}
- public ImageIcon(Image im)
+ public ImageIcon(String file)
{
- image = Toolkit.getDefaultToolkit().createImage(im.getSource());
+ this(file, file);
+ }
+
+ public ImageIcon(String file, String description)
+ {
+ this(Toolkit.getDefaultToolkit().getImage(file), description);
+ }
+
+ public ImageIcon(byte[] imageData)
+ {
+ this(imageData, null);
+ }
+
+ public ImageIcon(byte[] imageData, String description)
+ {
+ this(Toolkit.getDefaultToolkit().createImage(imageData), description);
}
public ImageIcon(URL url)
{
- image = Toolkit.getDefaultToolkit().getImage(url);
+ this(url, null);
+ }
+
+ public ImageIcon(URL url, String description)
+ {
+ this(Toolkit.getDefaultToolkit().getImage(url), description);
}
- public ImageIcon(String file, String descr)
+ public ImageIcon(Image image)
{
- this.file = file;
- this.descr = descr;
+ this(image, null);
+ }
- image = Toolkit.getDefaultToolkit().getImage(file);
- if (image == null)
- return;
+ public ImageIcon(Image image, String description)
+ {
+ this.image = Toolkit.getDefaultToolkit().createImage(image.getSource());
+ this.description = description;
+ }
- //loadImage(image);
+ public ImageObserver getImageObserver()
+ {
+ return observer;
}
- // not in SUN's spec !!!
- public void setParent(Component p)
+ public void setImageObserver(ImageObserver newObserver)
{
- observer = p;
+ observer = newObserver;
}
public Image getImage()
@@ -96,12 +116,12 @@
public String getDescription()
{
- return descr;
+ return description;
}
public void setDescription(String description)
{
- this.descr = description;
+ this.description = description;
}
public int getIconHeight()
@@ -116,6 +136,6 @@
public void paintIcon(Component c, Graphics g, int x, int y)
{
- g.drawImage(image, x, y, observer);
+ g.drawImage(image, x, y, observer != null ? observer : c);
}
}
Index: javax/swing/JButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JButton.java,v
retrieving revision 1.4.2.5
diff -u -b -B -r1.4.2.5 JButton.java
--- javax/swing/JButton.java 29 Jun 2004 09:10:35 -0000 1.4.2.5
+++ javax/swing/JButton.java 29 Jun 2004 09:56:55 -0000
@@ -120,9 +120,14 @@
return "JButton";
}
+ /**
+ * Overrides JComponent.removeNotify to check if this button is currently
+ * set as the default button on the RootPane, and if so, sets the RootPane's
+ * default button to null to ensure the RootPane doesn't hold onto an invalid
+ * button reference.
+ */
public void removeNotify()
{
- //Overrides JComponent.removeNotify to check if this button is currently set as the default button on the RootPane, and if so, sets the RootPane's default button to null to ensure the RootPane doesn't hold onto an invalid button reference.
}
public void setDefaultCapable(boolean defaultCapable)
@@ -132,7 +137,6 @@
public void updateUI()
{
- ButtonUI b = (ButtonUI) UIManager.getUI(this);
- setUI(b);
+ setUI((ButtonUI) UIManager.getUI(this));
}
}
Index: javax/swing/JRootPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JRootPane.java,v
retrieving revision 1.4.2.7
diff -u -b -B -r1.4.2.7 JRootPane.java
--- javax/swing/JRootPane.java 24 Jun 2004 05:31:32 -0000 1.4.2.7
+++ javax/swing/JRootPane.java 29 Jun 2004 09:56:55 -0000
@@ -222,6 +222,8 @@
}
}
+ private static final long serialVersionUID = 8690748000348575668L;
+
protected Component glassPane;
protected JLayeredPane layeredPane;
protected JMenuBar menuBar;
Index: javax/swing/UIManager.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/UIManager.java,v
retrieving revision 1.6.8.2
diff -u -b -B -r1.6.8.2 UIManager.java
--- javax/swing/UIManager.java 6 Jun 2004 12:57:00 -0000 1.6.8.2
+++ javax/swing/UIManager.java 29 Jun 2004 09:56:55 -0000
@@ -1,5 +1,5 @@
/* UIManager.java --
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -87,29 +87,44 @@
// Do nothing here.
}
- public static void addPropertyChangeListener (PropertyChangeListener listener)
+ /**
+ * Add a <code>PropertyChangeListener</code> to the listener list.
+ *
+ * @param listener the listener to add
+ */
+ public static void addPropertyChangeListener(PropertyChangeListener listener)
{
// FIXME
}
- public static void removePropertyChangeListener (PropertyChangeListener listener)
- // Remove a PropertyChangeListener from the listener list.
+ /**
+ * Remove a <code>PropertyChangeListener</code> from the listener list.
+ *
+ * @param listener the listener to remove
+ */
+ public static void removePropertyChangeListener(PropertyChangeListener listener)
{
// FIXME
}
/**
+ * Returns an array of all added <code>PropertyChangeListener</code> objects.
+ *
+ * @return an array of listeners
+ *
* @since 1.4
*/
- public static PropertyChangeListener[] getPropertyChangeListeners ()
+ public static PropertyChangeListener[] getPropertyChangeListeners()
{
// FIXME
throw new Error ("Not implemented");
}
+ /**
+ * Add a LookAndFeel to the list of auxiliary look and feels.
+ */
public static void addAuxiliaryLookAndFeel (LookAndFeel l)
{
- // Add a LookAndFeel to the list of auxiliary look and feels.
if (aux_installed == null)
{
aux_installed = new LookAndFeel[1];
@@ -201,14 +216,18 @@
return (Font) getLookAndFeel().getDefaults().get(key);
}
+ /**
+ * Returns an Icon from the defaults table.
+ */
public static Icon getIcon(Object key)
- // Returns an Icon from the defaults table.
{
return (Icon) getLookAndFeel().getDefaults().get(key);
}
+ /**
+ * Returns an Insets object from the defaults table.
+ */
public static Insets getInsets(Object key)
- // Returns an Insets object from the defaults table.
{
return (Insets) getLookAndFeel().getDefaults().getInsets(key);
}
@@ -240,49 +259,71 @@
return getLookAndFeel().getDefaults();
}
+ /**
+ * Returns a string from the defaults table.
+ */
public static String getString(Object key)
- // Returns a string from the defaults table.
{
return (String) getLookAndFeel().getDefaults().get(key);
}
+ /**
+ * Returns the name of the LookAndFeel class that implements the
+ * native systems look and feel if there is one, otherwise the name
+ * of the default cross platform LookAndFeel class.
+ */
public static String getSystemLookAndFeelClassName()
- // Returns the name of the LookAndFeel class that implements the native systems look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.
{
return getCrossPlatformLookAndFeelClassName();
}
+ /**
+ * Returns the L&F object that renders the target component.
+ */
public static ComponentUI getUI(JComponent target)
- // Returns the L&F object that renders the target component.
{
- ComponentUI ui = getDefaults().getUI(target);
- //System.out.println("GET-UI-> " + ui + ", for " + target);
- return ui;
+ return getDefaults().getUI(target);
}
+ /**
+ * Creates a new look and feel and adds it to the current array.
+ */
public static void installLookAndFeel(String name, String className)
- // Creates a new look and feel and adds it to the current array.
{
}
+ /**
+ * Adds the specified look and feel to the current array and then calls
+ * setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
+ */
public static void installLookAndFeel(LookAndFeelInfo info)
- // Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
{
}
+ /**
+ * Stores an object in the defaults table.
+ */
public static Object put(Object key, Object value)
- // Stores an object in the defaults table.
{
return getLookAndFeel().getDefaults().put(key,value);
}
+ /**
+ * Replaces the current array of installed LookAndFeelInfos.
+ */
public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
- // Replaces the current array of installed LookAndFeelInfos.
{
}
+ /**
+ * Set the current default look.
+ */
public static void setLookAndFeel(LookAndFeel newLookAndFeel)
+ throws UnsupportedLookAndFeelException
{
+ if (! newLookAndFeel.isSupportedLookAndFeel())
+ throw new UnsupportedLookAndFeelException(newLookAndFeel.getName());
+
if (look_and_feel != null)
look_and_feel.uninitialize();
@@ -294,11 +335,13 @@
//repaint();
}
+ /**
+ * Set the current default look and feel using a class name.
+ */
public static void setLookAndFeel (String className)
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
- // Set the current default look and feel using a class name.
Class c = Class.forName(className);
LookAndFeel a = (LookAndFeel) c.newInstance(); // throws class-cast-exception
setLookAndFeel(a);
Index: javax/swing/text/AbstractDocument.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/AbstractDocument.java,v
retrieving revision 1.3.8.10
diff -u -b -B -r1.3.8.10 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java 28 Jun 2004 10:54:19 -0000 1.3.8.10
+++ javax/swing/text/AbstractDocument.java 29 Jun 2004 09:56:55 -0000
@@ -92,15 +92,17 @@
return new LeafElement(parent, a, p0, p1 - p0);
}
- public Position createPosition(int offs)
+ public Position createPosition(final int offset)
+ throws BadLocationException
{
- final int a = offs;
+ if (offset < 0 || offset > getLength())
+ throw new BadLocationException(getText(0, getLength()), offset);
return new Position()
{
public int getOffset()
{
- return a;
+ return offset;
}
};
}
@@ -198,21 +200,13 @@
}
public String getText(int offset, int length)
- {
- try
+ throws BadLocationException
{
return content.getString(offset, length);
}
- catch (Exception e)
- {
- System.out.println("Hmmm, fail to getText: " + offset + " -> "
- + length);
-
- return null;
- }
- }
public void getText(int offset, int length, Segment txt)
+ throws BadLocationException
{
String a = getText(offset, length);
@@ -261,7 +255,8 @@
{
}
- public void remove(int offs, int len)
+ public void remove(int offset, int length)
+ throws BadLocationException
{
}
Index: javax/swing/text/ComponentView.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/ComponentView.java,v
retrieving revision 1.3
diff -u -b -B -r1.3 ComponentView.java
--- javax/swing/text/ComponentView.java 10 Jan 2004 21:07:44 -0000 1.3
+++ javax/swing/text/ComponentView.java 29 Jun 2004 09:56:56 -0000
@@ -79,6 +79,7 @@
}
public Shape modelToView(int pos, Shape a, Position.Bias b)
+ throws BadLocationException
{
return null;
}
Index: javax/swing/text/DefaultEditorKit.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/DefaultEditorKit.java,v
retrieving revision 1.4.8.2
diff -u -b -B -r1.4.8.2 DefaultEditorKit.java
--- javax/swing/text/DefaultEditorKit.java 29 Jun 2004 09:10:36 -0000 1.4.8.2
+++ javax/swing/text/DefaultEditorKit.java 29 Jun 2004 09:56:56 -0000
@@ -38,6 +38,7 @@
package javax.swing.text;
import java.io.InputStream;
+import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
@@ -103,53 +104,59 @@
{
}
- void deinstall(JEditorPane c)
+ /**
+ * Called when the kit is being removed from the JEditorPane.
+ */
+ public void deinstall(JEditorPane c)
{
- // Called when the kit is being removed from the JEditorPane.
}
- void install(JEditorPane c)
+ public void install(JEditorPane c)
{
}
- Caret createCaret()
+ public Caret createCaret()
{
return null;
}
- Document createDefaultDocument()
+ public Document createDefaultDocument()
{
return new PlainDocument();
}
- Action[] getActions()
+ public Action[] getActions()
{
return null;
}
- String getContentType()
+ public String getContentType()
{
return "text/plain";
}
- ViewFactory getViewFactory()
+ public ViewFactory getViewFactory()
{
return null;
}
- void read(InputStream in, Document doc, int pos)
+ public void read(InputStream in, Document doc, int pos)
+ throws BadLocationException, IOException
{
}
- void read(Reader in, Document doc, int pos)
+ public void read(Reader in, Document doc, int pos)
+ throws BadLocationException, IOException
{
}
- void write(OutputStream out, Document doc, int pos, int len)
+ public void write(OutputStream out, Document doc, int pos, int len)
+ throws BadLocationException, IOException
{
}
- void write(Writer out, Document doc, int pos, int len)
+ public void write(Writer out, Document doc, int pos, int len)
+ throws BadLocationException, IOException
{
}
}
Index: javax/swing/text/EditorKit.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/EditorKit.java,v
retrieving revision 1.2.8.1
diff -u -b -B -r1.2.8.1 EditorKit.java
--- javax/swing/text/EditorKit.java 29 Jun 2004 09:10:36 -0000 1.2.8.1
+++ javax/swing/text/EditorKit.java 29 Jun 2004 09:56:56 -0000
@@ -38,8 +38,10 @@
package javax.swing.text;
import java.io.InputStream;
+import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
+import java.io.Serializable;
import java.io.Writer;
import javax.swing.Action;
import javax.swing.JEditorPane;
@@ -48,38 +50,46 @@
public abstract class EditorKit
implements Cloneable
{
- EditorKit()
+ private static final long serialVersionUID = -5044124649345887822L;
+
+ public EditorKit()
{
}
- EditorKit(EditorKit kit)
+ public Object clone()
+ {
+ try
{
+ return super.clone();
}
-
- void deinstall(JEditorPane c)
+ catch (CloneNotSupportedException e)
{
- // Called when the kit is being removed from the JEditorPane.
+ return null;
+ }
}
- void install(JEditorPane c)
+ /**
+ * Called when the kit is being removed from the JEditorPane.
+ */
+ public void deinstall(JEditorPane c)
{
}
- abstract Caret createCaret();
-
- abstract Document createDefaultDocument();
-
- abstract Action[] getActions();
-
- abstract String getContentType();
-
- abstract ViewFactory getViewFactory();
-
- abstract void read(InputStream in, Document doc, int pos);
-
- abstract void read(Reader in, Document doc, int pos);
-
- abstract void write(OutputStream out, Document doc, int pos, int len);
+ public void install(JEditorPane c)
+ {
+ }
- abstract void write(Writer out, Document doc, int pos, int len);
+ public abstract Caret createCaret();
+ public abstract Document createDefaultDocument();
+ public abstract Action[] getActions();
+ public abstract String getContentType();
+ public abstract ViewFactory getViewFactory();
+ public abstract void read(InputStream in, Document doc, int pos)
+ throws BadLocationException, IOException;
+ public abstract void read(Reader in, Document doc, int pos)
+ throws BadLocationException, IOException;
+ public abstract void write(OutputStream out, Document doc, int pos, int len)
+ throws BadLocationException, IOException;
+ public abstract void write(Writer out, Document doc, int pos, int len)
+ throws BadLocationException, IOException;
}
Index: javax/swing/text/Segment.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/Segment.java,v
retrieving revision 1.2.8.2
diff -u -b -B -r1.2.8.2 Segment.java
--- javax/swing/text/Segment.java 29 Jun 2004 09:10:36 -0000 1.2.8.2
+++ javax/swing/text/Segment.java 29 Jun 2004 09:56:56 -0000
@@ -43,9 +43,20 @@
public class Segment
implements Cloneable, CharacterIterator
{
- char[] array;
- int count;
- int offset;
+ public char[] array;
+ public int count;
+ public int offset;
+
+ public Segment()
+ {
+ }
+
+ public Segment(char[] array, int offset, int count)
+ {
+ this.array = array;
+ this.offset = offset;
+ this.count = count;
+ }
public Object clone()
{
@@ -53,13 +64,11 @@
{
return super.clone();
}
- catch (Exception e)
+ catch (CloneNotSupportedException e)
{
- System.err.println("Huuuhhh, this class implements cloneable !!!!!!");
- System.err.println("I think there is a bug in this JVM somewhere");
- }
return null;
}
+ }
public char current()
{
Index: javax/swing/text/StyledEditorKit.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/StyledEditorKit.java,v
retrieving revision 1.3.8.2
diff -u -b -B -r1.3.8.2 StyledEditorKit.java
--- javax/swing/text/StyledEditorKit.java 29 Jun 2004 09:10:36 -0000 1.3.8.2
+++ javax/swing/text/StyledEditorKit.java 29 Jun 2004 09:56:56 -0000
@@ -55,7 +55,7 @@
*/
public class StyledEditorKit extends DefaultEditorKit
{
- static final long serialVersionUID = 7002391892985555948L;
+ private static final long serialVersionUID = 7002391892985555948L;
/**
* UnderlineAction