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]

[gui] Some (random) AWT and Swing fixlets


Hi,

While trying to get FreeMind (http://freemind.sf.net) working I made the
following changes to some AWT and Swing classes. It still doesn't really
work, but at least it starts up with this.

2005-02-13  Mark Wielaard  <mark@klomp.org>

     * java/awt/AWTKeyStroke.java (getAWTKeyStroke): Return null when
     the given String is null or cannot be parsed.

     * javax/swing/JRootPane.java (setJMenuBar): Remove current menubar
     if one is installed. Only install the given menubar is not null.

     * javax/swing/JViewport.java (getViewSize): Return an empty
     Dimension when the view isn't set.

     * javax/swing/ViewportLayout.java (preferredLayoutSize): Return an
     empty Dimension when there is no view set.
     (minimumLayoutSize): Likewise.
     (layoutContainer): Don't try to layout when there is no view.

I don't really have the intention to work on this much more. But if it
doesn't look bad I would like to commit it. Comments?

Cheers,

Mark
Index: java/awt/AWTKeyStroke.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/AWTKeyStroke.java,v
retrieving revision 1.6
diff -u -r1.6 AWTKeyStroke.java
--- java/awt/AWTKeyStroke.java	27 Sep 2004 15:11:46 -0000	1.6
+++ java/awt/AWTKeyStroke.java	13 Feb 2005 15:08:46 -0000
@@ -393,15 +393,16 @@
    * </code>      
    *
    * @param s the string to parse
-   * @return the specified keystroke
-   * @throws NullPointerException if s is null
-   * @throws IllegalArgumentException if s cannot be parsed
+   * @return the specified keystroke, or null when s is null
+   * or cannot be parsed correctly.
    */
   public static AWTKeyStroke getAWTKeyStroke(String s)
   {
+    if (s == null)
+      return null;
     StringTokenizer t = new StringTokenizer(s, " ");
     if (! t.hasMoreTokens())
-      throw new IllegalArgumentException();
+      return null;
     int modifiers = 0;
     boolean released = false;
     String token = null;
@@ -432,7 +433,7 @@
                                          KeyEvent.VK_UNDEFINED, modifiers,
                                          false);
               }
-            throw new IllegalArgumentException();
+            return null;
           }
         else if ("pressed".equals(token))
           {
@@ -454,7 +455,7 @@
     // Now token contains the VK name we must parse.
     Integer code = (Integer) vktable.get(token);
     if (code == null || t.hasMoreTokens())
-      throw new IllegalArgumentException();
+      return null;
     return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, code.intValue(),
                            modifiers, released);
   }
Index: javax/swing/JRootPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JRootPane.java,v
retrieving revision 1.19
diff -u -r1.19 JRootPane.java
--- javax/swing/JRootPane.java	31 Dec 2004 10:19:44 -0000	1.19
+++ javax/swing/JRootPane.java	13 Feb 2005 15:08:46 -0000
@@ -346,8 +346,12 @@
    */
   public void setJMenuBar(JMenuBar m)
   {
+    JLayeredPane jlPane = getLayeredPane();
+    if (menuBar != null)
+      jlPane.remove(menuBar);
     menuBar = m;
-    getLayeredPane().add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
+    if (menuBar != null)
+      jlPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
   }
 
   /**
Index: javax/swing/JViewport.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JViewport.java,v
retrieving revision 1.16
diff -u -r1.16 JViewport.java
--- javax/swing/JViewport.java	25 Jan 2005 07:07:25 -0000	1.16
+++ javax/swing/JViewport.java	13 Feb 2005 15:08:46 -0000
@@ -158,12 +158,23 @@
     fireStateChanged();
   }
 
+  /**
+   * Returns the viewSize when set, or the size of the set Component view.
+   * If no viewSize and no Component view is set an empty Dimension is
+   * returned.
+   */
   public Dimension getViewSize()
   {
     if (isViewSizeSet)
       return viewSize;
     else
-      return getView().getSize();
+      {
+	Component view = getView();
+	if (view != null)
+	  return view.getSize();
+	else
+	  return new Dimension();
+      }
   }
 
 
Index: javax/swing/ViewportLayout.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/ViewportLayout.java,v
retrieving revision 1.11
diff -u -r1.11 ViewportLayout.java
--- javax/swing/ViewportLayout.java	27 Dec 2004 11:24:47 -0000	1.11
+++ javax/swing/ViewportLayout.java	13 Feb 2005 15:08:46 -0000
@@ -63,17 +63,25 @@
   public void removeLayoutComponent(Component c) 
   {
   }
+
   public Dimension preferredLayoutSize(Container parent) 
   {
     JViewport vp = (JViewport)parent;
     Component view = vp.getView();
-    return view.getPreferredSize();
+    if (view != null)
+      return view.getPreferredSize();
+    else
+      return new Dimension();
   }
+
   public Dimension minimumLayoutSize(Container parent) 
   {
     JViewport vp = (JViewport)parent;
     Component view = vp.getView();
-    return view.getMinimumSize();
+    if (view != null)
+      return view.getMinimumSize();
+    else
+      return new Dimension();
   }
 
   /**
@@ -113,6 +121,9 @@
     JViewport port = (JViewport) parent;    
     Component view = port.getView();
 
+    if (view == null)
+      return;
+
     // These dimensions and positions are in *view space*.  Do not mix
     // variables in here from port space (eg. parent.getBounds()). This
     // function should be entirely in view space, because the methods on

Attachment: signature.asc
Description: This is a digitally signed message part


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