KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > configuration > sync > SyncConfigOptions


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.sync;
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
30 import javax.swing.BorderFactory JavaDoc;
31 import javax.swing.JComboBox JavaDoc;
32 import javax.swing.JLabel JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34 import javax.swing.JTextArea JavaDoc;
35
36 import org.openharmonise.him.configuration.*;
37
38
39 /**
40  * Configuration options for the way in which Content Manager
41  * synchronises with servers.
42  *
43  * @author Matthew Large
44  * @version $Revision: 1.1 $
45  *
46  */

47 public class SyncConfigOptions
48     extends AbstractConfigOptions
49     implements ApplyChangesListener, LayoutManager JavaDoc, ActionListener JavaDoc {
50
51     /**
52      * Label for auto sync.
53      */

54     private JTextArea JavaDoc m_autoSyncLabel = null;
55     
56     /**
57      * Options for auto sync.
58      */

59     private JComboBox JavaDoc m_autoSyncCombo = null;
60     
61     /**
62      * true if auto sync has changed.
63      */

64     private boolean m_bAutoSyncChanged = false;
65
66     /**
67      * Label for options.
68      */

69     private JLabel JavaDoc m_optionsLabel = null;
70     
71     /**
72      * Panel for border line.
73      */

74     private JPanel JavaDoc m_borderPanel = null;
75
76     /**
77      * Constructs a new sync configuration options.
78      *
79      * @param dialog Config dialog that will display these options
80      */

81     public SyncConfigOptions(ConfigDialog dialog) {
82         super(dialog);
83         dialog.addApplyChangesListener(this);
84         this.setup();
85     }
86     
87     /**
88      * Configures this options class.
89      *
90      */

91     private void setup() {
92         this.setLayout(this);
93         
94         this.m_optionsLabel = new JLabel JavaDoc("Submit changes to server on exit");
95         this.add(this.m_optionsLabel);
96         
97         String JavaDoc[] aData = new String JavaDoc[]{"Yes", "No"};
98         
99         String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("AUTO_SYNC_ON_EXIT");
100         
101         this.m_autoSyncLabel = new JTextArea JavaDoc("Automatically submit all changes to the server on exit?");
102
103         String JavaDoc fontName = "Dialog";
104         int fontSize = 11;
105         Font JavaDoc font = new Font JavaDoc(fontName, Font.PLAIN, fontSize);
106         this.m_autoSyncLabel.setFont(font);
107         this.m_autoSyncLabel.setWrapStyleWord(true);
108         this.m_autoSyncLabel.setOpaque(false);
109         this.m_autoSyncLabel.setEditable(false);
110         this.m_autoSyncLabel.setLineWrap(true);
111         this.add(m_autoSyncLabel);
112         
113         this.m_autoSyncCombo = new JComboBox JavaDoc(aData);
114         this.m_autoSyncCombo.setActionCommand("AUTOSYNC");
115         this.m_autoSyncCombo.addActionListener(this);
116         this.add(m_autoSyncCombo);
117         if(sValue!=null) {
118             if(sValue.equals("Yes")) {
119                 this.m_autoSyncCombo.setSelectedItem("Yes");
120             } else {
121                 this.m_autoSyncCombo.setSelectedItem("No");
122             }
123         }
124         
125         this.m_borderPanel = new JPanel JavaDoc();
126         this.m_borderPanel.setBorder( BorderFactory.createLineBorder(Color.BLACK) );
127         this.add(this.m_borderPanel);
128     }
129
130     /* (non-Javadoc)
131      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
132      */

133     public boolean applyChanges() {
134         if(this.m_bAutoSyncChanged) {
135             if(((String JavaDoc)this.m_autoSyncCombo.getSelectedItem()).equals("Yes")) {
136                 ConfigStore.getInstance().setProperty("AUTO_SYNC_ON_EXIT", "Yes");
137             } else {
138                 ConfigStore.getInstance().setProperty("AUTO_SYNC_ON_EXIT", "No");
139             }
140             this.m_bAutoSyncChanged = false;
141         }
142         return true;
143     }
144
145     /* (non-Javadoc)
146      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
147      */

148     public void discardChanges() {
149         //NO-OP
150
}
151
152     /* (non-Javadoc)
153      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
154      */

155     public void layoutContainer(Container JavaDoc arg0) {
156         
157         this.m_optionsLabel.setSize(this.m_optionsLabel.getPreferredSize());
158         this.m_optionsLabel.setLocation(10, 0);
159         
160         this.m_borderPanel.setSize(this.getSize().width-this.m_optionsLabel.getSize().width-10, 1);
161         this.m_borderPanel.setLocation(this.m_optionsLabel.getSize().width+this.m_optionsLabel.getLocation().x + 5, this.m_optionsLabel.getLocation().y+8);
162         this.m_autoSyncLabel.setSize(150, 50);
163         this.m_autoSyncLabel.setLocation(20, 20);
164         this.m_autoSyncCombo.setSize(150, 20);
165         this.m_autoSyncCombo.setLocation(200, 20);
166     }
167
168     /* (non-Javadoc)
169      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
170      */

171     public void actionPerformed(ActionEvent JavaDoc ae) {
172         if(ae.getActionCommand().equals("AUTOSYNC")) {
173             this.fireChangesMade();
174             this.m_bAutoSyncChanged = true;
175         }
176     }
177
178     /* (non-Javadoc)
179      * @see java.awt.Component#getPreferredSize()
180      */

181     public Dimension JavaDoc getPreferredSize() {
182         return new Dimension JavaDoc(this.getParent().getSize().width, 60);
183     }
184
185     /* (non-Javadoc)
186      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
187      */

188     public void removeLayoutComponent(Component JavaDoc arg0) {
189     }
190
191     /* (non-Javadoc)
192      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
193      */

194     public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
195     }
196
197     /* (non-Javadoc)
198      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
199      */

200     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
201         return this.getPreferredSize();
202     }
203
204     /* (non-Javadoc)
205      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
206      */

207     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
208         return this.getPreferredSize();
209     }
210
211 }
212
Popular Tags