KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifInternalFrameUI


1 /*
2  * @(#)MotifInternalFrameUI.java 1.26 04/05/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.java.swing.plaf.motif;
9
10 import java.awt.*;
11 import java.awt.event.*;
12 import javax.swing.*;
13 import javax.swing.event.*;
14
15 import java.util.EventListener JavaDoc;
16
17 import javax.swing.plaf.basic.*;
18 import javax.swing.border.*;
19 import javax.swing.plaf.*;
20
21
22 /**
23  * A Motif L&F implementation of InternalFrame.
24  * <p>
25  * <strong>Warning:</strong>
26  * Serialized objects of this class will not be compatible with
27  * future Swing releases. The current serialization support is appropriate
28  * for short term storage or RMI between applications running the same
29  * version of Swing. A future release of Swing will provide support for
30  * long term persistence.
31  *
32  * @version 1.26 05/18/04
33  * @author Tom Ball
34  */

35 public class MotifInternalFrameUI extends BasicInternalFrameUI {
36
37     Color color;
38     Color highlight;
39     Color shadow;
40     MotifInternalFrameTitlePane titlePane;
41
42     /**
43      * As of Java 2 platform v1.3 this previously undocumented field is no
44      * longer used.
45      * Key bindings are now defined by the LookAndFeel, please refer to
46      * the key bindings specification for further details.
47      *
48      * @deprecated As of Java 2 platform v1.3.
49      */

50     @Deprecated JavaDoc
51     protected KeyStroke closeMenuKey;
52
53
54 /////////////////////////////////////////////////////////////////////////////
55
// ComponentUI Interface Implementation methods
56
/////////////////////////////////////////////////////////////////////////////
57
public static ComponentUI createUI(JComponent w) {
58         return new MotifInternalFrameUI((JInternalFrame)w);
59     }
60
61     public MotifInternalFrameUI(JInternalFrame w) {
62         super(w);
63     }
64             
65     public void installUI(JComponent c) {
66         super.installUI(c);
67         setColors((JInternalFrame)c);
68     }
69
70     protected void installDefaults() {
71     Border frameBorder = frame.getBorder();
72         frame.setLayout(internalFrameLayout = createLayoutManager());
73         if (frameBorder == null || frameBorder instanceof UIResource) {
74             frame.setBorder(new MotifBorders.InternalFrameBorder(frame));
75         }
76     }
77
78
79     protected void installKeyboardActions(){
80       super.installKeyboardActions();
81       // We replace the
82
// we use JPopup in our TitlePane so need escape support
83
closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
84     }
85
86
87     protected void uninstallDefaults() {
88         LookAndFeel.uninstallBorder(frame);
89         frame.setLayout(null);
90         internalFrameLayout = null;
91     }
92
93     private JInternalFrame getFrame(){
94       return frame;
95     }
96
97     public JComponent createNorthPane(JInternalFrame w) {
98         titlePane = new MotifInternalFrameTitlePane(w);
99         return titlePane;
100     }
101
102     public Dimension getMaximumSize(JComponent x) {
103         return Toolkit.getDefaultToolkit().getScreenSize();
104     }
105
106     protected void uninstallKeyboardActions(){
107       super.uninstallKeyboardActions();
108       if (isKeyBindingRegistered()){
109     JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
110     SwingUtilities.replaceUIActionMap(di, null);
111     SwingUtilities.replaceUIInputMap(di, JComponent.WHEN_IN_FOCUSED_WINDOW,
112                      null);
113       }
114     }
115     
116     protected void setupMenuOpenKey(){
117     super.setupMenuOpenKey();
118     ActionMap map = SwingUtilities.getUIActionMap(frame);
119     if (map != null) {
120         // BasicInternalFrameUI creates an action with the same name, we override
121
// it as MotifInternalFrameTitlePane has a titlePane ivar that shadows the
122
// titlePane ivar in BasicInternalFrameUI, making supers action throw
123
// an NPE for us.
124
map.put("showSystemMenu", new AbstractAction(){
125         public void actionPerformed(ActionEvent e){
126             titlePane.showSystemMenu();
127         }
128         public boolean isEnabled(){
129             return isKeyBindingActive();
130         }
131         });
132     }
133     }
134
135     protected void setupMenuCloseKey(){
136     ActionMap map = SwingUtilities.getUIActionMap(frame);
137     if (map != null) {
138         map.put("hideSystemMenu", new AbstractAction(){
139         public void actionPerformed(ActionEvent e){
140             titlePane.hideSystemMenu();
141         }
142         public boolean isEnabled(){
143             return isKeyBindingActive();
144         }
145         });
146     }
147
148     // Set up the bindings for the DesktopIcon, it is odd that
149
// we install them, and not the desktop icon.
150
JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
151     InputMap diInputMap = SwingUtilities.getUIInputMap
152                       (di, JComponent.WHEN_IN_FOCUSED_WINDOW);
153     if (diInputMap == null) {
154         Object JavaDoc[] bindings = (Object JavaDoc[])UIManager.get
155                                   ("DesktopIcon.windowBindings");
156         if (bindings != null) {
157         diInputMap = LookAndFeel.makeComponentInputMap(di, bindings);
158
159         SwingUtilities.replaceUIInputMap(di, JComponent.
160                            WHEN_IN_FOCUSED_WINDOW,
161                            diInputMap);
162         }
163     }
164     ActionMap diActionMap = SwingUtilities.getUIActionMap(di);
165     if (diActionMap == null) {
166         diActionMap = new ActionMapUIResource();
167         diActionMap.put("hideSystemMenu", new AbstractAction(){
168         public void actionPerformed(ActionEvent e){
169             JInternalFrame.JDesktopIcon icon = getFrame().
170                          getDesktopIcon();
171             MotifDesktopIconUI micon = (MotifDesktopIconUI)icon.
172                                    getUI();
173             micon.hideSystemMenu();
174         }
175         public boolean isEnabled(){
176             return isKeyBindingActive();
177         }
178         });
179         SwingUtilities.replaceUIActionMap(di, diActionMap);
180     }
181     }
182
183     /** This method is called when the frame becomes selected.
184       */

185     protected void activateFrame(JInternalFrame f) {
186         super.activateFrame(f);
187         setColors(f);
188     }
189     /** This method is called when the frame is no longer selected.
190       */

191     protected void deactivateFrame(JInternalFrame f) {
192         setColors(f);
193         super.deactivateFrame(f);
194     }
195
196     void setColors(JInternalFrame frame) {
197         if (frame.isSelected()) {
198             color = UIManager.getColor("InternalFrame.activeTitleBackground");
199         } else {
200             color = UIManager.getColor("InternalFrame.inactiveTitleBackground");
201         }
202         highlight = color.brighter();
203         shadow = color.darker().darker();
204         titlePane.setColors(color, highlight, shadow);
205     }
206 }
207
Popular Tags