synthinternalframeui.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,486 行 · 第 1/4 页
JAVA
1,486 行
/* * @(#)SynthInternalFrameUI.java 1.13 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 java.awt.*;import java.awt.event.*;import java.awt.peer.LightweightPeer;import javax.swing.*;import javax.swing.plaf.*;import javax.swing.event.*;import java.beans.*;import java.io.Serializable;/** * A basic L&F implementation of JInternalFrame. * * @version 1.13 01/23/03 (originally from version 1.104 of BasicInternalFrameUI) * @author David Kloba * @author Joshua Outwater * @author Rich Schiavi */class SynthInternalFrameUI extends InternalFrameUI implements SynthUI, LazyActionMap.Loader { private SynthStyle style; // Listeners protected MouseInputAdapter borderListener; protected PropertyChangeListener propertyChangeListener; protected LayoutManager internalFrameLayout; protected ComponentListener componentListener; protected MouseInputListener glassPaneDispatcher; // Subcomponents protected JComponent northPane; protected JComponent southPane; protected JComponent westPane; protected JComponent eastPane; protected SynthInternalFrameTitlePane titlePane; protected JInternalFrame frame; private static DesktopManager sharedDesktopManager; private boolean componentListenerAdded = false; private Rectangle parentBounds; private boolean dragging = false; private boolean keyBindingRegistered = false; private boolean keyBindingActive = false; private InternalFrameListener internalFrameListener = null; public static ComponentUI createUI(JComponent b) { return new SynthInternalFrameUI(); } public void installUI(JComponent c) { frame = (JInternalFrame)c; fetchStyle(c); frame.setLayout(internalFrameLayout = createLayoutManager()); // PENDING (josh): Why is installListeners first? Can it be made // last? installListeners(); installComponents(); installDefaults(); installKeyboardActions(); } public void uninstallUI(JComponent c) { if (c != frame) { throw new IllegalComponentStateException( this + " was asked to deinstall() " + c + " when it only knows about " + frame + "."); } uninstallKeyboardActions(); uninstallDefaults(); uninstallComponents(); uninstallListeners(); frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); internalFrameLayout = null; frame.setLayout(null); frame = null; } protected void installDefaults(){ /* 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); } } } private void fetchStyle(JComponent c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { Icon frameIcon = frame.getFrameIcon(); if (frameIcon == null || frameIcon instanceof UIResource) { frame.setFrameIcon(context.getStyle().getIcon( context, "InternalFrame.icon")); } } context.dispose(); } protected void uninstallDefaults() { SynthContext context = getContext(frame, ENABLED); style.uninstallDefaults(context); context.dispose(); Icon frameIcon = frame.getFrameIcon(); if (frameIcon instanceof UIResource) { frame.setFrameIcon(null); } style = null; } protected void installKeyboardActions(){ if (internalFrameListener == null) { createInternalFrameListener(); } frame.addInternalFrameListener(internalFrameListener); LazyActionMap.installLazyActionMap(frame, this); } protected void uninstallKeyboardActions(){ if (internalFrameListener != null) { frame.removeInternalFrameListener(internalFrameListener); } SwingUtilities.replaceUIInputMap(frame, JComponent. WHEN_IN_FOCUSED_WINDOW, null); SwingUtilities.replaceUIActionMap(frame, null); } protected void installComponents(){ setNorthPane(createNorthPane(frame)); setSouthPane(createSouthPane(frame)); setEastPane(createEastPane(frame)); setWestPane(createWestPane(frame)); } protected void uninstallComponents(){ setNorthPane(null); setSouthPane(null); setEastPane(null); setWestPane(null); titlePane = null; } 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; } } 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; } public void loadActionMap(JComponent c, ActionMap map) { // add action for the system menu map.put("showSystemMenu", new AbstractAction() { public void actionPerformed(ActionEvent e){ //titlePane.showSystemMenu(); } public boolean isEnabled(){ return isKeyBindingActive(); } }); } 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) { SynthContext context = getContext(frame, ENABLED); Object[] bindings = (Object[])context.getStyle().get (context, "InternalFrame.windowBindings"); if (bindings != null) { return LookAndFeel.makeComponentInputMap(frame, bindings); } } return 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); } 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); } public int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } /** * 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 SynthInternalFrameTitlePane(w); titlePane.setName("InternalFrame.northPane"); 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? // Also, no longer registering on the desktopicon, the previous // action did nothing. InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); SwingUtilities.replaceUIInputMap(frame, JComponent.WHEN_IN_FOCUSED_WINDOW, map); //ActionMap actionMap = getActionMap(); //SwingUtilities.replaceUIActionMap(frame, actionMap); } protected void setupMenuCloseKey(){ } public JComponent getNorthPane() { return northPane; } public void setNorthPane(JComponent c) { if (northPane != null && northPane instanceof SynthInternalFrameTitlePane) { ((SynthInternalFrameTitlePane)northPane).uninstallListeners();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?