Source Code Cross Referenced for SynthDesktopIconUI.java in  » 6.0-JDK-Core » swing » javax » swing » plaf » synth » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing.plaf.synth 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.