Skip to content

Commit

Permalink
Improved way of opening gui/cli/standalone editors
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Nov 10, 2022
1 parent db077cf commit 65894f5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
16 changes: 12 additions & 4 deletions runtime-decompiler/src/main/java/org/jrd/backend/data/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jrd.backend.core.Logger;
import org.jrd.backend.data.cli.Cli;
import org.jrd.backend.data.cli.Help;
import org.jrd.frontend.frame.hex.StandaloneHex;
import org.jrd.frontend.frame.main.decompilerview.DecompilationController;
import org.jrd.frontend.frame.main.MainFrameView;
Expand All @@ -13,12 +14,19 @@ public static void main(String[] allArgs) throws Exception {
Cli cli = new Cli(allArgs, model);
if (cli.isGui()) {
setLookAndFeel();
if (cli.isHex()) {
StandaloneHex hexview = new StandaloneHex(cli.getFilteredArgs());
if (!cli.getFilteredArgs().isEmpty()) {
Help.printHelpText();
StandaloneHex hexview = new StandaloneHex(cli.getFilteredArgs(), cli.isHex());
hexview.setVisible(true);
} else {
MainFrameView mainView = new MainFrameView();
new DecompilationController(mainView, model, cli.shouldBeVerbose());
if (cli.isHex() && cli.getFilteredArgs().isEmpty()) {
Help.printHelpText();
StandaloneHex hexview = new StandaloneHex(cli.getFilteredArgs(), cli.isHex());
hexview.setVisible(true);
} else {
MainFrameView mainView = new MainFrameView();
new DecompilationController(mainView, model, cli.shouldBeVerbose());
}
}
} else {
cli.consumeCli();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public boolean shouldBeVerbose() {
return isVerbose;
}

@SuppressWarnings({"UnnecessaryParentheses"})
public boolean isGui() {
return filteredArgs.isEmpty() || (isHex && (CliSwitches.noMatch(filteredArgs)));
return filteredArgs.isEmpty() || CliSwitches.noMatch(filteredArgs);
}

public boolean isHex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class Help {
public static final String REMOVE_OVERRIDES_FORMAT = REMOVE_OVERRIDES + " <PUC> removalRegex";
public static final String LIST_PLUGINS_FORMAT = LIST_PLUGINS;
public static final String LIST_CLASSES_FORMAT = LIST_CLASSES + BASE_SHARED_OPTIONAL_FORMAT;
public static final String SEARCH_FORMAT = SEARCH + BASE_SHARED_FORMAT + " searchedSubstring true/false (details)";
public static final String SEARCH_FORMAT = SEARCH + BASE_SHARED_FORMAT + " searchedSubstring true/false (with/without details)";
public static final String LIST_CLASSESDETAILS_FORMAT = LIST_CLASSESDETAILS + BASE_SHARED_OPTIONAL_FORMAT;
public static final String LIST_CLASSESBYTECODEVERSIONS_FORMAT = LIST_CLASSESBYTECODEVERSIONS + BASE_SHARED_OPTIONAL_FORMAT;
public static final String LIST_CLASSESDETAILSVERSIONS_FORMAT = LIST_CLASSESDETAILSBYTECODEVERSIONS + BASE_SHARED_OPTIONAL_FORMAT;
Expand Down Expand Up @@ -225,7 +225,7 @@ public final class Help {
private Help() {
}

protected static void printHelpText() {
public static void printHelpText() {
printHelpText(new CliHelpFormatter());
}

Expand Down Expand Up @@ -263,7 +263,8 @@ default void printUsage() {
System.out.println(indent(1) + launcher(true) + launchOption);
}
System.out.println(
indent(1) + launcher(false) + HEX + " [file, file...]" + " launches standalone hex (and text) editor/diff. Mighty diff."
indent(1) + launcher(false) + "[" + HEX + "]" + " [file, file...]" +
" launches standalone hex (or text) editor/diff. Mighty diff. " + HEX + " suggests, how to open `file, file...`"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ public class StandaloneHex extends JFrame {
private static int counter = 0;
File lastOpened = new File(System.getProperty("user.dir"));

public StandaloneHex(List<String> files) throws HeadlessException, IOException {
public StandaloneHex(List<String> files, boolean hex) throws HeadlessException, IOException {
super("JRD's hex diff and editor");
this.setSize(900, 800);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
final JTabbedPane tp = new JTabbedPane();
for (String s : files) {
JPanel wrapper = new FeatureFullHex(new File(s), tp, new HexWithControls(null));
JPanel wrapper;
if (hex) {
wrapper = new FeatureFullHex(new File(s), tp, new HexWithControls(null));
} else {
wrapper = new FeatureFullHex(new File(s), tp, new TextWithControls(null));
}
tp.add(wrapper);
}
JPanel topButtons = new JPanel(new GridLayout(1, 2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public void windowClosing(WindowEvent e) {
openEditor.addActionListener(a -> {
StandaloneHex hexview = null;
try {
hexview = new StandaloneHex(new ArrayList<>());
hexview = new StandaloneHex(new ArrayList<>(), true);
hexview.setVisible(true);
} catch (IOException ex) {
Logger.getLogger().log(ex);
Expand Down

0 comments on commit 65894f5

Please sign in to comment.