[gui][PATCH] fixes to JRootPane.RootLayout and JLayeredPane
Olga Rodimina
rodimina@redhat.com
Mon May 17 16:24:00 GMT 2004
Hi,
Attached patch sets layout of the JLayeredPane to null and fixes
JRootPane.RootLayout to position contentPane and menuBar properly
within the layeredPane.
I'll be committing this patch to java-gui-branch.
Olga.
-------------- next part --------------
? .snprj
? libjava.proj
? patch
? javax/swing/patch
? javax/swing/plaf/basic/patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.98
diff -c -p -u -r1.2660.2.98 ChangeLog
--- ChangeLog 14 May 2004 02:25:43 -0000 1.2660.2.98
+++ ChangeLog 17 May 2004 16:18:53 -0000
@@ -1,3 +1,16 @@
+2004-05-17 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/JRootPane.java
+ (JRootPane.RootLayout): Reimplemented to
+ set bounds of contentPane and menuBar.
+ (setJMenuBar): Add menu bar to the layered pane.
+ (createLayeredPane): Set layout of layeredPane
+ to null.
+ * javax/swing/JLayeredPane.java:
+ (addImpl): Calculate index of the component in the
+ layeredPane according to the specified position within
+ the layer.
+
2004-05-13 Thomas Fitzsimmons <fitzsim@redhat.com>
* libgcj.spec.in (lib): Add -l-java-awt -l-java-applet
Index: javax/swing/JLayeredPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JLayeredPane.java,v
retrieving revision 1.6
diff -c -p -u -r1.6 JLayeredPane.java
--- javax/swing/JLayeredPane.java 9 Jan 2004 22:52:18 -0000 1.6
+++ javax/swing/JLayeredPane.java 17 May 2004 16:18:56 -0000
@@ -563,7 +563,7 @@ public class JLayeredPane extends JCompo
else
layer = DEFAULT_LAYER;
- int newIdx = insertIndexForLayer(layer.intValue (), -1);
+ int newIdx = insertIndexForLayer(layer.intValue (), index);
componentToLayer.put (comp, layer);
incrLayer (layer);
Index: javax/swing/JRootPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JRootPane.java,v
retrieving revision 1.4
diff -c -p -u -r1.4 JRootPane.java
--- javax/swing/JRootPane.java 12 Feb 2004 00:17:23 -0000 1.4
+++ javax/swing/JRootPane.java 17 May 2004 16:18:56 -0000
@@ -68,17 +68,146 @@ public class JRootPane extends JComponen
static protected class AccessibleJRootPane
{
}
-
- //A custom layout manager
- static protected class RootLayout extends BorderLayout
- {
- public Dimension preferredLayoutSize ( Container c )
- {
- Dimension p = super.preferredLayoutSize(c);
- return p;
- }
+
+ // Custom Layout Manager for JRootPane. It positions contentPane and
+ // menuBar withing its layeredPane.
+ protected class RootLayout extends Object implements LayoutManager2
+ {
+ public void addLayoutComponent(Component comp, Object constraints)
+ {
+ }
+
+ public void addLayoutComponent(String name, Component comp)
+ {
+ }
+
+ public float getLayoutAlignmentX(Container target)
+ {
+ return target.getAlignmentX();
+ }
+
+ public float getLayoutAlignmentY(Container target)
+ {
+ return target.getAlignmentY();
+ }
+
+ public void invalidateLayout(Container target)
+ {
+ }
+
+ public void layoutContainer(Container c)
+ {
+ Dimension menuBarSize;
+ Dimension containerSize = c.getSize(null);
+ Dimension contentPaneSize = contentPane.getPreferredSize();
+
+ /*
+ if size of top-level window wasn't set then just set
+ contentPane and menuBar to its preferred sizes.
+ Otherwise, if the size of top-level window was specified then
+ set menuBar to its preferred size and make content pane
+ to fit into the remaining space
+
+
+ +-------------------------------+
+ | JLayeredPane |
+ | +--------------------------+ |
+ | | menuBar | |
+ | +--------------------------+ |
+ | +--------------------------+ |
+ | |contentPane | |
+ | | | |
+ | | | |
+ | | | |
+ | +--------------------------+ |
+ +-------------------------------+
+
+ */
+ if (containerSize.width == 0 && containerSize.height == 0)
+ {
+ if (menuBar != null)
+ {
+ int maxWidth;
+ menuBarSize = menuBar.getPreferredSize();
+ maxWidth = Math.max(menuBarSize.width, contentPaneSize.width);
+ menuBar.setBounds(0, 0, maxWidth, menuBarSize.height);
+ contentPane.setBounds(0, menuBarSize.height, maxWidth,
+ contentPaneSize.height);
+ layeredPane.setSize(maxWidth,
+ menuBarSize.height + contentPaneSize.height);
+ }
+ else
+ {
+ contentPane.setBounds(0, 0, contentPaneSize.width,
+ contentPaneSize.height);
+ layeredPane.setSize(contentPaneSize.width, contentPaneSize.height);
+ }
+ }
+ else
+ {
+ if (menuBar != null)
+ {
+ menuBarSize = menuBar.getPreferredSize();
+ if (menuBarSize.height > containerSize.height)
+ menuBarSize.height = containerSize.height;
+ menuBar.setBounds(0, 0, containerSize.width, menuBarSize.height);
+ int remainingHeight = containerSize.height - menuBarSize.height;
+ contentPane.setBounds(0, menuBarSize.height,
+ containerSize.width,
+ (containerSize.height - menuBarSize.height));
+ }
+ else
+ contentPane.setBounds(0, 0, containerSize.width,
+ containerSize.height);
+
+ layeredPane.setSize(containerSize.width, containerSize.height);
+ }
+ }
+
+ public Dimension maximumLayoutSize(Container target)
+ {
+ return preferredLayoutSize(target);
+ }
+
+ public Dimension minimumLayoutSize(Container target)
+ {
+ return preferredLayoutSize(target);
+ }
+
+ public Dimension preferredLayoutSize(Container c)
+ {
+ Dimension menuBarSize;
+ Dimension prefSize;
+
+ Dimension containerSize = c.getSize();
+ Dimension contentPaneSize = contentPane.getPreferredSize();
+
+ if (containerSize.width == 0 && containerSize.height == 0)
+ {
+ if (menuBar != null)
+ {
+ int maxWidth;
+ menuBarSize = menuBar.getPreferredSize();
+ maxWidth = Math.max(menuBarSize.width, contentPaneSize.width);
+ prefSize = new Dimension(maxWidth,
+ contentPaneSize.height
+ + menuBarSize.height);
+ }
+ else
+ prefSize = contentPaneSize;
+ }
+ else
+ prefSize = c.getSize();
+
+ return prefSize;
+ }
+
+ public void removeLayoutComponent(Component comp)
+ {
+ }
}
-
+
+
/***********************************************************/
@@ -100,7 +229,10 @@ public class JRootPane extends JComponen
void setJMenuBar(JMenuBar m)
- { menuBar = m; }
+ {
+ menuBar = m;
+ getLayeredPane().add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
+ }
JMenuBar getJMenuBar()
{ return menuBar; }
@@ -206,6 +338,7 @@ public class JRootPane extends JComponen
JLayeredPane createLayeredPane()
{
JLayeredPane l = new JLayeredPane();
+ l.setLayout(null);
return l;
}
}
More information about the Java-patches
mailing list