1 /*
2  * Copyright (c) 1997, 2004, 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
23  * questions.
24  */
25 
26 package com.sun.java.swing.plaf.motif;
27 
28 import java.awt.*;
29 import java.awt.event.*;
30 import javax.swing.*;
31 import javax.swing.event.*;
32 
33 import java.util.EventListener;
34 
35 import javax.swing.plaf.basic.*;
36 import javax.swing.border.*;
37 import javax.swing.plaf.*;
38 
39 
40 /**
41  * A Motif L&F implementation of InternalFrame.
42  * <p>
43  * <strong>Warning:</strong>
44  * Serialized objects of this class will not be compatible with
45  * future Swing releases.  The current serialization support is appropriate
46  * for short term storage or RMI between applications running the same
47  * version of Swing.  A future release of Swing will provide support for
48  * long term persistence.
49  *
50  * @author Tom Ball
51  */
52 public class MotifInternalFrameUI extends BasicInternalFrameUI {
53 
54     Color color;
55     Color highlight;
56     Color shadow;
57     MotifInternalFrameTitlePane titlePane;
58 
59     /**
60      * As of Java 2 platform v1.3 this previously undocumented field is no
61      * longer used.
62      * Key bindings are now defined by the LookAndFeel, please refer to
63      * the key bindings specification for further details.
64      *
65      * @deprecated As of Java 2 platform v1.3.
66      */
67     @Deprecated
68     protected KeyStroke closeMenuKey;
69 
70 
71 /////////////////////////////////////////////////////////////////////////////
72 // ComponentUI Interface Implementation methods
73 /////////////////////////////////////////////////////////////////////////////
createUI(JComponent w)74     public static ComponentUI createUI(JComponent w)    {
75         return new MotifInternalFrameUI((JInternalFrame)w);
76     }
77 
MotifInternalFrameUI(JInternalFrame w)78     public MotifInternalFrameUI(JInternalFrame w)   {
79         super(w);
80     }
81 
installUI(JComponent c)82     public void installUI(JComponent c)   {
83         super.installUI(c);
84         setColors((JInternalFrame)c);
85     }
86 
installDefaults()87     protected void installDefaults() {
88         Border frameBorder = frame.getBorder();
89         frame.setLayout(internalFrameLayout = createLayoutManager());
90         if (frameBorder == null || frameBorder instanceof UIResource) {
91             frame.setBorder(new MotifBorders.InternalFrameBorder(frame));
92         }
93     }
94 
95 
installKeyboardActions()96     protected void installKeyboardActions(){
97       super.installKeyboardActions();
98       // We replace the
99       // we use JPopup in our TitlePane so need escape support
100       closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
101     }
102 
103 
uninstallDefaults()104     protected void uninstallDefaults() {
105         LookAndFeel.uninstallBorder(frame);
106         frame.setLayout(null);
107         internalFrameLayout = null;
108     }
109 
getFrame()110     private JInternalFrame getFrame(){
111       return frame;
112     }
113 
createNorthPane(JInternalFrame w)114     public JComponent createNorthPane(JInternalFrame w) {
115         titlePane = new MotifInternalFrameTitlePane(w);
116         return titlePane;
117     }
118 
getMaximumSize(JComponent x)119     public Dimension getMaximumSize(JComponent x) {
120         return Toolkit.getDefaultToolkit().getScreenSize();
121     }
122 
uninstallKeyboardActions()123     protected void uninstallKeyboardActions(){
124       super.uninstallKeyboardActions();
125       if (isKeyBindingRegistered()){
126         JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
127         SwingUtilities.replaceUIActionMap(di, null);
128         SwingUtilities.replaceUIInputMap(di, JComponent.WHEN_IN_FOCUSED_WINDOW,
129                                          null);
130       }
131     }
132 
setupMenuOpenKey()133     protected void setupMenuOpenKey(){
134         super.setupMenuOpenKey();
135         ActionMap map = SwingUtilities.getUIActionMap(frame);
136         if (map != null) {
137             // BasicInternalFrameUI creates an action with the same name, we override
138             // it as MotifInternalFrameTitlePane has a titlePane ivar that shadows the
139             // titlePane ivar in BasicInternalFrameUI, making supers action throw
140             // an NPE for us.
141             map.put("showSystemMenu", new AbstractAction(){
142                 public void actionPerformed(ActionEvent e){
143                     titlePane.showSystemMenu();
144                 }
145                 public boolean isEnabled(){
146                     return isKeyBindingActive();
147                 }
148             });
149         }
150     }
151 
setupMenuCloseKey()152     protected void setupMenuCloseKey(){
153         ActionMap map = SwingUtilities.getUIActionMap(frame);
154         if (map != null) {
155             map.put("hideSystemMenu", new AbstractAction(){
156                 public void actionPerformed(ActionEvent e){
157                     titlePane.hideSystemMenu();
158                 }
159                 public boolean isEnabled(){
160                     return isKeyBindingActive();
161                 }
162             });
163         }
164 
165         // Set up the bindings for the DesktopIcon, it is odd that
166         // we install them, and not the desktop icon.
167         JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
168         InputMap diInputMap = SwingUtilities.getUIInputMap
169                           (di, JComponent.WHEN_IN_FOCUSED_WINDOW);
170         if (diInputMap == null) {
171             Object[] bindings = (Object[])UIManager.get
172                                           ("DesktopIcon.windowBindings");
173             if (bindings != null) {
174                 diInputMap = LookAndFeel.makeComponentInputMap(di, bindings);
175 
176                 SwingUtilities.replaceUIInputMap(di, JComponent.
177                                                WHEN_IN_FOCUSED_WINDOW,
178                                                diInputMap);
179             }
180         }
181         ActionMap diActionMap = SwingUtilities.getUIActionMap(di);
182         if (diActionMap == null) {
183             diActionMap = new ActionMapUIResource();
184             diActionMap.put("hideSystemMenu", new AbstractAction(){
185                 public void actionPerformed(ActionEvent e){
186                     JInternalFrame.JDesktopIcon icon = getFrame().
187                                      getDesktopIcon();
188                     MotifDesktopIconUI micon = (MotifDesktopIconUI)icon.
189                                                getUI();
190                     micon.hideSystemMenu();
191                 }
192                 public boolean isEnabled(){
193                     return isKeyBindingActive();
194                 }
195             });
196             SwingUtilities.replaceUIActionMap(di, diActionMap);
197         }
198     }
199 
200     /** This method is called when the frame becomes selected.
201       */
activateFrame(JInternalFrame f)202     protected void activateFrame(JInternalFrame f) {
203         super.activateFrame(f);
204         setColors(f);
205     }
206     /** This method is called when the frame is no longer selected.
207       */
deactivateFrame(JInternalFrame f)208     protected void deactivateFrame(JInternalFrame f) {
209         setColors(f);
210         super.deactivateFrame(f);
211     }
212 
setColors(JInternalFrame frame)213     void setColors(JInternalFrame frame) {
214         if (frame.isSelected()) {
215             color = UIManager.getColor("InternalFrame.activeTitleBackground");
216         } else {
217             color = UIManager.getColor("InternalFrame.inactiveTitleBackground");
218         }
219         highlight = color.brighter();
220         shadow = color.darker().darker();
221         titlePane.setColors(color, highlight, shadow);
222     }
223 }
224