synthinternalframetitlepane.java
来自「java jdk 1.4的源码」· Java 代码 · 共 672 行 · 第 1/2 页
JAVA
672 行
} catch (SecurityException se) { // Use dispatchEvent instead. } } frame.dispatchEvent(e); } protected void enableActions() { restoreAction.setEnabled(frame.isMaximum() || frame.isIcon()); maximizeAction.setEnabled(frame.isMaximizable() && !frame.isMaximum()); iconifyAction.setEnabled(frame.isIconifiable() && !frame.isIcon()); closeAction.setEnabled(frame.isClosable()); sizeAction.setEnabled(false); moveAction.setEnabled(false); } protected PropertyChangeListener createPropertyChangeListener() { return new PropertyChangeHandler(); } protected LayoutManager createLayout() { SynthContext context = getContext(this); LayoutManager lm = (LayoutManager)style.get(context, "InternalFrameTitlePane.titlePaneLayout"); context.dispose(); return (lm != null) ? lm : new TitlePaneLayout(); } /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of <Foo>. */ class PropertyChangeHandler implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent evt) { String prop = (String)evt.getPropertyName(); if (SynthLookAndFeel.shouldUpdateStyle(evt)) { fetchStyle(SynthInternalFrameTitlePane.this); } if (JInternalFrame.IS_SELECTED_PROPERTY.equals(prop)) { repaint(); return; } if (JInternalFrame.IS_ICON_PROPERTY.equals(prop) || JInternalFrame.IS_MAXIMUM_PROPERTY.equals(prop)) { setButtonIcons(); enableActions(); return; } if (prop.equals("closable")) { if ((Boolean)evt.getNewValue() == Boolean.TRUE) { add(closeButton); } else { remove(closeButton); } } else if (prop.equals("maximizable")) { if ((Boolean)evt.getNewValue() == Boolean.TRUE) { add(maximizeButton); } else { remove(maximizeButton); } } else if (prop.equals("iconable")) { if ((Boolean)evt.getNewValue() == Boolean.TRUE) { add(minimizeButton); } else { remove(minimizeButton); } } enableActions(); revalidate(); repaint(); } } // end PropertyHandler class /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of <Foo>. */ class TitlePaneLayout implements LayoutManager { 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) { // Calculate width. int width = 22; if (frame.isClosable()) { width += 19; } if (frame.isMaximizable()) { width += 19; } if (frame.isIconifiable()) { width += 19; } FontMetrics fm = getFontMetrics(getFont()); String frameTitle = frame.getTitle(); int title_w = frameTitle != null ? fm.stringWidth(frameTitle) : 0; int title_length = frameTitle != null ? frameTitle.length() : 0; // Leave room for three characters in the title. if (title_length > 3) { int subtitle_w = fm.stringWidth(frameTitle.substring(0, 3) + "..."); width += (title_w < subtitle_w) ? title_w : subtitle_w; } else { width += title_w; } // Calculate height. Icon icon = frame.getFrameIcon(); int fontHeight = fm.getHeight(); fontHeight += 2; int iconHeight = 0; if (icon != null) { // SystemMenuBar forces the icon to be 16x16 or less. iconHeight = Math.min(icon.getIconHeight(), 16); } iconHeight += 2; int height = Math.max( fontHeight, iconHeight ); Dimension dim = new Dimension(width, height); // Take into account the border insets if any. if (getBorder() != null) { Insets insets = getBorder().getBorderInsets(c); dim.height += insets.top + insets.bottom; dim.width += insets.left + insets.right; } return dim; } public void layoutContainer(Container c) { boolean leftToRight = SynthLookAndFeel.isLeftToRight(frame); int w = getWidth(); int h = getHeight(); int x; Icon closeIcon = closeButton.getIcon(); int buttonHeight = (closeIcon != null) ? closeIcon.getIconHeight(): 12; if (buttonHeight == 0) { buttonHeight = 12; } //int buttonWidth = closeButton.getIcon().getIconWidth(); Icon icon = frame.getFrameIcon(); int iconHeight = (icon != null) ? icon.getIconHeight() : buttonHeight; Insets insets = frame.getInsets(); x = (leftToRight) ? insets.left : w - 16 - insets.right; menuButton.setBounds(x, (h - iconHeight) / 2, 16, 14); x = (leftToRight) ? w - 16 - insets.right : insets.left; if (frame.isClosable()) { closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14); x += (leftToRight) ? -(16 + 2) : 16 + 2; } if (frame.isMaximizable()) { maximizeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14); x += (leftToRight) ? -(16 + 2) : 16 + 2; } if (frame.isIconifiable()) { minimizeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14); } } } // end TitlePaneLayout /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of <Foo>. */ class CloseAction extends AbstractAction { public CloseAction() { super(CLOSE_CMD); } public void actionPerformed(ActionEvent e) { if(frame.isClosable()) { frame.doDefaultCloseAction(); } } } // end CloseAction /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of <Foo>. */ class MaximizeAction extends AbstractAction { public MaximizeAction() { super(MAXIMIZE_CMD); } public void actionPerformed(ActionEvent e) { if (frame.isMaximizable()) { if (!frame.isMaximum()) { try { frame.setMaximum(true); } catch (PropertyVetoException e5) { } } else { try { frame.setMaximum(false); } catch (PropertyVetoException e6) { } } } } } // MaximizeAction /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of <Foo>. */ class IconifyAction extends AbstractAction { public IconifyAction() { super(ICONIFY_CMD); } public void actionPerformed(ActionEvent e) { if (frame.isIconifiable()) { if (!frame.isIcon()) { try { frame.setIcon(true); } catch (PropertyVetoException e1) { } } else{ try { frame.setIcon(false); } catch (PropertyVetoException e1) { } } } } } // end IconifyAction /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of <Foo>. */ class RestoreAction extends AbstractAction { public RestoreAction() { super(RESTORE_CMD); } public void actionPerformed(ActionEvent e) { if (frame.isMaximizable() && frame.isMaximum()) { try { frame.setMaximum(false); } catch (PropertyVetoException e4) { } } else if (frame.isIconifiable() && frame.isIcon()) { try { frame.setIcon(false); } catch (PropertyVetoException e4) { } } } } // end RestoreAction /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of <Foo>. */ class MoveAction extends AbstractAction { public MoveAction() { super(MOVE_CMD); } public void actionPerformed(ActionEvent e) { // This action is currently undefined } } // end MoveAction /* * Handles showing and hiding the system menu. */ private class ShowSystemMenuAction extends AbstractAction { private boolean show; // whether to show the menu public ShowSystemMenuAction(boolean show) { this.show = show; } public void actionPerformed(ActionEvent e) { if (show) { // TODO: FIX THIS!!! } else { systemPopupMenu.setVisible(false); } } } /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of <Foo>. */ class SizeAction extends AbstractAction { public SizeAction() { super(SIZE_CMD); } public void actionPerformed(ActionEvent e) { // This action is currently undefined } } // end SizeAction private JButton createNoFocusButton() { JButton button = new JButton(); button.setFocusable(false); button.setMargin(new Insets(0,0,0,0)); return button; }} // End Title Pane Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?