From: Holger Z. <hz...@us...> - 2004-09-21 12:52:25
|
Update of /cvsroot/jake2/jake2/src/jake2/qcommon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14789/src/jake2/qcommon Modified Files: Q2DataDialog.java Log Message: dialog reorganized Index: Q2DataDialog.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/qcommon/Q2DataDialog.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Q2DataDialog.java 21 Sep 2004 10:46:08 -0000 1.5 --- Q2DataDialog.java 21 Sep 2004 12:52:14 -0000 1.6 *************** *** 32,35 **** --- 32,37 ---- int y = (mode.getHeight() - getHeight()) / 2; setLocation(x, y); + dir = System.getProperty("user.home") + "/jake2"; + jTextField1.setText(dir); } *************** *** 149,152 **** --- 151,156 ---- statusPanel.add(status, gridBagConstraints); getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH); + + installPanel = new InstallPanel(this); pack(); *************** *** 156,165 **** private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installButtonActionPerformed dir = jTextField1.getText(); ! InstallDialog installer = new InstallDialog(this, dir); dir += "/baseq2"; jTextField1.setText(dir); ! new Thread(installer).start(); ! }//GEN-LAST:event_installButtonActionPerformed --- 160,170 ---- private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installButtonActionPerformed dir = jTextField1.getText(); ! showInstallPanel(); ! installPanel.destDir = dir; ! dir += "/baseq2"; jTextField1.setText(dir); ! new Thread(installPanel).start(); }//GEN-LAST:event_installButtonActionPerformed *************** *** 208,211 **** --- 213,217 ---- private javax.swing.JPanel choosePanel; private JPanel statusPanel; + private InstallPanel installPanel; private JLabel status; private javax.swing.JTextField jTextField1; *************** *** 217,220 **** --- 223,227 ---- void showChooseDialog() { getContentPane().remove(statusPanel); + getContentPane().remove(installPanel); getContentPane().add(choosePanel, BorderLayout.SOUTH); validate(); *************** *** 229,232 **** --- 236,246 ---- } + void showInstallPanel() { + getContentPane().remove(choosePanel); + getContentPane().add(installPanel, BorderLayout.SOUTH); + validate(); + repaint(); + } + void setStatus(String text) { status.setText(text); *************** *** 244,247 **** --- 258,262 ---- } showStatus(); + repaint(); } *************** *** 268,278 **** } ! static class InstallDialog extends JDialog implements Runnable { static final String[] locs = { - "ftp://ftp.idsoftware.com/idstuff/quake2/q2-314-demo-x86.exe", "ftp://ftp.fu-berlin.de/pc/msdos/games/idgames/idstuff/quake2/q2-314-demo-x86.exe", "ftp://ftp.demon.co.uk/pub/mirrors/idsoftware/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.fragzone.se/pub/spel/quake2/q2-314-demo-x86.exe" }; static byte[] buf = new byte[8192]; String destDir; --- 283,293 ---- } ! static class InstallPanel extends JPanel implements Runnable { static final String[] locs = { "ftp://ftp.fu-berlin.de/pc/msdos/games/idgames/idstuff/quake2/q2-314-demo-x86.exe", "ftp://ftp.demon.co.uk/pub/mirrors/idsoftware/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.fragzone.se/pub/spel/quake2/q2-314-demo-x86.exe", ! "ftp://ftp.idsoftware.com/idstuff/quake2/q2-314-demo-x86.exe" }; static byte[] buf = new byte[8192]; String destDir; *************** *** 282,293 **** Q2DataDialog parent; ! public InstallDialog(Q2DataDialog parent, String dir) { ! super(parent); ! initComponents(); ! setResizable(false); ! ! this.parent = parent; ! destDir = dir; } --- 297,303 ---- Q2DataDialog parent; ! public InstallPanel(Q2DataDialog d) { initComponents(); ! parent = d; } *************** *** 295,311 **** progress.setMinimum(0); progress.setMaximum(100); ! progress.setMinimumSize(new Dimension(200, 20)); ! progress.setMaximumSize(new Dimension(200, 20)); ! progress.setPreferredSize(new Dimension(200, 20)); ! getContentPane().add(progress, BorderLayout.CENTER); ! getContentPane().add(label, BorderLayout.NORTH); ! pack(); } public void run() { ! ! parent.setEnabled(false); ! setVisible(true); ! InputStream in = null; OutputStream out = null; --- 305,331 ---- progress.setMinimum(0); progress.setMaximum(100); ! setLayout(new GridBagLayout()); ! GridBagConstraints gridBagConstraints = new GridBagConstraints(); ! ! 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; ! gridBagConstraints.anchor = GridBagConstraints.SOUTH; ! add(label, gridBagConstraints); ! gridBagConstraints.gridy = 1; ! gridBagConstraints.anchor = GridBagConstraints.NORTH; ! add(progress, gridBagConstraints); ! Dimension d = new Dimension(400, 100); ! setMinimumSize(d); ! setMaximumSize(d); ! setPreferredSize(d); } public void run() { ! InputStream in = null; OutputStream out = null; *************** *** 314,335 **** label.setText("downloading..."); try { - URL url = new URL(locs[1]); - URLConnection conn = url.openConnection(); - int length = conn.getContentLength(); - progress.setMaximum(length/1024); - - in = conn.getInputStream(); - - outFile = File.createTempFile("Jake2Data", ".zip"); - System.out.println(outFile.getCanonicalPath()); - outFile.deleteOnExit(); - out = new FileOutputStream(outFile); - - copyStream(in, out); - installData(outFile.getCanonicalPath()); - } catch (Exception e) {} try { --- 334,371 ---- label.setText("downloading..."); + File dir = null; + try { + dir = new File(destDir); + dir.mkdirs(); + } + catch (Exception e) {} + try { + if (!dir.isDirectory() || !dir.canWrite()) return; + } + catch (Exception e) { + return; + } + + for (int i = 0; i < locs.length; i++) { + try { + URL url = new URL(locs[i]); + 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); + break; + } catch (Exception e) {} + } try { installData(outFile.getCanonicalPath()); } catch (Exception e) {} + try { *************** *** 337,344 **** } catch (Exception e) {} ! setVisible(false); ! parent.setEnabled(true); parent.okButtonActionPerformed(null); - dispose(); } --- 373,378 ---- } catch (Exception e) {} ! parent.showChooseDialog(); parent.okButtonActionPerformed(null); } *************** *** 358,362 **** outFile.mkdirs(); } else { ! label.setText(outFile.getName()); progress.setMaximum((int)entry.getSize()/1024); progress.setValue(0); --- 392,396 ---- outFile.mkdirs(); } else { ! label.setText("installing " + outFile.getName()); progress.setMaximum((int)entry.getSize()/1024); progress.setValue(0); *************** *** 368,374 **** } } ! } catch (Exception e) { ! e.printStackTrace(); ! } } --- 402,406 ---- } } ! } catch (Exception e) {} } *************** *** 381,389 **** c += l; progress.setValue(c / 1024); - //progress.repaint(); } ! } catch (Exception e) { ! e.printStackTrace(); ! } try { --- 413,418 ---- c += l; progress.setValue(c / 1024); } ! } catch (Exception e) {} try { |