FileDocCategorySizeDatePackage
BasicInternalFrameTitlePane.javaAPI DocJava SE 5 API24958Fri Aug 26 14:58:04 BST 2005javax.swing.plaf.basic

BasicInternalFrameTitlePane

public class BasicInternalFrameTitlePane extends JComponent
The class that manages a basic title bar

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

version
1.41 01/18/01
author
David Kloba
author
Steve Wilson

Fields Summary
protected JMenuBar
menuBar
protected JButton
iconButton
protected JButton
maxButton
protected JButton
closeButton
protected JMenu
windowMenu
protected JInternalFrame
frame
protected Color
selectedTitleColor
protected Color
selectedTextColor
protected Color
notSelectedTitleColor
protected Color
notSelectedTextColor
protected Icon
maxIcon
protected Icon
minIcon
protected Icon
iconIcon
protected Icon
closeIcon
protected PropertyChangeListener
propertyChangeListener
protected Action
closeAction
protected Action
maximizeAction
protected Action
iconifyAction
protected Action
restoreAction
protected Action
moveAction
protected Action
sizeAction
protected static final String
CLOSE_CMD
protected static final String
ICONIFY_CMD
protected static final String
RESTORE_CMD
protected static final String
MAXIMIZE_CMD
protected static final String
MOVE_CMD
protected static final String
SIZE_CMD
private String
closeButtonToolTip
private String
iconButtonToolTip
private String
restoreButtonToolTip
private String
maxButtonToolTip
private Handler
handler
Constructors Summary
public BasicInternalFrameTitlePane(JInternalFrame f)


       
	frame = f;
	installTitlePane();
    
Methods Summary
protected voidaddSubComponents()

	add(menuBar);
	add(iconButton);
	add(maxButton);
	add(closeButton);
    
protected voidaddSystemMenuItems(javax.swing.JMenu systemMenu)

        JMenuItem mi = (JMenuItem)systemMenu.add(restoreAction);
	mi.setMnemonic('R");
	mi = (JMenuItem)systemMenu.add(moveAction);
	mi.setMnemonic('M");
	mi = (JMenuItem)systemMenu.add(sizeAction);
	mi.setMnemonic('S");
	mi = (JMenuItem)systemMenu.add(iconifyAction);
	mi.setMnemonic('n");
	mi = (JMenuItem)systemMenu.add(maximizeAction);
	mi.setMnemonic('x");
	systemMenu.add(new JSeparator());
	mi = (JMenuItem)systemMenu.add(closeAction);
	mi.setMnemonic('C");
    
protected voidassembleSystemMenu()

        menuBar = createSystemMenuBar();
	windowMenu = createSystemMenu();	    
	menuBar.add(windowMenu);
	addSystemMenuItems(windowMenu);
	enableActions();
    
javax.swing.ActionMapcreateActionMap()

	ActionMap map = new ActionMapUIResource();
	map.put("showSystemMenu", new ShowSystemMenuAction(true));
	map.put("hideSystemMenu", new ShowSystemMenuAction(false));
	return map;
    
protected voidcreateActions()

	maximizeAction = new MaximizeAction();
	iconifyAction = new IconifyAction();
	closeAction = new CloseAction();
	restoreAction = new RestoreAction();
	moveAction = new MoveAction();
	sizeAction = new SizeAction();
    
protected voidcreateButtons()

	iconButton = new NoFocusButton(
                     "InternalFrameTitlePane.iconifyButtonAccessibleName");
	iconButton.addActionListener(iconifyAction);
        if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
            iconButton.setToolTipText(iconButtonToolTip);
        }

	maxButton = new NoFocusButton(
                        "InternalFrameTitlePane.maximizeButtonAccessibleName");
	maxButton.addActionListener(maximizeAction);

	closeButton = new NoFocusButton(
                      "InternalFrameTitlePane.closeButtonAccessibleName");
	closeButton.addActionListener(closeAction);
        if (closeButtonToolTip != null && closeButtonToolTip.length() != 0) {
            closeButton.setToolTipText(closeButtonToolTip);
        }

        setButtonIcons();
    
protected java.awt.LayoutManagercreateLayout()

        return getHandler();
    
protected java.beans.PropertyChangeListenercreatePropertyChangeListener()

        return getHandler();
    
protected javax.swing.JMenucreateSystemMenu()

	return new JMenu("    ");
    
protected javax.swing.JMenuBarcreateSystemMenuBar()

	menuBar = new SystemMenuBar();
	menuBar.setBorderPainted(false);
	return menuBar;
    
protected voidenableActions()

        restoreAction.setEnabled(frame.isMaximum() || frame.isIcon()); 
        maximizeAction.setEnabled(
            (frame.isMaximizable() && !frame.isMaximum() && !frame.isIcon()) ||
            (frame.isMaximizable() && frame.isIcon()));
        iconifyAction.setEnabled(frame.isIconifiable() && !frame.isIcon()); 
        closeAction.setEnabled(frame.isClosable());
        sizeAction.setEnabled(false);
        moveAction.setEnabled(false);
    
private javax.swing.plaf.basic.BasicInternalFrameTitlePane$HandlergetHandler()

        if (handler == null) {
            handler = new Handler();
        }
        return handler;
    
protected java.lang.StringgetTitle(java.lang.String text, java.awt.FontMetrics fm, int availTextWidth)

        return SwingUtilities2.clipStringIfNecessary(
                           frame, fm, text, availTextWidth);
      
protected voidinstallDefaults()

        maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon");
	minIcon = UIManager.getIcon("InternalFrame.minimizeIcon");
	iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon");
	closeIcon = UIManager.getIcon("InternalFrame.closeIcon");

	selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
	selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
	notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
	notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
        setFont(UIManager.getFont("InternalFrame.titleFont"));
        closeButtonToolTip =
                UIManager.getString("InternalFrame.closeButtonToolTip");
        iconButtonToolTip =
                UIManager.getString("InternalFrame.iconButtonToolTip");
        restoreButtonToolTip =
                UIManager.getString("InternalFrame.restoreButtonToolTip");
        maxButtonToolTip =
                UIManager.getString("InternalFrame.maxButtonToolTip");
    
protected voidinstallListeners()

        if( propertyChangeListener == null ) {
            propertyChangeListener = createPropertyChangeListener();
        }
	frame.addPropertyChangeListener(propertyChangeListener);
    
protected voidinstallTitlePane()

	installDefaults();
        installListeners();
        
	createActions();
	enableActions();
	createActionMap();

	setLayout(createLayout());

	assembleSystemMenu();
	createButtons();
	addSubComponents();

    
public voidpaintComponent(java.awt.Graphics g)

	paintTitleBackground(g);

	if(frame.getTitle() != null) {
	    boolean isSelected = frame.isSelected();
	    Font f = g.getFont();
	    g.setFont(getFont());
	    if(isSelected)
		g.setColor(selectedTextColor);
	    else
		g.setColor(notSelectedTextColor);

            // Center text vertically.
	    FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
            int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
                    fm.getDescent()) / 2;

            int titleX;
            Rectangle r = new Rectangle(0, 0, 0, 0);
            if (frame.isIconifiable())  r = iconButton.getBounds();
            else if (frame.isMaximizable())  r = maxButton.getBounds();
            else if (frame.isClosable())  r = closeButton.getBounds();
	    int titleW;
	
            String title = frame.getTitle();
            if( BasicGraphicsUtils.isLeftToRight(frame) ) {
              if (r.x == 0)  r.x = frame.getWidth()-frame.getInsets().right;
              titleX = menuBar.getX() + menuBar.getWidth() + 2;
              titleW = r.x - titleX - 3;
              title = getTitle(frame.getTitle(), fm, titleW);
            } else {
                titleX = menuBar.getX() - 2
                         - SwingUtilities2.stringWidth(frame,fm,title);
            }
            
	    SwingUtilities2.drawString(frame, g, title, titleX, baseline);
	    g.setFont(f);
	}
    
protected voidpaintTitleBackground(java.awt.Graphics g)
Invoked from paintComponent. Paints the background of the titlepane. All text and icons will then be rendered on top of this background.

param
g the graphics to use to render the background
since
1.4

	boolean isSelected = frame.isSelected();

	if(isSelected)
	    g.setColor(selectedTitleColor);
	else
	    g.setColor(notSelectedTitleColor);
	g.fillRect(0, 0, getWidth(), getHeight());
    
protected voidpostClosingEvent(javax.swing.JInternalFrame frame)
Post a WINDOW_CLOSING-like event to the frame, so that it can be treated like a regular Frame.

        InternalFrameEvent e = new InternalFrameEvent(
            frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
        // Try posting event, unless there's a SecurityManager.
        if (JInternalFrame.class.getClassLoader() == null) {
            try {
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
                return;
            } catch (SecurityException se) {
                // Use dispatchEvent instead.
            }
        }
        frame.dispatchEvent(e);
    
protected voidsetButtonIcons()

        if(frame.isIcon()) {
            if (minIcon != null) {
                iconButton.setIcon(minIcon);
            }
            if (restoreButtonToolTip != null &&
                    restoreButtonToolTip.length() != 0) {
                iconButton.setToolTipText(restoreButtonToolTip);
            }
            if (maxIcon != null) {
                maxButton.setIcon(maxIcon);
            }
            if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
                maxButton.setToolTipText(maxButtonToolTip);
            }
        } else if (frame.isMaximum()) {
            if (iconIcon != null) {
	        iconButton.setIcon(iconIcon);
            }
            if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
                iconButton.setToolTipText(iconButtonToolTip);
            }
            if (minIcon != null) {
	        maxButton.setIcon(minIcon);
            }
            if (restoreButtonToolTip != null &&
                    restoreButtonToolTip.length() != 0) {
                maxButton.setToolTipText(restoreButtonToolTip);
            }
        } else {
            if (iconIcon != null) {
	        iconButton.setIcon(iconIcon);
            }
            if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
                iconButton.setToolTipText(iconButtonToolTip);
            }
            if (maxIcon != null) {
	        maxButton.setIcon(maxIcon);
            }
            if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
                maxButton.setToolTipText(maxButtonToolTip);
            }
        }
        if (closeIcon != null) {
	    closeButton.setIcon(closeIcon);
        }
    
protected voidshowSystemMenu()

	//      windowMenu.setPopupMenuVisible(true);
      //      windowMenu.setVisible(true);
      windowMenu.doClick();
    
protected voiduninstallDefaults()

    
protected voiduninstallListeners()

	frame.removePropertyChangeListener(propertyChangeListener);
        handler = null;