KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > templateeditor > dialogs > OptionsDialog


1 package com.genimen.djeneric.tools.templateeditor.dialogs;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.awt.Dimension JavaDoc;
5 import java.awt.Frame JavaDoc;
6 import java.awt.Toolkit JavaDoc;
7 import java.awt.event.ActionEvent JavaDoc;
8 import java.io.File JavaDoc;
9
10 import javax.swing.JButton JavaDoc;
11 import javax.swing.JDialog JavaDoc;
12 import javax.swing.JFileChooser JavaDoc;
13 import javax.swing.JLabel JavaDoc;
14 import javax.swing.JPanel JavaDoc;
15 import javax.swing.JTextField JavaDoc;
16
17 import com.genimen.djeneric.tools.generator.Generator;
18 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
19 import com.genimen.djeneric.util.DjLogger;
20 import com.genimen.djeneric.util.DjProperties;
21
22 public class OptionsDialog extends JDialog JavaDoc
23 {
24   private static final long serialVersionUID = 1L;
25   JPanel JavaDoc panel1 = new JPanel JavaDoc();
26   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
27   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
28   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
29   DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout();
30   DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout();
31   JLabel JavaDoc jLabel1 = new JLabel JavaDoc();
32   JLabel JavaDoc jLabel2 = new JLabel JavaDoc();
33   boolean _canceled = true;
34   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
35   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
36   JPanel JavaDoc jPanel4 = new JPanel JavaDoc();
37   JButton JavaDoc _butOk = new JButton JavaDoc();
38   JButton JavaDoc _butCancel = new JButton JavaDoc();
39   DjProperties _props;
40   JButton JavaDoc _butIncludePath = new JButton JavaDoc();
41   BorderLayout JavaDoc borderLayout4 = new BorderLayout JavaDoc();
42   JTextField JavaDoc _edtIncludePath = new JTextField JavaDoc();
43   JPanel JavaDoc jPanel6 = new JPanel JavaDoc();
44   JButton JavaDoc _butTemplate = new JButton JavaDoc();
45   BorderLayout JavaDoc borderLayout5 = new BorderLayout JavaDoc();
46   JTextField JavaDoc _edtTemplateSetPath = new JTextField JavaDoc();
47   JPanel JavaDoc jPanel7 = new JPanel JavaDoc();
48
49   public OptionsDialog(Frame JavaDoc frame, DjProperties props)
50   {
51     super(frame, "Options", true);
52     try
53     {
54       _props = props;
55
56       jbInit();
57       pack();
58       Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
59       Dimension JavaDoc frameSize = getSize();
60       setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
61
62       _edtIncludePath.setText(props.getProperty(Generator.KEY_INCLUDEPATH, ""));
63       _edtTemplateSetPath.setText(props.getProperty(Generator.KEY_TEMPLATEPATH, ""));
64
65       setVisible(true);
66     }
67     catch (Exception JavaDoc ex)
68     {
69       DjLogger.log(ex);
70     }
71   }
72
73   void jbInit() throws Exception JavaDoc
74   {
75     panel1.setLayout(borderLayout1);
76     jPanel1.setLayout(verticalFlowLayout1);
77     jPanel2.setLayout(verticalFlowLayout2);
78     jLabel1.setPreferredSize(new Dimension JavaDoc(102, 21));
79     jLabel1.setText("Template set path");
80     jLabel2.setPreferredSize(new Dimension JavaDoc(102, 21));
81     jLabel2.setText("Include path");
82     jPanel3.setLayout(borderLayout2);
83     _butOk.setPreferredSize(new Dimension JavaDoc(73, 27));
84     _butOk.setText("OK");
85     _butOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
86     {
87       public void actionPerformed(ActionEvent JavaDoc e)
88       {
89         _butOk_actionPerformed(e);
90       }
91     });
92     _butCancel.setText("Cancel");
93     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
94     {
95       public void actionPerformed(ActionEvent JavaDoc e)
96       {
97         _butCancel_actionPerformed(e);
98       }
99     });
100     _butIncludePath.setText("...");
101     _butIncludePath.addActionListener(new java.awt.event.ActionListener JavaDoc()
102     {
103       public void actionPerformed(ActionEvent JavaDoc e)
104       {
105         _butIncludePath_actionPerformed(e);
106       }
107     });
108     _butIncludePath.setPreferredSize(new Dimension JavaDoc(21, 21));
109     jPanel6.setLayout(borderLayout4);
110     _butTemplate.setPreferredSize(new Dimension JavaDoc(21, 21));
111     _butTemplate.addActionListener(new java.awt.event.ActionListener JavaDoc()
112     {
113       public void actionPerformed(ActionEvent JavaDoc e)
114       {
115         _butTemplate_actionPerformed(e);
116       }
117     });
118     _butTemplate.setText("...");
119     jPanel7.setLayout(borderLayout5);
120     _edtTemplateSetPath.setPreferredSize(new Dimension JavaDoc(300, 21));
121     getContentPane().add(panel1);
122     panel1.add(jPanel1, BorderLayout.WEST);
123     jPanel1.add(jLabel1, null);
124     jPanel1.add(jLabel2, null);
125     panel1.add(jPanel2, BorderLayout.CENTER);
126     jPanel7.add(_edtTemplateSetPath, BorderLayout.CENTER);
127     jPanel7.add(_butTemplate, BorderLayout.EAST);
128     jPanel2.add(jPanel7, null);
129     jPanel2.add(jPanel6, null);
130     jPanel6.add(_edtIncludePath, BorderLayout.CENTER);
131     jPanel6.add(_butIncludePath, BorderLayout.EAST);
132     this.getContentPane().add(jPanel3, BorderLayout.SOUTH);
133     jPanel3.add(jPanel4, BorderLayout.EAST);
134     jPanel4.add(_butCancel, null);
135     jPanel4.add(_butOk, null);
136   }
137
138   void _butOk_actionPerformed(ActionEvent JavaDoc e)
139   {
140     _canceled = false;
141     _props.setProperty(Generator.KEY_TEMPLATEPATH, _edtTemplateSetPath.getText());
142     _props.setProperty(Generator.KEY_INCLUDEPATH, _edtIncludePath.getText());
143     setVisible(false);
144   }
145
146   void _butCancel_actionPerformed(ActionEvent JavaDoc e)
147   {
148     setVisible(false);
149   }
150
151   public boolean wasCancelled()
152   {
153     return _canceled;
154   }
155
156   void _butIncludePath_actionPerformed(ActionEvent JavaDoc e)
157   {
158     _edtIncludePath.setText(getPath("Include path", _edtIncludePath.getText()));
159
160   }
161
162   String JavaDoc getPath(String JavaDoc title, String JavaDoc path)
163   {
164     JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
165     fc.setDialogTitle(title);
166
167     String JavaDoc startHere = path;
168
169     if (startHere.indexOf(";") != -1) startHere = startHere.substring(0, startHere.indexOf(";"));
170
171     if (startHere.trim().length() == 0) startHere = System.getProperties().getProperty("user.dir");
172
173     fc.setCurrentDirectory(new File JavaDoc(startHere));
174     fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
175
176     if (fc.showDialog(this, "Add to path") != JFileChooser.CANCEL_OPTION)
177     {
178       String JavaDoc current = path.trim();
179       if (current.length() != 0) current += ";";
180       current += fc.getSelectedFile().getAbsolutePath();
181
182       path = current;
183     }
184     return path;
185   }
186
187   void _butTemplate_actionPerformed(ActionEvent JavaDoc e)
188   {
189     _edtTemplateSetPath.setText(getPath("Template path", _edtTemplateSetPath.getText()));
190   }
191
192 }
Popular Tags