KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SynthDesktopIconUI.java 1.13 03/12/19
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 javax.swing.*;
13 import javax.swing.event.*;
14 import javax.swing.border.*;
15 import javax.swing.plaf.*;
16 import javax.swing.plaf.basic.BasicDesktopIconUI JavaDoc;
17 import java.beans.*;
18 import java.io.Serializable JavaDoc;
19 import sun.swing.plaf.synth.SynthUI;
20
21
22 /**
23  * Synth L&F for a minimized window on a desktop.
24  *
25  * @version 1.13, 12/19/03
26  * @author Joshua Outwater
27  */

28 class SynthDesktopIconUI extends BasicDesktopIconUI JavaDoc implements SynthUI,
29                     ActionListener, PropertyChangeListener {
30     private SynthStyle JavaDoc style;
31
32     public static ComponentUI createUI(JComponent c) {
33         return new SynthDesktopIconUI JavaDoc();
34     }
35
36     protected void installComponents() {
37     if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
38         iconPane = new JToggleButton(frame.getTitle(), frame.getFrameIcon()) {
39         public String JavaDoc getToolTipText() {
40             return getText();
41         }
42
43         public JPopupMenu getComponentPopupMenu() {
44             return frame.getComponentPopupMenu();
45         }
46         };
47         ToolTipManager.sharedInstance().registerComponent(iconPane);
48         iconPane.setFont(desktopIcon.getFont());
49         iconPane.setBackground(desktopIcon.getBackground());
50         iconPane.setForeground(desktopIcon.getForeground());
51     } else {
52         iconPane = new SynthInternalFrameTitlePane JavaDoc(frame);
53         iconPane.setName("InternalFrame.northPane");
54     }
55     desktopIcon.setLayout(new BorderLayout());
56     desktopIcon.add(iconPane, BorderLayout.CENTER);
57     }
58
59     protected void installListeners() {
60         super.installListeners();
61         desktopIcon.addPropertyChangeListener(this);
62
63     if (iconPane instanceof JToggleButton) {
64         frame.addPropertyChangeListener(this);
65         ((JToggleButton)iconPane).addActionListener(this);
66     }
67     }
68
69     protected void uninstallListeners() {
70     if (iconPane instanceof JToggleButton) {
71         frame.removePropertyChangeListener(this);
72     }
73         desktopIcon.removePropertyChangeListener(this);
74         super.uninstallListeners();
75     }
76
77     protected void installDefaults() {
78         updateStyle(desktopIcon);
79     }
80
81     private void updateStyle(JComponent c) {
82         SynthContext JavaDoc context = getContext(c, ENABLED);
83         style = SynthLookAndFeel.updateStyle(context, this);
84         context.dispose();
85     }
86
87     protected void uninstallDefaults() {
88         SynthContext JavaDoc context = getContext(desktopIcon, ENABLED);
89         style.uninstallDefaults(context);
90         context.dispose();
91         style = null;
92     }
93
94     public SynthContext JavaDoc getContext(JComponent c) {
95         return getContext(c, getComponentState(c));
96     }
97
98     private SynthContext JavaDoc getContext(JComponent c, int state) {
99         Region JavaDoc region = getRegion(c);
100         return SynthContext.getContext(SynthContext JavaDoc.class, c, region,
101                                        style, state);
102     }
103
104     private int getComponentState(JComponent c) {
105         return SynthLookAndFeel.getComponentState(c);
106     }
107
108     Region JavaDoc getRegion(JComponent c) {
109         return SynthLookAndFeel.getRegion(c);
110     }
111
112     public void update(Graphics g, JComponent c) {
113         SynthContext JavaDoc context = getContext(c);
114
115         SynthLookAndFeel.update(context, g);
116         context.getPainter().paintDesktopIconBackground(context, g, 0, 0,
117                                                   c.getWidth(), c.getHeight());
118         paint(context, g);
119         context.dispose();
120     }
121
122     public void paint(Graphics g, JComponent c) {
123         SynthContext JavaDoc context = getContext(c);
124
125         paint(context, g);
126         context.dispose();
127     }
128
129     protected void paint(SynthContext JavaDoc context, Graphics g) {
130     }
131
132     public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
133                             int y, int w, int h) {
134         context.getPainter().paintDesktopIconBorder(context, g, x, y, w, h);
135     }
136
137     public void actionPerformed(ActionEvent evt) {
138     if (evt.getSource() instanceof JToggleButton) {
139         // Either iconify the frame or deiconify and activate it.
140
JToggleButton button = (JToggleButton)evt.getSource();
141         try {
142         boolean selected = button.isSelected();
143         if (!selected && !frame.isIconifiable()) {
144             button.setSelected(true);
145         } else {
146             frame.setIcon(!selected);
147             if (selected) {
148             frame.setSelected(true);
149             }
150         }
151         } catch (PropertyVetoException e2) {
152         }
153     }
154     }
155
156     public void propertyChange(PropertyChangeEvent evt) {
157     if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) {
158         if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
159         updateStyle((JInternalFrame.JDesktopIcon)evt.getSource());
160         }
161     } else if (evt.getSource() instanceof JInternalFrame) {
162         JInternalFrame frame = (JInternalFrame)evt.getSource();
163         if (iconPane instanceof JToggleButton) {
164         JToggleButton button = (JToggleButton)iconPane;
165         String JavaDoc prop = evt.getPropertyName();
166         if (prop == "title") {
167             button.setText((String JavaDoc)evt.getNewValue());
168         } else if (prop == "frameIcon") {
169             button.setIcon((Icon)evt.getNewValue());
170         } else if (prop == JInternalFrame.IS_ICON_PROPERTY ||
171                prop == JInternalFrame.IS_SELECTED_PROPERTY) {
172             button.setSelected(!frame.isIcon() && frame.isSelected());
173         }
174         }
175     }
176     }
177 }
178
Popular Tags