This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui][PATCH] InternalFrame Dialogs for JOptionPane and other fixes
- From: Kim Ho <kho at redhat dot com>
- To: java-patches <java-patches at gcc dot gnu dot org>
- Date: Thu, 15 Jul 2004 22:21:40 -0400
- Subject: [gui][PATCH] InternalFrame Dialogs for JOptionPane and other fixes
Hi,
This add showInternalXXXDialogs for JOptionPane, changes the redispatch
for JInternalFrame and has a couple other fixes.
Cheers,
Kim
2004-07-15 Kim Ho <kho@redhat.com>
* javax/swing/DefaultDesktopManager.java:
(findMinimum): Removed.
(resizeFrame): Trust the UI to pass valid
bounds.
* javax/swing/JOptionPane.java:
Implemented showInternalXXXDialog methods.
(startModal): New method.
* javax/swing/plaf/basic/BasicInternalFrameUI.java:
(BorderListener::mouseDragged): Verify that the new
bounds are valid before passing them to the DesktopManager.
(preferredLayoutSize): Delegate
to getSize.
(minimumLayoutSize): Ditto.
(getSize): New method.
(GlassPaneDispatcher): Reimplemented by copying
a stripped down LightweightDispatcher from Container.
(getMinimumSize): Call minimumLayoutSize.
* javax/swing/plaf/basic/BasicOptionPaneUI.java:
Ran Jalopy.
(mousePressed): Add ability to properly close
JInternalFrames.
* javax/swing/plaf/basic/BasicToolBarUI.java:
(DragWindow): Set owner for DragWindow.
Index: javax/swing/DefaultDesktopManager.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/DefaultDesktopManager.java,v
retrieving revision 1.3.8.1
diff -u -r1.3.8.1 DefaultDesktopManager.java
--- javax/swing/DefaultDesktopManager.java 9 Jun 2004 20:55:10 -0000 1.3.8.1
+++ javax/swing/DefaultDesktopManager.java 16 Jul 2004 02:24:01 -0000
@@ -84,7 +84,7 @@
private transient Container pane;
/**
- * An array of Rectangles that holds the bounds of the JDesktopIcons in the
+ * An array of Rectangles that holds the bounds of the JDesktopIcons in the
* JDesktopPane when looking for where to place a new icon.
*/
private transient Rectangle[] iconRects;
@@ -436,7 +436,6 @@
int newWidth, int newHeight)
{
dragCache.setBounds(newX, newY, newWidth, newHeight);
- dragCache = findMinimum(dragCache, component);
if (currentDragMode == JDesktopPane.OUTLINE_DRAG_MODE)
{
@@ -628,27 +627,4 @@
{
return frame.getWasIcon();
} // wasIcon()
-
- /**
- * This is a helper method that determines the minimum size a
- * JInternalFrame can be resized to.
- *
- * @param r The desired size.
- * @param c The JComponent to find a minimum size for.
- *
- * @return The minimum size a JInternalFrame can be resized to.
- */
- private Rectangle findMinimum(Rectangle r, JComponent c)
- {
- if (r != null && c != null)
- {
- Dimension d = c.getPreferredSize();
- if (d != null)
- {
- r.width = Math.max(d.width, r.width);
- r.height = Math.max(d.height, r.height);
- }
- }
- return r;
- }
} // DefaultDesktopManager
Index: javax/swing/JOptionPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JOptionPane.java,v
retrieving revision 1.3.2.5
diff -u -r1.3.2.5 JOptionPane.java
--- javax/swing/JOptionPane.java 9 Jun 2004 20:55:10 -0000 1.3.2.5
+++ javax/swing/JOptionPane.java 16 Jul 2004 02:24:01 -0000
@@ -39,11 +39,15 @@
import java.awt.Component;
import java.awt.Dialog;
+import java.awt.Dimension;
import java.awt.Frame;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.swing.Icon;
+import javax.swing.JInternalFrame;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
import javax.swing.plaf.OptionPaneUI;
@@ -60,8 +64,9 @@
*/
protected class AccessibleJOptionPane extends JComponent.AccessibleJComponent
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 686071432213084821L;
-
+
/**
* Creates a new AccessibleJOptionPane object.
*/
@@ -80,8 +85,9 @@
}
}
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 5231143276678566796L;
-
+
/** The value returned when cancel option is selected. */
public static final int CANCEL_OPTION = 2;
@@ -373,6 +379,8 @@
dialog.getContentPane().add(this);
dialog.setModal(true);
dialog.setResizable(false);
+ dialog.invalidate();
+ dialog.repaint();
return dialog;
}
@@ -394,8 +402,21 @@
String title)
throws RuntimeException
{
- // FIXME: implement.
- return null;
+ JDesktopPane toUse = getDesktopPaneForComponent(parentComponent);
+ if (toUse == null)
+ throw new RuntimeException("parentComponent does not have a valid parent");
+
+ JInternalFrame frame = new JInternalFrame(title);
+
+ inputValue = UNINITIALIZED_VALUE;
+ value = UNINITIALIZED_VALUE;
+
+ frame.setClosable(true);
+ toUse.add(frame);
+
+ // FIXME: JLayeredPane broken? See bug # 16576
+ // frame.setLayer(JLayeredPane.MODAL_LAYER);
+ return frame;
}
/**
@@ -421,7 +442,8 @@
*/
public static JDesktopPane getDesktopPaneForComponent(Component parentComponent)
{
- return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, parentComponent);
+ return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
+ parentComponent);
}
/**
@@ -434,7 +456,8 @@
*/
public static Frame getFrameForComponent(Component parentComponent)
{
- return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent);
+ return (Frame) SwingUtilities.getAncestorOfClass(Frame.class,
+ parentComponent);
}
/**
@@ -822,6 +845,7 @@
{
JOptionPane pane = new JOptionPane(message);
JDialog dialog = pane.createDialog(parentComponent, "Select an Option");
+
dialog.pack();
dialog.show();
@@ -1064,123 +1088,171 @@
}
/**
- * DOCUMENT ME!
+ * This method shows an internal confirmation dialog with the given message.
+ * The internal frame dialog will be placed in the first JDesktopPane
+ * ancestor of the given parentComponent. This method will return the value
+ * selected.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
*
- * @return DOCUMENT ME!
+ * @return The value selected.
*/
public static int showInternalConfirmDialog(Component parentComponent,
Object message)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, null);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal confirmation dialog with the given message,
+ * optionType and title. The internal frame dialog will be placed in the
+ * first JDesktopPane ancestor of the given parentComponent. This method
+ * will return the selected value.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param optionType DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param optionType The option type.
*
- * @return DOCUMENT ME!
+ * @return The selected value.
*/
public static int showInternalConfirmDialog(Component parentComponent,
Object message, String title,
int optionType)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal confirmation dialog with the given message,
+ * title, optionTypes and icon for the given message type. The internal
+ * confirmation dialog will be placed in the first instance of
+ * JDesktopPane ancestor of the given parentComponent.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param optionType DOCUMENT ME!
- * @param messageType DOCUMENT ME!
+ * @param parentComponent The component to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title of the dialog.
+ * @param optionType The option type.
+ * @param messageType The message type.
*
- * @return DOCUMENT ME!
+ * @return The selected value.
*/
public static int showInternalConfirmDialog(Component parentComponent,
Object message, String title,
int optionType, int messageType)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message, messageType, optionType);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal confirmation dialog with the given message,
+ * title, option type, message type, and icon. The internal frame dialog
+ * will be placed in the first JDesktopPane ancestor that is found in the
+ * given parentComponent. This method returns the selected value.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param optionType DOCUMENT ME!
- * @param messageType DOCUMENT ME!
- * @param icon DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param optionType The option type.
+ * @param messageType The message type.
+ * @param icon The icon to display.
*
- * @return DOCUMENT ME!
+ * @return The selected value.
*/
public static int showInternalConfirmDialog(Component parentComponent,
Object message, String title,
int optionType, int messageType,
Icon icon)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message, messageType, optionType, icon);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal input dialog with the given message. The
+ * internal frame dialog will be placed in the first JDesktopPane ancestor
+ * of the given parent component. This method returns the value input by
+ * the user.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
*
- * @return DOCUMENT ME!
+ * @return The user selected value.
*/
public static String showInternalInputDialog(Component parentComponent,
Object message)
{
- // FIXME: implement
- return null;
+ JOptionPane pane = new JOptionPane(message);
+ pane.setWantsInput(true);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, null);
+
+ startModal(frame, pane);
+
+ return (String) pane.getInputValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal input dialog with the given message, title
+ * and message type. The internal input dialog will be placed in the first
+ * JDesktopPane ancestor found in the given parent component. This method
+ * will return the input value given by the user.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param messageType DOCUMENT ME!
+ * @param parentComponent The component to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param messageType The message type.
*
- * @return DOCUMENT ME!
+ * @return The user input value.
*/
public static String showInternalInputDialog(Component parentComponent,
Object message, String title,
int messageType)
{
- // FIXME: implement
- return null;
+ JOptionPane pane = new JOptionPane(message, messageType);
+ pane.setWantsInput(true);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return (String) pane.getInputValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal input dialog with the given message, title
+ * message type, icon, selection value list and initial selection value.
+ * The internal frame dialog will be placed in the first JDesktopPane
+ * ancestor found in the given parent component. This method returns the
+ * input value from the user.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param messageType DOCUMENT ME!
- * @param icon DOCUMENT ME!
- * @param selectionValues DOCUMENT ME!
- * @param initialSelectionValue DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param messageType The message type.
+ * @param icon The icon to display.
+ * @param selectionValues The selection value list.
+ * @param initialSelectionValue The initial selection value.
*
- * @return DOCUMENT ME!
+ * @return The user input value.
*/
public static Object showInternalInputDialog(Component parentComponent,
Object message, String title,
@@ -1188,66 +1260,94 @@
Object[] selectionValues,
Object initialSelectionValue)
{
- // FIXME: implement
- return null;
+ JOptionPane pane = new JOptionPane(message, messageType);
+ pane.setWantsInput(true);
+ pane.setIcon(icon);
+ pane.setSelectionValues(selectionValues);
+ pane.setInitialSelectionValue(initialSelectionValue);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return (String) pane.getInputValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal message dialog with the given message. The
+ * internal frame dialog will be placed in the first JDesktopPane ancestor
+ * found in the given parent component.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
+ * @param parentComponent The component to find a JDesktopPane in.
+ * @param message The message to display.
*/
public static void showInternalMessageDialog(Component parentComponent,
Object message)
{
- // FIXME: implement
+ JOptionPane pane = new JOptionPane(message);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, null);
+
+ startModal(frame, pane);
}
/**
- * DOCUMENT ME!
+ * This method shows an internal message dialog with the given message,
+ * title and message type. The internal message dialog is placed in the
+ * first JDesktopPane ancestor found in the given parent component.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param messageType DOCUMENT ME!
+ * @param parentComponent The parent component to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param messageType The message type.
*/
public static void showInternalMessageDialog(Component parentComponent,
Object message, String title,
int messageType)
{
- // FIXME: implement
+ JOptionPane pane = new JOptionPane(message, messageType);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
}
/**
- * DOCUMENT ME!
+ * This method shows an internal message dialog with the given message,
+ * title, message type and icon. The internal message dialog is placed in
+ * the first JDesktopPane ancestor found in the given parent component.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param messageType DOCUMENT ME!
- * @param icon DOCUMENT ME!
+ * @param parentComponent The component to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param messageType The message type.
+ * @param icon The icon to display.
*/
public static void showInternalMessageDialog(Component parentComponent,
Object message, String title,
int messageType, Icon icon)
{
- // FIXME: implement
+ JOptionPane pane = new JOptionPane(message, messageType);
+ pane.setIcon(icon);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
}
/**
- * DOCUMENT ME!
+ * This method displays an internal option dialog with the given message,
+ * title, option type, message type, icon, option list, and initial option
+ * value. The internal option dialog is placed in the first JDesktopPane
+ * ancestor found in the parent component. This method returns the option
+ * selected.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param optionType DOCUMENT ME!
- * @param messageType DOCUMENT ME!
- * @param icon DOCUMENT ME!
- * @param options DOCUMENT ME!
- * @param initialValue DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message displayed.
+ * @param title The title displayed.
+ * @param optionType The option type.
+ * @param messageType The message type.
+ * @param icon The icon to display.
+ * @param options The array of options.
+ * @param initialValue The initial value selected.
*
- * @return DOCUMENT ME!
+ * @return The option that was selected.
*/
public static int showInternalOptionDialog(Component parentComponent,
Object message, String title,
@@ -1255,8 +1355,14 @@
Icon icon, Object[] options,
Object initialValue)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message, messageType, optionType, icon,
+ options, initialValue);
+
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
@@ -1338,6 +1444,7 @@
{
JOptionPane pane = new JOptionPane(message, messageType, optionType, icon,
options, initialValue);
+
JDialog dialog = pane.createDialog(parentComponent, title);
dialog.pack();
dialog.show();
@@ -1394,4 +1501,49 @@
}
return false;
}
+
+ /**
+ * This helper method makes the JInternalFrame wait until it is notified by
+ * an InternalFrameClosing event. This method also adds the given
+ * JOptionPane to the JInternalFrame and sizes it according to the
+ * JInternalFrame's preferred size.
+ *
+ * @param f The JInternalFrame to make modal.
+ * @param pane The JOptionPane to add to the JInternalFrame.
+ */
+ private static void startModal(JInternalFrame f, JOptionPane pane)
+ {
+ f.getContentPane().add(pane);
+ f.pack();
+ f.show();
+
+ Dimension pref = f.getPreferredSize();
+ f.setBounds(0, 0, pref.width, pref.height);
+
+ synchronized (f)
+ {
+ final JInternalFrame tmp = f;
+ tmp.toFront();
+
+ f.addInternalFrameListener(new InternalFrameAdapter()
+ {
+ public void internalFrameClosed(InternalFrameEvent e)
+ {
+ synchronized (tmp)
+ {
+ tmp.removeInternalFrameListener(this);
+ tmp.notifyAll();
+ }
+ }
+ });
+ try
+ {
+ while (! f.isClosed())
+ f.wait();
+ }
+ catch (InterruptedException ignored)
+ {
+ }
+ }
+ }
}
Index: javax/swing/plaf/basic/BasicInternalFrameUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 BasicInternalFrameUI.java
--- javax/swing/plaf/basic/BasicInternalFrameUI.java 9 Jun 2004 20:55:11 -0000 1.1.2.1
+++ javax/swing/plaf/basic/BasicInternalFrameUI.java 16 Jul 2004 02:24:01 -0000
@@ -37,6 +37,7 @@
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 @@
/** 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 @@
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 @@
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 Dimension minimumLayoutSize(Container c)
{
- return preferredLayoutSize(c);
+ return getSize(c, true);
}
/**
@@ -522,9 +541,24 @@
*/
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 @@
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 @@
*/
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 void mouseEntered(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -623,7 +669,7 @@
*/
public void mouseClicked(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -633,7 +679,7 @@
*/
public void mouseDragged(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -643,7 +689,7 @@
*/
public void mouseExited(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -653,7 +699,7 @@
*/
public void mouseMoved(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -664,7 +710,7 @@
public void mousePressed(MouseEvent e)
{
activateFrame(frame);
- dispatchFor(e);
+ handleEvent(e);
}
/**
@@ -674,27 +720,149 @@
*/
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()
- .getGlassPane(),
- e, candidate);
- candidate.dispatchEvent(newevt);
+ 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(),
+ (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;
+ }
+ }
+ }
}
}
@@ -941,7 +1109,7 @@
installDefaults();
installListeners();
- installComponents();
+ installComponents();
installKeyboardActions();
frame.setOpaque(true);
@@ -958,7 +1126,7 @@
public void uninstallUI(JComponent c)
{
uninstallKeyboardActions();
- uninstallComponents();
+ uninstallComponents();
uninstallListeners();
uninstallDefaults();
@@ -1108,7 +1276,7 @@
*/
public Dimension getMinimumSize(JComponent x)
{
- return getPreferredSize(x);
+ return internalFrameLayout.minimumLayoutSize(x);
}
/**
Index: javax/swing/plaf/basic/BasicOptionPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicOptionPaneUI.java,v
retrieving revision 1.6.8.2
diff -u -r1.6.8.2 BasicOptionPaneUI.java
--- javax/swing/plaf/basic/BasicOptionPaneUI.java 12 Jul 2004 19:52:46 -0000 1.6.8.2
+++ javax/swing/plaf/basic/BasicOptionPaneUI.java 16 Jul 2004 02:24:01 -0000
@@ -56,6 +56,7 @@
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.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;
@@ -131,6 +133,20 @@
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)
+ {
+ }
+ }
}
}
@@ -644,8 +660,8 @@
toAdd = new JButton(buttons[i].toString());
hasCustomComponents = true;
}
- if (toAdd instanceof JButton)
- ((JButton) toAdd).addActionListener(createButtonActionListener(i));
+ if (toAdd instanceof JButton)
+ ((JButton) toAdd).addActionListener(createButtonActionListener(i));
if (i == initialIndex)
initialFocusComponent = toAdd;
container.add(toAdd);
@@ -808,7 +824,7 @@
buttonPanel.setLayout(createLayoutManager());
addButtonComponents(buttonPanel, getButtons(), getInitialValueIndex());
-
+
return buttonPanel;
}
@@ -834,18 +850,17 @@
addIcon(messageArea);
JPanel rightSide = new JPanel()
- {
- public Dimension getPreferredSize()
- {
- 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,
- orig.height);
- return value;
- }
- };
+ {
+ public Dimension getPreferredSize()
+ {
+ 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,
+ orig.height);
+ return value;
+ }
+ };
rightSide.setLayout(new GridBagLayout());
GridBagConstraints con = createConstraints();
@@ -860,8 +875,8 @@
// inputComponent = new JTextField();
// else if (selection.length < 20)
// inputComponent = new JComboBox(selection);
- // FIXME: Uncomment when the widgets are done.
- if (selection == null)
+ // FIXME: Uncomment when the widgets are done.
+ if (selection == null)
inputComponent = null;
else
inputComponent = new JList(selection);
@@ -975,9 +990,9 @@
tmp = questionIcon;
break;
}
- return tmp;
- // FIXME: Don't cast till the default icons are in.
- // return new IconUIResource(tmp);
+ return tmp;
+ // FIXME: Don't cast till the default icons are in.
+ // return new IconUIResource(tmp);
}
/**
Index: javax/swing/plaf/basic/BasicToolBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicToolBarUI.java,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 BasicToolBarUI.java
--- javax/swing/plaf/basic/BasicToolBarUI.java 13 Jul 2004 15:20:58 -0000 1.1.2.7
+++ javax/swing/plaf/basic/BasicToolBarUI.java 16 Jul 2004 02:24:02 -0000
@@ -86,6 +86,9 @@
*/
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;
@@ -1095,7 +1098,7 @@
*/
private DragWindow()
{
- super(null);
+ super(owner);
}
/**