Fix most warnings from GCJ
[jpcrr.git] / org / jpc / pluginsaux / NewDiskDialog.java
blobba9de0b833c5f5642b664aed49fe27e25eaad7bb
1 /*
2 JPC-RR: A x86 PC Hardware Emulator
3 Release 1
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009 H. Ilari Liusvaara
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Based on JPC x86 PC Hardware emulator,
22 A project from the Physics Dept, The University of Oxford
24 Details about original JPC can be found at:
26 www-jpc.physics.ox.ac.uk
30 package org.jpc.pluginsaux;
32 import org.jpc.diskimages.DiskImage;
33 import static org.jpc.Misc.callShowOptionDialog;
35 import javax.swing.*;
36 import java.awt.event.*;
37 import java.awt.*;
39 public class NewDiskDialog implements ActionListener, WindowListener
41 private JFrame window;
42 private JPanel panel;
43 private Response response;
44 private boolean answerReady;
45 private JTextField nameField;
46 private JComboBox imageField;
48 public class Response
50 public String diskName;
51 public String diskFile;
54 public NewDiskDialog()
56 response = null;
57 answerReady = false;
58 window = new JFrame("Add disk");
59 GridLayout layout = new GridLayout(0, 2);
60 panel = new JPanel(layout);
61 window.add(panel);
62 window.addWindowListener(this);
64 JLabel label = new JLabel("Image name");
65 nameField = new JTextField("Image", 40);
66 panel.add(label);
67 panel.add(nameField);
69 label = new JLabel("Image name");
70 String[] choices = DiskImage.getLibrary().imagesByType(10); //FLOPPY and CDROM
71 if(choices == null) {
72 synchronized(this) {
73 response = null;
74 answerReady = true;
75 notifyAll();
77 callShowOptionDialog(null, "No images available.", "Can't add disk", JOptionPane.YES_NO_OPTION,
78 JOptionPane.WARNING_MESSAGE, null, new String[]{"Dismiss"}, "Dismiss");
79 return;
82 imageField = new JComboBox(choices);
83 panel.add(label);
84 panel.add(imageField);
86 JButton ass = new JButton("Add");
87 ass.setActionCommand("ADD");
88 ass.addActionListener(this);
89 JButton cancl = new JButton("Cancel");
90 cancl.setActionCommand("CANCEL");
91 cancl.addActionListener(this);
92 panel.add(ass);
93 panel.add(cancl);
95 window.pack();
96 window.setVisible(true);
97 window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
100 public synchronized Response waitClose()
102 if(answerReady) {
103 answerReady = false;
104 return response;
106 while(!answerReady) {
107 try {
108 wait();
109 } catch(InterruptedException e) {
112 answerReady = false;
113 return response;
116 public void actionPerformed(ActionEvent evt)
118 String command = evt.getActionCommand();
119 if(command == "ADD") {
120 response = new Response();
121 response.diskFile = nameField.getText();
122 response.diskName = (String)(imageField.getSelectedItem());
123 window.setVisible(false);
124 window.dispose();
125 synchronized(this) {
126 answerReady = true;
127 notifyAll();
129 } else if(command == "CANCEL") {
130 window.setVisible(false);
131 window.dispose();
132 synchronized(this) {
133 response = null;
134 answerReady = true;
135 notifyAll();
140 public void windowActivated(WindowEvent e) { /* Not interested. */ }
141 public void windowClosed(WindowEvent e) { /* Not interested. */ }
142 public void windowDeactivated(WindowEvent e) { /* Not interested. */ }
143 public void windowDeiconified(WindowEvent e) { /* Not interested. */ }
144 public void windowIconified(WindowEvent e) { /* Not interested. */ }
145 public void windowOpened(WindowEvent e) { /* Not interested. */ }
147 public void windowClosing(WindowEvent e)
149 window.setVisible(false);
150 synchronized(this) {
151 response = null;
152 answerReady = true;
153 notifyAll();