KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > configuration > lnf > LookAndFeelConfigOptions


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.configuration.lnf;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Component JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.Font JavaDoc;
26 import java.awt.LayoutManager JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.util.HashMap JavaDoc;
30
31 import javax.swing.BorderFactory JavaDoc;
32 import javax.swing.JComboBox JavaDoc;
33 import javax.swing.JLabel JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35 import javax.swing.JTextArea JavaDoc;
36 import javax.swing.UIManager JavaDoc;
37
38 import org.openharmonise.him.configuration.*;
39
40
41 /**
42  * Configuration options for the application Look and Feel. Each option
43  * is represented as a {@link org.openharmonise.him.configuration.lnf.ConfigLnF}
44  * object so that they can each handle their own implementation specific details.
45  *
46  * @author Matthew Large
47  * @version $Revision: 1.2 $
48  *
49  */

50 public class LookAndFeelConfigOptions
51     extends AbstractConfigOptions
52     implements ApplyChangesListener, LayoutManager JavaDoc, ActionListener JavaDoc {
53
54     /**
55      * Skin label.
56      */

57     private JLabel JavaDoc m_label = null;
58     
59     /**
60      * Option values combo box.
61      */

62     private JComboBox JavaDoc m_combo = null;
63
64     /**
65      * Map of option name to {@link ConfigLnF} objects.
66      */

67     private HashMap JavaDoc m_options = new HashMap JavaDoc();
68     
69     /**
70      * true if the selected look and feel has changed.
71      */

72     private boolean m_bChanged = false;
73     
74     /**
75      * Label for automatic positioning of the metadata panel.
76      */

77     private JTextArea JavaDoc m_autoMetadataLabel = null;
78     
79     /**
80      * Options for automatic positioning of the metadata panel.
81      */

82     private JComboBox JavaDoc m_autoMetadataCombo = null;
83     
84     /**
85      * true if the metadata panel is to be automatically positioned.
86      */

87     private boolean m_bAutoMetadataChanged = false;
88     
89     /**
90      * Main options label.
91      */

92     private JLabel JavaDoc m_optionsLabel = null;
93     
94     /**
95      * Panel for border line.
96      */

97     private JPanel JavaDoc m_borderPanel = null;
98
99     public LookAndFeelConfigOptions() {
100         super(null);
101         this.setup();
102     }
103
104     /**
105      * Constructs a new look and feel config options.
106      *
107      * @param dialog Config dialog that will display these options
108      */

109     public LookAndFeelConfigOptions(ConfigDialog dialog) {
110         super(dialog);
111         dialog.addApplyChangesListener(this);
112         this.setup();
113     }
114     
115     /**
116      * Configures this options class.
117      *
118      */

119     private void setup() {
120         this.setLayout(this);
121         
122         this.m_optionsLabel = new JLabel JavaDoc("Look and feel");
123         this.add(this.m_optionsLabel);
124         
125         this.m_options.put("Native", new ConfigLnF( UIManager.getSystemLookAndFeelClassName(), this.m_dialog ));
126         this.m_options.put("Java", new ConfigLnF( UIManager.getCrossPlatformLookAndFeelClassName(), this.m_dialog ));
127         this.m_options.put("Modern", new ConfigSkinLnF("/themes/modernthemepack.zip", this.m_dialog));
128         this.m_options.put("Toxic", new ConfigSkinLnF("/themes/toxicthemepack.zip", this.m_dialog));
129         this.m_options.put("Whistler", new ConfigSkinLnF("/themes/whistlerthemepack.zip", this.m_dialog));
130         //this.m_options.put("Kunststoff", new ConfigLnF("com.incors.plaf.kunststoff.KunststoffLookAndFeel", this.m_dialog));
131

132         this.m_combo = new JComboBox JavaDoc(this.m_options.keySet().toArray());
133         
134         String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("LnF");
135         if(sValue!=null) {
136             this.m_combo.setSelectedItem(sValue);
137         } else {
138             this.m_combo.setSelectedItem("Whistler");
139         }
140         this.m_combo.addActionListener(this);
141         this.m_combo.setActionCommand("LNFLIST");
142         
143         this.add(m_combo);
144         
145         this.m_label = new JLabel JavaDoc("Choose skin");
146         this.add(m_label);
147         
148         sValue = ConfigStore.getInstance().getPropertyValue("AUTO_METADATA_POSITION");
149         
150         this.m_autoMetadataLabel = new JTextArea JavaDoc("Automatically position metadata panel?");
151
152         String JavaDoc fontName = "Dialog";
153         int fontSize = 11;
154         Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
155         this.m_autoMetadataLabel.setFont(font);
156         this.m_autoMetadataLabel.setOpaque(false);
157         this.m_autoMetadataLabel.setEditable(false);
158         this.m_autoMetadataLabel.setLineWrap(true);
159         this.add(this.m_autoMetadataLabel);
160         
161         this.m_autoMetadataCombo = new JComboBox JavaDoc( new String JavaDoc[]{"Yes","No"});
162         if(sValue!=null && sValue.equals("Yes")) {
163             this.m_autoMetadataCombo.setSelectedItem("Yes");
164         } else if(sValue!=null && sValue.equals("No")) {
165             this.m_autoMetadataCombo.setSelectedItem("No");
166         } else if(sValue==null) {
167             this.m_autoMetadataCombo.setSelectedItem("No");
168         }
169         this.m_autoMetadataCombo.addActionListener(this);
170         this.m_autoMetadataCombo.setActionCommand("AUTOMETADATA");
171         this.add(this.m_autoMetadataCombo);
172         
173         this.m_borderPanel = new JPanel JavaDoc();
174         this.m_borderPanel.setBorder( BorderFactory.createLineBorder(Color.BLACK) );
175         this.add(this.m_borderPanel);
176         
177     }
178     
179     /**
180      * Retrieves the stored skin option from the {@link ConfigStore}, if
181      * no value is found will default to the Whistler skin.
182      *
183      */

184     public void setStoredLnF() {
185         String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("LnF");
186         if(sValue!=null) {
187             ConfigLnF lnf = (ConfigLnF) this.m_options.get(sValue);
188             if(lnf!=null) {
189                 lnf.setLookAndFeel();
190             }
191         } else {
192             ConfigLnF lnf = (ConfigLnF) this.m_options.get("Whistler");
193             if(lnf!=null) {
194                 lnf.setLookAndFeel();
195             }
196         }
197     }
198
199     /* (non-Javadoc)
200      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
201      */

202     public void actionPerformed(ActionEvent JavaDoc ae) {
203         if(ae.getActionCommand().equals("LNFLIST")) {
204             this.fireChangesMade();
205             this.m_bChanged = true;
206         } else if(ae.getActionCommand().equals("AUTOMETADATA")) {
207             this.fireChangesMade();
208             this.m_bAutoMetadataChanged = true;
209         }
210     }
211
212     /* (non-Javadoc)
213      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
214      */

215     public boolean applyChanges() {
216         if(this.m_bChanged) {
217             ConfigLnF lnf = (ConfigLnF) this.m_options.get(this.m_combo.getSelectedItem());
218             lnf.setLookAndFeel();
219             ConfigStore.getInstance().setProperty("LnF", (String JavaDoc)this.m_combo.getSelectedItem());
220             this.m_bChanged = false;
221         }
222         if(this.m_bAutoMetadataChanged) {
223             ConfigStore.getInstance().setProperty("AUTO_METADATA_POSITION", (String JavaDoc)this.m_autoMetadataCombo.getSelectedItem());
224             this.m_bAutoMetadataChanged = false;
225         }
226         return true;
227     }
228
229     /* (non-Javadoc)
230      * @see java.awt.Component#getPreferredSize()
231      */

232     public Dimension JavaDoc getPreferredSize() {
233         return new Dimension JavaDoc(this.getParent().getSize().width, 100);
234     }
235
236     /* (non-Javadoc)
237      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
238      */

239     public void removeLayoutComponent(Component JavaDoc arg0) {
240     }
241
242     /* (non-Javadoc)
243      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
244      */

245     public void layoutContainer(Container JavaDoc arg0) {
246         
247         this.m_optionsLabel.setSize(this.m_optionsLabel.getPreferredSize());
248         this.m_optionsLabel.setLocation(10, 0);
249         
250         this.m_borderPanel.setSize(this.getSize().width-this.m_optionsLabel.getSize().width-10, 1);
251         this.m_borderPanel.setLocation(this.m_optionsLabel.getSize().width+this.m_optionsLabel.getLocation().x + 5, this.m_optionsLabel.getLocation().y+8);
252         
253         this.m_label.setSize(150, 20);
254         this.m_label.setLocation(20, 20);
255         this.m_combo.setSize(150, 20);
256         this.m_combo.setLocation(200, 20);
257         
258         this.m_autoMetadataLabel.setSize(150, 50);
259         this.m_autoMetadataLabel.setLocation(20, 50);
260         this.m_autoMetadataCombo.setSize(150, 20);
261         this.m_autoMetadataCombo.setLocation(200, 50);
262     }
263
264     /* (non-Javadoc)
265      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
266      */

267     public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
268     }
269
270     /* (non-Javadoc)
271      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
272      */

273     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
274         return this.getPreferredSize();
275     }
276
277     /* (non-Javadoc)
278      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
279      */

280     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
281         return this.getPreferredSize();
282     }
283
284     /* (non-Javadoc)
285      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
286      */

287     public void discardChanges() {
288         // NO-OP
289
}
290
291 }
292
Popular Tags