Source Code Cross Referenced for SynthListUI.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-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 javax.swing.*;
029        import javax.swing.border.*;
030        import javax.swing.event.*;
031        import javax.swing.plaf.*;
032        import javax.swing.plaf.basic.*;
033        import javax.swing.text.Position;
034
035        import java.awt.*;
036        import java.awt.event.*;
037        import java.awt.datatransfer.Transferable;
038        import java.awt.dnd.*;
039
040        import java.util.ArrayList;
041        import java.util.TooManyListenersException;
042
043        import java.beans.PropertyChangeListener;
044        import java.beans.PropertyChangeEvent;
045        import sun.swing.plaf.synth.SynthUI;
046
047        /**
048         * Synth's ListUI.
049         *
050         * @version 1.19, 05/05/07
051         * @author Scott Violet
052         */
053        class SynthListUI extends BasicListUI implements 
054                PropertyChangeListener, SynthUI {
055            private SynthStyle style;
056            private boolean useListColors;
057            private boolean useUIBorder;
058
059            public static ComponentUI createUI(JComponent list) {
060                return new SynthListUI();
061            }
062
063            public void update(Graphics g, JComponent c) {
064                SynthContext context = getContext(c);
065
066                SynthLookAndFeel.update(context, g);
067                context.getPainter().paintListBackground(context, g, 0, 0,
068                        c.getWidth(), c.getHeight());
069                context.dispose();
070                paint(g, c);
071            }
072
073            public void paintBorder(SynthContext context, Graphics g, int x,
074                    int y, int w, int h) {
075                context.getPainter().paintListBorder(context, g, x, y, w, h);
076            }
077
078            protected void installListeners() {
079                super .installListeners();
080                list.addPropertyChangeListener(this );
081            }
082
083            public void propertyChange(PropertyChangeEvent e) {
084                if (SynthLookAndFeel.shouldUpdateStyle(e)) {
085                    updateStyle((JList) e.getSource());
086                }
087            }
088
089            protected void uninstallListeners() {
090                super .uninstallListeners();
091                list.removePropertyChangeListener(this );
092            }
093
094            protected void installDefaults() {
095                if (list.getCellRenderer() == null
096                        || (list.getCellRenderer() instanceof  UIResource)) {
097                    list.setCellRenderer(new SynthListCellRenderer());
098                }
099                updateStyle(list);
100            }
101
102            private void updateStyle(JComponent c) {
103                SynthContext context = getContext(list, ENABLED);
104                SynthStyle oldStyle = style;
105
106                style = SynthLookAndFeel.updateStyle(context, this );
107
108                if (style != oldStyle) {
109                    context.setComponentState(SELECTED);
110                    Color sbg = list.getSelectionBackground();
111                    if (sbg == null || sbg instanceof  UIResource) {
112                        list.setSelectionBackground(style.getColor(context,
113                                ColorType.TEXT_BACKGROUND));
114                    }
115
116                    Color sfg = list.getSelectionForeground();
117                    if (sfg == null || sfg instanceof  UIResource) {
118                        list.setSelectionForeground(style.getColor(context,
119                                ColorType.TEXT_FOREGROUND));
120                    }
121
122                    useListColors = style.getBoolean(context,
123                            "List.rendererUseListColors", true);
124                    useUIBorder = style.getBoolean(context,
125                            "List.rendererUseUIBorder", true);
126
127                    int height = style.getInt(context, "List.cellHeight", -1);
128                    if (height != -1) {
129                        list.setFixedCellHeight(height);
130                    }
131                    if (oldStyle != null) {
132                        uninstallKeyboardActions();
133                        installKeyboardActions();
134                    }
135                }
136                context.dispose();
137            }
138
139            protected void uninstallDefaults() {
140                super .uninstallDefaults();
141
142                SynthContext context = getContext(list, ENABLED);
143
144                style.uninstallDefaults(context);
145                context.dispose();
146                style = null;
147            }
148
149            public SynthContext getContext(JComponent c) {
150                return getContext(c, getComponentState(c));
151            }
152
153            private SynthContext getContext(JComponent c, int state) {
154                return SynthContext.getContext(SynthContext.class, c,
155                        SynthLookAndFeel.getRegion(c), style, state);
156            }
157
158            private Region getRegion(JComponent c) {
159                return SynthLookAndFeel.getRegion(c);
160            }
161
162            private int getComponentState(JComponent c) {
163                return SynthLookAndFeel.getComponentState(c);
164            }
165
166            private class SynthListCellRenderer extends
167                    DefaultListCellRenderer.UIResource {
168                public String getName() {
169                    return "List.cellRenderer";
170                }
171
172                public void setBorder(Border b) {
173                    if (useUIBorder || b instanceof  SynthBorder) {
174                        super .setBorder(b);
175                    }
176                }
177
178                public Component getListCellRendererComponent(JList list,
179                        Object value, int index, boolean isSelected,
180                        boolean cellHasFocus) {
181                    if (!useListColors && (isSelected || cellHasFocus)) {
182                        SynthLookAndFeel.setSelectedUI(
183                                (SynthLabelUI) SynthLookAndFeel.getUIOfType(
184                                        getUI(), SynthLabelUI.class),
185                                isSelected, cellHasFocus, list.isEnabled(),
186                                false);
187                    } else {
188                        SynthLookAndFeel.resetSelectedUI();
189                    }
190
191                    super .getListCellRendererComponent(list, value, index,
192                            isSelected, cellHasFocus);
193                    return this ;
194                }
195
196                public void paint(Graphics g) {
197                    super.paint(g);
198                    SynthLookAndFeel.resetSelectedUI();
199                }
200            }
201        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.