aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/qcommon/Q2DataDialog.java
blob: 9dde19629e8f721eef8690891b11ae0492cc148b (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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
/*
 * Q2DataDialog.java
 * Copyright (C)  2003
 * 
 * $Id: Q2DataDialog.java,v 1.11 2004-09-26 19:58:56 hzi Exp $
 */

package jake2.qcommon;

import jake2.Globals;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import javax.imageio.ImageIO;
import javax.swing.*;


public class Q2DataDialog extends javax.swing.JDialog {
	
	static final String home = System.getProperty("user.home");
	static final String sep = System.getProperty("file.separator");
    
    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);
		dir = home + sep + "jake2" + sep + "baseq2";
		jTextField1.setText(dir);
    }
    
    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();
        cancelButton = 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));


		
        gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.gridwidth = 1;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
		gridBagConstraints.weightx = 0;
		gridBagConstraints.anchor = GridBagConstraints.SOUTHWEST;
		choosePanel.add(new JLabel("baseq2 directory"),gridBagConstraints);
        
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(5, 2, 5, 2);
        gridBagConstraints.weightx = 1;
        choosePanel.add(jTextField1, gridBagConstraints);

        changeButton.setText("...");
        changeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeButtonActionPerformed(evt);
            }
        });
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 1;
		gridBagConstraints.weightx = 0;
		gridBagConstraints.fill = java.awt.GridBagConstraints.NONE;
        gridBagConstraints.insets = new java.awt.Insets(5, 2, 5, 5);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        choosePanel.add(changeButton, gridBagConstraints);

		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.gridwidth = 4;
		gridBagConstraints.weightx = 0;
		gridBagConstraints.weighty = 1;
		gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
		choosePanel.add(new JPanel(), gridBagConstraints);

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
		gridBagConstraints.gridwidth = 4;
		gridBagConstraints.weighty = 0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        choosePanel.add(cancelButton, gridBagConstraints);

        exitButton.setText("Exit");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
		gridBagConstraints.gridwidth = 1;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
        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.gridx = 2;
        gridBagConstraints.gridy = 2;
		gridBagConstraints.gridwidth = 2;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
		choosePanel.add(okButton, gridBagConstraints);

 
		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);
		
		progressPanel = new ProgressPanel(this);
		installPanel = new InstallPanel(this);
		notFoundPanel = new NotFoundPanel(this);
						
        pack();
    }
	
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
		showNotFoundPanel();
    }
    
    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	System.exit(1);
    	dispose();
    }
    
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	
    	if (dir != null) {
    		Cvar.Set("cddir", dir);
    		FS.setCDDir();
    	}
    	
    	synchronized(this) {
    		notifyAll();
    	}
    }

    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 (Exception e) {}
		if (dir != null) jTextField1.setText(dir);
		else dir = jTextField1.getText();
        
    }//GEN-LAST:event_changeButtonActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    	System.exit(1);
    	dispose();
    }//GEN-LAST:event_formWindowClosing
        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton changeButton;
    private javax.swing.JButton exitButton;
    private javax.swing.JButton cancelButton;
    private Jake2Canvas canvas;
    private javax.swing.JPanel choosePanel;
    private JPanel statusPanel;
    private ProgressPanel progressPanel;
    private InstallPanel installPanel;
    private NotFoundPanel notFoundPanel;
    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().remove(progressPanel);
		getContentPane().remove(installPanel);
		getContentPane().remove(notFoundPanel);
		getContentPane().add(choosePanel, BorderLayout.SOUTH);
		validate();
		repaint();
	}
	
	void showStatus() {
		getContentPane().remove(choosePanel);
		getContentPane().remove(installPanel);
		getContentPane().add(statusPanel, BorderLayout.SOUTH);
		validate();
		repaint();		
	}
	
	void showProgressPanel() {
		getContentPane().remove(choosePanel);
		getContentPane().remove(installPanel);
		getContentPane().add(progressPanel, BorderLayout.SOUTH);
		validate();
		repaint();
	}
	
	void showInstallPanel() {
		getContentPane().remove(choosePanel);
		getContentPane().remove(statusPanel);
		getContentPane().remove(notFoundPanel);
		getContentPane().add(installPanel, BorderLayout.SOUTH);
		validate();
		repaint();
	}
	
	void showNotFoundPanel() {
		getContentPane().remove(choosePanel);
		getContentPane().remove(installPanel);
		getContentPane().remove(statusPanel);
		getContentPane().add(notFoundPanel, BorderLayout.SOUTH);
		validate();
		repaint();
	}	
	
	void setStatus(String text) {
		status.setText(text);
	}
	
	void testQ2Data() {
		while (FS.LoadFile("pics/colormap.pcx") == null) {
			showNotFoundPanel();
			
			try {
				synchronized(this) {
					wait();
				}
			} catch (InterruptedException e) {}
		}
		showStatus();
		repaint();
	}
		
	static class Jake2Canvas extends Canvas {
		private Image image;
		Jake2Canvas() {
			setSize(400, 200);
			try {
				image = ImageIO.read(getClass().getResource("/splash.png"));
			} catch (Exception e) {}

		}
		
		
		/* (non-Javadoc)
		 * @see java.awt.Component#paint(java.awt.Graphics)
		 */
		public void paint(Graphics g) {
			g.drawImage(image, 0, 0, null);
		}

	}
	
	static class NotFoundPanel extends JPanel {
		
		private Q2DataDialog parent;
		private ButtonGroup selection;
		private JRadioButton dir;
		private JRadioButton install;
		private JButton exit;
		private JButton ok;
		private JLabel message;
		
		NotFoundPanel(Q2DataDialog d) {
			parent = d;
			initComponents();
		}
		
		private void initComponents() {
			GridBagConstraints constraints = new GridBagConstraints();
			setLayout(new GridBagLayout());
			Dimension d = new Dimension(400, 100);
			setMinimumSize(d);
			setMaximumSize(d);
			setPreferredSize(d);
			
			message = new JLabel("Quake2 level data not found");
			message.setForeground(Color.RED);
			constraints.gridx = 0;
			constraints.gridy = 0;
			constraints.gridwidth = 2;
			constraints.insets = new Insets(5, 5, 2, 5);
			constraints.anchor = GridBagConstraints.CENTER;
			add(message, constraints);
						
			constraints.gridx = 1;
			constraints.gridy = 1;
			constraints.gridwidth = 2;
			constraints.weightx = 1;
			constraints.fill = GridBagConstraints.HORIZONTAL;			
			constraints.insets = new Insets(0, 2, 0, 5);
			constraints.anchor = GridBagConstraints.WEST;
			add(new JLabel("select baseq2 directory from existing Quake2 installation"), constraints);
			
			constraints.gridx = 1;
			constraints.gridy = 2;
			add(new JLabel("download and install Quake2 demo data (38MB)"), constraints);
			
			selection = new ButtonGroup();
			dir = new JRadioButton();
			install = new JRadioButton();
			selection.add(dir);
			selection.add(install);

			constraints.gridx = 0;
			constraints.gridy = 1;
			constraints.gridwidth = 1;
			constraints.weightx = 0;
			constraints.insets = new Insets(0, 5, 0, 2);
			constraints.fill = GridBagConstraints.NONE;
			constraints.anchor = GridBagConstraints.EAST;
			dir.setSelected(true);
			add(dir, constraints);
			
			constraints.gridx = 0;
			constraints.gridy = 2;
			add(install, constraints);
			
			constraints.gridx = 0;
			constraints.gridy = 3;
			constraints.gridwidth = 2;
			constraints.weighty = 1;
			constraints.insets = new Insets(5, 5, 5, 5);
			constraints.fill = GridBagConstraints.NONE;
			constraints.anchor = GridBagConstraints.SOUTHWEST;
			exit = new JButton("Exit");
			exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}});
			add(exit, constraints);			
			
			constraints.gridx = 2;
			constraints.gridy = 3;
			constraints.gridwidth = 1;
			constraints.anchor = GridBagConstraints.SOUTHEAST;	
			ok = new JButton("OK");
			ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ok();
			}});
			add(ok, constraints);				
		}
		
		private void ok() {
			if (dir.isSelected()) {
				parent.showChooseDialog();
			} else {
				parent.showInstallPanel();
			}
		}
	}
	
	static class InstallPanel extends JPanel {
		
		private Vector mirrorNames = new Vector();
		private Vector mirrorLinks = new Vector();		
		private Q2DataDialog parent;
		private JComboBox mirrorBox;
		private JTextField destDir;
		private JButton cancel;
		private JButton exit;
		private JButton install;
		private JButton choose;
		
		public InstallPanel(Q2DataDialog d) {
			initComponents();
			String dir = Q2DataDialog.home + Q2DataDialog.sep + "jake2";
			destDir.setText(dir);
			initMirrors();
			parent = d;
		}
		
		private void initComponents() {
			GridBagConstraints constraints = new GridBagConstraints();
			setLayout(new GridBagLayout());
			Dimension d = new Dimension(400, 100);
			setMinimumSize(d);
			setMaximumSize(d);
			setPreferredSize(d);
			
			constraints.gridx = 0;
			constraints.gridy = 0;
			constraints.insets = new Insets(5, 5, 0, 5);
			constraints.anchor = GridBagConstraints.SOUTHWEST;
			add(new JLabel("download mirror"), constraints);
			
			constraints.gridx = 0;
			constraints.gridy = 1;
			constraints.insets = new Insets(5, 5, 5, 5);
			add(new JLabel("destination directory"), constraints);
			
			constraints.gridx = 1;
			constraints.gridy = 0;
			constraints.weightx = 1;
			constraints.gridwidth = 3;
			constraints.insets = new Insets(5, 5, 0, 5);
			constraints.fill = GridBagConstraints.HORIZONTAL;
			mirrorBox = new JComboBox();
			add(mirrorBox, constraints);
			
			constraints.gridx = 1;
			constraints.gridy = 1;
			constraints.gridwidth = 2;
			constraints.fill = GridBagConstraints.BOTH;
			constraints.insets = new Insets(5, 5, 5, 5);
			destDir = new JTextField();
			add(destDir, constraints);
			
			constraints.gridx = 3;
			constraints.gridy = 1;
			constraints.weightx = 0;
			constraints.gridwidth = 1;
			constraints.fill = GridBagConstraints.NONE;
			choose = new JButton("...");
			choose.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					choose();
				}});
			add(choose, constraints);
			
			constraints.gridx = 0;
			constraints.gridy = 2;
			constraints.gridwidth = 1;
			constraints.weighty = 1;
			constraints.fill = GridBagConstraints.NONE;
			exit = new JButton("Exit");
			exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exit();
			}});
			add(exit, constraints);
			
			constraints.gridx = 0;
			constraints.gridy = 2;
			constraints.gridwidth = 4;
			constraints.anchor = GridBagConstraints.SOUTH;
			cancel = new JButton("Cancel");
			cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cancel();
			}});
			add(cancel, constraints);						

			constraints.gridx = 2;
			constraints.gridy = 2;
			constraints.gridwidth = 2;
			constraints.anchor = GridBagConstraints.SOUTHEAST;
			install = new JButton("Install");
			install.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				install();
			}});
			add(install, constraints);			
		}
		
		private void readMirrors() {
			InputStream in = getClass().getResourceAsStream("/mirrors");
			BufferedReader r = new BufferedReader(new InputStreamReader(in));
			try {
				int i = 0;
				while (true) {
					String name = r.readLine();
					String value = r.readLine();
					if (name == null || value == null) break;
					mirrorNames.add(name);
					mirrorLinks.add(value);
				}
			} catch (Exception e) {} 
			finally {
				try {
					r.close();
				} catch (Exception e1) {}
				try {
					in.close();
				} catch (Exception e1) {}
			}
		}
		
		private void initMirrors() {
			readMirrors();
			for (int i = 0; i < mirrorNames.size(); i++) {
				mirrorBox.addItem(mirrorNames.get(i));
			}
			int i = Globals.rnd.nextInt(mirrorNames.size());
			mirrorBox.setSelectedIndex(i);
		}
		
		private void cancel() {
			parent.showNotFoundPanel();
		}
		
		private void install() {
			parent.progressPanel.destDir = destDir.getText();
			parent.progressPanel.mirror = (String)mirrorLinks.get(mirrorBox.getSelectedIndex());
			parent.showProgressPanel();
			new Thread(parent.progressPanel).start();
		}
		
		private void exit() {
			System.exit(0);
		}
		
		private void choose() {
			JFileChooser chooser = new JFileChooser();
			chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
			chooser.setMultiSelectionEnabled(false);
			chooser.setDialogTitle("choose destination directory");
			chooser.showDialog(this, "OK");
    	
			String dir = null;
			try {
				dir = chooser.getSelectedFile().getCanonicalPath();
			} catch (Exception e) {}
			if (dir != null) destDir.setText(dir);			
		}
	}
	
	static class ProgressPanel extends JPanel implements Runnable {
		
		static byte[] buf = new byte[8192];
		String destDir;
		String mirror;
		
		JProgressBar progress = new JProgressBar();
		JLabel label = new JLabel("");
		JButton cancel = new JButton("Cancel");
		Q2DataDialog parent;
		boolean running;
		
		public ProgressPanel(Q2DataDialog d) {
			initComponents();
			parent = d;
		}
		
		void initComponents() {
			progress.setMinimum(0);
			progress.setMaximum(100);
			progress.setStringPainted(true);
			setLayout(new GridBagLayout());
			GridBagConstraints gridBagConstraints = new GridBagConstraints();

			gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			gridBagConstraints.gridwidth = 1;
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints.insets = new Insets(5, 10, 5, 10);
			gridBagConstraints.weightx = 1.0;
			gridBagConstraints.anchor = GridBagConstraints.SOUTH;
			add(label, gridBagConstraints);
			
			gridBagConstraints.gridy = 1;
			gridBagConstraints.anchor = GridBagConstraints.NORTH;
			add(progress, gridBagConstraints);
			
			gridBagConstraints.gridy = 1;
			gridBagConstraints.anchor = GridBagConstraints.SOUTH;
			gridBagConstraints.fill = GridBagConstraints.NONE;
			gridBagConstraints.weighty = 1;
			gridBagConstraints.weightx = 0;
			cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cancel();
			}});
			add(cancel, gridBagConstraints);
			
			Dimension d = new Dimension(400, 100);
			setMinimumSize(d);
			setMaximumSize(d);
			setPreferredSize(d);
		}
		
		void cancel() {
			synchronized(this) {
				running = false;
			}
		}
						
		public void run() {
			synchronized(this) {
				running = true;
			}
			
			InputStream in = null;
			OutputStream out = null;
			File outFile = null;
			
			label.setText("downloading...");
			
			File dir = null;
			try {
				dir = new File(destDir);
				dir.mkdirs();
			}
			catch (Exception e) {}
			try {
				if (!dir.isDirectory() || !dir.canWrite()) {
					endInstall();
					return;
				} 
			}
			catch (Exception e) {
				endInstall();
				return;
			}
			
			try {
				URL url = new URL(mirror);
				URLConnection conn = url.openConnection();
				int length = conn.getContentLength();
				progress.setMaximum(length / 1024);

				in = conn.getInputStream();

				outFile = File.createTempFile("Jake2Data", ".zip");
				outFile.deleteOnExit();
				out = new FileOutputStream(outFile);

				copyStream(in, out);
			} catch (Exception e) {
				endInstall();
				return;
			} finally {
				try {
					in.close();
				} catch (Exception e) {}
				try {
					out.close();
				} catch (Exception e) {}		
			}
			
			try {
				installData(outFile.getCanonicalPath());
			} catch (Exception e) {
				endInstall();
				return;
			}

			
			try {
				if (outFile != null) outFile.delete();
			} catch (Exception e) {}
			
			parent.dir = destDir + "/baseq2";
			parent.showChooseDialog();
			parent.okButtonActionPerformed(null);
		}
		
		
		void installData(String filename) throws Exception {
			InputStream in = null;
			OutputStream out = null;
			try {
				ZipFile f = new ZipFile(filename);
				Enumeration e = f.entries();
				while (e.hasMoreElements()) {
					ZipEntry entry = (ZipEntry)e.nextElement();
					String name = entry.getName();
					int i;
					if ((i = name.indexOf("/baseq2")) > -1 && name.indexOf(".dll") == -1) {
						name = destDir + name.substring(i);
						File outFile = new File(name);
						if (entry.isDirectory()) {
							outFile.mkdirs();
						} else {
							label.setText("installing " + outFile.getName());
							progress.setMaximum((int)entry.getSize()/1024);
							progress.setValue(0); 
							outFile.getParentFile().mkdirs();
							out = new FileOutputStream(outFile);
							in = f.getInputStream(entry);
							copyStream(in, out);
						}
					}
				}
			} catch (Exception e) {
				throw new Exception();
			} finally {
				try {in.close();} catch (Exception e1) {}
				try {out.close();} catch (Exception e1) {}				
			}
		}
		
		void endInstall() {
			parent.dir = destDir + "/baseq2";
			parent.showChooseDialog();
			parent.okButtonActionPerformed(null);			
		}
		
		void copyStream(InputStream in, OutputStream out) throws Exception {
			try {
				int c = 0;
				int l;
				while ((l = in.read(buf)) > 0) {
					if (!running) throw new Exception("installation canceled");
					out.write(buf, 0, l);
					c += l;
					progress.setValue(c / 1024);
				}
			} catch (Exception e) {
				throw new Exception();
			} finally {
				try {
					in.close();
				} catch (Exception e) {}
				try {
					out.close();
				} catch (Exception e) {}
			}			
		}
	}

}