1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.ui;
20
21 import java.awt.FlowLayout;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.File;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.io.OutputStream;
28 import java.util.Properties;
29
30 import javax.swing.JButton;
31 import javax.swing.JDialog;
32 import javax.swing.JFrame;
33 import javax.swing.JPanel;
34 import javax.swing.JTabbedPane;
35
36 import net.sf.jameleon.util.Configurator;
37
38 public class ConfigDialog extends JDialog{
39 private static final long serialVersionUID = 1L;
40 protected JTabbedPane tabbedPane;
41 protected GeneralConfigPanel generalPanel;
42 protected EnvironmentConfigPanel envPanel;
43 protected UIConfigPanel uiConfigPanel;
44 protected static final String ENV_PANEL = "Environment Settings";
45 protected static final String GENERAL_PANEL = "General Settings";
46 protected static final String UI_PANEL = "UI Settings";
47
48 public ConfigDialog(JFrame rootFrame){
49 super(rootFrame, "Jameleon Settings", true);
50 init();
51 setVisible(true);
52 }
53
54 private void init(){
55 tabbedPane = new JTabbedPane(JTabbedPane.TOP);
56 generalPanel = new GeneralConfigPanel();
57 envPanel = new EnvironmentConfigPanel();
58 uiConfigPanel = new UIConfigPanel();
59 tabbedPane.add(ENV_PANEL, envPanel);
60 tabbedPane.add(GENERAL_PANEL, generalPanel);
61 tabbedPane.add(UI_PANEL, uiConfigPanel);
62 getContentPane().add(tabbedPane, "Center");
63
64 JPanel p2 = new JPanel(new FlowLayout());
65 JButton ok = new JButton("Ok");
66 p2.add(ok);
67 JButton cancel = new JButton("Cancel");
68 p2.add(cancel);
69 getContentPane().add(p2, "South");
70
71 ok.addActionListener(new ActionListener() {
72 public void actionPerformed(ActionEvent evt) {
73 envPanel.updateProperties();
74 generalPanel.updateProperties();
75 uiConfigPanel.updateProperties();
76 Configurator config = Configurator.getInstance();
77 OutputStream os = null;
78 try{
79 Properties props = config.getProperties();
80 File f = new File(config.getConfigName());
81 if (!f.exists()) {
82 f.createNewFile();
83 }
84 os = new FileOutputStream(f);
85 props.store(os, null);
86 }catch(IOException ioe){
87 ioe.printStackTrace();
88 }finally{
89 if (os != null) {
90 try{
91 os.close();
92 }catch(IOException ioe){
93
94 }
95 }
96 }
97 Configurator.clearInstance();
98 setVisible(false);
99 dispose();
100 }
101 });
102 cancel.addActionListener(new ActionListener(){
103 public void actionPerformed(ActionEvent e) {
104 setVisible(false);
105 dispose();
106 }
107 });
108 pack();
109
110 }
111
112 }