⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicinternalframetitlepane.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* BasicInternalFrameTitlePane.java --   Copyright (C) 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.plaf.basic;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Insets;import java.awt.LayoutManager;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.KeyEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyVetoException;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.Icon;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JInternalFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.SwingConstants;import javax.swing.SwingUtilities;import javax.swing.UIManager;/** * This class acts as a titlebar for JInternalFrames. */public class BasicInternalFrameTitlePane extends JComponent{  /**   * The Action responsible for closing the JInternalFrame.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class CloseAction extends AbstractAction  {    /**     * Creates a new action.     */    public CloseAction()    {      super("Close");    }        /**     * This method is called when something closes the JInternalFrame.     *     * @param e The ActionEvent.     */    public void actionPerformed(ActionEvent e)    {      if (frame.isClosable())        {          try            {              frame.setClosed(true);            }          catch (PropertyVetoException pve)            {              // We do nothing if the attempt has been vetoed.            }        }    }  }  /**   * This Action is responsible for iconifying the JInternalFrame.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class IconifyAction extends AbstractAction  {    /**     * Creates a new action.     */    public IconifyAction()    {      super("Minimize");    }    /**     * This method is called when the user wants to iconify the     * JInternalFrame.     *     * @param e The ActionEvent.     */    public void actionPerformed(ActionEvent e)    {      if (frame.isIconifiable() && ! frame.isIcon())        {          try            {              frame.setIcon(true);            }          catch (PropertyVetoException pve)            {              // We do nothing if the attempt has been vetoed.            }        }    }  }  /**   * This Action is responsible for maximizing the JInternalFrame.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class MaximizeAction extends AbstractAction  {    /**     * Creates a new action.     */    public MaximizeAction()    {      super("Maximize");    }    /**     * This method is called when the user wants to maximize the     * JInternalFrame.     *     * @param e The ActionEvent.     */    public void actionPerformed(ActionEvent e)    {      try        {          if (frame.isMaximizable() && ! frame.isMaximum())            frame.setMaximum(true);          else if (frame.isMaximum())            frame.setMaximum(false);        }      catch (PropertyVetoException pve)        {          // We do nothing if the attempt has been vetoed.        }    }  }  /**   * This Action is responsible for dragging the JInternalFrame.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class MoveAction extends AbstractAction  {    /**     * Creates a new action.     */    public MoveAction()    {      super("Move");    }    /**     * This method is called when the user wants to drag the JInternalFrame.     *     * @param e The ActionEvent.     */    public void actionPerformed(ActionEvent e)    {      // FIXME: Implement keyboard driven? move actions.    }  }  /**   * This Action is responsible for restoring the JInternalFrame. Restoring   * the JInternalFrame is the same as setting the maximum property to false.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class RestoreAction extends AbstractAction  {    /**     * Creates a new action.     */    public RestoreAction()    {      super("Restore");    }    /**     * This method is called when the user wants to restore the     * JInternalFrame.     *     * @param e The ActionEvent.     */    public void actionPerformed(ActionEvent e)    {      if (frame.isMaximum())        {          try            {              frame.setMaximum(false);            }          catch (PropertyVetoException pve)            {              // We do nothing if the attempt has been vetoed.            }        }    }  }  /**   * This action is responsible for sizing the JInternalFrame.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class SizeAction extends AbstractAction  {    /**     * Creates a new action.     */    public SizeAction()    {      super("Size");    }    /**     * This method is called when the user wants to resize the JInternalFrame.     *     * @param e The ActionEvent.     */    public void actionPerformed(ActionEvent e)    {      // FIXME: Not sure how size actions should be handled.    }  }  /**   * This class is responsible for handling property change events from the   * JInternalFrame and adjusting the Title Pane as necessary.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class PropertyChangeHandler implements PropertyChangeListener  {    /**     * This method is called when a PropertyChangeEvent is received by the     * Title Pane.     *     * @param evt The PropertyChangeEvent.     */    public void propertyChange(PropertyChangeEvent evt)    {      String propName = evt.getPropertyName();      if (propName.equals("closable"))	{	  if (evt.getNewValue().equals(Boolean.TRUE))	    closeButton.setVisible(true);	  else	    closeButton.setVisible(false);	}      else if (propName.equals("iconifiable"))	{	  if (evt.getNewValue().equals(Boolean.TRUE))	    iconButton.setVisible(true);	  else	    iconButton.setVisible(false);	}      else if (propName.equals("maximizable"))	{	  if (evt.getNewValue().equals(Boolean.TRUE))	    maxButton.setVisible(true);	  else	    maxButton.setVisible(false);	}	    }  }  /**   * This class acts as the MenuBar for the TitlePane. Clicking on the Frame   * Icon in the top left corner will activate it.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class SystemMenuBar extends JMenuBar  {    /**     * This method returns true if it can receive focus.     *     * @return True if this Component can receive focus.     */    public boolean isFocusTransversable()    {      return true;    }    /**     * This method returns true if this Component is expected to paint all of     * itself.     *     * @return True if this Component is expect to paint all of itself.     */    public boolean isOpaque()    {      return true;    }    /**     * This method paints this Component.     *     * @param g The Graphics object to paint with.     */    public void paint(Graphics g)    {      Icon frameIcon = frame.getFrameIcon();      if (frameIcon == null)	frameIcon = BasicDesktopIconUI.defaultIcon;      frameIcon.paintIcon(this, g, 0, 0);    }    /**     * This method requests that focus be given to this Component.     */    public void requestFocus()    {      super.requestFocus();    }  }  /**   * This class acts as the Layout Manager for the TitlePane.   *   * @specnote Apparently this class was intended to be protected,   *           but was made public by a compiler bug and is now   *           public for compatibility.   */  public class TitlePaneLayout implements LayoutManager  {    /**     * Creates a new <code>TitlePaneLayout</code> object.     */    public TitlePaneLayout()    {      // Do nothing.    }    /**     * This method is called when adding a Component to the Container.     *     * @param name The name to reference the added Component by.     * @param c The Component to add.     */    public void addLayoutComponent(String name, Component c)    {      // Do nothing.    }    /**     * This method is called to lay out the children of the Title Pane.     *     * @param c The Container to lay out.     */    public void layoutContainer(Container c)    {      Dimension size = c.getSize();      Insets insets = c.getInsets();      int width = size.width - insets.left - insets.right;      int height = size.height - insets.top - insets.bottom;      // MenuBar is always present and located at the top left corner.      Dimension menupref = menuBar.getPreferredSize();      menuBar.setBounds(insets.left, insets.top, menupref.width, height);      int loc = width + insets.left - 1;      int top = insets.top + 1;      int buttonHeight = height - 4;      if (closeButton.isVisible())        {          int buttonWidth = closeIcon.getIconWidth();          loc -= buttonWidth + 2;          closeButton.setBounds(loc, top, buttonWidth, buttonHeight);        }      if (maxButton.isVisible())        {          int buttonWidth = maxIcon.getIconWidth();          loc -= buttonWidth + 2;          maxButton.setBounds(loc, top, buttonWidth, buttonHeight);        }      if (iconButton.isVisible())        {          int buttonWidth = iconIcon.getIconWidth();          loc -= buttonWidth + 2;          iconButton.setBounds(loc, top, buttonWidth, buttonHeight);        }      if (title != null)	title.setBounds(insets.left + menupref.width, insets.top,	                loc - menupref.width - insets.left, height);    }    /**     * This method returns the minimum size of the given Container given the     * children that it has.     *     * @param c The Container to get a minimum size for.     *     * @return The minimum size of the Container.     */    public Dimension minimumLayoutSize(Container c)    {      return preferredLayoutSize(c);    }    /**     * This method returns the preferred size of the given Container taking     * into account the children that it has.     *     * @param c The Container to lay out.     *     * @return The preferred size of the Container.     */    public Dimension preferredLayoutSize(Container c)    {      return new Dimension(22, 18);    }    /**     * This method is called when removing a Component from the Container.     *     * @param c The Component to remove.     */    public void removeLayoutComponent(Component c)    {      // Nothing to do here.    }  }  /**   * This helper class is used to create the minimize, maximize and close   * buttons in the top right corner of the Title Pane. These buttons are   * special since they cannot be given focus and have no border.   */  private class PaneButton extends JButton  {    /**     * Creates a new PaneButton object with the given Action.     *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -