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

📄 basicdesktoppaneui.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)BasicDesktopPaneUI.java	1.61 06/04/07 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.basic;import javax.swing.*;import javax.swing.plaf.*;import java.beans.*;import java.awt.event.*;import java.awt.Dimension;import java.awt.Insets;import java.awt.Graphics;import java.awt.KeyboardFocusManager;import java.awt.*;import java.util.Vector;import sun.swing.DefaultLookup;import sun.swing.UIAction;import sun.awt.AppContext;/** * Basic L&F for a desktop. * * @version 1.61 04/07/06 * @author Steve Wilson */public class BasicDesktopPaneUI extends DesktopPaneUI {    // Old actions forward to an instance of this.    private static final Actions SHARED_ACTION = new Actions();    private static Dimension minSize = new Dimension(0,0);    private static Dimension maxSize = new Dimension(Integer.MAX_VALUE,            Integer.MAX_VALUE);    private Handler handler;    private PropertyChangeListener pcl;    protected JDesktopPane desktop;    protected DesktopManager desktopManager;    /**     * As of Java 2 platform v1.3 this previously undocumented field is no     * longer used.     * Key bindings are now defined by the LookAndFeel, please refer to     * the key bindings specification for further details.     *     * @deprecated As of 1.3.     */    @Deprecated    protected KeyStroke minimizeKey;    /**     * As of Java 2 platform v1.3 this previously undocumented field is no     * longer used.     * Key bindings are now defined by the LookAndFeel, please refer to     * the key bindings specification for further details.     *     * @deprecated As of 1.3.     */    @Deprecated    protected KeyStroke maximizeKey;    /**     * As of Java 2 platform v1.3 this previously undocumented field is no     * longer used.     * Key bindings are now defined by the LookAndFeel, please refer to     * the key bindings specification for further details.     *     * @deprecated As of 1.3.     */    @Deprecated    protected KeyStroke closeKey;    /**     * As of Java 2 platform v1.3 this previously undocumented field is no     * longer used.     * Key bindings are now defined by the LookAndFeel, please refer to     * the key bindings specification for further details.     *     * @deprecated As of 1.3.     */    @Deprecated    protected KeyStroke navigateKey;    /**     * As of Java 2 platform v1.3 this previously undocumented field is no     * longer used.     * Key bindings are now defined by the LookAndFeel, please refer to     * the key bindings specification for further details.     *     * @deprecated As of 1.3.     */    @Deprecated    protected KeyStroke navigateKey2;    public static ComponentUI createUI(JComponent c) {        return new BasicDesktopPaneUI();    }    public BasicDesktopPaneUI() {    }    public void installUI(JComponent c)   {	desktop = (JDesktopPane)c;	installDefaults();	installDesktopManager();        installListeners();	installKeyboardActions();    }    public void uninstallUI(JComponent c) {	uninstallKeyboardActions();        uninstallListeners();	uninstallDesktopManager();        uninstallDefaults();	desktop = null;        handler = null;    }    protected void installDefaults() {	if (desktop.getBackground() == null || 	    desktop.getBackground() instanceof UIResource) {	    desktop.setBackground(UIManager.getColor("Desktop.background"));	}        LookAndFeel.installProperty(desktop, "opaque", Boolean.TRUE);    }    protected void uninstallDefaults() { }    /**     * Installs the <code>PropertyChangeListener</code> returned from     * <code>createPropertyChangeListener</code> on the     * <code>JDesktopPane</code>.     *     * @since 1.5     * @see #createPropertyChangeListener     */    protected void installListeners() {        pcl = createPropertyChangeListener();        desktop.addPropertyChangeListener(pcl);    }    /**     * Uninstalls the <code>PropertyChangeListener</code> returned from      * <code>createPropertyChangeListener</code> from the     * <code>JDesktopPane</code>.     *     * @since 1.5     * @see #createPropertyChangeListener     */    protected void uninstallListeners() {        desktop.removePropertyChangeListener(pcl);        pcl = null;    }    protected void installDesktopManager() {        desktopManager = desktop.getDesktopManager();	if(desktopManager == null) {	    desktopManager = new BasicDesktopManager();	    desktop.setDesktopManager(desktopManager);	}    }    protected void uninstallDesktopManager() {	if(desktop.getDesktopManager() instanceof UIResource) {	    desktop.setDesktopManager(null);	}	desktopManager = null;    }    protected void installKeyboardActions(){	InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);	if (inputMap != null) {	    SwingUtilities.replaceUIInputMap(desktop,			JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);	}	inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);	if (inputMap != null) {	    SwingUtilities.replaceUIInputMap(desktop,			JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,			inputMap);	}        LazyActionMap.installLazyActionMap(desktop, BasicDesktopPaneUI.class,                "DesktopPane.actionMap");	registerKeyboardActions();    }    protected void registerKeyboardActions(){    }     protected void unregisterKeyboardActions(){    }    InputMap getInputMap(int condition) {	if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {	    return createInputMap(condition);	}	else if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {	    return (InputMap)DefaultLookup.get(desktop, this,                    "Desktop.ancestorInputMap");	}	return null;    }    InputMap createInputMap(int condition) {	if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {	    Object[] bindings = (Object[])DefaultLookup.get(desktop,                    this, "Desktop.windowBindings");	    if (bindings != null) {		return LookAndFeel.makeComponentInputMap(desktop, bindings);	    }	}	return null;    }    static void loadActionMap(LazyActionMap map) {        map.put(new Actions(Actions.RESTORE));        map.put(new Actions(Actions.CLOSE));        map.put(new Actions(Actions.MOVE));        map.put(new Actions(Actions.RESIZE));        map.put(new Actions(Actions.LEFT));        map.put(new Actions(Actions.SHRINK_LEFT));        map.put(new Actions(Actions.RIGHT));        map.put(new Actions(Actions.SHRINK_RIGHT));        map.put(new Actions(Actions.UP));        map.put(new Actions(Actions.SHRINK_UP));        map.put(new Actions(Actions.DOWN));        map.put(new Actions(Actions.SHRINK_DOWN));        map.put(new Actions(Actions.ESCAPE));        map.put(new Actions(Actions.MINIMIZE));        map.put(new Actions(Actions.MAXIMIZE));        map.put(new Actions(Actions.NEXT_FRAME));        map.put(new Actions(Actions.PREVIOUS_FRAME));        map.put(new Actions(Actions.NAVIGATE_NEXT));        map.put(new Actions(Actions.NAVIGATE_PREVIOUS));    }    protected void uninstallKeyboardActions(){       unregisterKeyboardActions();      SwingUtilities.replaceUIInputMap(desktop, JComponent.				     WHEN_IN_FOCUSED_WINDOW, null);      SwingUtilities.replaceUIInputMap(desktop, JComponent.				     WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);      SwingUtilities.replaceUIActionMap(desktop, null);    }    public void paint(Graphics g, JComponent c) {}    public Dimension getPreferredSize(JComponent c) {return null;}    public Dimension getMinimumSize(JComponent c) {	return minSize;	}    public Dimension getMaximumSize(JComponent c){	return maxSize;    }    /**     * Returns the <code>PropertyChangeListener</code> to install on     * the <code>JDesktopPane</code>.     *     * @since 1.5     * @return The PropertyChangeListener that will be added to track     * changes in the desktop pane.     */    protected PropertyChangeListener createPropertyChangeListener() {        return getHandler();    }    private Handler getHandler() {        if (handler == null) {            handler = new Handler();        }        return handler;    }    private class Handler implements PropertyChangeListener {        public void propertyChange(PropertyChangeEvent evt) {            String propertyName = evt.getPropertyName();            if ("desktopManager" == propertyName) {                installDesktopManager();            }        }    }    /**     * The default DesktopManager installed by the UI.     */    private class BasicDesktopManager extends DefaultDesktopManager            implements UIResource {    }    private static class Actions extends UIAction {        private static String CLOSE = "close";        private static String ESCAPE = "escape";        private static String MAXIMIZE = "maximize";        private static String MINIMIZE = "minimize";        private static String MOVE = "move";        private static String RESIZE = "resize";        private static String RESTORE = "restore";        private static String LEFT = "left";        private static String RIGHT = "right";        private static String UP = "up";        private static String DOWN = "down";        private static String SHRINK_LEFT = "shrinkLeft";        private static String SHRINK_RIGHT = "shrinkRight";        private static String SHRINK_UP = "shrinkUp";        private static String SHRINK_DOWN = "shrinkDown";        private static String NEXT_FRAME = "selectNextFrame";        private static String PREVIOUS_FRAME = "selectPreviousFrame";        private static String NAVIGATE_NEXT = "navigateNext";        private static String NAVIGATE_PREVIOUS = "navigatePrevious";        private final int MOVE_RESIZE_INCREMENT = 10;        private static boolean moving = false;        private static boolean resizing = false;        private static JInternalFrame sourceFrame = null;        private static Component focusOwner = null;        Actions() {            super(null);        }        Actions(String name) {            super(name);        }        public void actionPerformed(ActionEvent e) {            JDesktopPane dp = (JDesktopPane)e.getSource();            String key = getName();            if (CLOSE == key || MAXIMIZE == key || MINIMIZE == key ||                    RESTORE == key) {                setState(dp, key);            }            else if (ESCAPE == key) {                if (sourceFrame == dp.getSelectedFrame() &&                        focusOwner != null) {                    focusOwner.requestFocus();                }                moving = false;                resizing = false;                sourceFrame = null;                focusOwner = null;            }            else if (MOVE == key || RESIZE == key) {                sourceFrame = dp.getSelectedFrame();                if (sourceFrame == null) {                    return;

⌨️ 快捷键说明

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