📄 smoothgradienttitlepane.java
字号:
package org.underworldlabs.swing.plaf.smoothgradient;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dialog;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Frame;import java.awt.Graphics;import java.awt.Image;import java.awt.LayoutManager;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.Locale;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.Icon;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JRootPane;import javax.swing.JSeparator;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.border.Border;import javax.swing.border.EmptyBorder;import javax.swing.plaf.UIResource;/* * SmoothGradientTitlePane.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * *//** * * @author Takis Diakoumis * @version $Revision: 1.4 $ * @date $Date: 2006/05/14 06:56:07 $ */class SmoothGradientTitlePane extends JComponent { private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0); private static final int IMAGE_HEIGHT = 16; private static final int IMAGE_WIDTH = 16; /** * PropertyChangeListener added to the JRootPane. */ private PropertyChangeListener propertyChangeListener; /** * JMenuBar, typically renders the system menu items. */ private JMenuBar menuBar; /** * Action used to close the Window. */ private Action closeAction; /** * Action used to iconify the Frame. */ private Action iconifyAction; /** * Action to restore the Frame size. */ private Action restoreAction; /** * Action to restore the Frame size. */ private Action maximizeAction; /** * Button used to maximize or restore the Frame. */ private JButton toggleButton; /** * Button used to maximize or restore the Frame. */ private JButton iconifyButton; /** * Button used to maximize or restore the Frame. */ private JButton closeButton; /** * Icon used for toggleButton when window is normal size. */ private Icon maximizeIcon; /** * Icon used for toggleButton when window is maximized. */ private Icon minimizeIcon; /** * Listens for changes in the state of the Window listener to update * the state of the widgets. */ private WindowListener windowListener; /** * Window we're currently in. */ private Window window; /** * JRootPane rendering for. */ private JRootPane rootPane; /** * Room remaining in title for bumps. */ private int buttonsWidth; /** * Buffered Frame.state property. As state isn't bound, this is kept * to determine when to avoid updating widgets. */ private int state; /** * MetalRootPaneUI that created us. */ private SmoothGradientRootPaneUI rootPaneUI; // Colors private Color inactiveBackground = UIManager.getColor("inactiveCaption"); private Color inactiveForeground = UIManager.getColor("inactiveCaptionText"); private Color inactiveShadow = UIManager.getColor("inactiveCaptionBorder"); private Color activeBumpsHighlight = SmoothGradientLookAndFeel.getInternalFrameBumpsHighlight(); private Color activeBumpsShadow = SmoothGradientLookAndFeel.getPrimaryControlDarkShadow(); private Color activeBackground = null; private Color activeForeground = null; private Color activeShadow = null; public SmoothGradientTitlePane(JRootPane root, SmoothGradientRootPaneUI ui) { this.rootPane = root; rootPaneUI = ui; state = -1; installSubcomponents(); determineColors(); installDefaults(); setLayout(createLayout()); } /** * Uninstalls the necessary state. */ private void uninstall() { uninstallListeners(); window = null; removeAll(); } /** * Installs the necessary listeners. */ private void installListeners() { if (window != null) { windowListener = createWindowListener(); window.addWindowListener(windowListener); propertyChangeListener = createWindowPropertyChangeListener(); window.addPropertyChangeListener(propertyChangeListener); } } /** * Uninstalls the necessary listeners. */ private void uninstallListeners() { if (window != null) { window.removeWindowListener(windowListener); window.removePropertyChangeListener(propertyChangeListener); } } /** * Returns the <code>WindowListener</code> to add to the * <code>Window</code>. */ private WindowListener createWindowListener() { return new WindowHandler(); } /** * Returns the <code>PropertyChangeListener</code> to install on * the <code>Window</code>. */ private PropertyChangeListener createWindowPropertyChangeListener() { return new PropertyChangeHandler(); } /** * Returns the <code>JRootPane</code> this was created for. */ public JRootPane getRootPane() { return rootPane; } /** * Returns the decoration style of the <code>JRootPane</code>. */ private int getWindowDecorationStyle() { return getRootPane().getWindowDecorationStyle(); } public void addNotify() { super.addNotify(); uninstallListeners(); window = SwingUtilities.getWindowAncestor(this); if (window != null) { if (window instanceof Frame) { setState(((Frame)window).getExtendedState()); } else { setState(0); } setActive(window.isActive()); installListeners(); } } public void removeNotify() { super.removeNotify(); uninstallListeners(); window = null; } /** * Adds any sub-Components contained in the <code>MetalTitlePane</code>. */ private void installSubcomponents() { if (getWindowDecorationStyle() == JRootPane.FRAME) { createActions(); menuBar = createMenuBar(); add(menuBar); createButtons(); add(iconifyButton); add(toggleButton); add(closeButton); } } /** * Determines the Colors to draw with. */ private void determineColors() { Color _activeBumpsHighlight = activeBumpsHighlight; switch (getWindowDecorationStyle()) { case JRootPane.FRAME: activeBackground = UIManager.getColor("activeCaption"); activeForeground = UIManager.getColor("activeCaptionText"); activeShadow = UIManager.getColor("activeCaptionBorder"); break; case JRootPane.ERROR_DIALOG: activeBackground = UIManager.getColor( "OptionPane.errorDialog.titlePane.background"); activeForeground = UIManager.getColor( "OptionPane.errorDialog.titlePane.foreground"); activeShadow = UIManager.getColor( "OptionPane.errorDialog.titlePane.shadow"); break; case JRootPane.QUESTION_DIALOG: case JRootPane.COLOR_CHOOSER_DIALOG: case JRootPane.FILE_CHOOSER_DIALOG: activeBackground = UIManager.getColor( "OptionPane.questionDialog.titlePane.background"); activeForeground = UIManager.getColor( "OptionPane.questionDialog.titlePane.foreground"); activeShadow = UIManager.getColor( "OptionPane.questionDialog.titlePane.shadow"); break; case JRootPane.WARNING_DIALOG: activeBackground = UIManager.getColor( "OptionPane.warningDialog.titlePane.background"); activeForeground = UIManager.getColor( "OptionPane.warningDialog.titlePane.foreground"); activeShadow = UIManager.getColor( "OptionPane.warningDialog.titlePane.shadow"); break; case JRootPane.PLAIN_DIALOG: case JRootPane.INFORMATION_DIALOG: default: _activeBumpsHighlight = SmoothGradientLookAndFeel.getInternalFrameBumpsHighlight(); activeBackground = UIManager.getColor("activeCaption"); activeForeground = UIManager.getColor("activeCaptionText"); activeShadow = UIManager.getColor("activeCaptionBorder"); break; } } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -