basiclookandfeel.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 1,300 行 · 第 1/5 页

JAVA
1,300
字号
/* BasicLookAndFeel.java --   Copyright (C) 2002, 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.AWTEvent;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Font;import java.awt.Toolkit;import java.awt.event.AWTEventListener;import java.awt.event.ActionEvent;import java.awt.event.MouseEvent;import java.io.IOException;import java.io.InputStream;import java.io.Serializable;import java.util.Enumeration;import java.util.ResourceBundle;import javax.sound.sampled.AudioInputStream;import javax.sound.sampled.AudioSystem;import javax.sound.sampled.Clip;import javax.sound.sampled.LineUnavailableException;import javax.sound.sampled.UnsupportedAudioFileException;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.ActionMap;import javax.swing.BorderFactory;import javax.swing.KeyStroke;import javax.swing.LookAndFeel;import javax.swing.MenuSelectionManager;import javax.swing.UIDefaults;import javax.swing.UIManager;import javax.swing.border.BevelBorder;import javax.swing.border.Border;import javax.swing.plaf.BorderUIResource;import javax.swing.plaf.ColorUIResource;import javax.swing.plaf.DimensionUIResource;import javax.swing.plaf.FontUIResource;import javax.swing.plaf.IconUIResource;import javax.swing.plaf.InsetsUIResource;/** * BasicLookAndFeel * @author Andrew Selkirk */public abstract class BasicLookAndFeel extends LookAndFeel  implements Serializable{  /**   * Helps closing menu popups when the user clicks outside of any menu area.   * This is implemented as an AWTEventListener that listens on the event   * queue directly, grabs all mouse events from there and finds out of they   * are targetted at a menu/submenu/menubar or not. If not,   * the MenuSelectionManager is messaged to close the currently opened menus,   * if any.   *    * @author Roman Kennke (kennke@aicas.com)   */  private class PopupHelper implements AWTEventListener  {    /**     * Receives an event from the event queue.     *     * @param event     */    public void eventDispatched(AWTEvent event)    {      if (event instanceof MouseEvent)        {          MouseEvent mouseEvent = (MouseEvent) event;          if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED)            mousePressed(mouseEvent);        }    }    /**     * Handles mouse pressed events from the event queue.     *     * @param ev the mouse pressed event     */    private void mousePressed(MouseEvent ev)    {      // Autoclose all menus managed by the MenuSelectionManager.      MenuSelectionManager m = MenuSelectionManager.defaultManager();      Component target = ev.getComponent();      if (target instanceof Container)        target = ((Container) target).findComponentAt(ev.getPoint());      if (! m.isComponentPartOfCurrentMenu(target))        m.clearSelectedPath();    }  }  /**   * An action that can play an audio file.   *   * @author Roman Kennke (kennke@aicas.com)   */  private class AudioAction extends AbstractAction  {    /**     * The UIDefaults key that specifies the sound.     */    Object key;    /**     * Creates a new AudioAction.     *     * @param key the key that describes the audio action, normally a filename     *        of an audio file relative to the current package     */    AudioAction(Object key)    {      this.key = key;    }    /**     * Plays the sound represented by this action.     *     * @param event the action event that triggers this audio action     */    public void actionPerformed(ActionEvent event)    {      // We only can handle strings for now.      if (key instanceof String)        {          String name = UIManager.getString(key);          InputStream stream = getClass().getResourceAsStream(name);          try            {              Clip clip = AudioSystem.getClip();              AudioInputStream audioStream =                AudioSystem.getAudioInputStream(stream);              clip.open(audioStream);            }          catch (LineUnavailableException ex)            {              // Nothing we can do about it.            }          catch (IOException ex)            {              // Nothing we can do about it.            }          catch (UnsupportedAudioFileException e)            {              // Nothing we can do about it.            }        }    }  }  static final long serialVersionUID = -6096995660290287879L;  /**   * Helps closing menu popups when user clicks outside of the menu area.   */  private transient PopupHelper popupHelper;  private ActionMap audioActionMap;  /**   * Creates a new instance of the Basic look and feel.   */  public BasicLookAndFeel()  {    // TODO  }  /**   * Creates and returns a new instance of the default resources for this look    * and feel.   *    * @return The UI defaults.   */  public UIDefaults getDefaults()  {    // Variables    UIDefaults def = new UIDefaults();    // Initialize Class Defaults    initClassDefaults(def);    // Initialize System Colour Defaults    initSystemColorDefaults(def);    // Initialize Component Defaults    initComponentDefaults(def);    // Return UI Defaults    return def;  }  /**   * Populates the <code>defaults</code> table with mappings between class IDs    * and fully qualified class names for the UI delegates.   *    * @param defaults  the defaults table (<code>null</code> not permitted).   */  protected void initClassDefaults(UIDefaults defaults)  {    // Variables    Object[] uiDefaults;    // Initialize Class Defaults    uiDefaults = new Object[] {      "ButtonUI", "javax.swing.plaf.basic.BasicButtonUI",      "CheckBoxMenuItemUI", "javax.swing.plaf.basic.BasicCheckBoxMenuItemUI",      "CheckBoxUI", "javax.swing.plaf.basic.BasicCheckBoxUI",      "ColorChooserUI", "javax.swing.plaf.basic.BasicColorChooserUI",      "ComboBoxUI", "javax.swing.plaf.basic.BasicComboBoxUI",      "DesktopIconUI", "javax.swing.plaf.basic.BasicDesktopIconUI",      "DesktopPaneUI", "javax.swing.plaf.basic.BasicDesktopPaneUI",      "EditorPaneUI", "javax.swing.plaf.basic.BasicEditorPaneUI",      "FileChooserUI", "javax.swing.plaf.basic.BasicFileChooserUI",      "FormattedTextFieldUI", "javax.swing.plaf.basic.BasicFormattedTextFieldUI",      "InternalFrameUI", "javax.swing.plaf.basic.BasicInternalFrameUI",      "LabelUI", "javax.swing.plaf.basic.BasicLabelUI",      "ListUI", "javax.swing.plaf.basic.BasicListUI",      "MenuBarUI", "javax.swing.plaf.basic.BasicMenuBarUI",      "MenuItemUI", "javax.swing.plaf.basic.BasicMenuItemUI",      "MenuUI", "javax.swing.plaf.basic.BasicMenuUI",      "OptionPaneUI", "javax.swing.plaf.basic.BasicOptionPaneUI",      "PanelUI", "javax.swing.plaf.basic.BasicPanelUI",      "PasswordFieldUI", "javax.swing.plaf.basic.BasicPasswordFieldUI",      "PopupMenuSeparatorUI", "javax.swing.plaf.basic.BasicPopupMenuSeparatorUI",

⌨️ 快捷键说明

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