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.reporting;
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.LayoutManager;
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener;
028:
029: import javax.swing.BorderFactory;
030: import javax.swing.JComboBox;
031: import javax.swing.JLabel;
032: import javax.swing.JPanel;
033:
034: import org.openharmonise.him.configuration.*;
035: import org.openharmonise.vfs.gui.*;
036:
037: /**
038: * Configuration options for the way in which Content Manager reports
039: * back to the user.
040: *
041: * @author Matthew Large
042: * @version $Revision: 1.1 $
043: *
044: */
045: public class ReportingConfigOptions extends AbstractConfigOptions
046: implements ApplyChangesListener, LayoutManager, ActionListener {
047:
048: /**
049: * Label for confirmations reporting.
050: */
051: private JLabel m_confirmationsLabel = null;
052:
053: /**
054: * Confirmations reporting field.
055: */
056: private JComboBox m_confirmationsCombo = null;
057:
058: /**
059: * true if the confirmations reporting value has changed.
060: */
061: private boolean m_bConfirmationsChanged = false;
062:
063: /**
064: * Label for informational reporting.
065: */
066: private JLabel m_informationLabel = null;
067:
068: /**
069: * Informational reporting field.
070: */
071: private JComboBox m_informationCombo = null;
072:
073: /**
074: * true if the informational reporting value has changed.
075: */
076: private boolean m_bInformationChanged = false;
077:
078: /**
079: * Label for error reporting.
080: */
081: private JLabel m_errorLabel = null;
082:
083: /**
084: * Error reporting field.
085: */
086: private JComboBox m_errorCombo = null;
087:
088: /**
089: * true if the error reporting value has changed.
090: */
091: private boolean m_bErrorChanged = false;
092:
093: /**
094: * Main label for reporting options.
095: */
096: private JLabel m_optionsLabel = null;
097:
098: /**
099: * Panel for border line.
100: */
101: private JPanel m_borderPanel = null;
102:
103: /**
104: * Constructs a new reporting config options.
105: *
106: * @param dialog Config dialog that will display these options
107: */
108: public ReportingConfigOptions(ConfigDialog dialog) {
109: super (dialog);
110: dialog.addApplyChangesListener(this );
111: this .setup();
112: }
113:
114: /**
115: * Configures this options class.
116: *
117: */
118: private void setup() {
119: this .setLayout(this );
120:
121: this .m_optionsLabel = new JLabel("Reporting options");
122: this .add(this .m_optionsLabel);
123:
124: String[] aData = new String[] { "Don't Report", "Report" };
125:
126: String sValue = ConfigStore.getInstance().getPropertyValue(
127: "MSG_CONFIRM_REPORT");
128:
129: this .m_confirmationsLabel = new JLabel("Confirmations");
130: this .m_confirmationsLabel.setIcon(IconManager.getInstance()
131: .getIcon("16-message-confirm.gif"));
132: this .add(m_confirmationsLabel);
133:
134: this .m_confirmationsCombo = new JComboBox(aData);
135: this .m_confirmationsCombo.setActionCommand("CONFIRM");
136: this .m_confirmationsCombo.addActionListener(this );
137: this .add(m_confirmationsCombo);
138: if (sValue != null) {
139: if (sValue.equals("TRUE")) {
140: this .m_confirmationsCombo.setSelectedItem("Report");
141: } else {
142: this .m_confirmationsCombo
143: .setSelectedItem("Don't Report");
144: }
145: } else {
146: this .m_confirmationsCombo.setSelectedItem("Report");
147: }
148:
149: sValue = ConfigStore.getInstance().getPropertyValue(
150: "MSG_INFORMATION_REPORT");
151:
152: this .m_informationLabel = new JLabel("Information");
153: this .m_informationLabel.setIcon(IconManager.getInstance()
154: .getIcon("16-message-information.gif"));
155: this .add(m_informationLabel);
156:
157: this .m_informationCombo = new JComboBox(aData);
158: this .m_informationCombo.setActionCommand("INFORMATION");
159: this .m_informationCombo.addActionListener(this );
160: this .add(m_informationCombo);
161: if (sValue != null) {
162: if (sValue.equals("TRUE")) {
163: this .m_informationCombo.setSelectedItem("Report");
164: } else {
165: this .m_informationCombo.setSelectedItem("Don't Report");
166: }
167: } else {
168: this .m_informationCombo.setSelectedItem("Report");
169: }
170:
171: sValue = ConfigStore.getInstance().getPropertyValue(
172: "MSG_ERROR_REPORT");
173:
174: this .m_errorLabel = new JLabel("Errors");
175: this .m_errorLabel.setIcon(IconManager.getInstance().getIcon(
176: "16-message-error.gif"));
177: this .add(m_errorLabel);
178:
179: this .m_errorCombo = new JComboBox(aData);
180: this .m_errorCombo.setActionCommand("ERROR");
181: this .m_errorCombo.addActionListener(this );
182: this .add(m_errorCombo);
183: if (sValue != null) {
184: if (sValue.equals("TRUE")) {
185: this .m_errorCombo.setSelectedItem("Report");
186: } else {
187: this .m_errorCombo.setSelectedItem("Don't Report");
188: }
189: } else {
190: this .m_errorCombo.setSelectedItem("Report");
191: }
192:
193: this .m_borderPanel = new JPanel();
194: this .m_borderPanel.setBorder(BorderFactory
195: .createLineBorder(Color.BLACK));
196: this .add(this .m_borderPanel);
197: }
198:
199: /* (non-Javadoc)
200: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
201: */
202: public boolean applyChanges() {
203: if (this .m_bConfirmationsChanged) {
204: if (((String) this .m_confirmationsCombo.getSelectedItem())
205: .equals("Report")) {
206: ConfigStore.getInstance().setProperty(
207: "MSG_CONFIRM_REPORT", "TRUE");
208: } else {
209: ConfigStore.getInstance().setProperty(
210: "MSG_CONFIRM_REPORT", "FALSE");
211: }
212: this .m_bConfirmationsChanged = false;
213: }
214: if (this .m_bInformationChanged) {
215: if (((String) this .m_informationCombo.getSelectedItem())
216: .equals("Report")) {
217: ConfigStore.getInstance().setProperty(
218: "MSG_INFORMATION_REPORT", "TRUE");
219: } else {
220: ConfigStore.getInstance().setProperty(
221: "MSG_INFORMATION_REPORT", "FALSE");
222: }
223: this .m_bInformationChanged = false;
224: }
225: if (this .m_bErrorChanged) {
226: if (((String) this .m_errorCombo.getSelectedItem())
227: .equals("Report")) {
228: ConfigStore.getInstance().setProperty(
229: "MSG_ERROR_REPORT", "TRUE");
230: } else {
231: ConfigStore.getInstance().setProperty(
232: "MSG_ERROR_REPORT", "FALSE");
233: }
234: this .m_bErrorChanged = false;
235: }
236: return true;
237: }
238:
239: /* (non-Javadoc)
240: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
241: */
242: public void actionPerformed(ActionEvent ae) {
243: if (ae.getActionCommand().equals("CONFIRM")) {
244: this .fireChangesMade();
245: this .m_bConfirmationsChanged = true;
246: } else if (ae.getActionCommand().equals("INFORMATION")) {
247: this .fireChangesMade();
248: this .m_bInformationChanged = true;
249: } else if (ae.getActionCommand().equals("ERROR")) {
250: this .fireChangesMade();
251: this .m_bErrorChanged = true;
252: }
253: }
254:
255: /* (non-Javadoc)
256: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
257: */
258: public void layoutContainer(Container arg0) {
259:
260: this .m_optionsLabel.setSize(this .m_optionsLabel
261: .getPreferredSize());
262: this .m_optionsLabel.setLocation(10, 0);
263:
264: this .m_borderPanel.setSize(this .getSize().width
265: - this .m_optionsLabel.getSize().width - 10, 1);
266: this .m_borderPanel.setLocation(
267: this .m_optionsLabel.getSize().width
268: + this .m_optionsLabel.getLocation().x + 5,
269: this .m_optionsLabel.getLocation().y + 8);
270:
271: this .m_confirmationsLabel.setSize(150, 20);
272: this .m_confirmationsLabel.setLocation(20, 20);
273: this .m_confirmationsCombo.setSize(150, 20);
274: this .m_confirmationsCombo.setLocation(200, 20);
275:
276: this .m_informationLabel.setSize(150, 20);
277: this .m_informationLabel.setLocation(20, 50);
278: this .m_informationCombo.setSize(150, 20);
279: this .m_informationCombo.setLocation(200, 50);
280:
281: this .m_errorLabel.setSize(150, 20);
282: this .m_errorLabel.setLocation(20, 80);
283: this .m_errorCombo.setSize(150, 20);
284: this .m_errorCombo.setLocation(200, 80);
285: }
286:
287: /* (non-Javadoc)
288: * @see java.awt.Component#getPreferredSize()
289: */
290: public Dimension getPreferredSize() {
291: return new Dimension(this .getParent().getSize().width, 120);
292: }
293:
294: /* (non-Javadoc)
295: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
296: */
297: public Dimension minimumLayoutSize(Container arg0) {
298: return this .getPreferredSize();
299: }
300:
301: /* (non-Javadoc)
302: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
303: */
304: public Dimension preferredLayoutSize(Container arg0) {
305: return this .getPreferredSize();
306: }
307:
308: /* (non-Javadoc)
309: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
310: */
311: public void removeLayoutComponent(Component arg0) {
312: }
313:
314: /* (non-Javadoc)
315: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
316: */
317: public void addLayoutComponent(String arg0, Component arg1) {
318: }
319:
320: /* (non-Javadoc)
321: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
322: */
323: public void discardChanges() {
324: // TODO Auto-generated method stub
325:
326: }
327:
328: }
|