KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > configuration > ConfigDialog


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;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.util.*;
24
25 import javax.swing.*;
26
27 import org.openharmonise.him.configuration.lnf.*;
28 import org.openharmonise.him.configuration.reporting.*;
29 import org.openharmonise.him.configuration.searchin.*;
30 import org.openharmonise.him.configuration.sync.*;
31 import org.openharmonise.vfs.context.*;
32 import org.openharmonise.vfs.gui.*;
33
34
35 /**
36  * Dialog to present configuration options to the user.
37  *
38  * @author Matthew Large
39  * @version $Revision: 1.1 $
40  *
41  */

42 public class ConfigDialog extends JDialog implements LayoutManager, ActionListener, ContextListener {
43
44     /**
45      * List of {@link ApplyChangesListener} objects.
46      */

47     private ArrayList m_listeners = new ArrayList();
48
49     /**
50      * Tabs.
51      */

52     private JTabbedPane m_tabs = null;
53     
54     /**
55      * OK button.
56      */

57     private JButton m_buttonOK = null;
58     
59     /**
60      * Cancel button.
61      */

62     private JButton m_buttonCancel = null;
63     
64     /**
65      * Apply button.
66      */

67     private JButton m_buttonApply = null;
68     
69     /**
70      * Name of tab to be selected when the dialog is first displayed.
71      */

72     private String JavaDoc m_sSelectTab = null;
73
74     /**
75      * Constructs a new configuration dialog.
76      *
77      * @param frame Owning frame
78      * @param sTitle Title for dialog
79      * @throws HeadlessException
80      */

81     public ConfigDialog(Frame frame, String JavaDoc sTitle) throws HeadlessException {
82         super(frame, sTitle, true);
83         this.setup();
84     }
85     
86     /**
87      * Configures this dialog.
88      *
89      */

90     private void setup() {
91         
92         ContextHandler.getInstance().addListener(ContextType.CONTEXT_APP_FOCUS, this);
93             
94         this.setResizable(false);
95         
96         this.getContentPane().setLayout(this);
97         
98         this.setSize(400,400);
99         int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2;
100         int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2;
101         
102         this.setLocation(x, y);
103
104         String JavaDoc fontName = "Dialog";
105         int fontSize = 11;
106         Font font = new Font(fontName, Font.PLAIN, fontSize);
107         this.getContentPane().setBackground(new Color(224,224,224));
108         
109         this.m_buttonOK = new JButton("OK");
110         this.m_buttonOK.setActionCommand("OK");
111         this.m_buttonOK.addActionListener(this);
112         this.m_buttonOK.setFont(font);
113         this.getContentPane().add(this.m_buttonOK);
114
115         this.m_buttonCancel = new JButton("Cancel");
116         this.m_buttonCancel.setActionCommand("CANCEL");
117         this.m_buttonCancel.addActionListener(this);
118         this.m_buttonCancel.setFont(font);
119         this.getContentPane().add(this.m_buttonCancel);
120
121         this.m_buttonApply = new JButton("Apply");
122         this.m_buttonApply.setEnabled(false);
123         this.m_buttonApply.setActionCommand("APPLY");
124         this.m_buttonApply.addActionListener(this);
125         this.m_buttonApply.setFont(font);
126         this.getContentPane().add(this.m_buttonApply);
127         
128         this.m_tabs = new JTabbedPane();
129         this.m_tabs.setFont(font);
130         
131         JPanel panel = new JPanel();
132         panel.setLayout(new FlowLayout(FlowLayout.CENTER));
133         
134         ReportingConfigOptions reportingOptions = new ReportingConfigOptions(this);
135         panel.add(reportingOptions);
136         
137         LookAndFeelConfigOptions options = new LookAndFeelConfigOptions(this);
138         panel.add(options);
139         
140         SyncConfigOptions syncOptions = new SyncConfigOptions(this);
141         panel.add(syncOptions);
142         
143         this.m_tabs.addTab("Options", panel);
144
145         panel = new SearchInOptions(this);
146         
147         this.m_tabs.addTab("Search in", panel);
148         
149         this.getContentPane().add(this.m_tabs);
150         
151     }
152     
153     /**
154      * Sets the name of the tab to be selected when the dialog is
155      * shown.
156      *
157      * @param sTabName Name of tab
158      */

159     public void setSelectedTab(String JavaDoc sTabName) {
160         this.m_sSelectTab = sTabName;
161     }
162
163     /* (non-Javadoc)
164      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
165      */

166     public void actionPerformed(ActionEvent ae) {
167         if(ae.getActionCommand().equals("OK")) {
168             this.fireApplyChanges();
169             ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this);
170             this.hide();
171         } else if(ae.getActionCommand().equals("CANCEL")) {
172             ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this);
173             this.hide();
174         } else if(ae.getActionCommand().equals("APPLY")) {
175             this.m_buttonApply.setEnabled(false);
176             this.fireApplyChanges();
177             
178         }
179     }
180
181     /* (non-Javadoc)
182      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
183      */

184     public void layoutContainer(Container arg0) {
185         this.m_tabs.setSize(this.getSize().width-10, 430);
186         this.m_tabs.setLocation(0, 0);
187         
188         this.m_buttonOK.setSize(70, 20);
189         this.m_buttonOK.setLocation(150, 340);
190         
191         this.m_buttonCancel.setSize(70, 20);
192         this.m_buttonCancel.setLocation(230, 340);
193         
194         this.m_buttonApply.setSize(70, 20);
195         this.m_buttonApply.setLocation(310, 340);
196     }
197     
198     /**
199      * Adds an apply changes listener.
200      *
201      * @param listener Listener to add
202      */

203     public void addApplyChangesListener(ApplyChangesListener listener) {
204         this.m_listeners.add(listener);
205     }
206     
207     /**
208      * Removes an apply changes listener.
209      *
210      * @param listener Listener to remove
211      */

212     public void removeApplyChangesListener(ApplyChangesListener listener) {
213         this.m_listeners.remove(listener);
214     }
215     
216     /**
217      * Fires an apply changes message to all listener.
218      *
219      */

220     private void fireApplyChanges() {
221         Iterator itor = this.m_listeners.iterator();
222         while (itor.hasNext()) {
223             ApplyChangesListener listener = (ApplyChangesListener) itor.next();
224             listener.applyChanges();
225         }
226     }
227     
228     /**
229      * Called by an options component to inform the dialog that a change
230      * has been made to a configuration option. This will enable the apply
231      * button.
232      *
233      */

234     public void changesMade() {
235         this.m_buttonApply.setEnabled(true);
236     }
237     
238     public static void main(String JavaDoc[] args) {
239         JFrame frame = new JFrame();
240         frame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() );
241         
242         ConfigDialog dialog = new ConfigDialog(frame, "Customise");
243         dialog.show();
244         System.exit(0);
245     }
246
247     /**
248      * @param arg0
249      * @throws java.awt.HeadlessException
250      */

251     private ConfigDialog(Dialog arg0) throws HeadlessException {
252         super(arg0);
253     }
254
255     /**
256      * @param arg0
257      * @param arg1
258      * @throws java.awt.HeadlessException
259      */

260     private ConfigDialog(Dialog arg0, boolean arg1) throws HeadlessException {
261         super(arg0, arg1);
262     }
263
264     /**
265      * @param arg0
266      * @throws java.awt.HeadlessException
267      */

268     private ConfigDialog(Frame arg0) throws HeadlessException {
269         super(arg0);
270     }
271
272     /**
273      * @param arg0
274      * @param arg1
275      * @throws java.awt.HeadlessException
276      */

277     private ConfigDialog(Frame arg0, boolean arg1) throws HeadlessException {
278         super(arg0, arg1);
279     }
280
281     /**
282      * @param arg0
283      * @param arg1
284      * @throws java.awt.HeadlessException
285      */

286     private ConfigDialog() throws HeadlessException {
287         super();
288     }
289
290     /**
291      * @param arg0
292      * @param arg1
293      * @param arg2
294      * @throws java.awt.HeadlessException
295      */

296     private ConfigDialog(Dialog arg0, String JavaDoc arg1, boolean arg2)
297         throws HeadlessException {
298         super(arg0, arg1, arg2);
299     }
300
301     /**
302      * @param arg0
303      * @param arg1
304      * @throws java.awt.HeadlessException
305      */

306     private ConfigDialog(Dialog arg0, String JavaDoc arg1) throws HeadlessException {
307         super(arg0, arg1);
308     }
309
310     /**
311      * @param arg0
312      * @param arg1
313      * @param arg2
314      * @throws java.awt.HeadlessException
315      */

316     private ConfigDialog(Frame arg0, String JavaDoc arg1, boolean arg2)
317         throws HeadlessException {
318         super(arg0, arg1, arg2);
319     }
320
321     /**
322      * @param arg0
323      * @param arg1
324      * @param arg2
325      * @param arg3
326      * @throws java.awt.HeadlessException
327      */

328     private ConfigDialog(
329         Dialog arg0,
330         String JavaDoc arg1,
331         boolean arg2,
332         GraphicsConfiguration arg3)
333         throws HeadlessException {
334         super(arg0, arg1, arg2, arg3);
335     }
336
337     /**
338      * @param arg0
339      * @param arg1
340      * @param arg2
341      * @param arg3
342      */

343     private ConfigDialog(
344         Frame arg0,
345         String JavaDoc arg1,
346         boolean arg2,
347         GraphicsConfiguration arg3) {
348         super(arg0, arg1, arg2, arg3);
349     }
350
351     /* (non-Javadoc)
352      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
353      */

354     public void removeLayoutComponent(Component arg0) {
355     }
356
357     /* (non-Javadoc)
358      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
359      */

360     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
361     }
362
363     /* (non-Javadoc)
364      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
365      */

366     public Dimension minimumLayoutSize(Container arg0) {
367         return this.getSize();
368     }
369
370     /* (non-Javadoc)
371      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
372      */

373     public Dimension preferredLayoutSize(Container arg0) {
374         return this.getSize();
375     }
376
377     /* (non-Javadoc)
378      * @see java.awt.Component#show()
379      */

380     public void show() {
381         if(this.m_sSelectTab!=null) {
382             int nIndex = 0;
383             for(int i=0; i<this.m_tabs.getTabCount(); i++) {
384                  if(this.m_tabs.getTitleAt(i).equals(this.m_sSelectTab)) {
385                     nIndex = i;
386                  }
387             }
388             this.m_tabs.setSelectedIndex(nIndex);
389         }
390         super.show();
391     }
392
393     /* (non-Javadoc)
394      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
395      */

396     public void contextMessage(ContextEvent ce) {
397         if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) {
398             this.toFront();
399         }
400     }
401
402 }
403
Popular Tags