📄 synthinternalframetitlepane.java
字号:
/* * @(#)SynthInternalFrameTitlePane.java 1.27 05/11/30 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.synth;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.plaf.*;import javax.swing.plaf.basic.BasicInternalFrameTitlePane;import javax.swing.border.*;import javax.swing.event.InternalFrameEvent;import java.util.EventListener;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;import java.beans.VetoableChangeListener;import java.beans.PropertyVetoException;import sun.swing.plaf.synth.SynthUI;import sun.swing.SwingUtilities2;/** * The class that manages a synth title bar * * @version 1.27 11/30/05 * @author David Kloba * @author Joshua Outwater * @author Steve Wilson */class SynthInternalFrameTitlePane extends BasicInternalFrameTitlePane implements SynthUI, PropertyChangeListener { protected JPopupMenu systemPopupMenu; protected JButton menuButton; private SynthStyle style; private int titleSpacing; private int buttonSpacing; // Alignment for the title, one of SwingConstants.(LEADING|TRAILING|CENTER) private int titleAlignment; public SynthInternalFrameTitlePane(JInternalFrame f) { super(f); } public String getUIClassID() { return "InternalFrameTitlePaneUI"; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } public 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); } private int getComponentState(JComponent c) { if (frame != null) { if (frame.isSelected()) { return SELECTED; } } return SynthLookAndFeel.getComponentState(c); } protected void addSubComponents() { menuButton.setName("InternalFrameTitlePane.menuButton"); iconButton.setName("InternalFrameTitlePane.iconifyButton"); maxButton.setName("InternalFrameTitlePane.maximizeButton"); closeButton.setName("InternalFrameTitlePane.closeButton"); add(menuButton); add(iconButton); add(maxButton); add(closeButton); } protected void installListeners() { super.installListeners(); frame.addPropertyChangeListener(this); addPropertyChangeListener(this); } protected void uninstallListeners() { frame.removePropertyChangeListener(this); removePropertyChangeListener(this); super.uninstallListeners(); } private void updateStyle(JComponent c) { SynthContext context = getContext(this, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { maxIcon = style.getIcon(context,"InternalFrameTitlePane.maximizeIcon"); minIcon = style.getIcon(context,"InternalFrameTitlePane.minimizeIcon"); iconIcon = style.getIcon(context,"InternalFrameTitlePane.iconifyIcon"); closeIcon = style.getIcon(context,"InternalFrameTitlePane.closeIcon"); titleSpacing = style.getInt(context, "InternalFrameTitlePane.titleSpacing", 2); buttonSpacing = style.getInt(context, "InternalFrameTitlePane.buttonSpacing", 2); String alignString = (String)style.get(context, "InternalFrameTitlePane.titleAlignment"); titleAlignment = SwingConstants.LEADING; if (alignString != null) { alignString = alignString.toUpperCase(); if (alignString.equals("TRAILING")) { titleAlignment = SwingConstants.TRAILING; } else if (alignString.equals("CENTER")) { titleAlignment = SwingConstants.CENTER; } } } context.dispose(); } protected void installDefaults() { super.installDefaults(); updateStyle(this); } protected void uninstallDefaults() { SynthContext context = getContext(this, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; JInternalFrame.JDesktopIcon di = frame.getDesktopIcon(); if(di != null && di.getComponentPopupMenu() == systemPopupMenu) { // Release link to systemMenu from the JInternalFrame di.setComponentPopupMenu(null); } super.uninstallDefaults(); } private static class JPopupMenuUIResource extends JPopupMenu implements UIResource { } protected void assembleSystemMenu() { systemPopupMenu = new JPopupMenuUIResource(); addSystemMenuItems(systemPopupMenu); enableActions(); menuButton = createNoFocusButton(); updateMenuIcon(); menuButton.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { try { frame.setSelected(true); } catch(PropertyVetoException pve) { } showSystemMenu(); } }); JPopupMenu p = frame.getComponentPopupMenu(); if (p == null || p instanceof UIResource) { frame.setComponentPopupMenu(systemPopupMenu); } if (frame.getDesktopIcon() != null) { p = frame.getDesktopIcon().getComponentPopupMenu(); if (p == null || p instanceof UIResource) { frame.getDesktopIcon().setComponentPopupMenu(systemPopupMenu); } } setInheritsPopupMenu(true); } protected void addSystemMenuItems(JPopupMenu menu) { // PENDING: this should all be localizable! JMenuItem mi = (JMenuItem)menu.add(restoreAction); mi.setMnemonic('R'); mi = (JMenuItem)menu.add(moveAction); mi.setMnemonic('M'); mi = (JMenuItem)menu.add(sizeAction); mi.setMnemonic('S'); mi = (JMenuItem)menu.add(iconifyAction); mi.setMnemonic('n'); mi = (JMenuItem)menu.add(maximizeAction); mi.setMnemonic('x'); menu.add(new JSeparator()); mi = (JMenuItem)menu.add(closeAction); mi.setMnemonic('C'); } protected void showSystemMenu() { Insets insets = frame.getInsets(); if (!frame.isIcon()) { systemPopupMenu.show(frame, insets.left, getY() + getHeight()); } else { systemPopupMenu.show(menuButton, getX() - insets.left - insets.right, getY() - systemPopupMenu.getPreferredSize().height - insets.bottom - insets.top); } } // SynthInternalFrameTitlePane has no UI, we'll invoke paint on it. public void paintComponent(Graphics g) { SynthContext context = getContext(this); SynthLookAndFeel.update(context, g); context.getPainter().paintInternalFrameTitlePaneBackground(context, g, 0, 0, getWidth(), getHeight()); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { String title = frame.getTitle(); if (title != null) { SynthStyle style = context.getStyle(); g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); g.setFont(style.getFont(context)); // Center text vertically. FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g); int baseline = (getHeight() + fm.getAscent() - fm.getLeading() - fm.getDescent()) / 2; JButton lastButton = null; if (frame.isIconifiable()) { lastButton = iconButton; } else if (frame.isMaximizable()) { lastButton = maxButton; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -