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

📄 basiccomboboxui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* BasicComboBoxUI.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.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Insets;import java.awt.LayoutManager;import java.awt.Rectangle;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import javax.accessibility.Accessible;import javax.swing.CellRendererPane;import javax.swing.ComboBoxEditor;import javax.swing.ComboBoxModel;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JList;import javax.swing.ListCellRenderer;import javax.swing.LookAndFeel;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.event.ListDataEvent;import javax.swing.event.ListDataListener;import javax.swing.plaf.ComboBoxUI;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.UIResource;/** * A UI delegate for the {@link JComboBox} component. * * @author Olga Rodimina * @author Robert Schuster */public class BasicComboBoxUI extends ComboBoxUI{  /**   * The arrow button that is displayed in the right side of JComboBox. This   * button is used to hide and show combo box's list of items.   */  protected JButton arrowButton;  /**   * The combo box represented by this UI delegate.   */  protected JComboBox comboBox;  /**   * The component that is responsible for displaying/editing the selected    * item of the combo box.    *    * @see BasicComboBoxEditor#getEditorComponent()   */  protected Component editor;  /**   * A listener listening to focus events occurring in the {@link JComboBox}.   */  protected FocusListener focusListener;  /**   * A flag indicating whether JComboBox currently has the focus.   */  protected boolean hasFocus;  /**   * A listener listening to item events fired by the {@link JComboBox}.   */  protected ItemListener itemListener;  /**   * A listener listening to key events that occur while {@link JComboBox} has   * the focus.   */  protected KeyListener keyListener;  /**   * A listener listening to mouse events occuring in the {@link JComboBox}.   */  private MouseListener mouseListener;  /**   * List used when rendering selected item of the combo box. The selection   * and foreground colors for combo box renderer are configured from this   * list.   */  protected JList listBox;  /**   * ListDataListener listening to JComboBox model   */  protected ListDataListener listDataListener;  /**   * Popup list containing the combo box's menu items.   */  protected ComboPopup popup;    protected KeyListener popupKeyListener;    protected MouseListener popupMouseListener;    protected MouseMotionListener popupMouseMotionListener;  /**   * Listener listening to changes in the bound properties of JComboBox   */  protected PropertyChangeListener propertyChangeListener;  /**    * The button background.    * @see #installDefaults()   */  private Color buttonBackground;    /**    * The button shadow.    * @see #installDefaults()   */  private Color buttonShadow;    /**   * The button dark shadow.   * @see #installDefaults()   */  private Color buttonDarkShadow;  /**   * The button highlight.   * @see #installDefaults()   */  private Color buttonHighlight;  /* Size of the largest item in the comboBox   * This is package-private to avoid an accessor method.   */  Dimension displaySize;  // FIXME: This fields aren't used anywhere at this moment.  protected Dimension cachedMinimumSize;  protected CellRendererPane currentValuePane;  protected boolean isMinimumSizeDirty;  /**   * Creates a new <code>BasicComboBoxUI</code> object.   */  public BasicComboBoxUI()  {    // Nothing to do here.  }  /**   * A factory method to create a UI delegate for the given    * {@link JComponent}, which should be a {@link JComboBox}.   *   * @param c The {@link JComponent} a UI is being created for.   *   * @return A UI delegate for the {@link JComponent}.   */  public static ComponentUI createUI(JComponent c)  {    return new BasicComboBoxUI();  }  /**   * Installs the UI for the given {@link JComponent}.   *   * @param c  the JComponent to install a UI for.   *    * @see #uninstallUI(JComponent)   */  public void installUI(JComponent c)  {    super.installUI(c);    if (c instanceof JComboBox)      {        comboBox = (JComboBox) c;        comboBox.setOpaque(true);        comboBox.setLayout(createLayoutManager());        installDefaults();        installComponents();        installListeners();        installKeyboardActions();      }  }  /**   * Uninstalls the UI for the given {@link JComponent}.   *   * @param c The JComponent that is having this UI removed.   *    * @see #installUI(JComponent)   */  public void uninstallUI(JComponent c)  {    uninstallKeyboardActions();    uninstallListeners();    uninstallComponents();    uninstallDefaults();    comboBox = null;  }  /**   * Installs the defaults that are defined in the {@link BasicLookAndFeel}    * for this {@link JComboBox}.   *    * @see #uninstallDefaults()   */  protected void installDefaults()  {    LookAndFeel.installColorsAndFont(comboBox, "ComboBox.background",                                     "ComboBox.foreground", "ComboBox.font");        // fetch the button color scheme    buttonBackground = UIManager.getColor("ComboBox.buttonBackground");    buttonShadow = UIManager.getColor("ComboBox.buttonShadow");    buttonDarkShadow = UIManager.getColor("ComboBox.buttonDarkShadow");    buttonHighlight = UIManager.getColor("ComboBox.buttonHighlight");  }  /**   * Creates and installs the listeners for this UI.   *    * @see #uninstallListeners()   */  protected void installListeners()  {    // install combo box's listeners    propertyChangeListener = createPropertyChangeListener();    comboBox.addPropertyChangeListener(propertyChangeListener);    focusListener = createFocusListener();    comboBox.addFocusListener(focusListener);    listBox.addFocusListener(focusListener);    itemListener = createItemListener();    comboBox.addItemListener(itemListener);    keyListener = createKeyListener();    comboBox.addKeyListener(keyListener);    mouseListener = createMouseListener();    arrowButton.addMouseListener(mouseListener);    // install listeners that listen to combo box model    listDataListener = createListDataListener();    comboBox.getModel().addListDataListener(listDataListener);  }  /**   * Uninstalls the defaults and sets any objects created during   * install to <code>null</code>.   *    * @see #installDefaults()   */  protected void uninstallDefaults()  {    if (comboBox.getFont() instanceof UIResource)      comboBox.setFont(null);    if (comboBox.getForeground() instanceof UIResource)      comboBox.setForeground(null);        if (comboBox.getBackground() instanceof UIResource)      comboBox.setBackground(null);    buttonBackground = null;    buttonShadow = null;    buttonDarkShadow = null;    buttonHighlight = null;  }  /**   * Detaches all the listeners we attached in {@link #installListeners}.   *    * @see #installListeners()   */  protected void uninstallListeners()  {    comboBox.removePropertyChangeListener(propertyChangeListener);    propertyChangeListener = null;    comboBox.removeFocusListener(focusListener);    listBox.removeFocusListener(focusListener);    focusListener = null;    comboBox.removeItemListener(itemListener);    itemListener = null;    comboBox.removeKeyListener(keyListener);    keyListener = null;    arrowButton.removeMouseListener(mouseListener);    mouseListener = null;    comboBox.getModel().removeListDataListener(listDataListener);    listDataListener = null;  }  /**   * Creates the popup that will contain list of combo box's items.   *   * @return popup containing list of combo box's items   */  protected ComboPopup createPopup()  {    return new BasicComboPopup(comboBox);  }  /**   * Creates a {@link KeyListener} to listen to key events.   *   * @return KeyListener that listens to key events.   */  protected KeyListener createKeyListener()  {    return new KeyHandler();  }  /**   * Creates a {@link MouseListener} that will listen to mouse events occurring   * in the combo box.   *   * @return the MouseListener   */  private MouseListener createMouseListener()  {    return new MouseHandler();  }  /**   * Creates the {@link FocusListener} that will listen to changes in this   * JComboBox's focus.   *   * @return the FocusListener.   */  protected FocusListener createFocusListener()  {    return new FocusHandler();  }  /**   * Creates a {@link ListDataListener} to listen to the combo box's data model.   *   * @return The new listener.   */  protected ListDataListener createListDataListener()  {    return new ListDataHandler();  }  /**   * Creates an {@link ItemListener} that will listen to the changes in   * the JComboBox's selection.   *   * @return The ItemListener   */  protected ItemListener createItemListener()  {    return new ItemHandler();  }  /**   * Creates a {@link PropertyChangeListener} to listen to the changes in   * the JComboBox's bound properties.   *   * @return The PropertyChangeListener   */  protected PropertyChangeListener createPropertyChangeListener()  {    return new PropertyChangeHandler();

⌨️ 快捷键说明

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