mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
...
This commit is contained in:
parent
bd49a0f144
commit
216e3668d6
17 changed files with 888 additions and 0 deletions
381
tutorials/java/src/phpdbg/ui/JConsole.java
Normal file
381
tutorials/java/src/phpdbg/ui/JConsole.java
Normal file
|
@ -0,0 +1,381 @@
|
|||
package phpdbg.ui;
|
||||
|
||||
|
||||
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 javax.swing.JOptionPane;
|
||||
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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author krakjoe
|
||||
*/
|
||||
public class JConsole extends javax.swing.JDialog {
|
||||
public enum MessageType {
|
||||
INFO (JOptionPane.INFORMATION_MESSAGE),
|
||||
WARN (JOptionPane.WARNING_MESSAGE),
|
||||
ERROR (JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
private final Integer type;
|
||||
private MessageType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
public Integer getType() { return this.type; }
|
||||
public Boolean equals(Integer other) { return this.type.equals(other); }
|
||||
public Boolean equals(MessageType other) { return this.type.equals(other.getType()); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates user interface
|
||||
* @param parent
|
||||
* @param modal
|
||||
*/
|
||||
public JConsole(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() {
|
||||
|
||||
stdoutPopupMenu = new javax.swing.JPopupMenu();
|
||||
resetStdout = new javax.swing.JMenuItem();
|
||||
mainSplit = new javax.swing.JSplitPane();
|
||||
input = new javax.swing.JTextField();
|
||||
outputScrollPane = new javax.swing.JScrollPane();
|
||||
output = new phpdbg.ui.JTerminalPane();
|
||||
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");
|
||||
|
||||
mainSplit.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
|
||||
mainSplit.setToolTipText("");
|
||||
|
||||
input.setToolTipText("");
|
||||
input.setEnabled(false);
|
||||
input.addKeyListener(new java.awt.event.KeyAdapter() {
|
||||
public void keyReleased(java.awt.event.KeyEvent evt) {
|
||||
inputKeyReleased(evt);
|
||||
}
|
||||
});
|
||||
mainSplit.setLeftComponent(input);
|
||||
|
||||
outputScrollPane.setViewportView(output);
|
||||
|
||||
mainSplit.setRightComponent(outputScrollPane);
|
||||
|
||||
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);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.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(mainSplit, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.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)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.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(hostLabel)))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void inputKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_inputKeyReleased
|
||||
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 DebugSocket(
|
||||
address, ports[0], this, true);
|
||||
new Thread(in).start();
|
||||
}
|
||||
}
|
||||
|
||||
if (stdoutCheckBox.isSelected()) {
|
||||
if (ports[1] > 0) {
|
||||
out = new DebugSocket(
|
||||
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(), MessageType.ERROR);
|
||||
}
|
||||
}//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 Boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
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 JTerminalPane getOutputField() { return output; }
|
||||
|
||||
public String getHost() {
|
||||
String address = host.getText();
|
||||
if (address != null && address.length() > 0) {
|
||||
return address;
|
||||
} else {
|
||||
messageBox("Invalid hostname provided !", MessageType.WARN);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Integer getStdinPort() {
|
||||
try {
|
||||
return Integer.parseInt(stdinPort.getText());
|
||||
} catch (NumberFormatException ex) {
|
||||
messageBox("Invalid stdin port provided !", MessageType.WARN);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer getStdoutPort() {
|
||||
try {
|
||||
return Integer.parseInt(stdoutPort.getText());
|
||||
} catch (NumberFormatException ex) {
|
||||
messageBox("Invalid stdout port provided !", MessageType.WARN);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public synchronized void messageBox(String message) {
|
||||
messageBox(message, MessageType.INFO);
|
||||
}
|
||||
|
||||
public synchronized void messageBox(String message, MessageType type) {
|
||||
JOptionPane.showMessageDialog(this, message, "phpdbg jui", type.getType());
|
||||
}
|
||||
/**
|
||||
* @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(JConsole.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(JConsole.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(JConsole.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(JConsole.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the dialog */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
@Override public void run() {
|
||||
dialog = new JConsole(new javax.swing.JFrame(), true);
|
||||
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||
if (in != null)
|
||||
in.quit();
|
||||
|
||||
if (out != null)
|
||||
out.quit();
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static DebugSocket in;
|
||||
private static DebugSocket out;
|
||||
private static JConsole dialog;
|
||||
private static Boolean connected = false;
|
||||
private static CommandHistory history = new CommandHistory();
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
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 phpdbg.ui.JTerminalPane output;
|
||||
private javax.swing.JScrollPane outputScrollPane;
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue