1
0
mirror of https://github.com/php/php-src.git synced 2026-03-31 12:42:29 +02:00

java example stuff

This commit is contained in:
krakjoe
2013-11-28 22:55:07 +00:00
parent 371ccf8ab9
commit f342ca88fa
22 changed files with 2012 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
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.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* In a RUSH !!!
* @author joe
*/
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 Boolean quit;
public DBGThread(final String host, final Integer port, final JTextField field) throws IOException {
super(host, port);
this.host = host;
this.port = port;
this.reader = true;
this.field = field;
this.area = null;
this.pane = null;
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;
}
public void quit() {
synchronized(this) {
this.quit = true;
this.notifyAll();
}
}
@Override
public void run() {
try {
if (this.reader) {
output = this.getOutputStream();
} else input = this.getInputStream();
synchronized(this) {
do {
if (this.reader) {
this.wait();
/* send command to stdin socket */
if (this.field.getText() != null) {
output.write(
this.field.getText().getBytes());
output.write("\n".getBytes());
output.flush();
}
this.field.setText(null);
} else {
/* get data from stdout socket */
byte[] bytes = new byte[1];
do {
/* this is some of the laziest programming I ever done */
if (input.available() == 0) {
this.wait(666);
continue;
}
if (input.read(bytes, 0, 1) > -1) {
area.setCaretPosition(
area.getText().length());
area.append(new String(bytes));
}
} while (!this.quit);
}
} while(!this.quit);
}
} catch (IOException | InterruptedException ex) {
Logger.getLogger(DBGThread.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

View File

@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" value="phpdbg jui"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jSplitPane1" pref="796" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<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"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="orientation" type="int" value="0"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextField" name="input">
<Properties>
<Property name="toolTipText" type="java.lang.String" value=""/>
</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"/>
</Constraint>
</Constraints>
</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>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="output">
<Properties>
<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"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="12"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@@ -0,0 +1,173 @@
import static java.awt.event.KeyEvent.VK_ENTER;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* 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.
*/
/**
*
* @author joe
*/
public class Main extends javax.swing.JDialog {
/**
* Creates new form NewJDialog
*/
public Main(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jSplitPane1 = new javax.swing.JSplitPane();
input = new javax.swing.JTextField();
outScrollPane = new javax.swing.JScrollPane();
output = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("phpdbg jui");
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
jSplitPane1.setToolTipText("");
input.setToolTipText("");
input.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
inputActionPerformed(evt);
}
});
input.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
inputKeyReleased(evt);
}
});
jSplitPane1.setLeftComponent(input);
output.setColumns(20);
output.setFont(new java.awt.Font("DialogInput", 0, 12)); // NOI18N
output.setRows(5);
outScrollPane.setViewportView(output);
jSplitPane1.setRightComponent(outScrollPane);
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()
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)
.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)
.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();
}
}
}//GEN-LAST:event_inputKeyReleased
/**
* @param args the command line arguments
*/
public static void main(final String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
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() {
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();
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;
// 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;
// End of variables declaration//GEN-END:variables
}