Source Code Cross Referenced for SynthOptionPaneUI.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.beans.*;
030        import javax.swing.*;
031        import javax.swing.event.*;
032        import javax.swing.plaf.*;
033        import javax.swing.plaf.basic.*;
034        import sun.swing.DefaultLookup;
035        import sun.swing.plaf.synth.SynthUI;
036
037        /**
038         * Synth's OptionPaneUI.
039         * 
040         * @version 1.21, 05/05/07
041         * @author James Gosling
042         * @author Scott Violet
043         * @author Amy Fowler
044         */
045        class SynthOptionPaneUI extends BasicOptionPaneUI implements 
046                PropertyChangeListener, SynthUI {
047            private SynthStyle style;
048
049            /**
050             * Creates a new BasicOptionPaneUI instance.
051             */
052            public static ComponentUI createUI(JComponent x) {
053                return new SynthOptionPaneUI();
054            }
055
056            protected void installDefaults() {
057                updateStyle(optionPane);
058            }
059
060            protected void installListeners() {
061                super .installListeners();
062                optionPane.addPropertyChangeListener(this );
063            }
064
065            private void updateStyle(JComponent c) {
066                SynthContext context = getContext(c, ENABLED);
067                SynthStyle oldStyle = style;
068
069                style = SynthLookAndFeel.updateStyle(context, this );
070                if (style != oldStyle) {
071                    minimumSize = (Dimension) style.get(context,
072                            "OptionPane.minimumSize");
073                    if (minimumSize == null) {
074                        minimumSize = new Dimension(262, 90);
075                    }
076                    if (oldStyle != null) {
077                        uninstallKeyboardActions();
078                        installKeyboardActions();
079                    }
080                }
081                context.dispose();
082            }
083
084            protected void uninstallDefaults() {
085                SynthContext context = getContext(optionPane, ENABLED);
086
087                style.uninstallDefaults(context);
088                context.dispose();
089                style = null;
090            }
091
092            protected void uninstallListeners() {
093                super .uninstallListeners();
094                optionPane.removePropertyChangeListener(this );
095            }
096
097            protected void installComponents() {
098                optionPane.add(createMessageArea());
099
100                Container separator = createSeparator();
101                if (separator != null) {
102                    optionPane.add(separator);
103                    SynthContext context = getContext(optionPane, ENABLED);
104                    optionPane
105                            .add(Box.createVerticalStrut(context.getStyle()
106                                    .getInt(context,
107                                            "OptionPane.separatorPadding", 6)));
108                    context.dispose();
109                }
110                optionPane.add(createButtonArea());
111                optionPane.applyComponentOrientation(optionPane
112                        .getComponentOrientation());
113            }
114
115            public SynthContext getContext(JComponent c) {
116                return getContext(c, getComponentState(c));
117            }
118
119            private SynthContext getContext(JComponent c, int state) {
120                return SynthContext.getContext(SynthContext.class, c,
121                        SynthLookAndFeel.getRegion(c), style, state);
122            }
123
124            private Region getRegion(JComponent c) {
125                return SynthLookAndFeel.getRegion(c);
126            }
127
128            private int getComponentState(JComponent c) {
129                return SynthLookAndFeel.getComponentState(c);
130            }
131
132            public void update(Graphics g, JComponent c) {
133                SynthContext context = getContext(c);
134
135                SynthLookAndFeel.update(context, g);
136                context.getPainter().paintOptionPaneBackground(context, g, 0,
137                        0, c.getWidth(), c.getHeight());
138                paint(context, g);
139                context.dispose();
140            }
141
142            public void paint(Graphics g, JComponent c) {
143                SynthContext context = getContext(c);
144
145                paint(context, g);
146                context.dispose();
147            }
148
149            protected void paint(SynthContext context, Graphics g) {
150            }
151
152            public void paintBorder(SynthContext context, Graphics g, int x,
153                    int y, int w, int h) {
154                context.getPainter().paintOptionPaneBorder(context, g, x, y, w,
155                        h);
156            }
157
158            public void propertyChange(PropertyChangeEvent e) {
159                if (SynthLookAndFeel.shouldUpdateStyle(e)) {
160                    updateStyle((JOptionPane) e.getSource());
161                }
162            }
163
164            protected boolean getSizeButtonsToSameWidth() {
165                return DefaultLookup.getBoolean(optionPane, this ,
166                        "OptionPane.sameSizeButtons", true);
167            }
168
169            /**
170             * Messaged from installComponents to create a Container containing the
171             * body of the message. The icon is the created by calling
172             * <code>addIcon</code>.
173             */
174            protected Container createMessageArea() {
175                JPanel top = new JPanel();
176                top.setName("OptionPane.messageArea");
177                top.setLayout(new BorderLayout());
178
179                /* Fill the body. */
180                Container body = new JPanel(new GridBagLayout());
181                Container realBody = new JPanel(new BorderLayout());
182
183                body.setName("OptionPane.body");
184                realBody.setName("OptionPane.realBody");
185
186                if (getIcon() != null) {
187                    JPanel sep = new JPanel();
188                    sep.setName("OptionPane.separator");
189                    sep.setPreferredSize(new Dimension(15, 1));
190                    realBody.add(sep, BorderLayout.BEFORE_LINE_BEGINS);
191                }
192                realBody.add(body, BorderLayout.CENTER);
193
194                GridBagConstraints cons = new GridBagConstraints();
195                cons.gridx = cons.gridy = 0;
196                cons.gridwidth = GridBagConstraints.REMAINDER;
197                cons.gridheight = 1;
198
199                SynthContext context = getContext(optionPane, ENABLED);
200                cons.anchor = context.getStyle().getInt(context,
201                        "OptionPane.messageAnchor", GridBagConstraints.CENTER);
202                context.dispose();
203
204                cons.insets = new Insets(0, 0, 3, 0);
205
206                addMessageComponents(body, cons, getMessage(),
207                        getMaxCharactersPerLineCount(), false);
208                top.add(realBody, BorderLayout.CENTER);
209
210                addIcon(top);
211                return top;
212            }
213
214            protected Container createSeparator() {
215                JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
216
217                separator.setName("OptionPane.separator");
218                return separator;
219            }
220        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.