📄 basicinternalframeui.java
字号:
/* * @(#)BasicInternalFrameUI.java 1.110 03/02/19 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.basic;import java.awt.*;import java.awt.event.*;import java.awt.peer.LightweightPeer;import javax.swing.*;import javax.swing.border.*;import javax.swing.plaf.*;import javax.swing.event.*;import java.beans.*;import java.io.Serializable;/** * A basic L&F implementation of JInternalFrame. * * @version 1.110 02/19/03 * @author David Kloba * @author Rich Schiavi */public class BasicInternalFrameUI extends InternalFrameUI { protected JInternalFrame frame; protected MouseInputAdapter borderListener; protected PropertyChangeListener propertyChangeListener; protected LayoutManager internalFrameLayout; protected ComponentListener componentListener; protected MouseInputListener glassPaneDispatcher; protected JComponent northPane; protected JComponent southPane; protected JComponent westPane; protected JComponent eastPane; protected BasicInternalFrameTitlePane titlePane; // access needs this private static DesktopManager sharedDesktopManager; private boolean componentListenerAdded = false; private Rectangle parentBounds; private boolean dragging = false; /** * 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 Java 2 platform v1.3. */ protected KeyStroke openMenuKey; private boolean keyBindingRegistered = false; private boolean keyBindingActive = false; private InternalFrameListener internalFrameListener = null; /////////////////////////////////////////////////////////////////////////////// ComponentUI Interface Implementation methods///////////////////////////////////////////////////////////////////////////// public static ComponentUI createUI(JComponent b) { return new BasicInternalFrameUI((JInternalFrame)b); } public BasicInternalFrameUI(JInternalFrame b) { } public void installUI(JComponent c) { frame = (JInternalFrame)c; installDefaults(); installListeners(); installComponents(); installKeyboardActions(); frame.setOpaque(true); } public void uninstallUI(JComponent c) { if(c != frame) throw new IllegalComponentStateException( this + " was asked to deinstall() " + c + " when it only knows about " + frame + "."); uninstallKeyboardActions(); uninstallComponents(); uninstallListeners(); uninstallDefaults(); frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); frame = null; } protected void installDefaults(){ Icon frameIcon = frame.getFrameIcon(); if (frameIcon == null || frameIcon instanceof UIResource) { frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon")); } /* enable the content pane to inherit background color from its parent by setting its background color to null. Fixes bug# 4268949. */ JComponent contentPane = (JComponent) frame.getContentPane(); if (contentPane != null) { Color bg = contentPane.getBackground(); if (bg instanceof UIResource) contentPane.setBackground(null); } frame.setLayout(internalFrameLayout = createLayoutManager()); frame.setBackground(UIManager.getLookAndFeelDefaults().getColor("control")); LookAndFeel.installBorder(frame, "InternalFrame.border"); } protected void installKeyboardActions(){ if (internalFrameListener == null) createInternalFrameListener(); frame.addInternalFrameListener(internalFrameListener); ActionMap actionMap = getActionMap(); SwingUtilities.replaceUIActionMap(frame, actionMap); } ActionMap getActionMap() { ActionMap map = (ActionMap)UIManager.get("InternalFrame.actionMap"); if (map == null) { map = createActionMap(); if (map != null) { UIManager.getLookAndFeelDefaults().put("InternalFrame.actionMap", map); } } return map; } ActionMap createActionMap() { ActionMap map = new ActionMapUIResource(); // add action for the system menu map.put("showSystemMenu", new AbstractAction(){ public void actionPerformed(ActionEvent e){ titlePane.showSystemMenu(); } public boolean isEnabled(){ return isKeyBindingActive(); } }); // Set the ActionMap's parent to the Auditory Feedback Action Map BasicLookAndFeel lf = (BasicLookAndFeel)UIManager.getLookAndFeel(); ActionMap audioMap = lf.getAudioActionMap(); map.setParent(audioMap); return map; } protected void installComponents(){ setNorthPane(createNorthPane(frame)); setSouthPane(createSouthPane(frame)); setEastPane(createEastPane(frame)); setWestPane(createWestPane(frame)); } /* * @since 1.3 */ protected void installListeners() { borderListener = createBorderListener(frame); propertyChangeListener = createPropertyChangeListener(); frame.addPropertyChangeListener(propertyChangeListener); installMouseHandlers(frame); glassPaneDispatcher = createGlassPaneDispatcher(); frame.getGlassPane().addMouseListener(glassPaneDispatcher); frame.getGlassPane().addMouseMotionListener(glassPaneDispatcher); componentListener = createComponentListener(); if (frame.getParent() != null) { parentBounds = frame.getParent().getBounds(); } if ((frame.getParent() != null) && !componentListenerAdded) { frame.getParent().addComponentListener(componentListener); componentListenerAdded = true; } } InputMap getInputMap(int condition) { if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { return createInputMap(condition); } return null; } InputMap createInputMap(int condition) { if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { Object[] bindings = (Object[])UIManager.get ("InternalFrame.windowBindings"); if (bindings != null) { return LookAndFeel.makeComponentInputMap(frame, bindings); } } return null; } protected void uninstallDefaults() { Icon frameIcon = frame.getFrameIcon(); if (frameIcon instanceof UIResource) { frame.setFrameIcon(null); } internalFrameLayout = null; frame.setLayout(null); LookAndFeel.uninstallBorder(frame); } protected void uninstallComponents(){ setNorthPane(null); setSouthPane(null); setEastPane(null); setWestPane(null); titlePane = null; } /* * @since 1.3 */ protected void uninstallListeners() { if ((frame.getParent() != null) && componentListenerAdded) { frame.getParent().removeComponentListener(componentListener); componentListenerAdded = false; } componentListener = null; frame.getGlassPane().removeMouseListener(glassPaneDispatcher); frame.getGlassPane().removeMouseMotionListener(glassPaneDispatcher); glassPaneDispatcher = null; deinstallMouseHandlers(frame); frame.removePropertyChangeListener(propertyChangeListener); propertyChangeListener = null; borderListener = null; } protected void uninstallKeyboardActions(){ if (internalFrameListener != null) { frame.removeInternalFrameListener(internalFrameListener); } SwingUtilities.replaceUIInputMap(frame, JComponent. WHEN_IN_FOCUSED_WINDOW, null); SwingUtilities.replaceUIActionMap(frame, null); } protected LayoutManager createLayoutManager(){ return new InternalFrameLayout(); } protected PropertyChangeListener createPropertyChangeListener(){ return new InternalFramePropertyChangeListener(); } public Dimension getPreferredSize(JComponent x) { if((JComponent)frame == x) return frame.getLayout().preferredLayoutSize(x); return new Dimension(100, 100); } public Dimension getMinimumSize(JComponent x) { if((JComponent)frame == x) { return frame.getLayout().minimumLayoutSize(x); } return new Dimension(0, 0); } public Dimension getMaximumSize(JComponent x) { return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); } /** * Installs necessary mouse handlers on <code>newPane</code> * and adds it to the frame. * Reverse process for the <code>currentPane</code>. */ protected void replacePane(JComponent currentPane, JComponent newPane) { if(currentPane != null) { deinstallMouseHandlers(currentPane); frame.remove(currentPane); } if(newPane != null) { frame.add(newPane); installMouseHandlers(newPane); } } protected void deinstallMouseHandlers(JComponent c) { c.removeMouseListener(borderListener); c.removeMouseMotionListener(borderListener); } protected void installMouseHandlers(JComponent c) { c.addMouseListener(borderListener); c.addMouseMotionListener(borderListener); } protected JComponent createNorthPane(JInternalFrame w) { titlePane = new BasicInternalFrameTitlePane(w); return titlePane; } protected JComponent createSouthPane(JInternalFrame w) { return null; } protected JComponent createWestPane(JInternalFrame w) { return null; } protected JComponent createEastPane(JInternalFrame w) { return null; } protected MouseInputAdapter createBorderListener(JInternalFrame w) { return new BorderListener(); } private InternalFrameListener getInternalFrameListener(){ return internalFrameListener; } protected void createInternalFrameListener(){ internalFrameListener = new BasicInternalFrameListener(); } protected final boolean isKeyBindingRegistered(){ return keyBindingRegistered; } protected final void setKeyBindingRegistered(boolean b){ keyBindingRegistered = b; } public final boolean isKeyBindingActive(){ return keyBindingActive; } protected final void setKeyBindingActive(boolean b){ keyBindingActive = b; } protected void setupMenuOpenKey(){ // PENDING(hania): Why are these WHEN_IN_FOCUSED_WINDOWs? Shouldn't // they be WHEN_ANCESTOR_OF_FOCUSED_COMPONENT?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -