Skip to content

Commit

Permalink
UI updates and add background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurieWired committed Mar 22, 2023
1 parent 6cb2c60 commit bc2d3da
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

import jadx.gui.jobs.BackgroundExecutor;
import jadx.gui.settings.JadxSettings;
import jadx.gui.ui.MainWindow;
import jadx.gui.utils.UiUtils;
Expand Down Expand Up @@ -66,6 +67,7 @@ private void initUI() {
RSyntaxTextArea codeInputArea = new RSyntaxTextArea(getDefaultCodeInputText());
codeInputArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
JScrollPane codeInputScrollPanel = new JScrollPane(codeInputArea);
codeInputScrollPanel.setPreferredSize(new Dimension(550, 200));

JLabel consoleOutputDescription = new JLabel("Console Output");
consoleOutputDescription.setPreferredSize(new Dimension(80, 16));
Expand All @@ -76,6 +78,7 @@ private void initUI() {
consoleOutputArea.setForeground(Color.WHITE);

JScrollPane consoleOutputScrollPanel = new JScrollPane(consoleOutputArea);
consoleOutputScrollPanel.setPreferredSize(new Dimension(550, 100));

// Input and output code areas
JPanel codePanel = initCodePanel(codeInputDescription, codeInputScrollPanel, consoleOutputDescription, consoleOutputScrollPanel);
Expand Down Expand Up @@ -146,6 +149,7 @@ private JPanel initCodeExamplesPanel(RSyntaxTextArea codeInputArea, JPanel fileP
southExamplesPanel.add(exampleScrollPane, BorderLayout.CENTER);
codeExamplesPanel.add(filePanel, BorderLayout.NORTH);
codeExamplesPanel.add(southExamplesPanel, BorderLayout.CENTER);
codeExamplesPanel.setPreferredSize(new Dimension(200, 400));

return codeExamplesPanel;
}
Expand All @@ -157,7 +161,7 @@ private void finishUI(JPanel mainPanel) {
setTitle("JADXecute");
pack();
if (!mainWindow.getSettings().loadWindowPos(this)) {
setSize(700, 500);
setSize(800, 500);
}
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Expand Down Expand Up @@ -293,12 +297,25 @@ private String getDefaultCodeInputText() {

private void runUserCode(RSyntaxTextArea codeInputArea, JTextArea consoleOutputArea, JLabel statusLabel, JButton run) {
statusLabel.setText("Status: Running...");
statusLabel.setForeground(Color.YELLOW);
statusLabel.setForeground(Color.ORANGE);

run.setText("Stop");
run.setForeground(Color.RED);
BackgroundExecutor executor = mainWindow.getBackgroundExecutor();
executor.execute("Jadexecute Task", () -> executeBackgroundTask(codeInputArea, consoleOutputArea, statusLabel),
analysisStatus -> finishTask(consoleOutputArea, statusLabel));
}

private void finishTask(JTextArea consoleOutputArea, JLabel statusLabel) {
if (consoleOutputArea.getText().contains("Java compilation error")) {
statusLabel.setText("Status: Error");
statusLabel.setForeground(Color.RED);
} else {
statusLabel.setText("Status: Done");
statusLabel.setForeground(Color.GREEN);
}
}

String codeInput = codeInputArea.getText();
private void executeBackgroundTask(RSyntaxTextArea codeInputArea, JTextArea consoleOutputArea, JLabel statusLabel) {
String codeInput = codeInputArea.getText();

try{
UserCodeLoader userCodeLoader = new UserCodeLoader();
Expand All @@ -309,17 +326,6 @@ private void runUserCode(RSyntaxTextArea codeInputArea, JTextArea consoleOutputA
statusLabel.setText("Status: Error");
statusLabel.setForeground(Color.RED);
}

if (consoleOutputArea.getText().contains("Java compilation error")) {
statusLabel.setText("Status: Error");
statusLabel.setForeground(Color.RED);
} else {
statusLabel.setText("Status: Done");
statusLabel.setForeground(Color.GREEN);
}

run.setText("Run");
run.setForeground(null);
}

private void close() {
Expand Down
Loading

0 comments on commit bc2d3da

Please sign in to comment.