Source Code Cross Referenced for SetFontPolicy.java in  » Swing-Library » substance-look-feel » test » samples » substance » api » 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 » substance look feel » test.samples.substance.api 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without 
005:         * modification, are permitted provided that the following conditions are met:
006:         * 
007:         *  o Redistributions of source code must retain the above copyright notice, 
008:         *    this list of conditions and the following disclaimer. 
009:         *     
010:         *  o Redistributions in binary form must reproduce the above copyright notice, 
011:         *    this list of conditions and the following disclaimer in the documentation 
012:         *    and/or other materials provided with the distribution. 
013:         *     
014:         *  o Neither the name of Substance Kirill Grouchnikov nor the names of 
015:         *    its contributors may be used to endorse or promote products derived 
016:         *    from this software without specific prior written permission. 
017:         *     
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
029:         */
030:        package test.samples.substance.api;
031:
032:        import java.awt.*;
033:
034:        import javax.swing.*;
035:        import javax.swing.event.ChangeEvent;
036:        import javax.swing.event.ChangeListener;
037:        import javax.swing.plaf.FontUIResource;
038:
039:        import org.jvnet.substance.SubstanceLookAndFeel;
040:        import org.jvnet.substance.fonts.FontPolicy;
041:        import org.jvnet.substance.fonts.FontSet;
042:        import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;
043:
044:        /**
045:         * Test application that shows the use of the
046:         * {@link SubstanceLookAndFeel#setFontPolicy(FontPolicy)} API.
047:         * 
048:         * @author Kirill Grouchnikov
049:         * @see SubstanceLookAndFeel#setFontPolicy(FontPolicy)
050:         */
051:        public class SetFontPolicy extends JFrame {
052:            /**
053:             * Wrapper around the base Substance font set. Is used to create larger /
054:             * smaller font sets.
055:             * 
056:             * @author Kirill Grouchnikov
057:             */
058:            private static class WrapperFontSet implements  FontSet {
059:                /**
060:                 * Extra size in pixels. Can be positive or negative.
061:                 */
062:                private int extra;
063:
064:                /**
065:                 * The base Substance font set.
066:                 */
067:                private FontSet delegate;
068:
069:                /**
070:                 * Creates a wrapper font set.
071:                 * 
072:                 * @param delegate
073:                 *            The base Substance font set.
074:                 * @param extra
075:                 *            Extra size in pixels. Can be positive or negative.
076:                 */
077:                public WrapperFontSet(FontSet delegate, int extra) {
078:                    super ();
079:                    this .delegate = delegate;
080:                    this .extra = extra;
081:                }
082:
083:                /**
084:                 * Returns the wrapped font.
085:                 * 
086:                 * @param systemFont
087:                 *            Original font.
088:                 * @return Wrapped font.
089:                 */
090:                private FontUIResource getWrappedFont(FontUIResource systemFont) {
091:                    return new FontUIResource(systemFont.getFontName(),
092:                            systemFont.getStyle(), systemFont.getSize()
093:                                    + this .extra);
094:                }
095:
096:                public FontUIResource getControlFont() {
097:                    return this .getWrappedFont(this .delegate.getControlFont());
098:                }
099:
100:                public FontUIResource getMenuFont() {
101:                    return this .getWrappedFont(this .delegate.getMenuFont());
102:                }
103:
104:                public FontUIResource getMessageFont() {
105:                    return this .getWrappedFont(this .delegate.getMessageFont());
106:                }
107:
108:                public FontUIResource getSmallFont() {
109:                    return this .getWrappedFont(this .delegate.getSmallFont());
110:                }
111:
112:                public FontUIResource getTitleFont() {
113:                    return this .getWrappedFont(this .delegate.getTitleFont());
114:                }
115:
116:                public FontUIResource getWindowTitleFont() {
117:                    return this .getWrappedFont(this .delegate
118:                            .getWindowTitleFont());
119:                }
120:            }
121:
122:            /**
123:             * Creates the main frame for <code>this</code> sample.
124:             */
125:            public SetFontPolicy() {
126:                super ("Set font policy");
127:
128:                this .setLayout(new BorderLayout());
129:
130:                JPanel panel = new JPanel(new FlowLayout());
131:
132:                // create a slider to control the font size.
133:                final JSlider fontSizeSlider = new JSlider(-3, 3, 0);
134:                fontSizeSlider.setPaintLabels(true);
135:                fontSizeSlider.setMajorTickSpacing(1);
136:                fontSizeSlider
137:                        .setToolTipText("Controls the global font set size");
138:                fontSizeSlider.addChangeListener(new ChangeListener() {
139:                    public void stateChanged(ChangeEvent e) {
140:                        // if the value is adjusting - ignore. This is done
141:                        // to make CPU usage better.
142:                        if (!fontSizeSlider.getModel().getValueIsAdjusting()) {
143:                            final int newValue = fontSizeSlider.getValue();
144:                            SwingUtilities.invokeLater(new Runnable() {
145:                                public void run() {
146:                                    // reset the base font policy to null - this 
147:                                    // restores the original font policy (default size).
148:                                    SubstanceLookAndFeel.setFontPolicy(null);
149:                                    // Get the default font set
150:                                    final FontSet substanceCoreFontSet = SubstanceLookAndFeel
151:                                            .getFontPolicy().getFontSet(
152:                                                    "Substance", null);
153:                                    // Create the wrapper font set
154:                                    FontPolicy newFontPolicy = new FontPolicy() {
155:                                        public FontSet getFontSet(
156:                                                String lafName, UIDefaults table) {
157:                                            return new WrapperFontSet(
158:                                                    substanceCoreFontSet,
159:                                                    newValue);
160:                                        }
161:                                    };
162:
163:                                    try {
164:                                        SetFontPolicy.this 
165:                                                .setCursor(Cursor
166:                                                        .getPredefinedCursor(Cursor.WAIT_CURSOR));
167:                                        // set the new font policy
168:                                        SubstanceLookAndFeel
169:                                                .setFontPolicy(newFontPolicy);
170:                                        // reset the LAF to have the changes
171:                                        UIManager
172:                                                .setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
173:                                        SwingUtilities
174:                                                .updateComponentTreeUI(SetFontPolicy.this );
175:                                        SetFontPolicy.this .setCursor(Cursor
176:                                                .getDefaultCursor());
177:                                    } catch (Exception exc) {
178:                                        exc.printStackTrace();
179:                                    }
180:                                }
181:                            });
182:                        }
183:                    }
184:                });
185:                panel.add(fontSizeSlider);
186:
187:                panel.add(new JButton("button"));
188:                panel.add(new JComboBox(new Object[] { "item1", "item2" }));
189:                //JSlider slider = new JSlider();
190:                //slider.setEnabled(false);
191:                //panel.add(slider);
192:
193:                this .add(panel, BorderLayout.CENTER);
194:
195:                this .setSize(400, 200);
196:                this .setLocationRelativeTo(null);
197:                this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
198:            }
199:
200:            /**
201:             * The main method for <code>this</code> sample. The arguments are
202:             * ignored.
203:             * 
204:             * @param args
205:             *            Ignored.
206:             * @throws Exception
207:             *             If some exception occured. Note that there is no special
208:             *             treatment of exception conditions in <code>this</code>
209:             *             sample code.
210:             */
211:            public static void main(String[] args) throws Exception {
212:                UIManager
213:                        .setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
214:                JFrame.setDefaultLookAndFeelDecorated(true);
215:                JDialog.setDefaultLookAndFeelDecorated(true);
216:                SwingUtilities.invokeLater(new Runnable() {
217:                    public void run() {
218:                        new SetFontPolicy().setVisible(true);
219:                    }
220:                });
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.