Skip to content

Commit

Permalink
fix(gui): improve log viewer dialog (#1311)(PR #1649)
Browse files Browse the repository at this point in the history
* [gui]: improve log viewer dialog

* use method from UiUtils to set window icons

Co-authored-by: Skylot <skylot@gmail.com>
  • Loading branch information
jpstotz and skylot authored Aug 18, 2022
1 parent 1d7b6fd commit c7e6e28
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions jadx-gui/src/main/java/jadx/gui/ui/dialog/LogViewerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
Expand All @@ -20,51 +22,72 @@
import jadx.gui.ui.MainWindow;
import jadx.gui.ui.codearea.AbstractCodeArea;
import jadx.gui.utils.NLS;
import jadx.gui.utils.UiUtils;
import jadx.gui.utils.logs.ILogListener;
import jadx.gui.utils.logs.LogCollector;

public class LogViewerDialog extends JDialog {
public class LogViewerDialog extends JFrame {
private static final long serialVersionUID = -2188700277429054641L;
private static final Level[] LEVEL_ITEMS = { Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR };

private static Level level = Level.WARN;

private final transient JadxSettings settings;
private transient RSyntaxTextArea textPane;
private JComboBox<Level> levelCb;

private static LogViewerDialog openLogDialog;

public static void open(MainWindow mainWindow) {
openWithLevel(mainWindow, level);
}

public static void openWithLevel(MainWindow mainWindow, Level newLevel) {
level = newLevel;
new LogViewerDialog(mainWindow).setVisible(true);
if (openLogDialog == null) {
LogViewerDialog newLogDialog = new LogViewerDialog(mainWindow);
newLogDialog.setVisible(true);
openLogDialog = newLogDialog;
} else {
LogViewerDialog logDialog = openLogDialog;
logDialog.levelCb.setSelectedItem(level);
logDialog.setVisible(true);
logDialog.toFront();
}
}

private LogViewerDialog(MainWindow mainWindow) {
this.settings = mainWindow.getSettings();
initUI(mainWindow);
registerLogListener();
settings.loadWindowPos(this);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
openLogDialog = null;
}
});
}

public final void initUI(MainWindow mainWindow) {
UiUtils.setWindowIcons(this);

textPane = AbstractCodeArea.getDefaultArea(mainWindow);
textPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));

JPanel controlPane = new JPanel();
controlPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
final JComboBox<Level> cb = new JComboBox<>(LEVEL_ITEMS);
cb.setSelectedItem(level);
cb.addActionListener(e -> {
int i = cb.getSelectedIndex();
levelCb = new JComboBox<>(LEVEL_ITEMS);
levelCb.setSelectedItem(level);
levelCb.addActionListener(e -> {
int i = levelCb.getSelectedIndex();
level = LEVEL_ITEMS[i];
registerLogListener();
});
JLabel levelLabel = new JLabel(NLS.str("log_viewer.log_level"));
levelLabel.setLabelFor(cb);
levelLabel.setLabelFor(levelCb);
controlPane.add(levelLabel);
controlPane.add(cb);
controlPane.add(levelCb);

JScrollPane scrollPane = new JScrollPane(textPane);

Expand All @@ -81,7 +104,6 @@ public final void initUI(MainWindow mainWindow) {
pack();
setSize(800, 600);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setModalityType(ModalityType.MODELESS);
setLocationRelativeTo(null);
}

Expand Down

0 comments on commit c7e6e28

Please sign in to comment.