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

📄 basicdesktoppaneui.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)BasicDesktopPaneUI.java	1.45 03/01/23 * * Copyright 2003 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;/** * Basic L&F for a desktop. * * @version 1.45 01/23/03 * @author Steve Wilson */public class BasicDesktopPaneUI extends DesktopPaneUI{    private static Dimension minSize = new Dimension(0,0);    private static Dimension maxSize = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);    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.     */    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.     */    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.     */    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.     */    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.     */    protected KeyStroke navigateKey2;    public static ComponentUI createUI(JComponent c) {        return new BasicDesktopPaneUI();    }    public BasicDesktopPaneUI() {    }    public void installUI(JComponent c)   {	desktop = (JDesktopPane)c;	installDefaults();	installDesktopManager();	installKeyboardActions();    }    public void uninstallUI(JComponent c) {	uninstallKeyboardActions();	uninstallDesktopManager();        uninstallDefaults();	desktop = null;    }    protected void installDefaults() {	if (desktop.getBackground() == null || 	    desktop.getBackground() instanceof UIResource) {	    desktop.setBackground(UIManager.getColor("Desktop.background"));	}            }    protected void uninstallDefaults() { }    protected void installDesktopManager() {	if(desktop.getDesktopManager() == null) {	    desktopManager = new DefaultDesktopManager();	    desktop.setDesktopManager(desktopManager);	}    }    protected void uninstallDesktopManager() {	if(desktop.getDesktopManager() == desktopManager) {	    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);	}	ActionMap actionMap = getActionMap();	SwingUtilities.replaceUIActionMap(desktop, 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)UIManager.get("Desktop.ancestorInputMap");	}	return null;    }    InputMap createInputMap(int condition) {	if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {	    Object[] bindings = (Object[])UIManager.get		                          ("Desktop.windowBindings");	    if (bindings != null) {		return LookAndFeel.makeComponentInputMap(desktop, bindings);	    }	}	return null;    }    ActionMap getActionMap() {	return createActionMap();    }    ActionMap createActionMap() {	ActionMap map = new ActionMapUIResource();	map.put("restore", new OpenAction());	map.put("close", new CloseAction());	map.put("move", new MoveResizeAction("move"));	map.put("resize", new MoveResizeAction("resize"));	map.put("left", new MoveResizeAction("left"));	map.put("shrinkLeft", new MoveResizeAction("shrinkLeft"));	map.put("right", new MoveResizeAction("right"));	map.put("shrinkRight", new MoveResizeAction("shrinkRight"));	map.put("up", new MoveResizeAction("up"));	map.put("shrinkUp", new MoveResizeAction("shrinkUp"));	map.put("down", new MoveResizeAction("down"));	map.put("shrinkDown", new MoveResizeAction("shrinkDown"));	map.put("escape", new MoveResizeAction("escape"));	map.put("minimize", new MinimizeAction());	map.put("maximize", new MaximizeAction());	map.put("selectNextFrame", nextAction = new NavigateAction());	map.put("selectPreviousFrame", new PreviousAction());        map.put("navigateNext", new NavigateOutAction(true));        map.put("navigatePrevious", new NavigateOutAction(false));	return map;    }    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;    }    /*     * Key binding for accessibility -----------------     */    private static Vector framesCache;    private NavigateAction nextAction;    private boolean moving = false;    private boolean resizing = false;    private final int MOVE_RESIZE_INCREMENT = 10;    /*     * Handles restoring a minimized or maximized internal frame.     */    protected class OpenAction extends AbstractAction {	public void actionPerformed(ActionEvent e) {	    // restore the selected minimized or maximized frame	    JInternalFrame f = desktop.getSelectedFrame();	    if (f == null) return;	    try {	      if (f.isIcon()) {		f.setIcon(false);	      } else if (f.isMaximum()) {		f.setMaximum(false);	      }	      f.setSelected(true);	    } catch (PropertyVetoException pve) {	    }	}	public boolean isEnabled() { 	    return true;	}    }    /*     * Handles closing an internal frame     */    protected class CloseAction extends AbstractAction {	public void actionPerformed(ActionEvent e) {	    JInternalFrame f = desktop.getSelectedFrame();	    if (f == null) return;	    if (f.isClosable()) {	      try {		f.setClosed(true);	      } catch (PropertyVetoException pve) {	      }	    }	}	public boolean isEnabled() { 	    return true;	}    }    /*     * Handles moving and resizing an internal frame     */    private class MoveResizeAction extends AbstractAction {	private String command;		public MoveResizeAction(String command) {	    this.command = command;	}	public void actionPerformed(ActionEvent e) {	    JInternalFrame c = desktop.getSelectedFrame(); 	    if (c == null) {		return;	    }	    if ("move".equals(command)) {		moving = true;		resizing = false;		return;	    } else if ("resize".equals(command)) {		moving = false;		resizing = true;		return;	    } else if ("escape".equals(command)) {		moving = resizing = false;		return;	    }	    if (!moving && !resizing) {		return;	    }

⌨️ 快捷键说明

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