Initial revision

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@164 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent a6bc1392d1
commit 10db6a2447
  1. 128
      jode/JodeAppletOneZero.java
  2. 22
      jode/jode-applet.html
  3. 125
      jode/jode/JodeWindow.java

@ -0,0 +1,128 @@
package jode;
import java.applet.*;
import java.awt.*;
import java.io.*;
public class JodeAppletOneZero extends Applet implements Runnable {
TextField classpathField;
TextField classField;
TextArea sourcecodeArea;
TextArea errorArea;
Thread decompileThread;
public JodeAppletOneZero() {
buildComponents(this);
}
public void init() {
String cp = getParameter("classpath");
if (cp != null)
setClasspath(cp);
String cls = getParameter("class");
if (cls != null)
setClass(cls);
}
private void buildComponents(Container frame) {
classpathField = new TextField(50);
classField = new TextField(50);
sourcecodeArea = new TextArea(20, 80);
errorArea = new TextArea(3, 80);
sourcecodeArea.setEditable(false);
errorArea.setEditable(false);
GridBagLayout gbl = new GridBagLayout();
frame.setLayout(gbl);
GridBagConstraints labelConstr = new GridBagConstraints();
GridBagConstraints textConstr = new GridBagConstraints();
GridBagConstraints areaConstr = new GridBagConstraints();
labelConstr.fill = GridBagConstraints.NONE;
textConstr.fill = GridBagConstraints.HORIZONTAL;
areaConstr.fill = GridBagConstraints.BOTH;
textConstr.gridwidth = GridBagConstraints.REMAINDER;
textConstr.weightx = 1.0;
areaConstr.gridwidth = GridBagConstraints.REMAINDER;
areaConstr.weightx = 1.0;
areaConstr.weighty = 1.0;
Label label = new Label("class path: ");
gbl.setConstraints(label, labelConstr);
frame.add(label);
gbl.setConstraints(classpathField, textConstr);
frame.add(classpathField);
label = new Label("class name: ");
gbl.setConstraints(label, labelConstr);
frame.add(label);
gbl.setConstraints(classField, textConstr);
frame.add(classField);
gbl.setConstraints(sourcecodeArea, areaConstr);
frame.add(sourcecodeArea);
areaConstr.gridheight = GridBagConstraints.REMAINDER;
areaConstr.weighty = 0.0;
gbl.setConstraints(errorArea, areaConstr);
frame.add(errorArea);
Decompiler.err = new PrintStream(new AreaOutputStream(errorArea));
}
public void setClasspath(String cp) {
classpathField.setText(cp);
}
public void setClass(String cls) {
classField.setText(cls);
}
public boolean action(Event e, Object arg) {
if (e.target == classField) {
if (decompileThread == null) {
decompileThread = new Thread(this);
sourcecodeArea.setText("Please wait, while decompiling...\n");
decompileThread.start();
} else
sourcecodeArea
.appendText("Be a little bit more patient, please.\n");
}
return true;
}
public class AreaOutputStream extends OutputStream {
private TextArea area;
public AreaOutputStream(TextArea a) {
area = a;
}
public void write(int b) throws IOException {
area.appendText(String.valueOf((byte)b));
}
public void write(byte[] b, int off, int len) throws IOException {
area.appendText(new String(b, off, len));
}
}
public void run() {
errorArea.setText("");
String cp = classpathField.getText();
cp = cp.replace(':', jode.bytecode.SearchPath.protocolSeparator);
cp = cp.replace(',', File.pathSeparatorChar);
JodeEnvironment env = new JodeEnvironment(cp);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
TabbedPrintWriter writer = new TabbedPrintWriter(out, " ");
env.doClass(classField.getText(), writer);
sourcecodeArea.setText(out.toString());
} catch (Throwable t) {
sourcecodeArea.setText("Didn't succeed.\n"
+"Check the below area for more info.");
t.printStackTrace(Decompiler.err);
} finally {
synchronized(this) {
decompileThread = null;
}
}
}
}

@ -0,0 +1,22 @@
<html>
<head>
<title>Jode Test Applet</title>
</head>
<body>
Press enter in the class name field to decompile this applet. You may
change the class path and name to point to an class file of your
choice. But note that most browsers doesn't allow loading files from
a different server.<br>
You can download <a href="jode/jode-applet.html">HTML-file</a> and
this <a href="jode_cls.zip">archive, if you want to test it yourself.
You should use the appletviewer in this case.
<applet code="jode/JodeAppletOneZero.class" codebase="./" width=640 height=400>
<param name=classpath
value="http://nirwana/~jochen/">
<param name=class value="jode.JodeAppletOneZero">
</applet>
</body>
</html>

@ -0,0 +1,125 @@
package jode;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class JodeWindow
implements ActionListener, Runnable
{
TextField classpathField;
TextField classField;
TextArea sourcecodeArea;
TextArea errorArea;
Thread decompileThread;
public JodeWindow(Container frame) {
buildComponents(frame);
}
private void buildComponents(Container frame) {
classpathField = new TextField(50);
classField = new TextField(50);
sourcecodeArea = new TextArea(20, 80);
errorArea = new TextArea(3, 80);
sourcecodeArea.setEditable(false);
errorArea.setEditable(false);
frame.setLayout(new GridBagLayout());
GridBagConstraints labelConstr = new GridBagConstraints();
GridBagConstraints textConstr = new GridBagConstraints();
GridBagConstraints areaConstr = new GridBagConstraints();
labelConstr.fill = GridBagConstraints.NONE;
textConstr.fill = GridBagConstraints.HORIZONTAL;
areaConstr.fill = GridBagConstraints.BOTH;
textConstr.gridwidth = GridBagConstraints.REMAINDER;
textConstr.weightx = 1.0;
areaConstr.gridwidth = GridBagConstraints.REMAINDER;
areaConstr.weightx = 1.0;
areaConstr.weighty = 1.0;
frame.add(new Label("class path: "), labelConstr);
frame.add(classpathField, textConstr);
frame.add(new Label("class name: "), labelConstr);
frame.add(classField, textConstr);
frame.add(sourcecodeArea, areaConstr);
areaConstr.gridheight = GridBagConstraints.REMAINDER;
areaConstr.weighty = 0.0;
frame.add(errorArea, areaConstr);
classField.addActionListener(this);
String cp = System.getProperty("java.class.path");
if (cp != null)
classpathField.setText(cp);
String cls = "jode.JodeWindow";
classField.setText(cls);
Decompiler.err = new PrintStream(new AreaOutputStream(errorArea));
}
public void setClasspath(String cp) {
classpathField.setText(cp);
}
public void setClass(String cls) {
classField.setText(cls);
}
public synchronized void actionPerformed(ActionEvent e) {
if (decompileThread == null) {
decompileThread = new Thread(this);
sourcecodeArea.setText("Please wait, while decompiling...\n");
decompileThread.start();
} else
sourcecodeArea.append("Be a little bit more patient, please.\n");
}
public class AreaOutputStream extends OutputStream {
private TextArea area;
public AreaOutputStream(TextArea a) {
area = a;
}
public void write(int b) throws IOException {
area.append(String.valueOf((byte)b));
}
public void write(byte[] b, int off, int len) throws IOException {
area.append(new String(b, off, len));
}
}
public void run() {
JodeEnvironment env = new JodeEnvironment(classpathField.getText());
ByteArrayOutputStream out = new ByteArrayOutputStream();
errorArea.setText("");
try {
TabbedPrintWriter writer = new TabbedPrintWriter(out, " ");
env.doClass(classField.getText(), writer);
sourcecodeArea.setText(out.toString());
} catch (Throwable t) {
sourcecodeArea.setText("Didn't succeed.\n"
+"Check the below area for more info.");
t.printStackTrace();
} finally {
synchronized(this) {
decompileThread = null;
}
}
}
public static void main(String argv[]) {
Frame frame = new Frame(Decompiler.copyright);
new JodeWindow(frame);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.show();
}
}
Loading…
Cancel
Save