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

📄 basicoptionpaneui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* BasicOptionPaneUI.java --   Copyright (C) 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.plaf.basic;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Graphics;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.LayoutManager;import java.awt.Polygon;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyVetoException;import javax.swing.BorderFactory;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.Icon;import javax.swing.JButton;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;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.LookAndFeel;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.border.Border;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.OptionPaneUI;/** * This class is the UI delegate for JOptionPane in the Basic Look and Feel. */public class BasicOptionPaneUI extends OptionPaneUI{  /**   * This is a helper class that listens to the buttons located at the bottom   * of the JOptionPane.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class ButtonActionListener implements ActionListener  {    /** The index of the option this button represents. */    protected int buttonIndex;    /**     * Creates a new ButtonActionListener object with the given buttonIndex.     *     * @param buttonIndex The index of the option this button represents.     */    public ButtonActionListener(int buttonIndex)    {      this.buttonIndex = buttonIndex;    }    /**     * This method is called when one of the option buttons are pressed.     *     * @param e The ActionEvent.     */    public void actionPerformed(ActionEvent e)    {      Object value = new Integer(JOptionPane.CLOSED_OPTION);      Object[] options = optionPane.getOptions();      if (options != null)	value = new Integer(buttonIndex);      else        {	  String text = ((JButton) e.getSource()).getText();	  if (text.equals(OK_STRING))	    value = new Integer(JOptionPane.OK_OPTION);	  if (text.equals(CANCEL_STRING))	    value = new Integer(JOptionPane.CANCEL_OPTION);	  if (text.equals(YES_STRING))	    value = new Integer(JOptionPane.YES_OPTION);	  if (text.equals(NO_STRING))	    value = new Integer(JOptionPane.NO_OPTION);        }      optionPane.setValue(value);      resetInputValue();      Window owner = SwingUtilities.windowForComponent(optionPane);      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)            {              // We do nothing if attempt has been vetoed.            }        }    }  }  /**   * This helper layout manager is responsible for the layout of the button   * area. The button area is the panel that holds the buttons which   * represent the options.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public static class ButtonAreaLayout implements LayoutManager  {    /** Whether this layout will center the buttons. */    protected boolean centersChildren = true;    /** The space between the buttons. */    protected int padding;    /** Whether the buttons will share the same widths. */    protected boolean syncAllWidths;    /** The width of the widest button. */    private transient int widthOfWidestButton;    /** The height of the tallest button. */    private transient int tallestButton;    /**     * Creates a new ButtonAreaLayout object with the given sync widths     * property and padding.     *     * @param syncAllWidths Whether the buttons will share the same widths.     * @param padding The padding between the buttons.     */    public ButtonAreaLayout(boolean syncAllWidths, int padding)    {      this.syncAllWidths = syncAllWidths;      this.padding = padding;    }    /**     * This method is called when a component is added to the container.     *     * @param string The constraints string.     * @param comp The component added.     */    public void addLayoutComponent(String string, Component comp)    {      // Do nothing.    }    /**     * This method returns whether the children will be centered.     *     * @return Whether the children will be centered.     */    public boolean getCentersChildren()    {      return centersChildren;    }    /**     * This method returns the amount of space between components.     *     * @return The amount of space between components.     */    public int getPadding()    {      return padding;    }    /**     * This method returns whether all components will share widths (set to     * largest width).     *     * @return Whether all components will share widths.     */    public boolean getSyncAllWidths()    {      return syncAllWidths;    }    /**     * This method lays out the given container.     *     * @param container The container to lay out.     */    public void layoutContainer(Container container)    {      Component[] buttonList = container.getComponents();      int x = container.getInsets().left;      if (getCentersChildren())	x += (int) ((double) (container.getSize().width) / 2	- (double) (buttonRowLength(container)) / 2);      for (int i = 0; i < buttonList.length; i++)        {	  Dimension dims = buttonList[i].getPreferredSize();	  if (syncAllWidths)	    {	      buttonList[i].setBounds(x, 0, widthOfWidestButton, dims.height);	      x += widthOfWidestButton + getPadding();	    }	  else	    {	      buttonList[i].setBounds(x, 0, dims.width, dims.height);	      x += dims.width + getPadding();	    }        }    }    /**     * This method returns the width of the given container taking into     * consideration the padding and syncAllWidths.     *     * @param c The container to calculate width for.     *     * @return The width of the given container.     */    private int buttonRowLength(Container c)    {      Component[] buttonList = c.getComponents();      int buttonLength = 0;      int widest = 0;      int tallest = 0;      for (int i = 0; i < buttonList.length; i++)        {	  Dimension dims = buttonList[i].getPreferredSize();	  buttonLength += dims.width + getPadding();	  widest = Math.max(widest, dims.width);	  tallest = Math.max(tallest, dims.height);        }      widthOfWidestButton = widest;      tallestButton = tallest;      int width;      if (getSyncAllWidths())	width = widest * buttonList.length	        + getPadding() * (buttonList.length - 1);      else	width = buttonLength;      Insets insets = c.getInsets();      width += insets.left + insets.right;      return width;    }    /**     * This method returns the minimum layout size for the given container.     *     * @param c The container to measure.     *     * @return The minimum layout size.     */    public Dimension minimumLayoutSize(Container c)    {      return preferredLayoutSize(c);    }    /**     * This method returns the preferred size of the given container.     *     * @param c The container to measure.     *     * @return The preferred size.     */    public Dimension preferredLayoutSize(Container c)    {      int w = buttonRowLength(c);      return new Dimension(w, tallestButton);    }    /**     * This method removes the given component from the layout manager's     * knowledge.     *     * @param c The component to remove.     */    public void removeLayoutComponent(Component c)    {      // Do nothing.    }    /**     * This method sets whether the children will be centered.     *     * @param newValue Whether the children will be centered.     */    public void setCentersChildren(boolean newValue)    {      centersChildren = newValue;    }    /**     * This method sets the amount of space between each component.     *     * @param newPadding The padding between components.     */    public void setPadding(int newPadding)    {      padding = newPadding;    }    /**     * This method sets whether the widths will be synced.     *     * @param newValue Whether the widths will be synced.     */    public void setSyncAllWidths(boolean newValue)    {      syncAllWidths = newValue;    }  }  /**   * This helper class handles property change events from the JOptionPane.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class PropertyChangeHandler implements PropertyChangeListener  {    /**     * This method is called when one of the properties of the JOptionPane     * changes.     *     * @param e The PropertyChangeEvent.     */    public void propertyChange(PropertyChangeEvent e)    {      if (e.getPropertyName().equals(JOptionPane.ICON_PROPERTY)          || e.getPropertyName().equals(JOptionPane.MESSAGE_TYPE_PROPERTY))	addIcon(messageAreaContainer);      else if (e.getPropertyName().equals(JOptionPane.INITIAL_SELECTION_VALUE_PROPERTY))	resetSelectedValue();      else if (e.getPropertyName().equals(JOptionPane.INITIAL_VALUE_PROPERTY)               || e.getPropertyName().equals(JOptionPane.OPTIONS_PROPERTY)               || e.getPropertyName().equals(JOptionPane.OPTION_TYPE_PROPERTY))        {	  Container newButtons = createButtonArea();	  optionPane.remove(buttonContainer);	  optionPane.add(newButtons);	  buttonContainer = newButtons;        }      else if (e.getPropertyName().equals(JOptionPane.MESSAGE_PROPERTY)               || e.getPropertyName().equals(JOptionPane.WANTS_INPUT_PROPERTY)               || e.getPropertyName().equals(JOptionPane.SELECTION_VALUES_PROPERTY))        {          optionPane.remove(messageAreaContainer);          messageAreaContainer = createMessageArea();          optionPane.add(messageAreaContainer);          Container newButtons = createButtonArea();          optionPane.remove(buttonContainer);          optionPane.add(newButtons);          buttonContainer = newButtons;          optionPane.add(buttonContainer);        }      optionPane.invalidate();      optionPane.repaint();    }  }  /**   * The minimum width for JOptionPanes.   */  public static final int MinimumWidth = 262;  /**   * The minimum height for JOptionPanes.   */  public static final int MinimumHeight = 90;  /** Whether the JOptionPane contains custom components. */  protected boolean hasCustomComponents = false;  // The initialFocusComponent seems to always be set to a button (even if   // I try to set initialSelectionValue). This is different from what the   // javadocs state (which should switch this reference to the input component   // if one is present since that is what's going to get focus).   /**   * The button that will receive focus based on initialValue when no input   * component is present. If an input component is present, then the input   * component will receive focus instead.   */  protected Component initialFocusComponent;  /** The component that receives input when the JOptionPane needs it. */  protected JComponent inputComponent;

⌨️ 快捷键说明

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