Save This Page
Home » openjdk-7 » javax » swing » plaf » basic » [javadoc | source]
    1   /*
    2    * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   package javax.swing.plaf.basic;
   27   
   28   import sun.swing.SwingUtilities2;
   29   import java.awt;
   30   import java.awt.event;
   31   import javax.accessibility.AccessibleContext;
   32   import javax.swing;
   33   import javax.swing.plaf;
   34   import javax.swing.border;
   35   import javax.swing.event.InternalFrameEvent;
   36   import java.util.EventListener;
   37   import java.beans.PropertyChangeListener;
   38   import java.beans.PropertyChangeEvent;
   39   import java.beans.VetoableChangeListener;
   40   import java.beans.PropertyVetoException;
   41   
   42   import sun.swing.DefaultLookup;
   43   import sun.swing.UIAction;
   44   
   45   /**
   46    * The class that manages a basic title bar
   47    * <p>
   48    * <strong>Warning:</strong>
   49    * Serialized objects of this class will not be compatible with
   50    * future Swing releases. The current serialization support is
   51    * appropriate for short term storage or RMI between applications running
   52    * the same version of Swing.  As of 1.4, support for long term storage
   53    * of all JavaBeans<sup><font size="-2">TM</font></sup>
   54    * has been added to the <code>java.beans</code> package.
   55    * Please see {@link java.beans.XMLEncoder}.
   56    *
   57    * @author David Kloba
   58    * @author Steve Wilson
   59    */
   60   public class BasicInternalFrameTitlePane extends JComponent
   61   {
   62       protected JMenuBar menuBar;
   63       protected JButton iconButton;
   64       protected JButton maxButton;
   65       protected JButton closeButton;
   66   
   67       protected JMenu windowMenu;
   68       protected JInternalFrame frame;
   69   
   70       protected Color selectedTitleColor;
   71       protected Color selectedTextColor;
   72       protected Color notSelectedTitleColor;
   73       protected Color notSelectedTextColor;
   74   
   75       protected Icon maxIcon;
   76       protected Icon minIcon;
   77       protected Icon iconIcon;
   78       protected Icon closeIcon;
   79   
   80       protected PropertyChangeListener propertyChangeListener;
   81   
   82       protected Action closeAction;
   83       protected Action maximizeAction;
   84       protected Action iconifyAction;
   85       protected Action restoreAction;
   86       protected Action moveAction;
   87       protected Action sizeAction;
   88   
   89       protected static final String CLOSE_CMD =
   90           UIManager.getString("InternalFrameTitlePane.closeButtonText");
   91       protected static final String ICONIFY_CMD =
   92           UIManager.getString("InternalFrameTitlePane.minimizeButtonText");
   93       protected static final String RESTORE_CMD =
   94           UIManager.getString("InternalFrameTitlePane.restoreButtonText");
   95       protected static final String MAXIMIZE_CMD =
   96           UIManager.getString("InternalFrameTitlePane.maximizeButtonText");
   97       protected static final String MOVE_CMD =
   98           UIManager.getString("InternalFrameTitlePane.moveButtonText");
   99       protected static final String SIZE_CMD =
  100           UIManager.getString("InternalFrameTitlePane.sizeButtonText");
  101   
  102       private String closeButtonToolTip;
  103       private String iconButtonToolTip;
  104       private String restoreButtonToolTip;
  105       private String maxButtonToolTip;
  106       private Handler handler;
  107   
  108       public BasicInternalFrameTitlePane(JInternalFrame f) {
  109           frame = f;
  110           installTitlePane();
  111       }
  112   
  113       protected void installTitlePane() {
  114           installDefaults();
  115           installListeners();
  116   
  117           createActions();
  118           enableActions();
  119           createActionMap();
  120   
  121           setLayout(createLayout());
  122   
  123           assembleSystemMenu();
  124           createButtons();
  125           addSubComponents();
  126   
  127       }
  128   
  129       protected void addSubComponents() {
  130           add(menuBar);
  131           add(iconButton);
  132           add(maxButton);
  133           add(closeButton);
  134       }
  135   
  136       protected void createActions() {
  137           maximizeAction = new MaximizeAction();
  138           iconifyAction = new IconifyAction();
  139           closeAction = new CloseAction();
  140           restoreAction = new RestoreAction();
  141           moveAction = new MoveAction();
  142           sizeAction = new SizeAction();
  143       }
  144   
  145       ActionMap createActionMap() {
  146           ActionMap map = new ActionMapUIResource();
  147           map.put("showSystemMenu", new ShowSystemMenuAction(true));
  148           map.put("hideSystemMenu", new ShowSystemMenuAction(false));
  149           return map;
  150       }
  151   
  152       protected void installListeners() {
  153           if( propertyChangeListener == null ) {
  154               propertyChangeListener = createPropertyChangeListener();
  155           }
  156           frame.addPropertyChangeListener(propertyChangeListener);
  157       }
  158   
  159       protected void uninstallListeners() {
  160           frame.removePropertyChangeListener(propertyChangeListener);
  161           handler = null;
  162       }
  163   
  164       protected void installDefaults() {
  165           maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon");
  166           minIcon = UIManager.getIcon("InternalFrame.minimizeIcon");
  167           iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon");
  168           closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
  169   
  170           selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
  171           selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
  172           notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
  173           notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
  174           setFont(UIManager.getFont("InternalFrame.titleFont"));
  175           closeButtonToolTip =
  176                   UIManager.getString("InternalFrame.closeButtonToolTip");
  177           iconButtonToolTip =
  178                   UIManager.getString("InternalFrame.iconButtonToolTip");
  179           restoreButtonToolTip =
  180                   UIManager.getString("InternalFrame.restoreButtonToolTip");
  181           maxButtonToolTip =
  182                   UIManager.getString("InternalFrame.maxButtonToolTip");
  183       }
  184   
  185   
  186       protected void uninstallDefaults() {
  187       }
  188   
  189       protected void createButtons() {
  190           iconButton = new NoFocusButton(
  191                        "InternalFrameTitlePane.iconifyButtonAccessibleName",
  192                        "InternalFrameTitlePane.iconifyButtonOpacity");
  193           iconButton.addActionListener(iconifyAction);
  194           if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
  195               iconButton.setToolTipText(iconButtonToolTip);
  196           }
  197   
  198           maxButton = new NoFocusButton(
  199                           "InternalFrameTitlePane.maximizeButtonAccessibleName",
  200                           "InternalFrameTitlePane.maximizeButtonOpacity");
  201           maxButton.addActionListener(maximizeAction);
  202   
  203           closeButton = new NoFocusButton(
  204                         "InternalFrameTitlePane.closeButtonAccessibleName",
  205                         "InternalFrameTitlePane.closeButtonOpacity");
  206           closeButton.addActionListener(closeAction);
  207           if (closeButtonToolTip != null && closeButtonToolTip.length() != 0) {
  208               closeButton.setToolTipText(closeButtonToolTip);
  209           }
  210   
  211           setButtonIcons();
  212       }
  213   
  214       protected void setButtonIcons() {
  215           if(frame.isIcon()) {
  216               if (minIcon != null) {
  217                   iconButton.setIcon(minIcon);
  218               }
  219               if (restoreButtonToolTip != null &&
  220                       restoreButtonToolTip.length() != 0) {
  221                   iconButton.setToolTipText(restoreButtonToolTip);
  222               }
  223               if (maxIcon != null) {
  224                   maxButton.setIcon(maxIcon);
  225               }
  226               if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
  227                   maxButton.setToolTipText(maxButtonToolTip);
  228               }
  229           } else if (frame.isMaximum()) {
  230               if (iconIcon != null) {
  231                   iconButton.setIcon(iconIcon);
  232               }
  233               if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
  234                   iconButton.setToolTipText(iconButtonToolTip);
  235               }
  236               if (minIcon != null) {
  237                   maxButton.setIcon(minIcon);
  238               }
  239               if (restoreButtonToolTip != null &&
  240                       restoreButtonToolTip.length() != 0) {
  241                   maxButton.setToolTipText(restoreButtonToolTip);
  242               }
  243           } else {
  244               if (iconIcon != null) {
  245                   iconButton.setIcon(iconIcon);
  246               }
  247               if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
  248                   iconButton.setToolTipText(iconButtonToolTip);
  249               }
  250               if (maxIcon != null) {
  251                   maxButton.setIcon(maxIcon);
  252               }
  253               if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
  254                   maxButton.setToolTipText(maxButtonToolTip);
  255               }
  256           }
  257           if (closeIcon != null) {
  258               closeButton.setIcon(closeIcon);
  259           }
  260       }
  261   
  262       protected void assembleSystemMenu() {
  263           menuBar = createSystemMenuBar();
  264           windowMenu = createSystemMenu();
  265           menuBar.add(windowMenu);
  266           addSystemMenuItems(windowMenu);
  267           enableActions();
  268       }
  269   
  270       protected void addSystemMenuItems(JMenu systemMenu) {
  271           JMenuItem mi = (JMenuItem)systemMenu.add(restoreAction);
  272           mi.setMnemonic('R');
  273           mi = (JMenuItem)systemMenu.add(moveAction);
  274           mi.setMnemonic('M');
  275           mi = (JMenuItem)systemMenu.add(sizeAction);
  276           mi.setMnemonic('S');
  277           mi = (JMenuItem)systemMenu.add(iconifyAction);
  278           mi.setMnemonic('n');
  279           mi = (JMenuItem)systemMenu.add(maximizeAction);
  280           mi.setMnemonic('x');
  281           systemMenu.add(new JSeparator());
  282           mi = (JMenuItem)systemMenu.add(closeAction);
  283           mi.setMnemonic('C');
  284       }
  285   
  286       protected JMenu createSystemMenu() {
  287           return new JMenu("    ");
  288       }
  289   
  290       protected JMenuBar createSystemMenuBar() {
  291           menuBar = new SystemMenuBar();
  292           menuBar.setBorderPainted(false);
  293           return menuBar;
  294       }
  295   
  296       protected void showSystemMenu(){
  297           //      windowMenu.setPopupMenuVisible(true);
  298         //      windowMenu.setVisible(true);
  299         windowMenu.doClick();
  300       }
  301   
  302       public void paintComponent(Graphics g)  {
  303           paintTitleBackground(g);
  304   
  305           if(frame.getTitle() != null) {
  306               boolean isSelected = frame.isSelected();
  307               Font f = g.getFont();
  308               g.setFont(getFont());
  309               if(isSelected)
  310                   g.setColor(selectedTextColor);
  311               else
  312                   g.setColor(notSelectedTextColor);
  313   
  314               // Center text vertically.
  315               FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
  316               int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
  317                       fm.getDescent()) / 2;
  318   
  319               int titleX;
  320               Rectangle r = new Rectangle(0, 0, 0, 0);
  321               if (frame.isIconifiable())  r = iconButton.getBounds();
  322               else if (frame.isMaximizable())  r = maxButton.getBounds();
  323               else if (frame.isClosable())  r = closeButton.getBounds();
  324               int titleW;
  325   
  326               String title = frame.getTitle();
  327               if( BasicGraphicsUtils.isLeftToRight(frame) ) {
  328                 if (r.x == 0)  r.x = frame.getWidth()-frame.getInsets().right;
  329                 titleX = menuBar.getX() + menuBar.getWidth() + 2;
  330                 titleW = r.x - titleX - 3;
  331                 title = getTitle(frame.getTitle(), fm, titleW);
  332               } else {
  333                   titleX = menuBar.getX() - 2
  334                            - SwingUtilities2.stringWidth(frame,fm,title);
  335               }
  336   
  337               SwingUtilities2.drawString(frame, g, title, titleX, baseline);
  338               g.setFont(f);
  339           }
  340       }
  341   
  342      /**
  343       * Invoked from paintComponent.
  344       * Paints the background of the titlepane.  All text and icons will
  345       * then be rendered on top of this background.
  346       * @param g the graphics to use to render the background
  347       * @since 1.4
  348       */
  349       protected void paintTitleBackground(Graphics g) {
  350           boolean isSelected = frame.isSelected();
  351   
  352           if(isSelected)
  353               g.setColor(selectedTitleColor);
  354           else
  355               g.setColor(notSelectedTitleColor);
  356           g.fillRect(0, 0, getWidth(), getHeight());
  357       }
  358   
  359       protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
  360           return SwingUtilities2.clipStringIfNecessary(
  361                              frame, fm, text, availTextWidth);
  362         }
  363   
  364       /**
  365        * Post a WINDOW_CLOSING-like event to the frame, so that it can
  366        * be treated like a regular Frame.
  367        */
  368       protected void postClosingEvent(JInternalFrame frame) {
  369           InternalFrameEvent e = new InternalFrameEvent(
  370               frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
  371           // Try posting event, unless there's a SecurityManager.
  372           if (JInternalFrame.class.getClassLoader() == null) {
  373               try {
  374                   Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
  375                   return;
  376               } catch (SecurityException se) {
  377                   // Use dispatchEvent instead.
  378               }
  379           }
  380           frame.dispatchEvent(e);
  381       }
  382   
  383   
  384       protected void enableActions() {
  385           restoreAction.setEnabled(frame.isMaximum() || frame.isIcon());
  386           maximizeAction.setEnabled(
  387               (frame.isMaximizable() && !frame.isMaximum() && !frame.isIcon()) ||
  388               (frame.isMaximizable() && frame.isIcon()));
  389           iconifyAction.setEnabled(frame.isIconifiable() && !frame.isIcon());
  390           closeAction.setEnabled(frame.isClosable());
  391           sizeAction.setEnabled(false);
  392           moveAction.setEnabled(false);
  393       }
  394   
  395       private Handler getHandler() {
  396           if (handler == null) {
  397               handler = new Handler();
  398           }
  399           return handler;
  400       }
  401   
  402       protected PropertyChangeListener createPropertyChangeListener() {
  403           return getHandler();
  404       }
  405   
  406       protected LayoutManager createLayout() {
  407           return getHandler();
  408       }
  409   
  410   
  411       private class Handler implements LayoutManager, PropertyChangeListener {
  412           //
  413           // PropertyChangeListener
  414           //
  415           public void propertyChange(PropertyChangeEvent evt) {
  416               String prop = (String)evt.getPropertyName();
  417   
  418               if (prop == JInternalFrame.IS_SELECTED_PROPERTY) {
  419                   repaint();
  420                   return;
  421               }
  422   
  423               if (prop == JInternalFrame.IS_ICON_PROPERTY ||
  424                       prop == JInternalFrame.IS_MAXIMUM_PROPERTY) {
  425                   setButtonIcons();
  426                   enableActions();
  427                   return;
  428               }
  429   
  430               if ("closable" == prop) {
  431                   if ((Boolean)evt.getNewValue() == Boolean.TRUE) {
  432                       add(closeButton);
  433                   } else {
  434                       remove(closeButton);
  435                   }
  436               } else if ("maximizable" == prop) {
  437                   if ((Boolean)evt.getNewValue() == Boolean.TRUE) {
  438                       add(maxButton);
  439                   } else {
  440                       remove(maxButton);
  441                   }
  442               } else if ("iconable" == prop) {
  443                   if ((Boolean)evt.getNewValue() == Boolean.TRUE) {
  444                       add(iconButton);
  445                   } else {
  446                       remove(iconButton);
  447                   }
  448               }
  449               enableActions();
  450   
  451               revalidate();
  452               repaint();
  453           }
  454   
  455   
  456           //
  457           // LayoutManager
  458           //
  459           public void addLayoutComponent(String name, Component c) {}
  460           public void removeLayoutComponent(Component c) {}
  461           public Dimension preferredLayoutSize(Container c) {
  462               return minimumLayoutSize(c);
  463           }
  464   
  465           public Dimension minimumLayoutSize(Container c) {
  466               // Calculate width.
  467               int width = 22;
  468   
  469               if (frame.isClosable()) {
  470                   width += 19;
  471               }
  472               if (frame.isMaximizable()) {
  473                   width += 19;
  474               }
  475               if (frame.isIconifiable()) {
  476                   width += 19;
  477               }
  478   
  479               FontMetrics fm = frame.getFontMetrics(getFont());
  480               String frameTitle = frame.getTitle();
  481               int title_w = frameTitle != null ? SwingUtilities2.stringWidth(
  482                                  frame, fm, frameTitle) : 0;
  483               int title_length = frameTitle != null ? frameTitle.length() : 0;
  484   
  485               // Leave room for three characters in the title.
  486               if (title_length > 3) {
  487                   int subtitle_w = SwingUtilities2.stringWidth(
  488                       frame, fm, frameTitle.substring(0, 3) + "...");
  489                   width += (title_w < subtitle_w) ? title_w : subtitle_w;
  490               } else {
  491                   width += title_w;
  492               }
  493   
  494               // Calculate height.
  495               Icon icon = frame.getFrameIcon();
  496               int fontHeight = fm.getHeight();
  497               fontHeight += 2;
  498               int iconHeight = 0;
  499               if (icon != null) {
  500                   // SystemMenuBar forces the icon to be 16x16 or less.
  501                   iconHeight = Math.min(icon.getIconHeight(), 16);
  502               }
  503               iconHeight += 2;
  504   
  505               int height = Math.max( fontHeight, iconHeight );
  506   
  507               Dimension dim = new Dimension(width, height);
  508   
  509               // Take into account the border insets if any.
  510               if (getBorder() != null) {
  511                   Insets insets = getBorder().getBorderInsets(c);
  512                   dim.height += insets.top + insets.bottom;
  513                   dim.width += insets.left + insets.right;
  514               }
  515               return dim;
  516           }
  517   
  518           public void layoutContainer(Container c) {
  519               boolean leftToRight = BasicGraphicsUtils.isLeftToRight(frame);
  520   
  521               int w = getWidth();
  522               int h = getHeight();
  523               int x;
  524   
  525               int buttonHeight = closeButton.getIcon().getIconHeight();
  526   
  527               Icon icon = frame.getFrameIcon();
  528               int iconHeight = 0;
  529               if (icon != null) {
  530                   iconHeight = icon.getIconHeight();
  531               }
  532               x = (leftToRight) ? 2 : w - 16 - 2;
  533               menuBar.setBounds(x, (h - iconHeight) / 2, 16, 16);
  534   
  535               x = (leftToRight) ? w - 16 - 2 : 2;
  536   
  537               if (frame.isClosable()) {
  538                   closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
  539                   x += (leftToRight) ? -(16 + 2) : 16 + 2;
  540               }
  541   
  542               if (frame.isMaximizable()) {
  543                   maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
  544                   x += (leftToRight) ? -(16 + 2) : 16 + 2;
  545               }
  546   
  547               if (frame.isIconifiable()) {
  548                   iconButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
  549               }
  550           }
  551       }
  552   
  553       /**
  554        * This class should be treated as a &quot;protected&quot; inner class.
  555        * Instantiate it only within subclasses of <Foo>.
  556        */
  557       public class PropertyChangeHandler implements PropertyChangeListener {
  558           // NOTE: This class exists only for backward compatability. All
  559           // its functionality has been moved into Handler. If you need to add
  560           // new functionality add it to the Handler, but make sure this
  561           // class calls into the Handler.
  562           public void propertyChange(PropertyChangeEvent evt) {
  563               getHandler().propertyChange(evt);
  564           }
  565       }
  566   
  567       /**
  568        * This class should be treated as a &quot;protected&quot; inner class.
  569        * Instantiate it only within subclasses of <Foo>.
  570        */
  571       public class TitlePaneLayout implements LayoutManager {
  572           // NOTE: This class exists only for backward compatability. All
  573           // its functionality has been moved into Handler. If you need to add
  574           // new functionality add it to the Handler, but make sure this
  575           // class calls into the Handler.
  576           public void addLayoutComponent(String name, Component c) {
  577               getHandler().addLayoutComponent(name, c);
  578           }
  579   
  580           public void removeLayoutComponent(Component c) {
  581               getHandler().removeLayoutComponent(c);
  582           }
  583   
  584           public Dimension preferredLayoutSize(Container c)  {
  585               return getHandler().preferredLayoutSize(c);
  586           }
  587   
  588           public Dimension minimumLayoutSize(Container c) {
  589               return getHandler().minimumLayoutSize(c);
  590           }
  591   
  592           public void layoutContainer(Container c) {
  593               getHandler().layoutContainer(c);
  594           }
  595       }
  596   
  597       /**
  598        * This class should be treated as a &quot;protected&quot; inner class.
  599        * Instantiate it only within subclasses of <Foo>.
  600        */
  601       public class CloseAction extends AbstractAction {
  602           public CloseAction() {
  603               super(CLOSE_CMD);
  604           }
  605   
  606           public void actionPerformed(ActionEvent e) {
  607               if(frame.isClosable()) {
  608                   frame.doDefaultCloseAction();
  609               }
  610           }
  611       } // end CloseAction
  612   
  613       /**
  614        * This class should be treated as a &quot;protected&quot; inner class.
  615        * Instantiate it only within subclasses of <Foo>.
  616        */
  617       public class MaximizeAction extends AbstractAction {
  618           public MaximizeAction() {
  619               super(MAXIMIZE_CMD);
  620           }
  621   
  622           public void actionPerformed(ActionEvent evt) {
  623               if (frame.isMaximizable()) {
  624                   if (frame.isMaximum() && frame.isIcon()) {
  625                       try {
  626                           frame.setIcon(false);
  627                       } catch (PropertyVetoException e) { }
  628                   } else if (!frame.isMaximum()) {
  629                       try {
  630                           frame.setMaximum(true);
  631                       } catch (PropertyVetoException e) { }
  632                   } else {
  633                       try {
  634                           frame.setMaximum(false);
  635                       } catch (PropertyVetoException e) { }
  636                   }
  637               }
  638           }
  639       }
  640   
  641       /**
  642        * This class should be treated as a &quot;protected&quot; inner class.
  643        * Instantiate it only within subclasses of <Foo>.
  644        */
  645       public class IconifyAction extends AbstractAction {
  646           public IconifyAction() {
  647               super(ICONIFY_CMD);
  648           }
  649   
  650           public void actionPerformed(ActionEvent e) {
  651               if(frame.isIconifiable()) {
  652                 if(!frame.isIcon()) {
  653                   try { frame.setIcon(true); } catch (PropertyVetoException e1) { }
  654                 } else{
  655                   try { frame.setIcon(false); } catch (PropertyVetoException e1) { }
  656                 }
  657               }
  658           }
  659       } // end IconifyAction
  660   
  661       /**
  662        * This class should be treated as a &quot;protected&quot; inner class.
  663        * Instantiate it only within subclasses of <Foo>.
  664        */
  665       public class RestoreAction extends AbstractAction {
  666           public RestoreAction() {
  667               super(RESTORE_CMD);
  668           }
  669   
  670           public void actionPerformed(ActionEvent evt) {
  671               if (frame.isMaximizable() && frame.isMaximum() && frame.isIcon()) {
  672                   try {
  673                       frame.setIcon(false);
  674                   } catch (PropertyVetoException e) { }
  675               } else if (frame.isMaximizable() && frame.isMaximum()) {
  676                   try {
  677                       frame.setMaximum(false);
  678                   } catch (PropertyVetoException e) { }
  679               } else if (frame.isIconifiable() && frame.isIcon()) {
  680                   try {
  681                       frame.setIcon(false);
  682                   } catch (PropertyVetoException e) { }
  683               }
  684           }
  685       }
  686   
  687       /**
  688        * This class should be treated as a &quot;protected&quot; inner class.
  689        * Instantiate it only within subclasses of <Foo>.
  690        */
  691       public class MoveAction extends AbstractAction {
  692           public MoveAction() {
  693               super(MOVE_CMD);
  694           }
  695   
  696           public void actionPerformed(ActionEvent e) {
  697               // This action is currently undefined
  698           }
  699       } // end MoveAction
  700   
  701       /*
  702        * Handles showing and hiding the system menu.
  703        */
  704       private class ShowSystemMenuAction extends AbstractAction {
  705           private boolean show;   // whether to show the menu
  706   
  707           public ShowSystemMenuAction(boolean show) {
  708               this.show = show;
  709           }
  710   
  711           public void actionPerformed(ActionEvent e) {
  712               if (show) {
  713                   windowMenu.doClick();
  714               } else {
  715                   windowMenu.setVisible(false);
  716               }
  717           }
  718       }
  719   
  720       /**
  721        * This class should be treated as a &quot;protected&quot; inner class.
  722        * Instantiate it only within subclasses of <Foo>.
  723        */
  724       public class SizeAction extends AbstractAction {
  725           public SizeAction() {
  726               super(SIZE_CMD);
  727           }
  728   
  729           public void actionPerformed(ActionEvent e) {
  730               // This action is currently undefined
  731           }
  732       } // end SizeAction
  733   
  734   
  735       /**
  736        * This class should be treated as a &quot;protected&quot; inner class.
  737        * Instantiate it only within subclasses of <Foo>.
  738        */
  739       public class SystemMenuBar extends JMenuBar {
  740           public boolean isFocusTraversable() { return false; }
  741           public void requestFocus() {}
  742           public void paint(Graphics g) {
  743               Icon icon = frame.getFrameIcon();
  744               if (icon == null) {
  745                 icon = (Icon)DefaultLookup.get(frame, frame.getUI(),
  746                         "InternalFrame.icon");
  747               }
  748               if (icon != null) {
  749                   // Resize to 16x16 if necessary.
  750                   if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) {
  751                       Image img = ((ImageIcon)icon).getImage();
  752                       ((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
  753                   }
  754                   icon.paintIcon(this, g, 0, 0);
  755               }
  756           }
  757   
  758           public boolean isOpaque() {
  759               return true;
  760           }
  761       } // end SystemMenuBar
  762   
  763   
  764       private class NoFocusButton extends JButton {
  765           private String uiKey;
  766           public NoFocusButton(String uiKey, String opacityKey) {
  767               setFocusPainted(false);
  768               setMargin(new Insets(0,0,0,0));
  769               this.uiKey = uiKey;
  770   
  771               Object opacity = UIManager.get(opacityKey);
  772               if (opacity instanceof Boolean) {
  773                   setOpaque(((Boolean)opacity).booleanValue());
  774               }
  775           }
  776           public boolean isFocusTraversable() { return false; }
  777           public void requestFocus() {};
  778           public AccessibleContext getAccessibleContext() {
  779               AccessibleContext ac = super.getAccessibleContext();
  780               if (uiKey != null) {
  781                   ac.setAccessibleName(UIManager.getString(uiKey));
  782                   uiKey = null;
  783               }
  784               return ac;
  785           }
  786       };  // end NoFocusButton
  787   
  788   }   // End Title Pane Class

Save This Page
Home » openjdk-7 » javax » swing » plaf » basic » [javadoc | source]