From 4f12915c1d15ba6446455ed1c483eb2600ba46a3 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 28 Sep 2008 14:06:47 +0000 Subject: Client: Completed step 4 Refs #69 --- .../DownloadItem/DownloadItemModeTest.form | 89 +++++++++ .../DownloadItem/DownloadItemModeTest.java | 221 +++++++++++++++++++++ .../resources/DownloadItemModeTest.properties | 7 + .../instadisc/FirstRun/FirstRunWizard.java | 20 +- .../com/fourisland/instadisc/FirstRun/Step2.java | 11 +- .../trunk/src/com/fourisland/instadisc/XmlRpc.java | 5 + 6 files changed, 341 insertions(+), 12 deletions(-) create mode 100644 client/trunk/src/com/fourisland/instadisc/DownloadItem/DownloadItemModeTest.form create mode 100644 client/trunk/src/com/fourisland/instadisc/DownloadItem/DownloadItemModeTest.java create mode 100644 client/trunk/src/com/fourisland/instadisc/DownloadItem/resources/DownloadItemModeTest.properties diff --git a/client/trunk/src/com/fourisland/instadisc/DownloadItem/DownloadItemModeTest.form b/client/trunk/src/com/fourisland/instadisc/DownloadItem/DownloadItemModeTest.form new file mode 100644 index 0000000..9f62e4e --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/DownloadItem/DownloadItemModeTest.form @@ -0,0 +1,89 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/client/trunk/src/com/fourisland/instadisc/DownloadItem/DownloadItemModeTest.java b/client/trunk/src/com/fourisland/instadisc/DownloadItem/DownloadItemModeTest.java new file mode 100644 index 0000000..d085448 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/DownloadItem/DownloadItemModeTest.java @@ -0,0 +1,221 @@ +/* + * DownloadItemModeTest.java + * + * Created on September 27, 2008, 10:20 AM + */ + +package com.fourisland.instadisc.DownloadItem; + +import com.fourisland.instadisc.Database.Wrapper; +import com.fourisland.instadisc.FirstRun.StepEndResults; +import com.fourisland.instadisc.XmlRpc; +import java.io.IOException; +import java.io.InputStream; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author hatkirby + */ +public class DownloadItemModeTest extends javax.swing.JDialog { + + /** Creates new form DownloadItemModeTest */ + public DownloadItemModeTest(java.awt.Frame parent, boolean modal) { + super(parent, modal); + + initComponents(); + + new Thread(new Runnable() { + public void run() { + runDownloadItemModeTest(); + } + }).start(); + } + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setName("Form"); // NOI18N + + org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.fourisland.instadisc.InstaDiscApp.class).getContext().getResourceMap(DownloadItemModeTest.class); + jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N + jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N + jLabel1.setName("jLabel1"); // NOI18N + + jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N + jLabel2.setName("jLabel2"); // NOI18N + + jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N + jLabel3.setName("jLabel3"); // NOI18N + + jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N + jButton1.setEnabled(false); + jButton1.setName("jButton1"); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addGroup(layout.createSequentialGroup() + .addGap(12, 12, 12) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE))) + .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + StepEndResults.ok = true; + this.setVisible(false); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + DownloadItemModeTest dialog = new DownloadItemModeTest(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + // End of variables declaration//GEN-END:variables + + public void runDownloadItemModeTest() { + try + { + ServerSocket svr = new ServerSocket(); + java.net.InetSocketAddress addr = new java.net.InetSocketAddress(61200); + svr.bind(addr); + + new Thread(new DownloadItemModeTestThread(svr)).start(); + + XmlRpc xmlrpc = new XmlRpc("downloadItemModeTest"); + xmlrpc.resetParams(); + if (((Integer) xmlrpc.execute()) == 1) + { + Wrapper.setConfig("downloadItemMode", "Pull"); + } + } catch (IOException ex) + { + Logger.getLogger(DownloadItemModeTest.class.getName()).log(Level.SEVERE, null, ex); + } + + jLabel3.setText("You're download item mode has been set to " + Wrapper.getConfig("downloadItemMode") + ""); + jButton1.setEnabled(true); + } +} + +class DownloadItemModeTestThread implements Runnable +{ + ServerSocket svr; + + public DownloadItemModeTestThread(ServerSocket svr) + { + this.svr = svr; + } + + public void run() { + try + { + Socket s = svr.accept(); + + InputStream is = s.getInputStream(); + int buffer[] = new int[1000]; + int rs = 0; + int i = 0; + + while (rs != -1) + { + try + { + rs = is.read(); + + if (rs != -1) + { + buffer[i] = rs; + } + + i++; + } catch (SocketException ex) + { + return; + } catch (IOException ex) + { + Logger.getLogger(DownloadItemModeTest.class.getName()).log(Level.SEVERE, null, ex); + } + } + + StringBuilder result = new StringBuilder(); + int j = 0; + for (j = 0; j < i; j++) + { + result.append(Character.toString((char) buffer[j])); + } + + if (result.toString().trim().equals("InstaDisc Download Item Mode Test")) + { + Wrapper.setConfig("downloadItemMode", "Push"); + } + + s.close(); + svr.close(); + } catch (IOException ex) + { + Logger.getLogger(DownloadItemModeTestThread.class.getName()).log(Level.SEVERE, null, ex); + } + } +} \ No newline at end of file diff --git a/client/trunk/src/com/fourisland/instadisc/DownloadItem/resources/DownloadItemModeTest.properties b/client/trunk/src/com/fourisland/instadisc/DownloadItem/resources/DownloadItemModeTest.properties new file mode 100644 index 0000000..d558d31 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/DownloadItem/resources/DownloadItemModeTest.properties @@ -0,0 +1,7 @@ + +jLabel1.text=Download Item Mode Test +#NOI18N +jLabel1.font=DejaVu Sans-Plain-18 +jLabel2.text=InstaDisc can recieve items for you in two ways, Push or Pull. Push is faster, but may not work for some people. Pull isn't as efficent, but should work for anyone. InstaDisc is now running a test to see which method is best for you. +jLabel3.text=The test is running.... +jButton1.text=Next diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/FirstRunWizard.java b/client/trunk/src/com/fourisland/instadisc/FirstRun/FirstRunWizard.java index 0919f21..713cc83 100644 --- a/client/trunk/src/com/fourisland/instadisc/FirstRun/FirstRunWizard.java +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/FirstRunWizard.java @@ -5,6 +5,8 @@ package com.fourisland.instadisc.FirstRun; +import com.fourisland.instadisc.Database.Wrapper; +import com.fourisland.instadisc.DownloadItem.DownloadItemModeTest; import javax.swing.JFrame; /** @@ -25,8 +27,22 @@ public class FirstRunWizard implements Runnable { if (StepEndResults.ok) { StepEndResults.ok = false; - Step3 s3 = new Step3(new JFrame(), true); - s3.setVisible(true); + DownloadItemModeTest dIMT = new DownloadItemModeTest(new JFrame(), true); + dIMT.setVisible(true); + if (StepEndResults.ok) + { + StepEndResults.ok = false; + Step3 s3 = new Step3(new JFrame(), true); + s3.setVisible(true); + + Wrapper.setConfig("initCheck", "done"); + Wrapper.setConfig("itemBufferSize", "10"); + Wrapper.setConfig("verIDBufferSize", "10000"); + Wrapper.setConfig("nextFilterID", "0"); + Wrapper.setConfig("ipCheckValue", "1"); + Wrapper.setConfig("ipCheckUnit", "day"); + Wrapper.setConfig("useUnreadFlag", "true"); + } } } System.exit(0); diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.java b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.java index 292dbb1..85180ee 100644 --- a/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.java +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.java @@ -8,8 +8,6 @@ package com.fourisland.instadisc.FirstRun; import com.fourisland.instadisc.Database.Wrapper; import com.fourisland.instadisc.Item.MD5; import com.fourisland.instadisc.XmlRpc; -import java.net.MalformedURLException; -import java.net.URL; /** * @@ -142,17 +140,10 @@ public class Step2 extends javax.swing.JDialog { if (r == 1) { - jLabel5.setText("Error: No registration exists on the specified Central Server with the specified UN/PW combination"); + jLabel5.setText("Error: Couldn't find the specified user."); } else { Wrapper.setConfig("username", jTextField1.getText()); Wrapper.setConfig("password", password); - Wrapper.setConfig("itemBufferSize", "10"); - Wrapper.setConfig("verIDBufferSize", "10000"); - Wrapper.setConfig("nextFilterID", "0"); - Wrapper.setConfig("ipCheckValue", "1"); - Wrapper.setConfig("ipCheckUnit", "day"); - Wrapper.setConfig("useUnreadFlag", "true"); - Wrapper.setConfig("initCheck", "done"); StepEndResults.ok = true; this.setVisible(false); diff --git a/client/trunk/src/com/fourisland/instadisc/XmlRpc.java b/client/trunk/src/com/fourisland/instadisc/XmlRpc.java index 4fe5b4b..86bff6f 100644 --- a/client/trunk/src/com/fourisland/instadisc/XmlRpc.java +++ b/client/trunk/src/com/fourisland/instadisc/XmlRpc.java @@ -88,4 +88,9 @@ public class XmlRpc { } return result; } + + public void resetParams() + { + params = new Object[] {}; + } } -- cgit 1.4.1