Added code to actually paint the one touch buttons on the divider and implemented the missing class in MetalSplitPaneDivider.
2005-11-24 Lillian Angel <[EMAIL PROTECTED]> * javax/swing/plaf/basic/BasicArrowButton.java (paint): Fixed locations, so button is drawn in proper place. * javax/swing/plaf/basic/BasicSplitPaneDivider.java (paint): Added code to paint buttons. * javax/swing/plaf/metal/MetalSplitPaneDivider.java: Added new fields. (MetalSplitPaneDivider): Initialized new fields, and set layout to new inner class. (paint): Added code to paint buttons. (DividerLayout): New class implemented. (DividerLayout.init): Implemented. (DividerLayout.addLayoutComponent): Implemented. (DividerLayout.layoutContainer): Implemented. (DividerLayout.minimumLayoutSize): Implemented. (DividerLayout.preferredLayoutSize): Implemented. (DividerLayout.removeLayoutComponent): Implemented.
Index: javax/swing/plaf/basic/BasicArrowButton.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicArrowButton.java,v retrieving revision 1.16 diff -u -r1.16 BasicArrowButton.java --- javax/swing/plaf/basic/BasicArrowButton.java 20 Oct 2005 14:55:02 -0000 1.16 +++ javax/swing/plaf/basic/BasicArrowButton.java 24 Nov 2005 18:11:53 -0000 @@ -162,8 +162,8 @@ super.paint(g); Rectangle bounds = getBounds(); int size = bounds.height / 4; - int x = (bounds.width - size) / 2; - int y = (bounds.height - size) / 2; + int x = bounds.x + (bounds.width - size) / 2; + int y = (bounds.height - size) / 4; ButtonModel m = getModel(); if (m.isArmed()) { Index: javax/swing/plaf/basic/BasicSplitPaneDivider.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicSplitPaneDivider.java,v retrieving revision 1.11 diff -u -r1.11 BasicSplitPaneDivider.java --- javax/swing/plaf/basic/BasicSplitPaneDivider.java 18 Oct 2005 22:10:32 -0000 1.11 +++ javax/swing/plaf/basic/BasicSplitPaneDivider.java 24 Nov 2005 18:11:53 -0000 @@ -45,6 +45,7 @@ import java.awt.Graphics; import java.awt.Insets; import java.awt.LayoutManager; +import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; @@ -375,6 +376,11 @@ { dividerSize = getSize(); border.paintBorder(this, g, 0, 0, dividerSize.width, dividerSize.height); + } + if (splitPane.isOneTouchExpandable()) + { + ((BasicArrowButton) rightButton).paint(g); + ((BasicArrowButton) leftButton).paint(g); } } Index: javax/swing/plaf/metal/MetalSplitPaneDivider.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalSplitPaneDivider.java,v retrieving revision 1.3 diff -u -r1.3 MetalSplitPaneDivider.java --- javax/swing/plaf/metal/MetalSplitPaneDivider.java 28 Sep 2005 13:16:48 -0000 1.3 +++ javax/swing/plaf/metal/MetalSplitPaneDivider.java 24 Nov 2005 18:11:53 -0000 @@ -38,9 +38,17 @@ package javax.swing.plaf.metal; import java.awt.Color; +import java.awt.Component; +import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; +import java.awt.LayoutManager; +import java.awt.Point; +import javax.swing.JSplitPane; +import javax.swing.SwingConstants; +import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicSplitPaneDivider; /** @@ -56,7 +64,13 @@ /** The light color in the pattern. */ Color light; + + /** The JSplitPane the divider is on. */ + JSplitPane splitPane; + /** The split pane orientation. */ + int orientation; + /** * Creates a new instance of MetalSplitPaneDivider. * @@ -65,6 +79,9 @@ public MetalSplitPaneDivider(MetalSplitPaneUI ui, Color light, Color dark) { super(ui); + setLayout(new DividerLayout()); + this.splitPane = super.splitPane; + this.orientation = super.orientation; this.light = light; this.dark = dark; } @@ -76,9 +93,127 @@ */ public void paint(Graphics g) { - //super.paint(g); Dimension s = getSize(); MetalUtils.fillMetalPattern(splitPane, g, 2, 2, s.width - 4, s.height - 4, light, dark); + if (splitPane.isOneTouchExpandable()) + { + ((BasicArrowButton) rightButton).paint(g); + ((BasicArrowButton) leftButton).paint(g); + } + } + + /** + * This helper class acts as the Layout Manager for the divider. + */ + protected class DividerLayout implements LayoutManager + { + /** The right button. */ + BasicArrowButton rb; + + /** The left button. */ + BasicArrowButton lb; + + /** + * Creates a new DividerLayout object. + */ + protected DividerLayout() + { + // Nothing to do here + } + + /** + * This method is called when a Component is added. + * + * @param string The constraints string. + * @param c The Component to add. + */ + public void addLayoutComponent(String string, Component c) + { + // Nothing to do here, constraints are set depending on + // orientation in layoutContainer + } + + /** + * This method is called to lay out the container. + * + * @param c The container to lay out. + */ + public void layoutContainer(Container c) + { + // The only components we care about setting up are the + // one touch buttons. + if (splitPane.isOneTouchExpandable()) + { + if (c.getComponentCount() == 2) + { + Component c1 = c.getComponent(0); + Component c2 = c.getComponent(1); + if ((c1 instanceof BasicArrowButton) + && (c2 instanceof BasicArrowButton)) + { + lb = ((BasicArrowButton) c1); + rb = ((BasicArrowButton) c2); + } + } + if (rb != null && lb != null) + { + Point p = getLocation(); + lb.setSize(lb.getPreferredSize()); + rb.setSize(rb.getPreferredSize()); + lb.setLocation(p.x, p.y); + + if (orientation == JSplitPane.HORIZONTAL_SPLIT) + { + rb.setDirection(SwingConstants.EAST); + lb.setDirection(SwingConstants.WEST); + rb.setLocation(p.x, p.y + lb.getHeight()); + } + else + { + rb.setDirection(SwingConstants.SOUTH); + lb.setDirection(SwingConstants.NORTH); + rb.setLocation(p.x + lb.getWidth(), p.y); + } + } + } + } + + /** + * This method returns the minimum layout size. + * + * @param c The container to calculate for. + * + * @return The minimum layout size. + */ + public Dimension minimumLayoutSize(Container c) + { + return preferredLayoutSize(c); + } + + /** + * This method returns the preferred layout size. + * + * @param c The container to calculate for. + * + * @return The preferred layout size. + */ + public Dimension preferredLayoutSize(Container c) + { + int dividerSize = getDividerSize(); + return new Dimension(dividerSize, dividerSize); + } + + /** + * This method is called when a component is removed. + * + * @param c The component to remove. + */ + public void removeLayoutComponent(Component c) + { + // Nothing to do here. If buttons are removed + // they will not be layed out when layoutContainer is + // called. + } } }
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches