diff --git a/jode/JodeAppletOneZero.java b/jode/JodeAppletOneZero.java index 73f37cb..e57cf74 100644 --- a/jode/JodeAppletOneZero.java +++ b/jode/JodeAppletOneZero.java @@ -5,13 +5,12 @@ import java.io.*; public class JodeAppletOneZero extends Applet implements Runnable { - TextField classpathField; - TextField classField; - TextArea sourcecodeArea; - TextArea errorArea; + TextField classpathField, classField; + TextArea sourcecodeArea, errorArea; + Checkbox verboseCheck, prettyCheck; + Button startButton, saveButton; + String lastClassName; - Thread decompileThread; - public JodeAppletOneZero() { buildComponents(this); } @@ -25,23 +24,37 @@ public class JodeAppletOneZero extends Applet implements Runnable { setClass(cls); } - private void buildComponents(Container frame) { + private void buildComponents(Container window) { classpathField = new TextField(50); classField = new TextField(50); sourcecodeArea = new TextArea(20, 80); errorArea = new TextArea(3, 80); + verboseCheck = new Checkbox("verbose"); + prettyCheck = new Checkbox("pretty"); + startButton = new Button("start"); + saveButton = new Button("save"); + saveButton.disable(); sourcecodeArea.setEditable(false); errorArea.setEditable(false); GridBagLayout gbl = new GridBagLayout(); - frame.setLayout(gbl); + window.setLayout(gbl); GridBagConstraints labelConstr = new GridBagConstraints(); GridBagConstraints textConstr = new GridBagConstraints(); GridBagConstraints areaConstr = new GridBagConstraints(); + GridBagConstraints checkConstr = new GridBagConstraints(); + GridBagConstraints buttonConstr = new GridBagConstraints(); labelConstr.fill = GridBagConstraints.NONE; textConstr.fill = GridBagConstraints.HORIZONTAL; areaConstr.fill = GridBagConstraints.BOTH; + checkConstr.fill = GridBagConstraints.NONE; + buttonConstr.fill = GridBagConstraints.NONE; + labelConstr.anchor = GridBagConstraints.EAST; + textConstr.anchor = GridBagConstraints.CENTER; + checkConstr.anchor = GridBagConstraints.WEST; + buttonConstr.anchor = GridBagConstraints.CENTER; + labelConstr.anchor = GridBagConstraints.EAST; textConstr.gridwidth = GridBagConstraints.REMAINDER; textConstr.weightx = 1.0; areaConstr.gridwidth = GridBagConstraints.REMAINDER; @@ -50,20 +63,34 @@ public class JodeAppletOneZero extends Applet implements Runnable { Label label = new Label("class path: "); gbl.setConstraints(label, labelConstr); - frame.add(label); + window.add(label); gbl.setConstraints(classpathField, textConstr); - frame.add(classpathField); + window.add(classpathField); label = new Label("class name: "); gbl.setConstraints(label, labelConstr); - frame.add(label); + window.add(label); gbl.setConstraints(classField, textConstr); - frame.add(classField); + window.add(classField); + gbl.setConstraints(verboseCheck, checkConstr); + window.add(verboseCheck); + gbl.setConstraints(prettyCheck, checkConstr); + window.add(prettyCheck); + labelConstr.weightx = 1.0; + label = new Label(); + gbl.setConstraints(label, labelConstr); + window.add(label); + gbl.setConstraints(startButton, buttonConstr); + window.add(startButton); + buttonConstr.gridwidth = GridBagConstraints.REMAINDER; + gbl.setConstraints(saveButton, buttonConstr); + window.add(saveButton); + gbl.setConstraints(sourcecodeArea, areaConstr); - frame.add(sourcecodeArea); + window.add(sourcecodeArea); areaConstr.gridheight = GridBagConstraints.REMAINDER; areaConstr.weighty = 0.0; gbl.setConstraints(errorArea, areaConstr); - frame.add(errorArea); + window.add(errorArea); Decompiler.err = new PrintStream(new AreaOutputStream(errorArea)); } @@ -76,14 +103,32 @@ public class JodeAppletOneZero extends Applet implements Runnable { } 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"); + if (e.target == startButton) { + startButton.disable(); + Thread decompileThread = new Thread(this); + sourcecodeArea.setText("Please wait, while decompiling...\n"); + decompileThread.start(); + } else if (e.target == saveButton) { + FileDialog fd = new FileDialog(new Frame(), + "Save decompiled code", + FileDialog.SAVE); + fd.setFile(lastClassName.substring + (lastClassName.lastIndexOf('.')+1).concat(".java")); + fd.show(); + String fileName = fd.getFile(); + if (fileName == null) + return true; + try { + File f = new File(new File(fd.getDirectory()), fileName); + FileWriter out = new FileWriter(f); + out.write(sourcecodeArea.getText()); + out.close(); + } catch (IOException ex) { + errorArea.setText(""); + Decompiler.err.println("Couldn't write to file " + + fileName + ": "); + ex.printStackTrace(Decompiler.err); + } } return true; } @@ -105,7 +150,12 @@ public class JodeAppletOneZero extends Applet implements Runnable { } public void run() { + Decompiler.isVerbose = verboseCheck.getState(); + Decompiler.prettyLocals = prettyCheck.getState(); errorArea.setText(""); + saveButton.disable(); + lastClassName = classField.getText(); + String cp = classpathField.getText(); cp = cp.replace(':', jode.bytecode.SearchPath.protocolSeparator); cp = cp.replace(',', File.pathSeparatorChar); @@ -115,14 +165,13 @@ public class JodeAppletOneZero extends Applet implements Runnable { TabbedPrintWriter writer = new TabbedPrintWriter(out, " "); env.doClass(classField.getText(), writer); sourcecodeArea.setText(out.toString()); + saveButton.enable(); } 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; - } + startButton.enable(); } } } diff --git a/jode/jode-applet.html b/jode/jode-applet.html index 6ad1dd0..26387a3 100644 --- a/jode/jode-applet.html +++ b/jode/jode-applet.html @@ -3,20 +3,45 @@
jode.JodeWindow
, so you may start it
+under SUN JDK with (the exact commands depend on your operating
+system, java virtual machine, shell etc):
+
++ set CLASSPATH=jode_cls.zip + java jode.JodeWindow ++ +Back to the Decompiler Page + -