📄 skintitlepane.java
字号:
/* ====================================================================
*
* Skin Look And Feel 1.2.10 License.
*
* Copyright (c) 2000-2004 L2FProd.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by L2FProd.com
* (http://www.L2FProd.com/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Skin Look And Feel", "SkinLF" and "L2FProd.com" must not
* be used to endorse or promote products derived from this software
* without prior written permission. For written permission, please
* contact info@L2FProd.com.
*
* 5. Products derived from this software may not be called "SkinLF"
* nor may "SkinLF" appear in their names without prior written
* permission of L2FProd.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL L2FPROD.COM OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
package com.l2fprod.gui.plaf.skin;
import com.l2fprod.util.OS;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.LayoutManager;
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.beans.PropertyVetoException;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
/**
* Description of the Class
*
* @author fred
*/
public class SkinTitlePane extends BasicInternalFrameTitlePane {
/**
* Description of the Field
*/
protected Window m_Window;
private SkinWindowButton[] m_WindowButtons;
/**
* Description of the Field
*/
private Action shadeAction;
private Skin skin;
private WindowListener m_WindowListener;
public final static int ICON_OFFSET = 16;
/**
* Align button relative to top left of window
*/
public final static int ALIGN_TOP_LEFT = 0;
/**
* Align button relative to the top right of window
*/
public final static int ALIGN_TOP_RIGHT = 1;
/**
* Description of the Field
*/
public final static int CLOSE_ACTION = 0;
/**
* Description of the Field
*/
public final static int MAXIMIZE_ACTION = 22;
/**
* Description of the Field
*/
public final static int MINIMIZE_ACTION = 23;
/**
* Description of the Field
*/
public final static int NO_ACTION = -1;
/**
* Constructor for the SkinTitlePane object
*
* @param f Description of Parameter
*/
public SkinTitlePane(JInternalFrame f) {
this(new Window.InternalFrameWindow(f));
}
/**
* Constructor for the SkinTitlePane object
*
* @param f Description of Parameter
*/
public SkinTitlePane(Window f) {
super(null);
m_Window = f;
// in JDK1.4 Sun changed the way listener is added remove before
// it was in add/remove notify now add is made in installDefaults
// and remove by BasicInternalFrameUI
if (OS.isOneDotFourOrMore()) {
installListeners();
}
}
/**
* Gets the Window attribute of the SkinTitlePane object
*
* @return The Window value
*/
public Window getWindow() {
return m_Window;
}
/**
* Gets the PreferredSize attribute of the SkinTitlePane object
*
* @return The PreferredSize value
*/
public Dimension getPreferredSize() {
return skin.getFrame().getTopPreferredSize();
}
/**
* Gets the MinimumSize attribute of the SkinTitlePane object
*
* @return The MinimumSize value
*/
public Dimension getMinimumSize() {
return skin.getFrame().getTopPreferredSize();
}
/**
* Description of the Method
*
* @param g Description of Parameter
*/
public void paintComponent(Graphics g) {
boolean isSelected = m_Window.isSelected();
Font f = g.getFont();
if (m_Window.getTitle() != null) {
if (isSelected) {
g.setColor(selectedTextColor);
}
else {
g.setColor(notSelectedTextColor);
}
g.setFont(UIManager.getFont("InternalFrame.titleFont"));
}
skin.getFrame().paintTop(g, this, isSelected, m_Window.getTitle());
g.setFont(f);
}
/**
* Sets the ButtonIcons attribute of the SkinTitlePane object
*/
protected void setButtonIcons() {
}
/**
* Description of the Method
*/
protected void installTitlePane() {
installDefaults();
createActions();
enableActions();
assembleSystemMenu();
setLayout(createLayout());
add(menuBar);
setOpaque(true);
skin = SkinLookAndFeel.getSkin();
createButtons();
}
/**
* Description of the Method
*/
protected void createActions() {
maximizeAction = new MaximizeAction();
maximizeAction.setEnabled(true);
iconifyAction = new IconifyAction();
iconifyAction.setEnabled(true);
closeAction = new CloseAction();
closeAction.setEnabled(true);
restoreAction = new RestoreAction();
restoreAction.setEnabled(true);
shadeAction = new ShadeAction();
shadeAction.setEnabled(true);
}
/**
* Overriden to register on the window
*/
protected void installListeners() {
// the window container may be null when the titlePane is used by
// a JFrame/JDialog
if (m_Window == null || m_Window.getContainer() == null) {
return;
}
if (propertyChangeListener == null) {
propertyChangeListener = createPropertyChangeListener();
}
m_Window.addPropertyChangeListener(propertyChangeListener);
if (m_Window instanceof Window.FrameWindow) {
if (m_WindowListener == null) {
m_WindowListener = createWindowListener();
}
((Window.FrameWindow)m_Window).getMainFrame().addWindowListener(
m_WindowListener);
}
}
/**
* called by the SkinRootPaneUI when the window container has been
* set
*/
void windowSet() {
installListeners();
}
/**
* Tracks window activation events to update the buttons and the
* titlebar
*/
private WindowListener createWindowListener() {
return new WindowAdapter() {
public void windowActivated(WindowEvent e) {
try {
m_Window.setSelected(true);
updateButtons();
} catch (PropertyVetoException ex) {}
}
public void windowDeactivated(WindowEvent e) {
try {
m_Window.setSelected(false);
updateButtons();
} catch (PropertyVetoException ex) {}
}
};
}
/**
* Overriden to unregister on the window
*/
protected void uninstallListeners() {
m_Window.removePropertyChangeListener(propertyChangeListener);
if (m_Window instanceof Window.FrameWindow && m_WindowListener != null) {
((Window.FrameWindow)m_Window).getMainFrame().removeWindowListener(
m_WindowListener);
}
}
/**
* Same as parent class except it does not initialize the icons
*/
protected void installDefaults() {
selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
}
/**
* Description of the Method
*/
protected void createButtons() {
SkinWindowButton[] buttonsLeft =
skin.getFrame().getWindowButtons(ALIGN_TOP_LEFT);
if (buttonsLeft != null) {
for (int i = 0, c = buttonsLeft.length; i < c; i++) {
addButton(buttonsLeft[i]);
}
}
SkinWindowButton[] buttonsRight =
skin.getFrame().getWindowButtons(ALIGN_TOP_RIGHT);
if (buttonsRight != null) {
for (int i = 0, c = buttonsRight.length; i < c; i++) {
addButton(buttonsRight[i]);
}
}
m_WindowButtons = new SkinWindowButton[buttonsLeft.length
+ buttonsRight.length];
System.arraycopy(buttonsLeft, 0, m_WindowButtons, 0, buttonsLeft.length);
System.arraycopy(buttonsRight, 0, m_WindowButtons, buttonsLeft.length,
buttonsRight.length);
}
private void updateButtons() {
for (int i = 0; i < m_WindowButtons.length; i++) {
m_WindowButtons[i].setSelected(m_Window.isSelected());
}
repaint();
}
/**
* Adds a feature to the Button attribute of the SkinTitlePane object
*
* @param button The feature to be added to the Button attribute
*/
protected void addButton(SkinWindowButton button) {
switch (button.getWindowAction()) {
case CLOSE_ACTION:
button.addActionListener(closeAction);
registerButtonForAction(button, closeAction);
break;
case MAXIMIZE_ACTION:
button.addActionListener(maximizeAction);
registerButtonForAction(button, maximizeAction);
break;
case MINIMIZE_ACTION:
button.addActionListener(iconifyAction);
registerButtonForAction(button, iconifyAction);
break;
}
add(button);
}
/**
* Adds a feature to the SystemMenuItems attribute of the SkinTitlePane object
*
* @param systemMenu The feature to be added to the SystemMenuItems attribute
*/
protected void addSystemMenuItems(JMenu systemMenu) {
JMenuItem mi = systemMenu.add(restoreAction);
mi.setMnemonic('R');
mi = systemMenu.add(iconifyAction);
mi.setMnemonic('n');
mi = systemMenu.add(maximizeAction);
mi.setMnemonic('x');
if (!Boolean.TRUE.equals(UIManager.get("TitlePane.disableShade"))) {
systemMenu.add(shadeAction);
}
systemMenu.add(new JSeparator());
mi = systemMenu.add(closeAction);
mi.setMnemonic('C');
}
protected JMenuBar createSystemMenuBar() {
menuBar = new SystemMenuBar();
menuBar.setBorderPainted(false);
return menuBar;
}
/**
* Description of the Method
*/
protected void enableActions() {
if (m_Window == null) {
return;
}
restoreAction.setEnabled(m_Window.isMaximum() || m_Window.isIcon());
maximizeAction.setEnabled(m_Window.isMaximizable());
iconifyAction.setEnabled(m_Window.isIconifiable() && !m_Window.isIcon());
closeAction.setEnabled(m_Window.isClosable());
shadeAction.setEnabled(!m_Window.isMaximum() && !m_Window.isIcon());
doLayout();
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
protected PropertyChangeListener createPropertyChangeListener() {
return new PropertyChangeHandler();
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -