1
2
3
4 package net.sf.bddbddb;
5
6 import java.applet.Applet;
7 import java.applet.AudioClip;
8 import java.awt.BorderLayout;
9 import java.io.File;
10 import java.io.IOException;
11 import java.net.MalformedURLException;
12 import javax.swing.JButton;
13 import javax.swing.JFileChooser;
14 import javax.swing.JFrame;
15 import javax.swing.JMenu;
16 import javax.swing.JMenuBar;
17 import javax.swing.JMenuItem;
18 import javax.swing.JPanel;
19 import javax.swing.JScrollPane;
20 import javax.swing.JTextField;
21 import javax.swing.JTextPane;
22 import javax.swing.filechooser.FileFilter;
23
24 /***
25 * SolverGUI
26 *
27 * @author John Whaley
28 * @version $Id: SolverGUI.java 531 2005-04-29 06:39:10Z joewhaley $
29 */
30 public class SolverGUI extends JFrame {
31 /***
32 * Version ID for serialization.
33 */
34 private static final long serialVersionUID = 4049917160464004665L;
35
36 private javax.swing.JPanel jContentPane = null;
37 private JMenuBar jJMenuBar = null;
38 private JMenu jFileMenu = null;
39 private JMenuItem jOpenMenuItem = null;
40 private JMenuItem jExitMenuItem = null;
41 private JFileChooser jFileChooser = null;
42 private JTextPane jTextPane = null;
43 private JMenuItem jSaveMenuItem = null;
44 private JMenuItem jSaveAsMenuItem = null;
45 private JPanel jPanel = null;
46 private JTextField jTextField = null;
47 private JButton jButton = null;
48 private FileFilter jFileFilter = null;
49 private JScrollPane jScrollPane = null;
50
51 /***
52 * This method initializes jJMenuBar
53 *
54 * @return javax.swing.JMenuBar
55 */
56 private JMenuBar getJJMenuBar() {
57 if (jJMenuBar == null) {
58 jJMenuBar = new JMenuBar();
59 jJMenuBar.add(getJFileMenu());
60 }
61 return jJMenuBar;
62 }
63
64 /***
65 * This method initializes jFileMenu
66 *
67 * @return javax.swing.JMenu
68 */
69 private JMenu getJFileMenu() {
70 if (jFileMenu == null) {
71 jFileMenu = new JMenu();
72 jFileMenu.setText("File");
73 jFileMenu.add(getJOpenMenuItem());
74 jFileMenu.add(getJSaveMenuItem());
75 jFileMenu.add(getJSaveAsMenuItem());
76 jFileMenu.addSeparator();
77 jFileMenu.add(getJExitMenuItem());
78 }
79 return jFileMenu;
80 }
81
82 /***
83 * This method initializes jOpenMenuItem
84 *
85 * @return javax.swing.JMenuItem
86 */
87 private JMenuItem getJOpenMenuItem() {
88 if (jOpenMenuItem == null) {
89 jOpenMenuItem = new JMenuItem();
90 jOpenMenuItem.setText("Open Datalog...");
91 jOpenMenuItem.addActionListener(new java.awt.event.ActionListener() {
92 public void actionPerformed(java.awt.event.ActionEvent e) {
93
94 JFileChooser fc = getJFileChooser();
95 int returnVal = fc.showOpenDialog(SolverGUI.this);
96 if (returnVal == JFileChooser.APPROVE_OPTION) {
97 File file = fc.getSelectedFile();
98 try {
99 jTextPane.setPage(file.toURL());
100 } catch (MalformedURLException e1) {
101
102 e1.printStackTrace();
103 } catch (IOException e1) {
104
105 e1.printStackTrace();
106 }
107 } else {
108
109 }
110 }
111 });
112 }
113 return jOpenMenuItem;
114 }
115
116 private static void createAndShowGUI() {
117 SolverGUI t = new SolverGUI();
118 t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
119 t.setVisible(true);
120 }
121
122 /***
123 * This method initializes jExitMenuItem
124 *
125 * @return javax.swing.JMenuItem
126 */
127 private JMenuItem getJExitMenuItem() {
128 if (jExitMenuItem == null) {
129 jExitMenuItem = new JMenuItem();
130 jExitMenuItem.setText("Exit");
131 jExitMenuItem.addActionListener(new java.awt.event.ActionListener() {
132 public void actionPerformed(java.awt.event.ActionEvent e) {
133 System.exit(0);
134 }
135 });
136 }
137 return jExitMenuItem;
138 }
139
140 /***
141 * This method initializes jFileFilter
142 *
143 * @return javax.swing.FileFilter
144 */
145 private FileFilter getJFileFilter() {
146 if (jFileFilter == null) {
147 jFileFilter = new FileFilter() {
148 public boolean accept(File f) {
149 return f.isDirectory() || f.getName().endsWith(".datalog");
150 }
151
152 public String getDescription() {
153 return "Datalog files (.datalog)";
154 }
155 };
156 }
157 return jFileFilter;
158 }
159
160 /***
161 * This method initializes jFileChooser
162 *
163 * @return javax.swing.JFileChooser
164 */
165 private JFileChooser getJFileChooser() {
166 if (jFileChooser == null) {
167 jFileChooser = new JFileChooser();
168 jFileChooser.setFileFilter(getJFileFilter());
169 }
170 return jFileChooser;
171 }
172
173 /***
174 * This method initializes jTextPane
175 *
176 * @return javax.swing.JTextPane
177 */
178 private JTextPane getJTextPane() {
179 if (jTextPane == null) {
180 jTextPane = new JTextPane();
181 jTextPane.setFont(new java.awt.Font("Times New Roman", java.awt.Font.ITALIC, 16));
182 }
183 return jTextPane;
184 }
185
186 /***
187 * This method initializes jSaveMenuItem
188 *
189 * @return javax.swing.JMenuItem
190 */
191 private JMenuItem getJSaveMenuItem() {
192 if (jSaveMenuItem == null) {
193 jSaveMenuItem = new JMenuItem();
194 jSaveMenuItem.setText("Save");
195 }
196 return jSaveMenuItem;
197 }
198
199 /***
200 * This method initializes jSaveAsMenuItem
201 *
202 * @return javax.swing.JMenuItem
203 */
204 private JMenuItem getJSaveAsMenuItem() {
205 if (jSaveAsMenuItem == null) {
206 jSaveAsMenuItem = new JMenuItem();
207 jSaveAsMenuItem.setText("Save As...");
208 jSaveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
209 public void actionPerformed(java.awt.event.ActionEvent e) {
210 JFileChooser fc = getJFileChooser();
211 int returnVal = fc.showSaveDialog(SolverGUI.this);
212 if (returnVal == JFileChooser.APPROVE_OPTION) {
213 File file = fc.getSelectedFile();
214 jTextPane.setText("Saving: " + file.getName());
215 } else {
216 jTextPane.setText("Save command cancelled by user.");
217 }
218 }
219 });
220 }
221 return jSaveAsMenuItem;
222 }
223
224 /***
225 * This method initializes jPanel
226 *
227 * @return javax.swing.JPanel
228 */
229 private JPanel getJPanel() {
230 if (jPanel == null) {
231 jPanel = new JPanel();
232 jPanel.setLayout(new BorderLayout());
233 jPanel.add(getJTextField(), java.awt.BorderLayout.CENTER);
234 jPanel.add(getJButton(), java.awt.BorderLayout.EAST);
235 }
236 return jPanel;
237 }
238
239 /***
240 * This method initializes jTextField
241 *
242 * @return javax.swing.JTextField
243 */
244 private JTextField getJTextField() {
245 if (jTextField == null) {
246 jTextField = new JTextField();
247 jTextField.addActionListener(new java.awt.event.ActionListener() {
248 public void actionPerformed(java.awt.event.ActionEvent e) {
249
250 System.out.println("actionPerformed()");
251
252
253
254 }
255 });
256 }
257 return jTextField;
258 }
259
260 /***
261 * This method initializes jButton
262 *
263 * @return javax.swing.JButton
264 */
265 private JButton getJButton() {
266 if (jButton == null) {
267 jButton = new JButton();
268 jButton.setText("Add");
269 jButton.addActionListener(new java.awt.event.ActionListener() {
270 public void actionPerformed(java.awt.event.ActionEvent e) {
271 File sound = new File("bddbddb.wav");
272 try {
273 AudioClip audioClip = Applet.newAudioClip(sound.toURL());
274 audioClip.play();
275 } catch (MalformedURLException e1) {
276
277 e1.printStackTrace();
278 }
279 }
280 });
281 }
282 return jButton;
283 }
284
285 /***
286 *
287 * This method initializes jScrollPane
288 *
289 *
290 *
291 * @return javax.swing.JScrollPane
292 *
293 */
294 private JScrollPane getJScrollPane() {
295 if (jScrollPane == null) {
296 jScrollPane = new JScrollPane();
297 jScrollPane.setViewportView(getJTextPane());
298 }
299 return jScrollPane;
300 }
301
302 public static void main(String[] args) {
303 javax.swing.SwingUtilities.invokeLater(new Runnable() {
304 public void run() {
305 createAndShowGUI();
306 }
307 });
308 }
309
310 /***
311 * This is the default constructor
312 */
313 public SolverGUI() {
314 super();
315 initialize();
316 }
317
318 /***
319 * This method initializes this
320 */
321 private void initialize() {
322 this.setTitle("bddbddb");
323 this.setSize(300, 200);
324 this.setJMenuBar(getJJMenuBar());
325 this.setContentPane(getJContentPane());
326 }
327
328 /***
329 * This method initializes jContentPane
330 *
331 * @return javax.swing.JPanel
332 */
333 private javax.swing.JPanel getJContentPane() {
334 if (jContentPane == null) {
335 jContentPane = new javax.swing.JPanel();
336 jContentPane.setLayout(new java.awt.BorderLayout());
337 jContentPane.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
338 jContentPane.add(getJPanel(), java.awt.BorderLayout.SOUTH);
339 }
340 return jContentPane;
341 }
342 }