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

📄 basicoptionpaneui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    return messageArea;  }  /**   * This method creates a new PropertyChangeListener for listening to the   * JOptionPane.   *   * @return A new PropertyChangeListener.   */  protected PropertyChangeListener createPropertyChangeListener()  {    return new PropertyChangeHandler();  }  /**   * This method creates a Container that will separate the message and button   * areas.   *   * @return A Container that will separate the message and button areas.   */  protected Container createSeparator()  {    // FIXME: Figure out what this method is supposed to return and where    // this should be added to the OptionPane.    return null;  }  /**   * This method creates a new BasicOptionPaneUI for the given component.   *   * @param x The component to create a UI for.   *   * @return A new BasicOptionPaneUI.   */  public static ComponentUI createUI(JComponent x)  {    return new BasicOptionPaneUI();  }  /**   * This method returns the buttons for the JOptionPane. If no options are   * set, a set of options will be created based upon the optionType.   *   * @return The buttons that will be added.   */  protected Object[] getButtons()  {    if (optionPane.getOptions() != null)      return optionPane.getOptions();    switch (optionPane.getOptionType())      {      case JOptionPane.YES_NO_OPTION:	return new Object[] { YES_STRING, NO_STRING };      case JOptionPane.YES_NO_CANCEL_OPTION:	return new Object[] { YES_STRING, NO_STRING, CANCEL_STRING };      case JOptionPane.OK_CANCEL_OPTION:	return new Object[] { OK_STRING, CANCEL_STRING };      case JOptionPane.DEFAULT_OPTION:        return (optionPane.getWantsInput() ) ?               new Object[] { OK_STRING, CANCEL_STRING } :               ( optionPane.getMessageType() == JOptionPane.QUESTION_MESSAGE ) ?               new Object[] { YES_STRING, NO_STRING, CANCEL_STRING } :               // ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, PLAIN_MESSAGE               new Object[] { OK_STRING };      }    return null;  }  /**   * This method will return the icon the user has set or the icon that will   * be used based on message type.   *   * @return The icon to use in the JOptionPane.   */  protected Icon getIcon()  {    if (optionPane.getIcon() != null)      return optionPane.getIcon();    else      return getIconForType(optionPane.getMessageType());  }  /**   * This method returns the icon for the given messageType.   *   * @param messageType The type of message.   *   * @return The icon for the given messageType.   */  protected Icon getIconForType(int messageType)  {    Icon tmp = null;    switch (messageType)      {      case JOptionPane.ERROR_MESSAGE:	tmp = errorIcon;	break;      case JOptionPane.INFORMATION_MESSAGE:	tmp = infoIcon;	break;      case JOptionPane.WARNING_MESSAGE:	tmp = warningIcon;	break;      case JOptionPane.QUESTION_MESSAGE:	tmp = questionIcon;	break;      }    return tmp;    // FIXME: Don't cast till the default icons are in.    // return new IconUIResource(tmp);  }  /**   * This method returns the index of the initialValue in the options array.   *   * @return The index of the initalValue.   */  protected int getInitialValueIndex()  {    Object[] buttons = getButtons();    if (buttons == null)      return -1;    Object select = optionPane.getInitialValue();    for (int i = 0; i < buttons.length; i++)      {	if (select == buttons[i])	  return i;      }    return 0;  }  /**   * This method returns the maximum number of characters that should be   * placed on a line.   *   * @return The maximum number of characteres that should be placed on a   *         line.   */  protected int getMaxCharactersPerLineCount()  {    return optionPane.getMaxCharactersPerLineCount();  }  /**   * This method returns the maximum size.   *   * @param c The JComponent to measure.   *   * @return The maximum size.   */  public Dimension getMaximumSize(JComponent c)  {    return getPreferredSize(c);  }  /**   * This method returns the message of the JOptionPane.   *   * @return The message.   */  protected Object getMessage()  {    return optionPane.getMessage();  }  /**   * This method returns the minimum size of the JOptionPane.   *   * @return The minimum size.   */  public Dimension getMinimumOptionPaneSize()  {    return minimumSize;  }  /**   * This method returns the minimum size.   *   * @param c The JComponent to measure.   *   * @return The minimum size.   */  public Dimension getMinimumSize(JComponent c)  {    return getPreferredSize(c);  }  /**   * This method returns the preferred size of the JOptionPane. The preferred   * size is the maximum of the size desired by the layout and the minimum   * size.   *   * @param c The JComponent to measure.   *   * @return The preferred size.   */  public Dimension getPreferredSize(JComponent c)  {    Dimension d = optionPane.getLayout().preferredLayoutSize(optionPane);    Dimension d2 = getMinimumOptionPaneSize();    int w = Math.max(d.width, d2.width);    int h = Math.max(d.height, d2.height);    return new Dimension(w, h);  }  /**   * This method returns whether all buttons should have the same width.   *   * @return Whether all buttons should have the same width.   */  protected boolean getSizeButtonsToSameWidth()  {    return true;  }  /**   * This method installs components for the JOptionPane.   */  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);      }    // 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.    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();  }  /**   * This method installs defaults for the JOptionPane.   */  protected void installDefaults()  {    LookAndFeel.installColorsAndFont(optionPane, "OptionPane.background",                                     "OptionPane.foreground",                                     "OptionPane.font");    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.    // Once they do, replace the synthetic icons with these ones.    /*    warningIcon = (IconUIResource) defaults.getIcon("OptionPane.warningIcon");    infoIcon = (IconUIResource) defaults.getIcon("OptionPane.informationIcon");    errorIcon = (IconUIResource) defaults.getIcon("OptionPane.errorIcon");    questionIcon = (IconUIResource) defaults.getIcon("OptionPane.questionIcon");    */  }  /**   * This method installs keyboard actions for the JOptionpane.   */  protected void installKeyboardActions()  {    // FIXME: implement.  }  /**   * This method installs listeners for the JOptionPane.   */  protected void installListeners()  {    propertyChangeListener = createPropertyChangeListener();    optionPane.addPropertyChangeListener(propertyChangeListener);  }  /**   * This method installs the UI for the JOptionPane.   *   * @param c The JComponent to install the UI for.   */  public void installUI(JComponent c)  {    if (c instanceof JOptionPane)      {	optionPane = (JOptionPane) c;	installDefaults();	installComponents();	installListeners();	installKeyboardActions();      }  }  /**   * Changes the inputValue property in the JOptionPane based on the current   * value of the inputComponent.   */  protected void resetInputValue()  {    if (optionPane.getWantsInput() && inputComponent != null)      {	Object output = null;	if (inputComponent instanceof JTextField)	  output = ((JTextField) inputComponent).getText();	else if (inputComponent instanceof JComboBox)	  output = ((JComboBox) inputComponent).getSelectedItem();	else if (inputComponent instanceof JList)	  output = ((JList) inputComponent).getSelectedValue();	if (output != null)	  optionPane.setInputValue(output);      }  }  /**   * This method requests focus to the inputComponent (if one is present) and   * the initialFocusComponent otherwise.   *   * @param op The JOptionPane.   */  public void selectInitialValue(JOptionPane op)  {    if (inputComponent != null)      {	inputComponent.requestFocus();	return;      }    if (initialFocusComponent != null)      initialFocusComponent.requestFocus();  }  /**   * This method resets the value in the inputComponent to the   * initialSelectionValue property.   * This is package-private to avoid an accessor method.   */  void resetSelectedValue()  {    if (inputComponent != null)      {	Object init = optionPane.getInitialSelectionValue();	if (init == null)	  return;	if (inputComponent instanceof JTextField)	  ((JTextField) inputComponent).setText((String) init);	else if (inputComponent instanceof JComboBox)	  ((JComboBox) inputComponent).setSelectedItem(init);	else if (inputComponent instanceof JList)	  {	    //  ((JList) inputComponent).setSelectedValue(init, true);	  }      }  }  /**   * This method uninstalls all the components in the JOptionPane.   */  protected void uninstallComponents()  {    optionPane.removeAll();    buttonContainer = null;    messageAreaContainer = null;  }  /**   * This method uninstalls the defaults for the JOptionPane.   */  protected void uninstallDefaults()  {    optionPane.setFont(null);    optionPane.setForeground(null);    optionPane.setBackground(null);    minimumSize = null;    messageBorder = null;    buttonBorder = null;    messageForeground = null;    // FIXME: ImageIcons don't seem to work properly    /*    warningIcon = null;    errorIcon = null;    questionIcon = null;    infoIcon = null;    */  }  /**   * This method uninstalls keyboard actions for the JOptionPane.   */  protected void uninstallKeyboardActions()  {    // FIXME: implement.  }  /**   * This method uninstalls listeners for the JOptionPane.   */  protected void uninstallListeners()  {    optionPane.removePropertyChangeListener(propertyChangeListener);    propertyChangeListener = null;  }  /**   * This method uninstalls the UI for the given JComponent.   *   * @param c The JComponent to uninstall for.   */  public void uninstallUI(JComponent c)  {    uninstallKeyboardActions();    uninstallListeners();    uninstallComponents();    uninstallDefaults();    optionPane = null;  }}

⌨️ 快捷键说明

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