⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicoptionpaneui.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			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 &quot;public&quot; due to a compiler bug.     * This class should be treated as a &quot;protected&quot; 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 &quot;public&quot; due to a compiler bug.     * This class should be treated as a &quot;protected&quot; 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;        private int minimumWidth = -1;        ButtonFactory(String text, int mnemonic, Icon icon, int minimumWidth) {            this.text = text;            this.mnemonic = mnemonic;            this.icon = icon;            this.minimumWidth = minimumWidth;        }        JButton createButton() {            JButton button = null;            if (minimumWidth > 0) {                button = new ConstrainedButton(text, minimumWidth);            } else {                button = new JButton(text);            }            if (icon != null) {                button.setIcon(icon);            }            if (mnemonic != 0) {                button.setMnemonic(mnemonic);            }            return button;        }                private static class ConstrainedButton extends JButton {            int minimumWidth;            ConstrainedButton(String text, int minimumWidth) {                super(text);                this.minimumWidth = minimumWidth;            }            public Dimension getMinimumSize() {                Dimension min = super.getMinimumSize();                min.width = Math.max(min.width, minimumWidth);                return min;            }            public Dimension getPreferredSize() {                Dimension pref = super.getPreferredSize();                pref.width = Math.max(pref.width, minimumWidth);                return pref;            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -