?? basicoptionpaneui.java
字號:
int extraWidth = cInsets.left + cInsets.right; if (syncAllWidths) { int maxWidth = 0; for(int counter = 0; counter < numChildren; counter++){ aSize = children[counter].getPreferredSize(); height = Math.max(height, aSize.height); maxWidth = Math.max(maxWidth, aSize.width); } return new Dimension(extraWidth + (maxWidth * numChildren) + (numChildren - 1) * padding, extraHeight + height); } else { int totalWidth = 0; for(int counter = 0; counter < numChildren; counter++){ aSize = children[counter].getPreferredSize(); height = Math.max(height, aSize.height); totalWidth += aSize.width; } totalWidth += ((numChildren - 1) * padding); return new Dimension(extraWidth + totalWidth, extraHeight + height); } } } return new Dimension(0, 0); } public Dimension preferredLayoutSize(Container c) { return minimumLayoutSize(c); } public void removeLayoutComponent(Component c) { } } /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of BasicOptionPaneUI. */ public class PropertyChangeHandler implements PropertyChangeListener { /** * If the source of the PropertyChangeEvent <code>e</code> equals the * optionPane and is one of the ICON_PROPERTY, MESSAGE_PROPERTY, * OPTIONS_PROPERTY or INITIAL_VALUE_PROPERTY, * validateComponent is invoked. */ public void propertyChange(PropertyChangeEvent e) { getHandler().propertyChange(e); } } /** * Configures any necessary colors/fonts for the specified label * used representing the message. */ private void configureMessageLabel(JLabel label) { Color color = (Color)DefaultLookup.get(optionPane, this, "OptionPane.messageForeground"); if (color != null) { label.setForeground(color); } Font messageFont = (Font)DefaultLookup.get(optionPane, this, "OptionPane.messageFont"); if (messageFont != null) { label.setFont(messageFont); } } /** * Configures any necessary colors/fonts for the specified button * used representing the button portion of the optionpane. */ private void configureButton(JButton button) { Font buttonFont = (Font)DefaultLookup.get(optionPane, this, "OptionPane.buttonFont"); if (buttonFont != null) { button.setFont(buttonFont); } } /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of BasicOptionPaneUI. */ public class ButtonActionListener implements ActionListener { protected int buttonIndex; public ButtonActionListener(int buttonIndex) { this.buttonIndex = buttonIndex; } public void actionPerformed(ActionEvent e) { if (optionPane != null) { int optionType = optionPane.getOptionType(); Object[] options = optionPane.getOptions(); /* If the option pane takes input, then store the input value * if custom options were specified, if the option type is * DEFAULT_OPTION, OR if option type is set to a predefined * one and the user chose the affirmative answer. */ if (inputComponent != null) { if (options != null || optionType == JOptionPane.DEFAULT_OPTION || ((optionType == JOptionPane.YES_NO_OPTION || optionType == JOptionPane.YES_NO_CANCEL_OPTION || optionType == JOptionPane.OK_CANCEL_OPTION) && buttonIndex == 0)) { resetInputValue(); } } if (options == null) { if (optionType == JOptionPane.OK_CANCEL_OPTION && buttonIndex == 1) { optionPane.setValue(new Integer(2)); } else { optionPane.setValue(new Integer(buttonIndex)); } } else { optionPane.setValue(options[buttonIndex]); } } } } private class Handler implements ActionListener, MouseListener, PropertyChangeListener { // // ActionListener // public void actionPerformed(ActionEvent e) { optionPane.setInputValue(((JTextField)e.getSource()).getText()); } // // MouseListener // public void mouseClicked(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { JList list = (JList)e.getSource(); int index = list.locationToIndex(e.getPoint()); optionPane.setInputValue(list.getModel().getElementAt(index)); } } // // PropertyChangeListener // public void propertyChange(PropertyChangeEvent e) { if(e.getSource() == optionPane) { // Option Pane Auditory Cue Activation // only respond to "ancestor" changes // the idea being that a JOptionPane gets a JDialog when it is // set to appear and loses it's JDialog when it is dismissed. if ("ancestor" == e.getPropertyName()) { JOptionPane op = (JOptionPane)e.getSource(); boolean isComingUp; // if the old value is null, then the JOptionPane is being // created since it didn't previously have an ancestor. if (e.getOldValue() == null) { isComingUp = true; } else { isComingUp = false; } // figure out what to do based on the message type switch (op.getMessageType()) { case JOptionPane.PLAIN_MESSAGE: if (isComingUp) { BasicLookAndFeel.playSound(optionPane, "OptionPane.informationSound"); } break; case JOptionPane.QUESTION_MESSAGE: if (isComingUp) { BasicLookAndFeel.playSound(optionPane, "OptionPane.questionSound"); } break; case JOptionPane.INFORMATION_MESSAGE: if (isComingUp) { BasicLookAndFeel.playSound(optionPane, "OptionPane.informationSound"); } break; case JOptionPane.WARNING_MESSAGE: if (isComingUp) { BasicLookAndFeel.playSound(optionPane, "OptionPane.warningSound"); } break; case JOptionPane.ERROR_MESSAGE: if (isComingUp) { BasicLookAndFeel.playSound(optionPane, "OptionPane.errorSound"); } break; default: System.err.println("Undefined JOptionPane type: " + op.getMessageType()); break; } } // Visual activity String changeName = e.getPropertyName(); if(changeName == JOptionPane.OPTIONS_PROPERTY || changeName == JOptionPane.INITIAL_VALUE_PROPERTY || changeName == JOptionPane.ICON_PROPERTY || changeName == JOptionPane.MESSAGE_TYPE_PROPERTY || changeName == JOptionPane.OPTION_TYPE_PROPERTY || changeName == JOptionPane.MESSAGE_PROPERTY || changeName == JOptionPane.SELECTION_VALUES_PROPERTY || changeName == JOptionPane.INITIAL_SELECTION_VALUE_PROPERTY || changeName == JOptionPane.WANTS_INPUT_PROPERTY) { uninstallComponents(); installComponents(); optionPane.validate(); } else if (changeName == "componentOrientation") { ComponentOrientation o = (ComponentOrientation)e.getNewValue(); JOptionPane op = (JOptionPane)e.getSource(); if (o != (ComponentOrientation)e.getOldValue()) { op.applyComponentOrientation(o); } } } } } // // Classes used when optionPane.getWantsInput returns true. // /** * A JTextField that allows you to specify an array of KeyStrokes that * that will have their bindings processed regardless of whether or * not they are registered on the JTextField. This is used as we really * want the ActionListener to be notified so that we can push the * change to the JOptionPane, but we also want additional bindings * (those of the JRootPane) to be processed as well. */ private static class MultiplexingTextField extends JTextField { private KeyStroke[] strokes; MultiplexingTextField(int cols) { super(cols); } /** * Sets the KeyStrokes that will be additional processed for * ancestor bindings. */ void setKeyStrokes(KeyStroke[] strokes) { this.strokes = strokes; } protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { boolean processed = super.processKeyBinding(ks, e, condition, pressed); if (processed && condition != JComponent.WHEN_IN_FOCUSED_WINDOW) { for (int counter = strokes.length - 1; counter >= 0; counter--) { if (strokes[counter].equals(ks)) { // Returning false will allow further processing // of the bindings, eg our parent Containers will get a // crack at them. return false; } } } return processed; } } /** * Registered in the ActionMap. Sets the value of the option pane * to <code>JOptionPane.CLOSED_OPTION</code>. */ private static class Actions extends UIAction { private static final String CLOSE = "close"; Actions(String key) { super(key); } public void actionPerformed(ActionEvent e) { if (getName() == CLOSE) { JOptionPane optionPane = (JOptionPane)e.getSource(); optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION)); } } } /** * This class is used to create the default buttons. This indirection is * used so that addButtonComponents can tell which Buttons were created * by us vs subclassers or from the JOptionPane itself. */ private static class ButtonFactory { private String text; private int mnemonic; private Icon icon; ButtonFactory(String text, int mnemonic, Icon icon) { this.text = text; this.mnemonic = mnemonic; this.icon = icon; } JButton createButton() { JButton button = new JButton(text); if (icon != null) { button.setIcon(icon); } if (mnemonic != 0) { button.setMnemonic(mnemonic); } return button; } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -