synthdesktoppaneui.java
来自「java jdk 1.4的源码」· Java 代码 · 共 673 行 · 第 1/2 页
JAVA
673 行
/* * @(#)SynthDesktopPaneUI.java 1.9 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.java.swing.plaf.gtk;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;/** * Synth L&F for a desktop. * * @version 1.9, 01/23/03 (originally from version 1.44 of BasicDesktopPaneUI) * @author Joshua Outwater * @author Steve Wilson */class SynthDesktopPaneUI extends DesktopPaneUI implements PropertyChangeListener, SynthUI, LazyActionMap.Loader { private static Dimension minSize = new Dimension(0,0); private static Dimension maxSize = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); private SynthStyle style; 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 SynthDesktopPaneUI(); } public SynthDesktopPaneUI() { } public void installUI(JComponent c) { desktop = (JDesktopPane)c; installDefaults(); installDesktopManager(); installKeyboardActions(); installListeners(); } public void uninstallUI(JComponent c) { uninstallKeyboardActions(); uninstallDesktopManager(); uninstallDefaults(); uninstallListeners(); desktop = null; } protected void installListeners() { desktop.addPropertyChangeListener(this); } protected void installDefaults() { fetchStyle(desktop); } private void fetchStyle(JDesktopPane c) { SynthContext context = getContext(c, ENABLED); style = SynthLookAndFeel.updateStyle(context, this); context.dispose(); } protected void uninstallListeners() { desktop.removePropertyChangeListener(this); } protected void uninstallDefaults() { SynthContext context = getContext(desktop, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } 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); } LazyActionMap.installLazyActionMap(desktop, this); 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; } public void loadActionMap(JComponent c, ActionMap map) { 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", new NavigateAction()); map.put("selectPreviousFrame", new PreviousAction()); map.put("navigateNext", new NavigateOutAction(true)); map.put("navigatePrevious", new NavigateOutAction(false)); } 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 SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { } public Dimension getPreferredSize(JComponent c) {return null;} public Dimension getMinimumSize(JComponent c) { return minSize; } public Dimension getMaximumSize(JComponent c){ return maxSize; } public void propertyChange(PropertyChangeEvent evt) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) { fetchStyle((JDesktopPane)evt.getSource()); } } /* * Key binding for accessibility ----------------- */ private static Vector framesCache; 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; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?