summaryrefslogtreecommitdiff
path: root/javax/swing/plaf/basic
diff options
context:
space:
mode:
Diffstat (limited to 'javax/swing/plaf/basic')
-rw-r--r--javax/swing/plaf/basic/BasicArrowButton.java67
-rw-r--r--javax/swing/plaf/basic/BasicButtonUI.java55
-rw-r--r--javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java15
-rw-r--r--javax/swing/plaf/basic/BasicInternalFrameUI.java232
-rw-r--r--javax/swing/plaf/basic/BasicListUI.java21
-rw-r--r--javax/swing/plaf/basic/BasicLookAndFeel.java10
-rw-r--r--javax/swing/plaf/basic/BasicMenuBarUI.java21
-rw-r--r--javax/swing/plaf/basic/BasicMenuItemUI.java113
-rw-r--r--javax/swing/plaf/basic/BasicMenuUI.java47
-rw-r--r--javax/swing/plaf/basic/BasicOptionPaneUI.java38
-rw-r--r--javax/swing/plaf/basic/BasicPopupMenuUI.java205
-rw-r--r--javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java14
-rw-r--r--javax/swing/plaf/basic/BasicRootPaneUI.java10
-rw-r--r--javax/swing/plaf/basic/BasicScrollBarUI.java27
-rw-r--r--javax/swing/plaf/basic/BasicScrollPaneUI.java29
-rw-r--r--javax/swing/plaf/basic/BasicSliderUI.java94
-rw-r--r--javax/swing/plaf/basic/BasicSplitPaneDivider.java24
-rw-r--r--javax/swing/plaf/basic/BasicSplitPaneUI.java14
-rw-r--r--javax/swing/plaf/basic/BasicTabbedPaneUI.java2
-rw-r--r--javax/swing/plaf/basic/BasicTextFieldUI.java82
-rw-r--r--javax/swing/plaf/basic/BasicTextUI.java218
-rw-r--r--javax/swing/plaf/basic/BasicToolBarSeparatorUI.java132
-rw-r--r--javax/swing/plaf/basic/BasicToolBarUI.java1277
-rw-r--r--javax/swing/plaf/basic/BasicViewportUI.java1
-rw-r--r--javax/swing/plaf/basic/Makefile.am2
25 files changed, 2327 insertions, 423 deletions
diff --git a/javax/swing/plaf/basic/BasicArrowButton.java b/javax/swing/plaf/basic/BasicArrowButton.java
index cb2c99baf..b12450157 100644
--- a/javax/swing/plaf/basic/BasicArrowButton.java
+++ b/javax/swing/plaf/basic/BasicArrowButton.java
@@ -40,9 +40,11 @@ package javax.swing.plaf.basic;
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;
@@ -170,6 +172,47 @@ public class BasicArrowButton extends JButton implements SwingConstants
/** 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 @@ public class BasicArrowButton extends JButton implements SwingConstants
{
super();
setDirection(direction);
+ setBorder(tmpBorder);
}
/**
@@ -234,29 +278,6 @@ public class BasicArrowButton extends JButton implements SwingConstants
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);
}
/**
diff --git a/javax/swing/plaf/basic/BasicButtonUI.java b/javax/swing/plaf/basic/BasicButtonUI.java
index b766d387d..9134fb2e2 100644
--- a/javax/swing/plaf/basic/BasicButtonUI.java
+++ b/javax/swing/plaf/basic/BasicButtonUI.java
@@ -61,7 +61,7 @@ public class BasicButtonUI extends ButtonUI
{
/** A constant used to pad out elements in the button's layout and
preferred size calculations. */
- int defaultTextIconGap = 3;
+ int defaultTextIconGap = 4;
/** A constant added to the defaultTextIconGap to adjust the text
within this particular button. */
@@ -92,6 +92,7 @@ public class BasicButtonUI extends ButtonUI
b.setBackground(defaults.getColor("Button.background"));
b.setMargin(defaults.getInsets("Button.margin"));
b.setBorder(defaults.getBorder("Button.border"));
+ b.setIconTextGap(defaults.getInt("Button.textIconGap"));
b.setOpaque(true);
}
@@ -100,6 +101,7 @@ public class BasicButtonUI extends ButtonUI
b.setForeground(null);
b.setBackground(null);
b.setBorder(null);
+ b.setIconTextGap(defaultTextIconGap);
b.setMargin(null);
}
@@ -234,19 +236,19 @@ public class BasicButtonUI extends ButtonUI
b.getVerticalTextPosition(),
b.getHorizontalTextPosition(),
vr, ir, tr,
- defaultTextIconGap
+ b.getIconTextGap()
+ defaultTextShiftOffset);
if ((b.getModel().isArmed() && b.getModel().isPressed())
|| b.isSelected())
- paintButtonPressed(g, br, c);
+ paintButtonPressed(g, b);
else
paintButtonNormal(g, br, c);
paintIcon(g, c, ir);
if (text != null)
- paintText(g, c, tr, b.getText());
- paintFocus(g, c, vr, tr, ir);
+ paintText(g, b, tr, text);
+ paintFocus(g, b, vr, tr, ir);
}
/**
@@ -256,7 +258,7 @@ public class BasicButtonUI extends ButtonUI
* "focusPainted" property is <code>true</code>.
*
* @param g Graphics context to paint with
- * @param c Component to paint the focus of
+ * @param b Button to paint the focus of
* @param vr Visible rectangle, the area in which to paint
* @param tr Text rectangle, contained in visible rectangle
* @param ir Icon rectangle, contained in visible rectangle
@@ -264,10 +266,9 @@ public class BasicButtonUI extends ButtonUI
* @see AbstractButton.isFocusPainted()
* @see JComponent.hasFocus()
*/
- protected void paintFocus(Graphics g, JComponent c, Rectangle vr,
+ protected void paintFocus(Graphics g, AbstractButton b, Rectangle vr,
Rectangle tr, Rectangle ir)
{
- AbstractButton b = (AbstractButton) c;
if (b.hasFocus() && b.isFocusPainted())
{
Graphics2D g2 = (Graphics2D) g;
@@ -313,13 +314,14 @@ public class BasicButtonUI extends ButtonUI
* pressedBackgroundColor}.
*
* @param g The graphics context to paint with
- * @param area The area in which to paint
- * @param b The component to paint the state of
+ * @param b The button to paint the state of
*/
- protected void paintButtonPressed(Graphics g, Rectangle area, JComponent b)
+ protected void paintButtonPressed(Graphics g, AbstractButton b)
{
- if (((AbstractButton)b).isContentAreaFilled())
+ if (b.isContentAreaFilled())
{
+ Rectangle area = new Rectangle();
+ SwingUtilities.calculateInnerArea(b, area);
g.setColor(b.getBackground().darker());
g.fillRect(area.x, area.y, area.width, area.height);
}
@@ -334,7 +336,7 @@ public class BasicButtonUI extends ButtonUI
* @param area The area in which to paint
* @param b The component to paint the state of
*/
- protected void paintButtonNormal(Graphics g, Rectangle area, JComponent b)
+ private void paintButtonNormal(Graphics g, Rectangle area, JComponent b)
{
if (((AbstractButton)b).isContentAreaFilled() && b.isOpaque())
{
@@ -355,20 +357,37 @@ public class BasicButtonUI extends ButtonUI
protected void paintText(Graphics g, JComponent c, Rectangle textRect,
String text)
{
- Font f = c.getFont();
+ paintText(g, (AbstractButton) c, textRect, text);
+ }
+
+ /**
+ * Paints the "text" property of an {@link AbstractButton}, using the
+ * {@link textColor} color.
+ *
+ * @param g The graphics context to paint with
+ * @param b The button to paint the state of
+ * @param textRect The area in which to paint the text
+ * @param text The text to paint
+ *
+ * @since 1.4
+ */
+ protected void paintText(Graphics g, AbstractButton b, Rectangle textRect,
+ String text)
+ {
+ Font f = b.getFont();
g.setFont(f);
FontMetrics fm = g.getFontMetrics(f);
- if (c.isEnabled())
+ if (b.isEnabled())
{
- g.setColor(c.getForeground());
+ g.setColor(b.getForeground());
g.drawString(text, textRect.x, textRect.y + fm.getAscent());
}
else
{
- g.setColor(c.getBackground().brighter());
+ g.setColor(b.getBackground().brighter());
g.drawString(text, textRect.x, textRect.y + fm.getAscent());
- g.setColor(c.getBackground().darker());
+ g.setColor(b.getBackground().darker());
g.drawString(text, textRect.x + 1, textRect.y + fm.getAscent() + 1);
}
}
diff --git a/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java b/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java
index 397a2f100..c7d88d1a6 100644
--- a/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java
+++ b/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java
@@ -53,11 +53,12 @@ import javax.swing.plaf.ComponentUI;
public class BasicCheckBoxMenuItemUI extends BasicMenuItemUI
{
/**
- * DOCUMENT ME!
+ * Factory method to create a BasicCheckBoxMenuItemUI for the given {@link
+ * JComponent}, which should be a JCheckBoxMenuItem
*
- * @param c DOCUMENT ME!
+ * @param c The {@link JComponent} a UI is being created for.
*
- * @return $returnType$ DOCUMENT ME!
+ * @return A BasicCheckBoxMenuItemUI for the {@link JComponent}.
*/
public static ComponentUI createUI(final JComponent c)
{
@@ -71,11 +72,12 @@ public class BasicCheckBoxMenuItemUI extends BasicMenuItemUI
*/
protected String getPropertyPrefix()
{
- return null; // TODO
+ return null;
}
/**
- * DOCUMENT ME!
+ * This method installs the defaults that are defined in the Basic look and
+ * feel for this JRadioButtonMenuItem
*/
protected void installDefaults()
{
@@ -93,7 +95,8 @@ public class BasicCheckBoxMenuItemUI extends BasicMenuItemUI
* @param path DOCUMENT ME!
* @param manager DOCUMENT ME!
*/
- void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement[] path,
+ public void processMouseEvent(JMenuItem item, MouseEvent e,
+ MenuElement[] path,
MenuSelectionManager manager)
{
}
diff --git a/javax/swing/plaf/basic/BasicInternalFrameUI.java b/javax/swing/plaf/basic/BasicInternalFrameUI.java
index 5c598b763..d394b951b 100644
--- a/javax/swing/plaf/basic/BasicInternalFrameUI.java
+++ b/javax/swing/plaf/basic/BasicInternalFrameUI.java
@@ -37,6 +37,7 @@ exception statement from your version. */
package javax.swing.plaf.basic;
+import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
@@ -179,6 +180,9 @@ public class BasicInternalFrameUI extends InternalFrameUI
/** The direction that the resize is occuring in. */
private transient int direction = -1;
+ /** Cache rectangle that can be reused. */
+ private transient Rectangle cacheRect = new Rectangle();
+
/**
* This method is called when the mouse is clicked.
*
@@ -204,6 +208,9 @@ public class BasicInternalFrameUI extends InternalFrameUI
return;
DesktopManager dm = getDesktopManager();
Rectangle b = frame.getBounds();
+ Dimension min = frame.getMinimumSize();
+ if (min == null)
+ min = new Dimension(0, 0);
Insets insets = frame.getInsets();
int x = e.getX();
int y = e.getY();
@@ -212,31 +219,43 @@ public class BasicInternalFrameUI extends InternalFrameUI
switch (direction)
{
case NORTH:
- dm.resizeFrame(frame, b.x, b.y + y, b.width, b.height - y);
+ cacheRect.setBounds(b.x,
+ Math.min(b.y + y, b.y + b.height
+ - min.height), b.width, b.height
+ - y);
break;
case NORTH_EAST:
- dm.resizeFrame(frame, b.x, b.y + y, x, b.height - y);
+ cacheRect.setBounds(b.x,
+ Math.min(b.y + y, b.y + b.height
+ - min.height), x, b.height - y);
break;
case EAST:
- dm.resizeFrame(frame, b.x, b.y, x, b.height);
+ cacheRect.setBounds(b.x, b.y, x, b.height);
break;
case SOUTH_EAST:
- dm.resizeFrame(frame, b.x, b.y, x, y);
+ cacheRect.setBounds(b.x, b.y, x, y);
break;
case SOUTH:
- dm.resizeFrame(frame, b.x, b.y, b.width, y);
+ cacheRect.setBounds(b.x, b.y, b.width, y);
break;
case SOUTH_WEST:
- dm.resizeFrame(frame, b.x + x, b.y, b.width - x, y);
+ cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
+ b.y, b.width - x, y);
break;
case WEST:
- dm.resizeFrame(frame, b.x + x, b.y, b.width - x, b.height);
+ cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
+ b.y, b.width - x, b.height);
break;
case NORTH_WEST:
- dm.resizeFrame(frame, b.x + x, b.y + y, b.width - x, b.height
- - y);
+ cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
+ Math.min(b.y + y, b.y + b.height
+ - min.height), b.width - x,
+ b.height - y);
break;
}
+ dm.resizeFrame(frame, cacheRect.x, cacheRect.y,
+ Math.max(min.width, cacheRect.width),
+ Math.max(min.height, cacheRect.height));
}
else if (e.getSource() == titlePane)
{
@@ -498,7 +517,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public Dimension minimumLayoutSize(Container c)
{
- return preferredLayoutSize(c);
+ return getSize(c, true);
}
/**
@@ -522,9 +541,24 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public Dimension preferredLayoutSize(Container c)
{
+ return getSize(c, false);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ * @param min DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ private Dimension getSize(Container c, boolean min)
+ {
Insets insets = frame.getInsets();
Dimension contentDims = frame.getContentPane().getPreferredSize();
+ if (min)
+ contentDims.width = contentDims.height = 0;
int nWidth = 0;
int nHeight = 0;
int sWidth = 0;
@@ -578,8 +612,8 @@ public class BasicInternalFrameUI extends InternalFrameUI
int width = Math.max(sWidth, nWidth);
width = Math.max(width, contentDims.width + eWidth + wWidth);
- int height = Math.max(contentDims.height, eHeight);
- height = Math.max(height, wHeight);
+ int height = Math.max(eHeight, wHeight);
+ height = Math.max(height, contentDims.height);
height += nHeight + sHeight;
width += insets.left + insets.right;
@@ -606,6 +640,18 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
protected class GlassPaneDispatcher implements MouseInputListener
{
+ /** The MouseEvent target. */
+ private transient Component mouseEventTarget;
+
+ /** The component pressed. */
+ private transient Component pressedComponent;
+
+ /** The last component entered. */
+ private transient Component lastComponentEntered;
+
+ /** The number of presses. */
+ private transient int pressCount;
+
/**
* This method is called when the mouse enters the glass pane.
*
@@ -613,7 +659,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public void mouseEntered(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -623,7 +669,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public void mouseClicked(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -633,7 +679,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public void mouseDragged(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -643,7 +689,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public void mouseExited(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -653,7 +699,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public void mouseMoved(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -664,7 +710,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
public void mousePressed(MouseEvent e)
{
activateFrame(frame);
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -674,27 +720,149 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public void mouseReleased(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
- * This helper method redispatches the MouseEvent to the proper sub
- * component.
+ * This method acquires a candidate component to dispatch the MouseEvent
+ * to.
*
- * @param e The MouseEvent.
+ * @param me The MouseEvent to acquire a component for.
*/
- private void dispatchFor(MouseEvent e)
+ private void acquireComponentForMouseEvent(MouseEvent me)
{
- Component candidate = SwingUtilities.getDeepestComponentAt(frame.getRootPane()
- .getContentPane(),
- e.getX(),
- e.getY());
- if (candidate == null || candidate == frame.getRootPane().getGlassPane())
+ int x = me.getX();
+ int y = me.getY();
+
+ // Find the candidate which should receive this event.
+ Component parent = frame.getContentPane();
+ if (parent == null)
return;
- MouseEvent newevt = SwingUtilities.convertMouseEvent(frame.getRootPane()
+ Component candidate = null;
+ Point p = me.getPoint();
+ while (candidate == null && parent != null)
+ {
+ candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
+ if (candidate == null)
+ {
+ p = SwingUtilities.convertPoint(parent, p.x, p.y,
+ parent.getParent());
+ parent = parent.getParent();
+ }
+ }
+
+ // If the only candidate we found was the native container itself,
+ // don't dispatch any event at all. We only care about the lightweight
+ // children here.
+ if (candidate == frame.getContentPane())
+ candidate = null;
+
+ // If our candidate is new, inform the old target we're leaving.
+ if (lastComponentEntered != null && lastComponentEntered.isShowing()
+ && lastComponentEntered != candidate)
+ {
+ Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y,
+ lastComponentEntered);
+ MouseEvent exited = new MouseEvent(lastComponentEntered,
+ MouseEvent.MOUSE_EXITED,
+ me.getWhen(), me.getModifiers(),
+ tp.x, tp.y, me.getClickCount(),
+ me.isPopupTrigger(),
+ me.getButton());
+ lastComponentEntered.dispatchEvent(exited);
+ lastComponentEntered = null;
+ }
+
+ // If we have a candidate, maybe enter it.
+ if (candidate != null)
+ {
+ mouseEventTarget = candidate;
+ if (candidate.isLightweight() && candidate.isShowing()
+ && candidate != frame.getContentPane()
+ && candidate != lastComponentEntered)
+ {
+ lastComponentEntered = mouseEventTarget;
+ Point cp = SwingUtilities.convertPoint(frame.getContentPane(),
+ x, y, lastComponentEntered);
+ MouseEvent entered = new MouseEvent(lastComponentEntered,
+ MouseEvent.MOUSE_ENTERED,
+ me.getWhen(),
+ me.getModifiers(), cp.x,
+ cp.y, me.getClickCount(),
+ me.isPopupTrigger(),
+ me.getButton());
+ lastComponentEntered.dispatchEvent(entered);
+ }
+ }
+
+ if (me.getID() == MouseEvent.MOUSE_RELEASED
+ || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0
+ || me.getID() == MouseEvent.MOUSE_DRAGGED)
+ // If any of the following events occur while a button is held down,
+ // they should be dispatched to the same component to which the
+ // original MOUSE_PRESSED event was dispatched:
+ // - MOUSE_RELEASED
+ // - MOUSE_PRESSED: another button pressed while the first is held down
+ // - MOUSE_DRAGGED
+ mouseEventTarget = pressedComponent;
+ else if (me.getID() == MouseEvent.MOUSE_CLICKED)
+ {
+ // Don't dispatch CLICKED events whose target is not the same as the
+ // target for the original PRESSED event.
+ if (candidate != pressedComponent)
+ mouseEventTarget = null;
+ else if (pressCount == 0)
+ pressedComponent = null;
+ }
+ }
+
+ /**
+ * This is a helper method that dispatches the GlassPane MouseEvents to
+ * the proper component.
+ *
+ * @param e The AWTEvent to be dispatched. Usually an instance of
+ * MouseEvent.
+ */
+ private void handleEvent(AWTEvent e)
+ {
+ if (e instanceof MouseEvent)
+ {
+ MouseEvent me = SwingUtilities.convertMouseEvent(frame.getRootPane()
.getGlassPane(),
- e, candidate);
- candidate.dispatchEvent(newevt);
+ (MouseEvent) e,
+ frame.getRootPane()
+ .getGlassPane());
+
+ acquireComponentForMouseEvent(me);
+
+ // Avoid dispatching ENTERED and EXITED events twice.
+ if (mouseEventTarget != null && mouseEventTarget.isShowing()
+ && e.getID() != MouseEvent.MOUSE_ENTERED
+ && e.getID() != MouseEvent.MOUSE_EXITED)
+ {
+ MouseEvent newEvt = SwingUtilities.convertMouseEvent(frame
+ .getContentPane(),
+ me,
+ mouseEventTarget);
+ mouseEventTarget.dispatchEvent(newEvt);
+
+ switch (e.getID())
+ {
+ case MouseEvent.MOUSE_PRESSED:
+ if (pressCount++ == 0)
+ pressedComponent = mouseEventTarget;
+ break;
+ case MouseEvent.MOUSE_RELEASED:
+ // Clear our memory of the original PRESSED event, only if
+ // we're not expecting a CLICKED event after this. If
+ // there is a CLICKED event after this, it will do clean up.
+ if (--pressCount == 0
+ && mouseEventTarget != pressedComponent)
+ pressedComponent = null;
+ break;
+ }
+ }
+ }
}
}
@@ -1108,7 +1276,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
*/
public Dimension getMinimumSize(JComponent x)
{
- return getPreferredSize(x);
+ return internalFrameLayout.minimumLayoutSize(x);
}
/**
diff --git a/javax/swing/plaf/basic/BasicListUI.java b/javax/swing/plaf/basic/BasicListUI.java
index b356bdf2a..bd5c53b04 100644
--- a/javax/swing/plaf/basic/BasicListUI.java
+++ b/javax/swing/plaf/basic/BasicListUI.java
@@ -121,7 +121,6 @@ public class BasicListUI extends ListUI
*/
public void contentsChanged(ListDataEvent e)
{
- // System.err.println(this + ".contentsChanged(" + e + ")");
BasicListUI.this.damageLayout();
}
@@ -132,7 +131,6 @@ public class BasicListUI extends ListUI
*/
public void intervalAdded(ListDataEvent e)
{
- // System.err.println(this + ".intervalAdded(" + e + ")");
BasicListUI.this.damageLayout();
}
@@ -143,7 +141,6 @@ public class BasicListUI extends ListUI
*/
public void intervalRemoved(ListDataEvent e)
{
- // System.err.println(this + ".intervalRemoved(" + e + ")");
BasicListUI.this.damageLayout();
}
}
@@ -161,7 +158,6 @@ public class BasicListUI extends ListUI
*/
public void valueChanged(ListSelectionEvent e)
{
- // System.err.println(this + ".valueChanged(" + e + ")");
}
}
@@ -189,12 +185,10 @@ public class BasicListUI extends ListUI
*/
public void mousePressed(MouseEvent event)
{
- // System.err.println("got mouse click event " + event);
int row = BasicListUI.this.convertYToRow(event.getY());
if (row == -1)
return;
- // System.err.println("clicked on row " + row);
BasicListUI.this.list.setSelectedIndex(row);
}
@@ -262,7 +256,6 @@ public class BasicListUI extends ListUI
*/
public void propertyChange(PropertyChangeEvent e)
{
- // System.err.println(this + ".propertyChange(" + e + ")");
if (e.getSource() == BasicListUI.this.list)
{
if (e.getOldValue() != null && e.getOldValue() instanceof ListModel)
@@ -357,6 +350,8 @@ public class BasicListUI extends ListUI
*/
public Rectangle getCellBounds(JList l, int index1, int index2)
{
+ maybeUpdateLayoutState();
+
if (l != list || cellWidth == -1)
return null;
@@ -366,6 +361,7 @@ public class BasicListUI extends ListUI
getRowHeight(lo));
Rectangle hibounds = new Rectangle(0, convertRowToY(hi), cellWidth,
getRowHeight(hi));
+
return lobounds.union(hibounds);
}
@@ -408,7 +404,6 @@ public class BasicListUI extends ListUI
{
int h = getRowHeight(row);
- // System.err.println("convertYToRow(" + y0 + ") vs. " + h);
if (y0 < h)
return row;
y0 -= h;
@@ -468,7 +463,6 @@ public class BasicListUI extends ListUI
*/
void maybeUpdateLayoutState()
{
- // System.err.println(this + ".maybeUpdateLayoutState()");
if (updateLayoutStateNeeded != 0)
{
updateLayoutState();
@@ -576,7 +570,6 @@ public class BasicListUI extends ListUI
installDefaults();
installListeners();
installKeyboardActions();
- // System.err.println(this + ".installUI()");
maybeUpdateLayoutState();
}
@@ -618,11 +611,9 @@ public class BasicListUI extends ListUI
*/
public Dimension getPreferredSize(JComponent c)
{
- maybeUpdateLayoutState();
if (list.getModel().getSize() == 0)
return new Dimension(0, 0);
- int nrows = Math.min(list.getVisibleRowCount(), list.getModel().getSize());
- Rectangle bounds = getCellBounds(list, 0, nrows - 1);
+ Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1);
return bounds.getSize();
}
@@ -678,7 +669,7 @@ public class BasicListUI extends ListUI
*/
public void paint(Graphics g, JComponent c)
{
- int nrows = Math.min(list.getVisibleRowCount(), list.getModel().getSize());
+ int nrows = list.getModel().getSize();
if (nrows == 0)
return;
@@ -687,11 +678,13 @@ public class BasicListUI extends ListUI
ListModel model = list.getModel();
ListSelectionModel sel = list.getSelectionModel();
int lead = sel.getLeadSelectionIndex();
+ Rectangle clip = g.getClipBounds();
paintBackground(g, list);
for (int row = 0; row < nrows; ++row)
{
Rectangle bounds = getCellBounds(list, row, row);
+ if (bounds.intersects(clip))
paintCell(g, row, bounds, render, model, sel, lead);
}
}
diff --git a/javax/swing/plaf/basic/BasicLookAndFeel.java b/javax/swing/plaf/basic/BasicLookAndFeel.java
index 314ab5f66..324fa01ff 100644
--- a/javax/swing/plaf/basic/BasicLookAndFeel.java
+++ b/javax/swing/plaf/basic/BasicLookAndFeel.java
@@ -250,7 +250,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"Button.foreground", new ColorUIResource(Color.black),
"Button.highlight", new ColorUIResource(Color.white),
"Button.light", new ColorUIResource(Color.lightGray.brighter()),
- "Button.margin", new InsetsUIResource(2, 2, 2, 2),
+ "Button.margin", new InsetsUIResource(2, 14, 2, 14),
"Button.shadow", new ColorUIResource(Color.gray),
"Button.textIconGap", new Integer(4),
"Button.textShiftOffset", new Integer(0),
@@ -493,7 +493,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"ENTER", "return",
"SPACE", "return"
},
- "Menutext.selectionBackground", new ColorUIResource(lightPurple),
+ "Menu.selectionBackground", new ColorUIResource(lightPurple),
"Menu.selectionForeground", new ColorUIResource(Color.black),
"MenuBar.background", new ColorUIResource(Color.lightGray),
"MenuBar.border", new BasicBorders.MenuBarBorder(null, null),
@@ -875,12 +875,12 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"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),
diff --git a/javax/swing/plaf/basic/BasicMenuBarUI.java b/javax/swing/plaf/basic/BasicMenuBarUI.java
index cff8a011c..f0bd73fa0 100644
--- a/javax/swing/plaf/basic/BasicMenuBarUI.java
+++ b/javax/swing/plaf/basic/BasicMenuBarUI.java
@@ -101,9 +101,9 @@ public class BasicMenuBarUI extends MenuBarUI
}
/**
- * DOCUMENT ME!
+ * Creates ChangeListener
*
- * @return DOCUMENT ME!
+ * @return The ChangeListener
*/
protected ChangeListener createChangeListener()
{
@@ -112,7 +112,7 @@ public class BasicMenuBarUI extends MenuBarUI
/**
* Creates ContainerListener() to listen for ContainerEvents
- * fired by JMenuBar
+ * fired by JMenuBar.
*
* @return The ContainerListener
*/
@@ -242,7 +242,7 @@ public class BasicMenuBarUI extends MenuBarUI
}
/**
- * DOCUMENT ME!
+ * Unregisters all the listeners that this UI delegate was using.
*/
protected void uninstallListeners()
{
@@ -273,7 +273,8 @@ public class BasicMenuBarUI extends MenuBarUI
}
/**
- * This class handles ContainerEvents fired by JMenuBar
+ * This class handles ContainerEvents fired by JMenuBar. It revalidates
+ * and repaints menu bar whenever menu is added or removed from it.
*/
protected class ContainerHandler implements ContainerListener
{
@@ -284,17 +285,19 @@ public class BasicMenuBarUI extends MenuBarUI
*/
public void componentAdded(ContainerEvent e)
{
- System.out.println("BasicMenuBar...componentAdded.. listener");
+ menuBar.revalidate();
+ menuBar.repaint();
}
/**
- * This method is called whenever menu is removed from the menu bar
+ * This method is called whenever menu is removed from the menu bar.
*
* @param e The ContainerEvent.
*/
public void componentRemoved(ContainerEvent e)
{
- System.out.println("BasicMenuBar...componentRemoved.. listener");
+ menuBar.revalidate();
+ menuBar.repaint();
}
}
@@ -313,6 +316,8 @@ public class BasicMenuBarUI extends MenuBarUI
{
if (e.getPropertyName().equals(JMenuBar.BORDER_PAINTED_CHANGED_PROPERTY))
menuBar.repaint();
+ if (e.getPropertyName().equals(JMenuBar.MARGIN_CHANGED_PROPERTY))
+ menuBar.repaint();
}
}
}
diff --git a/javax/swing/plaf/basic/BasicMenuItemUI.java b/javax/swing/plaf/basic/BasicMenuItemUI.java
index e5e407a55..e52d3f63e 100644
--- a/javax/swing/plaf/basic/BasicMenuItemUI.java
+++ b/javax/swing/plaf/basic/BasicMenuItemUI.java
@@ -35,7 +35,6 @@ 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;
@@ -152,7 +151,7 @@ public class BasicMenuItemUI extends MenuItemUI
protected Color selectionBackground;
/**
- * Color of the background that is used when menu item is selected.
+ * Color of the text that is used when menu item is selected.
*/
protected Color selectionForeground;
@@ -276,6 +275,11 @@ public class BasicMenuItemUI extends MenuItemUI
public MenuElement[] getPath()
{
ArrayList path = new ArrayList();
+
+ // Path to menu should also include its popup menu.
+ if (menuItem instanceof JMenu)
+ path.add(((JMenu) menuItem).getPopupMenu());
+
Component c = menuItem;
while (c instanceof MenuElement)
{
@@ -306,19 +310,6 @@ public class BasicMenuItemUI extends MenuItemUI
Icon arrowIcon,
int defaultTextIconGap)
{
- // FIXME: Need to implement.
- return null;
- }
-
- /**
- * Returns preferred size of the given component
- *
- * @param c component for which to return preferred size
- *
- * @return $Dimension$ preferred size for the given component
- */
- public Dimension getPreferredSize(JComponent c)
- {
JMenuItem m = (JMenuItem) c;
Dimension d = BasicGraphicsUtils.getPreferredButtonSize(m,
defaultTextIconGap);
@@ -361,10 +352,17 @@ public class BasicMenuItemUI extends MenuItemUI
}
/**
- * DOCUMENT ME!
+ * Returns preferred size of the given component
+ *
+ * @param c component for which to return preferred size
*
- * @return $returnType$ DOCUMENT ME!
+ * @return $Dimension$ preferred size for the given component
*/
+ public Dimension getPreferredSize(JComponent c)
+ {
+ return getPreferredMenuItemSize(c, checkIcon, arrowIcon, defaultTextIconGap);
+ }
+
protected String getPropertyPrefix()
{
return null;
@@ -416,6 +414,7 @@ public class BasicMenuItemUI extends MenuItemUI
protected void installListeners()
{
menuItem.addMouseListener(mouseInputListener);
+ menuItem.addMouseMotionListener(mouseInputListener);
menuItem.addMenuDragMouseListener(menuDragMouseListener);
menuItem.addMenuKeyListener(menuKeyListener);
menuItem.addPropertyChangeListener(propertyChangeListener);
@@ -433,6 +432,7 @@ public class BasicMenuItemUI extends MenuItemUI
super.installUI(c);
menuItem = (JMenuItem) c;
installDefaults();
+ installComponents(menuItem);
installListeners();
}
@@ -516,7 +516,7 @@ public class BasicMenuItemUI extends MenuItemUI
{
if (m.isContentAreaFilled())
{
- g.setColor(m.getBackground().darker());
+ g.setColor(selectionBackground);
g.fillRect(br.x, br.y, br.width, br.height);
}
}
@@ -529,6 +529,7 @@ public class BasicMenuItemUI extends MenuItemUI
}
}
+ // If this menu item is a JCheckBoxMenuItem then paint check icon
if (checkIcon != null)
{
SwingUtilities.layoutCompoundLabel(m, fm, null, checkIcon, vertAlign,
@@ -543,6 +544,7 @@ public class BasicMenuItemUI extends MenuItemUI
vr.x = cr.x + cr.width + defaultTextIconGap;
}
+ // if this is a submenu, then paint arrow icon to indicate it.
if (arrowIcon != null && (c instanceof JMenu))
{
if (! ((JMenu) c).isTopLevelMenu())
@@ -555,27 +557,25 @@ public class BasicMenuItemUI extends MenuItemUI
}
}
- // paint text and user menu icon if it exists
- SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), m.getIcon(),
- vertAlign, horAlign, vertTextPos,
- horTextPos, vr, ir, tr,
- defaultTextIconGap);
-
- paintText(g, m, tr, m.getText());
-
// paint icon
// FIXME: should paint different icon at different button state's.
// i.e disabled icon when button is disabled.. etc.
-
- /*
Icon i = m.getIcon();
if (i != null)
{
- int x = ir.x;
- int y = ir.y;
- i.paintIcon(c, g, x, y);
+ i.paintIcon(c, g, vr.x, vr.y);
+
+ // Adjust view rectangle, s.t text would be drawn after menu item's icon.
+ vr.x += i.getIconWidth() + defaultTextIconGap;
}
- */
+
+ // paint text and user menu icon if it exists
+ SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), m.getIcon(),
+ vertAlign, horAlign, vertTextPos,
+ horTextPos, vr, ir, tr,
+ defaultTextIconGap);
+
+ paintText(g, m, tr, m.getText());
// paint accelerator
String acceleratorText = "";
@@ -612,11 +612,28 @@ public class BasicMenuItemUI extends MenuItemUI
Font f = menuItem.getFont();
g.setFont(f);
FontMetrics fm = g.getFontMetrics(f);
- g.setColor(menuItem.getForeground());
+ if (text != null && ! text.equals(""))
+ {
+ if (menuItem.isEnabled())
+ g.setColor(menuItem.getForeground());
+ else
+ // FIXME: should fix this to use 'disabledForeground', but its
+ // default value in BasicLookAndFeel is null.
+ g.setColor(Color.gray);
+
+ int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
+
+ if (mnemonicIndex != -1)
+ BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,
+ textRect.x,
+ textRect.y
+ + fm.getAscent());
+ else
BasicGraphicsUtils.drawString(g, text, 0, textRect.x,
textRect.y + fm.getAscent());
}
+ }
/**
* This method uninstalls the components for this {@link JMenuItem}.
@@ -682,6 +699,7 @@ public class BasicMenuItemUI extends MenuItemUI
{
uninstallListeners();
uninstallDefaults();
+ uninstallComponents(menuItem);
menuItem = null;
}
@@ -751,7 +769,14 @@ public class BasicMenuItemUI extends MenuItemUI
{
g.setFont(acceleratorFont);
FontMetrics fm = g.getFontMetrics(acceleratorFont);
+
+ if (menuItem.isEnabled())
g.setColor(acceleratorForeground);
+ else
+ // FIXME: should fix this to use 'disabledForeground', but its
+ // default value in BasicLookAndFeel is null.
+ g.setColor(Color.gray);
+
BasicGraphicsUtils.drawString(g, acceleratorText, 0, acceleratorRect.x,
acceleratorRect.y + fm.getAscent());
}
@@ -859,14 +884,17 @@ public class BasicMenuItemUI extends MenuItemUI
*/
public void mouseReleased(MouseEvent e)
{
- Rectangle size = menuItem.getBounds(); //this.getParent().getSize();
+ Rectangle size = menuItem.getBounds();
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
if (e.getX() > 0 && e.getX() < size.width && e.getY() > 0
&& e.getY() < size.height)
{
- MenuSelectionManager manager = MenuSelectionManager.defaultManager();
manager.clearSelectedPath();
- menuItem.doClick(0);
+ menuItem.doClick();
}
+
+ else
+ manager.processMouseEvent(e);
}
}
@@ -882,6 +910,8 @@ public class BasicMenuItemUI extends MenuItemUI
*/
public void menuDragMouseDragged(MenuDragMouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(e.getPath());
}
/**
@@ -892,6 +922,8 @@ public class BasicMenuItemUI extends MenuItemUI
*/
public void menuDragMouseEntered(MenuDragMouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(e.getPath());
}
/**
@@ -912,6 +944,13 @@ public class BasicMenuItemUI extends MenuItemUI
*/
public void menuDragMouseReleased(MenuDragMouseEvent e)
{
+ MenuElement[] path = e.getPath();
+
+ if (path[path.length - 1] instanceof JMenuItem)
+ ((JMenuItem) path[path.length - 1]).doClick();
+
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
}
@@ -963,6 +1002,8 @@ public class BasicMenuItemUI extends MenuItemUI
*/
public void propertyChange(PropertyChangeEvent evt)
{
+ menuItem.revalidate();
+ menuItem.repaint();
}
}
}
diff --git a/javax/swing/plaf/basic/BasicMenuUI.java b/javax/swing/plaf/basic/BasicMenuUI.java
index 60559a4a0..01dca763d 100644
--- a/javax/swing/plaf/basic/BasicMenuUI.java
+++ b/javax/swing/plaf/basic/BasicMenuUI.java
@@ -213,8 +213,11 @@ public class BasicMenuUI extends BasicMenuItemUI
acceleratorFont = defaults.getFont("Menu.acceleratorFont");
acceleratorForeground = defaults.getColor("Menu.acceleratorForeground");
acceleratorSelectionForeground = defaults.getColor("Menu.acceleratorSelectionForeground");
+ selectionBackground = defaults.getColor("Menu.selectionBackground");
+ selectionForeground = defaults.getColor("Menu.selectionForeground");
arrowIcon = defaults.getIcon("Menu.arrowIcon");
oldBorderPainted = defaults.getBoolean("Menu.borderPainted");
+ menuItem.setOpaque(true);
}
/**
@@ -233,7 +236,9 @@ public class BasicMenuUI extends BasicMenuItemUI
protected void installListeners()
{
((JMenu) menuItem).addMouseListener(mouseInputListener);
+ ((JMenu) menuItem).addMouseMotionListener(mouseInputListener);
((JMenu) menuItem).addMenuListener(menuListener);
+ ((JMenu) menuItem).addMenuDragMouseListener(menuDragMouseListener);
}
protected void setupPostTimer(JMenu menu)
@@ -254,6 +259,8 @@ public class BasicMenuUI extends BasicMenuItemUI
acceleratorFont = null;
acceleratorForeground = null;
acceleratorSelectionForeground = null;
+ selectionBackground = null;
+ selectionForeground = null;
arrowIcon = null;
}
@@ -304,11 +311,10 @@ public class BasicMenuUI extends BasicMenuItemUI
selected. (If nothing was selected, menu should be pressed before
it will be selected)
*/
-
JMenu menu = (JMenu) menuItem;
if (! menu.isTopLevelMenu()
|| (menu.isTopLevelMenu()
- && (((JMenuBar) menu.getParent()).isSelected())))
+ && (((JMenuBar) menu.getParent()).isSelected() && ! menu.isArmed())))
{
// set new selection and forward this event to MenuSelectionManager
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
@@ -329,7 +335,6 @@ public class BasicMenuUI extends BasicMenuItemUI
public void mousePressed(MouseEvent e)
{
-
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
JMenu menu = (JMenu) menuItem;
manager.processMouseEvent(e);
@@ -339,11 +344,9 @@ public class BasicMenuUI extends BasicMenuItemUI
if (menu.isTopLevelMenu())
{
if (menu.getPopupMenu().isVisible())
- {
// If menu is visible and menu button was pressed..
// then need to cancel the menu
manager.clearSelectedPath();
- }
else
{
// Display the menu
@@ -374,30 +377,44 @@ public class BasicMenuUI extends BasicMenuItemUI
{
/**
* This method is called when menu is cancelled. The menu is cancelled
- * when its popup menu is closed without selection.
+ * when its popup menu is closed without selection. It clears selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuCanceled(MenuEvent e)
{
+ menuDeselected(e);
}
/**
- * This method is called when menu is deselected.
+ * This method is called when menu is deselected. It clears selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuDeselected(MenuEvent e)
{
+ JMenu menu = (JMenu) menuItem;
+ if (menu.isTopLevelMenu())
+ ((JMenuBar) menu.getParent()).getSelectionModel().clearSelection();
+ else
+ ((JPopupMenu) menu.getParent()).getSelectionModel().clearSelection();
}
/**
- * This method is called when menu is selected.
+ * This method is called when menu is selected. It sets selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuSelected(MenuEvent e)
{
+ JMenu menu = (JMenu) menuItem;
+ if (menu.isTopLevelMenu())
+ ((JMenuBar) menu.getParent()).setSelected(menu);
+ else
+ ((JPopupMenu) menu.getParent()).setSelected(menu);
}
}
@@ -426,31 +443,35 @@ public class BasicMenuUI extends BasicMenuItemUI
}
/**
- * This class handles mouse dragged events.
+ * This class handles mouse dragged events occuring in the menu.
*/
protected class MenuDragMouseHandler implements MenuDragMouseListener
{
/**
- * Tbis method is invoked when mouse is dragged over the menu item.
+ * This method is invoked when mouse is dragged over the menu item.
*
* @param e The MenuDragMouseEvent
*/
public void menuDragMouseDragged(MenuDragMouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(e.getPath());
}
/**
- * Tbis method is invoked when mouse enters the menu item while it is
+ * This method is invoked when mouse enters the menu item while it is
* being dragged.
*
* @param e The MenuDragMouseEvent
*/
public void menuDragMouseEntered(MenuDragMouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(e.getPath());
}
/**
- * Tbis method is invoked when mouse exits the menu item while
+ * This method is invoked when mouse exits the menu item while
* it is being dragged
*
* @param e The MenuDragMouseEvent
@@ -460,7 +481,7 @@ public class BasicMenuUI extends BasicMenuItemUI
}
/**
- * Tbis method is invoked when mouse was dragged and released
+ * This method is invoked when mouse was dragged and released
* inside the menu item.
*
* @param e The MenuDragMouseEvent
diff --git a/javax/swing/plaf/basic/BasicOptionPaneUI.java b/javax/swing/plaf/basic/BasicOptionPaneUI.java
index 8d65ee092..8a696b8cb 100644
--- a/javax/swing/plaf/basic/BasicOptionPaneUI.java
+++ b/javax/swing/plaf/basic/BasicOptionPaneUI.java
@@ -56,6 +56,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.beans.PropertyVetoException;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
@@ -63,6 +64,7 @@ import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
+import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
@@ -111,7 +113,7 @@ public class BasicOptionPaneUI extends OptionPaneUI
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();
@@ -131,6 +133,20 @@ public class BasicOptionPaneUI extends OptionPaneUI
if (owner instanceof JDialog)
((JDialog) owner).dispose();
+
+ //else we probably have some kind of internal frame.
+ JInternalFrame inf = (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class,
+ optionPane);
+ if (inf != null)
+ {
+ try
+ {
+ inf.setClosed(true);
+ }
+ catch (PropertyVetoException pve)
+ {
+ }
+ }
}
}
@@ -642,10 +658,10 @@ public class BasicOptionPaneUI extends OptionPaneUI
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);
@@ -837,8 +853,7 @@ public class BasicOptionPaneUI extends OptionPaneUI
{
public Dimension getPreferredSize()
{
- int w = Math.max(optionPane.getSize().width,
- minimumWidth);
+ int w = Math.max(optionPane.getSize().width, minimumWidth);
Insets i = optionPane.getInsets();
Dimension orig = super.getPreferredSize();
Dimension value = new Dimension(w - i.left - i.right - iconSize,
@@ -856,10 +871,13 @@ public class BasicOptionPaneUI extends OptionPaneUI
{
Object[] selection = optionPane.getSelectionValues();
+// 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 = new JTextField();
- else if (selection.length < 20)
- inputComponent = new JComboBox(selection);
+ inputComponent = null;
else
inputComponent = new JList(selection);
if (inputComponent != null)
@@ -972,7 +990,9 @@ public class BasicOptionPaneUI extends OptionPaneUI
tmp = questionIcon;
break;
}
- return new IconUIResource(tmp);
+ return tmp;
+ // FIXME: Don't cast till the default icons are in.
+ // return new IconUIResource(tmp);
}
/**
diff --git a/javax/swing/plaf/basic/BasicPopupMenuUI.java b/javax/swing/plaf/basic/BasicPopupMenuUI.java
index 48612d876..f5b3e24c2 100644
--- a/javax/swing/plaf/basic/BasicPopupMenuUI.java
+++ b/javax/swing/plaf/basic/BasicPopupMenuUI.java
@@ -40,15 +40,20 @@ package javax.swing.plaf.basic;
import java.awt.AWTKeyStroke;
import java.awt.BasicStroke;
import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagLayout;
+import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Stroke;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
@@ -88,14 +93,22 @@ import javax.swing.plaf.PopupMenuUI;
/**
- * DOCUMENT ME!
+ * UI Delegate for JPopupMenu
*/
public class BasicPopupMenuUI extends PopupMenuUI
{
+ /* popupMenu for which this UI delegate is for*/
protected JPopupMenu popupMenu;
+
+ /* MouseInputListener listens to mouse events */
private static transient MouseInputListener mouseInputListener;
+
+ /* PopupMenuListener listens to popup menu events fired by JPopupMenu*/
private transient PopupMenuListener popupMenuListener;
+ /* ComponentListener listening to popupMenu's invoker. */
+ private TopWindowListener topWindowListener;
+
/**
* Creates a new BasicPopupMenuUI object.
*/
@@ -103,14 +116,16 @@ public class BasicPopupMenuUI extends PopupMenuUI
{
popupMenuListener = new PopupMenuHandler();
mouseInputListener = new MouseInputHandler();
+ topWindowListener = new TopWindowListener();
}
/**
- * DOCUMENT ME!
+ * Factory method to create a BasicPopupMenuUI for the given {@link
+ * JComponent}, which should be a {@link JMenuItem}.
*
- * @param x DOCUMENT ME!
+ * @param x The {@link JComponent} a UI is being created for.
*
- * @return DOCUMENT ME!
+ * @return A BasicPopupMenuUI for the {@link JComponent}.
*/
public static ComponentUI createUI(JComponent x)
{
@@ -118,9 +133,11 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * Installs and initializes all fields for this UI delegate. Any properties
+ * of the UI that need to be initialized and/or set to defaults will be
+ * done now. It will also install any listeners necessary.
*
- * @param c DOCUMENT ME!
+ * @param c The {@link JComponent} that is having this UI installed.
*/
public void installUI(JComponent c)
{
@@ -128,14 +145,15 @@ public class BasicPopupMenuUI extends PopupMenuUI
popupMenu = (JPopupMenu) c;
popupMenu.setLayout(new GridBagLayout());
popupMenu.setBorderPainted(true);
- popupMenu.setDefaultLightWeightPopupEnabled(true);
+ JPopupMenu.setDefaultLightWeightPopupEnabled(true);
installDefaults();
installListeners();
}
/**
- * DOCUMENT ME!
+ * This method installs the defaults that are defined in the Basic look and
+ * feel for this {@link JPopupMenu}.
*/
public void installDefaults()
{
@@ -148,7 +166,7 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * This method installs the listeners for the {@link JMenuItem}.
*/
protected void installListeners()
{
@@ -158,16 +176,19 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * This method installs the keyboard actions for this {@link JPopupMenu}.
*/
protected void installKeyboardActions()
{
+ // FIXME: Need to implement
}
/**
- * DOCUMENT ME!
+ * Performs the opposite of installUI. Any properties or resources that need
+ * to be cleaned up will be done now. It will also uninstall any listeners
+ * it has. In addition, any properties of this UI will be nulled.
*
- * @param c DOCUMENT ME!
+ * @param c The {@link JComponent} that is having this UI uninstalled.
*/
public void uninstallUI(JComponent c)
{
@@ -177,7 +198,8 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * This method uninstalls the defaults and sets any objects created during
+ * install to null
*/
protected void uninstallDefaults()
{
@@ -188,25 +210,29 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * Unregisters all the listeners that this UI delegate was using.
*/
protected void uninstallListeners()
{
+ popupMenu.removeMouseListener(mouseInputListener);
+ popupMenu.removeMouseMotionListener(mouseInputListener);
+ popupMenu.removePopupMenuListener(popupMenuListener);
}
/**
- * DOCUMENT ME!
+ * Uninstalls any keyboard actions.
*/
protected void uninstallKeyboardActions()
{
+ // FIXME: Need to implement
}
/**
- * DOCUMENT ME!
+ * This method returns the minimum size of the JPopupMenu.
*
- * @param c DOCUMENT ME!
+ * @param c The JComponent to find a size for.
*
- * @return DOCUMENT ME!
+ * @return The minimum size.
*/
public Dimension getMinimumSize(JComponent c)
{
@@ -214,11 +240,11 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * This method returns the preferred size of the JPopupMenu.
*
- * @param c DOCUMENT ME!
+ * @param c The JComponent to find a size for.
*
- * @return DOCUMENT ME!
+ * @return The preferred size.
*/
public Dimension getPreferredSize(JComponent c)
{
@@ -226,11 +252,11 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * This method returns the minimum size of the JPopupMenu.
*
- * @param c DOCUMENT ME!
+ * @param c The JComponent to find a size for.
*
- * @return DOCUMENT ME!
+ * @return The minimum size.
*/
public Dimension getMaximumSize(JComponent c)
{
@@ -238,11 +264,13 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * Return true if given mouse event is a platform popup trigger,
+ * and false otherwise
*
- * @param e DOCUMENT ME!
+ * @param e MouseEvent that is to be checked for popup trigger event
*
- * @return DOCUMENT ME!
+ * @return true if given mouse event is a platform popup trigger,
+ * and false otherwise
*/
public boolean isPopupTrigger(MouseEvent e)
{
@@ -250,102 +278,153 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * DOCUMENT ME!
+ * This listener handles PopupMenuEvents fired by JPopupMenu
*/
- protected class PopupMenuHandler implements PopupMenuListener
+ private class PopupMenuHandler implements PopupMenuListener
{
/**
- * DOCUMENT ME!
+ * This method is invoked when JPopupMenu is cancelled.
*
- * @param event DOCUMENT ME!
+ * @param event the PopupMenuEvent
*/
public void popupMenuCanceled(PopupMenuEvent event)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
/**
- * DOCUMENT ME!
+ * This method is invoked when JPopupMenu becomes invisible
*
- * @param event DOCUMENT ME!
+ * @param event the PopupMenuEvent
*/
public void popupMenuWillBecomeInvisible(PopupMenuEvent event)
{
+ // remove listener that listens to component events fired
+ // by the top - level window that this popup belongs to.
+ Component invoker = popupMenu.getInvoker();
+
+ Container rootContainer = (Container) SwingUtilities.getRoot(invoker);
+ rootContainer.removeComponentListener(topWindowListener);
}
/**
- * DOCUMENT ME!
+ * This method is invoked when JPopupMenu becomes visible
*
- * @param event DOCUMENT ME!
+ * @param event the PopupMenuEvent
*/
public void popupMenuWillBecomeVisible(PopupMenuEvent event)
{
+ // Adds topWindowListener to top-level window to listener to
+ // ComponentEvents fired by it. We need to cancel this popup menu
+ // if topWindow to which this popup belongs was resized or moved.
+ Component invoker = popupMenu.getInvoker();
+ Container rootContainer = (Container) SwingUtilities.getRoot(invoker);
+ rootContainer.addComponentListener(topWindowListener);
+
+ // if this popup menu is a free floating popup menu,
+ // then by default its first element should be always selected when
+ // this popup menu becomes visible.
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+
+ if (manager.getSelectedPath().length == 0)
+ {
+ // Set selected path to point to the first item in the popup menu
+ MenuElement[] path = new MenuElement[2];
+ path[0] = popupMenu;
+ Component[] comps = popupMenu.getComponents();
+ if (comps.length != 0 && comps[0] instanceof MenuElement)
+ path[1] = (MenuElement) comps[0];
+ manager.setSelectedPath(path);
+ }
}
}
/**
- * DOCUMENT ME!
+ * ComponentListener that listens to Component Events fired by the
+ * top - level window to which popup menu belongs. If top-level
+ * window was resized, moved or hidded then popup menu will
+ * be hidded and selected path of current menu hierarchy will be set
+ * to null.
+ *
*/
- protected class MouseInputHandler implements MouseInputListener
+ private class TopWindowListener implements ComponentListener
{
/**
- * DOCUMENT ME!
+ * This method is invoked when top-level window is resized.
+ * This method closes current menu hierarchy.
*
- * @param e DOCUMENT ME!
+ * @param e The ComponentEvent
*/
- public void mouseClicked(MouseEvent e)
+ public void componentResized(ComponentEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
/**
- * DOCUMENT ME!
+ * This method is invoked when top-level window is moved.
+ * This method closes current menu hierarchy.
*
- * @param e DOCUMENT ME!
+ * @param e The ComponentEvent
*/
- public void mouseDragged(MouseEvent e)
+ public void componentMoved(ComponentEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
/**
- * DOCUMENT ME!
+ * This method is invoked when top-level window is shown
+ * This method does nothing by default.
*
- * @param e DOCUMENT ME!
+ * @param e The ComponentEvent
*/
- public void mouseEntered(MouseEvent e)
+ public void componentShown(ComponentEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
/**
- * DOCUMENT ME!
+ * This method is invoked when top-level window is hidden
+ * This method closes current menu hierarchy.
*
- * @param e DOCUMENT ME!
+ * @param e The ComponentEvent
*/
+ public void componentHidden(ComponentEvent e)
+ {
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
+ }
+ }
+
+ private class MouseInputHandler implements MouseInputListener
+ {
+ public void mouseClicked(MouseEvent e)
+ {
+ }
+
+ public void mouseDragged(MouseEvent e)
+ {
+ }
+
+ public void mouseEntered(MouseEvent e)
+ {
+ }
+
public void mouseExited(MouseEvent e)
{
}
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
public void mouseMoved(MouseEvent e)
{
}
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
public void mousePressed(MouseEvent e)
{
}
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
public void mouseReleased(MouseEvent e)
{
}
diff --git a/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java b/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java
index 4ae25532d..a63c95fbc 100644
--- a/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java
+++ b/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java
@@ -38,7 +38,6 @@ exception statement from your version. */
package javax.swing.plaf.basic;
import java.awt.event.MouseEvent;
-
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.MenuElement;
@@ -49,7 +48,7 @@ import javax.swing.plaf.ComponentUI;
/**
- * DOCUMENT ME!
+ * UI Delegator for JRadioButtonMenuItem
*/
public class BasicRadioButtonMenuItemUI extends BasicMenuItemUI
{
@@ -64,11 +63,12 @@ public class BasicRadioButtonMenuItemUI extends BasicMenuItemUI
}
/**
- * DOCUMENT ME!
+ * Factory method to create a BasicRadioButtonMenuItemUI for the given {@link
+ * JComponent}, which should be a JRadioButtonMenuItem.
*
- * @param b DOCUMENT ME!
+ * @param b The {@link JComponent} a UI is being created for.
*
- * @return $returnType$ DOCUMENT ME!
+ * @return A BasicRadioButtonMenuItemUI for the {@link JComponent}.
*/
public static ComponentUI createUI(JComponent b)
{
@@ -83,7 +83,6 @@ public class BasicRadioButtonMenuItemUI extends BasicMenuItemUI
protected String getPropertyPrefix()
{
return null;
- // TODO
}
/**
@@ -94,7 +93,8 @@ public class BasicRadioButtonMenuItemUI extends BasicMenuItemUI
* @param path DOCUMENT ME!
* @param manager DOCUMENT ME!
*/
- void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement[] path,
+ public void processMouseEvent(JMenuItem item, MouseEvent e,
+ MenuElement[] path,
MenuSelectionManager manager)
{
}
diff --git a/javax/swing/plaf/basic/BasicRootPaneUI.java b/javax/swing/plaf/basic/BasicRootPaneUI.java
index 96f09a119..7201549a2 100644
--- a/javax/swing/plaf/basic/BasicRootPaneUI.java
+++ b/javax/swing/plaf/basic/BasicRootPaneUI.java
@@ -38,12 +38,16 @@ exception statement from your version. */
package javax.swing.plaf.basic;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
+import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.RootPaneUI;
public class BasicRootPaneUI extends RootPaneUI
+ implements PropertyChangeListener
{
public static ComponentUI createUI(JComponent x)
{
@@ -53,7 +57,11 @@ public class BasicRootPaneUI extends RootPaneUI
public void installUI(JComponent c)
{
c.setOpaque(true);
- c.setBackground(javax.swing.UIManager.getColor("control"));
+ c.setBackground(UIManager.getColor("control"));
super.installUI(c);
}
+
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ }
}
diff --git a/javax/swing/plaf/basic/BasicScrollBarUI.java b/javax/swing/plaf/basic/BasicScrollBarUI.java
index 478ecc08d..913b3260b 100644
--- a/javax/swing/plaf/basic/BasicScrollBarUI.java
+++ b/javax/swing/plaf/basic/BasicScrollBarUI.java
@@ -548,14 +548,9 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
3));
/** The Icon that points right. */
- private static Icon rightIcon = new arrowIcon(new Polygon(new int[]
- {
- 3, 7, 3
- },
- new int[]
- {
- 2, 5, 8
- }, 3));
+ private static Icon rightIcon = new arrowIcon(new Polygon(new int[] { 3, 7, 3},
+ new int[] { 2, 5, 8},
+ 3));
/**
* This method adds a component to the layout.
@@ -606,7 +601,15 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
protected JButton createIncreaseButton(int orientation)
{
if (incrButton == null)
+ {
incrButton = new JButton();
+ incrButton.setMargin(new Insets(0,0,0,0));
+ incrButton.setHorizontalAlignment(SwingConstants.CENTER);
+ incrButton.setHorizontalTextPosition(SwingConstants.CENTER);
+ incrButton.setVerticalAlignment(SwingConstants.CENTER);
+ incrButton.setVerticalTextPosition(SwingConstants.CENTER);
+ }
+
if (orientation == SwingConstants.HORIZONTAL)
incrButton.setIcon(rightIcon);
else
@@ -626,7 +629,15 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
protected JButton createDecreaseButton(int orientation)
{
if (decrButton == null)
+ {
decrButton = new JButton();
+ decrButton.setMargin(new Insets(0,0,0,0));
+ decrButton.setHorizontalAlignment(SwingConstants.CENTER);
+ decrButton.setHorizontalTextPosition(SwingConstants.CENTER);
+ decrButton.setVerticalAlignment(SwingConstants.CENTER);
+ decrButton.setVerticalTextPosition(SwingConstants.CENTER);
+ }
+
if (orientation == SwingConstants.HORIZONTAL)
decrButton.setIcon(leftIcon);
else
diff --git a/javax/swing/plaf/basic/BasicScrollPaneUI.java b/javax/swing/plaf/basic/BasicScrollPaneUI.java
index 2148a9210..4d7041247 100644
--- a/javax/swing/plaf/basic/BasicScrollPaneUI.java
+++ b/javax/swing/plaf/basic/BasicScrollPaneUI.java
@@ -43,11 +43,15 @@ import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
+import javax.swing.ScrollPaneConstants;
import javax.swing.ScrollPaneLayout;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.ScrollPaneUI;
public class BasicScrollPaneUI extends ScrollPaneUI
+ implements ScrollPaneConstants
{
public static ComponentUI createUI(final JComponent c)
@@ -55,12 +59,37 @@ public class BasicScrollPaneUI extends ScrollPaneUI
return new BasicScrollPaneUI();
}
+ protected void installDefaults(JScrollPane p)
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ p.setForeground(defaults.getColor("ScrollPane.foreground"));
+ p.setBackground(defaults.getColor("ScrollPane.background"));
+ p.setFont(defaults.getFont("ScrollPane.font"));
+ p.setBorder(defaults.getBorder("ScrollPane.border"));
+ p.setOpaque(true);
+ }
+
+ protected void uninstallDefaults(JScrollPane p)
+ {
+ p.setForeground(null);
+ p.setBackground(null);
+ p.setFont(null);
+ p.setBorder(null);
+ }
public void installUI(final JComponent c)
{
super.installUI(c);
+ this.installDefaults((JScrollPane)c);
+ }
+
+ public void uninstallUI(final JComponent c)
+ {
+ super.uninstallUI(c);
+ this.uninstallDefaults((JScrollPane)c);
}
+
public Dimension getMinimumSize(JComponent c)
{
JScrollPane p = (JScrollPane ) c;
diff --git a/javax/swing/plaf/basic/BasicSliderUI.java b/javax/swing/plaf/basic/BasicSliderUI.java
index 073e42c0f..7334b2e0e 100644
--- a/javax/swing/plaf/basic/BasicSliderUI.java
+++ b/javax/swing/plaf/basic/BasicSliderUI.java
@@ -58,7 +58,6 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Dictionary;
import java.util.Enumeration;
-
import javax.swing.BoundedRangeModel;
import javax.swing.JComponent;
import javax.swing.JLabel;
@@ -152,7 +151,6 @@ public class BasicSliderUI extends SliderUI
{
// Maximum, minimum, and extent values will be taken
// care of automatically when the slider is repainted.
-
// Only thing that needs recalculation is the thumb.
calculateThumbLocation();
slider.repaint();
@@ -232,12 +230,12 @@ public class BasicSliderUI extends SliderUI
slider.getModel().addChangeListener(changeListener);
calculateThumbLocation();
}
+
// elif the componentOrientation changes (this is a bound property,
// just undocumented) we change leftToRightCache. In Sun's
// implementation, the LTR cache changes on a repaint. This is strange
// since there is no need to do so. We could events here and
// update the cache.
-
// elif the border/insets change, we recalculateInsets.
slider.repaint();
}
@@ -330,8 +328,9 @@ public class BasicSliderUI extends SliderUI
/** The current Y position of the mouse. */
protected int currentMouseY;
- /** The offset between the current slider value
- and the cursor's position. */
+ /**
+ * The offset between the current slider value and the cursor's position.
+ */
protected int offset;
/**
@@ -390,9 +389,6 @@ public class BasicSliderUI extends SliderUI
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()))
{
@@ -857,8 +853,8 @@ public class BasicSliderUI extends SliderUI
*/
/**
- * This method returns the preferred size when the slider is
- * horizontally oriented.
+ * This method returns the preferred size when the slider is horizontally
+ * oriented.
*
* @return The dimensions of the preferred horizontal size.
*/
@@ -868,8 +864,9 @@ public class BasicSliderUI extends SliderUI
// The width should cover all the labels (which are usually the
// deciding factor of the width)
- int width = getWidthOfWidestLabel() * (slider.getLabelTable() == null ?
- 0 : slider.getLabelTable().size());
+ int width = getWidthOfWidestLabel() * (slider.getLabelTable() == null ? 0
+ : slider.getLabelTable()
+ .size());
// If there are not enough labels.
// This number is pretty much arbitrary, but it looks nice.
@@ -878,28 +875,27 @@ public class BasicSliderUI extends SliderUI
// We can only draw inside of the focusRectangle, so we have to
// pad it with insets.
- width += insets.left + insets.right + focusInsets.left +
- focusInsets.right;
+ width += insets.left + insets.right + focusInsets.left + focusInsets.right;
// Height is determined by the thumb, the ticks and the labels.
int height = thumbHeight;
- if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 ||
- slider.getMinorTickSpacing() > 0)
+ if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
+ || slider.getMinorTickSpacing() > 0)
height += tickHeight;
if (slider.getPaintLabels())
height += getHeightOfTallestLabel();
- height += insets.top + insets.bottom + focusInsets.top +
- focusInsets.bottom;
+ height += insets.top + insets.bottom + focusInsets.top
+ + focusInsets.bottom;
return new Dimension(width, height);
}
/**
- * This method returns the preferred size when the slider is
- * vertically oriented.
+ * This method returns the preferred size when the slider is vertically
+ * oriented.
*
* @return The dimensions of the preferred vertical size.
*/
@@ -907,33 +903,33 @@ public class BasicSliderUI extends SliderUI
{
Insets insets = slider.getInsets();
- int height = getHeightOfTallestLabel() * (slider.getLabelTable() == null ?
- 0 : slider.getLabelTable().size());
+ int height = getHeightOfTallestLabel() * (slider.getLabelTable() == null
+ ? 0 : slider.getLabelTable()
+ .size());
if (height < 200)
height = 200;
- height += insets.top + insets.bottom + focusInsets.top +
- focusInsets.bottom;
+ height += insets.top + insets.bottom + focusInsets.top
+ + focusInsets.bottom;
int width = thumbHeight;
- if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 ||
- slider.getMinorTickSpacing() > 0)
+ if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
+ || slider.getMinorTickSpacing() > 0)
width += tickHeight;
if (slider.getPaintLabels())
width += getWidthOfWidestLabel();
- width += insets.left + insets.right + focusInsets.left +
- focusInsets.right;
+ width += insets.left + insets.right + focusInsets.left + focusInsets.right;
return new Dimension(width, height);
}
/**
- * This method returns the minimum size when the slider is
- * horizontally oriented.
+ * This method returns the minimum size when the slider is horizontally
+ * oriented.
*
* @return The dimensions of the minimum horizontal size.
*/
@@ -943,8 +939,8 @@ public class BasicSliderUI extends SliderUI
}
/**
- * This method returns the minimum size of the slider when it
- * is vertically oriented.
+ * This method returns the minimum size of the slider when it is vertically
+ * oriented.
*
* @return The dimensions of the minimum vertical size.
*/
@@ -1005,8 +1001,8 @@ public class BasicSliderUI extends SliderUI
}
/**
- * This method calculates all the sizes of the rectangles by delegating
- * to the helper methods calculateXXXRect.
+ * This method calculates all the sizes of the rectangles by delegating to
+ * the helper methods calculateXXXRect.
*/
protected void calculateGeometry()
{
@@ -1539,18 +1535,17 @@ public class BasicSliderUI extends SliderUI
c.translate((trackRect.width / 2) + (width / 2), trackRect.height);
d.translate((trackRect.width / 2) + (width / 2), 0);
}
- high = new Polygon(new int[] { b.x, c.x, d.x },
- new int[] { b.y, c.y, d.y }, 3);
- shadow = new Polygon(new int[] { b.x, a.x, d.x },
- new int[] { b.y, a.y, d.y }, 3);
+ g.setColor(Color.GRAY);
+ g.fillRect(a.x, a.y, width, height);
g.setColor(getHighlightColor());
- g.drawPolygon(high);
+ g.drawLine(b.x, b.y, c.x, c.y);
+ g.drawLine(c.x, c.y, d.x, d.y);
+
g.setColor(getShadowColor());
- g.drawPolygon(shadow);
+ g.drawLine(b.x, b.y, a.x, a.y);
+ g.drawLine(a.x, a.y, d.x, d.y);
- g.setColor(Color.GRAY);
- g.fillRect(a.x + 1, a.y + 1, width - 2, height - 2);
g.setColor(saved_color);
}
@@ -1662,8 +1657,11 @@ public class BasicSliderUI extends SliderUI
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 +1676,11 @@ public class BasicSliderUI extends SliderUI
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 +1695,11 @@ public class BasicSliderUI extends SliderUI
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 +1714,11 @@ public class BasicSliderUI extends SliderUI
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);
}
/**
@@ -1786,7 +1793,6 @@ public class BasicSliderUI extends SliderUI
// the labels may not fit inside the slider's bounds. Rather than mucking
// with font sizes and possible icon sizes, we'll set the bounds for
// the label and let it get clipped.
-
Dimension dim = label.getPreferredSize();
int w = (int) dim.getWidth();
int h = (int) dim.getHeight();
@@ -1804,8 +1810,6 @@ public class BasicSliderUI extends SliderUI
// | |
// | |
// The label must move w/2 to the right to fit directly under the value.
-
-
int xpos = xPositionForValue(value) - w / 2;
int ypos = labelRect.y;
diff --git a/javax/swing/plaf/basic/BasicSplitPaneDivider.java b/javax/swing/plaf/basic/BasicSplitPaneDivider.java
index e169f6d09..e06eb05f5 100644
--- a/javax/swing/plaf/basic/BasicSplitPaneDivider.java
+++ b/javax/swing/plaf/basic/BasicSplitPaneDivider.java
@@ -157,6 +157,29 @@ public class BasicSplitPaneDivider extends Container
* 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 @@ public class BasicSplitPaneDivider extends Container
setLayout(new DividerLayout());
setBasicSplitPaneUI(ui);
setDividerSize(splitPane.getDividerSize());
+ setBorder(tmpBorder);
}
/**
diff --git a/javax/swing/plaf/basic/BasicSplitPaneUI.java b/javax/swing/plaf/basic/BasicSplitPaneUI.java
index f1ccb1339..f73b52045 100644
--- a/javax/swing/plaf/basic/BasicSplitPaneUI.java
+++ b/javax/swing/plaf/basic/BasicSplitPaneUI.java
@@ -133,7 +133,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
throw new IllegalArgumentException("Illegal placement in JSplitPane");
components[i] = component;
resetSizeAt(i);
- layoutContainer(splitPane);
+ splitPane.revalidate();
splitPane.repaint();
}
@@ -1265,15 +1265,9 @@ public class BasicSplitPaneUI extends SplitPaneUI
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.revalidate();
splitPane.repaint();
}
@@ -1414,7 +1408,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
getSplitPane().setLayout(layoutManager);
// invalidating by itself does not invalidate the layout.
- getSplitPane().invalidate();
+ getSplitPane().revalidate();
}
/**
@@ -1437,7 +1431,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
nonContinuousLayoutDivider.setVisible(true);
nonContinuousLayoutDivider.setBounds(divider.getBounds());
}
- splitPane.invalidate();
+ splitPane.revalidate();
splitPane.repaint();
}
diff --git a/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/javax/swing/plaf/basic/BasicTabbedPaneUI.java
index b1929aa36..44e302b01 100644
--- a/javax/swing/plaf/basic/BasicTabbedPaneUI.java
+++ b/javax/swing/plaf/basic/BasicTabbedPaneUI.java
@@ -1108,7 +1108,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants
{
selectedRun = getRunForTab(tabPane.getTabCount(),
tabPane.getSelectedIndex());
- tabPane.layout();
+ tabPane.revalidate();
tabPane.repaint();
}
}
diff --git a/javax/swing/plaf/basic/BasicTextFieldUI.java b/javax/swing/plaf/basic/BasicTextFieldUI.java
new file mode 100644
index 000000000..b43fd97cf
--- /dev/null
+++ b/javax/swing/plaf/basic/BasicTextFieldUI.java
@@ -0,0 +1,82 @@
+/* BasicTextFieldUI.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.beans.PropertyChangeEvent;
+
+import javax.swing.JComponent;
+import javax.swing.JTextField;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.text.Element;
+import javax.swing.text.FieldView;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.View;
+
+public class BasicTextFieldUI extends BasicTextUI
+{
+ public BasicTextFieldUI()
+ {
+ super();
+ }
+
+ public View create(Element elem)
+ {
+ return new FieldView(elem);
+ }
+
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicTextFieldUI();
+ }
+
+ protected String getPropertyPrefix()
+ {
+ return "TextField";
+ }
+
+ public void installUI(JComponent c)
+ {
+ super.installUI(c);
+ }
+
+ protected void propertyChange(PropertyChangeEvent event)
+ {
+ // Does nothing by default.
+ }
+}
diff --git a/javax/swing/plaf/basic/BasicTextUI.java b/javax/swing/plaf/basic/BasicTextUI.java
index af7ab7e3a..817a5e4a2 100644
--- a/javax/swing/plaf/basic/BasicTextUI.java
+++ b/javax/swing/plaf/basic/BasicTextUI.java
@@ -1,5 +1,5 @@
/* BasicTextUI.java
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,85 +35,186 @@ 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.Container;
import java.awt.Dimension;
import java.awt.Graphics;
+import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.Shape;
+
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.TextUI;
+import javax.swing.plaf.UIResource;
import javax.swing.text.BadLocationException;
+import javax.swing.text.Caret;
+import javax.swing.text.DefaultCaret;
import javax.swing.text.DefaultEditorKit;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.Element;
+import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
+import javax.swing.text.PlainDocument;
import javax.swing.text.Position;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
-public class BasicTextUI extends TextUI
+public abstract class BasicTextUI extends TextUI
implements ViewFactory
{
- int gap = 3;
- View view = null; // was: new RootView();
- Color textColor;
- Color disabledTextColor;
- Color normalBackgroundColor;
- EditorKit kit = new DefaultEditorKit();
+ public static class BasicCaret extends DefaultCaret
+ implements UIResource
+ {
+ public BasicCaret()
+ {
+ }
+ }
+
+ public static class BasicHighlighter extends DefaultHighlighter
+ implements UIResource
+ {
+ public BasicHighlighter()
+ {
+ }
+ }
- /* *****************************************************************
- * This View is way too incomplete to be of any use. To avoid errors
- * when compiling with the Sun JDK, it has been commented out.
- * -- Sascha Brawer (brawer@dandelis.ch)
- *
- * (begin of commented out section)
- class RootView extends View
+ private class RootView extends View
{
- RootView()
+ private JTextComponent textComponent;
+ private View view;
+
+ public RootView(JTextComponent parent)
{
super(null);
+ textComponent = parent;
}
- public void paint(Graphics g, Shape s)
+
+ public void setView(View v)
{
if (view != null)
+ view.setParent(null);
+
+ if (v != null)
+ v.setParent(null);
+
+ view = v;
+ }
+
+ public Container getContainer()
{
- Rectangle r = s.getBounds();
+ return textComponent;
+ }
+
+ public float getPreferredSpan(int axis)
+ {
+ if (view != null)
+ return view.getPreferredSpan(axis);
- view.setSize((int)r.getWidth(),
- (int)r.getHeight());
- view.paint(g, s);
+ return Integer.MAX_VALUE;
}
+
+ public void paint(Graphics g, Shape s)
+ {
+ System.out.println("Michael: BasicTextUI.RootView.paint");
+
+ if (view != null)
+ view.paint(g, s);
}
}
- * (end of commented out section)
- *************************************************************** */
+
+ RootView rootView;
+ JTextComponent textComponent;
+ int gap = 3;
+ EditorKit kit = new DefaultEditorKit();
+
public BasicTextUI()
{
}
- public static ComponentUI createUI(final JComponent c)
+ protected Caret createCaret()
{
- return new BasicTextUI();
+ return new BasicCaret();
+ }
+
+ protected Highlighter createHighlighter()
+ {
+ return new BasicHighlighter();
+ }
+
+ protected final JTextComponent getComponent()
+ {
+ return textComponent;
}
public void installUI(final JComponent c)
{
super.installUI(c);
+ c.setOpaque(true);
- textColor = new Color(0, 0, 0);
- disabledTextColor = new Color(130, 130, 130);
- normalBackgroundColor = new Color(192, 192, 192);
+ textComponent = (JTextComponent) c;
+
+ Document doc = textComponent.getDocument();
+ if (doc == null)
+ {
+ doc = new PlainDocument();
+ textComponent.setDocument(doc);
}
- public Dimension getPreferredSize(JComponent c)
+ rootView = new RootView(textComponent);
+ setView(create(doc.getDefaultRootElement()));
+
+ installDefaults();
+ installListeners();
+ installKeyboardActions();
+ }
+
+ protected void installDefaults()
+ {
+ }
+
+ protected void installListeners()
{
- JTextComponent b = (JTextComponent) c;
+ }
- View v = getRootView(b);
+ protected void installKeyboardActions()
+ {
+ }
+
+ public void uninstallUI(final JComponent c)
+ {
+ super.uninstallUI(c);
+ rootView = null;
+
+ uninstallDefaults();
+ uninstallListeners();
+ uninstallKeyboardActions();
+ }
+
+ protected void uninstallDefaults()
+ {
+ }
+
+ protected void uninstallListeners()
+ {
+ }
+
+ protected void uninstallKeyboardActions()
+ {
+ }
+
+ protected abstract String getPropertyPrefix();
+
+ public Dimension getPreferredSize(JComponent c)
+ {
+ View v = getRootView(textComponent);
float w = v.getPreferredSpan(View.X_AXIS);
float h = v.getPreferredSpan(View.Y_AXIS);
@@ -121,9 +222,32 @@ public class BasicTextUI extends TextUI
return new Dimension((int) w, (int) h);
}
- public void paint(Graphics g, JComponent c)
+ public final void paint(Graphics g, JComponent c)
{
- // view.paint(
+ paintSafely(g);
+ }
+
+ protected void paintSafely(Graphics g)
+ {
+ Caret caret = textComponent.getCaret();
+ Highlighter highlighter = textComponent.getHighlighter();
+
+ if (textComponent.isOpaque())
+ paintBackground(g);
+
+ rootView.paint(g, getVisibleEditorRect());
+
+ if (highlighter != null)
+ highlighter.paint(g);
+
+ if (caret != null)
+ caret.paint(g);
+ }
+
+ protected void paintBackground(Graphics g)
+ {
+ g.setColor(Color.WHITE); // FIXME: set background color
+ g.fillRect(0, 0, textComponent.getWidth(), textComponent.getHeight());
}
public void damageRange(JTextComponent t, int p0, int p1)
@@ -151,7 +275,7 @@ public class BasicTextUI extends TextUI
public View getRootView(JTextComponent t)
{
- return view;
+ return rootView;
}
public Rectangle modelToView(JTextComponent t, int pos)
@@ -181,4 +305,30 @@ public class BasicTextUI extends TextUI
// subclasses have to implement this to get this functionality
return null;
}
+
+ public View create(Element elem, int p0, int p1)
+ {
+ // subclasses have to implement this to get this functionality
+ return null;
+ }
+
+ protected Rectangle getVisibleEditorRect()
+ {
+ int width = textComponent.getWidth();
+ int height = textComponent.getHeight();
+
+ if (width <= 0 || height <= 0)
+ return null;
+
+ Insets insets = textComponent.getInsets();
+ return new Rectangle(insets.left, insets.top,
+ width - insets.left + insets.right,
+ height - insets.top + insets.bottom);
+ }
+
+ protected final void setView(View view)
+ {
+ rootView.setView(view);
+ view.setParent(rootView);
+ }
}
diff --git a/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java b/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java
new file mode 100644
index 000000000..f35968c65
--- /dev/null
+++ b/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java
@@ -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;
+ }
+}
diff --git a/javax/swing/plaf/basic/BasicToolBarUI.java b/javax/swing/plaf/basic/BasicToolBarUI.java
index 9e935a276..4fb142b1c 100644
--- a/javax/swing/plaf/basic/BasicToolBarUI.java
+++ b/javax/swing/plaf/basic/BasicToolBarUI.java
@@ -37,304 +37,1401 @@ exception statement from your version. */
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.border.Border;
import javax.swing.event.MouseInputListener;
-
-import java.beans.PropertyChangeListener;
-import java.awt.event.ContainerListener;
-import java.awt.event.FocusListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.WindowListener;
-
+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
+
+/**
+ * This is the Basic Look and Feel UI class for JToolBar.
+ */
+public class BasicToolBarUI extends ToolBarUI implements SwingConstants
{
+ /** Static owner of all DragWindows. */
+ private static JFrame owner = new JFrame();
+
+ /** The border used when the JToolBar is in nonrollover mode. */
+ private static Border nonRolloverBorder;
- public class DragWindow
- {}
+ /** 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;
- //protected KeyStroke downKey
- // Deprecated. As of Java 2 platform v1.3.
+
+ /** 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;
- //protected KeyStroke leftKey;
- // Deprecated. As of Java 2 platform v1.3.
+
+ /** The PropertyChangeListener for the JToolBar. */
protected PropertyChangeListener propertyListener;
- //protected KeyStroke rightKey;
- // Deprecated. As of Java 2 platform v1.3.
+
+ /** The JToolBar this UI delegate is responsible for. */
protected JToolBar toolBar;
+
+ /** The Container listener for the JToolBar. */
protected ContainerListener toolBarContListener;
- protected FocusListener toolBarFocusListener;
- // protected KeyStroke upKey;
- // Deprecated. As of Java 2 platform v1.3.
- private Dimension maximumSize;
- private Dimension minimumSize;
- private Dimension preferredSize;
- private boolean floating;
- private boolean rolloverBorders;
+ /** 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;
- BasicToolBarUI(JToolBar b)
+ /** 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)
{
super();
}
- /* Can Component c dock at Point p? */
- boolean canDock(Component c, Point p)
+ /**
+ * 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;
+
return false;
}
+ /**
+ * 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();
+
+ // 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);
+
+ // The order of checking is 1. top 2. bottom 3. left 4. right
+ if (! pBounds.contains(p))
+ return -1;
+
+ if (p.y < limit)
+ return SwingConstants.NORTH;
+
+ if (p.y > (pBounds.height - limit))
+ return SwingConstants.SOUTH;
+
+ if (p.x < limit)
+ return SwingConstants.WEST;
+
+ if (p.x > (pBounds.width - limit))
+ return SwingConstants.EAST;
+
+ return -1;
+ }
+
+ /**
+ * This method creates a new DockingListener for the JToolBar.
+ *
+ * @return A new DockingListener for the JToolBar.
+ */
protected MouseInputListener createDockingListener()
{
- return null;
+ return new DockingListener(toolBar);
}
+ /**
+ * 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 null;
+ return new DragWindow();
}
+ /**
+ * 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;
}
+ /**
+ * 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)
{
- return null;
+ // This one is used by default though.
+ return new ToolBarDialog();
}
+ /**
+ * This method creates a new WindowListener for the JToolBar.
+ *
+ * @return A new WindowListener.
+ */
protected WindowListener createFrameListener()
{
- return null;
+ return new FrameListener();
}
+ /**
+ * 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 null;
+ return new EtchedBorderUIResource();
}
+ /**
+ * This method creates a new PropertyChangeListener for the JToolBar.
+ *
+ * @return A new PropertyChangeListener.
+ */
protected PropertyChangeListener createPropertyListener()
{
- return null;
+ return new PropertyListener();
}
+ /**
+ * 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 null;
+ 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);
+ }
+ }
+ };
}
+ /**
+ * This method creates a new Container listener for the JToolBar.
+ *
+ * @return A new Container listener.
+ */
protected ContainerListener createToolBarContListener()
{
- return null;
+ return new ToolBarContListener();
}
+ /**
+ * This method creates a new FocusListener for the JToolBar.
+ *
+ * @return A new FocusListener for the JToolBar.
+ */
protected FocusListener createToolBarFocusListener()
{
- return null;
+ return new ToolBarFocusListener();
}
+ /**
+ * 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;
}
- /* Return the Color which is displayed when over a docking area */
- Color getDockingColor()
+ 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;
}
- /* Return the Color which is displayed when over a floating area */
- Color getFloatingColor()
+ /**
+ * 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;
}
- /* See ComponentUI */
+ /**
+ * 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);
}
+ /**
+ * This method installs the needed components for the JToolBar.
+ */
protected void installComponents()
{
+ floatFrame = (Window) createFloatingWindow(toolBar);
+
+ 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"));
+
+ 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)
{
- toolbar.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent event) {
- System.err.println("toolbar clicked");
- }
- } );
- }
+ dockingListener = createDockingListener();
+ toolBar.addMouseListener(dockingListener);
+ toolBar.addMouseMotionListener(dockingListener);
- /* Call setBorderToNonRollover for each child component of c */
+ 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]);
}
- /* Call setBorderToNormal for each child component of c */
+ /**
+ * 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]);
}
- /* Call setBorderToRollover for each child component of c */
+ /**
+ * 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);
- 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;
- }
+ installDefaults();
+ installComponents();
installListeners(toolBar);
+ installKeyboardActions();
}
}
- boolean isFloating()
+ /**
+ * This method returns whether the JToolBar is floating.
+ *
+ * @return Whether the JToolBar is floating.
+ */
+ public boolean isFloating()
{
- return false;
+ return floatFrame.isVisible();
}
- boolean isRolloverBorders()
+ /**
+ * This method returns whether rollover borders have been set.
+ *
+ * @return Whether rollover borders have been set.
+ */
+ public boolean isRolloverBorders()
{
- return false;
+ 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.
}
- /* Make Component c have a non-rollover border (created by
- createNonRolloverBorder). */
+ /**
+ * 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);
+ }
}
- /* Make Component c have the border that it originally had before being
- added to the toolbar. */
+ /**
+ * 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);
+ }
}
- /* Make Component c have a rollover border (created by
- createRolloverBorder). */
+ /**
+ * 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);
+ }
}
- /* Display in Color c when over a docking area */
- void setDockingColor(Color c)
+ /**
+ * This method sets the docking color.
+ *
+ * @param c The docking color.
+ */
+ public void setDockingColor(Color c)
{
dockingColor = c;
}
- void setFloating(boolean b, Point p)
+ /**
+ * 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;
}
- /* Display in Color c when over a floating area */
- void setFloatingColor(Color 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()
{
- floatingColor = c;
+ 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;
}
- void setFloatingLocation(int x, int y)
+ /**
+ * This method uninstalls keyboard actions installed by the UI.
+ */
+ protected void uninstallKeyboardActions()
{
+ // FIXME: implement.
}
- void setOrientation(int orientation)
+ /**
+ * 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;
}
- /* Set flag to enable rollover borders for the toolbar */
- void setRolloverBorders(boolean rollover)
+ /**
+ * 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)
{
- rolloverBorders = rollover;
+ toolBar = t;
}
- protected void uninstallComponents()
+ /**
+ * This method is called when the mouse is clicked.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseClicked(MouseEvent e)
{
+ // Don't care.
}
- protected void uninstallDefaults()
+ /**
+ * 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);
}
- protected void uninstallKeyboardActions()
+ /**
+ * This method is called when the mouse enters the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseEntered(MouseEvent e)
{
+ // Don't care (yet).
}
- protected void uninstallListeners()
+ /**
+ * 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 uninstallUI(JComponent c)
+ /**
+ * This method is called when the mouse is moved in the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseMoved(MouseEvent e)
+ {
+ }
+
+ /**
+ * 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)
+ {
+ 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);
+ }
+
+ /**
+ * This method is called when the mouse is released from the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseReleased(MouseEvent e)
+ {
+ if (! isDragging || ! toolBar.isFloatable())
+ return;
+
+ isDragging = false;
+ floatAt(e.getPoint(), origin);
+ dragWindow.hide();
+ }
+ }
+
+ /**
+ * 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(owner);
+ }
+
+ /**
+ * The color that the border should be.
+ *
+ * @return The border color.
+ */
+ public Color getBorderColor()
+ {
+ if (borderColor == null)
+ return Color.BLACK;
+
+ return borderColor;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * This method returns the mouse offset from the top left corner of the
+ * DragWindow.
+ *
+ * @return The mouse offset.
+ */
+ public Point getOffset()
+ {
+ return offset;
+ }
+
+ /**
+ * This method paints the DragWindow.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ // 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);
+ }
+
+ /**
+ * This method changes the border color.
+ *
+ * @param c The new border color.
+ */
+ public void setBorderColor(Color c)
+ {
+ borderColor = c;
+ }
+
+ /**
+ * This method changes the mouse offset.
+ *
+ * @param p The new mouse offset.
+ */
+ public void setOffset(Point p)
{
+ offset = p;
}
+ /**
+ * FIXME: Do something.
+ *
+ * @param o DOCUMENT ME!
+ */
+ public void setOrientation(int o)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * 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();
+ }
+ }
+
+ /**
+ * 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());
+ }
+ }
+
+ /**
+ * 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();
+ }
+ }
+
+ /**
+ * 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();
+ setName((toolBar.getName() != null) ? toolBar.getName() : "");
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ protected class ToolBarFocusListener implements FocusListener
+ {
+ /**
+ * Creates a new ToolBarFocusListener object.
+ */
+ protected ToolBarFocusListener()
+ {
+ // FIXME: implement.
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void focusGained(FocusEvent e)
+ {
+ // FIXME: implement.
+ }
+
+ /**
+ * 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);
+ }
+ }
+ }
+ }
}
diff --git a/javax/swing/plaf/basic/BasicViewportUI.java b/javax/swing/plaf/basic/BasicViewportUI.java
index 715c11a68..feefacaae 100644
--- a/javax/swing/plaf/basic/BasicViewportUI.java
+++ b/javax/swing/plaf/basic/BasicViewportUI.java
@@ -173,6 +173,7 @@ public class BasicViewportUI extends ViewportUI
g.clearRect(0, 0, portBounds.width, portBounds.height);
}
+ g2.setClip(g.getClipBounds());
g2.translate(-pos.x, -pos.y);
try
{
diff --git a/javax/swing/plaf/basic/Makefile.am b/javax/swing/plaf/basic/Makefile.am
index b1cfdb950..07d0b912b 100644
--- a/javax/swing/plaf/basic/Makefile.am
+++ b/javax/swing/plaf/basic/Makefile.am
@@ -30,7 +30,9 @@ BasicSliderUI.java \
BasicSplitPaneDivider.java \
BasicSplitPaneUI.java \
BasicTabbedPaneUI.java \
+BasicTextFieldUI.java \
BasicTextUI.java \
+BasicToolBarSeparatorUI.java \
BasicToolBarUI.java \
BasicToggleButtonUI.java \
BasicTreeUI.java \