1 /*
2 * Copyright 2002-2006 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package javax.swing.plaf.synth;
27
28 import java.awt;
29 import java.awt.event;
30 import java.awt.peer.LightweightPeer;
31
32 import javax.swing;
33 import javax.swing.plaf;
34 import javax.swing.plaf.basic.BasicInternalFrameUI;
35 import javax.swing.event;
36
37 import java.beans;
38 import java.io.Serializable;
39 import sun.swing.plaf.synth.SynthUI;
40
41
42 /**
43 * Synth's InternalFrameUI.
44 *
45 * @author David Kloba
46 * @author Joshua Outwater
47 * @author Rich Schiavi
48 */
49 class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
50 PropertyChangeListener {
51 private SynthStyle style;
52
53 private static DesktopManager sharedDesktopManager;
54 private boolean componentListenerAdded = false;
55
56 private Rectangle parentBounds;
57
58 public static ComponentUI createUI(JComponent b) {
59 return new SynthInternalFrameUI((JInternalFrame)b);
60 }
61
62 public SynthInternalFrameUI(JInternalFrame b) {
63 super(b);
64 }
65
66 public void installDefaults() {
67 frame.setLayout(internalFrameLayout = createLayoutManager());
68 updateStyle(frame);
69 }
70
71 protected void installListeners() {
72 super.installListeners();
73 frame.addPropertyChangeListener(this);
74 }
75
76 protected void uninstallComponents() {
77 if (frame.getComponentPopupMenu() instanceof UIResource) {
78 frame.setComponentPopupMenu(null);
79 }
80 super.uninstallComponents();
81 }
82
83 protected void uninstallListeners() {
84 frame.removePropertyChangeListener(this);
85 super.uninstallListeners();
86 }
87
88 private void updateStyle(JComponent c) {
89 SynthContext context = getContext(c, ENABLED);
90 SynthStyle oldStyle = style;
91
92 style = SynthLookAndFeel.updateStyle(context, this);
93 if (style != oldStyle) {
94 Icon frameIcon = frame.getFrameIcon();
95 if (frameIcon == null || frameIcon instanceof UIResource) {
96 frame.setFrameIcon(context.getStyle().getIcon(
97 context, "InternalFrame.icon"));
98 }
99 if (oldStyle != null) {
100 uninstallKeyboardActions();
101 installKeyboardActions();
102 }
103 }
104 context.dispose();
105 }
106
107 protected void uninstallDefaults() {
108 SynthContext context = getContext(frame, ENABLED);
109 style.uninstallDefaults(context);
110 context.dispose();
111 style = null;
112 if(frame.getLayout() == internalFrameLayout) {
113 frame.setLayout(null);
114 }
115
116 }
117
118 public SynthContext getContext(JComponent c) {
119 return getContext(c, getComponentState(c));
120 }
121
122 private SynthContext getContext(JComponent c, int state) {
123 return SynthContext.getContext(SynthContext.class, c,
124 SynthLookAndFeel.getRegion(c), style, state);
125 }
126
127 private Region getRegion(JComponent c) {
128 return SynthLookAndFeel.getRegion(c);
129 }
130
131 public int getComponentState(JComponent c) {
132 return SynthLookAndFeel.getComponentState(c);
133 }
134
135 protected JComponent createNorthPane(JInternalFrame w) {
136 titlePane = new SynthInternalFrameTitlePane(w);
137 titlePane.setName("InternalFrame.northPane");
138 return titlePane;
139 }
140
141 protected ComponentListener createComponentListener() {
142 if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
143 return new ComponentHandler() {
144 public void componentResized(ComponentEvent e) {
145 if (frame != null && frame.isMaximum()) {
146 JDesktopPane desktop = (JDesktopPane)e.getSource();
147 for (Component comp : desktop.getComponents()) {
148 if (comp instanceof SynthDesktopPaneUI.TaskBar) {
149 frame.setBounds(0, 0,
150 desktop.getWidth(),
151 desktop.getHeight() - comp.getHeight());
152 frame.revalidate();
153 break;
154 }
155 }
156 }
157
158 // Update the new parent bounds for next resize, but don't
159 // let the super method touch this frame
160 JInternalFrame f = frame;
161 frame = null;
162 super.componentResized(e);
163 frame = f;
164 }
165 };
166 } else {
167 return super.createComponentListener();
168 }
169 }
170
171 public void update(Graphics g, JComponent c) {
172 SynthContext context = getContext(c);
173
174 SynthLookAndFeel.update(context, g);
175 context.getPainter().paintInternalFrameBackground(context,
176 g, 0, 0, c.getWidth(), c.getHeight());
177 paint(context, g);
178 context.dispose();
179 }
180
181 public void paint(Graphics g, JComponent c) {
182 SynthContext context = getContext(c);
183
184 paint(context, g);
185 context.dispose();
186 }
187
188 protected void paint(SynthContext context, Graphics g) {
189 }
190
191 public void paintBorder(SynthContext context, Graphics g, int x,
192 int y, int w, int h) {
193 context.getPainter().paintInternalFrameBorder(context,
194 g, x, y, w, h);
195 }
196
197 public void propertyChange(PropertyChangeEvent evt) {
198 SynthStyle oldStyle = style;
199 JInternalFrame f = (JInternalFrame)evt.getSource();
200 String prop = evt.getPropertyName();
201
202 if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
203 updateStyle(f);
204 }
205
206 if (style == oldStyle &&
207 (prop == JInternalFrame.IS_MAXIMUM_PROPERTY ||
208 prop == JInternalFrame.IS_SELECTED_PROPERTY)) {
209 // Border (and other defaults) may need to change
210 SynthContext context = getContext(f, ENABLED);
211 style.uninstallDefaults(context);
212 style.installDefaults(context, this);
213 }
214 }
215 }