001 /*
002 * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.swing.plaf.synth;
027
028 import java.awt.*;
029 import java.awt.event.*;
030 import java.awt.peer.LightweightPeer;
031
032 import javax.swing.*;
033 import javax.swing.plaf.*;
034 import javax.swing.plaf.basic.BasicInternalFrameUI;
035 import javax.swing.event.*;
036
037 import java.beans.*;
038 import java.io.Serializable;
039 import sun.swing.plaf.synth.SynthUI;
040
041 /**
042 * Synth's InternalFrameUI.
043 *
044 * @version 1.28 05/05/07
045 * @author David Kloba
046 * @author Joshua Outwater
047 * @author Rich Schiavi
048 */
049 class SynthInternalFrameUI extends BasicInternalFrameUI implements
050 SynthUI, PropertyChangeListener {
051 private SynthStyle style;
052
053 private static DesktopManager sharedDesktopManager;
054 private boolean componentListenerAdded = false;
055
056 private Rectangle parentBounds;
057
058 public static ComponentUI createUI(JComponent b) {
059 return new SynthInternalFrameUI((JInternalFrame) b);
060 }
061
062 public SynthInternalFrameUI(JInternalFrame b) {
063 super (b);
064 }
065
066 public void installDefaults() {
067 frame.setLayout(internalFrameLayout = createLayoutManager());
068 updateStyle(frame);
069 }
070
071 protected void installListeners() {
072 super .installListeners();
073 frame.addPropertyChangeListener(this );
074 }
075
076 protected void uninstallComponents() {
077 if (frame.getComponentPopupMenu() instanceof UIResource) {
078 frame.setComponentPopupMenu(null);
079 }
080 super .uninstallComponents();
081 }
082
083 protected void uninstallListeners() {
084 frame.removePropertyChangeListener(this );
085 super .uninstallListeners();
086 }
087
088 private void updateStyle(JComponent c) {
089 SynthContext context = getContext(c, ENABLED);
090 SynthStyle oldStyle = style;
091
092 style = SynthLookAndFeel.updateStyle(context, this );
093 if (style != oldStyle) {
094 Icon frameIcon = frame.getFrameIcon();
095 if (frameIcon == null || frameIcon instanceof UIResource) {
096 frame.setFrameIcon(context.getStyle().getIcon(context,
097 "InternalFrame.icon"));
098 }
099 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
147 .getSource();
148 for (Component comp : desktop.getComponents()) {
149 if (comp instanceof SynthDesktopPaneUI.TaskBar) {
150 frame.setBounds(0, 0, desktop
151 .getWidth(), desktop
152 .getHeight()
153 - comp.getHeight());
154 frame.revalidate();
155 break;
156 }
157 }
158 }
159
160 // Update the new parent bounds for next resize, but don't
161 // let the super method touch this frame
162 JInternalFrame f = frame;
163 frame = null;
164 super .componentResized(e);
165 frame = f;
166 }
167 };
168 } else {
169 return super .createComponentListener();
170 }
171 }
172
173 public void update(Graphics g, JComponent c) {
174 SynthContext context = getContext(c);
175
176 SynthLookAndFeel.update(context, g);
177 context.getPainter().paintInternalFrameBackground(context, g,
178 0, 0, c.getWidth(), c.getHeight());
179 paint(context, g);
180 context.dispose();
181 }
182
183 public void paint(Graphics g, JComponent c) {
184 SynthContext context = getContext(c);
185
186 paint(context, g);
187 context.dispose();
188 }
189
190 protected void paint(SynthContext context, Graphics g) {
191 }
192
193 public void paintBorder(SynthContext context, Graphics g, int x,
194 int y, int w, int h) {
195 context.getPainter().paintInternalFrameBorder(context, g, x, y,
196 w, h);
197 }
198
199 public void propertyChange(PropertyChangeEvent evt) {
200 SynthStyle oldStyle = style;
201 JInternalFrame f = (JInternalFrame) evt.getSource();
202 String prop = evt.getPropertyName();
203
204 if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
205 updateStyle(f);
206 }
207
208 if (style == oldStyle
209 && (prop == JInternalFrame.IS_MAXIMUM_PROPERTY || prop == JInternalFrame.IS_SELECTED_PROPERTY)) {
210 // Border (and other defaults) may need to change
211 SynthContext context = getContext(f, ENABLED);
212 style.uninstallDefaults(context);
213 style.installDefaults(context, this);
214 }
215 }
216 }
|