src/share/classes/javax/swing/plaf/metal/MetalTitlePane.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2006, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  32 import java.beans.*;
  33 import javax.swing.*;
  34 import javax.swing.border.*;
  35 import javax.swing.event.InternalFrameEvent;
  36 import javax.swing.plaf.*;
  37 import javax.swing.plaf.basic.*;
  38 import java.util.Locale;
  39 import javax.accessibility.*;
  40 
  41 
  42 /**
  43  * Class that manages a JLF awt.Window-descendant class's title bar.
  44  * <p>
  45  * This class assumes it will be created with a particular window
  46  * decoration style, and that if the style changes, a new one will
  47  * be created.
  48  *
  49  * @author Terry Kellerman
  50  * @since 1.4
  51  */

  52 class MetalTitlePane extends JComponent {
  53     private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0);
  54     private static final int IMAGE_HEIGHT = 16;
  55     private static final int IMAGE_WIDTH = 16;
  56 
  57     /**
  58      * PropertyChangeListener added to the JRootPane.
  59      */
  60     private PropertyChangeListener propertyChangeListener;
  61 
  62     /**
  63      * JMenuBar, typically renders the system menu items.
  64      */
  65     private JMenuBar menuBar;
  66     /**
  67      * Action used to close the Window.
  68      */
  69     private Action closeAction;
  70 
  71     /**


 764         }
 765 
 766         int bumpXOffset;
 767         int bumpLength;
 768         if( leftToRight ) {
 769             bumpLength = width - buttonsWidth - xOffset - 5;
 770             bumpXOffset = xOffset;
 771         } else {
 772             bumpLength = xOffset - buttonsWidth - 5;
 773             bumpXOffset = buttonsWidth + 5;
 774         }
 775         int bumpYOffset = 3;
 776         int bumpHeight = getHeight() - (2 * bumpYOffset);
 777         bumps.setBumpArea( bumpLength, bumpHeight );
 778         bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
 779     }
 780 
 781     /**
 782      * Actions used to <code>close</code> the <code>Window</code>.
 783      */

 784     private class CloseAction extends AbstractAction {
 785         public CloseAction() {
 786             super(UIManager.getString("MetalTitlePane.closeTitle",
 787                                       getLocale()));
 788         }
 789 
 790         public void actionPerformed(ActionEvent e) {
 791             close();
 792         }
 793     }
 794 
 795 
 796     /**
 797      * Actions used to <code>iconfiy</code> the <code>Frame</code>.
 798      */

 799     private class IconifyAction extends AbstractAction {
 800         public IconifyAction() {
 801             super(UIManager.getString("MetalTitlePane.iconifyTitle",
 802                                       getLocale()));
 803         }
 804 
 805         public void actionPerformed(ActionEvent e) {
 806             iconify();
 807         }
 808     }
 809 
 810 
 811     /**
 812      * Actions used to <code>restore</code> the <code>Frame</code>.
 813      */

 814     private class RestoreAction extends AbstractAction {
 815         public RestoreAction() {
 816             super(UIManager.getString
 817                   ("MetalTitlePane.restoreTitle", getLocale()));
 818         }
 819 
 820         public void actionPerformed(ActionEvent e) {
 821             restore();
 822         }
 823     }
 824 
 825 
 826     /**
 827      * Actions used to <code>restore</code> the <code>Frame</code>.
 828      */

 829     private class MaximizeAction extends AbstractAction {
 830         public MaximizeAction() {
 831             super(UIManager.getString("MetalTitlePane.maximizeTitle",
 832                                       getLocale()));
 833         }
 834 
 835         public void actionPerformed(ActionEvent e) {
 836             maximize();
 837         }
 838     }
 839 
 840 
 841     /**
 842      * Class responsible for drawing the system menu. Looks up the
 843      * image to draw from the Frame associated with the
 844      * <code>JRootPane</code>.
 845      */

 846     private class SystemMenuBar extends JMenuBar {
 847         public void paint(Graphics g) {
 848             if (isOpaque()) {
 849                 g.setColor(getBackground());
 850                 g.fillRect(0, 0, getWidth(), getHeight());
 851             }
 852 
 853             if (systemIcon != null) {
 854                 g.drawImage(systemIcon, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
 855             } else {
 856                 Icon icon = UIManager.getIcon("InternalFrame.icon");
 857 
 858                 if (icon != null) {
 859                     icon.paintIcon(this, g, 0, 0);
 860                 }
 861             }
 862         }
 863         public Dimension getMinimumSize() {
 864             return getPreferredSize();
 865         }


   1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  32 import java.beans.*;
  33 import javax.swing.*;
  34 import javax.swing.border.*;
  35 import javax.swing.event.InternalFrameEvent;
  36 import javax.swing.plaf.*;
  37 import javax.swing.plaf.basic.*;
  38 import java.util.Locale;
  39 import javax.accessibility.*;
  40 
  41 
  42 /**
  43  * Class that manages a JLF awt.Window-descendant class's title bar.
  44  * <p>
  45  * This class assumes it will be created with a particular window
  46  * decoration style, and that if the style changes, a new one will
  47  * be created.
  48  *
  49  * @author Terry Kellerman
  50  * @since 1.4
  51  */
  52 @SuppressWarnings("serial") // Superclass is not serializable across versions
  53 class MetalTitlePane extends JComponent {
  54     private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0);
  55     private static final int IMAGE_HEIGHT = 16;
  56     private static final int IMAGE_WIDTH = 16;
  57 
  58     /**
  59      * PropertyChangeListener added to the JRootPane.
  60      */
  61     private PropertyChangeListener propertyChangeListener;
  62 
  63     /**
  64      * JMenuBar, typically renders the system menu items.
  65      */
  66     private JMenuBar menuBar;
  67     /**
  68      * Action used to close the Window.
  69      */
  70     private Action closeAction;
  71 
  72     /**


 765         }
 766 
 767         int bumpXOffset;
 768         int bumpLength;
 769         if( leftToRight ) {
 770             bumpLength = width - buttonsWidth - xOffset - 5;
 771             bumpXOffset = xOffset;
 772         } else {
 773             bumpLength = xOffset - buttonsWidth - 5;
 774             bumpXOffset = buttonsWidth + 5;
 775         }
 776         int bumpYOffset = 3;
 777         int bumpHeight = getHeight() - (2 * bumpYOffset);
 778         bumps.setBumpArea( bumpLength, bumpHeight );
 779         bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
 780     }
 781 
 782     /**
 783      * Actions used to <code>close</code> the <code>Window</code>.
 784      */
 785     @SuppressWarnings("serial") // Superclass is not serializable across versions
 786     private class CloseAction extends AbstractAction {
 787         public CloseAction() {
 788             super(UIManager.getString("MetalTitlePane.closeTitle",
 789                                       getLocale()));
 790         }
 791 
 792         public void actionPerformed(ActionEvent e) {
 793             close();
 794         }
 795     }
 796 
 797 
 798     /**
 799      * Actions used to <code>iconfiy</code> the <code>Frame</code>.
 800      */
 801     @SuppressWarnings("serial") // Superclass is not serializable across versions
 802     private class IconifyAction extends AbstractAction {
 803         public IconifyAction() {
 804             super(UIManager.getString("MetalTitlePane.iconifyTitle",
 805                                       getLocale()));
 806         }
 807 
 808         public void actionPerformed(ActionEvent e) {
 809             iconify();
 810         }
 811     }
 812 
 813 
 814     /**
 815      * Actions used to <code>restore</code> the <code>Frame</code>.
 816      */
 817     @SuppressWarnings("serial") // Superclass is not serializable across versions
 818     private class RestoreAction extends AbstractAction {
 819         public RestoreAction() {
 820             super(UIManager.getString
 821                   ("MetalTitlePane.restoreTitle", getLocale()));
 822         }
 823 
 824         public void actionPerformed(ActionEvent e) {
 825             restore();
 826         }
 827     }
 828 
 829 
 830     /**
 831      * Actions used to <code>restore</code> the <code>Frame</code>.
 832      */
 833     @SuppressWarnings("serial") // Superclass is not serializable across versions
 834     private class MaximizeAction extends AbstractAction {
 835         public MaximizeAction() {
 836             super(UIManager.getString("MetalTitlePane.maximizeTitle",
 837                                       getLocale()));
 838         }
 839 
 840         public void actionPerformed(ActionEvent e) {
 841             maximize();
 842         }
 843     }
 844 
 845 
 846     /**
 847      * Class responsible for drawing the system menu. Looks up the
 848      * image to draw from the Frame associated with the
 849      * <code>JRootPane</code>.
 850      */
 851     @SuppressWarnings("serial") // Superclass is not serializable across versions
 852     private class SystemMenuBar extends JMenuBar {
 853         public void paint(Graphics g) {
 854             if (isOpaque()) {
 855                 g.setColor(getBackground());
 856                 g.fillRect(0, 0, getWidth(), getHeight());
 857             }
 858 
 859             if (systemIcon != null) {
 860                 g.drawImage(systemIcon, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
 861             } else {
 862                 Icon icon = UIManager.getIcon("InternalFrame.icon");
 863 
 864                 if (icon != null) {
 865                     icon.paintIcon(this, g, 0, 0);
 866                 }
 867             }
 868         }
 869         public Dimension getMinimumSize() {
 870             return getPreferredSize();
 871         }