This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[patch][gui] JSplitPane, JDialog, and other things
- From: Kim Ho <kho at redhat dot com>
- To: java-patches <java-patches at gcc dot gnu dot org>
- Date: 19 Apr 2004 15:36:51 -0400
- Subject: [patch][gui] JSplitPane, JDialog, and other things
- Organization:
Hi,
This patch implements JSplitPane, reworks some of JDialog and has some
other small fixes.
Cheers,
Kim
2004-04-19 Kim Ho <kho@redhat.com>
* java/awt/Container.java:
(remove): Set the component's parent to null.
(getComponentAt): Implement.
* javax/swing/JComponent.java:
(JComponent): Initialize defaultLocale
(getDefaultLocale): Implement.
(setDefaultLocale): ditto.
* javax/swing/JSlider.java:
(JSlider): Fix calculation of value.
* javax/swing/JSplitPane.java: Implement.
* javax/swing/plaf/basic/BasicLookAndFeel.java:
Change SplitPane's default divider size.
* javax/swing/plaf/basic/BasicScrollBarUI:
(paint): Remove unused code.
* javax/swing/plaf/basic/BasicSplitPaneDivider.java:
Added comments and ran through jalopy.
(setBasicSplitPaneUI): Get reference to hidden divider
and set up one touch buttons if necessary.
(setBorder): Fire propertyChangeEvent only if
borders are different.
(getPreferredSize): Defer to layout manager.
(propertyChange): Implement.
(oneTouchExpandableChanged): ditto.
(createLeftOneTouchButton): Use BasicArrowButton.
(createRightOneTouchButton): ditto.
(moveDividerTo): New method. Moves the divider
to a set location based on the last divider location.
(BasicSplitPaneDivider::MouseHandler): Implement.
(BasicSplitPaneDivider::OneTouchButton): Removed.
(BasicSplitPaneDivider::DragController): Implement.
(BasicSplitPaneDivider::VerticalDragController):
ditto.
(BasicSplitPaneDivider::DividerLayout): ditto.
* javax/swing/plaf/basic/BasicSplitPaneUI: Reimplement.
* javax/swing/plaf/basic/BasicTabbedPaneUI:
(calculateLayoutInfo): Don't show component if it's
null.
(paintTab): Fix title paint logic.
Index: java/awt/Container.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Container.java,v
retrieving revision 1.34.2.6
diff -u -r1.34.2.6 Container.java
--- java/awt/Container.java 10 Mar 2004 21:43:01 -0000 1.34.2.6
+++ java/awt/Container.java 19 Apr 2004 19:22:46 -0000
@@ -386,6 +386,7 @@
{
Component r = component[index];
+ r.parent = null;
r.removeNotify();
System.arraycopy(component, index + 1, component, index,
@@ -852,6 +853,11 @@
public Component getComponentAt(int x, int y)
{
return locate (x, y);
+ }
+
+ public Component getComponentAt(int index)
+ {
+ return component[index];
}
/**
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JComponent.java,v
retrieving revision 1.7.2.4
diff -u -r1.7.2.4 JComponent.java
--- javax/swing/JComponent.java 22 Mar 2004 23:38:19 -0000 1.7.2.4
+++ javax/swing/JComponent.java 19 Apr 2004 19:22:46 -0000
@@ -65,6 +65,7 @@
import java.io.Serializable;
import java.util.EventListener;
import java.util.Hashtable;
+import java.util.Locale;
import java.util.Vector;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
@@ -107,6 +108,8 @@
ComponentUI ui;
private SwingPropertyChangeSupport changeSupport;
+ static Locale defaultLocale;
+
Hashtable prop_hash;
@@ -280,6 +283,10 @@
super();
super.setLayout(new FlowLayout());
+ // By default, all JComponents have a locale of
+ // the VM default.
+ defaultLocale = Locale.getDefault();
+
//eventMask |= AWTEvent.COMP_KEY_EVENT_MASK;
// enableEvents( AWTEvent.KEY_EVENT_MASK );
@@ -1095,6 +1102,16 @@
{
// Resets the UI property to a value from the current look and feel.
System.out.println("update UI not overwritten in class: " + this);
+ }
+
+ public static Locale getDefaultLocale()
+ {
+ return defaultLocale;
+ }
+
+ public static void setDefaultLocale(Locale l)
+ {
+ defaultLocale = l;
}
}
Index: javax/swing/JSlider.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JSlider.java,v
retrieving revision 1.3.18.6
diff -u -r1.3.18.6 JSlider.java
--- javax/swing/JSlider.java 23 Mar 2004 14:42:19 -0000 1.3.18.6
+++ javax/swing/JSlider.java 19 Apr 2004 19:22:47 -0000
@@ -307,7 +307,7 @@
*/
public JSlider(int minimum, int maximum)
{
- this(HORIZONTAL, minimum, maximum, (maximum - minimum) / 2);
+ this(HORIZONTAL, minimum, maximum, (maximum + minimum) / 2);
}
/**
Index: javax/swing/JSplitPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JSplitPane.java,v
retrieving revision 1.2
diff -u -r1.2 JSplitPane.java
--- javax/swing/JSplitPane.java 10 Jan 2004 21:07:43 -0000 1.2
+++ javax/swing/JSplitPane.java 19 Apr 2004 19:22:47 -0000
@@ -1,648 +1,775 @@
-/* JSplitPane.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-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.Component;
import java.awt.Graphics;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleStateSet;
import javax.accessibility.AccessibleValue;
+import javax.swing.UIManager;
import javax.swing.plaf.SplitPaneUI;
+
/**
- * JSplitPane
- * @author Andrew Selkirk
- * @version 1.0
+ * This class implements JSplitPane. It is used to divide two components. By
+ * dragging the SplitPane's divider, the user can resize the two components.
+ * Note that the divider cannot resize a component to smaller than it's
+ * minimum size.
*/
-public class JSplitPane extends JComponent implements Accessible {
-
- //-------------------------------------------------------------
- // Classes ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * AccessibleJSplitPane
- */
- protected class AccessibleJSplitPane extends AccessibleJComponent
- implements AccessibleValue {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor AccessibleJSplitPane
- * @param component TODO
- */
- protected AccessibleJSplitPane(JSplitPane component) {
- super(component);
- // TODO
- } // AccessibleJSplitPane()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * getAccessibleStateSet
- * @returns AccessibleStateSet
- */
- public AccessibleStateSet getAccessibleStateSet() {
- return null; // TODO
- } // getAccessibleStateSet()
-
- /**
- * getAccessibleRole
- * @returns AccessibleRole
- */
- public AccessibleRole getAccessibleRole() {
- return AccessibleRole.SPLIT_PANE;
- } // getAccessibleRole()
-
- /**
- * getAccessibleValue
- * @returns AccessibleValue
- */
- public AccessibleValue getAccessibleValue() {
- return null; // TODO
- } // getAccessibleValue()
-
- /**
- * getCurrentAccessibleValue
- * @returns Number
- */
- public Number getCurrentAccessibleValue() {
- return null; // TODO
- } // getCurrentAccessibleValue()
-
- /**
- * setCurrentAccessibleValue
- * @param value0 TODO
- * @returns boolean
- */
- public boolean setCurrentAccessibleValue(Number value0) {
- return false; // TODO
- } // setCurrentAccessibleValue()
-
- /**
- * getMinimumAccessibleValue
- * @returns Number
- */
- public Number getMinimumAccessibleValue() {
- return null; // TODO
- } // getMinimumAccessibleValue()
-
- /**
- * getMaximumAccessibleValue
- * @returns Number
- */
- public Number getMaximumAccessibleValue() {
- return null; // TODO
- } // getMaximumAccessibleValue()
-
-
- } // AccessibleJSplitPane
-
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * uiClassID
- */
- private static final String uiClassID = "SplitPaneUI";
-
- /**
- * VERTICAL_SPLIT
- */
- public static final int VERTICAL_SPLIT = 0;
-
- /**
- * HORIZONTAL_SPLIT
- */
- public static final int HORIZONTAL_SPLIT = 1;
-
- /**
- * LEFT
- */
- public static final String LEFT = "left";
-
- /**
- * RIGHT
- */
- public static final String RIGHT = "right";
-
- /**
- * TOP
- */
- public static final String TOP = "top";
-
- /**
- * BOTTOM
- */
- public static final String BOTTOM = "bottom";
-
- /**
- * DIVIDER
- */
- public static final String DIVIDER = "divider";
-
- /**
- * ORIENTATION_PROPERTY
- */
- public static final String ORIENTATION_PROPERTY = "orientation";
-
- /**
- * CONTINUOUS_LAYOUT_PROPERTY
- */
- public static final String CONTINUOUS_LAYOUT_PROPERTY = "continuousLayout";
-
- /**
- * DIVIDER_SIZE_PROPERTY
- */
- public static final String DIVIDER_SIZE_PROPERTY = "dividerSize";
-
- /**
- * ONE_TOUCH_EXPANDABLE_PROPERTY
- */
- public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = "oneTouchExpandable";
-
- /**
- * LAST_DIVIDER_LOCATION_PROPERTY
- */
- public static final String LAST_DIVIDER_LOCATION_PROPERTY = "lastDividerLocation";
-
- /**
- * DIVIDER_LOCATION_PROPERTY
- */
- public static final String DIVIDER_LOCATION_PROPERTY = "dividerLocation";
-
- /**
- * RESIZE_WEIGHT_PROPERTY
- */
- public static final String RESIZE_WEIGHT_PROPERTY = "resizeWeight";
-
- /**
- * orientation
- */
- protected int orientation;
-
- /**
- * continuousLayout
- */
- protected boolean continuousLayout;
-
- /**
- * leftComponent
- */
- protected Component leftComponent;
-
- /**
- * rightComponent
- */
- protected Component rightComponent;
-
- /**
- * dividerSize
- */
- protected int dividerSize;
-
- /**
- * oneTouchExpandable
- */
- protected boolean oneTouchExpandable;
-
- /**
- * lastDividerLocation
- */
- protected int lastDividerLocation;
-
- /**
- * resizeWeight
- */
- private double resizeWeight;
-
- /**
- * dividerLocation
- */
- private int dividerLocation;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor JSplitPane
- */
- public JSplitPane() {
- // TODO
- } // JSplitPane()
-
- /**
- * Constructor JSplitPane
- * @param value0 TODO
- */
- public JSplitPane(int value0) {
- // TODO
- } // JSplitPane()
-
- /**
- * Constructor JSplitPane
- * @param value0 TODO
- * @param value1 TODO
- */
- public JSplitPane(int value0, boolean value1) {
- // TODO
- } // JSplitPane()
-
- /**
- * Constructor JSplitPane
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public JSplitPane(int value0, Component value1, Component value2) {
- // TODO
- } // JSplitPane()
-
- /**
- * Constructor JSplitPane
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- * @param value3 TODO
- */
- public JSplitPane(int value0, boolean value1, Component value2, Component value3) {
- // TODO
- } // JSplitPane()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * writeObject
- * @param stream TODO
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream stream) throws IOException {
- // TODO
- } // writeObject()
-
- /**
- * remove
- * @param value0 TODO
- */
- public void remove(Component value0) {
- // TODO
- } // remove()
-
- /**
- * remove
- * @param value0 TODO
- */
- public void remove(int value0) {
- // TODO
- } // remove()
-
- /**
- * removeAll
- */
- public void removeAll() {
- // TODO
- } // removeAll()
-
- /**
- * setUI
- * @param ui TODO
- */
- public void setUI(SplitPaneUI ui) {
- super.setUI(ui);
- } // setUI()
-
- /**
- * getUI
- * @returns SplitPaneUI
- */
- public SplitPaneUI getUI() {
- return (SplitPaneUI) ui;
- } // getUI()
-
- /**
- * updateUI
- */
- public void updateUI() {
- setUI((SplitPaneUI) UIManager.get(this));
- invalidate();
- } // updateUI()
-
- /**
- * getUIClassID
- * @returns String
- */
- public String getUIClassID() {
- return uiClassID;
- } // getUIClassID()
-
- /**
- * setDividerSize
- * @param value0 TODO
- */
- public void setDividerSize(int value0) {
- // TODO
- } // setDividerSize()
-
- /**
- * getDividerSize
- * @returns int
- */
- public int getDividerSize() {
- return 0; // TODO
- } // getDividerSize()
-
- /**
- * setLeftComponent
- * @param value0 TODO
- */
- public void setLeftComponent(Component value0) {
- // TODO
- } // setLeftComponent()
-
- /**
- * getLeftComponent
- * @returns Component
- */
- public Component getLeftComponent() {
- return null; // TODO
- } // getLeftComponent()
-
- /**
- * setTopComponent
- * @param value0 TODO
- */
- public void setTopComponent(Component value0) {
- // TODO
- } // setTopComponent()
-
- /**
- * getTopComponent
- * @returns Component
- */
- public Component getTopComponent() {
- return null; // TODO
- } // getTopComponent()
-
- /**
- * setRightComponent
- * @param value0 TODO
- */
- public void setRightComponent(Component value0) {
- // TODO
- } // setRightComponent()
-
- /**
- * getRightComponent
- * @returns Component
- */
- public Component getRightComponent() {
- return null; // TODO
- } // getRightComponent()
-
- /**
- * setBottomComponent
- * @param value0 TODO
- */
- public void setBottomComponent(Component value0) {
- // TODO
- } // setBottomComponent()
-
- /**
- * getBottomComponent
- * @returns Component
- */
- public Component getBottomComponent() {
- return null; // TODO
- } // getBottomComponent()
-
- /**
- * setOneTouchExpandable
- * @param value0 TODO
- */
- public void setOneTouchExpandable(boolean value0) {
- // TODO
- } // setOneTouchExpandable()
-
- /**
- * isOneTouchExpandable
- * @returns boolean
- */
- public boolean isOneTouchExpandable() {
- return false; // TODO
- } // isOneTouchExpandable()
-
- /**
- * setLastDividerLocation
- * @param value0 TODO
- */
- public void setLastDividerLocation(int value0) {
- // TODO
- } // setLastDividerLocation()
-
- /**
- * getLastDividerLocation
- * @returns int
- */
- public int getLastDividerLocation() {
- return 0; // TODO
- } // getLastDividerLocation()
-
- /**
- * setOrientation
- * @param value0 TODO
- */
- public void setOrientation(int value0) {
- // TODO
- } // setOrientation()
-
- /**
- * getOrientation
- * @returns int
- */
- public int getOrientation() {
- return 0; // TODO
- } // getOrientation()
-
- /**
- * setContinuousLayout
- * @param value0 TODO
- */
- public void setContinuousLayout(boolean value0) {
- // TODO
- } // setContinuousLayout()
-
- /**
- * isContinuousLayout
- * @returns boolean
- */
- public boolean isContinuousLayout() {
- return false; // TODO
- } // isContinuousLayout()
-
- /**
- * setResizeWeight
- * @param value0 TODO
- */
- public void setResizeWeight(double value0) {
- // TODO
- } // setResizeWeight()
-
- /**
- * getResizeWeight
- * @returns double
- */
- public double getResizeWeight() {
- return 0.0; // TODO
- } // getResizeWeight()
-
- /**
- * resetToPreferredSizes
- */
- public void resetToPreferredSizes() {
- // TODO
- } // resetToPreferredSizes()
-
- /**
- * setDividerLocation
- * @param value0 TODO
- */
- public void setDividerLocation(double value0) {
- // TODO
- } // setDividerLocation()
-
- /**
- * setDividerLocation
- * @param value0 TODO
- */
- public void setDividerLocation(int value0) {
- // TODO
- } // setDividerLocation()
-
- /**
- * getDividerLocation
- * @returns int
- */
- public int getDividerLocation() {
- return 0; // TODO
- } // getDividerLocation()
-
- /**
- * getMinimumDividerLocation
- * @returns int
- */
- public int getMinimumDividerLocation() {
- return 0; // TODO
- } // getMinimumDividerLocation()
-
- /**
- * getMaximumDividerLocation
- * @returns int
- */
- public int getMaximumDividerLocation() {
- return 0; // TODO
- } // getMaximumDividerLocation()
-
- /**
- * isValidateRoot
- * @returns boolean
- */
- public boolean isValidateRoot() {
- return false; // TODO
- } // isValidateRoot()
-
- /**
- * addImpl
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- protected void addImpl(Component value0, Object value1, int value2) {
- // TODO
- } // addImpl()
-
- /**
- * paintChildren
- * @param value0 TODO
- */
- protected void paintChildren(Graphics value0) {
- // TODO
- } // paintChildren()
-
- /**
- * paramString
- * @returns String
- */
- protected String paramString() {
- return null; // TODO
- } // paramString()
-
- /**
- * getAccessibleContext
- * @returns AccessibleContext
- */
- public AccessibleContext getAccessibleContext() {
- if (accessibleContext == null) {
- accessibleContext = new AccessibleJSplitPane(this);
- } // if
- return accessibleContext;
- } // getAccessibleContext()
-
-
-} // JSplitPane
+public class JSplitPane extends JComponent implements Accessible
+{
+ /**
+ * DOCUMENT ME!
+ */
+ protected class AccessibleJSplitPane extends JComponent.AccessibleJComponent
+ implements AccessibleValue
+ {
+ /**
+ * Creates a new AccessibleJSplitPane object.
+ *
+ * @param value0 DOCUMENT ME!
+ */
+ protected AccessibleJSplitPane(JSplitPane value0)
+ {
+ super(value0);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AccessibleStateSet getAccessibleStateSet()
+ {
+ return null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AccessibleValue getAccessibleValue()
+ {
+ return null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Number getCurrentAccessibleValue()
+ {
+ return null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param value0 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean setCurrentAccessibleValue(Number value0)
+ {
+ return false;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Number getMinimumAccessibleValue()
+ {
+ return null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Number getMaximumAccessibleValue()
+ {
+ return null;
+ }
+ }
+
+ /** The constraints string used to add components to the bottom. */
+ public static final String BOTTOM = "bottom";
+
+ /** The property fired when the continuousLayout property changes. */
+ public static final String CONTINUOUS_LAYOUT_PROPERTY = "continuousLayout";
+
+ /** The property fired when the divider property changes. */
+ public static final String DIVIDER = "divider";
+
+ /** The property fired when the divider location property changes. */
+ public static final String DIVIDER_LOCATION_PROPERTY = "dividerLocation";
+
+ /** The property fired when the divider size property changes. */
+ public static final String DIVIDER_SIZE_PROPERTY = "dividerSize";
+
+ /**
+ * The value of the orientation when the components are split horizontally.
+ */
+ public static final int HORIZONTAL_SPLIT = 1;
+
+ /** The property fired when the last divider location property changes. */
+ public static final String LAST_DIVIDER_LOCATION_PROPERTY = "lastDividerLocation";
+
+ /** The constraints string used to add components to the left. */
+ public static final String LEFT = "left";
+
+ /** The property fired when the one touch expandable property changes. */
+ public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = "oneTouchExpandable";
+
+ /** The property fired when the orientation property changes. */
+ public static final String ORIENTATION_PROPERTY = "orientation";
+
+ /** The property fired when the resize weight property changes. */
+ public static final String RESIZE_WEIGHT_PROPERTY = "resizeWeight";
+
+ /** The constraints string used to add components to the right. */
+ public static final String RIGHT = "right";
+
+ /** The constraints string used to add components to the top. */
+ public static final String TOP = "top";
+
+ /** The value of the orientation when the components are split vertically. */
+ public static final int VERTICAL_SPLIT = 0;
+
+ /** Whether the JSplitPane uses continuous layout. */
+ protected boolean continuousLayout;
+
+ /** Whether the JSplitPane uses one touch expandable buttons. */
+ protected boolean oneTouchExpandable = false;
+
+ // This is the master dividerSize variable and sets the BasicSplitPaneDivider one accordingly
+
+ /** The size of the divider. */
+ protected int dividerSize = 10;
+
+ /** The last location of the divider given by the UI. */
+ protected int lastDividerLocation;
+
+ /** The orientation of the JSplitPane. */
+ protected int orientation;
+
+ /** The component on the top or left. */
+ protected Component leftComponent;
+
+ /** The component on the right or bottom. */
+ protected Component rightComponent;
+
+ /** Determines how extra space should be allocated. */
+ private transient double resizeWeight;
+
+ /**
+ * Creates a new JSplitPane object with the given orientation, layout mode,
+ * and left and right components.
+ *
+ * @param newOrientation The orientation to use.
+ * @param newContinuousLayout The layout mode to use.
+ * @param newLeftComponent The left component.
+ * @param newRightComponent The right component.
+ *
+ * @throws IllegalArgumentException DOCUMENT ME!
+ */
+ public JSplitPane(int newOrientation, boolean newContinuousLayout,
+ Component newLeftComponent, Component newRightComponent)
+ {
+ if (newOrientation != HORIZONTAL_SPLIT && newOrientation != VERTICAL_SPLIT)
+ throw new IllegalArgumentException("orientation is invalid.");
+ orientation = newOrientation;
+ continuousLayout = newContinuousLayout;
+ setLeftComponent(newLeftComponent);
+ setRightComponent(newRightComponent);
+
+ updateUI();
+ }
+
+ /**
+ * Creates a new JSplitPane object using nonContinuousLayout mode, the given
+ * orientation and left and right components.
+ *
+ * @param newOrientation The orientation to use.
+ * @param newLeftComponent The left component.
+ * @param newRightComponent The right component.
+ */
+ public JSplitPane(int newOrientation, Component newLeftComponent,
+ Component newRightComponent)
+ {
+ this(newOrientation, false, newLeftComponent, newRightComponent);
+ }
+
+ /**
+ * Creates a new JSplitPane object with the given layout mode and
+ * orientation.
+ *
+ * @param newOrientation The orientation to use.
+ * @param newContinuousLayout The layout mode to use.
+ */
+ public JSplitPane(int newOrientation, boolean newContinuousLayout)
+ {
+ this(newOrientation, newContinuousLayout, null, null);
+ }
+
+ /**
+ * Creates a new JSplitPane object using a nonContinuousLayout mode and the
+ * given orientation.
+ *
+ * @param newOrientation The orientation to use.
+ */
+ public JSplitPane(int newOrientation)
+ {
+ this(newOrientation, false, null, null);
+ }
+
+ /**
+ * Creates a new JSplitPane object using HORIZONTAL_SPLIT and a
+ * nonContinuousLayout mode.
+ */
+ public JSplitPane()
+ {
+ this(HORIZONTAL_SPLIT, false, null, null);
+ }
+
+ /**
+ * This method adds a component to the JSplitPane. The constraints object is
+ * a string that identifies where this component should go. If the
+ * constraints is not a known one, it will throw an
+ * IllegalArgumentException. The valid constraints are LEFT, TOP, RIGHT,
+ * BOTTOM and DIVIDER.
+ *
+ * @param comp The component to add.
+ * @param constraints The constraints string to use.
+ * @param index Where to place to component in the list of components.
+ *
+ * @throws IllegalArgumentException When the constraints is not a known identifier.
+ */
+ protected void addImpl(Component comp, Object constraints, int index)
+ {
+ int left = 0;
+ int right = 1;
+ int div = 2;
+ int place;
+ if (constraints == null)
+ {
+ if (leftComponent == null)
+ constraints = LEFT;
+ else if (rightComponent == null)
+ constraints = RIGHT;
+ }
+
+ if (constraints instanceof String)
+ {
+ String placement = (String) constraints;
+
+ if (placement.equals(BOTTOM) || placement.equals(RIGHT))
+ {
+ if (rightComponent != null)
+ remove(rightComponent);
+ rightComponent = comp;
+ }
+ else if (placement.equals(LEFT) || placement.equals(TOP))
+ {
+ if (leftComponent != null)
+ remove(leftComponent);
+ leftComponent = comp;
+ }
+ else if (placement.equals(DIVIDER))
+ constraints = null;
+ else
+ throw new IllegalArgumentException("Constraints is not a known identifier.");
+
+ super.addImpl(comp, constraints, index);
+ }
+ invalidate();
+ layout();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ if (accessibleContext == null)
+ accessibleContext = new AccessibleJSplitPane(this);
+ return accessibleContext;
+ }
+
+ /**
+ * This method returns the bottom component.
+ *
+ * @return The bottom component.
+ */
+ public Component getBottomComponent()
+ {
+ return rightComponent;
+ }
+
+ /**
+ * This method returns the location of the divider. This method is passed to
+ * the UI.
+ *
+ * @return The location of the divider.
+ */
+ public int getDividerLocation()
+ {
+ if (ui != null)
+ return ((SplitPaneUI) ui).getDividerLocation(this);
+ else
+ return -1;
+ }
+
+ /**
+ * This method returns the size of the divider.
+ *
+ * @return The size of the divider.
+ */
+ public int getDividerSize()
+ {
+ return dividerSize;
+ }
+
+ /**
+ * This method returns the last divider location.
+ *
+ * @return The last divider location.
+ */
+ public int getLastDividerLocation()
+ {
+ return lastDividerLocation;
+ }
+
+ /**
+ * This method returns the left component.
+ *
+ * @return The left component.
+ */
+ public Component getLeftComponent()
+ {
+ return leftComponent;
+ }
+
+ /**
+ * This method returns the maximum divider location. This method is passed
+ * to the UI.
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getMaximumDividerLocation()
+ {
+ if (ui != null)
+ return ((SplitPaneUI) ui).getMaximumDividerLocation(this);
+ else
+ return -1;
+ }
+
+ /**
+ * This method returns the minimum divider location. This method is passed
+ * to the UI.
+ *
+ * @return The minimum divider location.
+ */
+ public int getMinimumDividerLocation()
+ {
+ if (ui != null)
+ return ((SplitPaneUI) ui).getMinimumDividerLocation(this);
+ else
+ return -1;
+ }
+
+ /**
+ * This method returns the orientation that the JSplitPane is using.
+ *
+ * @return The current orientation.
+ */
+ public int getOrientation()
+ {
+ return orientation;
+ }
+
+ /**
+ * This method returns the current resize weight.
+ *
+ * @return The current resize weight.
+ */
+ public double getResizeWeight()
+ {
+ return resizeWeight;
+ }
+
+ /**
+ * This method returns the right component.
+ *
+ * @return The right component.
+ */
+ public Component getRightComponent()
+ {
+ return rightComponent;
+ }
+
+ /**
+ * This method returns the top component.
+ *
+ * @return The top component.
+ */
+ public Component getTopComponent()
+ {
+ return leftComponent;
+ }
+
+ /**
+ * This method returns the UI.
+ *
+ * @return The UI.
+ */
+ public SplitPaneUI getUI()
+ {
+ return (SplitPaneUI) ui;
+ }
+
+ /**
+ * This method returns true if the JSplitPane is using a continuousLayout.
+ *
+ * @return True if using a continuousLayout.
+ */
+ public boolean isContinuousLayout()
+ {
+ return continuousLayout;
+ }
+
+ /**
+ * This method returns true if the divider has one touch expandable buttons.
+ *
+ * @return True if one touch expandable is used.
+ */
+ public boolean isOneTouchExpandable()
+ {
+ return oneTouchExpandable;
+ }
+
+ /**
+ * This method returns true.
+ *
+ * @return true.
+ */
+ public boolean isValidateRoot()
+ {
+ return true;
+ }
+
+ /**
+ * This method overrides JComponent's paintChildren so the UI can be
+ * messaged when the children have finished painting.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ protected void paintChildren(Graphics g)
+ {
+ super.paintChildren(g);
+ if (ui != null)
+ ((SplitPaneUI) ui).finishedPaintingChildren(this, g);
+ }
+
+ /**
+ * This method returns a String that describes this JSplitPane. The string
+ * is primarily used for debugging purposes.
+ *
+ * @return A String used for debugging purposes.
+ */
+ protected String paramString()
+ {
+ return "JSplitPane";
+ }
+
+ /**
+ * This method removes the given component from the JSplitPane.
+ *
+ * @param component The Component to remove.
+ */
+ public void remove(Component component)
+ {
+ if (component == leftComponent)
+ leftComponent = null;
+ else if (component == rightComponent)
+ rightComponent = null;
+ super.remove(component);
+ }
+
+ /**
+ * This method removes the component at the given index.
+ *
+ * @param index The index of the component to remove.
+ */
+ public void remove(int index)
+ {
+ Component component = getComponentAt(index);
+ if (component == leftComponent)
+ leftComponent = null;
+ else if (component == rightComponent)
+ rightComponent = null;
+ super.remove(index);
+ }
+
+ /**
+ * This method removes all components from the JSplitPane.
+ */
+ public void removeAll()
+ {
+ leftComponent = null;
+ rightComponent = null;
+ super.removeAll();
+ }
+
+ /**
+ * This method resets all children of the JSplitPane to their preferred
+ * sizes.
+ */
+ public void resetToPreferredSizes()
+ {
+ if (ui != null)
+ ((SplitPaneUI) ui).resetToPreferredSizes(this);
+ }
+
+ /**
+ * This method sets the bottom component.
+ *
+ * @param comp The Component to be placed at the bottom.
+ */
+ public void setBottomComponent(Component comp)
+ {
+ if (comp != null)
+ add(comp, BOTTOM);
+ else
+ add(new JButton("right button"), BOTTOM);
+ }
+
+ /**
+ * This method sets the layout mode for the JSplitPane.
+ *
+ * @param newContinuousLayout Whether the JSplitPane is in continuousLayout
+ * mode.
+ */
+ public void setContinuousLayout(boolean newContinuousLayout)
+ {
+ if (newContinuousLayout != continuousLayout)
+ {
+ boolean oldValue = continuousLayout;
+ continuousLayout = newContinuousLayout;
+ firePropertyChange(CONTINUOUS_LAYOUT_PROPERTY, oldValue,
+ continuousLayout);
+ }
+ }
+
+ /**
+ * This method sets the location of the divider. A value of 0 sets the
+ * divider to the farthest left. A value of 1 sets the divider to the
+ * farthest right.
+ *
+ * @param proportionalLocation A double that describes the location of the
+ * divider.
+ *
+ * @throws IllegalArgumentException DOCUMENT ME!
+ */
+ public void setDividerLocation(double proportionalLocation)
+ {
+ if (proportionalLocation > 1 || proportionalLocation < 0)
+ throw new IllegalArgumentException("proportion has to be between 0 and 1.");
+
+ int max = (orientation == HORIZONTAL_SPLIT) ? getWidth() : getHeight();
+ setDividerLocation((int) (proportionalLocation * max));
+ }
+
+ /**
+ * This method sets the location of the divider.
+ *
+ * @param location The location of the divider.
+ */
+ public void setDividerLocation(int location)
+ {
+ if (ui != null && location != getDividerLocation())
+ {
+ int oldLocation = getDividerLocation();
+ ((SplitPaneUI) ui).setDividerLocation(this, location);
+ firePropertyChange(DIVIDER_LOCATION_PROPERTY, oldLocation, location);
+ }
+ }
+
+ /**
+ * This method sets the size of the divider.
+ *
+ * @param newSize The size of the divider.
+ */
+ public void setDividerSize(int newSize)
+ {
+ if (newSize != dividerSize)
+ {
+ int oldSize = dividerSize;
+ dividerSize = newSize;
+ firePropertyChange(DIVIDER_SIZE_PROPERTY, oldSize, dividerSize);
+ }
+ }
+
+ // This doesn't appear to do anything when set from user side.
+ // so it probably is only used from the UI side to change the
+ // lastDividerLocation var.
+
+ /**
+ * This method sets the last location of the divider.
+ *
+ * @param newLastLocation The last location of the divider.
+ */
+ public void setLastDividerLocation(int newLastLocation)
+ {
+ if (newLastLocation != lastDividerLocation)
+ {
+ int oldValue = lastDividerLocation;
+ lastDividerLocation = newLastLocation;
+ firePropertyChange(LAST_DIVIDER_LOCATION_PROPERTY, oldValue,
+ lastDividerLocation);
+ }
+ }
+
+ /**
+ * This method sets the left component.
+ *
+ * @param comp The left component.
+ */
+ public void setLeftComponent(Component comp)
+ {
+ if (comp != null)
+ add(comp, LEFT);
+ else
+ add(new JButton("left button"), LEFT);
+ }
+
+ /**
+ * This method sets whether the divider has one touch expandable buttons.
+ * The one touch expandable buttons can expand the size of either component
+ * to the maximum allowed size.
+ *
+ * @param newValue Whether the divider will have one touch expandable
+ * buttons.
+ */
+ public void setOneTouchExpandable(boolean newValue)
+ {
+ if (newValue != oneTouchExpandable)
+ {
+ boolean oldValue = oneTouchExpandable;
+ oneTouchExpandable = newValue;
+ firePropertyChange(ONE_TOUCH_EXPANDABLE_PROPERTY, oldValue,
+ oneTouchExpandable);
+ }
+ }
+
+ /**
+ * This method sets the orientation of the JSplitPane.
+ *
+ * @param orientation The orientation of the JSplitPane.
+ *
+ * @throws IllegalArgumentException DOCUMENT ME!
+ */
+ public void setOrientation(int orientation)
+ {
+ if (orientation != HORIZONTAL_SPLIT && orientation != VERTICAL_SPLIT)
+ throw new IllegalArgumentException("orientation must be one of VERTICAL_SPLIT, HORIZONTAL_SPLIT");
+ if (orientation != this.orientation)
+ {
+ int oldOrientation = this.orientation;
+ this.orientation = orientation;
+ firePropertyChange(ORIENTATION_PROPERTY, oldOrientation,
+ this.orientation);
+ }
+ }
+
+ /**
+ * This method determines how extra space will be distributed among the left
+ * and right components. A value of 0 will allocate all extra space to the
+ * right component. A value of 1 indicates that all extra space will go to
+ * the left component. A value in between 1 and 0 will split the space
+ * accordingly.
+ *
+ * @param value The resize weight.
+ */
+ public void setResizeWeight(double value)
+ {
+ resizeWeight = value;
+ }
+
+ /**
+ * This method sets the right component.
+ *
+ * @param comp The right component.
+ */
+ public void setRightComponent(Component comp)
+ {
+ if (comp != null)
+ add(comp, RIGHT);
+ else
+ add(new JButton("right button"), RIGHT);
+ }
+
+ /**
+ * This method sets the top component.
+ *
+ * @param comp The top component.
+ */
+ public void setTopComponent(Component comp)
+ {
+ if (comp != null)
+ add(comp, TOP);
+ else
+ add(new JButton("left button"), TOP);
+ }
+
+ /**
+ * This method sets the UI used by the JSplitPane.
+ *
+ * @param ui The UI to use.
+ */
+ public void setUI(SplitPaneUI ui)
+ {
+ super.setUI(ui);
+ }
+
+ /**
+ * This method resets the UI to the one specified by the current Look and
+ * Feel.
+ */
+ public void updateUI()
+ {
+ setUI((SplitPaneUI) UIManager.getUI(this));
+ invalidate();
+ repaint();
+ }
+
+ /**
+ * This method returns a string identifier to determine which UI class it
+ * needs.
+ *
+ * @return A string that identifies it's UI class.
+ */
+ public String getUIClassID()
+ {
+ return "SplitPaneUI";
+ }
+}
Index: javax/swing/plaf/basic/BasicLookAndFeel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java,v
retrieving revision 1.4.2.7
diff -u -r1.4.2.7 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java 29 Mar 2004 17:19:43 -0000 1.4.2.7
+++ javax/swing/plaf/basic/BasicLookAndFeel.java 19 Apr 2004 19:22:48 -0000
@@ -694,7 +694,7 @@
}),
"SplitPane.background", new ColorUIResource(Color.lightGray),
"SplitPane.border", new BasicBorders.SplitPaneBorder(null, null),
- "SplitPane.dividerSize", new Integer(7),
+ "SplitPane.dividerSize", new Integer(10),
"SplitPane.highlight", new ColorUIResource(Color.white),
"SplitPane.shadow", new ColorUIResource(Color.gray),
"TabbedPane.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] {
Index: javax/swing/plaf/basic/BasicScrollBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicScrollBarUI.java,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 BasicScrollBarUI.java
--- javax/swing/plaf/basic/BasicScrollBarUI.java 22 Mar 2004 23:38:20 -0000 1.1.2.3
+++ javax/swing/plaf/basic/BasicScrollBarUI.java 19 Apr 2004 19:22:48 -0000
@@ -1047,14 +1047,6 @@
public void paint(Graphics g, JComponent c)
{
layoutContainer(scrollbar);
-
-// Rectangle r = incrButton.getBounds();
-// SwingUtilities.paintComponent(g, incrButton, scrollbar, r.x, r.y, r.width,
-// r.height);
-// r = decrButton.getBounds();
-// SwingUtilities.paintComponent(g, decrButton, scrollbar, r.x, r.y, r.width,
-// r.height);
-
paintTrack(g, c, getTrackBounds());
paintThumb(g, c, getThumbBounds());
Index: javax/swing/plaf/basic/BasicSplitPaneDivider.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicSplitPaneDivider.java,v
retrieving revision 1.1
diff -u -r1.1 BasicSplitPaneDivider.java
--- javax/swing/plaf/basic/BasicSplitPaneDivider.java 24 Jun 2003 09:48:42 -0000 1.1
+++ javax/swing/plaf/basic/BasicSplitPaneDivider.java 19 Apr 2004 19:22:49 -0000
@@ -1,5 +1,5 @@
/* BasicSplitPaneDivider.java
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,14 +35,15 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing.plaf.basic;
+import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
+import java.awt.LayoutManager;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
@@ -50,173 +51,173 @@
import java.beans.PropertyChangeListener;
import javax.swing.JButton;
import javax.swing.JSplitPane;
+import javax.swing.SwingConstants;
import javax.swing.border.Border;
/**
- * The divider that separates the two parts of a JSplitPane in the
- * Basic look and feel.
- *
- * <p>Implementation status: We do not have a real implementation yet.
- * Currently, it is mostly a stub to allow compiling other parts of
- * the javax.swing.plaf.basic package, although some parts are already
+ * The divider that separates the two parts of a JSplitPane in the Basic look
+ * and feel.
+ *
+ * <p>
+ * Implementation status: We do not have a real implementation yet. Currently,
+ * it is mostly a stub to allow compiling other parts of the
+ * javax.swing.plaf.basic package, although some parts are already
* functional.
+ * </p>
*
- * @author Sascha Brawer (brawer@dandelis.ch)
+ * @author Sascha Brawer (brawer_AT_dandelis.ch)
*/
-public class BasicSplitPaneDivider
- extends Container
+public class BasicSplitPaneDivider extends Container
implements PropertyChangeListener
{
/**
- * Determined using the <code>serialver</code> tool
- * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
+ * Determined using the <code>serialver</code> tool of Apple/Sun JDK 1.3.1
+ * on MacOS X 10.1.5.
*/
static final long serialVersionUID = 1463404307042803342L;
-
/**
- * The width and height of the little buttons for showing and
- * hiding parts of a JSplitPane in a single mouse click.
+ * The width and height of the little buttons for showing and hiding parts
+ * of a JSplitPane in a single mouse click.
*/
protected static final int ONE_TOUCH_SIZE = 6;
-
- // FIXME: Javadoc.
+ /** The distance the one touch buttons will sit from the divider's edges. */
protected static final int ONE_TOUCH_OFFSET = 2;
-
/**
* An object that performs the tasks associated with an ongoing drag
- * operation, or <code>null</code> if the user is currently not
- * dragging the divider.
+ * operation, or <code>null</code> if the user is currently not dragging
+ * the divider.
*/
protected DragController dragger;
-
/**
* The delegate object that is responsible for the UI of the
* <code>JSplitPane</code> that contains this divider.
*/
protected BasicSplitPaneUI splitPaneUI;
-
- /**
- * The thickness of the divider in pixels.
- */
+ /** The thickness of the divider in pixels. */
protected int dividerSize;
-
- /**
- * A divider that is used for layout purposes.
- */
+ /** A divider that is used for layout purposes. */
protected Component hiddenDivider;
-
- /**
- * The JSplitPane containing this divider.
- */
+ /** The JSplitPane containing this divider. */
protected JSplitPane splitPane;
-
/**
- * The listener for handling mouse events from both the divider
- * and the containing <code>JSplitPane</code>.
- *
- * <p>The reason for also handling MouseEvents from the containing
- * <code>JSplitPane</code> is that users should be able to start
- * a drag gesture from inside the JSplitPane, but slightly outisde
- * the divider.
+ * The listener for handling mouse events from both the divider and the
+ * containing <code>JSplitPane</code>.
+ *
+ * <p>
+ * The reason for also handling MouseEvents from the containing
+ * <code>JSplitPane</code> is that users should be able to start a drag
+ * gesture from inside the JSplitPane, but slightly outisde the divider.
+ * </p>
*/
protected MouseHandler mouseHandler = new MouseHandler();
-
/**
- * The current orientation of the containing <code>JSplitPane</code>,
- * which is either {@link javax.swing.JSplitPane#HORIZONTAL_SPLIT}
- * or {@link javax.swing.JSplitPane#VERTICAL_SPLIT}.
+ * The current orientation of the containing <code>JSplitPane</code>, which
+ * is either {@link javax.swing.JSplitPane#HORIZONTAL_SPLIT} or {@link
+ * javax.swing.JSplitPane#VERTICAL_SPLIT}.
*/
protected int orientation;
-
/**
- * The button for showing and hiding the left (or top) component
- * of the <code>JSplitPane</code>.
+ * The button for showing and hiding the left (or top) component of the
+ * <code>JSplitPane</code>.
*/
protected JButton leftButton;
-
/**
- * The button for showing and hiding the right (or bottom) component
- * of the <code>JSplitPane</code>.
+ * The button for showing and hiding the right (or bottom) component of the
+ * <code>JSplitPane</code>.
*/
protected JButton rightButton;
-
/**
- * The border of this divider. Typically, this will be an instance of
- * {@link javax.swing.plaf.basic.BasicBorders.SplitPaneDividerBorder}.
+ * The border of this divider. Typically, this will be an instance of {@link
+ * javax.swing.plaf.basic.BasicBorders.SplitPaneDividerBorder}.
*
* @see #getBorder()
* @see #setBorder(javax.swing.border.Border)
*/
private Border border;
+ // This is not a pixel count.
+ // This int should be able to take 3 values.
+ // left (top), middle, right(bottom)
+ // 0 1 2
+
+ /** Keeps track of where the divider should be placed when using one touch expand
+ * buttons. */
+ private transient int currentDividerLocation = 1;
/**
* Constructs a new divider.
*
- * @param ui the UI delegate of the enclosing
- * <code>JSplitPane</code>.
+ * @param ui the UI delegate of the enclosing <code>JSplitPane</code>.
*/
public BasicSplitPaneDivider(BasicSplitPaneUI ui)
{
+ setLayout(new DividerLayout());
setBasicSplitPaneUI(ui);
+ setDividerSize(splitPane.getDividerSize());
}
-
/**
- * Sets the delegate object that is responsible for the UI of the
- * {@link javax.swing.JSplitPane} containing this divider.
+ * Sets the delegate object that is responsible for the UI of the {@link
+ * javax.swing.JSplitPane} containing this divider.
*
- * @param newUI the UI delegate, or <code>null</code> to release
- * the connection to the current delegate.
+ * @param newUI the UI delegate, or <code>null</code> to release the
+ * connection to the current delegate.
*/
public void setBasicSplitPaneUI(BasicSplitPaneUI newUI)
{
/* Remove the connection to the existing JSplitPane. */
if (splitPane != null)
- {
- splitPane.removePropertyChangeListener(this);
- splitPane.removeMouseListener(mouseHandler);
- splitPane.removeMouseMotionListener(mouseHandler);
- splitPane = null;
- }
-
+ {
+ splitPane.removePropertyChangeListener(this);
+ splitPane.removeMouseListener(mouseHandler);
+ splitPane.removeMouseMotionListener(mouseHandler);
+ removeMouseListener(mouseHandler);
+ removeMouseMotionListener(mouseHandler);
+ splitPane = null;
+ hiddenDivider = null;
+ }
+
/* Establish the connection to the new JSplitPane. */
splitPaneUI = newUI;
if (splitPaneUI != null)
splitPane = newUI.getSplitPane();
if (splitPane != null)
- {
- splitPane.addPropertyChangeListener(this);
- splitPane.addMouseListener(mouseHandler);
- splitPane.addMouseMotionListener(mouseHandler);
- orientation = splitPane.getOrientation();
- }
+ {
+ splitPane.addPropertyChangeListener(this);
+ splitPane.addMouseListener(mouseHandler);
+ splitPane.addMouseMotionListener(mouseHandler);
+ addMouseListener(mouseHandler);
+ addMouseMotionListener(mouseHandler);
+ hiddenDivider = splitPaneUI.getNonContinuousLayoutDivider();
+ orientation = splitPane.getOrientation();
+ oneTouchExpandableChanged();
+ }
}
-
/**
- * Returns the delegate object that is responsible for the UI of the
- * {@link javax.swing.JSplitPane} containing this divider.
+ * Returns the delegate object that is responsible for the UI of the {@link
+ * javax.swing.JSplitPane} containing this divider.
+ *
+ * @return The UI for the JSplitPane.
*/
public BasicSplitPaneUI getBasicSplitPaneUI()
{
return splitPaneUI;
}
-
/**
* Sets the thickness of the divider.
*
@@ -227,37 +228,40 @@
this.dividerSize = newSize;
}
-
/**
* Retrieves the thickness of the divider.
+ *
+ * @return The thickness of the divider.
*/
public int getDividerSize()
{
return dividerSize;
}
-
-
+
/**
* Sets the border of this divider.
*
* @param border the new border. Typically, this will be an instance of
- * {@link javax.swing.plaf.basic.BasicBorders.SplitPaneDividerBorder}.
+ * {@link
+ * javax.swing.plaf.basic.BasicBorders.SplitPaneDividerBorder}.
*
* @since 1.3
*/
public void setBorder(Border border)
{
- Border oldValue = this.border;
- this.border = border;
- firePropertyChange("border", oldValue, border);
+ if (border != this.border)
+ {
+ Border oldValue = this.border;
+ this.border = border;
+ firePropertyChange("border", oldValue, border);
+ }
}
-
/**
* Retrieves the border of this divider.
*
- * @return the current border, or <code>null</code> if no border
- * has been set.
+ * @return the current border, or <code>null</code> if no border has been
+ * set.
*
* @since 1.3
*/
@@ -265,13 +269,12 @@
{
return border;
}
-
/**
- * Retrieves the insets of the divider. If a border has been
- * installed on the divider, the result of calling its
- * <code>getBorderInsets</code> method is returned. Otherwise,
- * the inherited implementation will be invoked.
+ * Retrieves the insets of the divider. If a border has been installed on
+ * the divider, the result of calling its <code>getBorderInsets</code>
+ * method is returned. Otherwise, the inherited implementation will be
+ * invoked.
*
* @see javax.swing.border.Border#getBorderInsets(java.awt.Component)
*/
@@ -282,42 +285,56 @@
else
return super.getInsets();
}
-
-
+
/**
* Returns the preferred size of this divider, which is
- * <code>dividerSize</code> by <code>dividerSize</code>
- * pixels.
+ * <code>dividerSize</code> by <code>dividerSize</code> pixels.
+ *
+ * @return The preferred size of the divider.
*/
public Dimension getPreferredSize()
{
- return new Dimension(dividerSize, dividerSize);
+ return getLayout().preferredLayoutSize(this);
}
-
/**
* Returns the minimal size of this divider, which is
- * <code>dividerSize</code> by <code>dividerSize</code>
- * pixels.
+ * <code>dividerSize</code> by <code>dividerSize</code> pixels.
+ *
+ * @return The minimal size of the divider.
*/
public Dimension getMinimumSize()
{
return getPreferredSize();
}
-
-
+
/**
- * Processes events from the <code>JSplitPane</code> that contains
- * this divider.
+ * Processes events from the <code>JSplitPane</code> that contains this
+ * divider.
+ *
+ * @param e The PropertyChangeEvent.
*/
public void propertyChange(PropertyChangeEvent e)
{
- // FIXME: Not yet implemented.
+ if (e.getPropertyName().equals(JSplitPane.ONE_TOUCH_EXPANDABLE_PROPERTY))
+ oneTouchExpandableChanged();
+ else if (e.getPropertyName().equals(JSplitPane.ORIENTATION_PROPERTY))
+ {
+ orientation = splitPane.getOrientation();
+ if (splitPane.isOneTouchExpandable())
+ {
+ layout();
+ repaint();
+ }
+ }
+ else if (e.getPropertyName().equals(JSplitPane.DIVIDER_SIZE_PROPERTY))
+ dividerSize = splitPane.getDividerSize();
}
-
/**
* Paints the divider by painting its border.
+ *
+ * @param g The Graphics Object to paint with.
*/
public void paint(Graphics g)
{
@@ -325,50 +342,85 @@
super.paint(g);
if (border != null)
- {
- dividerSize = getSize();
- border.paintBorder(this, g, 0, 0, dividerSize.width, dividerSize.height);
- //System.out.println(dividerSize);
- //g.setColor(java.awt.Color.white);
- //g.drawRect(0, 0, 5, 5);
- }
+ {
+ dividerSize = getSize();
+ border.paintBorder(this, g, 0, 0, dividerSize.width, dividerSize.height);
+ }
}
-
/**
- * Reacts to changes of the <code>oneToughExpandable</code>
- * property of the containing <code>JSplitPane</code>.
+ * Reacts to changes of the <code>oneToughExpandable</code> property of the
+ * containing <code>JSplitPane</code>.
*/
protected void oneTouchExpandableChanged()
{
- // FIXME: Not yet implemented.
+ if (splitPane.isOneTouchExpandable())
+ {
+ leftButton = createLeftOneTouchButton();
+ rightButton = createRightOneTouchButton();
+ add(leftButton);
+ add(rightButton);
+
+ leftButton.addMouseListener(mouseHandler);
+ rightButton.addMouseListener(mouseHandler);
+
+ // Set it to 1.
+ currentDividerLocation = 1;
+ }
+ else
+ {
+ if (leftButton != null && rightButton != null)
+ {
+ leftButton.removeMouseListener(mouseHandler);
+ rightButton.removeMouseListener(mouseHandler);
+
+ remove(leftButton);
+ remove(rightButton);
+ leftButton = null;
+ rightButton = null;
+ }
+ }
+ layout();
+ repaint();
}
-
/**
- * Creates a button for showing and hiding the left (or top)
- * part of a <code>JSplitPane</code>.
+ * Creates a button for showing and hiding the left (or top) part of a
+ * <code>JSplitPane</code>.
+ *
+ * @return The left one touch button.
*/
protected JButton createLeftOneTouchButton()
{
- return new OneTouchButton(/* left */ true);
- }
+ int dir = SwingConstants.WEST;
+ if (orientation == JSplitPane.VERTICAL_SPLIT)
+ dir = SwingConstants.NORTH;
+ JButton button = new BasicArrowButton(dir);
+ button.setBorderPainted(false);
+ return button;
+ }
/**
- * Creates a button for showing and hiding the right (or bottom)
- * part of a <code>JSplitPane</code>.
+ * Creates a button for showing and hiding the right (or bottom) part of a
+ * <code>JSplitPane</code>.
+ *
+ * @return The right one touch button.
*/
protected JButton createRightOneTouchButton()
{
- return new OneTouchButton(/* left */ false);
+ int dir = SwingConstants.EAST;
+ if (orientation == JSplitPane.VERTICAL_SPLIT)
+ dir = SwingConstants.SOUTH;
+ JButton button = new BasicArrowButton(dir);
+ button.setBorderPainted(false);
+ return button;
}
-
/**
* Prepares the divider for dragging by calling the
- * <code>startDragging</code> method of the UI delegate of the
- * enclosing <code>JSplitPane</code>.
+ * <code>startDragging</code> method of the UI delegate of the enclosing
+ * <code>JSplitPane</code>.
*
* @see BasicSplitPaneUI#startDragging()
*/
@@ -378,15 +430,14 @@
splitPaneUI.startDragging();
}
-
/**
* Drags the divider to a given location by calling the
- * <code>dragDividerTo</code> method of the UI delegate of the
- * enclosing <code>JSplitPane</code>.
+ * <code>dragDividerTo</code> method of the UI delegate of the enclosing
+ * <code>JSplitPane</code>.
*
* @param location the new location of the divider.
*
- * @see BasicSplitPaneUI#dragDividerTo(int location)
+ * @see BasicSplitPaneUI#dragDividerTo(int location)
*/
protected void dragDividerTo(int location)
{
@@ -394,11 +445,9 @@
splitPaneUI.dragDividerTo(location);
}
-
/**
- * Finishes a dragging gesture by calling the
- * <code>finishDraggingTo</code> method of the UI delegate of the
- * enclosing <code>JSplitPane</code>.
+ * Finishes a dragging gesture by calling the <code>finishDraggingTo</code>
+ * method of the UI delegate of the enclosing <code>JSplitPane</code>.
*
* @param location the new, final location of the divider.
*
@@ -410,125 +459,425 @@
splitPaneUI.finishDraggingTo(location);
}
+ /**
+ * This helper method moves the divider to one of the
+ * three locations when using one touch expand buttons.
+ * Location 0 is the left (or top) most location.
+ * Location 1 is the middle.
+ * Location 2 is the right (or bottom) most location.
+ *
+ * @param locationIndex The location to move to.
+ */
+ private void moveDividerTo(int locationIndex)
+ {
+ Insets insets = splitPane.getInsets();
+ switch (locationIndex)
+ {
+ case 1:
+ splitPane.setDividerLocation(splitPane.getLastDividerLocation());
+ break;
+ case 0:
+ int top = (orientation == JSplitPane.HORIZONTAL_SPLIT) ? insets.left
+ : insets.top;
+ splitPane.setDividerLocation(top);
+ break;
+ case 2:
+ int bottom;
+ if (orientation == JSplitPane.HORIZONTAL_SPLIT)
+ bottom = splitPane.getBounds().width - insets.right - dividerSize;
+ else
+ bottom = splitPane.getBounds().height - insets.bottom - dividerSize;
+ splitPane.setDividerLocation(bottom);
+ break;
+ }
+ }
/**
- * The listener for handling mouse events from both the divider
- * and the containing <code>JSplitPane</code>.
- *
- * <p>The reason for also handling MouseEvents from the containing
- * <code>JSplitPane</code> is that users should be able to start
- * a drag gesture from inside the JSplitPane, but slightly outisde
- * the divider.
+ * The listener for handling mouse events from both the divider and the
+ * containing <code>JSplitPane</code>.
+ *
+ * <p>
+ * The reason for also handling MouseEvents from the containing
+ * <code>JSplitPane</code> is that users should be able to start a drag
+ * gesture from inside the JSplitPane, but slightly outisde the divider.
+ * </p>
*
- * @author Sascha Brawer (brawer@dandelis.ch)
+ * @author Sascha Brawer (brawer_AT_dandelis.ch)
*/
- protected class MouseHandler
- extends MouseAdapter
+ protected class MouseHandler extends MouseAdapter
implements MouseMotionListener
{
-
+ /** Keeps track of whether a drag is occurring. */
+ private transient boolean isDragging;
+
+ /**
+ * This method is called when the mouse is pressed.
+ *
+ * @param e The MouseEvent.
+ */
public void mousePressed(MouseEvent e)
{
- // FIXME: Not yet implemented.
+ if (splitPane.isOneTouchExpandable())
+ {
+ if (e.getSource() == leftButton)
+ {
+ currentDividerLocation--;
+ if (currentDividerLocation < 0)
+ currentDividerLocation = 0;
+ moveDividerTo(currentDividerLocation);
+ return;
+ }
+ else if (e.getSource() == rightButton)
+ {
+ currentDividerLocation++;
+ if (currentDividerLocation > 2)
+ currentDividerLocation = 2;
+ moveDividerTo(currentDividerLocation);
+ return;
+ }
+ }
+ isDragging = true;
+ currentDividerLocation = 1;
+ if (orientation == JSplitPane.HORIZONTAL_SPLIT)
+ dragger = new DragController(e);
+ else
+ dragger = new VerticalDragController(e);
+ prepareForDragging();
}
-
+ /**
+ * This method is called when the mouse is released.
+ *
+ * @param e The MouseEvent.
+ */
public void mouseReleased(MouseEvent e)
{
- // FIXME: Not yet implemented.
+ if (isDragging)
+ dragger.completeDrag(e);
+ isDragging = false;
}
-
/**
- * Repeatedly invoked when the user is dragging the mouse cursor
- * while having pressed a mouse button.
+ * Repeatedly invoked when the user is dragging the mouse cursor while
+ * having pressed a mouse button.
+ *
+ * @param e The MouseEvent.
*/
public void mouseDragged(MouseEvent e)
{
- // FIXME: Not yet implemented.
+ if (dragger != null)
+ dragger.continueDrag(e);
}
-
/**
- * Repeatedly invoked when the user is dragging the mouse cursor
- * without having pressed a mouse button.
+ * Repeatedly invoked when the user is dragging the mouse cursor without
+ * having pressed a mouse button.
+ *
+ * @param e The MouseEvent.
*/
public void mouseMoved(MouseEvent e)
{
- // FIXME: Not yet implemented.
+ // Do nothing.
}
}
-
/**
- * A small button for showing and hiding parts of a
- * <code>JSplitPane</code> with a single mouse click.
+ * Performs the tasks associated with an ongoing drag operation.
*
- * @author Sascha Brawer (brawer@dandelis.ch)
+ * @author Sascha Brawer (brawer_AT_dandelis.ch)
*/
- private static class OneTouchButton
- extends JButton
+ protected class DragController
{
- OneTouchButton(boolean left)
+ /** The difference between where the mouse is clicked and the
+ * initial divider location. */
+ transient int offset;
+
+ /**
+ * Creates a new DragController object.
+ *
+ * @param e The MouseEvent to initialize with.
+ */
+ protected DragController(MouseEvent e)
{
- // FIXME: Set various properties of the button.
- // Make sure it looks identical to the small
- // buttons of the Sun reference implementation.
- // The size should also be the same.
- if (left)
- setText("<");
- else
- setText(">");
+ offset = e.getX();
+ }
- Dimension butSize = new Dimension(ONE_TOUCH_SIZE, ONE_TOUCH_SIZE);
- setMinimumSize(butSize);
- setMaximumSize(butSize);
- setPreferredSize(butSize);
+ /**
+ * This method returns true if the divider can move.
+ *
+ * @return True if dragging is allowed.
+ */
+ protected boolean isValid()
+ {
+ // Views can always be resized?
+ return true;
+ }
- setBorderPainted(false);
+ /**
+ * Returns a position for the divider given the MouseEvent.
+ *
+ * @param e MouseEvent.
+ *
+ * @return The position for the divider to move to.
+ */
+ protected int positionForMouseEvent(MouseEvent e)
+ {
+ return e.getX() + getX() - offset;
+ ;
}
- }
+ /**
+ * This method returns one of the two paramters
+ * for the orientation. In this case, it returns x.
+ *
+ * @param x The x coordinate.
+ * @param y The y coordinate.
+ *
+ * @return The x coordinate.
+ */
+ protected int getNeededLocation(int x, int y)
+ {
+ return x;
+ }
+
+ /**
+ * This method is called to pass on the drag information
+ * to the UI through dragDividerTo.
+ *
+ * @param newX The x coordinate of the MouseEvent.
+ * @param newY The y coordinate of the MouseEvent.
+ */
+ protected void continueDrag(int newX, int newY)
+ {
+ if (isValid())
+ dragDividerTo(adjust(x, y));
+ }
+
+ /**
+ * This method is called to pass on the drag information
+ * to the UI through dragDividerTo.
+ *
+ * @param e The MouseEvent.
+ */
+ protected void continueDrag(MouseEvent e)
+ {
+ if (isValid())
+ dragDividerTo(positionForMouseEvent(e));
+ }
+
+ /**
+ * This method is called to finish the drag session
+ * by calling finishDraggingTo.
+ *
+ * @param x The x coordinate of the MouseEvent.
+ * @param y The y coordinate of the MouseEvent.
+ */
+ protected void completeDrag(int x, int y)
+ {
+ finishDraggingTo(adjust(x, y));
+ }
+
+ /**
+ * This method is called to finish the drag session
+ * by calling finishDraggingTo.
+ *
+ * @param e The MouseEvent.
+ */
+ protected void completeDrag(MouseEvent e)
+ {
+ finishDraggingTo(positionForMouseEvent(e));
+ }
+
+ /**
+ * This is a helper method that includes the offset
+ * in the needed location.
+ *
+ * @param x The x coordinate of the MouseEvent.
+ * @param y The y coordinate of the MouseEvent.
+ *
+ * @return The needed location adjusted by the offsets.
+ */
+ int adjust(int x, int y)
+ {
+ return getNeededLocation(x, y) + getX() - offset;
+ }
+ }
/**
- * Performs the tasks associated with an ongoing drag
- * operation.
- *
- * @author Sascha Brawer (brawer@dandelis.ch)
+ * This is a helper class that controls dragging when
+ * the orientation is VERTICAL_SPLIT.
*/
- protected class DragController
+ protected class VerticalDragController extends DragController
{
- // FIXME: Not yet implemented.
- protected DragController(MouseEvent e)
+ /**
+ * Creates a new VerticalDragController object.
+ *
+ * @param e The MouseEvent to initialize with.
+ */
+ protected VerticalDragController(MouseEvent e)
{
+ super(e);
+ offset = e.getY();
}
- protected boolean isValid()
+ /**
+ * This method returns one of the two parameters given
+ * the orientation. In this case, it returns y.
+ *
+ * @param x The x coordinate of the MouseEvent.
+ * @param y The y coordinate of the MouseEvent.
+ *
+ * @return The y coordinate.
+ */
+ protected int getNeededLocation(int x, int y)
{
- // FIXME: Not yet implemented.
- return true;
+ return y;
}
+ /**
+ * This method returns the new location of the divider
+ * given a MouseEvent.
+ *
+ * @param e The MouseEvent.
+ *
+ * @return The new location of the divider.
+ */
protected int positionForMouseEvent(MouseEvent e)
{
- return 0;
+ return e.getY() + getY() - offset;
}
- protected int getNeededLocation(int x, int y)
+ /**
+ * This is a helper method that includes the offset
+ * in the needed location.
+ *
+ * @param x The x coordinate of the MouseEvent.
+ * @param y The y coordinate of the MouseEvent.
+ *
+ * @return The needed location adjusted by the offsets.
+ */
+ int adjust(int x, int y)
+ {
+ return getNeededLocation(x, y) + getY() - offset;
+ }
+ }
+
+ /**
+ * This helper class acts as the Layout Manager for
+ * the divider.
+ */
+ protected class DividerLayout implements LayoutManager
+ {
+ /**
+ * Creates a new DividerLayout object.
+ */
+ protected DividerLayout()
{
- return 0;
}
- protected void continueDrag(int newX, int newY)
+ /**
+ * 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)
{
+ // Do nothing.
}
- protected void completeDrag(int x, int y)
+ /**
+ * This method is called to lay out the container.
+ *
+ * @param c The container to lay out.
+ */
+ public void layoutContainer(Container c)
{
+ if (splitPane.isOneTouchExpandable())
+ {
+ changeButtonOrientation();
+ positionButtons();
+ }
}
- protected void completeDrag(MouseEvent e)
+ /**
+ * 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)
+ {
+ 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)
+ {
+ // Do nothing.
+ }
+
+ /**
+ * This method changes the button orientation when
+ * the orientation of the SplitPane changes.
+ */
+ private void changeButtonOrientation()
+ {
+ if (orientation == JSplitPane.HORIZONTAL_SPLIT)
+ {
+ ((BasicArrowButton) rightButton).setDirection(SwingConstants.EAST);
+ ((BasicArrowButton) leftButton).setDirection(SwingConstants.WEST);
+ }
+ else
+ {
+ ((BasicArrowButton) rightButton).setDirection(SwingConstants.SOUTH);
+ ((BasicArrowButton) leftButton).setDirection(SwingConstants.NORTH);
+ }
+ }
+
+ /**
+ * This method sizes and positions the buttons.
+ */
+ private void positionButtons()
+ {
+ int w = 0;
+ int h = 0;
+ if (orientation == JSplitPane.HORIZONTAL_SPLIT)
+ {
+ rightButton.setLocation(ONE_TOUCH_OFFSET, ONE_TOUCH_OFFSET);
+ leftButton.setLocation(ONE_TOUCH_OFFSET,
+ ONE_TOUCH_OFFSET + 2 * ONE_TOUCH_SIZE);
+ w = dividerSize - 2 * ONE_TOUCH_OFFSET;
+ h = 2 * ONE_TOUCH_SIZE;
+ }
+ else
+ {
+ leftButton.setLocation(ONE_TOUCH_OFFSET, ONE_TOUCH_OFFSET);
+ rightButton.setLocation(ONE_TOUCH_OFFSET + 2 * ONE_TOUCH_SIZE,
+ ONE_TOUCH_OFFSET);
+ h = dividerSize - 2 * ONE_TOUCH_OFFSET;
+ w = 2 * ONE_TOUCH_SIZE;
+ }
+ Dimension dims = new Dimension(w, h);
+ leftButton.setSize(dims);
+ rightButton.setSize(dims);
}
}
}
Index: javax/swing/plaf/basic/BasicSplitPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicSplitPaneUI.java,v
retrieving revision 1.1
diff -u -r1.1 BasicSplitPaneUI.java
--- javax/swing/plaf/basic/BasicSplitPaneUI.java 24 Jun 2003 09:48:42 -0000 1.1
+++ javax/swing/plaf/basic/BasicSplitPaneUI.java 19 Apr 2004 19:22:50 -0000
@@ -1,5 +1,5 @@
/* BasicSplitPaneUI.java
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,273 +37,1484 @@
package javax.swing.plaf.basic;
+import java.awt.Canvas;
+import java.awt.Color;
import java.awt.Component;
+import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
+import java.awt.LayoutManager2;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.MouseEvent;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JSplitPane;
import javax.swing.KeyStroke;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.SplitPaneUI;
+
/**
- * FIXME: Stubbed to allow compiling other classes,
- * no real implementation.
+ * This is the Basic Look and Feel implementation of the SplitPaneUI class.
*/
-public class BasicSplitPaneUI
- extends SplitPaneUI
+public class BasicSplitPaneUI extends SplitPaneUI
{
- protected static final String NON_CONTINUOUS_DIVIDER
- = "nonContinuousDivider";
+ /**
+ * This Layout Manager controls the position and size of the components when
+ * the JSplitPane's orientation is HORIZONTAL_SPLIT.
+ */
+ protected class BasicHorizontalLayoutManager implements LayoutManager2
+ {
+ // 3 components at a time.
+ // LEFT/TOP = 0
+ // RIGHT/BOTTOM = 1
+ // DIVIDER = 2
+
+ /**
+ * This array contains the components in the JSplitPane. The left/top
+ * component is at index 0, the right/bottom is at 1, and the divider is
+ * at 2.
+ */
+ protected Component[] components = new Component[3];
+
+ // These are the _current_ widths of the associated component.
+
+ /**
+ * This array contains the current width (for HORIZONTAL_SPLIT) or height
+ * (for VERTICAL_SPLIT) of the components. The indices are the same as
+ * for components.
+ */
+ protected int[] sizes = new int[3];
+
+ /**
+ * This method adds the component given to the JSplitPane. The position of
+ * the component is given by the constraints object.
+ *
+ * @param comp The Component to add.
+ * @param constraints The constraints that bind the object.
+ */
+ public void addLayoutComponent(Component comp, Object constraints)
+ {
+ addLayoutComponent((String) constraints, comp);
+ }
+
+ /**
+ * This method is called to add a Component to the JSplitPane. The
+ * placement string determines where the Component will be placed. The
+ * string should be one of LEFT, RIGHT, TOP, BOTTOM or null (signals that
+ * the component is the divider).
+ *
+ * @param place The placement of the Component.
+ * @param component The Component to add.
+ *
+ * @throws IllegalArgumentException DOCUMENT ME!
+ */
+ public void addLayoutComponent(String place, Component component)
+ {
+ int i = 0;
+ if (place == null)
+ i = 2;
+ else if (place.equals(JSplitPane.TOP) || place.equals(JSplitPane.LEFT))
+ i = 0;
+ else if (place.equals(JSplitPane.BOTTOM)
+ || place.equals(JSplitPane.RIGHT))
+ i = 1;
+ else
+ throw new IllegalArgumentException("Illegal placement in JSplitPane");
+ components[i] = component;
+ resetSizeAt(i);
+ layoutContainer(splitPane);
+ splitPane.repaint();
+ }
+
+ /**
+ * This method returns the width of the JSplitPane minus the insets.
+ *
+ * @param containerSize The Dimensions of the JSplitPane.
+ * @param insets The Insets of the JSplitPane.
+ *
+ * @return The width of the JSplitPane minus the insets.
+ */
+ protected int getAvailableSize(Dimension containerSize, Insets insets)
+ {
+ return containerSize.width - insets.left - insets.right;
+ }
+
+ /**
+ * This method returns the given insets left value. If the given inset is
+ * null, then 0 is returned.
+ *
+ * @param insets The Insets to use with the JSplitPane.
+ *
+ * @return The inset's left value.
+ */
+ protected int getInitialLocation(Insets insets)
+ {
+ if (insets != null)
+ return insets.left;
+ return 0;
+ }
+
+ /**
+ * This specifies how a component is aligned with respect to other
+ * components in the x fdirection.
+ *
+ * @param target The container.
+ *
+ * @return The component's alignment.
+ */
+ public float getLayoutAlignmentX(Container target)
+ {
+ return target.getAlignmentX();
+ }
+
+ /**
+ * This specifies how a component is aligned with respect to other
+ * components in the y direction.
+ *
+ * @param target The container.
+ *
+ * @return The component's alignment.
+ */
+ public float getLayoutAlignmentY(Container target)
+ {
+ return target.getAlignmentY();
+ }
+
+ /**
+ * This method returns the preferred width of the component.
+ *
+ * @param c The component to measure.
+ *
+ * @return The preferred width of the component.
+ */
+ protected int getPreferredSizeOfComponent(Component c)
+ {
+ Dimension dims = c.getPreferredSize();
+ if (dims != null)
+ return dims.width;
+ return 0;
+ }
+
+ /**
+ * This method returns the current width of the component.
+ *
+ * @param c The component to measure.
+ *
+ * @return The width of the component.
+ */
+ protected int getSizeOfComponent(Component c)
+ {
+ return c.getWidth();
+ }
+
+ /**
+ * This method returns the sizes array.
+ *
+ * @return The sizes array.
+ */
+ protected int[] getSizes()
+ {
+ return sizes;
+ }
+
+ /**
+ * This method invalidates the layout. It does nothing.
+ *
+ * @param c The container to invalidate.
+ */
+ public void invalidateLayout(Container c)
+ {
+ // DO NOTHING
+ }
+
+ /**
+ * This method lays out the components in the container.
+ *
+ * @param container The container to lay out.
+ */
+ public void layoutContainer(Container container)
+ {
+ if (container instanceof JSplitPane)
+ {
+ JSplitPane split = (JSplitPane) container;
+ distributeExtraSpace();
+ Insets insets = split.getInsets();
+ int width = getInitialLocation(insets);
+ Dimension dims = split.getSize();
+ for (int i = 0; i < components.length; i += 2)
+ {
+ if (components[i] == null)
+ continue;
+ setComponentToSize(components[i], sizes[i], width, insets, dims);
+ width += sizes[i];
+ }
+ if (components[1] != null)
+ {
+ setComponentToSize(components[1], sizes[1], width, insets, dims);
+ width += sizes[1];
+ }
+ }
+ }
+
+ /**
+ * This method returns the maximum size for the container given the
+ * components. It returns a new Dimension object that has width and
+ * height equal to Integer.MAX_VALUE.
+ *
+ * @param target The container to measure.
+ *
+ * @return The maximum size.
+ */
+ public Dimension maximumLayoutSize(Container target)
+ {
+ return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
+ }
+
+ /**
+ * This method returns the container's minimum size. The minimum width is
+ * the sum of all the component's minimum widths. The minimum height is
+ * the maximum of all the components' minimum heights.
+ *
+ * @param target The container to measure.
+ *
+ * @return The minimum size.
+ */
+ public Dimension minimumLayoutSize(Container target)
+ {
+ if (target instanceof JSplitPane)
+ {
+ JSplitPane split = (JSplitPane) target;
+ Insets insets = target.getInsets();
+
+ int height = 0;
+ int width = 0;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] == null)
+ continue;
+ Dimension dims = components[i].getMinimumSize();
+ if (dims != null)
+ {
+ width += dims.width;
+ height = Math.max(height, dims.height);
+ }
+ }
+ return new Dimension(width, height);
+ }
+ return null;
+ }
+
+ /**
+ * This method returns the container's preferred size. The preferred width
+ * is the sum of all the component's preferred widths. The preferred
+ * height is the maximum of all the components' preferred heights.
+ *
+ * @param target The container to measure.
+ *
+ * @return The preferred size.
+ */
+ public Dimension preferredLayoutSize(Container target)
+ {
+ if (target instanceof JSplitPane)
+ {
+ JSplitPane split = (JSplitPane) target;
+ Insets insets = target.getInsets();
+
+ int height = 0;
+ int width = 0;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] == null)
+ continue;
+ Dimension dims = components[i].getPreferredSize();
+ if (dims != null)
+ {
+ width += dims.width;
+ if (! (components[i] instanceof BasicSplitPaneDivider))
+ height = Math.max(height, dims.height);
+ }
+ }
+ return new Dimension(500, 500); //width, height);
+ }
+ return null;
+ }
+
+ /**
+ * This method removes the component from the layout.
+ *
+ * @param component The component to remove from the layout.
+ */
+ public void removeLayoutComponent(Component component)
+ {
+ for (int i = 0; i < components.length; i++)
+ {
+ if (component == components[i])
+ {
+ components[i] = null;
+ sizes[i] = 0;
+ }
+ }
+ }
+
+ /**
+ * This method resets the size of Component to the preferred size.
+ *
+ * @param index The index of the component to reset.
+ */
+ protected void resetSizeAt(int index)
+ {
+ if (components[index] != null)
+ sizes[index] = getPreferredSizeOfComponent(components[index]);
+ }
+
+ /**
+ * This method resets the sizes of all the components.
+ */
+ public void resetToPreferredSizes()
+ {
+ for (int i = 0; i < components.length; i++)
+ resetSizeAt(i);
+ }
+
+ /**
+ * This methods sets the bounds of the given component. The width is the
+ * size. The height is the container size minus the top and bottom
+ * inset. The x coordinate is the location given. The y coordinate is
+ * the top inset.
+ *
+ * @param c The component to set.
+ * @param size The width of the component.
+ * @param location The x coordinate.
+ * @param insets The insets to use.
+ * @param containerSize The height of the container.
+ */
+ protected void setComponentToSize(Component c, int size, int location,
+ Insets insets, Dimension containerSize)
+ {
+ int w = size;
+ int h = containerSize.height - insets.top - insets.bottom;
+ int x = location;
+ int y = insets.top;
+ c.setBounds(x, y, w, h);
+ }
+
+ /**
+ * This method stores the given int array as the new sizes array.
+ *
+ * @param newSizes The array to use as sizes.
+ */
+ protected void setSizes(int[] newSizes)
+ {
+ sizes = newSizes;
+ }
+
+ /**
+ * This method determines the size of each component. It should be called
+ * when a new Layout Manager is created for an existing JSplitPane.
+ */
+ protected void updateComponents()
+ {
+ Component left = splitPane.getLeftComponent();
+ Component right = splitPane.getRightComponent();
+
+ if (left != null)
+ {
+ components[0] = left;
+ resetSizeAt(0);
+ }
+ if (right != null)
+ {
+ components[1] = right;
+ resetSizeAt(1);
+ }
+ components[2] = divider;
+ resetSizeAt(2);
+ }
+
+ /**
+ * This method resizes the left and right components to fit inside the
+ * JSplitPane when there is extra space.
+ */
+ void distributeExtraSpace()
+ {
+ int availSize = getAvailableSize(splitPane.getSize(),
+ splitPane.getInsets());
+ int[] newSizes = new int[3];
+ double weight = splitPane.getResizeWeight();
+
+ int oldLen = sizes[0] + sizes[1];
+
+ // dividers don't change size.
+ availSize -= sizes[2] + oldLen;
+
+ int rightAlloc = (int) (availSize * (1 - weight));
+ int leftAlloc = availSize - rightAlloc;
+
+ sizes[0] += leftAlloc;
+ sizes[1] += rightAlloc;
+ }
+
+ /**
+ * This method returns the minimum width of the component at the given
+ * index.
+ *
+ * @param index The index to check.
+ *
+ * @return The minimum width.
+ */
+ int minimumSizeOfComponent(int index)
+ {
+ Dimension dims = components[index].getMinimumSize();
+ if (dims != null)
+ return dims.width;
+ else
+ return 0;
+ }
+ } //end BasicHorizontalLayoutManager
+
+ /**
+ * This class is the Layout Manager for the JSplitPane when the orientation
+ * is VERTICAL_SPLIT.
+ */
+ protected class BasicVerticalLayoutManager
+ extends BasicHorizontalLayoutManager
+ {
+ /**
+ * This method returns the height of the container minus the top and
+ * bottom inset.
+ *
+ * @param containerSize The size of the container.
+ * @param insets The insets of the container.
+ *
+ * @return The height minus top and bottom inset.
+ */
+ protected int getAvailableSize(Dimension containerSize, Insets insets)
+ {
+ return containerSize.height - insets.top - insets.bottom;
+ }
+
+ /**
+ * This method returns the top inset.
+ *
+ * @param insets The Insets to use.
+ *
+ * @return The top inset.
+ */
+ protected int getInitialLocation(Insets insets)
+ {
+ return insets.top;
+ }
+
+ /**
+ * This method returns the preferred height of the component.
+ *
+ * @param c The component to measure.
+ *
+ * @return The preferred height of the component.
+ */
+ protected int getPreferredSizeOfComponent(Component c)
+ {
+ Dimension dims = c.getPreferredSize();
+ if (dims != null)
+ return dims.height;
+ return 0;
+ }
+
+ /**
+ * This method returns the current height of the component.
+ *
+ * @param c The component to measure.
+ *
+ * @return The current height of the component.
+ */
+ protected int getSizeOfComponent(Component c)
+ {
+ return c.getHeight();
+ }
+
+ /**
+ * This method returns the minimum layout size. The minimum height is the
+ * sum of all the components' minimum heights. The minimum width is the
+ * maximum of all the components' minimum widths.
+ *
+ * @param container The container to measure.
+ *
+ * @return The minimum size.
+ */
+ public Dimension minimumLayoutSize(Container container)
+ {
+ if (container instanceof JSplitPane)
+ {
+ JSplitPane split = (JSplitPane) container;
+ Insets insets = container.getInsets();
+
+ int height = 0;
+ int width = 0;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] == null)
+ continue;
+ Dimension dims = components[i].getMinimumSize();
+ if (dims != null)
+ {
+ height += dims.height;
+ width = Math.max(width, dims.width);
+ }
+ }
+ return new Dimension(width, height);
+ }
+ return null;
+ }
+
+ /**
+ * This method returns the preferred layout size. The preferred height is
+ * the sum of all the components' preferred heights. The preferred width
+ * is the maximum of all the components' preferred widths.
+ *
+ * @param container The container to measure.
+ *
+ * @return The preferred size.
+ */
+ public Dimension preferredLayoutSize(Container container)
+ {
+ if (container instanceof JSplitPane)
+ {
+ JSplitPane split = (JSplitPane) container;
+ Insets insets = container.getInsets();
+
+ int height = 0;
+ int width = 0;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] == null)
+ continue;
+ Dimension dims = components[i].getPreferredSize();
+ if (dims != null)
+ {
+ height += dims.height;
+ width = Math.max(width, dims.width);
+ }
+ }
+ return new Dimension(500, 500); //width, height);
+ }
+ return null;
+ }
+
+ /**
+ * This method sets the bounds of the given component. The y coordinate is
+ * the location given. The x coordinate is the left inset. The height is
+ * the size given. The width is the container size minus the left and
+ * right inset.
+ *
+ * @param c The component to set bounds for.
+ * @param size The height.
+ * @param location The y coordinate.
+ * @param insets The insets to use.
+ * @param containerSize The container's size.
+ */
+ protected void setComponentToSize(Component c, int size, int location,
+ Insets insets, Dimension containerSize)
+ {
+ int y = location;
+ int x = insets.left;
+ int h = size;
+ int w = containerSize.width - insets.left - insets.right;
+
+ c.setBounds(x, y, w, h);
+ }
+
+ /**
+ * This method returns the minimum height of the component at the given
+ * index.
+ *
+ * @param index The index of the component to check.
+ *
+ * @return The minimum height of the given component.
+ */
+ int minimumSizeOfComponent(int index)
+ {
+ Dimension dims = components[index].getMinimumSize();
+ if (dims != null)
+ return dims.height;
+ else
+ return 0;
+ }
+ }
+
+ /**
+ * This class handles FocusEvents from the JComponent.
+ */
+ protected class FocusHandler extends FocusAdapter
+ {
+ /**
+ * This method is called when the JSplitPane gains focus.
+ *
+ * @param ev The FocusEvent.
+ */
+ public void focusGained(FocusEvent ev)
+ {
+ // FIXME: implement.
+ }
+
+ /**
+ * This method is called when the JSplitPane loses focus.
+ *
+ * @param ev The FocusEvent.
+ */
+ public void focusLost(FocusEvent ev)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * This is a deprecated class. It is supposed to be used for handling down
+ * and right key presses.
+ */
+ protected class KeyboardDownRightHandler implements ActionListener
+ {
+ /**
+ * This method is called when the down or right keys are pressed.
+ *
+ * @param ev The ActionEvent
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * This is a deprecated class. It is supposed to be used for handling end
+ * key presses.
+ */
+ protected class KeyboardEndHandler implements ActionListener
+ {
+ /**
+ * This method is called when the end key is pressed.
+ *
+ * @param ev The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * This is a deprecated class. It is supposed to be used for handling home
+ * key presses.
+ */
+ protected class KeyboardHomeHandler implements ActionListener
+ {
+ /**
+ * This method is called when the home key is pressed.
+ *
+ * @param ev The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * This is a deprecated class. It is supposed to be used for handling resize
+ * toggles.
+ */
+ protected class KeyboardResizeToggleHandler implements ActionListener
+ {
+ /**
+ * This method is called when a resize is toggled.
+ *
+ * @param ev The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * This is a deprecated class. It is supposed to be used for handler up and
+ * left key presses.
+ */
+ protected class KeyboardUpLeftHandler implements ActionListener
+ {
+ /**
+ * This method is called when the left or up keys are pressed.
+ *
+ * @param ev The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * This helper class handles PropertyChangeEvents from the JSplitPane. When
+ * a property changes, this will update the UI accordingly.
+ */
+ protected class PropertyHandler implements PropertyChangeListener
+ {
+ /**
+ * This method is called whenever one of the JSplitPane's properties
+ * change.
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ if (e.getPropertyName().equals(JSplitPane.DIVIDER_SIZE_PROPERTY))
+ {
+ int newSize = splitPane.getDividerSize();
+ int[] tmpSizes = layoutManager.getSizes();
+ dividerSize = tmpSizes[2];
+ Component left = splitPane.getLeftComponent();
+ Component right = splitPane.getRightComponent();
+ int newSpace = newSize - tmpSizes[2];
+
+ tmpSizes[2] = newSize;
+
+ tmpSizes[0] += newSpace / 2;
+ tmpSizes[1] += newSpace / 2;
+
+ layoutManager.setSizes(tmpSizes);
+ }
+ else if (e.getPropertyName().equals(JSplitPane.ORIENTATION_PROPERTY))
+ {
+ int max = layoutManager.getAvailableSize(splitPane.getSize(),
+ splitPane.getInsets());
+ int dividerLoc = getDividerLocation(splitPane);
+ double prop = ((double) dividerLoc) / max;
+
+ resetLayoutManager();
+ if (prop <= 1 && prop >= 0)
+ splitPane.setDividerLocation(prop);
+ }
+ layoutManager.layoutContainer(splitPane);
+ splitPane.repaint();
+ // Don't have to deal with continuous_layout - only
+ // necessary in dragging modes (and it's checked
+ // every time you drag there)
+ // Don't have to deal with resize_weight (as there
+ // will be no extra space associated with this
+ // event - the changes to the weighting will
+ // be taken into account the next time the
+ // sizes change.)
+ // Don't have to deal with divider_location
+ // The method in JSplitPane calls our setDividerLocation
+ // so we'll know about those anyway.
+ // Don't have to deal with last_divider_location
+ // Although I'm not sure why, it doesn't seem to
+ // have any effect on Sun's JSplitPane.
+ // one_touch_expandable changes are dealt with
+ // by our divider.
+ }
+ }
+
+ /** The location of the divider when dragging began. */
+ protected int beginDragDividerLocation;
+
+ /** The size of the divider while dragging. */
+ protected int dividerSize;
+ /** The location where the last drag location ended. */
+ transient int lastDragLocation = -1;
+
+ /** The distance the divider is moved when moved by keyboard actions. */
protected static int KEYBOARD_DIVIDER_MOVE_OFFSET;
- protected JSplitPane splitPane;
+ /** The divider that divides this JSplitPane. */
protected BasicSplitPaneDivider divider;
+
+ /** The listener that listens for PropertyChangeEvents from the JSplitPane. */
protected PropertyChangeListener propertyChangeListener;
+
+ /** The JSplitPane's focus handler. */
protected FocusListener focusListener;
- protected int dividerSize;
- protected Component nonContinuousLayoutDivider;
- protected boolean draggingHW;
- protected int beginDragDividerLocation;
- protected KeyStroke upKey;
- protected KeyStroke downKey;
- protected KeyStroke leftKey;
- protected KeyStroke rightKey;
- protected KeyStroke homeKey;
- protected KeyStroke endKey;
- protected KeyStroke dividerResizeToggleKey;
- protected ActionListener keyboardUpLeftListener;
+
+ /** Deprecated. The handler for down and right key presses. */
protected ActionListener keyboardDownRightListener;
- protected ActionListener keyboardHomeListener;
+
+ /** Deprecated. The handler for end key presses. */
protected ActionListener keyboardEndListener;
+
+ /** Deprecated. The handler for home key presses. */
+ protected ActionListener keyboardHomeListener;
+
+ /** Deprecated. The handler for toggling resizes. */
protected ActionListener keyboardResizeToggleListener;
- public static ComponentUI createUI(JComponent c)
- {
- BasicSplitPaneUI newUI;
+ /** Deprecated. The handler for up and left key presses. */
+ protected ActionListener keyboardUpLeftListener;
- newUI = new BasicSplitPaneUI();
- newUI.installUI(c);
- return newUI;
- }
+ /** The JSplitPane's current layout manager. */
+ protected BasicHorizontalLayoutManager layoutManager;
+
+ /** Deprecated. The divider resize toggle key. */
+ protected KeyStroke dividerResizeToggleKey;
+
+ /** Deprecated. The down key. */
+ protected KeyStroke downKey;
+
+ /** Deprecated. The end key. */
+ protected KeyStroke endKey;
+
+ /** Deprecated. The home key. */
+ protected KeyStroke homeKey;
+
+ /** Deprecated. The left key. */
+ protected KeyStroke leftKey;
+
+ /** Deprecated. The right key. */
+ protected KeyStroke rightKey;
+
+ /** Deprecated. The up key. */
+ protected KeyStroke upKey;
+
+ /** Set to true when dragging heavy weight components. */
+ protected boolean draggingHW;
+
+ /**
+ * The constraints object used when adding the non-continuous divider to the
+ * JSplitPane.
+ */
+ protected static String NON_CONTINUOUS_DIVIDER;
+
+ /** The dark divider used when dragging in non-continuous layout mode. */
+ protected Component nonContinuousLayoutDivider;
+ /** The JSplitPane that this UI draws. */
+ protected JSplitPane splitPane;
+
+ /**
+ * Creates a new BasicSplitPaneUI object.
+ */
public BasicSplitPaneUI()
{
- propertyChangeListener = createPropertyChangeListener();
- focusListener = createFocusListener();
}
+ /**
+ * This method creates a new BasicSplitPaneUI for the given JComponent.
+ *
+ * @param x The JComponent to create a UI for.
+ *
+ * @return A new BasicSplitPaneUI.
+ */
+ public static ComponentUI createUI(JComponent x)
+ {
+ return new BasicSplitPaneUI();
+ }
+
+ /**
+ * This method installs the BasicSplitPaneUI for the given JComponent.
+ *
+ * @param c The JComponent to install the UI for.
+ */
public void installUI(JComponent c)
{
+ if (c instanceof JSplitPane)
+ {
+ splitPane = (JSplitPane) c;
+ installDefaults();
+ installListeners();
+ installKeyboardActions();
+ }
}
- protected void installDefaults()
+ /**
+ * This method uninstalls the BasicSplitPaneUI for the given JComponent.
+ *
+ * @param c The JComponent to uninstall the UI for.
+ */
+ public void uninstallUI(JComponent c)
{
- }
+ uninstallKeyboardActions();
+ uninstallListeners();
+ uninstallDefaults();
- protected void installListeners()
- {
+ splitPane = null;
}
- protected void installKeyboardListeners()
+ /**
+ * This method installs the defaults given by the Look and Feel.
+ */
+ protected void installDefaults()
{
- }
-
- protected void installKeyboardActions()
+ resetLayoutManager();
+ divider = createDefaultDivider();
+ nonContinuousLayoutDivider = createDefaultNonContinuousLayoutDivider();
+ splitPane.add(divider, JSplitPane.DIVIDER);
+
+ // There is no need to add the nonContinuousLayoutDivider
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ splitPane.setBackground(defaults.getColor("SplitPane.background"));
+ splitPane.setBorder(defaults.getBorder("SplitPane.border"));
+ splitPane.setDividerSize(defaults.getInt("SplitPane.dividerSize"));
+ }
+
+ /**
+ * This method uninstalls the defaults and nulls any objects created during
+ * install.
+ */
+ protected void uninstallDefaults()
{
+ layoutManager = null;
+ splitPane.remove(divider);
+ divider = null;
+ nonContinuousLayoutDivider = null;
+
+ splitPane.setBackground(null);
+ splitPane.setBorder(null);
}
- public void uninstallUI(JComponent c)
+ /**
+ * This method installs the listeners needed for this UI to function.
+ */
+ protected void installListeners()
{
+ propertyChangeListener = createPropertyChangeListener();
+ focusListener = createFocusListener();
+
+ splitPane.addPropertyChangeListener(propertyChangeListener);
+ splitPane.addFocusListener(focusListener);
}
- protected void uninstallDefaults()
+ /**
+ * This method uninstalls all listeners registered for the UI.
+ */
+ protected void uninstallListeners()
{
+ splitPane.removePropertyChangeListener(propertyChangeListener);
+ splitPane.removeFocusListener(focusListener);
+
+ focusListener = null;
+ propertyChangeListener = null;
}
- protected void uninstallListeners()
+ /**
+ * This method installs the keyboard actions for the JSplitPane.
+ */
+ protected void installKeyboardActions()
{
+ // FIXME: implement.
}
+ /**
+ * This method reverses the work done in installKeyboardActions.
+ */
protected void uninstallKeyboardActions()
{
+ // FIXME: implement.
}
+ /**
+ * This method creates a new PropertyChangeListener.
+ *
+ * @return A new PropertyChangeListener.
+ */
protected PropertyChangeListener createPropertyChangeListener()
{
- return null;
+ return new PropertyHandler();
}
+ /**
+ * This method creates a new FocusListener.
+ *
+ * @return A new FocusListener.
+ */
protected FocusListener createFocusListener()
{
- return null;
+ return new FocusHandler();
}
+ /**
+ * Deprecated. This method creates a new ActionListener for up and left key
+ * presses.
+ *
+ * @return A new ActionListener for up and left keys.
+ */
protected ActionListener createKeyboardUpLeftListener()
{
- return null;
+ return new KeyboardUpLeftHandler();
}
+ /**
+ * Deprecated. This method creates a new ActionListener for down and right
+ * key presses.
+ *
+ * @return A new ActionListener for down and right keys.
+ */
protected ActionListener createKeyboardDownRightListener()
{
- return null;
+ return new KeyboardDownRightHandler();
}
+ /**
+ * Deprecated. This method creates a new ActionListener for home key
+ * presses.
+ *
+ * @return A new ActionListener for home keys.
+ */
protected ActionListener createKeyboardHomeListener()
{
- return null;
+ return new KeyboardHomeHandler();
}
+ /**
+ * Deprecated. This method creates a new ActionListener for end key presses.
+ *
+ * @return A new ActionListener for end keys.
+ */
protected ActionListener createKeyboardEndListener()
{
- return null;
+ return new KeyboardEndHandler();
}
+ /**
+ * Depcreated. This method creates a new ActionListener for resize toggle
+ * key events.
+ *
+ * @return A new ActionListener for resize toggle keys.
+ */
protected ActionListener createKeyboardResizeToggleListener()
{
- return null;
+ return new KeyboardResizeToggleHandler();
}
+ /**
+ * This method returns the orientation of the JSplitPane.
+ *
+ * @return The orientation of the JSplitPane.
+ */
public int getOrientation()
{
return splitPane.getOrientation();
}
+ /**
+ * This method sets the orientation of the JSplitPane.
+ *
+ * @param orientation The new orientation of the JSplitPane.
+ */
public void setOrientation(int orientation)
{
+ splitPane.setOrientation(orientation);
}
-
+ /**
+ * This method returns true if the JSplitPane is using continuous layout.
+ *
+ * @return True if the JSplitPane is using continuous layout.
+ */
public boolean isContinuousLayout()
{
- return false;
+ return splitPane.isContinuousLayout();
}
+ /**
+ * This method sets the continuous layout property of the JSplitPane.
+ *
+ * @param b True if the JsplitPane is to use continuous layout.
+ */
public void setContinuousLayout(boolean b)
{
+ splitPane.setContinuousLayout(b);
}
+ /**
+ * This method returns the last location the divider was dragged to.
+ *
+ * @return The last location the divider was dragged to.
+ */
public int getLastDragLocation()
{
- return 0;
+ return lastDragLocation;
}
+ /**
+ * This method sets the last location the divider was dragged to.
+ *
+ * @param l The last location the divider was dragged to.
+ */
public void setLastDragLocation(int l)
{
+ lastDragLocation = l;
}
-
+ /**
+ * This method returns the BasicSplitPaneDivider that divides this
+ * JSplitPane.
+ *
+ * @return The divider for the JSplitPane.
+ */
public BasicSplitPaneDivider getDivider()
{
return divider;
}
-
+ /**
+ * This method creates a nonContinuousLayoutDivider for use with the
+ * JSplitPane in nonContinousLayout mode. The default divider is a gray
+ * Canvas.
+ *
+ * @return The default nonContinousLayoutDivider.
+ */
protected Component createDefaultNonContinuousLayoutDivider()
{
- return null;
+ if (nonContinuousLayoutDivider == null)
+ {
+ nonContinuousLayoutDivider = new Canvas();
+ nonContinuousLayoutDivider.setBackground(Color.DARK_GRAY);
+ }
+ return nonContinuousLayoutDivider;
}
+ /**
+ * This method sets the component to use as the nonContinuousLayoutDivider.
+ *
+ * @param newDivider The component to use as the nonContinuousLayoutDivider.
+ */
protected void setNonContinuousLayoutDivider(Component newDivider)
{
- setNonContinuousLayoutDivider(newDivider, true /* false? */);
+ setNonContinuousLayoutDivider(newDivider, true);
}
+ /**
+ * This method sets the component to use as the nonContinuousLayoutDivider.
+ *
+ * @param newDivider The component to use as the nonContinuousLayoutDivider.
+ * @param rememberSizes FIXME: document.
+ */
protected void setNonContinuousLayoutDivider(Component newDivider,
boolean rememberSizes)
{
+ // FIXME: use rememberSizes for something
nonContinuousLayoutDivider = newDivider;
}
+ /**
+ * This method returns the nonContinuousLayoutDivider.
+ *
+ * @return The nonContinuousLayoutDivider.
+ */
public Component getNonContinuousLayoutDivider()
{
return nonContinuousLayoutDivider;
}
+ /**
+ * This method returns the JSplitPane that this BasicSplitPaneUI draws.
+ *
+ * @return The JSplitPane.
+ */
public JSplitPane getSplitPane()
{
return splitPane;
}
+ /**
+ * This method creates the divider used normally with the JSplitPane.
+ *
+ * @return The default divider.
+ */
public BasicSplitPaneDivider createDefaultDivider()
{
- return null;
+ if (divider == null)
+ divider = new BasicSplitPaneDivider(this);
+ return divider;
}
+ /**
+ * This method is called when JSplitPane's resetToPreferredSizes is called.
+ * It resets the sizes of all components in the JSplitPane.
+ *
+ * @param jc The JSplitPane to reset.
+ */
public void resetToPreferredSizes(JSplitPane jc)
{
+ layoutManager.resetToPreferredSizes();
}
+ /**
+ * This method sets the location of the divider.
+ *
+ * @param jc The JSplitPane to set the divider location in.
+ * @param location The new location of the divider.
+ */
public void setDividerLocation(JSplitPane jc, int location)
{
- }
-
+ setLastDragLocation(getDividerLocation(splitPane));
+ splitPane.setLastDividerLocation(getDividerLocation(splitPane));
+ int[] tmpSizes = layoutManager.getSizes();
+ tmpSizes[0] = location
+ - layoutManager.getInitialLocation(splitPane.getInsets());
+ tmpSizes[1] = layoutManager.getAvailableSize(splitPane.getSize(),
+ splitPane.getInsets())
+ - tmpSizes[0] - tmpSizes[1];
+ Point p = divider.getLocation();
+
+// if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
+ // setLastDragLocation(p.x);
+// else
+// setLastDragLocation(p.y);
+ layoutManager.setSizes(tmpSizes);
+ layoutManager.layoutContainer(splitPane);
+
+ splitPane.repaint();
+ }
+
+ /**
+ * This method returns the location of the divider.
+ *
+ * @param jc The JSplitPane to retrieve the location for.
+ *
+ * @return The location of the divider.
+ */
public int getDividerLocation(JSplitPane jc)
{
- return 0;
+ return layoutManager.sizes[0]
+ + layoutManager.getInitialLocation(splitPane.getInsets());
}
+ /**
+ * This method returns the smallest value possible for the location of the
+ * divider.
+ *
+ * @param jc The JSplitPane.
+ *
+ * @return The minimum divider location.
+ */
public int getMinimumDividerLocation(JSplitPane jc)
{
- return 0;
+ int value = layoutManager.getInitialLocation(jc.getInsets());
+ if (layoutManager.components[0] != null)
+ value += layoutManager.minimumSizeOfComponent(0);
+ return value;
}
+ /**
+ * This method returns the largest value possible for the location of the
+ * divider.
+ *
+ * @param jc The JSplitPane.
+ *
+ * @return The maximum divider location.
+ */
public int getMaximumDividerLocation(JSplitPane jc)
{
- return 0;
+ int value = layoutManager.getInitialLocation(jc.getInsets())
+ + layoutManager.getAvailableSize(jc.getSize(), jc.getInsets())
+ - splitPane.getDividerSize();
+ if (layoutManager.components[1] != null)
+ value -= layoutManager.minimumSizeOfComponent(1);
+ return value;
}
+ /**
+ * This method is called after the children of the JSplitPane are painted.
+ *
+ * @param jc The JSplitPane.
+ * @param g The Graphics object to paint with.
+ */
public void finishedPaintingChildren(JSplitPane jc, Graphics g)
{
+ if (! splitPane.isContinuousLayout() && nonContinuousLayoutDivider != null
+ && nonContinuousLayoutDivider.isVisible())
+ javax.swing.SwingUtilities.paintComponent(g, nonContinuousLayoutDivider,
+ null,
+ nonContinuousLayoutDivider
+ .getBounds());
}
+ /**
+ * This method is called to paint the JSplitPane.
+ *
+ * @param g The Graphics object to paint with.
+ * @param jc The JSplitPane to paint.
+ */
public void paint(Graphics g, JComponent jc)
{
+ // Do nothing. All the painting is handled by children.
}
+ /**
+ * This method returns the preferred size of the JSplitPane.
+ *
+ * @param jc The JSplitPane.
+ *
+ * @return The preferred size of the JSplitPane.
+ */
public Dimension getPreferredSize(JComponent jc)
{
- return null;
+ return layoutManager.preferredLayoutSize((Container) jc);
}
+ /**
+ * This method returns the minimum size of the JSplitPane.
+ *
+ * @param jc The JSplitPane.
+ *
+ * @return The minimum size of the JSplitPane.
+ */
public Dimension getMinimumSize(JComponent jc)
{
- return null;
+ return layoutManager.minimumLayoutSize((Container) jc);
}
+ /**
+ * This method returns the maximum size of the JSplitPane.
+ *
+ * @param jc The JSplitPane.
+ *
+ * @return The maximum size of the JSplitPane.
+ */
public Dimension getMaximumSize(JComponent jc)
{
- return null;
+ return layoutManager.maximumLayoutSize((Container) jc);
}
+ /**
+ * This method returns the border insets of the current border.
+ *
+ * @param jc The JSplitPane.
+ *
+ * @return The current border insets.
+ */
public Insets getInsets(JComponent jc)
{
- return new Insets(0, 0, 0, 0);
+ return splitPane.getBorder().getBorderInsets(splitPane);
}
+ /**
+ * This method resets the current layout manager. The type of layout manager
+ * is dependent on the current orientation.
+ */
protected void resetLayoutManager()
{
- }
-
+ if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
+ layoutManager = new BasicHorizontalLayoutManager();
+ else
+ layoutManager = new BasicVerticalLayoutManager();
+ layoutManager.invalidateLayout(splitPane);
+ layoutManager.updateComponents();
+ getSplitPane().setLayout(layoutManager);
+
+ // invalidating by itself does not invalidate the layout.
+ getSplitPane().invalidate();
+ }
+
+ /**
+ * This method is called when dragging starts. It resets lastDragLocation
+ * and dividerSize.
+ */
protected void startDragging()
{
- }
+ dividerSize = divider.getDividerSize();
+ setLastDragLocation(-1);
+ if (! splitPane.getLeftComponent().isLightweight()
+ || ! splitPane.getRightComponent().isLightweight())
+ draggingHW = true;
+
+ if (splitPane.isContinuousLayout())
+ nonContinuousLayoutDivider.setVisible(false);
+ else
+ {
+ nonContinuousLayoutDivider.setVisible(true);
+ nonContinuousLayoutDivider.setBounds(divider.getBounds());
+ }
+ splitPane.invalidate();
+ splitPane.repaint();
+ }
+
+ /**
+ * This method is called whenever the divider is dragged. If the JSplitPane
+ * is in continuousLayout mode, the divider needs to be moved and the
+ * JSplitPane needs to be laid out.
+ *
+ * @param location The new location of the divider.
+ */
protected void dragDividerTo(int location)
{
- }
-
+ location = validLocation(location);
+ if (beginDragDividerLocation == -1)
+ beginDragDividerLocation = location;
+
+ if (splitPane.isContinuousLayout())
+ splitPane.setDividerLocation(location);
+ else
+ {
+ Point p = nonContinuousLayoutDivider.getLocation();
+ if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
+ p.x = location;
+ else
+ p.y = location;
+ nonContinuousLayoutDivider.setLocation(p);
+ }
+ setLastDragLocation(location);
+ splitPane.repaint();
+ }
+
+ /**
+ * This method is called when the dragging is finished.
+ *
+ * @param location The location where the drag finished.
+ */
protected void finishDraggingTo(int location)
{
- }
-
+ if (nonContinuousLayoutDivider != null)
+ nonContinuousLayoutDivider.setVisible(false);
+ draggingHW = false;
+ location = validLocation(location);
+ dragDividerTo(location);
+ splitPane.setDividerLocation(location);
+ splitPane.setLastDividerLocation(beginDragDividerLocation);
+ beginDragDividerLocation = -1;
+ splitPane.repaint();
+ }
+
+ /**
+ * Deprecated. This method returns the width of one of the sides of the
+ * divider's border.
+ *
+ * @return The width of one side of the divider's border.
+ */
protected int getDividerBorderSize()
{
- return 0;
+ if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
+ return divider.getBorder().getBorderInsets(divider).left;
+ else
+ return divider.getBorder().getBorderInsets(divider).top;
+ }
+
+ /**
+ * This is a helper method that returns a valid location for the divider
+ * when dragging.
+ *
+ * @param location The location to check.
+ *
+ * @return A valid location.
+ */
+ private int validLocation(int location)
+ {
+ if (location < getMinimumDividerLocation(splitPane))
+ return getMinimumDividerLocation(splitPane);
+ if (location > getMaximumDividerLocation(splitPane))
+ return getMaximumDividerLocation(splitPane);
+ return location;
}
}
Index: javax/swing/plaf/basic/BasicTabbedPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java,v
retrieving revision 1.3.16.3
diff -u -r1.3.16.3 BasicTabbedPaneUI.java
--- javax/swing/plaf/basic/BasicTabbedPaneUI.java 23 Mar 2004 19:02:18 -0000 1.3.16.3
+++ javax/swing/plaf/basic/BasicTabbedPaneUI.java 19 Apr 2004 19:22:51 -0000
@@ -230,10 +230,11 @@
{
Component visible = getVisibleComponent();
Insets insets = getContentBorderInsets(tabPane.getTabPlacement());
- visible.setBounds(contentRect.x + insets.left,
- contentRect.y + insets.top,
- contentRect.width - insets.left - insets.right,
- contentRect.height - insets.top - insets.bottom);
+ if (visible != null)
+ visible.setBounds(contentRect.x + insets.left,
+ contentRect.y + insets.top,
+ contentRect.width - insets.left - insets.right,
+ contentRect.height - insets.top - insets.bottom);
}
}
@@ -1796,7 +1797,7 @@
// FIXME: Paint little folding corner and jagged edge clipped tab.
if (icon != null)
paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
- if (title == null || ! title.equals(""))
+ if (title != null && ! title.equals(""))
paintText(g, tabPlacement, tabPane.getFont(), fm, tabIndex, title,
textRect, isSelected);
}