KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > SynthInternalFrameUI


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

7
8 package javax.swing.plaf.synth;
9
10 import java.awt.*;
11 import java.awt.event.*;
12 import java.awt.peer.LightweightPeer;
13
14 import javax.swing.*;
15 import javax.swing.plaf.*;
16 import javax.swing.plaf.basic.BasicInternalFrameUI JavaDoc;
17 import javax.swing.event.*;
18
19 import java.beans.*;
20 import java.io.Serializable JavaDoc;
21 import sun.swing.plaf.synth.SynthUI;
22
23
24 /**
25  * Synth's InternalFrameUI.
26  *
27  * @version 1.20 04/16/04
28  * @author David Kloba
29  * @author Joshua Outwater
30  * @author Rich Schiavi
31  */

32 class SynthInternalFrameUI extends BasicInternalFrameUI JavaDoc implements SynthUI,
33         PropertyChangeListener {
34     private SynthStyle JavaDoc style;
35  
36     private static DesktopManager sharedDesktopManager;
37     private boolean componentListenerAdded = false;
38
39     private Rectangle parentBounds;
40
41     public static ComponentUI createUI(JComponent b) {
42         return new SynthInternalFrameUI JavaDoc((JInternalFrame)b);
43     }
44
45     public SynthInternalFrameUI(JInternalFrame b) {
46         super(b);
47     }
48
49     public void installDefaults() {
50         frame.setLayout(internalFrameLayout = createLayoutManager());
51         updateStyle(frame);
52     }
53
54     protected void installListeners() {
55         super.installListeners();
56         frame.addPropertyChangeListener(this);
57     }
58
59     protected void uninstallComponents() {
60     if (frame.getComponentPopupMenu() instanceof UIResource) {
61         frame.setComponentPopupMenu(null);
62     }
63     super.uninstallComponents();
64     }
65
66     protected void uninstallListeners() {
67         frame.removePropertyChangeListener(this);
68         super.uninstallListeners();
69     }
70
71     private void updateStyle(JComponent c) {
72         SynthContext JavaDoc context = getContext(c, ENABLED);
73         SynthStyle JavaDoc oldStyle = style;
74
75         style = SynthLookAndFeel.updateStyle(context, this);
76         if (style != oldStyle) {
77             Icon frameIcon = frame.getFrameIcon();
78             if (frameIcon == null || frameIcon instanceof UIResource) {
79                 frame.setFrameIcon(context.getStyle().getIcon(
80                                    context, "InternalFrame.icon"));
81             }
82             if (oldStyle != null) {
83                 uninstallKeyboardActions();
84                 installKeyboardActions();
85             }
86         }
87         context.dispose();
88     }
89
90     protected void uninstallDefaults() {
91         SynthContext JavaDoc context = getContext(frame, ENABLED);
92         style.uninstallDefaults(context);
93         context.dispose();
94         style = null;
95         if(frame.getLayout() == internalFrameLayout) {
96             frame.setLayout(null);
97         }
98
99     }
100
101     public SynthContext JavaDoc getContext(JComponent c) {
102         return getContext(c, getComponentState(c));
103     }
104
105     private SynthContext JavaDoc getContext(JComponent c, int state) {
106         return SynthContext.getContext(SynthContext JavaDoc.class, c,
107                             SynthLookAndFeel.getRegion(c), style, state);
108     }
109
110     private Region JavaDoc getRegion(JComponent c) {
111         return SynthLookAndFeel.getRegion(c);
112     }
113
114     public int getComponentState(JComponent c) {
115         return SynthLookAndFeel.getComponentState(c);
116     }
117
118     protected JComponent createNorthPane(JInternalFrame w) {
119         titlePane = new SynthInternalFrameTitlePane JavaDoc(w);
120     titlePane.setName("InternalFrame.northPane");
121         return titlePane;
122     }
123     
124     protected ComponentListener createComponentListener() {
125     if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
126         return new ComponentHandler() {
127         public void componentResized(ComponentEvent e) {
128             if (frame != null && frame.isMaximum()) {
129             JDesktopPane desktop = (JDesktopPane)e.getSource();
130             for (Component comp : desktop.getComponents()) {
131                 if (comp instanceof SynthDesktopPaneUI.TaskBar JavaDoc) {
132                 frame.setBounds(0, 0,
133                         desktop.getWidth(),
134                         desktop.getHeight() - comp.getHeight());
135                 frame.revalidate();
136                 break;
137                 }
138             }
139             }
140
141             // Update the new parent bounds for next resize, but don't
142
// let the super method touch this frame
143
JInternalFrame f = frame;
144             frame = null;
145             super.componentResized(e);
146             frame = f;
147         }
148         };
149     } else {
150         return super.createComponentListener();
151     }
152     }
153
154     public void update(Graphics g, JComponent c) {
155         SynthContext JavaDoc context = getContext(c);
156
157         SynthLookAndFeel.update(context, g);
158         context.getPainter().paintInternalFrameBackground(context,
159                           g, 0, 0, c.getWidth(), c.getHeight());
160         paint(context, g);
161         context.dispose();
162     }
163
164     public void paint(Graphics g, JComponent c) {
165         SynthContext JavaDoc context = getContext(c);
166
167         paint(context, g);
168         context.dispose();
169     }
170
171     protected void paint(SynthContext JavaDoc context, Graphics g) {
172     }
173
174     public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
175                             int y, int w, int h) {
176         context.getPainter().paintInternalFrameBorder(context,
177                                                             g, x, y, w, h);
178     }
179
180     public void propertyChange(PropertyChangeEvent evt) {
181         if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
182             updateStyle((JInternalFrame)evt.getSource());
183         }
184     }
185 }
186
Popular Tags