001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.configuration.lnf;
020:
021: import java.awt.Color;
022: import java.awt.Component;
023: import java.awt.Container;
024: import java.awt.Dimension;
025: import java.awt.Font;
026: import java.awt.LayoutManager;
027: import java.awt.event.ActionEvent;
028: import java.awt.event.ActionListener;
029: import java.util.HashMap;
030:
031: import javax.swing.BorderFactory;
032: import javax.swing.JComboBox;
033: import javax.swing.JLabel;
034: import javax.swing.JPanel;
035: import javax.swing.JTextArea;
036: import javax.swing.UIManager;
037:
038: import org.openharmonise.him.configuration.*;
039:
040: /**
041: * Configuration options for the application Look and Feel. Each option
042: * is represented as a {@link org.openharmonise.him.configuration.lnf.ConfigLnF}
043: * object so that they can each handle their own implementation specific details.
044: *
045: * @author Matthew Large
046: * @version $Revision: 1.2 $
047: *
048: */
049: public class LookAndFeelConfigOptions extends AbstractConfigOptions
050: implements ApplyChangesListener, LayoutManager, ActionListener {
051:
052: /**
053: * Skin label.
054: */
055: private JLabel m_label = null;
056:
057: /**
058: * Option values combo box.
059: */
060: private JComboBox m_combo = null;
061:
062: /**
063: * Map of option name to {@link ConfigLnF} objects.
064: */
065: private HashMap m_options = new HashMap();
066:
067: /**
068: * true if the selected look and feel has changed.
069: */
070: private boolean m_bChanged = false;
071:
072: /**
073: * Label for automatic positioning of the metadata panel.
074: */
075: private JTextArea m_autoMetadataLabel = null;
076:
077: /**
078: * Options for automatic positioning of the metadata panel.
079: */
080: private JComboBox m_autoMetadataCombo = null;
081:
082: /**
083: * true if the metadata panel is to be automatically positioned.
084: */
085: private boolean m_bAutoMetadataChanged = false;
086:
087: /**
088: * Main options label.
089: */
090: private JLabel m_optionsLabel = null;
091:
092: /**
093: * Panel for border line.
094: */
095: private JPanel m_borderPanel = null;
096:
097: public LookAndFeelConfigOptions() {
098: super (null);
099: this .setup();
100: }
101:
102: /**
103: * Constructs a new look and feel config options.
104: *
105: * @param dialog Config dialog that will display these options
106: */
107: public LookAndFeelConfigOptions(ConfigDialog dialog) {
108: super (dialog);
109: dialog.addApplyChangesListener(this );
110: this .setup();
111: }
112:
113: /**
114: * Configures this options class.
115: *
116: */
117: private void setup() {
118: this .setLayout(this );
119:
120: this .m_optionsLabel = new JLabel("Look and feel");
121: this .add(this .m_optionsLabel);
122:
123: this .m_options.put("Native", new ConfigLnF(UIManager
124: .getSystemLookAndFeelClassName(), this .m_dialog));
125: this .m_options
126: .put("Java", new ConfigLnF(UIManager
127: .getCrossPlatformLookAndFeelClassName(),
128: this .m_dialog));
129: this .m_options.put("Modern", new ConfigSkinLnF(
130: "/themes/modernthemepack.zip", this .m_dialog));
131: this .m_options.put("Toxic", new ConfigSkinLnF(
132: "/themes/toxicthemepack.zip", this .m_dialog));
133: this .m_options.put("Whistler", new ConfigSkinLnF(
134: "/themes/whistlerthemepack.zip", this .m_dialog));
135: //this.m_options.put("Kunststoff", new ConfigLnF("com.incors.plaf.kunststoff.KunststoffLookAndFeel", this.m_dialog));
136:
137: this .m_combo = new JComboBox(this .m_options.keySet().toArray());
138:
139: String sValue = ConfigStore.getInstance().getPropertyValue(
140: "LnF");
141: if (sValue != null) {
142: this .m_combo.setSelectedItem(sValue);
143: } else {
144: this .m_combo.setSelectedItem("Whistler");
145: }
146: this .m_combo.addActionListener(this );
147: this .m_combo.setActionCommand("LNFLIST");
148:
149: this .add(m_combo);
150:
151: this .m_label = new JLabel("Choose skin");
152: this .add(m_label);
153:
154: sValue = ConfigStore.getInstance().getPropertyValue(
155: "AUTO_METADATA_POSITION");
156:
157: this .m_autoMetadataLabel = new JTextArea(
158: "Automatically position metadata panel?");
159:
160: String fontName = "Dialog";
161: int fontSize = 11;
162: Font font = new Font(fontName, Font.PLAIN, fontSize);
163: this .m_autoMetadataLabel.setFont(font);
164: this .m_autoMetadataLabel.setOpaque(false);
165: this .m_autoMetadataLabel.setEditable(false);
166: this .m_autoMetadataLabel.setLineWrap(true);
167: this .add(this .m_autoMetadataLabel);
168:
169: this .m_autoMetadataCombo = new JComboBox(new String[] { "Yes",
170: "No" });
171: if (sValue != null && sValue.equals("Yes")) {
172: this .m_autoMetadataCombo.setSelectedItem("Yes");
173: } else if (sValue != null && sValue.equals("No")) {
174: this .m_autoMetadataCombo.setSelectedItem("No");
175: } else if (sValue == null) {
176: this .m_autoMetadataCombo.setSelectedItem("No");
177: }
178: this .m_autoMetadataCombo.addActionListener(this );
179: this .m_autoMetadataCombo.setActionCommand("AUTOMETADATA");
180: this .add(this .m_autoMetadataCombo);
181:
182: this .m_borderPanel = new JPanel();
183: this .m_borderPanel.setBorder(BorderFactory
184: .createLineBorder(Color.BLACK));
185: this .add(this .m_borderPanel);
186:
187: }
188:
189: /**
190: * Retrieves the stored skin option from the {@link ConfigStore}, if
191: * no value is found will default to the Whistler skin.
192: *
193: */
194: public void setStoredLnF() {
195: String sValue = ConfigStore.getInstance().getPropertyValue(
196: "LnF");
197: if (sValue != null) {
198: ConfigLnF lnf = (ConfigLnF) this .m_options.get(sValue);
199: if (lnf != null) {
200: lnf.setLookAndFeel();
201: }
202: } else {
203: ConfigLnF lnf = (ConfigLnF) this .m_options.get("Whistler");
204: if (lnf != null) {
205: lnf.setLookAndFeel();
206: }
207: }
208: }
209:
210: /* (non-Javadoc)
211: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
212: */
213: public void actionPerformed(ActionEvent ae) {
214: if (ae.getActionCommand().equals("LNFLIST")) {
215: this .fireChangesMade();
216: this .m_bChanged = true;
217: } else if (ae.getActionCommand().equals("AUTOMETADATA")) {
218: this .fireChangesMade();
219: this .m_bAutoMetadataChanged = true;
220: }
221: }
222:
223: /* (non-Javadoc)
224: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
225: */
226: public boolean applyChanges() {
227: if (this .m_bChanged) {
228: ConfigLnF lnf = (ConfigLnF) this .m_options.get(this .m_combo
229: .getSelectedItem());
230: lnf.setLookAndFeel();
231: ConfigStore.getInstance().setProperty("LnF",
232: (String) this .m_combo.getSelectedItem());
233: this .m_bChanged = false;
234: }
235: if (this .m_bAutoMetadataChanged) {
236: ConfigStore.getInstance()
237: .setProperty(
238: "AUTO_METADATA_POSITION",
239: (String) this .m_autoMetadataCombo
240: .getSelectedItem());
241: this .m_bAutoMetadataChanged = false;
242: }
243: return true;
244: }
245:
246: /* (non-Javadoc)
247: * @see java.awt.Component#getPreferredSize()
248: */
249: public Dimension getPreferredSize() {
250: return new Dimension(this .getParent().getSize().width, 100);
251: }
252:
253: /* (non-Javadoc)
254: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
255: */
256: public void removeLayoutComponent(Component arg0) {
257: }
258:
259: /* (non-Javadoc)
260: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
261: */
262: public void layoutContainer(Container arg0) {
263:
264: this .m_optionsLabel.setSize(this .m_optionsLabel
265: .getPreferredSize());
266: this .m_optionsLabel.setLocation(10, 0);
267:
268: this .m_borderPanel.setSize(this .getSize().width
269: - this .m_optionsLabel.getSize().width - 10, 1);
270: this .m_borderPanel.setLocation(
271: this .m_optionsLabel.getSize().width
272: + this .m_optionsLabel.getLocation().x + 5,
273: this .m_optionsLabel.getLocation().y + 8);
274:
275: this .m_label.setSize(150, 20);
276: this .m_label.setLocation(20, 20);
277: this .m_combo.setSize(150, 20);
278: this .m_combo.setLocation(200, 20);
279:
280: this .m_autoMetadataLabel.setSize(150, 50);
281: this .m_autoMetadataLabel.setLocation(20, 50);
282: this .m_autoMetadataCombo.setSize(150, 20);
283: this .m_autoMetadataCombo.setLocation(200, 50);
284: }
285:
286: /* (non-Javadoc)
287: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
288: */
289: public void addLayoutComponent(String arg0, Component arg1) {
290: }
291:
292: /* (non-Javadoc)
293: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
294: */
295: public Dimension minimumLayoutSize(Container arg0) {
296: return this .getPreferredSize();
297: }
298:
299: /* (non-Javadoc)
300: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
301: */
302: public Dimension preferredLayoutSize(Container arg0) {
303: return this .getPreferredSize();
304: }
305:
306: /* (non-Javadoc)
307: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
308: */
309: public void discardChanges() {
310: // NO-OP
311: }
312:
313: }
|