aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/qcommon/Q2DataDialog.java
blob: cf1a9fa720a43d78468807cec17e4762938b6e2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
 * Q2DataDialog.java
 *
 * Created on 17. September 2004, 20:13
 */

package jake2.qcommon;

import java.awt.*;
import java.awt.DisplayMode;
import java.awt.GraphicsEnvironment;
import java.io.IOException;

import javax.swing.*;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

/**
 *
 * @author  hoz
 */
public class Q2DataDialog extends javax.swing.JDialog {
    
    /** Creates new form Q2DataDialog */
    public Q2DataDialog() {
        super();
        initComponents();
       
		DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
		int x = (mode.getWidth() - getWidth()) / 2;
		int y = (mode.getHeight() - getHeight()) / 2;
		setLocation(x, y);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        choosePanel = new javax.swing.JPanel();
        statusPanel = new JPanel();
        status = new JLabel("initializing Jake2...");
        jTextField1 = new javax.swing.JTextField();
        changeButton = new javax.swing.JButton();
        installButton = new javax.swing.JButton();
        exitButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Jake2 - Bytonic Software");

        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        choosePanel.setLayout(new java.awt.GridBagLayout());

        choosePanel.setMaximumSize(new java.awt.Dimension(400, 100));
        choosePanel.setMinimumSize(new java.awt.Dimension(400, 100));
        choosePanel.setPreferredSize(new java.awt.Dimension(400, 100));
        jTextField1.setPreferredSize(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        gridBagConstraints.weightx = 1.0;
        choosePanel.add(jTextField1, gridBagConstraints);

        changeButton.setText("change");
        changeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        choosePanel.add(changeButton, gridBagConstraints);

        installButton.setText("Install");
        installButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                installButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        choosePanel.add(installButton, gridBagConstraints);

        exitButton.setText("Exit");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        choosePanel.add(exitButton, gridBagConstraints);

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        choosePanel.add(okButton, gridBagConstraints);

        //getContentPane().add(choosePanel, java.awt.BorderLayout.SOUTH);

		Jake2Canvas c = new Jake2Canvas();
		getContentPane().add(c, BorderLayout.CENTER);

		statusPanel.setLayout(new java.awt.GridBagLayout());
		statusPanel.setMaximumSize(new java.awt.Dimension(400, 100));
		statusPanel.setMinimumSize(new java.awt.Dimension(400, 100));
		statusPanel.setPreferredSize(new java.awt.Dimension(400, 100));
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.gridwidth = 1;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
		gridBagConstraints.weightx = 1.0;
		statusPanel.add(status, gridBagConstraints);
		getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH);
						
        pack();
    }//GEN-END:initComponents

    private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_installButtonActionPerformed

    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
    	System.exit(1);
    	dispose();
    }//GEN-LAST:event_exitButtonActionPerformed

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
    	
    	Cvar.Set("cddir", dir);
    	FS.setCDDir();
    	
    	synchronized(this) {
    		notifyAll();
    	}
    }//GEN-LAST:event_okButtonActionPerformed

    private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeButtonActionPerformed
    	JFileChooser chooser = new JFileChooser();
    	chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    	chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    	chooser.setMultiSelectionEnabled(false);
    	chooser.setDialogTitle("choose a valid baseq2 directory");
    	chooser.showDialog(this, "OK");
    	
    	dir = null;
    	try {
			dir = chooser.getSelectedFile().getCanonicalPath();
		} catch (IOException e) {}
		jTextField1.setText(dir);
        
    }//GEN-LAST:event_changeButtonActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    	System.exit(1);
    	dispose();
    }//GEN-LAST:event_formWindowClosing
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new Q2DataDialog().show();
        System.out.println("Hi");
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton changeButton;
    private javax.swing.JButton exitButton;
    private javax.swing.JButton installButton;
    private Jake2Canvas canvas;
    private javax.swing.JPanel choosePanel;
    private JPanel statusPanel;
    private JLabel status;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables
    
	private String dir;
	
	void showChooseDialog() {
		getContentPane().remove(statusPanel);
		getContentPane().add(choosePanel, BorderLayout.SOUTH);
		validate();
		repaint();
	}
	
	void showStatus() {
		getContentPane().remove(choosePanel);
		getContentPane().add(statusPanel, BorderLayout.SOUTH);
		validate();
		repaint();		
	}
	
	void setStatus(String text) {
		status.setText(text);
	}
	
	void testQ2Data() {
		while (FS.LoadFile("pics/colormap.pcx") == null) {
			showChooseDialog();
			
			try {
				synchronized(this) {
					wait();
				}
			} catch (InterruptedException e) {}
		}
		showStatus();
	}
		
	static class Jake2Canvas extends Canvas {
		private Image image;
		Jake2Canvas() {
			setSize(400, 200);
			image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/splash.png"));
			while (!Toolkit.getDefaultToolkit().prepareImage(image, -1, -1, null)) {
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {}
			} 
		}
		
		
		/* (non-Javadoc)
		 * @see java.awt.Component#paint(java.awt.Graphics)
		 */
		public void paint(Graphics g) {
			g.drawImage(image, 0, 0, null);
		}

	}
}