1 /*
2 * MythSim
3 *
4 * Copyright (C) 2002-2004 Jason Vroustouris <jasonv@jasonv.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 package org.mythsim.swing;
22
23 import javax.swing.*;
24 import java.awt.*;
25 import java.awt.event.*;
26 import org.mythsim.swing.*;
27 import java.io.*;
28
29 /***
30 * The Open Dialog.
31 * @author Jason Vroustouris
32 */
33 public class FileJDialog
34 extends JDialog
35 implements ActionListener {
36
37 /*** Reference to mythsim object. **/
38 private MythSimSwing ms;
39 private JButton ucodeJButton = new JButton("...");
40 private JButton memJButton = new JButton("...");
41 private JButton okJButton = new JButton("Ok");
42 private JButton cancelJButton = new JButton("Cancel");
43 private JTextField ucodeJTextField = new JTextField();
44 private JTextField memJTextField = new JTextField();
45 private File ucodeFile = null;
46 private File memFile = null;
47 private boolean filesValid = false;
48 /*** Create and display About Dialog. **/
49 public FileJDialog(MythSimSwing _ms) {
50 super(_ms.f, "Open", true);
51 ms = _ms; // Set up Frame Size
52 filesValid = false;
53 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
54 Dimension frameSize = new Dimension( (int) (500),
55 (int) (100));
56 int x = (int) (screenSize.width / 2 - 250);
57 int y = (int) (screenSize.height / 2 - 50);
58 setBounds(x, y, frameSize.width, frameSize.height);
59 ucodeJButton.addActionListener(this);
60 memJButton.addActionListener(this);
61 okJButton.addActionListener(this);
62 cancelJButton.addActionListener(this);
63 ucodeFile = ms.getMicrocodeFile();
64 memFile = ms.getMemoryFile();
65 ucodeJTextField.setText(ucodeFile.toString());
66 memJTextField.setText(memFile.toString());
67 ucodeJTextField.setEnabled(false);
68 memJTextField.setEnabled(false);
69
70 getContentPane().setLayout(new BorderLayout());
71 // Center Panel
72 JPanel centerPanel = new JPanel(new BorderLayout());
73 JPanel centerWestPanel = new JPanel(new GridLayout(2, 1));
74 JPanel centerCenterPanel = new JPanel(new GridLayout(2, 1));
75 JPanel centerEastPanel = new JPanel(new GridLayout(2, 1));
76 centerWestPanel.add(new JLabel(" mem file: "));
77 centerWestPanel.add(new JLabel(" ucode file: "));
78 centerCenterPanel.add(memJTextField);
79 centerCenterPanel.add(ucodeJTextField);
80 centerEastPanel.add(memJButton);
81 centerEastPanel.add(ucodeJButton);
82 centerPanel.add(centerWestPanel, BorderLayout.WEST);
83 centerPanel.add(centerCenterPanel, BorderLayout.CENTER);
84 centerPanel.add(centerEastPanel, BorderLayout.EAST);
85 getContentPane().add(centerPanel, BorderLayout.CENTER);
86
87 // South Panel
88 JPanel southPanel = new JPanel(new GridLayout(1, 2));
89 southPanel.add(okJButton);
90 southPanel.add(cancelJButton);
91 getContentPane().add(southPanel, BorderLayout.SOUTH);
92 show();
93
94 }
95
96 public boolean isValid() {
97 return filesValid;
98 }
99
100 public void selectMemoryFile() {
101 JFileChooser chooserMemory = new JFileChooser(memFile);
102 chooserMemory.setDialogTitle("Select mem file.");
103 chooserMemory.setCurrentDirectory(ms.currentDirectory);
104 //chooserMemory.setCurrentDirectory(memFile);
105 switch (chooserMemory.showOpenDialog(this)) {
106 case JFileChooser.APPROVE_OPTION:
107 memFile = chooserMemory.getSelectedFile();
108 this.memJTextField.setText(memFile.toString());
109 break;
110 default:
111 dispose();
112 }
113 ms.currentDirectory = chooserMemory.getCurrentDirectory();
114 }
115
116 public void selectUcodeFile() {
117 JFileChooser chooserMicrocode = new JFileChooser(ucodeFile);
118 chooserMicrocode.setDialogTitle("Open ucode file.");
119 //if (ms.currentDirectory != null) {
120 chooserMicrocode.setCurrentDirectory(ms.currentDirectory);
121 //}
122 //chooserMicrocode.setCurrentDirectory(ucodeFile);
123 switch (chooserMicrocode.showOpenDialog(this)) {
124 case JFileChooser.APPROVE_OPTION:
125 ucodeFile = chooserMicrocode.getSelectedFile();
126 this.ucodeJTextField.setText(ucodeFile.toString());
127 break;
128 default:
129 dispose();
130 }
131 ms.currentDirectory = chooserMicrocode.getCurrentDirectory();
132 }
133
134
135 /*** Handel ActionEvents from the OK JButton **/
136 public void actionPerformed(ActionEvent a) {
137 if (a.getSource() == this.ucodeJButton) {
138 selectUcodeFile();
139 }
140 if (a.getSource() == this.memJButton) {
141 selectMemoryFile();
142 }
143 if (a.getSource() == this.okJButton) {
144 try {
145 ms.setFileMicrocode(ucodeFile);
146 }
147 catch (FileNotFoundException ex) {
148 JOptionPane.showMessageDialog(ms.f, "Ucode file not found.");
149 return;
150 }
151 try {
152 ms.setFileMemory(memFile);
153 }
154 catch (FileNotFoundException ex) {
155 JOptionPane.showMessageDialog(ms.f, "Memory file not found.");
156 return;
157 }
158 filesValid = true;
159 hide();
160 }
161 if (a.getSource() == this.cancelJButton) {
162 ms.setMode(MythSimSwing.NO_FILES_MODE);
163 filesValid = false;
164 hide();
165 }
166 }
167
168 }
This page was automatically generated by Maven