📄 basicinternalframeui.java
字号:
/* * @(#)BasicInternalFrameUI.java 1.130 07/08/20 * * Copyright 2006 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;import sun.swing.DefaultLookup;import sun.swing.UIAction;/** * A basic L&F implementation of JInternalFrame. * * @version 1.130 08/20/07 * @author David Kloba * @author Rich Schiavi */public class BasicInternalFrameUI extends InternalFrameUI { protected JInternalFrame frame; private Handler handler; protected MouseInputAdapter borderListener; protected PropertyChangeListener propertyChangeListener; protected LayoutManager internalFrameLayout; protected ComponentListener componentListener; protected MouseInputListener glassPaneDispatcher; private InternalFrameListener internalFrameListener; 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; private boolean resizing = 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. */ @Deprecated protected KeyStroke openMenuKey; private boolean keyBindingRegistered = false; private boolean keyBindingActive = false;/////////////////////////////////////////////////////////////////////////////// ComponentUI Interface Implementation methods///////////////////////////////////////////////////////////////////////////// public static ComponentUI createUI(JComponent b) { return new BasicInternalFrameUI((JInternalFrame)b); } public BasicInternalFrameUI(JInternalFrame b) { LookAndFeel laf = UIManager.getLookAndFeel(); if (laf instanceof BasicLookAndFeel) { ((BasicLookAndFeel)laf).installAWTEventListener(); } } public void installUI(JComponent c) { frame = (JInternalFrame)c; installDefaults(); installListeners(); installComponents(); installKeyboardActions(); LookAndFeel.installProperty(frame, "opaque", Boolean.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(); updateFrameCursor(); handler = null; 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. Container contentPane = 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(){ createInternalFrameListener(); if (internalFrameListener != null) { frame.addInternalFrameListener(internalFrameListener); } LazyActionMap.installLazyActionMap(frame, BasicInternalFrameUI.class, "InternalFrame.actionMap"); } static void loadActionMap(LazyActionMap map) { map.put(new UIAction("showSystemMenu") { public void actionPerformed(ActionEvent evt) { JInternalFrame iFrame = (JInternalFrame)evt.getSource(); if (iFrame.getUI() instanceof BasicInternalFrameUI) { JComponent comp = ((BasicInternalFrameUI) iFrame.getUI()).getNorthPane(); if (comp instanceof BasicInternalFrameTitlePane) { ((BasicInternalFrameTitlePane)comp). showSystemMenu(); } } } public boolean isEnabled(Object sender){ if (sender instanceof JInternalFrame) { JInternalFrame iFrame = (JInternalFrame)sender; if (iFrame.getUI() instanceof BasicInternalFrameUI) { return ((BasicInternalFrameUI)iFrame.getUI()). isKeyBindingActive(); } } return false; } }); // Set the ActionMap's parent to the Auditory Feedback Action Map BasicLookAndFeel.installAudioActionMap(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(); if (glassPaneDispatcher != null) { 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; } } // Provide a FocusListener to listen for a WINDOW_LOST_FOCUS event, // so that a resize can be cancelled if the focus is lost while resizing // when an Alt-Tab, modal dialog popup, iconify, dispose, or remove // of the internal frame occurs. private WindowFocusListener getWindowFocusListener(){ return getHandler(); } // Cancel a resize in progress by calling finishMouseReleased(). private void cancelResize() { if (resizing) { if (borderListener instanceof BorderListener) { ((BorderListener)borderListener).finishMouseReleased(); } } } private Handler getHandler() { if (handler == null) { handler = new Handler(); } return handler; } 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[])DefaultLookup.get( frame, this, "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); if(titlePane != null) { titlePane.uninstallDefaults(); } titlePane = null; } /** * @since 1.3 */ protected void uninstallListeners() { if ((frame.getParent() != null) && componentListenerAdded) { frame.getParent().removeComponentListener(componentListener); componentListenerAdded = false; } componentListener = null; if (glassPaneDispatcher != 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); } internalFrameListener = null; SwingUtilities.replaceUIInputMap(frame, JComponent. WHEN_IN_FOCUSED_WINDOW, null); SwingUtilities.replaceUIActionMap(frame, null); } void updateFrameCursor() { if (resizing) { return; } Cursor s = (Cursor)frame.getLastCursor(); if (s == null) { s = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); } frame.setCursor(s); } protected LayoutManager createLayoutManager(){ return getHandler(); } protected PropertyChangeListener createPropertyChangeListener(){ return getHandler(); } 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -