Source Code Cross Referenced for FontSelectorPane.java in  » Mail-Clients » pooka » net » suberic » util » gui » propedit » 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 » Mail Clients » pooka » net.suberic.util.gui.propedit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.suberic.util.gui.propedit;
002:
003:        import java.io.*;
004:        import javax.swing.*;
005:        import java.awt.event.*;
006:        import net.suberic.util.swing.JFontChooser;
007:        import java.awt.Font;
008:
009:        /**
010:         * This displays the currently selected file (if any), along with a 
011:         * button which will bring up a FontChooser to choose any other file(s).
012:         *
013:         * If property._enabledBox is set to true, then this also adds a 
014:         * checkbox to show whether or not to use this property, or just to use
015:         * the defaults.
016:         * 
017:         */
018:
019:        public class FontSelectorPane extends SwingPropertyEditor {
020:
021:            JLabel label;
022:            JTextField valueDisplay;
023:            JButton inputButton;
024:
025:            boolean useEnabledBox = false;
026:            JCheckBox enabledBox = null;
027:            boolean origEnabled = false;
028:
029:            /**
030:             * @param propertyName The property to be edited.  
031:             * @param template The property that will define the layout of the 
032:             *                 editor.
033:             * @param manager The PropertyEditorManager that will manage the
034:             *                   changes.
035:             * @param isEnabled Whether or not this editor is enabled by default. 
036:             */
037:            public void configureEditor(String propertyName, String template,
038:                    PropertyEditorManager newManager, boolean isEnabled) {
039:                property = propertyName;
040:                manager = newManager;
041:                editorTemplate = template;
042:                originalValue = manager.getProperty(property, "");
043:
044:                if (debug) {
045:                    System.out.println("property is " + property
046:                            + "; editorTemplate is " + editorTemplate);
047:                }
048:
049:                label = createLabel();
050:
051:                valueDisplay = new JTextField(originalValue);
052:
053:                inputButton = createInputButton();
054:
055:                valueDisplay.setPreferredSize(new java.awt.Dimension(
056:                        150 - inputButton.getPreferredSize().width,
057:                        valueDisplay.getMinimumSize().height));
058:
059:                this .add(label);
060:                labelComponent = label;
061:                JPanel tmpPanel = new JPanel(new java.awt.FlowLayout(
062:                        java.awt.FlowLayout.LEFT, 0, 0));
063:                tmpPanel.add(valueDisplay);
064:                tmpPanel.add(inputButton);
065:                tmpPanel.setPreferredSize(new java.awt.Dimension(150,
066:                        valueDisplay.getMinimumSize().height));
067:
068:                useEnabledBox = manager.getProperty(
069:                        editorTemplate + "._enabledBox", "false")
070:                        .equalsIgnoreCase("true");
071:                if (useEnabledBox) {
072:                    enabledBox = new JCheckBox();
073:                    origEnabled = manager.getProperty(property + "._enabled",
074:                            "false").equalsIgnoreCase("true");
075:                    enabledBox.setSelected(origEnabled);
076:                    enabledBox.addItemListener(new ItemListener() {
077:                        public void itemStateChanged(ItemEvent e) {
078:                            enabledBoxUpdated(enabledBox.isSelected());
079:                        }
080:                    });
081:                    enabledBoxUpdated(origEnabled);
082:                    tmpPanel.add(enabledBox);
083:                }
084:
085:                valueComponent = tmpPanel;
086:                //this.add(valueDisplay);
087:                //this.add(inputButton);
088:                this .add(tmpPanel);
089:
090:                this .setEnabled(isEnabled);
091:
092:                manager.registerPropertyEditor(property, this );
093:            }
094:
095:            /**
096:             * Creates a button that will bring up a way to select a new Font.
097:             */
098:            public JButton createInputButton() {
099:                try {
100:                    java.net.URL url = this .getClass().getResource(
101:                            manager.getProperty(
102:                                    "FontSelectorPane.inputButton.image",
103:                                    "/net/suberic/util/gui/images/More.gif"));
104:                    if (url != null) {
105:                        ImageIcon icon = new ImageIcon(url);
106:
107:                        JButton newButton = new JButton(icon);
108:
109:                        newButton.setPreferredSize(new java.awt.Dimension(icon
110:                                .getIconHeight(), icon.getIconWidth()));
111:                        newButton.addActionListener(new AbstractAction() {
112:                            public void actionPerformed(ActionEvent e) {
113:                                selectNewFont();
114:                            }
115:                        });
116:
117:                        return newButton;
118:                    }
119:                } catch (java.util.MissingResourceException mre) {
120:                }
121:
122:                JButton newButton = new JButton();
123:                newButton.addActionListener(new AbstractAction() {
124:                    public void actionPerformed(ActionEvent e) {
125:                        selectNewFont();
126:                    }
127:                });
128:
129:                return newButton;
130:            }
131:
132:            /**
133:             * This actually brings up a FontChooser to select a new Font for 
134:             * the value of the property.
135:             */
136:            public void selectNewFont() {
137:                String fontText = valueDisplay.getText();
138:                Font f = null;
139:                if (fontText != null && fontText.length() > 0) {
140:                    f = Font.decode(fontText);
141:                }
142:
143:                String newFontText = JFontChooser.showStringDialog(this ,
144:                        manager.getProperty("FontEditorPane.Select", "Select"),
145:                        f);
146:
147:                if (newFontText != null) {
148:                    try {
149:                        firePropertyChangingEvent(newFontText);
150:                        firePropertyChangedEvent(newFontText);
151:                        valueDisplay.setText(newFontText);
152:                    } catch (PropertyValueVetoException pvve) {
153:                        manager.getFactory().showError(
154:                                this ,
155:                                "Error changing value " + label.getText()
156:                                        + " to " + newFontText + ":  "
157:                                        + pvve.getReason());
158:                    }
159:                }
160:
161:            }
162:
163:            //  as defined in net.suberic.util.gui.PropertyEditorUI
164:
165:            /**
166:             * This writes the currently configured value in the PropertyEditorUI
167:             * to the source PropertyEditorManager.
168:             */
169:            public void setValue() {
170:                if (isEnabled() && isChanged()) {
171:                    //System.err.println("setting value for " + property);
172:                    manager.setProperty(property, (String) valueDisplay
173:                            .getText());
174:
175:                    if (useEnabledBox) {
176:                        if (enabledBox.isSelected())
177:                            manager.setProperty(property + "._enabled", "true");
178:                        else
179:                            manager
180:                                    .setProperty(property + "._enabled",
181:                                            "false");
182:                    }
183:                }
184:            }
185:
186:            /**
187:             * Returns the current values of the edited properties as a 
188:             * java.util.Properties object.
189:             */
190:            public java.util.Properties getValue() {
191:                java.util.Properties retProps = new java.util.Properties();
192:
193:                retProps.setProperty(property, (String) valueDisplay.getText());
194:                if (useEnabledBox) {
195:                    if (enabledBox.isSelected())
196:                        retProps.setProperty(property + "._enabled", "true");
197:                    else
198:                        retProps.setProperty(property + "._enabled", "false");
199:                }
200:                return retProps;
201:            }
202:
203:            /**
204:             * This resets the editor to the original (or latest set, if setValue() 
205:             * has been called) value of the edited property.
206:             */
207:            public void resetDefaultValue() {
208:                valueDisplay.setText(originalValue);
209:                if (useEnabledBox)
210:                    enabledBox.setSelected(origEnabled);
211:            }
212:
213:            /**
214:             * Returns whether or not this editor still has its originally configured
215:             * value.
216:             */
217:            public boolean isChanged() {
218:                if (useEnabledBox) {
219:                    return (enabledBox.isSelected() != origEnabled || !(originalValue
220:                            .equals(valueDisplay.getText())));
221:                } else {
222:                    return (!(originalValue.equals(valueDisplay.getText())));
223:                }
224:            }
225:
226:            /**
227:             * Sets the enabled property of the PropertyEditorUI.  Disabled 
228:             * editors should not be able to do setValue() calls.
229:             */
230:            public void setEnabled(boolean newValue) {
231:                if (useEnabledBox) {
232:                    enabledBox.setEnabled(newValue);
233:                    //inputButton.setEnabled(newValue && enabledBox.isSelected());
234:
235:                    if (inputButton != null) {
236:                        inputButton.setEnabled(newValue
237:                                && enabledBox.isSelected());
238:                    }
239:                    if (valueDisplay != null) {
240:                        valueDisplay.setEnabled(newValue
241:                                && enabledBox.isSelected());
242:                    }
243:
244:                } else {
245:                    if (inputButton != null) {
246:                        inputButton.setEnabled(newValue);
247:                    }
248:                    if (valueDisplay != null) {
249:                        valueDisplay.setEnabled(newValue);
250:                    }
251:                }
252:                enabled = newValue;
253:            }
254:
255:            /**
256:             * Called when the enabledBox's value is updated.
257:             */
258:            private void enabledBoxUpdated(boolean newValue) {
259:                if (inputButton != null)
260:                    inputButton.setEnabled(newValue);
261:
262:                if (valueDisplay != null)
263:                    valueDisplay.setEnabled(newValue);
264:            }
265:
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.