jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifInternalFrameUI.java
author darcy
Mon, 10 Mar 2014 13:54:25 -0700
changeset 23632 cd7a34d12e8c
parent 5506 202f599c92aa
permissions -rw-r--r--
8033908: Fix serial lint warnings in com.sun.java.swing.plaf Reviewed-by: serb, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A Motif L&F implementation of InternalFrame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Tom Ball
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class MotifInternalFrameUI extends BasicInternalFrameUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    Color color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    MotifInternalFrameTitlePane titlePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected KeyStroke closeMenuKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
// ComponentUI Interface Implementation methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static ComponentUI createUI(JComponent w)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return new MotifInternalFrameUI((JInternalFrame)w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public MotifInternalFrameUI(JInternalFrame w)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        super(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public void installUI(JComponent c)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        setColors((JInternalFrame)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Border frameBorder = frame.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        frame.setLayout(internalFrameLayout = createLayoutManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (frameBorder == null || frameBorder instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            frame.setBorder(new MotifBorders.InternalFrameBorder(frame));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected void installKeyboardActions(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
      super.installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
      // We replace the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      // we use JPopup in our TitlePane so need escape support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        LookAndFeel.uninstallBorder(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        frame.setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        internalFrameLayout = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private JInternalFrame getFrame(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      return frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public JComponent createNorthPane(JInternalFrame w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        titlePane = new MotifInternalFrameTitlePane(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return titlePane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public Dimension getMaximumSize(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return Toolkit.getDefaultToolkit().getScreenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    protected void uninstallKeyboardActions(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      super.uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      if (isKeyBindingRegistered()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        SwingUtilities.replaceUIActionMap(di, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        SwingUtilities.replaceUIInputMap(di, JComponent.WHEN_IN_FOCUSED_WINDOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                         null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
   133
    @SuppressWarnings("serial") // anonymous class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    protected void setupMenuOpenKey(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        super.setupMenuOpenKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        ActionMap map = SwingUtilities.getUIActionMap(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            // BasicInternalFrameUI creates an action with the same name, we override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            // it as MotifInternalFrameTitlePane has a titlePane ivar that shadows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            // titlePane ivar in BasicInternalFrameUI, making supers action throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            // an NPE for us.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            map.put("showSystemMenu", new AbstractAction(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                public void actionPerformed(ActionEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    titlePane.showSystemMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                public boolean isEnabled(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    return isKeyBindingActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
   153
    @SuppressWarnings("serial") // anonymous class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected void setupMenuCloseKey(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        ActionMap map = SwingUtilities.getUIActionMap(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            map.put("hideSystemMenu", new AbstractAction(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                public void actionPerformed(ActionEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    titlePane.hideSystemMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                public boolean isEnabled(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    return isKeyBindingActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        // Set up the bindings for the DesktopIcon, it is odd that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        // we install them, and not the desktop icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        InputMap diInputMap = SwingUtilities.getUIInputMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                          (di, JComponent.WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (diInputMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            Object[] bindings = (Object[])UIManager.get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                          ("DesktopIcon.windowBindings");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            if (bindings != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                diInputMap = LookAndFeel.makeComponentInputMap(di, bindings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                SwingUtilities.replaceUIInputMap(di, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                               WHEN_IN_FOCUSED_WINDOW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                               diInputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        ActionMap diActionMap = SwingUtilities.getUIActionMap(di);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (diActionMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            diActionMap = new ActionMapUIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            diActionMap.put("hideSystemMenu", new AbstractAction(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                public void actionPerformed(ActionEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    JInternalFrame.JDesktopIcon icon = getFrame().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                     getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    MotifDesktopIconUI micon = (MotifDesktopIconUI)icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                               getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    micon.hideSystemMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                public boolean isEnabled(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    return isKeyBindingActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            SwingUtilities.replaceUIActionMap(di, diActionMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /** This method is called when the frame becomes selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected void activateFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        super.activateFrame(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        setColors(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /** This method is called when the frame is no longer selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    protected void deactivateFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        setColors(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        super.deactivateFrame(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    void setColors(JInternalFrame frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (frame.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            color = UIManager.getColor("InternalFrame.activeTitleBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            color = UIManager.getColor("InternalFrame.inactiveTitleBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        highlight = color.brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        shadow = color.darker().darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        titlePane.setColors(color, highlight, shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
}