diff options
author | Roman Kennke <roman@kennke.org> | 2006-07-26 13:39:37 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-07-26 13:39:37 +0000 |
commit | e7036024993a09589db0e49f278447dc647ca216 (patch) | |
tree | 520572605df44b5d568052bf3dce85ede0ee4af4 | |
parent | 9911bb56bbd21467deec02df4bee9591531ad2d8 (diff) | |
download | classpath-e7036024993a09589db0e49f278447dc647ca216.tar.gz |
2006-07-26 Roman Kennke <kennke@aicas.com>
* javax/swing/JOptionPane.java
(createDialog): Add property change handler for closing
the dialog when the value property changes.
(ValuePropertyHandler): New inner helper class.
* javax/swing/plaf/basic/BasicOptionPaneUI.java
(OptionPaneCloseAction): New class.
(messageForeground): Removed field.
(messageBorder): Removed field.
(buttonBorder): Removed field.
(addIcon): Configure the new label.
(addMessageComponents): Configure newly created labels.
(burstStringInto): Likewise.
(createButtonArea): Install border here.
(createMessageArea): Install border and foreground here.
(createSeparator): Added comment and removed
NotImplementedException.
(installComponents): Don't install the UI defaults for the
message and button area here. This is moved to the
corresponding create* methods. Adjusted comment about
separator.
(installDefaults): Removed initialization of removed fields.
(installKeyboardActions): Implemented.
(getActionMap): New helper method.
(createDefaultActions): New helper method.
(uninstallDefaults): Removed de-initialization of removed fields.
(uninstallKeyboardActions): Implemented.
(configureLabel): New helper method.
* javax/swing/plaf/basic/BasicTableUI.java
(getActionMap): Fixed the UI property names.
* javax/swing/plaf/basic/BasicToolBarUI.java
(getActionMap): Fixed the UI property names.
-rw-r--r-- | ChangeLog | 34 | ||||
-rw-r--r-- | javax/swing/JOptionPane.java | 42 | ||||
-rw-r--r-- | javax/swing/plaf/basic/BasicOptionPaneUI.java | 164 | ||||
-rw-r--r-- | javax/swing/plaf/basic/BasicTableUI.java | 2 | ||||
-rw-r--r-- | javax/swing/plaf/basic/BasicToolBarUI.java | 4 |
5 files changed, 187 insertions, 59 deletions
@@ -1,3 +1,37 @@ +2006-07-26 Roman Kennke <kennke@aicas.com> + + * javax/swing/JOptionPane.java + (createDialog): Add property change handler for closing + the dialog when the value property changes. + (ValuePropertyHandler): New inner helper class. + * javax/swing/plaf/basic/BasicOptionPaneUI.java + (OptionPaneCloseAction): New class. + (messageForeground): Removed field. + (messageBorder): Removed field. + (buttonBorder): Removed field. + (addIcon): Configure the new label. + (addMessageComponents): Configure newly created labels. + (burstStringInto): Likewise. + (createButtonArea): Install border here. + (createMessageArea): Install border and foreground here. + (createSeparator): Added comment and removed + NotImplementedException. + (installComponents): Don't install the UI defaults for the + message and button area here. This is moved to the + corresponding create* methods. Adjusted comment about + separator. + (installDefaults): Removed initialization of removed fields. + (installKeyboardActions): Implemented. + (getActionMap): New helper method. + (createDefaultActions): New helper method. + (uninstallDefaults): Removed de-initialization of removed fields. + (uninstallKeyboardActions): Implemented. + (configureLabel): New helper method. + * javax/swing/plaf/basic/BasicTableUI.java + (getActionMap): Fixed the UI property names. + * javax/swing/plaf/basic/BasicToolBarUI.java + (getActionMap): Fixed the UI property names. + 2006-07-26 David Gilbert <david.gilbert@object-refinery.com> * java/awt/image/BandedSampleModel.java diff --git a/javax/swing/JOptionPane.java b/javax/swing/JOptionPane.java index f94905538..43caecd1a 100644 --- a/javax/swing/JOptionPane.java +++ b/javax/swing/JOptionPane.java @@ -48,6 +48,8 @@ import java.awt.MenuComponent; import java.awt.Toolkit; import java.awt.event.MouseAdapter; import java.awt.event.MouseMotionAdapter; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; @@ -378,11 +380,49 @@ public class JOptionPane extends JComponent implements Accessible dialog.setResizable(false); dialog.pack(); dialog.setLocationRelativeTo(parentComponent); - + + addPropertyChangeListener(new ValuePropertyHandler(dialog)); return dialog; } /** + * Handles changes of the value property. Whenever this property changes, + * the JOptionPane dialog should be closed. + */ + private static class ValuePropertyHandler + implements PropertyChangeListener + { + /** + * The dialog to close. + */ + JDialog dialog; + + /** + * Creates a new instance. + * + * @param d the dialog to be closed + */ + ValuePropertyHandler(JDialog d) + { + dialog = d; + } + + /** + * Receives notification when any of the properties change. + */ + public void propertyChange(PropertyChangeEvent p) + { + String prop = p.getPropertyName(); + Object val = p.getNewValue(); + if (prop.equals(VALUE_PROPERTY) && val != null + && val != UNINITIALIZED_VALUE) + { + dialog.setVisible(false); + } + } + } + + /** * This method creates a new JInternalFrame that is in the JLayeredPane * which contains the parentComponent given. If no suitable JLayeredPane * can be found from the parentComponent given, a RuntimeException will be diff --git a/javax/swing/plaf/basic/BasicOptionPaneUI.java b/javax/swing/plaf/basic/BasicOptionPaneUI.java index 27bcb8c46..b837c2f0e 100644 --- a/javax/swing/plaf/basic/BasicOptionPaneUI.java +++ b/javax/swing/plaf/basic/BasicOptionPaneUI.java @@ -38,13 +38,12 @@ exception statement from your version. */ package javax.swing.plaf.basic; -import gnu.classpath.NotImplementedException; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; +import java.awt.Font; import java.awt.Graphics; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -58,10 +57,14 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.Icon; +import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; @@ -76,6 +79,7 @@ import javax.swing.LookAndFeel; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.border.Border; +import javax.swing.plaf.ActionMapUIResource; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.OptionPaneUI; @@ -85,6 +89,21 @@ import javax.swing.plaf.OptionPaneUI; public class BasicOptionPaneUI extends OptionPaneUI { /** + * Implements the "close" keyboard action. + */ + static class OptionPaneCloseAction + extends AbstractAction + { + + public void actionPerformed(ActionEvent event) + { + JOptionPane op = (JOptionPane) event.getSource(); + op.setValue(new Integer(JOptionPane.CLOSED_OPTION)); + } + + } + + /** * This is a helper class that listens to the buttons located at the bottom * of the JOptionPane. * @@ -462,15 +481,6 @@ public class BasicOptionPaneUI extends OptionPaneUI /** The size of the icons. */ private static final int ICON_SIZE = 36; - /** The foreground color for the message area. */ - private transient Color messageForeground; - - /** The border around the message area. */ - private transient Border messageBorder; - - /** The border around the button area. */ - private transient Border buttonBorder; - /** The string used to describe OK buttons. */ private static final String OK_STRING = "OK"; @@ -700,6 +710,7 @@ public class BasicOptionPaneUI extends OptionPaneUI if (icon != null) { iconLabel = new JLabel(icon); + configureLabel(iconLabel); top.add(iconLabel, BorderLayout.WEST); } } @@ -761,7 +772,9 @@ public class BasicOptionPaneUI extends OptionPaneUI } else if (msg instanceof Icon) { - container.add(new JLabel((Icon) msg), cons); + JLabel label = new JLabel((Icon) msg); + configureLabel(label); + container.add(label, cons); cons.gridy++; } else @@ -778,8 +791,11 @@ public class BasicOptionPaneUI extends OptionPaneUI addMessageComponents(container, cons, tmp, maxll, true); } else - addMessageComponents(container, cons, new JLabel(msg.toString()), - maxll, true); + { + JLabel label = new JLabel(msg.toString()); + configureLabel(label); + addMessageComponents(container, cons, label, maxll, true); + } } } @@ -810,6 +826,7 @@ public class BasicOptionPaneUI extends OptionPaneUI remainder = d.substring(maxll); } JLabel label = new JLabel(line); + configureLabel(label); c.add(label); // If there is nothing left to burst, then we can stop. @@ -820,8 +837,12 @@ public class BasicOptionPaneUI extends OptionPaneUI if (remainder.length() > maxll || remainder.contains("\n")) burstStringInto(c, remainder, maxll); else - // Add the remainder to the container and be done. - c.add(new JLabel(remainder)); + { + // Add the remainder to the container and be done. + JLabel l = new JLabel(remainder); + configureLabel(l); + c.add(l); + } } /** @@ -857,6 +878,9 @@ public class BasicOptionPaneUI extends OptionPaneUI protected Container createButtonArea() { JPanel buttonPanel = new JPanel(); + Border b = UIManager.getBorder("OptionPane.buttonAreaBorder"); + if (b != null) + buttonPanel.setBorder(b); buttonPanel.setLayout(createLayoutManager()); addButtonComponents(buttonPanel, getButtons(), getInitialValueIndex()); @@ -882,6 +906,10 @@ public class BasicOptionPaneUI extends OptionPaneUI protected Container createMessageArea() { JPanel messageArea = new JPanel(); + Border messageBorder = UIManager.getBorder("OptionPane.messageAreaBorder"); + if (messageBorder != null) + messageArea.setBorder(messageBorder); + messageArea.setLayout(new BorderLayout()); addIcon(messageArea); @@ -935,10 +963,10 @@ public class BasicOptionPaneUI extends OptionPaneUI * @return A Container that will separate the message and button areas. */ protected Container createSeparator() - throws NotImplementedException { - // FIXME: Figure out what this method is supposed to return and where - // this should be added to the OptionPane. + // The reference implementation returns null here. When overriding + // to return something non-null, the component gets added between + // the message area and the button area. See installComponents(). return null; } @@ -1139,35 +1167,17 @@ public class BasicOptionPaneUI extends OptionPaneUI */ protected void installComponents() { - // reset it. - hasCustomComponents = false; - Container msg = createMessageArea(); - if (msg != null) - { - ((JComponent) msg).setBorder(messageBorder); - msg.setForeground(messageForeground); - messageAreaContainer = msg; - optionPane.add(msg); - } + // First thing is the message area. + optionPane.add(createMessageArea()); - // FIXME: Figure out if the separator should be inserted here or what - // this thing is supposed to do. Note: The JDK does NOT insert another - // component at this place. The JOptionPane only has two panels in it - // and there actually are applications that depend on this beeing so. + // Add separator when createSeparator() is overridden to return + // something other than null. Container sep = createSeparator(); if (sep != null) optionPane.add(sep); - Container button = createButtonArea(); - if (button != null) - { - ((JComponent) button).setBorder(buttonBorder); - buttonContainer = button; - optionPane.add(button); - } - - optionPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 11, 11)); - optionPane.invalidate(); + // Last thing is the button area. + optionPane.add(createButtonArea()); } /** @@ -1181,10 +1191,6 @@ public class BasicOptionPaneUI extends OptionPaneUI LookAndFeel.installBorder(optionPane, "OptionPane.border"); optionPane.setOpaque(true); - messageBorder = UIManager.getBorder("OptionPane.messageAreaBorder"); - messageForeground = UIManager.getColor("OptionPane.messageForeground"); - buttonBorder = UIManager.getBorder("OptionPane.buttonAreaBorder"); - minimumSize = UIManager.getDimension("OptionPane.minimumSize"); // FIXME: Image icons don't seem to work properly right now. @@ -1202,9 +1208,44 @@ public class BasicOptionPaneUI extends OptionPaneUI * This method installs keyboard actions for the JOptionpane. */ protected void installKeyboardActions() - throws NotImplementedException { - // FIXME: implement. + // Install the input map. + Object[] bindings = + (Object[]) SharedUIDefaults.get("OptionPane.windowBindings"); + InputMap inputMap = LookAndFeel.makeComponentInputMap(optionPane, + bindings); + SwingUtilities.replaceUIInputMap(optionPane, + JComponent.WHEN_IN_FOCUSED_WINDOW, + inputMap); + + // FIXME: The JDK uses a LazyActionMap for parentActionMap + SwingUtilities.replaceUIActionMap(optionPane, getActionMap()); + } + + /** + * Fetches the action map from the UI defaults, or create a new one + * if the action map hasn't been initialized. + * + * @return the action map + */ + private ActionMap getActionMap() + { + ActionMap am = (ActionMap) UIManager.get("OptionPane.actionMap"); + if (am == null) + { + am = createDefaultActions(); + UIManager.getLookAndFeelDefaults().put("OptionPane.actionMap", am); + } + return am; + } + + private ActionMap createDefaultActions() + { + ActionMapUIResource am = new ActionMapUIResource(); + Action action = new OptionPaneCloseAction(); + + am.put("close", action); + return am; } /** @@ -1317,10 +1358,6 @@ public class BasicOptionPaneUI extends OptionPaneUI minimumSize = null; - messageBorder = null; - buttonBorder = null; - messageForeground = null; - // FIXME: ImageIcons don't seem to work properly /* @@ -1335,9 +1372,10 @@ public class BasicOptionPaneUI extends OptionPaneUI * This method uninstalls keyboard actions for the JOptionPane. */ protected void uninstallKeyboardActions() - throws NotImplementedException { - // FIXME: implement. + SwingUtilities.replaceUIInputMap(optionPane, JComponent. + WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); + SwingUtilities.replaceUIActionMap(optionPane, null); } /** @@ -1363,4 +1401,20 @@ public class BasicOptionPaneUI extends OptionPaneUI optionPane = null; } + + /** + * Applies the proper UI configuration to labels that are added to + * the OptionPane. + * + * @param l the label to configure + */ + private void configureLabel(JLabel l) + { + Color c = UIManager.getColor("OptionPane.messageForeground"); + if (c != null) + l.setForeground(c); + Font f = UIManager.getFont("OptionPane.messageFont"); + if (f != null) + l.setFont(f); + } } diff --git a/javax/swing/plaf/basic/BasicTableUI.java b/javax/swing/plaf/basic/BasicTableUI.java index f3ca7205d..d26f5abdd 100644 --- a/javax/swing/plaf/basic/BasicTableUI.java +++ b/javax/swing/plaf/basic/BasicTableUI.java @@ -506,7 +506,7 @@ public class BasicTableUI extends TableUI if (am == null) { am = createDefaultActions(); - UIManager.getLookAndFeelDefaults().put("Tree.actionMap", am); + UIManager.getLookAndFeelDefaults().put("Table.actionMap", am); } return am; } diff --git a/javax/swing/plaf/basic/BasicToolBarUI.java b/javax/swing/plaf/basic/BasicToolBarUI.java index b4aa3bc2f..1c36b408d 100644 --- a/javax/swing/plaf/basic/BasicToolBarUI.java +++ b/javax/swing/plaf/basic/BasicToolBarUI.java @@ -672,11 +672,11 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants */ private ActionMap getActionMap() { - ActionMap am = (ActionMap) UIManager.get("Table.actionMap"); + ActionMap am = (ActionMap) UIManager.get("ToolBar.actionMap"); if (am == null) { am = createDefaultActions(); - UIManager.getLookAndFeelDefaults().put("Tree.actionMap", am); + UIManager.getLookAndFeelDefaults().put("ToolBar.actionMap", am); } return am; } |