This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui][PATCH] JToolBar and some other things
- From: Kim Ho <kho at redhat dot com>
- To: java-patches <java-patches at gcc dot gnu dot org>
- Date: Mon, 12 Jul 2004 15:34:16 -0400
- Subject: [gui][PATCH] JToolBar and some other things
Hi,
Committing this patch that implements JToolBar and fixes a couple other
widgets.
Cheers,
Kim
2004-07-12 Kim Ho <kho@redhat.com>
* Makefile.am: Added new file.
* Makefile.in: Regenerated.
* gcj/Makefile.in: Regenerated.
* include/Makefile.in: Regenerated.
* javax/swing/AbstractButton.java:
Add rollOverEnabled property.
(setRolloverEnabled): Use new property.
(isRolloverEnabled): Use new property.
* javax/swing/JTabbedPane.java:
(setComponent): Remove useless JTabbedPane.this.
* javax/swing/JToolBar.java: Finish implementation.
* javax/swing/plaf/basic/BasicArrowButton.java:
(paint): Moved border painting to a border.
* javax/swing/plaf/basic/BasicLookAndFeel.java:
Change JToolBar look and feel defaults.
* javax/swing/plaf/basic/BasicOptionPaneUI.java
(actionPerformed): Return Integer index instead of name.
(addButtonComponents): Check to see if component is
JButton last.
(createMessageArea): Don't use components that are not
completed yet.
(getIconForType): Use temporary icons.
* javax/swing/plaf/basic/BasicSliderUI.java:
(mousePressed): Do not return if it's on thumb.
(paintMinorTickForHorizSlider): Use BLACK to paint ticks.
(paintMinorTickForVertSlider): ditto.
(paintMajorTickForHorizSlider): ditto.
(paintMajorTickForVertSlider): ditto.
* javax/swing/plaf/basic/BasicSplitPaneDivider.java:
Add a border around the SplitPaneDivider.
* javax/swing/plaf/basic/BasicSplitPaneUI.java:
Remove comments.
* javax/swing/plaf/basic/BasicToolBarSeparatorUI.java:
New file. Implemented.
* javax/swing/plaf/basic/BasicToolBarUI.java:
Implemented.
* testsuite/Makefile.in: Regenerated.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.361.2.24
diff -u -r1.361.2.24 Makefile.am
--- Makefile.am 7 Jul 2004 19:14:30 -0000 1.361.2.24
+++ Makefile.am 12 Jul 2004 19:25:07 -0000
@@ -1328,6 +1328,7 @@
javax/swing/plaf/basic/BasicTextUI.java \
javax/swing/plaf/basic/BasicToggleButtonUI.java \
javax/swing/plaf/basic/BasicToolBarUI.java \
+javax/swing/plaf/basic/BasicToolBarSeparatorUI.java \
javax/swing/plaf/basic/BasicTreeUI.java \
javax/swing/plaf/basic/BasicViewportUI.java \
javax/swing/plaf/basic/BasicLookAndFeel.java \
Index: javax/swing/AbstractButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/AbstractButton.java,v
retrieving revision 1.5.2.13
diff -u -r1.5.2.13 AbstractButton.java
--- javax/swing/AbstractButton.java 10 Jul 2004 17:53:02 -0000 1.5.2.13
+++ javax/swing/AbstractButton.java 12 Jul 2004 19:25:18 -0000
@@ -206,6 +206,9 @@
/** Whether or not the button fills its content area. */
boolean contentAreaFilled;
+
+ /** Whether rollover is enabled. */
+ boolean rollOverEnabled;
/** The action taken when the button is clicked. */
Action action;
@@ -793,11 +796,10 @@
*/
public void setRolloverEnabled(boolean r)
{
- boolean old = getModel().isRollover();
- getModel().setRollover(r);
- if (old != getModel().isRollover())
+ if (rollOverEnabled != r)
{
- firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, old, r);
+ rollOverEnabled = r;
+ firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, !r, r);
revalidate();
repaint();
}
@@ -811,7 +813,7 @@
*/
public boolean isRolloverEnabled()
{
- return getModel().isRollover();
+ return rollOverEnabled;
}
/**
Index: javax/swing/JTabbedPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTabbedPane.java,v
retrieving revision 1.3.2.6
diff -u -r1.3.2.6 JTabbedPane.java
--- javax/swing/JTabbedPane.java 15 Jun 2004 17:32:30 -0000 1.3.2.6
+++ javax/swing/JTabbedPane.java 12 Jul 2004 19:25:18 -0000
@@ -312,9 +312,9 @@
*/
public void setComponent(Component c)
{
- JTabbedPane.this.remove(component);
+ remove(component);
this.component = c;
- JTabbedPane.this.add(c);
+ add(c);
}
/**
Index: javax/swing/JToolBar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JToolBar.java,v
retrieving revision 1.3.8.4
diff -u -r1.3.8.4 JToolBar.java
--- javax/swing/JToolBar.java 17 Jun 2004 20:35:55 -0000 1.3.8.4
+++ javax/swing/JToolBar.java 12 Jul 2004 19:25:19 -0000
@@ -38,6 +38,7 @@
package javax.swing;
import java.awt.Component;
+import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
@@ -46,26 +47,31 @@
import java.beans.PropertyChangeListener;
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.swing.plaf.ToolBarUI;
+
/**
- * JToolBar
- * @author Andrew Selkirk
- * @version 1.0
+ * JToolBar is a component that provides a toolbar to Swing programs. Users
+ * can add buttons (or actions that will be represented by JButtons) as well
+ * as other components to the JToolBar. JToolBars can be dragged in and out
+ * of their parent components. If the JToolBar is dragged out of the parent,
+ * then it will be displayed in its own RootPaneContainer. For dragging to
+ * work properly, JToolBars need to be placed in a Container that has a
+ * BorderLayout. That parent Container cannot have components in the NORTH,
+ * EAST, SOUTH, or WEST components (that is not the JToolBar).
*/
-public class JToolBar extends JComponent
- implements SwingConstants, Accessible
+public class JToolBar extends JComponent implements SwingConstants, Accessible
{
/**
* AccessibleJToolBar
*/
protected class AccessibleJToolBar extends AccessibleJComponent
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -5516888265903814215L;
/**
@@ -77,6 +83,7 @@
/**
* getAccessibleStateSet
+ *
* @return AccessibleStateSet
*/
public AccessibleStateSet getAccessibleStateSet()
@@ -86,6 +93,7 @@
/**
* getAccessibleRole
+ *
* @return AccessibleRole
*/
public AccessibleRole getAccessibleRole()
@@ -94,417 +102,686 @@
}
}
- /**
- * Separator
- */
- public static class Separator extends JSeparator {
-
- private static final long serialVersionUID = -1656745644823105219L;
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * separatorSize
- */
- private Dimension size;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor Separator
- */
- public Separator() {
- // TODO
- } // Separator()
-
- /**
- * Constructor Separator
- * @param size TODO
- */
- public Separator(Dimension size) {
- // TODO
- } // Separator()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * getUIClassID
- * @returns String
- */
- public String getUIClassID() {
- return null; // TODO
- } // getUIClassID()
-
- /**
- * getPreferredSize
- * @returns Dimension
- */
- public Dimension getPreferredSize() {
- return null; // TODO
- } // getPreferredSize()
-
- /**
- * getMaximumSize
- * @returns Dimension
- */
- public Dimension getMaximumSize() {
- return null; // TODO
- } // getMaximumSize()
-
- /**
- * getMinimumSize
- * @returns Dimension
- */
- public Dimension getMinimumSize() {
- return null; // TODO
- } // getMinimumSize()
-
- /**
- * getSeparatorSize
- * @returns Dimension
- */
- public Dimension getSeparatorSize() {
- return null; // TODO
- } // getSeparatorSize()
-
- /**
- * setSeparatorSize
- * @param size TODO
- */
- public void setSeparatorSize(Dimension size) {
- // TODO
- } // setSeparatorSize()
-
-
- } // Separator
-
-// /**
-// * DefaultJToolBarLayout
-// */
-// private class DefaultJToolBarLayout {
-//
-// private void DefaultJToolBarLayout() {
-// }
-//
-// private LayoutManager getLayout() {
-// switch (JToolBar.this.getOrientation()) {
-// case HORIZONTAL: setLayout(new GridLayout(1, 0, 4, 4));
-// break;
-// case VERTICAL: setLayout(new GridLayout(0, 1, 4, 4));
-// break;
-// }
-// }
-// } // DefaultJToolBarLayout
-
-
- private static final long serialVersionUID = -1269915519555129643L;
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * uiClassID
- */
- private static final String uiClassID = "ToolBarUI";
-
- /**
- * paintBorder
- */
- private boolean paintBorder;
-
- /**
- * margin
- */
- private Insets margin;
-
- /**
- * floatable
- */
- private boolean floatable;
-
- /**
- * orientation
- */
- private int orientation = HORIZONTAL;
-
-// protected transient DefaultJToolBarLayout toolbarLayout;
-
- /** Fired in a PropertyChangeEvent when the "orientation" property changes.
- */
- public static final String ORIENTATION_CHANGED_PROPERTY = "orientation";
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor JToolBar
- */
- public JToolBar() {
- this(null);
- } // JToolBar()
-
- /**
- * Constructor JToolBar
- * @param orientation JToolBar orientation (HORIZONTAL or VERTICAL)
- */
- public JToolBar(int orientation) {
- this(null, orientation);
- } // JToolBar()
-
- /**
- * Constructor JToolBar
- * @param name Name assigned to undocked tool bar.
- */
- public JToolBar(String name) {
- this(name, HORIZONTAL);
- } // JToolBar()
-
- /**
- * Constructor JToolBar
- * @param name Name assigned to undocked tool bar.
- * @param orientation JToolBar orientation (HORIZONTAL or VERTICAL)
- */
- public JToolBar(String name, int orientation) {
- setName(name);
- if (orientation != HORIZONTAL && orientation != VERTICAL)
- throw new IllegalArgumentException(orientation + " is not a legal orientation");
- this.orientation = orientation;
-// toolbarLayout = new DefaultJToolBarLayout();
- updateUI();
- } // JToolBar()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * writeObject
- * @param stream TODO
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream stream) throws IOException {
- // TODO
- } // writeObject()
-
- /**
- * add
- * @param action TODO
- * @returns JButton
- */
- public JButton add(Action action) {
- return null; // TODO
- } // add()
-
- /**
- * paintBorder
- * @param graphics TODO
- */
- protected void paintBorder(Graphics graphics) {
- // TODO
- } // paintBorder()
-
- /**
- * getUI
- * @returns ToolBarUI
- */
- public ToolBarUI getUI() {
- System.out.println("ui = " + ui);
- return (ToolBarUI) ui;
- } // getUI()
-
- /**
- * setUI
- * @param ui TODO
- */
- public void setUI(ToolBarUI ui) {
- super.setUI(ui);
- } // setUI()
-
- /**
- * updateUI
- */
- public void updateUI() {
- setUI((ToolBarUI)UIManager.getUI(this));
- } // updateUI()
-
- /**
- * getUIClassID
- * @returns String
- */
- public String getUIClassID() {
- return uiClassID;
- } // getUIClassID()
-
- /**
- * getComponentIndex
- * @param component TODO
- * @returns int
- */
- public int getComponentIndex(Component component) {
- return 0; // TODO
- } // getComponentIndex()
-
- /**
- * getComponentAtIndex
- * @param index TODO
- * @returns Component
- */
- public Component getComponentAtIndex(int index) {
- return null; // TODO
- } // getComponentAtIndex()
-
- /**
- * getMargin
- * @returns Insets
- */
- public Insets getMargin() {
- return null; // TODO
- } // getMargin()
-
- /**
- * setMargin
- * @param margin TODO
- */
- public void setMargin(Insets margin) {
- // TODO
- } // setMargin()
-
- /**
- * isBorderPainted
- * @returns boolean
- */
- public boolean isBorderPainted() {
- return false; // TODO
- } // isBorderPainted()
-
- /**
- * setBorderPainted
- * @param painted TODO
- */
- public void setBorderPainted(boolean painted) {
- // TODO
- } // setBorderPainted()
-
- /**
- * isFloatable
- * @returns boolean
- */
- public boolean isFloatable() {
- return false; // TODO
- } // isFloatable()
-
- /**
- * setFloatable
- * @param floatable TODO
- */
- public void setFloatable(boolean floatable) {
- // TODO
- } // setFloatable()
-
- /**
- * getOrientation
- * @returns int
- */
- public int getOrientation() {
- return this.orientation;
- } // getOrientation()
-
- /**
- * setLayout
- * @param mgr
- */
- public void setLayout(LayoutManager mgr) {
- super.setLayout(mgr);
- } // setLayout()
-
- /**
- * setOrientation
- * @param orientation
- */
- public void setOrientation(int orientation) {
- if (orientation != HORIZONTAL && orientation != VERTICAL)
- throw new IllegalArgumentException(orientation + " is not a legal orientation");
- if (orientation != this.orientation)
+ /**
+ * This is the private JToolBar layout manager.
+ */
+ private class DefaultToolBarLayout implements LayoutManager
+ {
+ /**
+ * This method is called when a new component is added to the container.
+ *
+ * @param name The name of the component added.
+ * @param comp The component that was added.
+ */
+ public void addLayoutComponent(String name, Component comp)
+ {
+ // Do nothing.
+ }
+
+ /**
+ * This method is called to lay out the given container to position and
+ * size the child components.
+ *
+ * @param c The container to lay out.
+ *
+ * @throws Error DOCUMENT ME!
+ */
+ public void layoutContainer(Container c)
+ {
+ if (! (c instanceof JToolBar))
+ throw new Error("DefaultToolBarLayout can only be used on JToolBars.");
+ Insets insets = getInsets();
+ Insets margin = getMargin();
+ int middle;
+ if (margin != null)
+ {
+ insets.left += margin.left;
+ insets.top += margin.top;
+ insets.bottom += margin.bottom;
+ insets.right += margin.right;
+ }
+ Component[] components = c.component;
+ Dimension tdims = c.getSize();
+ int start = 0;
+ Dimension pref;
+
+ if (getOrientation() == SwingUtilities.HORIZONTAL)
+ {
+ start += insets.left;
+ for (int i = 0; i < components.length; i++)
{
- int oldOrientation = this.orientation;
- this.orientation = orientation;
- firePropertyChange(ORIENTATION_CHANGED_PROPERTY, oldOrientation,
- this.orientation);
+ if (components[i] != null && components[i].isVisible())
+ {
+ pref = components[i].getPreferredSize();
+ if (pref != null)
+ {
+ middle = (tdims.height - pref.height) / 2;
+ components[i].setBounds(start, middle, pref.width,
+ pref.height);
+ start += pref.width;
+ }
+ }
}
- } // setOrientation()
+ }
+ else
+ {
+ start += insets.top;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] != null && components[i].isVisible())
+ {
+ pref = components[i].getPreferredSize();
+ if (pref != null)
+ {
+ middle = (tdims.width - pref.width) / 2;
+ components[i].setBounds(middle, start, pref.width,
+ pref.height);
+ start += pref.height;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * This method returns the minimum size of the given container given the
+ * child components.
+ *
+ * @param parent The container to measure.
+ *
+ * @return The minimum size of the given container.
+ */
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ return preferredLayoutSize(parent);
+ }
+
+ /**
+ * This method returns the preferred size of the given container given the
+ * child components.
+ *
+ * @param parent The container to measure.
+ *
+ * @return The preferred size of the given container.
+ */
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ int orientation = getOrientation();
+ Component[] components = getComponents();
+
+ int limit = 0;
+ int total = 0;
+ Dimension dims;
+
+ int w = 0;
+ int h = 0;
+
+ if (orientation == SwingConstants.HORIZONTAL)
+ {
+ for (int i = 0; i < components.length; i++)
+ {
+ dims = components[i].getPreferredSize();
+ if (dims != null)
+ {
+ if (dims.height > limit)
+ limit = dims.height;
+ total += dims.width;
+ }
+ }
+ w = total;
+ h = limit;
+ }
+ else
+ {
+ for (int i = 0; i < components.length; i++)
+ {
+ dims = components[i].getPreferredSize();
+ if (dims != null)
+ {
+ if (dims.width > limit)
+ limit = dims.width;
+ total += dims.height;
+ }
+ }
+ w = limit;
+ h = total;
+ }
+
+ Insets insets = getInsets();
+ w += insets.left + insets.right;
+ h += insets.top + insets.bottom;
+
+ Insets margin = getMargin();
+ if (margin != null)
+ {
+ w += margin.left + margin.right;
+ h += margin.top + margin.bottom;
+ }
+
+ return new Dimension(w, h);
+ }
+
+ /**
+ * This method is called when the given component is removed from the
+ * container.
+ *
+ * @param comp The component removed.
+ */
+ public void removeLayoutComponent(Component comp)
+ {
+ // Do nothing.
+ }
+ }
+
+ /**
+ * This is an extension of JSeparator used in toolbars. Unlike JSeparator,
+ * nothing is painted for this Separator, it is only blank space that
+ * separates components.
+ */
+ public static class Separator extends JSeparator
+ {
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = -1656745644823105219L;
+
+ /**
+ * Creates a new Separator object.
+ */
+ public Separator()
+ {
+ super();
+ } // Separator()
+
+ /**
+ * Creates a new Separator object with the given size.
+ *
+ * @param size The size of the separator.
+ */
+ public Separator(Dimension size)
+ {
+ setPreferredSize(size);
+ } // Separator()
+
+ /**
+ * This method returns the String ID of the UI class of Separator.
+ *
+ * @return The UI class' String ID.
+ */
+ public String getUIClassID()
+ {
+ return "ToolBarSeparatorUI";
+ } // getUIClassID()
+
+ /**
+ * This method returns the preferred size of the Separator.
+ *
+ * @return The preferred size of the Separator.
+ */
+ public Dimension getPreferredSize()
+ {
+ return super.getPreferredSize();
+ } // getPreferredSize()
+
+ /**
+ * This method returns the maximum size of the Separator.
+ *
+ * @return The maximum size of the Separator.
+ */
+ public Dimension getMaximumSize()
+ {
+ return super.getPreferredSize();
+ } // getMaximumSize()
+
+ /**
+ * This method returns the minimum size of the Separator.
+ *
+ * @return The minimum size of the Separator.
+ */
+ public Dimension getMinimumSize()
+ {
+ return super.getPreferredSize();
+ } // getMinimumSize()
+
+ /**
+ * This method returns the size of the Separator.
+ *
+ * @return The size of the Separator.
+ */
+ public Dimension getSeparatorSize()
+ {
+ return super.getPreferredSize();
+ } // getSeparatorSize()
+
+ /**
+ * This method sets the size of the Separator.
+ *
+ * @param size The new size of the Separator.
+ */
+ public void setSeparatorSize(Dimension size)
+ {
+ setPreferredSize(size);
+ } // setSeparatorSize()
+ } // Separator
+
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = -1269915519555129643L;
+
+ /** Whether the JToolBar paints its border. */
+ private transient boolean paintBorder = true;
+
+ /** The extra insets around the JToolBar. */
+ private transient Insets margin;
+
+ /** Whether the JToolBar can float (and be dragged around). */
+ private transient boolean floatable = true;
+
+ /** Whether the buttons will have rollover borders. */
+ private transient boolean rollover;
+
+ /** The orientation of the JToolBar. */
+ private int orientation = HORIZONTAL;
+
+ /** Fired in a PropertyChangeEvent when the orientation property changes. */
+ public static final String ORIENTATION_CHANGED_PROPERTY = "orientation";
+
+ /** Fired in a PropertyChangeEvent when the floatable property changes. */
+ public static final String FLOATABLE_CHANGED_PROPERTY = "floatable";
+
+ /** Fired in a PropertyChangeEvent when the borderPainted property changes. */
+ public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted";
+
+ /** Fired in a PropertyChangeEvent when the margin property changes. */
+ public static final String MARGIN_CHANGED_PROPERTY = "margin";
+
+ /** Fired in a PropertyChangeEvent when the rollover property changes. */
+ public static final String ROLLOVER_CHANGED_PROPERTY = "rollover";
+
+ /**
+ * This method creates a new JToolBar object with horizontal orientation
+ * and no name.
+ */
+ public JToolBar()
+ {
+ this(null, HORIZONTAL);
+ } // JToolBar()
+
+ /**
+ * This method creates a new JToolBar with the given orientation and no
+ * name.
+ *
+ * @param orientation JToolBar orientation (HORIZONTAL or VERTICAL)
+ */
+ public JToolBar(int orientation)
+ {
+ this(null, orientation);
+ } // JToolBar()
+
+ /**
+ * This method creates a new JToolBar object with the given name and
+ * horizontal orientation.
+ *
+ * @param name Name assigned to undocked tool bar.
+ */
+ public JToolBar(String name)
+ {
+ this(name, HORIZONTAL);
+ } // JToolBar()
+
+ /**
+ * This method creates a new JToolBar object with the given name and
+ * orientation.
+ *
+ * @param name Name assigned to undocked tool bar.
+ * @param orientation JToolBar orientation (HORIZONTAL or VERTICAL)
+ */
+ public JToolBar(String name, int orientation)
+ {
+ setName(name);
+ setOrientation(orientation);
+ setLayout(new DefaultToolBarLayout());
+ revalidate();
+ updateUI();
+ } // JToolBar()
+
+ /**
+ * This method adds a new JButton that performs the given Action to the
+ * JToolBar.
+ *
+ * @param action The Action to add to the JToolBar.
+ *
+ * @return The JButton that wraps the Action.
+ */
+ public JButton add(Action action)
+ {
+ JButton b = createActionComponent(action);
+ add(b);
+ return b;
+ } // add()
+
+ /**
+ * This method paints the border if the borderPainted property is true.
+ *
+ * @param graphics The graphics object to paint with.
+ */
+ protected void paintBorder(Graphics graphics)
+ {
+ if (paintBorder && isFloatable())
+ super.paintBorder(graphics);
+ } // paintBorder()
+
+ /**
+ * This method returns the UI class used to paint this JToolBar.
+ *
+ * @return The UI class for this JToolBar.
+ */
+ public ToolBarUI getUI()
+ {
+ return (ToolBarUI) ui;
+ } // getUI()
+
+ /**
+ * This method sets the UI used with the JToolBar.
+ *
+ * @param ui The UI used with the JToolBar.
+ */
+ public void setUI(ToolBarUI ui)
+ {
+ super.setUI(ui);
+ } // setUI()
+
+ /**
+ * This method resets the UI used to the Look and Feel defaults.
+ */
+ public void updateUI()
+ {
+ setUI((ToolBarUI) UIManager.getUI(this));
+ revalidate();
+ repaint();
+ } // updateUI()
+
+ /**
+ * This method returns the String identifier for the UI class to the used
+ * with the JToolBar.
+ *
+ * @return The String identifier for the UI class.
+ */
+ public String getUIClassID()
+ {
+ return "ToolBarUI";
+ } // getUIClassID()
+
+ /**
+ * This method sets the rollover property for the JToolBar. In rollover
+ * mode, JButtons inside the JToolBar will only display their borders when
+ * the mouse is moving over them.
+ *
+ * @param b The new rollover property.
+ */
+ public void setRollover(boolean b)
+ {
+ if (b != rollover)
+ {
+ rollover = b;
+ firePropertyChange(ROLLOVER_CHANGED_PROPERTY, ! rollover, rollover);
+ revalidate();
+ repaint();
+ }
+ }
+
+ /**
+ * This method returns the rollover property.
+ *
+ * @return The rollover property.
+ */
+ public boolean isRollover()
+ {
+ return rollover;
+ }
+
+ /**
+ * This method returns the index of the given component.
+ *
+ * @param component The component to find.
+ *
+ * @return The index of the given component.
+ */
+ public int getComponentIndex(Component component)
+ {
+ Component[] components = getComponents();
+ if (components == null)
+ return -1;
+
+ for (int i = 0; i < components.length; i++)
+ if (components[i] == component)
+ return i;
+
+ return -1;
+ } // getComponentIndex()
+
+ /**
+ * This method returns the component at the given index.
+ *
+ * @param index The index of the component.
+ *
+ * @return The component at the given index.
+ */
+ public Component getComponentAtIndex(int index)
+ {
+ return getComponent(index);
+ } // getComponentAtIndex()
+
+ /**
+ * This method returns the margin property.
+ *
+ * @return The margin property.
+ */
+ public Insets getMargin()
+ {
+ return margin;
+ } // getMargin()
+
+ /**
+ * This method sets the margin property. The margin property determines the
+ * extra space between the children components of the JToolBar and the
+ * border.
+ *
+ * @param margin The margin property.
+ */
+ public void setMargin(Insets margin)
+ {
+ if ((this.margin != null && margin == null)
+ || (this.margin == null && margin != null)
+ || (margin != null && this.margin != null
+ && (margin.left != this.margin.left
+ || margin.right != this.margin.right || margin.top != this.margin.top
+ || margin.bottom != this.margin.bottom)))
+ {
+ Insets oldMargin = this.margin;
+ this.margin = margin;
+ firePropertyChange(MARGIN_CHANGED_PROPERTY, oldMargin, this.margin);
+ revalidate();
+ repaint();
+ }
+ } // setMargin()
+
+ /**
+ * This method returns the borderPainted property.
+ *
+ * @return The borderPainted property.
+ */
+ public boolean isBorderPainted()
+ {
+ return paintBorder;
+ } // isBorderPainted()
+
+ /**
+ * This method sets the borderPainted property. If set to false, the border
+ * will not be painted.
+ *
+ * @param painted Whether the border will be painted.
+ */
+ public void setBorderPainted(boolean painted)
+ {
+ if (painted != paintBorder)
+ {
+ paintBorder = painted;
+ firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, ! paintBorder,
+ paintBorder);
+ repaint();
+ }
+ } // setBorderPainted()
+
+ /**
+ * This method returns the floatable property.
+ *
+ * @return The floatable property.
+ */
+ public boolean isFloatable()
+ {
+ return floatable;
+ } // isFloatable()
+
+ /**
+ * This method sets the floatable property. If set to false, the JToolBar
+ * cannot be dragged.
+ *
+ * @param floatable Whether the JToolBar can be dragged.
+ */
+ public void setFloatable(boolean floatable)
+ {
+ if (floatable != this.floatable)
+ {
+ this.floatable = floatable;
+ firePropertyChange(FLOATABLE_CHANGED_PROPERTY, ! floatable, floatable);
+ }
+ } // setFloatable()
- /**
- * addSeparator
- */
- public void addSeparator() {
- // TODO
- } // addSeparator()
-
- /**
- * addSeparator
- * @param size TODO
- */
- public void addSeparator(Dimension size) {
- // TODO
- } // addSeparator()
-
- /**
- * createActionComponent
- * @param action TODO
- * @returns JButton
- */
- protected JButton createActionComponent(Action action) {
- return null; // TODO
- } // createActionComponent()
-
- /**
- * createActionChangeListener
- * @param button TODO
- * @returns PropertyChangeListener
- */
- protected PropertyChangeListener createActionChangeListener(JButton button) {
- return null; // TODO
- } // createActionChangeListener()
-
- /**
- * addImpl
- * @param component TODO
- * @param constraints TODO
- * @param index TODO
- */
- /*
- protected void addImpl(Component component, Object constraints, int index) {
- // TODO
- } // addImpl()
- */
- /**
- * paramString
- * @returns String
- */
- protected String paramString() {
- return null; // TODO
- } // paramString()
+ /**
+ * This method returns the orientation of the JToolBar.
+ *
+ * @return The orientation of the JToolBar.
+ */
+ public int getOrientation()
+ {
+ return orientation;
+ } // getOrientation()
+
+ /**
+ * This method sets the layout manager to be used with the JToolBar.
+ *
+ * @param mgr The Layout Manager used with the JToolBar.
+ */
+ public void setLayout(LayoutManager mgr)
+ {
+ super.setLayout(mgr);
+ revalidate();
+ repaint();
+ } // setLayout()
+
+ /**
+ * This method sets the orientation property for JToolBar.
+ *
+ * @param orientation The new orientation for JToolBar.
+ *
+ * @throws IllegalArgumentException If the orientation is not HORIZONTAL or
+ * VERTICAL.
+ */
+ public void setOrientation(int orientation)
+ {
+ if (orientation != HORIZONTAL && orientation != VERTICAL)
+ throw new IllegalArgumentException(orientation
+ + " is not a legal orientation");
+ if (orientation != this.orientation)
+ {
+ int oldOrientation = this.orientation;
+ this.orientation = orientation;
+ firePropertyChange(ORIENTATION_CHANGED_PROPERTY, oldOrientation,
+ this.orientation);
+ revalidate();
+ repaint();
+ }
+ } // setOrientation()
+
+ /**
+ * This method adds a Separator of default size to the JToolBar.
+ */
+ public void addSeparator()
+ {
+ add(new Separator());
+ } // addSeparator()
+
+ /**
+ * This method adds a Separator with the given size to the JToolBar.
+ *
+ * @param size The size of the Separator.
+ */
+ public void addSeparator(Dimension size)
+ {
+ add(new Separator(size));
+ } // addSeparator()
+
+ /**
+ * This method is used to create JButtons which can be added to the JToolBar
+ * for the given action.
+ *
+ * @param action The action to create a JButton for.
+ *
+ * @return The JButton created from the action.
+ */
+ protected JButton createActionComponent(Action action)
+ {
+ return new JButton(action);
+ } // createActionComponent()
+
+ /**
+ * This method creates a pre-configured PropertyChangeListener which updates
+ * the control as changes are made to the Action. However, this is no
+ * longer the recommended way of adding Actions to Containers. As such,
+ * this method returns null.
+ *
+ * @param button The JButton to configure a PropertyChangeListener for.
+ *
+ * @return null.
+ */
+ protected PropertyChangeListener createActionChangeListener(JButton button)
+ {
+ // XXX: As specified, this returns null. But seems kind of strange, usually deprecated methods don't just return null, verify!
+ return null;
+ } // createActionChangeListener()
+
+ /**
+ * This method overrides Container's addImpl method. If a JButton is added,
+ * it is disabled.
+ *
+ * @param component The Component to add.
+ * @param constraints The Constraints placed on the component.
+ * @param index The index to place the Component at.
+ */
+ protected void addImpl(Component component, Object constraints, int index)
+ {
+ // XXX: Sun says disable button but test cases show otherwise.
+ super.addImpl(component, constraints, index);
+ } // addImpl()
+
+ /**
+ * This method returns a String description of the JToolBar.
+ *
+ * @return A String description of the JToolBar.
+ */
+ protected String paramString()
+ {
+ return "JToolBar";
+ } // paramString()
/**
* getAccessibleContext
+ *
* @return AccessibleContext
*/
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
accessibleContext = new AccessibleJToolBar();
-
+
return accessibleContext;
}
}
Index: javax/swing/plaf/basic/BasicArrowButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicArrowButton.java,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 BasicArrowButton.java
--- javax/swing/plaf/basic/BasicArrowButton.java 10 Jun 2004 06:56:47 -0000 1.1.2.2
+++ javax/swing/plaf/basic/BasicArrowButton.java 12 Jul 2004 19:25:19 -0000
@@ -40,9 +40,11 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
+import java.awt.Insets;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.Rectangle;
+import javax.swing.border.Border;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.SwingConstants;
@@ -169,6 +171,47 @@
/** The top and left edges of the button. */
private transient Color highlight = Color.BLACK;
+
+ /** The border around the ArrowButton. */
+ private transient Border tmpBorder = new Border()
+ {
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ public boolean isBorderOpaque()
+ {
+ return false;
+ }
+
+ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
+ {
+ Rectangle bounds = getBounds();
+
+ Color saved = g.getColor();
+ g.setColor(highlight);
+
+ g.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height);
+ g.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y);
+
+ g.setColor(shadow);
+
+ g.drawLine(bounds.x + 1, bounds.y + bounds.height - 1,
+ bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
+ g.drawLine(bounds.x + bounds.width - 1, bounds.y + 1,
+ bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
+
+ g.setColor(darkShadow);
+
+ g.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width,
+ bounds.y + bounds.height);
+ g.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width,
+ bounds.y + bounds.height);
+
+ g.setColor(saved);
+ }
+ };
/**
* Creates a new BasicArrowButton object.
@@ -179,6 +222,7 @@
{
super();
setDirection(direction);
+ setBorder(tmpBorder);
}
/**
@@ -234,29 +278,6 @@
public void paint(Graphics g)
{
super.paint(g);
- Rectangle bounds = getBounds();
-
- Color saved = g.getColor();
- g.setColor(highlight);
-
- g.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height);
- g.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y);
-
- g.setColor(shadow);
-
- g.drawLine(bounds.x + 1, bounds.y + bounds.height - 1,
- bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
- g.drawLine(bounds.x + bounds.width - 1, bounds.y + 1,
- bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
-
- g.setColor(darkShadow);
-
- g.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width,
- bounds.y + bounds.height);
- g.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width,
- bounds.y + bounds.height);
-
- g.setColor(saved);
}
/**
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.14
diff -u -r1.4.2.14 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java 10 Jul 2004 17:53:04 -0000 1.4.2.14
+++ javax/swing/plaf/basic/BasicLookAndFeel.java 12 Jul 2004 19:25:20 -0000
@@ -875,12 +875,12 @@
"ToolBar.background", new ColorUIResource(Color.lightGray),
"ToolBar.border", new BorderUIResource.EtchedBorderUIResource(),
"ToolBar.dockingBackground", new ColorUIResource(Color.lightGray),
- "ToolBar.dockingForeground", new ColorUIResource(Color.red),
+ "ToolBar.dockingForeground", new ColorUIResource(11, 30, 143),
"ToolBar.floatingBackground", new ColorUIResource(Color.lightGray),
- "ToolBar.floatingForeground", new ColorUIResource(Color.darkGray),
+ "ToolBar.floatingForeground", new ColorUIResource(113, 171, 212),
"ToolBar.font", new FontUIResource("Dialog", Font.PLAIN, 12),
"ToolBar.foreground", new ColorUIResource(Color.black),
- "ToolBar.separatorSize", new DimensionUIResource(10, 10),
+ "ToolBar.separatorSize", new DimensionUIResource(20, 20),
"ToolTip.background", new ColorUIResource(Color.white),
"ToolTip.border", new BorderUIResource.LineBorderUIResource(Color.lightGray),
"ToolTip.font", new FontUIResource("SansSerif", Font.PLAIN, 12),
Index: javax/swing/plaf/basic/BasicOptionPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicOptionPaneUI.java,v
retrieving revision 1.6.8.1
diff -u -r1.6.8.1 BasicOptionPaneUI.java
--- javax/swing/plaf/basic/BasicOptionPaneUI.java 3 May 2004 19:11:00 -0000 1.6.8.1
+++ javax/swing/plaf/basic/BasicOptionPaneUI.java 12 Jul 2004 19:25:21 -0000
@@ -111,7 +111,7 @@
Object value = new Integer(JOptionPane.CLOSED_OPTION);
Object[] options = optionPane.getOptions();
if (options != null)
- value = options[buttonIndex];
+ value = new Integer(buttonIndex);
else
{
String text = ((JButton) e.getSource()).getText();
@@ -642,10 +642,10 @@
toAdd = new JButton((Icon) buttons[i]);
else
toAdd = new JButton(buttons[i].toString());
- ((JButton) toAdd).addActionListener(createButtonActionListener(i));
hasCustomComponents = true;
}
-
+ if (toAdd instanceof JButton)
+ ((JButton) toAdd).addActionListener(createButtonActionListener(i));
if (i == initialIndex)
initialFocusComponent = toAdd;
container.add(toAdd);
@@ -808,7 +808,7 @@
buttonPanel.setLayout(createLayoutManager());
addButtonComponents(buttonPanel, getButtons(), getInitialValueIndex());
-
+
return buttonPanel;
}
@@ -856,10 +856,13 @@
{
Object[] selection = optionPane.getSelectionValues();
- if (selection == null)
- inputComponent = new JTextField();
- else if (selection.length < 20)
- inputComponent = new JComboBox(selection);
+// if (selection == null)
+// inputComponent = new JTextField();
+// else if (selection.length < 20)
+// inputComponent = new JComboBox(selection);
+ // FIXME: Uncomment when the widgets are done.
+ if (selection == null)
+ inputComponent = null;
else
inputComponent = new JList(selection);
if (inputComponent != null)
@@ -972,7 +975,9 @@
tmp = questionIcon;
break;
}
- return new IconUIResource(tmp);
+ return tmp;
+ // FIXME: Don't cast till the default icons are in.
+ // return new IconUIResource(tmp);
}
/**
Index: javax/swing/plaf/basic/BasicSliderUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicSliderUI.java,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 BasicSliderUI.java
--- javax/swing/plaf/basic/BasicSliderUI.java 10 Jun 2004 10:32:39 -0000 1.1.2.10
+++ javax/swing/plaf/basic/BasicSliderUI.java 12 Jul 2004 19:25:22 -0000
@@ -390,9 +390,6 @@
if (slider.getSnapToTicks())
value = findClosestTick(value);
- if (value == slider.getValue())
- return;
-
// If the thumb is hit, then we don't need to set the timers to move it.
if (!thumbRect.contains(e.getPoint()))
{
@@ -1662,8 +1659,11 @@
Rectangle tickBounds, int x)
{
int y = tickRect.y + tickRect.height / 4;
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
g.drawLine(x, y, x, y + tickRect.height / 4);
+ g.setColor(saved);
}
/**
@@ -1678,8 +1678,11 @@
Rectangle tickBounds, int x)
{
int y = tickRect.y + tickRect.height / 4;
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
g.drawLine(x, y, x, y + tickRect.height / 2);
+ g.setColor(saved);
}
/**
@@ -1694,8 +1697,11 @@
int y)
{
int x = tickRect.x + tickRect.width / 4;
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
g.drawLine(x, y, x + tickRect.width / 4, y);
+ g.setColor(saved);
}
/**
@@ -1710,8 +1716,11 @@
int y)
{
int x = tickRect.x + tickRect.width / 4;
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
g.drawLine(x, y, x + tickRect.width / 2, y);
+ g.setColor(saved);
}
/**
Index: javax/swing/plaf/basic/BasicSplitPaneDivider.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicSplitPaneDivider.java,v
retrieving revision 1.1.26.2
diff -u -r1.1.26.2 BasicSplitPaneDivider.java
--- javax/swing/plaf/basic/BasicSplitPaneDivider.java 9 Jun 2004 09:40:32 -0000 1.1.26.2
+++ javax/swing/plaf/basic/BasicSplitPaneDivider.java 12 Jul 2004 19:25:22 -0000
@@ -156,6 +156,29 @@
/** Keeps track of where the divider should be placed when using one touch expand
* buttons. */
private transient int currentDividerLocation = 1;
+
+ private transient Border tmpBorder = new Border()
+ {
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(2, 2, 2, 2);
+ }
+
+ public boolean isBorderOpaque()
+ {
+ return false;
+ }
+
+ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
+ {
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
+
+ g.drawRect(x + 2, y + 2, width - 4, height - 4);
+
+ g.setColor(saved);
+ }
+ };
/**
* Constructs a new divider.
@@ -167,6 +190,7 @@
setLayout(new DividerLayout());
setBasicSplitPaneUI(ui);
setDividerSize(splitPane.getDividerSize());
+ setBorder(tmpBorder);
}
/**
Index: javax/swing/plaf/basic/BasicSplitPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicSplitPaneUI.java,v
retrieving revision 1.1.26.1
diff -u -r1.1.26.1 BasicSplitPaneUI.java
--- javax/swing/plaf/basic/BasicSplitPaneUI.java 19 Apr 2004 19:46:05 -0000 1.1.26.1
+++ javax/swing/plaf/basic/BasicSplitPaneUI.java 12 Jul 2004 19:25:23 -0000
@@ -1267,10 +1267,6 @@
- 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);
Index: javax/swing/plaf/basic/BasicToolBarSeparatorUI.java
===================================================================
RCS file: javax/swing/plaf/basic/BasicToolBarSeparatorUI.java
diff -N javax/swing/plaf/basic/BasicToolBarSeparatorUI.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/basic/BasicToolBarSeparatorUI.java 12 Jul 2004 19:25:23 -0000
@@ -0,0 +1,132 @@
+/* BasicToolBarSeparatorUI.java
+ Copyright (C) 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.plaf.basic;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Rectangle;
+import javax.swing.JComponent;
+import javax.swing.JToolBar.Separator;
+import javax.swing.JSeparator;
+import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.SeparatorUI;
+
+
+/**
+ * The Basic Look and Feel UI delegate for Separator.
+ */
+public class BasicToolBarSeparatorUI extends BasicSeparatorUI
+{
+ private transient Dimension size;
+
+ /**
+ * Creates a new UI delegate for the given JComponent.
+ *
+ * @param c The JComponent to create a delegate for.
+ *
+ * @return A new BasicToolBarSeparatorUI.
+ */
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicToolBarSeparatorUI();
+ }
+
+ /**
+ * This method installs the defaults that are given by the Basic L&F.
+ *
+ * @param s The Separator that is being installed.
+ */
+ protected void installDefaults(JSeparator s)
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+ size = defaults.getDimension("ToolBar.separatorSize");
+ }
+
+ /**
+ * This method does nothing as a Separator is just blank space.
+ *
+ * @param g The Graphics object to paint with
+ * @param c The JComponent to paint.
+ */
+ public void paint(Graphics g, JComponent c)
+ {
+ // Do nothing.
+ }
+
+ /**
+ * This method returns the preferred size of the JComponent.
+ *
+ * @param c The JComponent to measure.
+ *
+ * @return The preferred size.
+ */
+ public Dimension getPreferredSize(JComponent c)
+ {
+ return size;
+ }
+
+ /**
+ * This method returns the minimum size of the JComponent.
+ *
+ * @param c The JComponent to measure.
+ *
+ * @return The minimum size.
+ */
+ public Dimension getMinimumSize(JComponent c)
+ {
+ return size;
+ }
+
+ /**
+ * This method returns the maximum size of the JComponent.
+ *
+ * @param c The JComponent to measure.
+ *
+ * @return The maximum size.
+ */
+ public Dimension getMaximumSize(JComponent c)
+ {
+ return size;
+ }
+}
Index: javax/swing/plaf/basic/BasicToolBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicToolBarUI.java,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 BasicToolBarUI.java
--- javax/swing/plaf/basic/BasicToolBarUI.java 10 Jul 2004 17:53:04 -0000 1.1.2.4
+++ javax/swing/plaf/basic/BasicToolBarUI.java 12 Jul 2004 19:25:23 -0000
@@ -37,310 +37,1398 @@
package javax.swing.plaf.basic;
+import java.awt.BorderLayout;
+import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
-import java.awt.Color;
import java.awt.Dimension;
+import java.awt.Graphics;
import java.awt.GridLayout;
+import java.awt.Insets;
import java.awt.Point;
+import java.awt.Rectangle;
import java.awt.Window;
+import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
+import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Enumeration;
-
-import javax.swing.JFrame;
+import java.util.Hashtable;
import javax.swing.JButton;
import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
import javax.swing.JToolBar;
import javax.swing.RootPaneContainer;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
-import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.event.MouseInputListener;
+import javax.swing.plaf.BorderUIResource;
+import javax.swing.plaf.BorderUIResource.EtchedBorderUIResource;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.ToolBarUI;
+import javax.swing.plaf.UIResource;
-public class BasicToolBarUI extends ToolBarUI
- implements SwingConstants
+
+/**
+ * This is the Basic Look and Feel UI class for JToolBar.
+ */
+public class BasicToolBarUI extends ToolBarUI implements SwingConstants
{
- public class DragWindow extends Window
+ /** The border used when the JToolBar is in nonrollover mode. */
+ private static Border nonRolloverBorder;
+
+ /** The border used when the JToolBar is in rollover mode. */
+ private static Border rolloverBorder;
+
+ /** The last known BorderLayout constraint before floating. */
+ protected String constraintBeforeFloating;
+
+ /** The last known orientation of the JToolBar before floating. */
+ private int lastGoodOrientation;
+
+ /** The color of the border when it is dockable. */
+ protected Color dockingBorderColor;
+
+ /** The background color of the JToolBar when it is dockable. */
+ protected Color dockingColor;
+
+ /** The docking listener responsible for mouse events on the JToolBar. */
+ protected MouseInputListener dockingListener;
+
+ /** The window used for dragging the JToolBar. */
+ protected BasicToolBarUI.DragWindow dragWindow;
+
+ /** The color of the border when it is not dockable. */
+ protected Color floatingBorderColor;
+
+ /** The background color of the JToolBar when it is not dockable. */
+ protected Color floatingColor;
+
+ /** The index of the focused component. */
+ protected int focusedCompIndex;
+
+ /** The PropertyChangeListener for the JToolBar. */
+ protected PropertyChangeListener propertyListener;
+
+ /** The JToolBar this UI delegate is responsible for. */
+ protected JToolBar toolBar;
+
+ /** The Container listener for the JToolBar. */
+ protected ContainerListener toolBarContListener;
+
+ /** The Focus listener for the JToolBar. */
+ protected FocusListener toolBarFocusListener;
+
+ /**
+ * The floating window that is responsible for holding the JToolBar when it
+ * is dragged outside of its original parent.
+ */
+ private transient Window floatFrame;
+
+ /** The original parent of the JToolBar. */
+ private transient Container origParent;
+
+ /** A hashtable of components and their original borders. */
+ private transient Hashtable borders;
+
+ /** A window listener for the floatable frame. */
+ private transient WindowListener windowListener;
+
+ /** A set of cached bounds of the JToolBar. */
+ private transient Dimension cachedBounds;
+
+ /** The cached orientation of the JToolBar. */
+ private transient int cachedOrientation;
+
+ /**
+ * This method creates a new BasicToolBarUI object for the given JToolBar.
+ *
+ * @param b The JToolBar to represent with this UI.
+ */
+ public BasicToolBarUI(JToolBar b)
{
- public DragWindow()
- {
- super(null); // this throws
- }
+ super();
}
- protected String constraintBeforeFloating;
- protected Color dockingBorderColor;
- protected Color dockingColor;
- protected MouseInputListener dockingListener;
- //protected KeyStroke downKey
- // Deprecated. As of Java 2 platform v1.3.
- protected BasicToolBarUI.DragWindow dragWindow;
- protected Color floatingBorderColor;
- protected Color floatingColor;
- protected int focusedCompIndex;
- //protected KeyStroke leftKey;
- // Deprecated. As of Java 2 platform v1.3.
- protected PropertyChangeListener propertyListener;
- //protected KeyStroke rightKey;
- // Deprecated. As of Java 2 platform v1.3.
- protected JToolBar toolBar;
- protected ContainerListener toolBarContListener;
- protected FocusListener toolBarFocusListener;
- // protected KeyStroke upKey;
- // Deprecated. As of Java 2 platform v1.3.
+ /**
+ * This method returns whether the JToolBar can dock at the given position.
+ *
+ * @param c The component to try to dock in.
+ * @param p The position of the mouse cursor relative to the given
+ * component.
+ *
+ * @return Whether the JToolBar can dock.
+ */
+ protected boolean canDock(Component c, Point p)
+ {
+ if (areaOfClick(c, p) != -1)
+ return true;
- private Dimension maximumSize;
- private Dimension minimumSize;
- private Dimension preferredSize;
- private boolean floating;
- private boolean rolloverBorders;
+ return false;
+ }
- BasicToolBarUI(JToolBar b)
- {
- super();
- }
+ /**
+ * This helper method returns the position of the JToolBar if it can dock.
+ *
+ * @param c The component to try to dock in.
+ * @param p The position of the mouse cursor relative to the given
+ * component.
+ *
+ * @return One of the SwingConstants directions or -1 if the JToolBar can't
+ * dock.
+ */
+ private int areaOfClick(Component c, Point p)
+ {
+ // Has to dock in immediate parent, not eventual root container.
+ Rectangle pBounds = c.getBounds();
- /* Can Component c dock at Point p? */
- boolean canDock(Component c, Point p)
- {
- return false;
- }
+ // XXX: In Sun's implementation, the space the toolbar has to dock is dependent on the size it had last.
+ Dimension d = toolBar.getSize();
+ int limit = Math.min(d.width, d.height);
- protected MouseInputListener createDockingListener()
- {
- return null;
- }
+ // The order of checking is 1. top 2. bottom 3. left 4. right
+ if (! pBounds.contains(p))
+ return -1;
- protected BasicToolBarUI.DragWindow createDragWindow(JToolBar toolbar)
- {
- return null;
- }
+ if (p.y < limit)
+ return SwingConstants.NORTH;
- protected JFrame createFloatingFrame(JToolBar toolbar)
- {
- return null;
- }
+ if (p.y > (pBounds.height - limit))
+ return SwingConstants.SOUTH;
- protected RootPaneContainer createFloatingWindow(JToolBar toolbar)
- {
- return null;
- }
+ if (p.x < limit)
+ return SwingConstants.WEST;
- protected WindowListener createFrameListener()
- {
- return null;
- }
+ if (p.x > (pBounds.width - limit))
+ return SwingConstants.EAST;
- protected Border createNonRolloverBorder()
- {
- return null;
- }
+ return -1;
+ }
- protected PropertyChangeListener createPropertyListener()
- {
- return null;
- }
+ /**
+ * This method creates a new DockingListener for the JToolBar.
+ *
+ * @return A new DockingListener for the JToolBar.
+ */
+ protected MouseInputListener createDockingListener()
+ {
+ return new DockingListener(toolBar);
+ }
- protected Border createRolloverBorder()
- {
- return null;
- }
+ /**
+ * This method creates a new DragWindow for the given JToolBar.
+ *
+ * @param toolbar The JToolBar to create a DragWindow for.
+ *
+ * @return A new DragWindow.
+ */
+ protected BasicToolBarUI.DragWindow createDragWindow(JToolBar toolbar)
+ {
+ return new DragWindow();
+ }
- protected ContainerListener createToolBarContListener()
- {
- return null;
- }
+ /**
+ * This method creates a new floating frame for the JToolBar. By default,
+ * this UI uses createFloatingWindow instead. This method of creating a
+ * floating frame is deprecated.
+ *
+ * @param toolbar The JToolBar to create a floating frame for.
+ *
+ * @return A new floating frame.
+ */
+ protected JFrame createFloatingFrame(JToolBar toolbar)
+ {
+ // FIXME: Though deprecated, this should still work.
+ return null;
+ }
- protected FocusListener createToolBarFocusListener()
- {
- return null;
- }
+ /**
+ * This method creates a new floating window for the JToolBar. This is the
+ * method used by default to create a floating container for the JToolBar.
+ *
+ * @param toolbar The JToolBar to create a floating window for.
+ *
+ * @return A new floating window.
+ */
+ protected RootPaneContainer createFloatingWindow(JToolBar toolbar)
+ {
+ // This one is used by default though.
+ return new ToolBarDialog();
+ }
- public static ComponentUI createUI(JComponent c)
- {
- return new BasicToolBarUI((JToolBar) c);
- }
+ /**
+ * This method creates a new WindowListener for the JToolBar.
+ *
+ * @return A new WindowListener.
+ */
+ protected WindowListener createFrameListener()
+ {
+ return new FrameListener();
+ }
- protected void dragTo(Point position, Point origin)
- {
- }
+ /**
+ * This method creates a new nonRolloverBorder for JButtons when the
+ * JToolBar's rollover property is set to false.
+ *
+ * @return A new NonRolloverBorder.
+ */
+ protected Border createNonRolloverBorder()
+ {
+ return new EtchedBorderUIResource();
+ }
- protected void floatAt(Point position, Point origin)
- {
- }
+ /**
+ * This method creates a new PropertyChangeListener for the JToolBar.
+ *
+ * @return A new PropertyChangeListener.
+ */
+ protected PropertyChangeListener createPropertyListener()
+ {
+ return new PropertyListener();
+ }
- /* Return the Color which is displayed when over a docking area */
- Color getDockingColor()
- {
- return dockingColor;
- }
+ /**
+ * This method creates a new rollover border for JButtons when the
+ * JToolBar's rollover property is set to true.
+ *
+ * @return A new rollover border.
+ */
+ protected Border createRolloverBorder()
+ {
+ return new EtchedBorderUIResource()
+ {
+ public void paintBorder(Component c, Graphics g, int x, int y,
+ int width, int height)
+ {
+ if (c instanceof JButton)
+ {
+ if (((JButton) c).getModel().isRollover())
+ super.paintBorder(c, g, x, y, width, height);
+ }
+ }
+ };
+ }
- /* Return the Color which is displayed when over a floating area */
- Color getFloatingColor()
- {
- return floatingColor;
- }
+ /**
+ * This method creates a new Container listener for the JToolBar.
+ *
+ * @return A new Container listener.
+ */
+ protected ContainerListener createToolBarContListener()
+ {
+ return new ToolBarContListener();
+ }
+
+ /**
+ * This method creates a new FocusListener for the JToolBar.
+ *
+ * @return A new FocusListener for the JToolBar.
+ */
+ protected FocusListener createToolBarFocusListener()
+ {
+ return new ToolBarFocusListener();
+ }
- /* See ComponentUI */
+ /**
+ * This method creates a new UI delegate for the given JComponent.
+ *
+ * @param c The JComponent to create a UI delegate for.
+ *
+ * @return A new UI delegate.
+ */
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicToolBarUI((JToolBar) c);
+ }
+
+ /**
+ * This method is called to drag the DragWindow around when the JToolBar is
+ * being dragged around.
+ *
+ * @param position The mouse cursor coordinates relative to the JToolBar.
+ * @param origin The screen position of the JToolBar.
+ */
+ protected void dragTo(Point position, Point origin)
+ {
+ int loc = areaOfClick(origParent,
+ SwingUtilities.convertPoint(toolBar, position,
+ origParent));
+
+ if (loc != -1)
+ {
+ dragWindow.setBorderColor(dockingBorderColor);
+ dragWindow.setBackground(dockingColor);
+ }
+ else
+ {
+ dragWindow.setBorderColor(floatingBorderColor);
+ dragWindow.setBackground(floatingColor);
+ }
+
+ int w = 0;
+ int h = 0;
+
+ boolean tmp = ((loc == SwingConstants.NORTH)
+ || (loc == SwingConstants.SOUTH) || (loc == -1));
+
+ if (((cachedOrientation == SwingConstants.HORIZONTAL) && tmp)
+ || ((cachedOrientation == VERTICAL) && ! tmp))
+ {
+ w = cachedBounds.width;
+ h = cachedBounds.height;
+ }
+ else
+ {
+ w = cachedBounds.height;
+ h = cachedBounds.width;
+ }
+
+ Point p = dragWindow.getOffset();
+ Insets insets = toolBar.getInsets();
+
+ dragWindow.setBounds((origin.x + position.x) - p.x
+ - ((insets.left + insets.right) / 2),
+ (origin.y + position.y) - p.y
+ - ((insets.top + insets.bottom) / 2), w, h);
+
+ if (! dragWindow.isVisible())
+ dragWindow.show();
+ }
+
+ /**
+ * This method is used at the end of a drag session to place the frame in
+ * either its original parent as a docked JToolBar or in its floating
+ * frame.
+ *
+ * @param position The position of the mouse cursor relative to the
+ * JToolBar.
+ * @param origin The screen position of the JToolBar before the drag session
+ * started.
+ */
+ protected void floatAt(Point position, Point origin)
+ {
+ Point p = new Point(position);
+ int aoc = areaOfClick(origParent,
+ SwingUtilities.convertPoint(toolBar, p, origParent));
+
+ Container oldParent = toolBar.getParent();
+
+ oldParent.remove(toolBar);
+ oldParent.doLayout();
+ oldParent.repaint();
+
+ Container newParent;
+
+ if (aoc == -1)
+ newParent = ((RootPaneContainer) floatFrame).getContentPane();
+ else
+ {
+ floatFrame.hide();
+ newParent = origParent;
+ }
+
+ String constraint;
+ switch (aoc)
+ {
+ case SwingConstants.EAST:
+ constraint = BorderLayout.EAST;
+ break;
+ case SwingConstants.NORTH:
+ constraint = BorderLayout.NORTH;
+ break;
+ case SwingConstants.SOUTH:
+ constraint = BorderLayout.SOUTH;
+ break;
+ case SwingConstants.WEST:
+ constraint = BorderLayout.WEST;
+ break;
+ default:
+ constraint = BorderLayout.CENTER;
+ break;
+ }
+
+ int newOrientation = SwingConstants.HORIZONTAL;
+ if ((aoc != -1)
+ && ((aoc == SwingConstants.EAST) || (aoc == SwingConstants.WEST)))
+ newOrientation = SwingConstants.VERTICAL;
+
+ if (aoc != -1)
+ {
+ constraintBeforeFloating = constraint;
+ lastGoodOrientation = newOrientation;
+ }
+
+ newParent.add(toolBar, constraint);
+
+ setFloating(aoc == -1, null);
+ toolBar.setOrientation(newOrientation);
+
+ Insets insets = floatFrame.getInsets();
+ Dimension dims = toolBar.getPreferredSize();
+ p = dragWindow.getOffset();
+ setFloatingLocation((position.x + origin.x) - p.x
+ - ((insets.left + insets.right) / 2),
+ (position.y + origin.y) - p.y
+ - ((insets.top + insets.bottom) / 2));
+
+ if (aoc == -1)
+ {
+ floatFrame.pack();
+ floatFrame.setSize(dims.width + insets.left + insets.right,
+ dims.height + insets.top + insets.bottom);
+ floatFrame.show();
+ }
+
+ newParent.invalidate();
+ newParent.validate();
+ newParent.repaint();
+ }
+
+ /**
+ * This method returns the docking color.
+ *
+ * @return The docking color.
+ */
+ public Color getDockingColor()
+ {
+ return dockingColor;
+ }
+
+ /**
+ * This method returns the Color which is displayed when over a floating
+ * area.
+ *
+ * @return The color which is displayed when over a floating area.
+ */
+ public Color getFloatingColor()
+ {
+ return floatingColor;
+ }
+
+ /**
+ * This method returns the maximum size of the given JComponent for this UI.
+ *
+ * @param c The JComponent to find the maximum size for.
+ *
+ * @return The maximum size for this UI.
+ */
public Dimension getMaximumSize(JComponent c)
- {
- return null;
- }
+ {
+ return getPreferredSize(c);
+ }
- /* See ComponentUI */
+ /**
+ * This method returns the minimum size of the given JComponent for this UI.
+ *
+ * @param c The JComponent to find a minimum size for.
+ *
+ * @return The minimum size for this UI.
+ */
public Dimension getMinimumSize(JComponent c)
- {
- return null;
- }
+ {
+ return getPreferredSize(c);
+ }
- /* See ComponentUI */
+ /**
+ * This method returns the preferred size of the given JComponent for this
+ * UI.
+ *
+ * @param c The JComponent to find a preferred size for.
+ *
+ * @return The preferred size for this UI.
+ */
public Dimension getPreferredSize(JComponent c)
- {
- return null;
- }
+ {
+ return toolBar.getLayout().preferredLayoutSize(c);
+ }
- protected void installComponents()
- {
- }
+ /**
+ * This method installs the needed components for the JToolBar.
+ */
+ protected void installComponents()
+ {
+ floatFrame = (Window) createFloatingWindow(toolBar);
- protected void installDefaults()
- {
- }
+ dragWindow = createDragWindow(toolBar);
+
+ cachedBounds = toolBar.getPreferredSize();
+ cachedOrientation = toolBar.getOrientation();
+
+ nonRolloverBorder = createNonRolloverBorder();
+ rolloverBorder = createRolloverBorder();
+
+ borders = new Hashtable();
+
+ fillHashtable();
+ }
+
+ /**
+ * This method installs the defaults as specified by the look and feel.
+ */
+ protected void installDefaults()
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+ toolBar.setBorder(new ToolBarBorder());
+ toolBar.setBackground(defaults.getColor("ToolBar.background"));
+ toolBar.setForeground(defaults.getColor("ToolBar.foreground"));
+ toolBar.setFont(defaults.getFont("ToolBar.font"));
- protected void installKeyboardActions()
+ dockingBorderColor = defaults.getColor("ToolBar.dockingForeground");
+ dockingColor = defaults.getColor("ToolBar.dockingBackground");
+
+ floatingBorderColor = defaults.getColor("ToolBar.floatingForeground");
+ floatingColor = defaults.getColor("ToolBar.floatingBackground");
+ }
+
+ /**
+ * This method installs the keyboard actions for the JToolBar as specified
+ * by the look and feel.
+ */
+ protected void installKeyboardActions()
+ {
+ // FIXME: implement.
+ }
+
+ /**
+ * This method installs listeners for the JToolBar.
+ *
+ * @param toolbar The JToolBar to register listeners for.
+ */
+ protected void installListeners(JToolBar toolbar)
+ {
+ dockingListener = createDockingListener();
+ toolBar.addMouseListener(dockingListener);
+ toolBar.addMouseMotionListener(dockingListener);
+
+ propertyListener = createPropertyListener();
+ toolBar.addPropertyChangeListener(propertyListener);
+
+ toolBarContListener = createToolBarContListener();
+ toolBar.addContainerListener(toolBarContListener);
+
+ windowListener = createFrameListener();
+ floatFrame.addWindowListener(windowListener);
+
+ toolBarFocusListener = createToolBarFocusListener();
+ toolBar.addFocusListener(toolBarFocusListener);
+ }
+
+ /**
+ * This method installs non rollover borders for each component inside the
+ * given JComponent.
+ *
+ * @param c The JComponent whose children need to have non rollover borders
+ * installed.
+ */
+ protected void installNonRolloverBorders(JComponent c)
+ {
+ Component[] components = toolBar.getComponents();
+
+ for (int i = 0; i < components.length; i++)
+ setBorderToNonRollover(components[i]);
+ }
+
+ /**
+ * This method installs normal (or their original) borders for each
+ * component inside the given JComponent.
+ *
+ * @param c The JComponent whose children need to have their original
+ * borders installed.
+ */
+ protected void installNormalBorders(JComponent c)
+ {
+ Component[] components = toolBar.getComponents();
+
+ for (int i = 0; i < components.length; i++)
+ setBorderToNormal(components[i]);
+ }
+
+ /**
+ * This method install rollover borders for each component inside the given
+ * JComponent.
+ *
+ * @param c The JComponent whose children need to have rollover borders
+ * installed.
+ */
+ protected void installRolloverBorders(JComponent c)
+ {
+ Component[] components = toolBar.getComponents();
+
+ for (int i = 0; i < components.length; i++)
+ setBorderToRollover(components[i]);
+ }
+
+ /**
+ * This method fills the borders hashtable with a list of components that
+ * are JButtons and their borders.
+ */
+ private void fillHashtable()
+ {
+ Component[] c = toolBar.getComponents();
+
+ for (int i = 0; i < c.length; i++)
+ {
+ if (c[i] instanceof JButton)
+ {
+ // Don't really care about anything other than JButtons
+ JButton b = (JButton) c[i];
+
+ if (b.getBorder() != null)
+ borders.put(b, b.getBorder());
+ }
+ }
+ }
+
+ /**
+ * This method installs the UI for the given JComponent.
+ *
+ * @param c The JComponent to install a UI for.
+ */
+ public void installUI(JComponent c)
+ {
+ super.installUI(c);
+
+ if (c instanceof JToolBar)
+ {
+ toolBar = (JToolBar) c;
+ toolBar.setOpaque(true);
+ installDefaults();
+ installComponents();
+ installListeners(toolBar);
+ installKeyboardActions();
+ }
+ }
+
+ /**
+ * This method returns whether the JToolBar is floating.
+ *
+ * @return Whether the JToolBar is floating.
+ */
+ public boolean isFloating()
+ {
+ return floatFrame.isVisible();
+ }
+
+ /**
+ * This method returns whether rollover borders have been set.
+ *
+ * @return Whether rollover borders have been set.
+ */
+ public boolean isRolloverBorders()
+ {
+ return toolBar.isRollover();
+ }
+
+ /**
+ * This method navigates in the given direction giving focus to the next
+ * component in the given direction.
+ *
+ * @param direction The direction to give focus to.
+ */
+ protected void navigateFocusedComp(int direction)
+ {
+ // FIXME: Implement.
+ }
+
+ /**
+ * This method sets the border of the given component to a non rollover
+ * border.
+ *
+ * @param c The Component whose border needs to be set.
+ */
+ protected void setBorderToNonRollover(Component c)
+ {
+ if (c instanceof JButton)
+ {
+ JButton b = (JButton) c;
+ b.setRolloverEnabled(false);
+ b.setBorder(nonRolloverBorder);
+ }
+ }
+
+ /**
+ * This method sets the border of the given component to its original value.
+ *
+ * @param c The Component whose border needs to be set.
+ */
+ protected void setBorderToNormal(Component c)
+ {
+ if (c instanceof JButton)
+ {
+ JButton b = (JButton) c;
+ Border border = (Border) borders.get(b);
+ b.setBorder(border);
+ }
+ }
+
+ /**
+ * This method sets the border of the given component to a rollover border.
+ *
+ * @param c The Component whose border needs to be set.
+ */
+ protected void setBorderToRollover(Component c)
+ {
+ if (c instanceof JButton)
+ {
+ JButton b = (JButton) c;
+ b.setRolloverEnabled(true);
+ b.setBorder(rolloverBorder);
+ }
+ }
+
+ /**
+ * This method sets the docking color.
+ *
+ * @param c The docking color.
+ */
+ public void setDockingColor(Color c)
+ {
+ dockingColor = c;
+ }
+
+ /**
+ * This method sets the floating property for the JToolBar.
+ *
+ * @param b Whether the JToolBar is floating.
+ * @param p FIXME
+ */
+ public void setFloating(boolean b, Point p)
+ {
+ // FIXME: use p for something. It's not location
+ // since we already have setFloatingLocation.
+ floatFrame.setVisible(b);
+ }
+
+ /**
+ * This method sets the color displayed when the JToolBar is not in a
+ * dockable area.
+ *
+ * @param c The floating color.
+ */
+ public void setFloatingColor(Color c)
+ {
+ floatingColor = c;
+ }
+
+ /**
+ * This method sets the floating location of the JToolBar.
+ *
+ * @param x The x coordinate for the floating frame.
+ * @param y The y coordinate for the floating frame.
+ */
+ public void setFloatingLocation(int x, int y)
+ {
+ // x,y are the coordinates of the new JFrame created to store the toolbar
+ // XXX: The floating location is bogus is not floating.
+ floatFrame.setLocation(x, y);
+ floatFrame.invalidate();
+ floatFrame.validate();
+ floatFrame.repaint();
+ }
+
+ /**
+ * This is a convenience method for changing the orientation of the
+ * JToolBar.
+ *
+ * @param orientation The new orientation.
+ */
+ public void setOrientation(int orientation)
+ {
+ toolBar.setOrientation(orientation);
+ }
+
+ /**
+ * This method changes the child components to have rollover borders if the
+ * given parameter is true. Otherwise, the components are set to have non
+ * rollover borders.
+ *
+ * @param rollover Whether the children will have rollover borders.
+ */
+ public void setRolloverBorders(boolean rollover)
+ {
+ if (rollover)
+ installRolloverBorders(toolBar);
+ else
+ installNonRolloverBorders(toolBar);
+ }
+
+ /**
+ * This method uninstall UI installed components from the JToolBar.
+ */
+ protected void uninstallComponents()
+ {
+ installNormalBorders(toolBar);
+ borders = null;
+ rolloverBorder = null;
+ nonRolloverBorder = null;
+ cachedBounds = null;
+
+ floatFrame = null;
+ dragWindow = null;
+ }
+
+ /**
+ * This method removes the defaults installed by the Look and Feel.
+ */
+ protected void uninstallDefaults()
+ {
+ toolBar.setBackground(null);
+ toolBar.setForeground(null);
+ toolBar.setFont(null);
+
+ dockingBorderColor = null;
+ dockingColor = null;
+ floatingBorderColor = null;
+ floatingColor = null;
+ }
+
+ /**
+ * This method uninstalls keyboard actions installed by the UI.
+ */
+ protected void uninstallKeyboardActions()
+ {
+ // FIXME: implement.
+ }
+
+ /**
+ * This method uninstalls listeners installed by the UI.
+ */
+ protected void uninstallListeners()
+ {
+ toolBar.removeFocusListener(toolBarFocusListener);
+ toolBarFocusListener = null;
+
+ floatFrame.removeWindowListener(windowListener);
+ windowListener = null;
+
+ toolBar.removeContainerListener(toolBarContListener);
+ toolBarContListener = null;
+
+ toolBar.removeMouseMotionListener(dockingListener);
+ toolBar.removeMouseListener(dockingListener);
+ dockingListener = null;
+ }
+
+ /**
+ * This method uninstalls the UI.
+ *
+ * @param c The JComponent that is having this UI removed.
+ */
+ public void uninstallUI(JComponent c)
+ {
+ uninstallKeyboardActions();
+ uninstallListeners();
+ uninstallComponents();
+ uninstallDefaults();
+ toolBar = null;
+ }
+
+ /**
+ * This is the MouseHandler class that allows the user to drag the JToolBar
+ * in and out of the parent and dock it if it can.
+ */
+ protected class DockingListener implements MouseInputListener
+ {
+ /** Whether the JToolBar is being dragged. */
+ protected boolean isDragging;
+
+ /**
+ * The origin point. This point is saved from the beginning press and is
+ * used until the end of the drag session.
+ */
+ protected Point origin;
+
+ /** The JToolBar being dragged. */
+ protected JToolBar toolBar;
+
+ /**
+ * Creates a new DockingListener object.
+ *
+ * @param t The JToolBar this DockingListener is being used for.
+ */
+ public DockingListener(JToolBar t)
{
+ toolBar = t;
}
- protected void installListeners(JToolBar toolbar)
+ /**
+ * This method is called when the mouse is clicked.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseClicked(MouseEvent e)
{
- toolbar.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent event) {
- System.err.println("toolbar clicked");
- }
- } );
+ // Don't care.
}
- /* Call setBorderToNonRollover for each child component of c */
- protected void installNonRolloverBorders(JComponent c)
+ /**
+ * This method is called when the mouse is dragged. It delegates the drag
+ * painting to the dragTo method.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseDragged(MouseEvent e)
{
+ if (isDragging)
+ dragTo(e.getPoint(), origin);
}
- /* Call setBorderToNormal for each child component of c */
- protected void installNormalBorders(JComponent c)
+ /**
+ * This method is called when the mouse enters the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseEntered(MouseEvent e)
{
+ // Don't care (yet).
}
- /* Call setBorderToRollover for each child component of c */
- protected void installRolloverBorders(JComponent c)
+ /**
+ * This method is called when the mouse exits the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseExited(MouseEvent e)
{
+ // Don't care (yet).
}
- public void installUI(JComponent c)
+ /**
+ * This method is called when the mouse is moved in the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseMoved(MouseEvent e)
{
- super.installUI(c);
- if (c instanceof JToolBar)
- {
- toolBar = (JToolBar) c;
- toolBar.setOpaque(true);
- switch (toolBar.getOrientation()) {
- case 0: toolBar.setLayout(new GridLayout(1, 0, 4, 4));
- break;
- case 1: toolBar.setLayout(new GridLayout(0, 1, 4, 4));
- break;
- }
- installListeners(toolBar);
- }
}
- boolean isFloating()
+ /**
+ * This method is called when the mouse is pressed in the JToolBar. If the
+ * press doesn't occur in a place where it causes the JToolBar to be
+ * dragged, it returns. Otherwise, it starts a drag session.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mousePressed(MouseEvent e)
{
- return false;
+ if (! toolBar.isFloatable())
+ return;
+
+ Point ssd = e.getPoint();
+ Insets insets = toolBar.getInsets();
+
+ // Verify that this click occurs in the top inset.
+ if (toolBar.getOrientation() == SwingConstants.HORIZONTAL)
+ {
+ if (e.getX() > insets.left)
+ return;
+ }
+ else
+ {
+ if (e.getY() > insets.top)
+ return;
+ }
+
+ origin = new Point(0, 0);
+ SwingUtilities.convertPointToScreen(ssd, toolBar);
+
+ if (! (SwingUtilities.getAncestorOfClass(Window.class, toolBar) instanceof UIResource))
+ // Need to know who keeps the toolBar if it gets dragged back into it.
+ origParent = toolBar.getParent();
+
+ SwingUtilities.convertPointToScreen(origin, toolBar);
+
+ isDragging = true;
+
+ if (dragWindow != null)
+ dragWindow.setOffset(new Point(e.getX(), e.getY()));
+
+ dragTo(e.getPoint(), origin);
}
- boolean isRolloverBorders()
+ /**
+ * This method is called when the mouse is released from the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseReleased(MouseEvent e)
{
- return false;
+ if (! isDragging || ! toolBar.isFloatable())
+ return;
+
+ isDragging = false;
+ floatAt(e.getPoint(), origin);
+ dragWindow.hide();
}
+ }
- protected void navigateFocusedComp(int direction)
+ /**
+ * This is the window that appears when the JToolBar is being dragged
+ * around.
+ */
+ protected class DragWindow extends Window
+ {
+ /**
+ * The current border color. It changes depending on whether the JToolBar
+ * is over a place that allows it to dock.
+ */
+ private Color borderColor;
+
+ /** The between the mouse and the top left corner of the window. */
+ private Point offset;
+
+ /**
+ * Creates a new DragWindow object.
+ */
+ private DragWindow()
{
+ super((Window) SwingUtilities.getOwnerFrame());
}
- /* Make Component c have a non-rollover border (created by
- createNonRolloverBorder). */
- protected void setBorderToNonRollover(Component c)
+ /**
+ * The color that the border should be.
+ *
+ * @return The border color.
+ */
+ public Color getBorderColor()
{
+ if (borderColor == null)
+ return Color.BLACK;
+
+ return borderColor;
}
- /* Make Component c have the border that it originally had before being
- added to the toolbar. */
- protected void setBorderToNormal(Component c)
+ /**
+ * This method returns the insets for the DragWindow.
+ *
+ * @return The insets for the DragWindow.
+ */
+ public Insets getInsets()
{
+ // This window has no decorations, so insets are empty.
+ return new Insets(0, 0, 0, 0);
}
- /* Make Component c have a rollover border (created by
- createRolloverBorder). */
- protected void setBorderToRollover(Component c)
+ /**
+ * This method returns the mouse offset from the top left corner of the
+ * DragWindow.
+ *
+ * @return The mouse offset.
+ */
+ public Point getOffset()
{
+ return offset;
}
- /* Display in Color c when over a docking area */
- void setDockingColor(Color c)
+ /**
+ * This method paints the DragWindow.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
{
- dockingColor = c;
+ // No visiting children necessary.
+ Color saved = g.getColor();
+ Rectangle b = getBounds();
+
+ g.setColor(getBorderColor());
+ g.drawRect(0, 0, b.width - 1, b.height - 1);
+
+ g.setColor(saved);
}
- void setFloating(boolean b, Point p)
+ /**
+ * This method changes the border color.
+ *
+ * @param c The new border color.
+ */
+ public void setBorderColor(Color c)
{
+ borderColor = c;
}
- /* Display in Color c when over a floating area */
- void setFloatingColor(Color c)
+ /**
+ * This method changes the mouse offset.
+ *
+ * @param p The new mouse offset.
+ */
+ public void setOffset(Point p)
{
- floatingColor = c;
+ offset = p;
}
- void setFloatingLocation(int x, int y)
+ /**
+ * FIXME: Do something.
+ *
+ * @param o DOCUMENT ME!
+ */
+ public void setOrientation(int o)
{
+ // FIXME: implement.
}
+ }
- void setOrientation(int orientation)
- {
+ /**
+ * This helper class listens for Window events from the floatable window and
+ * if it is closed, returns the JToolBar to the last known good location.
+ */
+ protected class FrameListener extends WindowAdapter
+ {
+ /**
+ * This method is called when the floating window is closed.
+ *
+ * @param e The WindowEvent.
+ */
+ public void windowClosing(WindowEvent e)
+ {
+ Container parent = toolBar.getParent();
+ parent.remove(toolBar);
+
+ if (origParent != null)
+ {
+ origParent.add(toolBar,
+ (constraintBeforeFloating != null)
+ ? constraintBeforeFloating : BorderLayout.NORTH);
+ toolBar.setOrientation(lastGoodOrientation);
+ }
+
+ origParent.invalidate();
+ origParent.validate();
+ origParent.repaint();
}
+ }
- /* Set flag to enable rollover borders for the toolbar */
- void setRolloverBorders(boolean rollover)
- {
- rolloverBorders = rollover;
+ /**
+ * This helper class listens for PropertyChangeEvents from the JToolBar.
+ */
+ protected class PropertyListener implements PropertyChangeListener
+ {
+ /**
+ * This method is called when a property from the JToolBar is changed.
+ *
+ * @param e The PropertyChangeEvent.
+ */
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ // FIXME: need name properties so can change floatFrame title.
+ if (e.getPropertyName().equals(JToolBar.ROLLOVER_CHANGED_PROPERTY))
+ setRolloverBorders(toolBar.isRollover());
}
+ }
- protected void uninstallComponents()
- {
+ /**
+ * This helper class listens for components added to and removed from the
+ * JToolBar.
+ */
+ protected class ToolBarContListener implements ContainerListener
+ {
+ /**
+ * This method is responsible for setting rollover or non rollover for new
+ * buttons added to the JToolBar.
+ *
+ * @param e The ContainerEvent.
+ */
+ public void componentAdded(ContainerEvent e)
+ {
+ if (e.getChild() instanceof JButton)
+ {
+ JButton b = (JButton) e.getChild();
+
+ if (b.getBorder() != null)
+ borders.put(b, b.getBorder());
+ }
+
+ if (isRolloverBorders())
+ setBorderToRollover(e.getChild());
+ else
+ setBorderToNonRollover(e.getChild());
+
+ cachedBounds = toolBar.getPreferredSize();
+ cachedOrientation = toolBar.getOrientation();
+ }
+
+ /**
+ * This method is responsible for giving the child components their
+ * original borders when they are removed.
+ *
+ * @param e The ContainerEvent.
+ */
+ public void componentRemoved(ContainerEvent e)
+ {
+ setBorderToNormal(e.getChild());
+ cachedBounds = toolBar.getPreferredSize();
+ cachedOrientation = toolBar.getOrientation();
}
+ }
- protected void uninstallDefaults()
+ /**
+ * This is the floating window that is returned when getFloatingWindow is
+ * called.
+ */
+ private class ToolBarDialog extends JDialog implements UIResource
+ {
+ /**
+ * Creates a new ToolBarDialog object with the name given by the JToolBar.
+ */
+ public ToolBarDialog()
{
+ super(SwingUtilities.getOwnerFrame(),
+ (toolBar.getName() != null) ? toolBar.getName() : "");
}
+ }
- protected void uninstallKeyboardActions()
+ /**
+ * DOCUMENT ME!
+ */
+ protected class ToolBarFocusListener implements FocusListener
+ {
+ /**
+ * Creates a new ToolBarFocusListener object.
+ */
+ protected ToolBarFocusListener()
{
+ // FIXME: implement.
}
- protected void uninstallListeners()
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void focusGained(FocusEvent e)
{
+ // FIXME: implement.
}
- public void uninstallUI(JComponent c)
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void focusLost(FocusEvent e)
{
+ // FIXME: implement.
}
+ }
+
+ /**
+ * This helper class acts as the border for the JToolBar.
+ */
+ private static class ToolBarBorder implements Border
+ {
+ /** The size of the larger, draggable side of the border. */
+ private static int offset = 10;
+
+ /** The other sides. */
+ private static int regular = 2;
+ /**
+ * This method returns the border insets for the JToolBar.
+ *
+ * @param c The Component to find insets for.
+ *
+ * @return The border insets.
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ if (c instanceof JToolBar)
+ {
+ JToolBar tb = (JToolBar) c;
+ int orientation = tb.getOrientation();
+
+ if (! tb.isFloatable())
+ return new Insets(regular, regular, regular, regular);
+ else if (orientation == SwingConstants.HORIZONTAL)
+ return new Insets(regular, offset, regular, regular);
+ else
+ return new Insets(offset, regular, regular, regular);
+ }
+
+ return new Insets(0, 0, 0, 0);
+ }
+
+ /**
+ * This method returns whether the border is opaque.
+ *
+ * @return Whether the border is opaque.
+ */
+ public boolean isBorderOpaque()
+ {
+ return false;
+ }
+
+ /**
+ * This method paints the ribbed area of the border.
+ *
+ * @param g The Graphics object to paint with.
+ * @param x The x coordinate of the area.
+ * @param y The y coordinate of the area.
+ * @param w The width of the area.
+ * @param h The height of the area.
+ * @param size The size of the bump.
+ * @param c The color of the bumps.
+ */
+ private void paintBumps(Graphics g, int x, int y, int w, int h, int size,
+ Color c)
+ {
+ Color saved = g.getColor();
+ g.setColor(c);
+
+ int hgap = 2 * size;
+ int vgap = 4 * size;
+ int count = 0;
+
+ for (int i = x; i < (w + x); i += hgap)
+ for (int j = ((count++ % 2) == 0) ? y : (y + (2 * size)); j < (h + y);
+ j += vgap)
+ g.fillRect(i, j, size, size);
+
+ g.setColor(saved);
+ }
+
+ /**
+ * This method paints the border around the given Component.
+ *
+ * @param c The Component whose border is being painted.
+ * @param g The Graphics object to paint with.
+ * @param x The x coordinate of the component.
+ * @param y The y coordinate of the component.
+ * @param width The width of the component.
+ * @param height The height of the component.
+ */
+ public void paintBorder(Component c, Graphics g, int x, int y, int width,
+ int height)
+ {
+ if (c instanceof JToolBar)
+ {
+ JToolBar tb = (JToolBar) c;
+
+ int orientation = tb.getOrientation();
+
+ if (orientation == SwingConstants.HORIZONTAL)
+ {
+ paintBumps(g, x, y, offset, height, 1, Color.WHITE);
+ paintBumps(g, x + 1, y + 1, offset - 1, height - 1, 1, Color.GRAY);
+ }
+ else
+ {
+ paintBumps(g, x, y, width, offset, 1, Color.WHITE);
+ paintBumps(g, x + 1, y + 1, width - 1, offset - 1, 1, Color.GRAY);
+ }
+ }
+ }
+ }
}