001 /*
002 * Copyright 2002-2003 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 javax.swing.*;
031 import javax.swing.event.*;
032 import javax.swing.border.*;
033 import javax.swing.plaf.*;
034 import javax.swing.plaf.basic.BasicDesktopIconUI;
035 import java.beans.*;
036 import java.io.Serializable;
037 import sun.swing.plaf.synth.SynthUI;
038
039 /**
040 * Synth L&F for a minimized window on a desktop.
041 *
042 * @version 1.20, 05/05/07
043 * @author Joshua Outwater
044 */
045 class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI,
046 ActionListener, PropertyChangeListener {
047 private SynthStyle style;
048
049 public static ComponentUI createUI(JComponent c) {
050 return new SynthDesktopIconUI();
051 }
052
053 protected void installComponents() {
054 if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
055 iconPane = new JToggleButton(frame.getTitle(), frame
056 .getFrameIcon()) {
057 public String getToolTipText() {
058 return getText();
059 }
060
061 public JPopupMenu getComponentPopupMenu() {
062 return frame.getComponentPopupMenu();
063 }
064 };
065 ToolTipManager.sharedInstance().registerComponent(iconPane);
066 iconPane.setFont(desktopIcon.getFont());
067 iconPane.setBackground(desktopIcon.getBackground());
068 iconPane.setForeground(desktopIcon.getForeground());
069 } else {
070 iconPane = new SynthInternalFrameTitlePane(frame);
071 iconPane.setName("InternalFrame.northPane");
072 }
073 desktopIcon.setLayout(new BorderLayout());
074 desktopIcon.add(iconPane, BorderLayout.CENTER);
075 }
076
077 protected void installListeners() {
078 super .installListeners();
079 desktopIcon.addPropertyChangeListener(this );
080
081 if (iconPane instanceof JToggleButton) {
082 frame.addPropertyChangeListener(this );
083 ((JToggleButton) iconPane).addActionListener(this );
084 }
085 }
086
087 protected void uninstallListeners() {
088 if (iconPane instanceof JToggleButton) {
089 frame.removePropertyChangeListener(this );
090 }
091 desktopIcon.removePropertyChangeListener(this );
092 super .uninstallListeners();
093 }
094
095 protected void installDefaults() {
096 updateStyle(desktopIcon);
097 }
098
099 private void updateStyle(JComponent c) {
100 SynthContext context = getContext(c, ENABLED);
101 style = SynthLookAndFeel.updateStyle(context, this );
102 context.dispose();
103 }
104
105 protected void uninstallDefaults() {
106 SynthContext context = getContext(desktopIcon, ENABLED);
107 style.uninstallDefaults(context);
108 context.dispose();
109 style = null;
110 }
111
112 public SynthContext getContext(JComponent c) {
113 return getContext(c, getComponentState(c));
114 }
115
116 private SynthContext getContext(JComponent c, int state) {
117 Region region = getRegion(c);
118 return SynthContext.getContext(SynthContext.class, c, region,
119 style, state);
120 }
121
122 private int getComponentState(JComponent c) {
123 return SynthLookAndFeel.getComponentState(c);
124 }
125
126 Region getRegion(JComponent c) {
127 return SynthLookAndFeel.getRegion(c);
128 }
129
130 public void update(Graphics g, JComponent c) {
131 SynthContext context = getContext(c);
132
133 SynthLookAndFeel.update(context, g);
134 context.getPainter().paintDesktopIconBackground(context, g, 0,
135 0, c.getWidth(), c.getHeight());
136 paint(context, g);
137 context.dispose();
138 }
139
140 public void paint(Graphics g, JComponent c) {
141 SynthContext context = getContext(c);
142
143 paint(context, g);
144 context.dispose();
145 }
146
147 protected void paint(SynthContext context, Graphics g) {
148 }
149
150 public void paintBorder(SynthContext context, Graphics g, int x,
151 int y, int w, int h) {
152 context.getPainter().paintDesktopIconBorder(context, g, x, y,
153 w, h);
154 }
155
156 public void actionPerformed(ActionEvent evt) {
157 if (evt.getSource() instanceof JToggleButton) {
158 // Either iconify the frame or deiconify and activate it.
159 JToggleButton button = (JToggleButton) evt.getSource();
160 try {
161 boolean selected = button.isSelected();
162 if (!selected && !frame.isIconifiable()) {
163 button.setSelected(true);
164 } else {
165 frame.setIcon(!selected);
166 if (selected) {
167 frame.setSelected(true);
168 }
169 }
170 } catch (PropertyVetoException e2) {
171 }
172 }
173 }
174
175 public void propertyChange(PropertyChangeEvent evt) {
176 if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) {
177 if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
178 updateStyle((JInternalFrame.JDesktopIcon) evt
179 .getSource());
180 }
181 } else if (evt.getSource() instanceof JInternalFrame) {
182 JInternalFrame frame = (JInternalFrame) evt.getSource();
183 if (iconPane instanceof JToggleButton) {
184 JToggleButton button = (JToggleButton) iconPane;
185 String prop = evt.getPropertyName();
186 if (prop == "title") {
187 button.setText((String) evt.getNewValue());
188 } else if (prop == "frameIcon") {
189 button.setIcon((Icon) evt.getNewValue());
190 } else if (prop == JInternalFrame.IS_ICON_PROPERTY
191 || prop == JInternalFrame.IS_SELECTED_PROPERTY) {
192 button.setSelected(!frame.isIcon()
193 && frame.isSelected());
194 }
195 }
196 }
197 }
198 }
|