Source Code Cross Referenced for JFontChooser.java in  » Swing-Library » l2fprod-common » com » l2fprod » common » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » l2fprod common » com.l2fprod.common.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * L2FProd.com Common Components 7.3 License.
003:         *
004:         * Copyright 2005-2007 L2FProd.com
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */package com.l2fprod.common.swing;
018:
019:        import com.l2fprod.common.swing.plaf.FontChooserUI;
020:        import com.l2fprod.common.swing.plaf.JFontChooserAddon;
021:        import com.l2fprod.common.swing.plaf.LookAndFeelAddons;
022:
023:        import java.awt.BorderLayout;
024:        import java.awt.Component;
025:        import java.awt.Dialog;
026:        import java.awt.Font;
027:        import java.awt.Frame;
028:        import java.awt.Window;
029:
030:        import javax.swing.JComponent;
031:        import javax.swing.JOptionPane;
032:        import javax.swing.SwingUtilities;
033:
034:        /**
035:         * <code>JFontChooser</code> provides a pane of controls designed to allow a
036:         * user to manipulate and select a font.
037:         * 
038:         * @javabean.class
039:         *          name="JFontChooser"
040:         *          shortDescription="A component that supports selecting a Font."
041:         *          stopClass="javax.swing.JComponent"
042:         * 
043:         * @javabean.attribute
044:         *          name="isContainer"
045:         *          value="Boolean.FALSE"
046:         *          rtexpr="true"
047:         * 
048:         * @javabean.icons
049:         *          mono16="JFontChooser16-mono.gif"
050:         *          color16="JFontChooser16.gif"
051:         *          mono32="JFontChooser32-mono.gif"
052:         *          color32="JFontChooser32.gif"
053:         */
054:        public class JFontChooser extends JComponent {
055:
056:            // ensure at least the default ui is registered
057:            static {
058:                LookAndFeelAddons.contribute(new JFontChooserAddon());
059:            }
060:
061:            public static final String SELECTED_FONT_CHANGED_KEY = "selectedFont";
062:
063:            protected Font selectedFont;
064:
065:            private FontChooserModel model;
066:
067:            /**
068:             * Creates a font chooser with an initial default font and a default
069:             * model.
070:             */
071:            public JFontChooser() {
072:                this (new DefaultFontChooserModel());
073:            }
074:
075:            /**
076:             * Creates a font chooser with an initial default font and a custom
077:             * model.
078:             * 
079:             * @param model
080:             */
081:            public JFontChooser(FontChooserModel model) {
082:                super ();
083:                this .model = model;
084:                selectedFont = getFont();
085:                updateUI();
086:            }
087:
088:            /**
089:             * Notification from the <code>UIManager</code> that the L&F has
090:             * changed. Replaces the current UI object with the latest version
091:             * from the <code>UIManager</code>.
092:             * 
093:             * @see javax.swing.JComponent#updateUI
094:             */
095:            public void updateUI() {
096:                setUI((FontChooserUI) LookAndFeelAddons.getUI(this ,
097:                        FontChooserUI.class));
098:            }
099:
100:            /**
101:             * Sets the L&F object that renders this component.
102:             * 
103:             * @param ui the <code>FontChooserUI</code> L&F object
104:             * @see javax.swing.UIDefaults#getUI
105:             * 
106:             * @beaninfo
107:             *  bound: true
108:             *  hidden: true
109:             *  description: The UI object that implements the font chooser's LookAndFeel.
110:             */
111:            public void setUI(FontChooserUI ui) {
112:                super .setUI(ui);
113:            }
114:
115:            /**
116:             * Returns the name of the L&F class that renders this component.
117:             * 
118:             * @return the string "FontChooserUI"
119:             * @see javax.swing.JComponent#getUIClassID
120:             * @see javax.swing.UIDefaults#getUI
121:             */
122:            public String getUIClassID() {
123:                return "FontChooserUI";
124:            }
125:
126:            /**
127:             * Sets the selected font of this JFontChooser. This will fire a <code>PropertyChangeEvent</code>
128:             * for the property named {@link #SELECTED_FONT_CHANGED_KEY}.
129:             * 
130:             * @param f the font to select
131:             * @see javax.swing.JComponent#addPropertyChangeListener(java.beans.PropertyChangeListener)
132:             * 
133:             * @javabean.property
134:             *  bound="true"
135:             *  preferred="true"
136:             *  shortDescription="The current font the chooser is to display"
137:             */
138:            public void setSelectedFont(Font f) {
139:                Font oldFont = selectedFont;
140:                selectedFont = f;
141:                firePropertyChange(SELECTED_FONT_CHANGED_KEY, oldFont,
142:                        selectedFont);
143:            }
144:
145:            /**
146:             * Gets the current font value from the font chooser.
147:             * 
148:             * @return the current font value of the font chooser
149:             */
150:            public Font getSelectedFont() {
151:                return selectedFont;
152:            }
153:
154:            /**
155:             * Gets the font chooser model of this font chooser.
156:             * 
157:             * @return the font chooser model of this font chooser.
158:             */
159:            public FontChooserModel getModel() {
160:                return model;
161:            }
162:
163:            /**
164:             * Shows a modal font-chooser dialog and blocks until the dialog is
165:             * hidden. If the user presses the "OK" button, then this method
166:             * hides/disposes the dialog and returns the selected color. If the
167:             * user presses the "Cancel" button or closes the dialog without
168:             * pressing "OK", then this method hides/disposes the dialog and
169:             * returns <code>null</code>.
170:             * 
171:             * @param parent the parent <code>Component</code> for the
172:             *          dialog
173:             * @param title the String containing the dialog's title
174:             * @return the selected font or <code>null</code> if the user
175:             *         opted out
176:             * @exception java.awt.HeadlessException if GraphicsEnvironment.isHeadless()
177:             *              returns true.
178:             * @see java.awt.GraphicsEnvironment#isHeadless
179:             */
180:            public Font showFontDialog(Component parent, String title) {
181:                BaseDialog dialog = createDialog(parent, title);
182:                if (dialog.ask()) {
183:                    return getSelectedFont();
184:                } else {
185:                    return null;
186:                }
187:            }
188:
189:            protected BaseDialog createDialog(Component parent, String title) {
190:                BaseDialog dialog;
191:                Window window = (parent == null ? JOptionPane.getRootFrame()
192:                        : SwingUtilities.windowForComponent(parent));
193:                if (window instanceof  Frame) {
194:                    dialog = new BaseDialog((Frame) window, title, true);
195:                } else {
196:                    dialog = new BaseDialog((Dialog) window, title, true);
197:                }
198:                dialog.setDialogMode(BaseDialog.OK_CANCEL_DIALOG);
199:                dialog.getBanner().setVisible(false);
200:
201:                dialog.getContentPane().setLayout(new BorderLayout());
202:                dialog.getContentPane().add("Center", this );
203:                dialog.pack();
204:                dialog.setLocationRelativeTo(parent);
205:
206:                return dialog;
207:            }
208:
209:            /**
210:             * Similar to {@link #showFontDialog(Component, String)} except it can be
211:             * called from a static context. Prefer
212:             * {@link #showFontDialog(Component, String)} if you want to control the
213:             * dialog created by the method call or if you want to specify a custom
214:             * {@link FontChooserModel}.
215:             * 
216:             * @param parent
217:             *          the parent <code>Component</code> for the dialog
218:             * @param title
219:             *          the String containing the dialog's title
220:             * @param initialFont
221:             *          the initial Font set when the font-chooser is shown
222:             * @return the selected font or <code>null</code> if the user opted out
223:             * @exception java.awt.HeadlessException
224:             *              if GraphicsEnvironment.isHeadless() returns true.
225:             * @see java.awt.GraphicsEnvironment#isHeadless
226:             * @see #showFontDialog(Component, String)
227:             */
228:            public static Font showDialog(Component parent, String title,
229:                    Font initialFont) {
230:                JFontChooser chooser = new JFontChooser();
231:                chooser.setSelectedFont(initialFont);
232:                return chooser.showFontDialog(parent, title);
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.