Source Code Cross Referenced for FontChooser.java in  » Testing » abbot-1.0.1 » example » 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 » Testing » abbot 1.0.1 » example 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package example;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:        import java.beans.*;
006:
007:        import javax.swing.*;
008:        import javax.swing.border.EmptyBorder;
009:
010:        /**
011:         * Select a font
012:         */
013:
014:        public class FontChooser extends JPanel implements 
015:                PropertyChangeListener, ItemListener {
016:            protected Font specifiedFont = new Font("Serif", Font.PLAIN, 10);
017:            protected JComboBox name;
018:            protected JCheckBox bold, italic;
019:            protected NumberChooser size;
020:            protected static String[] availableFonts = null;
021:
022:            public FontChooser() {
023:                setLayout(new GridLayout(2, 2));
024:                if (availableFonts == null) {
025:                    GraphicsEnvironment ge = GraphicsEnvironment
026:                            .getLocalGraphicsEnvironment();
027:                    availableFonts = ge.getAvailableFontFamilyNames();
028:                }
029:                name = new JComboBox(availableFonts);
030:                name.setSelectedItem(specifiedFont.getName());
031:                name.addItemListener(this );
032:                add(name);
033:                size = new NumberChooser(1, 128, specifiedFont.getSize());
034:                add(size);
035:                size.setColumns(3);
036:                size.addPropertyChangeListener(this );
037:                add(bold = new JCheckBox("bold"));
038:                bold.setSelected(specifiedFont.isBold());
039:                bold.addItemListener(this );
040:                add(italic = new JCheckBox("italic"));
041:                italic.setSelected(specifiedFont.isItalic());
042:                italic.addItemListener(this );
043:            }
044:
045:            public void setSpecifiedFont(Font f) {
046:                name.setSelectedItem(f.getName());
047:                bold.setSelected(f.isBold());
048:                italic.setSelected(f.isItalic());
049:                size.setValue(f.getSize());
050:                fireStateChange();
051:            }
052:
053:            public Font getSpecifiedFont() {
054:                return new Font((String) name.getSelectedItem(), (bold
055:                        .isSelected() ? Font.BOLD : 0)
056:                        | (italic.isSelected() ? Font.ITALIC : 0), size
057:                        .getValue());
058:            }
059:
060:            public void itemStateChanged(ItemEvent e) {
061:                fireStateChange();
062:            }
063:
064:            public void propertyChange(PropertyChangeEvent e) {
065:                fireStateChange();
066:            }
067:
068:            protected PropertyChangeSupport listeners = new PropertyChangeSupport(
069:                    this );
070:
071:            public void addPropertyChangeListener(PropertyChangeListener l) {
072:                listeners.addPropertyChangeListener(l);
073:            }
074:
075:            public void removePropertyChangeListener(PropertyChangeListener l) {
076:                listeners.removePropertyChangeListener(l);
077:            }
078:
079:            /** update our internal font, then tell everyone about it */
080:            protected void fireStateChange() {
081:                Font oldFont = specifiedFont;
082:                specifiedFont = getSpecifiedFont();
083:                listeners.firePropertyChange("style", oldFont, specifiedFont);
084:            }
085:
086:            /** Put up a frame containing a font chooser to make it easy for a script
087:             * to play with.
088:             */
089:            public static void main(String[] args) {
090:                final JFrame frame = new JFrame("Font Chooser unit test");
091:                frame.addWindowListener(new WindowAdapter() {
092:                    public void windowClosing(WindowEvent e) {
093:                        frame.dispose();
094:                    }
095:                });
096:                final JPanel panel = new JPanel(new BorderLayout());
097:                //panel.setBorder(new EmptyBorder(10, 10, 10, 10));
098:                String text = "The quick brown fox jumped over the lazy dog";
099:                FontChooser chooser = new FontChooser();
100:                panel.add(chooser, BorderLayout.NORTH);
101:                final JLabel label = new JLabel(text);
102:                panel.add(label, BorderLayout.CENTER);
103:                label.setFont(chooser.getSpecifiedFont());
104:                frame.getContentPane().add(panel);
105:                ((JPanel) frame.getContentPane()).setBorder(new EmptyBorder(4,
106:                        4, 4, 4));
107:
108:                // Position the frame away from the screen edge to avoid stupid
109:                // toolbars and such
110:                frame.setLocation(new Point(50, 50));
111:                frame.setSize(400, 300);
112:                frame.pack();
113:
114:                Dimension s1 = panel.getPreferredSize();
115:                Dimension s2 = frame.getPreferredSize();
116:                final int hoff = s2.height - s1.height;
117:                final int width = s2.width;
118:                chooser.addPropertyChangeListener(new PropertyChangeListener() {
119:                    public void propertyChange(PropertyChangeEvent ev) {
120:                        label.setFont((Font) ev.getNewValue());
121:                        if (frame != null) {
122:                            Dimension size = panel.getPreferredSize();
123:                            size.height += hoff;
124:                            size.width = width;
125:                            frame.setSize(size);
126:                        }
127:                    }
128:                });
129:                frame.setVisible(true);
130:            }
131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.