📄 metalinternalframetitlepane.java
字号:
/* * @(#)MetalInternalFrameTitlePane.java 1.59 05/11/30 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.metal;import sun.swing.SwingUtilities2;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.InternalFrameEvent;import java.util.EventListener;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;import javax.swing.plaf.basic.BasicInternalFrameTitlePane;/** * Class that manages a JLF title bar * @version 1.59 11/30/05 * @author Steve Wilson * @author Brian Beck * @since 1.3 */public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { protected boolean isPalette = false; protected Icon paletteCloseIcon; protected int paletteTitleHeight; private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0); /** * Key used to lookup Color from UIManager. If this is null, * <code>getWindowTitleBackground</code> is used. */ private String selectedBackgroundKey; /** * Key used to lookup Color from UIManager. If this is null, * <code>getWindowTitleForeground</code> is used. */ private String selectedForegroundKey; /** * Key used to lookup shadow color from UIManager. If this is null, * <code>getPrimaryControlDarkShadow</code> is used. */ private String selectedShadowKey; /** * Boolean indicating the state of the <code>JInternalFrame</code>s * closable property at <code>updateUI</code> time. */ private boolean wasClosable; int buttonsWidth = 0; MetalBumps activeBumps = new MetalBumps( 0, 0, MetalLookAndFeel.getPrimaryControlHighlight(), MetalLookAndFeel.getPrimaryControlDarkShadow(), (UIManager.get("InternalFrame.activeTitleGradient") != null) ? null : MetalLookAndFeel.getPrimaryControl() ); MetalBumps inactiveBumps = new MetalBumps( 0, 0, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow(), (UIManager.get("InternalFrame.inactiveTitleGradient") != null) ? null : MetalLookAndFeel.getControl() ); MetalBumps paletteBumps; private Color activeBumpsHighlight = MetalLookAndFeel. getPrimaryControlHighlight(); private Color activeBumpsShadow = MetalLookAndFeel. getPrimaryControlDarkShadow(); public MetalInternalFrameTitlePane(JInternalFrame f) { super( f ); } public void addNotify() { super.addNotify(); // This is done here instead of in installDefaults as I was worried // that the BasicInternalFrameUI might not be fully initialized, and // that if this resets the closable state the BasicInternalFrameUI // Listeners that get notified might be in an odd/uninitialized state. updateOptionPaneState(); } protected void installDefaults() { super.installDefaults(); setFont( UIManager.getFont("InternalFrame.titleFont") ); paletteTitleHeight = UIManager.getInt("InternalFrame.paletteTitleHeight"); paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon"); wasClosable = frame.isClosable(); selectedForegroundKey = selectedBackgroundKey = null; if (MetalLookAndFeel.usingOcean()) { setOpaque(true); } } protected void uninstallDefaults() { super.uninstallDefaults(); if (wasClosable != frame.isClosable()) { frame.setClosable(wasClosable); } } protected void createButtons() { super.createButtons(); Boolean paintActive = frame.isSelected() ? Boolean.TRUE:Boolean.FALSE; iconButton.putClientProperty("paintActive", paintActive); iconButton.setBorder(handyEmptyBorder); maxButton.putClientProperty("paintActive", paintActive); maxButton.setBorder(handyEmptyBorder); closeButton.putClientProperty("paintActive", paintActive); closeButton.setBorder(handyEmptyBorder); // The palette close icon isn't opaque while the regular close icon is. // This makes sure palette close buttons have the right background. closeButton.setBackground(MetalLookAndFeel.getPrimaryControlShadow()); if (MetalLookAndFeel.usingOcean()) { iconButton.setContentAreaFilled(false); maxButton.setContentAreaFilled(false); closeButton.setContentAreaFilled(false); } } /** * Override the parent's method to do nothing. Metal frames do not * have system menus. */ protected void assembleSystemMenu() {} /** * Override the parent's method to do nothing. Metal frames do not * have system menus. */ protected void addSystemMenuItems(JMenu systemMenu) {} /** * Override the parent's method to do nothing. Metal frames do not * have system menus. */ protected void showSystemMenu() {} /** * Override the parent's method avoid creating a menu bar. Metal frames * do not have system menus. */ protected void addSubComponents() { add(iconButton); add(maxButton); add(closeButton); } protected PropertyChangeListener createPropertyChangeListener() { return new MetalPropertyChangeHandler(); } protected LayoutManager createLayout() { return new MetalTitlePaneLayout(); } class MetalPropertyChangeHandler extends BasicInternalFrameTitlePane.PropertyChangeHandler { public void propertyChange(PropertyChangeEvent evt) { String prop = (String)evt.getPropertyName(); if( prop.equals(JInternalFrame.IS_SELECTED_PROPERTY) ) { Boolean b = (Boolean)evt.getNewValue(); iconButton.putClientProperty("paintActive", b); closeButton.putClientProperty("paintActive", b); maxButton.putClientProperty("paintActive", b); } else if ("JInternalFrame.messageType".equals(prop)) { updateOptionPaneState(); frame.repaint(); } super.propertyChange(evt); } } class MetalTitlePaneLayout extends TitlePaneLayout { public void addLayoutComponent(String name, Component c) {} public void removeLayoutComponent(Component c) {} public Dimension preferredLayoutSize(Container c) { return minimumLayoutSize(c); } public Dimension minimumLayoutSize(Container c) { // Compute width. int width = 30; if (frame.isClosable()) { width += 21; } if (frame.isMaximizable()) { width += 16 + (frame.isClosable() ? 10 : 4); } if (frame.isIconifiable()) { width += 16 + (frame.isMaximizable() ? 2 : (frame.isClosable() ? 10 : 4)); } FontMetrics fm = frame.getFontMetrics(getFont()); String frameTitle = frame.getTitle(); int title_w = frameTitle != null ? SwingUtilities2.stringWidth( frame, fm, frameTitle) : 0; int title_length = frameTitle != null ? frameTitle.length() : 0; if (title_length > 2) { int subtitle_w = SwingUtilities2.stringWidth(frame, fm, frame.getTitle().substring(0, 2) + "..."); width += (title_w < subtitle_w) ? title_w : subtitle_w; } else { width += title_w; } // Compute height. int height = 0; if (isPalette) { height = paletteTitleHeight; } else { int fontHeight = fm.getHeight(); fontHeight += 7; Icon icon = frame.getFrameIcon(); int iconHeight = 0; if (icon != null) { // SystemMenuBar forces the icon to be 16x16 or less. iconHeight = Math.min(icon.getIconHeight(), 16); } iconHeight += 5; height = Math.max(fontHeight, iconHeight); } return new Dimension(width, height); } public void layoutContainer(Container c) { boolean leftToRight = MetalUtils.isLeftToRight(frame); int w = getWidth(); int x = leftToRight ? w : 0; int y = 2; int spacing; // assumes all buttons have the same dimensions // these dimensions include the borders int buttonHeight = closeButton.getIcon().getIconHeight(); int buttonWidth = closeButton.getIcon().getIconWidth(); if(frame.isClosable()) { if (isPalette) { spacing = 3; x += leftToRight ? -spacing -(buttonWidth+2) : spacing; closeButton.setBounds(x, y, buttonWidth+2, getHeight()-4); if( !leftToRight ) x += (buttonWidth+2); } else { spacing = 4; x += leftToRight ? -spacing -buttonWidth : spacing;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -