Commit:    734fe5508a96868a3e6c03c323f5fb436dc91aa0
Author:    krakjoe <joe.watk...@live.co.uk>         Fri, 29 Nov 2013 01:48:21 
+0000
Parents:   8a63a99d2ea348d653742b2729fd995fb74fe796
Branches:  PHP-5.6

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=734fe5508a96868a3e6c03c323f5fb436dc91aa0

Log:
update java example

Changed paths:
  M  tutorials/java-example.png
  M  tutorials/java/dist/phpdbg-ui.jar
  M  tutorials/java/src/DBGThread.java
  A  tutorials/java/src/History.java
  M  tutorials/java/src/Main.form
  M  tutorials/java/src/Main.java

diff --git a/tutorials/java-example.png b/tutorials/java-example.png
index 618882d..571b768 100644
Binary files a/tutorials/java-example.png and b/tutorials/java-example.png 
differ
diff --git a/tutorials/java/dist/phpdbg-ui.jar 
b/tutorials/java/dist/phpdbg-ui.jar
index 24dd4b9..fc4e9d1 100644
Binary files a/tutorials/java/dist/phpdbg-ui.jar and 
b/tutorials/java/dist/phpdbg-ui.jar differ
diff --git a/tutorials/java/src/DBGThread.java 
b/tutorials/java/src/DBGThread.java
index 9f00faa..73e2dc4 100644
--- a/tutorials/java/src/DBGThread.java
+++ b/tutorials/java/src/DBGThread.java
@@ -3,11 +3,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.Socket;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
 
 /*
  * To change this license header, choose License Headers in Project Properties.
@@ -16,80 +11,52 @@ import javax.swing.JTextField;
  */
 
 /**
- * In a RUSH !!!
- * @author joe
+ * Manage input and output data
+ * @author krakjoe
  */
 public class DBGThread extends Socket implements Runnable {
-    private final String host;
-    private final Integer port;
     private final Boolean reader;
-    private final JTextField field;
-    private final JTextArea area;
-    private final JScrollPane pane;
-    private InputStream input;
-    private OutputStream output;
-    private String buffer;
+    private final Main main;
     private Boolean quit;
 
-    public DBGThread(final String host, final Integer port, final JTextField 
field) throws IOException {
+    public DBGThread(final String host, final Integer port, final Main main, 
Boolean reader) throws IOException {
         super(host, port);
         
-        this.host = host;
-        this.port = port;
-        this.reader = true;
-        this.field = field;
-        this.area = null;
-        this.pane = null;
+        this.main = main;
+        this.reader = reader;
         this.quit = false;
-        this.buffer = null;
-    }
-    
-    public DBGThread(final String host, final Integer port, final JTextArea 
area, JScrollPane pane) throws IOException {
-        super(host, port);
         
-        this.host = host;
-        this.port = port;
-        this.reader = false;
-        this.field = null;
-        this.area = area;
-        this.pane = pane;
-        this.quit = false;
-        this.buffer = null;
-    }
-    
-    public Boolean isReader() {
-        return this.reader;
+        main.setConnected(true);
     }
     
     public void quit() {
         synchronized(this) {
-            this.quit = true;
+            quit = true;
             this.notifyAll(); 
         }
     }
     
-    @Override
-    public void run() {
+    @Override public void run() {
         try {
-            if (this.reader) {
-                output = this.getOutputStream();
-            } else input = this.getInputStream();
-            
             synchronized(this) {
                 do {
-                    if (this.reader) {
+                    if (reader) {
+                        String command;
+                        OutputStream output = getOutputStream();
+                        
                         this.wait();
                         
+                        command = main.getInputField().getText();
                         /* send command to stdin socket */
-                        if (this.field.getText() != null) {    
+                        if (command != null) {    
                             output.write(
-                               this.field.getText().getBytes());
+                               command.getBytes());
                             output.write("\n".getBytes());
                             output.flush();
                         }
-                        this.field.setText(null);
-                        
+                        main.getInputField().setText(null);
                     } else {
+                        InputStream input = getInputStream();
                         /* get data from stdout socket */
                         byte[] bytes = new byte[1];
                         do {
@@ -100,16 +67,24 @@ public class DBGThread extends Socket implements Runnable {
                             }
                             
                             if (input.read(bytes, 0, 1) > -1) {
-                                area.setCaretPosition(
-                                        area.getText().length());
-                                area.append(new String(bytes));
+                                main.getOutputField().setCaretPosition(
+                                        
main.getOutputField().getText().length());
+                                main.getOutputField().append(new 
String(bytes));
                             }
-                        } while (!this.quit);
+                        } while (!quit);
                     }
-                } while(!this.quit);
+                } while(!quit);
             }
         } catch (IOException | InterruptedException ex) {
-            Logger.getLogger(DBGThread.class.getName()).log(Level.SEVERE, 
null, ex);
+            if (!quit) {
+                main.messageBox(ex.getMessage());
+            }
+        } finally {
+            try {
+                close();
+            } catch (IOException ex) { /* naughty me */ } finally {
+               main.setConnected(false); 
+            }
         }
     }
 }
diff --git a/tutorials/java/src/History.java b/tutorials/java/src/History.java
new file mode 100644
index 0000000..a7521d2
--- /dev/null
+++ b/tutorials/java/src/History.java
@@ -0,0 +1,47 @@
+
+import java.util.ArrayList;
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Implement a simple history list for command input
+ * @author krakjoe
+ */
+public class History extends ArrayList<String> {
+    private Integer position = new Integer(0);
+    
+    public History() {
+        super();
+    }
+    
+    @Override public boolean add(String text) {
+        String last = last();
+        if (text != null) {
+           if (last == null || !last.equals(text)) {
+               if (super.add(text)) {
+                   position = size();
+                   return true;
+               }
+           }
+        }
+        return false;
+    }
+    
+    public String last() {
+        if (position >= 1) {
+            position--;
+            return get(position);
+        } else return new String();
+    }
+    
+    public String next() {
+        if (position+1 < size()) {
+            position++;
+            return get(position);
+        } else return new String();
+    }
+}
\ No newline at end of file
diff --git a/tutorials/java/src/Main.form b/tutorials/java/src/Main.form
index 0d4c93d..a5cb28e 100644
--- a/tutorials/java/src/Main.form
+++ b/tutorials/java/src/Main.form
@@ -1,6 +1,24 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 
 <Form version="1.3" maxVersion="1.9" 
type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
+  <NonVisualComponents>
+    <Container class="javax.swing.JPopupMenu" name="stdoutPopupMenu">
+
+      <Layout 
class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
+        <Property name="useNullLayout" type="boolean" value="true"/>
+      </Layout>
+      <SubComponents>
+        <MenuItem class="javax.swing.JMenuItem" name="resetStdout">
+          <Properties>
+            <Property name="text" type="java.lang.String" value="Clear"/>
+          </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" 
listener="java.awt.event.ActionListener" 
parameters="java.awt.event.ActionEvent" handler="resetStdoutActionPerformed"/>
+          </Events>
+        </MenuItem>
+      </SubComponents>
+    </Container>
+  </NonVisualComponents>
   <Properties>
     <Property name="defaultCloseOperation" type="int" value="2"/>
     <Property name="title" type="java.lang.String" value="phpdbg jui"/>
@@ -24,9 +42,26 @@
   <Layout>
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <Group type="102" alignment="0" attributes="0">
+          <Group type="102" attributes="0">
               <EmptySpace max="-2" attributes="0"/>
-              <Component id="jSplitPane1" pref="796" max="32767" 
attributes="0"/>
+              <Group type="103" groupAlignment="0" attributes="0">
+                  <Component id="mainSplit" max="32767" attributes="0"/>
+                  <Group type="102" attributes="0">
+                      <Component id="hostLabel" min="-2" max="-2" 
attributes="0"/>
+                      <EmptySpace max="-2" attributes="0"/>
+                      <Component id="host" pref="359" max="32767" 
attributes="0"/>
+                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
+                      <Component id="stdinCheckBox" min="-2" max="-2" 
attributes="0"/>
+                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
+                      <Component id="stdinPort" min="-2" pref="60" max="-2" 
attributes="0"/>
+                      <EmptySpace type="separate" max="-2" attributes="0"/>
+                      <Component id="stdoutCheckBox" min="-2" max="-2" 
attributes="0"/>
+                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
+                      <Component id="stdoutPort" min="-2" pref="60" max="-2" 
attributes="0"/>
+                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
+                      <Component id="openButton" min="-2" max="-2" 
attributes="0"/>
+                  </Group>
+              </Group>
               <EmptySpace max="-2" attributes="0"/>
           </Group>
       </Group>
@@ -34,15 +69,25 @@
     <DimensionLayout dim="1">
       <Group type="103" groupAlignment="0" attributes="0">
           <Group type="102" alignment="0" attributes="0">
-              <EmptySpace min="-2" max="-2" attributes="0"/>
-              <Component id="jSplitPane1" pref="457" max="32767" 
attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="mainSplit" pref="428" max="32767" attributes="0"/>
+              <EmptySpace type="unrelated" max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="3" max="-2" attributes="0">
+                  <Component id="stdoutPort" alignment="3" min="-2" max="-2" 
attributes="0"/>
+                  <Component id="stdinCheckBox" alignment="3" min="-2" 
max="-2" attributes="0"/>
+                  <Component id="stdoutCheckBox" alignment="3" min="-2" 
max="-2" attributes="0"/>
+                  <Component id="stdinPort" alignment="3" min="-2" max="-2" 
attributes="0"/>
+                  <Component id="host" alignment="0" min="-2" max="-2" 
attributes="0"/>
+                  <Component id="openButton" alignment="0" max="32767" 
attributes="0"/>
+                  <Component id="hostLabel" alignment="3" min="-2" max="-2" 
attributes="0"/>
+              </Group>
               <EmptySpace max="-2" attributes="0"/>
           </Group>
       </Group>
     </DimensionLayout>
   </Layout>
   <SubComponents>
-    <Container class="javax.swing.JSplitPane" name="jSplitPane1">
+    <Container class="javax.swing.JSplitPane" name="mainSplit">
       <Properties>
         <Property name="orientation" type="int" value="0"/>
         <Property name="toolTipText" type="java.lang.String" value=""/>
@@ -53,14 +98,11 @@
         <Component class="javax.swing.JTextField" name="input">
           <Properties>
             <Property name="toolTipText" type="java.lang.String" value=""/>
+            <Property name="enabled" type="boolean" value="false"/>
           </Properties>
           <Events>
-            <EventHandler event="actionPerformed" 
listener="java.awt.event.ActionListener" 
parameters="java.awt.event.ActionEvent" handler="inputActionPerformed"/>
             <EventHandler event="keyReleased" 
listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" 
handler="inputKeyReleased"/>
           </Events>
-          <AuxValues>
-            <AuxValue name="JavaCodeGenerator_VariableModifier" 
type="java.lang.Integer" value="12"/>
-          </AuxValues>
           <Constraints>
             <Constraint 
layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"
 
value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
               <JSplitPaneConstraints position="left"/>
@@ -69,7 +111,6 @@
         </Component>
         <Container class="javax.swing.JScrollPane" name="outScrollPane">
           <AuxValues>
-            <AuxValue name="JavaCodeGenerator_VariableModifier" 
type="java.lang.Integer" value="12"/>
             <AuxValue name="autoScrollPane" type="java.lang.Boolean" 
value="true"/>
           </AuxValues>
           <Constraints>
@@ -82,19 +123,66 @@
           <SubComponents>
             <Component class="javax.swing.JTextArea" name="output">
               <Properties>
+                <Property name="editable" type="boolean" value="false"/>
                 <Property name="columns" type="int" value="20"/>
                 <Property name="font" type="java.awt.Font" 
editor="org.netbeans.beaninfo.editors.FontEditor">
                   <Font name="DialogInput" size="12" style="0"/>
                 </Property>
                 <Property name="rows" type="int" value="5"/>
+                <Property name="componentPopupMenu" 
type="javax.swing.JPopupMenu" 
editor="org.netbeans.modules.form.ComponentChooserEditor">
+                  <ComponentRef name="stdoutPopupMenu"/>
+                </Property>
               </Properties>
-              <AuxValues>
-                <AuxValue name="JavaCodeGenerator_VariableModifier" 
type="java.lang.Integer" value="12"/>
-              </AuxValues>
             </Component>
           </SubComponents>
         </Container>
       </SubComponents>
     </Container>
+    <Component class="javax.swing.JTextField" name="host">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="127.0.0.1"/>
+        <Property name="toolTipText" type="java.lang.String" value="Set the 
hostname, or IPv4 address of the machine running the phpdbg remote console 
server"/>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JTextField" name="stdoutPort">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="8000"/>
+        <Property name="toolTipText" type="java.lang.String" value=""/>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JCheckBox" name="stdinCheckBox">
+      <Properties>
+        <Property name="selected" type="boolean" value="true"/>
+        <Property name="text" type="java.lang.String" value="stdin:"/>
+        <Property name="toolTipText" type="java.lang.String" value="Set the 
port for stdin, or uncheck to disable stdin"/>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JCheckBox" name="stdoutCheckBox">
+      <Properties>
+        <Property name="selected" type="boolean" value="true"/>
+        <Property name="text" type="java.lang.String" value="stdout:"/>
+        <Property name="toolTipText" type="java.lang.String" value="Set the 
port for stdout, or unset to disable stdout"/>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JButton" name="openButton">
+      <Properties>
+        <Property name="actionCommand" type="java.lang.String" value="open"/>
+        <Property name="label" type="java.lang.String" value="open"/>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" 
listener="java.awt.event.ActionListener" 
parameters="java.awt.event.ActionEvent" handler="openButtonActionPerformed"/>
+      </Events>
+    </Component>
+    <Component class="javax.swing.JTextField" name="stdinPort">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="4000"/>
+        <Property name="toolTipText" type="java.lang.String" value=""/>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JLabel" name="hostLabel">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="Hostname:"/>
+      </Properties>
+    </Component>
   </SubComponents>
 </Form>
diff --git a/tutorials/java/src/Main.java b/tutorials/java/src/Main.java
index 1aa792e..84d0f13 100644
--- a/tutorials/java/src/Main.java
+++ b/tutorials/java/src/Main.java
@@ -1,8 +1,14 @@
 
+import static java.awt.event.KeyEvent.VK_DOWN;
 import static java.awt.event.KeyEvent.VK_ENTER;
+import static java.awt.event.KeyEvent.VK_UP;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.swing.JOptionPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
 
 /*
  * To change this license header, choose License Headers in Project Properties.
@@ -12,12 +18,13 @@ import java.util.logging.Logger;
 
 /**
  *
- * @author joe
+ * @author krakjoe
  */
 public class Main extends javax.swing.JDialog {
-
     /**
-     * Creates new form NewJDialog
+     * Creates user interface
+     * @param parent
+     * @param modal
      */
     public Main(java.awt.Frame parent, boolean modal) {
         super(parent, modal);
@@ -33,36 +40,78 @@ public class Main extends javax.swing.JDialog {
     // <editor-fold defaultstate="collapsed" desc="Generated 
Code">//GEN-BEGIN:initComponents
     private void initComponents() {
 
-        jSplitPane1 = new javax.swing.JSplitPane();
+        stdoutPopupMenu = new javax.swing.JPopupMenu();
+        resetStdout = new javax.swing.JMenuItem();
+        mainSplit = new javax.swing.JSplitPane();
         input = new javax.swing.JTextField();
         outScrollPane = new javax.swing.JScrollPane();
         output = new javax.swing.JTextArea();
+        host = new javax.swing.JTextField();
+        stdoutPort = new javax.swing.JTextField();
+        stdinCheckBox = new javax.swing.JCheckBox();
+        stdoutCheckBox = new javax.swing.JCheckBox();
+        openButton = new javax.swing.JButton();
+        stdinPort = new javax.swing.JTextField();
+        hostLabel = new javax.swing.JLabel();
+
+        resetStdout.setText("Clear");
+        resetStdout.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                resetStdoutActionPerformed(evt);
+            }
+        });
+        stdoutPopupMenu.add(resetStdout);
 
         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
         setTitle("phpdbg jui");
 
-        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
-        jSplitPane1.setToolTipText("");
+        mainSplit.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
+        mainSplit.setToolTipText("");
 
         input.setToolTipText("");
-        input.addActionListener(new java.awt.event.ActionListener() {
-            public void actionPerformed(java.awt.event.ActionEvent evt) {
-                inputActionPerformed(evt);
-            }
-        });
+        input.setEnabled(false);
         input.addKeyListener(new java.awt.event.KeyAdapter() {
             public void keyReleased(java.awt.event.KeyEvent evt) {
                 inputKeyReleased(evt);
             }
         });
-        jSplitPane1.setLeftComponent(input);
+        mainSplit.setLeftComponent(input);
 
+        output.setEditable(false);
         output.setColumns(20);
         output.setFont(new java.awt.Font("DialogInput", 0, 12)); // NOI18N
         output.setRows(5);
+        output.setComponentPopupMenu(stdoutPopupMenu);
         outScrollPane.setViewportView(output);
 
-        jSplitPane1.setRightComponent(outScrollPane);
+        mainSplit.setRightComponent(outScrollPane);
+
+        host.setText("127.0.0.1");
+        host.setToolTipText("Set the hostname, or IPv4 address of the machine 
running the phpdbg remote console server");
+
+        stdoutPort.setText("8000");
+        stdoutPort.setToolTipText("");
+
+        stdinCheckBox.setSelected(true);
+        stdinCheckBox.setText("stdin:");
+        stdinCheckBox.setToolTipText("Set the port for stdin, or uncheck to 
disable stdin");
+
+        stdoutCheckBox.setSelected(true);
+        stdoutCheckBox.setText("stdout:");
+        stdoutCheckBox.setToolTipText("Set the port for stdout, or unset to 
disable stdout");
+
+        openButton.setActionCommand("open");
+        openButton.setLabel("open");
+        openButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                openButtonActionPerformed(evt);
+            }
+        });
+
+        stdinPort.setText("4000");
+        stdinPort.setToolTipText("");
+
+        hostLabel.setText("Hostname:");
 
         javax.swing.GroupLayout layout = new 
javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
@@ -70,34 +119,181 @@ public class Main extends javax.swing.JDialog {
             
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
-                .addComponent(jSplitPane1, 
javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)
+                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(mainSplit)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(hostLabel)
+                        
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                        .addComponent(host, 
javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
+                        
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(stdinCheckBox)
+                        
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(stdinPort, 
javax.swing.GroupLayout.PREFERRED_SIZE, 60, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addGap(18, 18, 18)
+                        .addComponent(stdoutCheckBox)
+                        
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(stdoutPort, 
javax.swing.GroupLayout.PREFERRED_SIZE, 60, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                        
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(openButton)))
                 .addContainerGap())
         );
         layout.setVerticalGroup(
             
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
-                .addComponent(jSplitPane1, 
javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
+                .addComponent(mainSplit, javax.swing.GroupLayout.DEFAULT_SIZE, 
428, Short.MAX_VALUE)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE,
 false)
+                    .addComponent(stdoutPort, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(stdinCheckBox)
+                    .addComponent(stdoutCheckBox)
+                    .addComponent(stdinPort, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(host, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(openButton, 
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
Short.MAX_VALUE)
+                    .addComponent(hostLabel))
                 .addContainerGap())
         );
 
         pack();
     }// </editor-fold>//GEN-END:initComponents
 
-    private void inputActionPerformed(java.awt.event.ActionEvent evt) 
{//GEN-FIRST:event_inputActionPerformed
-        // TODO add your handling code here:
-        
-    }//GEN-LAST:event_inputActionPerformed
-
     private void inputKeyReleased(java.awt.event.KeyEvent evt) 
{//GEN-FIRST:event_inputKeyReleased
-        // TODO add your handling code here:
-        if (evt.getKeyCode() == VK_ENTER) {
-            synchronized(this.in) {
-                this.in.notifyAll();
-            }
+        switch (evt.getKeyCode()) {
+            case VK_ENTER: {
+                if (in != null) {
+                    history.add(input.getText());
+                    synchronized(in) {
+                        in.notifyAll();
+                    }
+                }
+            } break;
+ 
+            case VK_UP: {
+                String last = history.last();
+                if (last.length() > 0) {
+                    input.setText(last);
+                }
+            } break;
+                
+            case VK_DOWN: {
+                String next = history.next();
+                if (next.length() > 0) {
+                    input.setText(next);
+                }
+            } break;
         }
     }//GEN-LAST:event_inputKeyReleased
 
+    private void openButtonActionPerformed(java.awt.event.ActionEvent evt) 
{//GEN-FIRST:event_openButtonActionPerformed
+        try {
+            if (!connected) {
+                Integer ports[] = new Integer[2];
+                String address = getHost();
+
+                if (address != null) {
+                    ports[0] = stdinCheckBox.isSelected() ? getStdinPort() : 
-1;
+                    ports[1] = stdoutCheckBox.isSelected() ? getStdoutPort() : 
-1;
+
+                    if (ports[0] != 0 && ports[1] != 0) {
+                        if (stdinCheckBox.isSelected()) {
+                            if (ports[0] > 0) {
+                                in = new DBGThread(
+                                        address, ports[0], this, true);
+                                new Thread(in).start();
+                            }
+                        }
+
+                        if (stdoutCheckBox.isSelected()) {
+                            if (ports[1] > 0) {
+                               out = new DBGThread(
+                                       address, ports[1], this, false);
+                                new Thread(out).start(); 
+                            }
+                        }
+                    }
+                }
+            } else {
+                if (in != null) {
+                    in.quit();
+                }
+                if (out != null) {
+                    out.quit();
+                }
+            }
+        } catch (IOException ex) {
+            messageBox(ex.getMessage());
+        }
+    }//GEN-LAST:event_openButtonActionPerformed
+
+    private void resetStdoutActionPerformed(java.awt.event.ActionEvent evt) 
{//GEN-FIRST:event_resetStdoutActionPerformed
+        // TODO add your handling code here:
+        output.setText(null);
+    }//GEN-LAST:event_resetStdoutActionPerformed
+
+    
+    public void setConnected(Boolean isConnected) {
+        synchronized(this) {
+            if (isConnected) {
+                connected = true;
+                openButton.setText("Disconnect");
+                host.setEnabled(false);
+                stdinPort.setEnabled(false);
+                stdinCheckBox.setEnabled(false);
+                if (stdinCheckBox.isSelected()) {
+                    input.setEnabled(true);
+                } else input.setEnabled(false);
+                stdoutPort.setEnabled(false);
+                stdoutCheckBox.setEnabled(false);
+            } else {
+                connected = false;
+                openButton.setText("Connect");
+                host.setEnabled(true);
+                stdinPort.setEnabled(true);
+                input.setEnabled(false);
+                stdinCheckBox.setEnabled(true);
+                stdoutPort.setEnabled(true);
+                stdoutCheckBox.setEnabled(true);
+            }
+        }
+    }
+    
+    public JTextField getInputField() { return input; }
+    public JTextArea getOutputField() { return output; }
+    
+    public String getHost() { 
+        String address = host.getText();
+        if (address != null && address.length() > 0) {
+            return address;
+        } else {
+            messageBox("Invalid hostname provided !");
+        }
+        
+        return null;
+    }
+    
+    public Integer getStdinPort() { 
+        try {
+            return Integer.parseInt(stdinPort.getText()); 
+        } catch (NumberFormatException ex) {
+            messageBox("Invalid stdin port provided !");
+        }
+        
+        return 0;
+    }
+    
+    public Integer getStdoutPort() { 
+        try {
+            return Integer.parseInt(stdoutPort.getText()); 
+        } catch (NumberFormatException ex) {
+            messageBox("Invalid stdout port provided !");
+        }
+        
+        return 0;
+    }
+    
+    public synchronized void messageBox(String message) {
+        JOptionPane.showMessageDialog(this, message);
+    }
     /**
      * @param args the command line arguments
      */
@@ -124,50 +320,47 @@ public class Main extends javax.swing.JDialog {
             
java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
         }
         //</editor-fold>
-
+        
         /* Create and display the dialog */
         java.awt.EventQueue.invokeLater(new Runnable() {
-            public void run() {
+            @Override public void run() {
                 dialog = new Main(new javax.swing.JFrame(), true);
                 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                     @Override
                     public void windowClosing(java.awt.event.WindowEvent e) {
-                        dialog.in.quit();
-                        dialog.out.quit();
+                        if (in != null)
+                            in.quit();
+                        
+                        if (out != null)
+                            out.quit();
+                        
                         System.exit(0);
                     }
                 });
                 dialog.setVisible(true);
             }
         });
-        
-        java.awt.EventQueue.invokeLater(new Runnable(){
-            public void run(){
-                try {
-                    dialog.in = new DBGThread(
-                            args[0], Integer.parseInt(args[1]), input);
-                    dialog.out = new DBGThread(
-                            args[0], Integer.parseInt(args[1]) * 2, output, 
outScrollPane);
-                    
-                    new Thread(dialog.in).start();
-                    new Thread(dialog.out).start();
-                    
-                } catch (IOException ex) {
-                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, 
null, ex);
-                    System.exit(0);
-                }
-            }
-        });
     }
     
-    private DBGThread in;
-    private DBGThread out;
-    protected static Main dialog;
+    private static DBGThread in;
+    private static DBGThread out;
+    private static Main dialog;
+    private static Boolean connected = false;
+    private static History history = new History();
     
     // Variables declaration - do not modify//GEN-BEGIN:variables
-    protected static javax.swing.JTextField input;
-    private javax.swing.JSplitPane jSplitPane1;
-    protected static javax.swing.JScrollPane outScrollPane;
-    protected static javax.swing.JTextArea output;
+    private javax.swing.JTextField host;
+    private javax.swing.JLabel hostLabel;
+    private javax.swing.JTextField input;
+    private javax.swing.JSplitPane mainSplit;
+    private javax.swing.JButton openButton;
+    private javax.swing.JScrollPane outScrollPane;
+    private javax.swing.JTextArea output;
+    private javax.swing.JMenuItem resetStdout;
+    private javax.swing.JCheckBox stdinCheckBox;
+    private javax.swing.JTextField stdinPort;
+    private javax.swing.JCheckBox stdoutCheckBox;
+    private javax.swing.JPopupMenu stdoutPopupMenu;
+    private javax.swing.JTextField stdoutPort;
     // End of variables declaration//GEN-END:variables
 }
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to