📄 basicinternalframetitlepane.java
字号:
} } 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() { return 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>. */ public class PropertyChangeHandler implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent evt) { String prop = (String)evt.getPropertyName(); 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(maxButton); else remove(maxButton); } else if( prop.equals("iconable") ) { if( (Boolean)evt.getNewValue() == Boolean.TRUE ) add(iconButton); else remove(iconButton); } 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>. */ public 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 = BasicGraphicsUtils.isLeftToRight(frame); int w = getWidth(); int h = getHeight(); int x; int buttonHeight = closeButton.getIcon().getIconHeight(); //int buttonWidth = closeButton.getIcon().getIconWidth(); Icon icon = frame.getFrameIcon(); int iconHeight = 0; if (icon != null) { iconHeight = icon.getIconHeight(); } x = (leftToRight) ? 2 : w - 16 - 2; menuBar.setBounds(x, (h - iconHeight) / 2, 16, 16); x = (leftToRight) ? w - 16 - 2 : 2; if (frame.isClosable()) { closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14); x += (leftToRight) ? -(16 + 2) : 16 + 2; } if(frame.isMaximizable()) { maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14); x += (leftToRight) ? -(16 + 2) : 16 + 2; } if(frame.isIconifiable()) { iconButton.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>. */ public 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>. */ public 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>. */ public 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>. */ public 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>. */ public 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) { windowMenu.doClick(); } else { windowMenu.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>. */ public class SizeAction extends AbstractAction { public SizeAction() { super(SIZE_CMD); } public void actionPerformed(ActionEvent e) { // This action is currently undefined } } // end SizeAction /** * 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>. */ public class SystemMenuBar extends JMenuBar { public boolean isFocusTraversable() { return false; } public void requestFocus() {} public void paint(Graphics g) { Icon icon = frame.getFrameIcon(); if (icon == null) { icon = UIManager.getIcon("InternalFrame.icon"); } if (icon != null) { // Resize to 16x16 if necessary. if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) { Image img = ((ImageIcon)icon).getImage(); ((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH)); } icon.paintIcon(this, g, 0, 0); } } public boolean isOpaque() { return true; } } // end SystemMenuBar private class NoFocusButton extends JButton { public NoFocusButton() { setFocusPainted(false); setMargin(new Insets(0,0,0,0)); setOpaque(true); } public boolean isFocusTraversable() { return false; } public void requestFocus() {}; }; // end NoFocusButton} // End Title Pane Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -