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.sync;
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:
030: import javax.swing.BorderFactory;
031: import javax.swing.JComboBox;
032: import javax.swing.JLabel;
033: import javax.swing.JPanel;
034: import javax.swing.JTextArea;
035:
036: import org.openharmonise.him.configuration.*;
037:
038: /**
039: * Configuration options for the way in which Content Manager
040: * synchronises with servers.
041: *
042: * @author Matthew Large
043: * @version $Revision: 1.1 $
044: *
045: */
046: public class SyncConfigOptions extends AbstractConfigOptions implements
047: ApplyChangesListener, LayoutManager, ActionListener {
048:
049: /**
050: * Label for auto sync.
051: */
052: private JTextArea m_autoSyncLabel = null;
053:
054: /**
055: * Options for auto sync.
056: */
057: private JComboBox m_autoSyncCombo = null;
058:
059: /**
060: * true if auto sync has changed.
061: */
062: private boolean m_bAutoSyncChanged = false;
063:
064: /**
065: * Label for options.
066: */
067: private JLabel m_optionsLabel = null;
068:
069: /**
070: * Panel for border line.
071: */
072: private JPanel m_borderPanel = null;
073:
074: /**
075: * Constructs a new sync configuration options.
076: *
077: * @param dialog Config dialog that will display these options
078: */
079: public SyncConfigOptions(ConfigDialog dialog) {
080: super (dialog);
081: dialog.addApplyChangesListener(this );
082: this .setup();
083: }
084:
085: /**
086: * Configures this options class.
087: *
088: */
089: private void setup() {
090: this .setLayout(this );
091:
092: this .m_optionsLabel = new JLabel(
093: "Submit changes to server on exit");
094: this .add(this .m_optionsLabel);
095:
096: String[] aData = new String[] { "Yes", "No" };
097:
098: String sValue = ConfigStore.getInstance().getPropertyValue(
099: "AUTO_SYNC_ON_EXIT");
100:
101: this .m_autoSyncLabel = new JTextArea(
102: "Automatically submit all changes to the server on exit?");
103:
104: String fontName = "Dialog";
105: int fontSize = 11;
106: Font font = new Font(fontName, Font.PLAIN, fontSize);
107: this .m_autoSyncLabel.setFont(font);
108: this .m_autoSyncLabel.setWrapStyleWord(true);
109: this .m_autoSyncLabel.setOpaque(false);
110: this .m_autoSyncLabel.setEditable(false);
111: this .m_autoSyncLabel.setLineWrap(true);
112: this .add(m_autoSyncLabel);
113:
114: this .m_autoSyncCombo = new JComboBox(aData);
115: this .m_autoSyncCombo.setActionCommand("AUTOSYNC");
116: this .m_autoSyncCombo.addActionListener(this );
117: this .add(m_autoSyncCombo);
118: if (sValue != null) {
119: if (sValue.equals("Yes")) {
120: this .m_autoSyncCombo.setSelectedItem("Yes");
121: } else {
122: this .m_autoSyncCombo.setSelectedItem("No");
123: }
124: }
125:
126: this .m_borderPanel = new JPanel();
127: this .m_borderPanel.setBorder(BorderFactory
128: .createLineBorder(Color.BLACK));
129: this .add(this .m_borderPanel);
130: }
131:
132: /* (non-Javadoc)
133: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
134: */
135: public boolean applyChanges() {
136: if (this .m_bAutoSyncChanged) {
137: if (((String) this .m_autoSyncCombo.getSelectedItem())
138: .equals("Yes")) {
139: ConfigStore.getInstance().setProperty(
140: "AUTO_SYNC_ON_EXIT", "Yes");
141: } else {
142: ConfigStore.getInstance().setProperty(
143: "AUTO_SYNC_ON_EXIT", "No");
144: }
145: this .m_bAutoSyncChanged = false;
146: }
147: return true;
148: }
149:
150: /* (non-Javadoc)
151: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
152: */
153: public void discardChanges() {
154: //NO-OP
155: }
156:
157: /* (non-Javadoc)
158: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
159: */
160: public void layoutContainer(Container arg0) {
161:
162: this .m_optionsLabel.setSize(this .m_optionsLabel
163: .getPreferredSize());
164: this .m_optionsLabel.setLocation(10, 0);
165:
166: this .m_borderPanel.setSize(this .getSize().width
167: - this .m_optionsLabel.getSize().width - 10, 1);
168: this .m_borderPanel.setLocation(
169: this .m_optionsLabel.getSize().width
170: + this .m_optionsLabel.getLocation().x + 5,
171: this .m_optionsLabel.getLocation().y + 8);
172: this .m_autoSyncLabel.setSize(150, 50);
173: this .m_autoSyncLabel.setLocation(20, 20);
174: this .m_autoSyncCombo.setSize(150, 20);
175: this .m_autoSyncCombo.setLocation(200, 20);
176: }
177:
178: /* (non-Javadoc)
179: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
180: */
181: public void actionPerformed(ActionEvent ae) {
182: if (ae.getActionCommand().equals("AUTOSYNC")) {
183: this .fireChangesMade();
184: this .m_bAutoSyncChanged = true;
185: }
186: }
187:
188: /* (non-Javadoc)
189: * @see java.awt.Component#getPreferredSize()
190: */
191: public Dimension getPreferredSize() {
192: return new Dimension(this .getParent().getSize().width, 60);
193: }
194:
195: /* (non-Javadoc)
196: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
197: */
198: public void removeLayoutComponent(Component arg0) {
199: }
200:
201: /* (non-Javadoc)
202: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
203: */
204: public void addLayoutComponent(String arg0, Component arg1) {
205: }
206:
207: /* (non-Javadoc)
208: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
209: */
210: public Dimension minimumLayoutSize(Container arg0) {
211: return this .getPreferredSize();
212: }
213:
214: /* (non-Javadoc)
215: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
216: */
217: public Dimension preferredLayoutSize(Container arg0) {
218: return this.getPreferredSize();
219: }
220:
221: }
|