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: Fox for PR 13006 / javax.swing.BoxLayout


Hi list,



I wrote the attached patch to fix the libgcj part of the bug of PR 13006.

Please review and comment.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2346
diff -u -b -B -r1.2346 ChangeLog
--- ChangeLog	19 Nov 2003 12:06:36 -0000	1.2346
+++ ChangeLog	19 Nov 2003 12:55:50 -0000
@@ -1,3 +1,24 @@
+2003-11-19  Michael Koch  <konqueror@gmx.de>
+
+	* javax/swing/BoxLayout.java
+	(serialVersionUIR): New member variable.
+	(X_AXIS, Y_AXIS): Documentation added.
+	(LINE_AXIS, PAGE_AXIS): New constants.
+	(grid): Renamed from gridbag.
+	(BoxLayout): Use new constants, throw exception if invalid value for
+	way, added documentation.
+	(BoxLayout): Removed.
+	(addLayoutComponent): Use new constants, added documentation.
+	(removeLayoutComponent): Likewise.
+	(addLayoutContainer): Added documentation.
+	(preferredLayoutSize): Added documentation, check given argument.
+	(minimumLayoutSize): Likewise.
+	(layoutContainer): Likewise.
+	(getLayoutAlignmentX): Likewise.
+	(getLayoutAlignmentY): Likewise.
+	(invalidateLayout): Likewise.
+	(maximumLayoutSize): Likewise.
+
 2003-11-19  Guilhem Lavaux <guilhem@kaffe.org>
 	    Jim Pick  <jim@kaffe.org>
 
Index: javax/swing/BoxLayout.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/BoxLayout.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 BoxLayout.java
--- javax/swing/BoxLayout.java	11 Jun 2003 13:20:39 -0000	1.2
+++ javax/swing/BoxLayout.java	19 Nov 2003 12:55:50 -0000
@@ -1,5 +1,5 @@
 /* BoxLayout.java -- A layout for swing components.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -35,11 +35,12 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
-
 package javax.swing;
 
-import java.awt.Container;
+import java.awt.AWTError;
 import java.awt.Component;
+import java.awt.ComponentOrientation;
+import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.GridLayout;
 import java.awt.LayoutManager2;
@@ -54,101 +56,203 @@
  */
 public class BoxLayout implements LayoutManager2, Serializable
 {
-    GridLayout      gridbag;
+  /*
+   * Needed for serialization.
+   */
+  private static final long serialVersionUID = -2474455742719112368L;
+
+  /**
+   * Specifies that components are laid out left to right.
+   */
+  public static final int X_AXIS = 0;
     
-    final static int X_AXIS = 0;
-    final static int Y_AXIS = 1;
+  /**
+   * Specifies that components are laid out top to bottom.
+   */
+  public static final int Y_AXIS = 1;
 
+  /**
+   * Specifies that components are laid out in the direction of a line of text.
+   */
+  public static final int LINE_AXIS = 2;
+
+  /**
+   * Sepcifies that components are laid out in the direction of the line flow.
+   */
+  public static final int PAGE_AXIS = 3;
+
+  /*
+   * The container given to the constructor.
+   */
+  Container container;
+  
+  /*
+   * Internal layout.
+   */
+  GridLayout grid;
+
+  /*
+   * Current type of component layouting. Defaults to X_AXIS.
+   */
     int way = X_AXIS;
 
-    BoxLayout(JComponent p,
-	      int way)
+  /**
+   * Constructs a <code>BoxLayout</code> object.
+   *
+   * @param container The container that needs to be laid out.
+   * @param way The orientation of the components.
+   *
+   * @exception AWTError If way has an invalid value.
+   */
+  public BoxLayout(Container container, int way)
     {
 	int width = 0;
 	int height = 0;
+    ComponentOrientation orientation = container.getComponentOrientation();
 
+    this.container = container;
 	this.way = way;
 
-	if (way == X_AXIS)
+    switch (way)
 	    {
+      case X_AXIS:
 		width = 1;
-	    }
+	break;
+      case Y_AXIS:
+	height = 1;
+	break;
+      case LINE_AXIS:
+	if (orientation.isHorizontal())
+          height = 1;
 	else
-	    {
+	  width = 1;
+	break;
+      case PAGE_AXIS:
+	if (!orientation.isHorizontal())
 		height = 1;
+	else
+	  width = 1;
+	break;
+      default:
+	throw new AWTError("Invalid value for way");
 	    }
 	
-
-	gridbag = new GridLayout(width, height);
-    }
-    
-    BoxLayout(int way)
-    {
-	this(null,way);
+    grid = new GridLayout(width, height);
     }
     
-
-    public void addLayoutComponent(String name, Component comp)
-    {
-	if (way == X_AXIS)
+  /**
+   * Adds a component to the layout.
+   */
+  public void addLayoutComponent(String name, Component component)
 	    {
-		gridbag.setColumns( gridbag.getColumns() + 1);
-	    }
+    if (way == X_AXIS
+        || (way == LINE_AXIS
+            && component.getComponentOrientation().isHorizontal())
+        || (way == PAGE_AXIS
+            && !component.getComponentOrientation().isHorizontal()))
+      grid.setColumns(grid.getColumns() + 1);
 	else
-	    {
-		gridbag.setRows( gridbag.getRows() + 1);
-	    }
+      grid.setRows(grid.getRows() + 1);
     }
 
-    public void removeLayoutComponent(Component comp)
-    {
-	gridbag.removeLayoutComponent(comp);
-	if (way == X_AXIS)
+  /**
+   * Removes a component from the layout.
+   */
+  public void removeLayoutComponent(Component component)
 	    {
-		gridbag.setColumns( gridbag.getColumns() - 1);
-	    }
+    grid.removeLayoutComponent(component);
+
+    if (way == X_AXIS
+        || (way == LINE_AXIS
+            && component.getComponentOrientation().isHorizontal())
+        || (way == PAGE_AXIS
+            && !component.getComponentOrientation().isHorizontal()))
+      grid.setColumns(grid.getColumns() - 1);
 	else
-	    {
-		gridbag.setRows( gridbag.getRows() - 1);
-	    }
+      grid.setRows(grid.getRows() - 1);
     }
 
+  /**
+   * Returns the preferred size of the layout.
+   */
     public Dimension preferredLayoutSize(Container parent)
     {
-	return gridbag.preferredLayoutSize(parent);
+    if (parent != container)
+      throw new AWTError("invalid parent");
+    
+    return grid.preferredLayoutSize(parent);
     }
 
+  /**
+   * Returns the minimum size of the layout.
+   */
     public Dimension minimumLayoutSize(Container parent)
     {
-	return gridbag.minimumLayoutSize(parent);
+    if (parent != container)
+      throw new AWTError("invalid parent");
+    
+    return grid.minimumLayoutSize(parent);
     }
 
+  /**
+   * Lays out the specified container using this layout.
+   */
     public void layoutContainer(Container parent)
     {	
-	gridbag.layoutContainer(parent);
+    if (parent != container)
+      throw new AWTError("invalid parent");
+    
+    grid.layoutContainer(parent);
     }
 
-    public void addLayoutComponent ( Component child, Object constraints )
+  /**
+   * Adds a component to the layout.
+   */
+  public void addLayoutComponent(Component child, Object constraints)
     {
 	addLayoutComponent("", child);
     }
 
-    public float getLayoutAlignmentX ( Container parent )
+  /**
+   * Returns the alignment along the X axis for the container.
+   */
+  public float getLayoutAlignmentX(Container parent)
     {
+    if (parent != container)
+      throw new AWTError("invalid parent");
+    
 	return 0;
     }
 
-    public float getLayoutAlignmentY ( Container parent )
+  /**
+   * Returns the alignment along the Y axis for the container.
+   */
+  public float getLayoutAlignmentY(Container parent)
     {
+    if (parent != container)
+      throw new AWTError("invalid parent");
+    
 	return 0;
     }
 
-    public void invalidateLayout ( Container parent )
+  /**
+   * Invalidates the layout.
+   */
+  public void invalidateLayout(Container parent)
     {
+    if (parent != container)
+      throw new AWTError("invalid parent");
     }
 
-    public Dimension maximumLayoutSize ( Container parent )
+  /**
+   * Returns the maximum size of the layout gived the components
+   * in the given container.
+   */
+  public Dimension maximumLayoutSize(Container parent)
     {
+    if (parent != container)
+      throw new AWTError("invalid parent");
+    
 	return preferredLayoutSize(parent);
     }
 }

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