Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui]: improve log viewer dialog #1649

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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