Skip to content

Commit

Permalink
fix: disable HTML rendering in labels if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 20, 2022
1 parent e9e4570 commit 6844a46
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import jadx.gui.settings.JadxSettings;
import jadx.gui.ui.MainWindow;
import jadx.gui.utils.UiUtils;
import jadx.gui.utils.ui.NodeLabel;

public class QuarkDialog extends JDialog {
private static final long serialVersionUID = 4855753773520368215L;
Expand Down Expand Up @@ -59,7 +60,7 @@ private void initUI() {
description.setAlignmentX(0.5f);

fileSelectCombo = new JComboBox<>(files.toArray(new Path[0]));
fileSelectCombo.setRenderer((list, value, index, isSelected, cellHasFocus) -> new JLabel(value.getFileName().toString()));
fileSelectCombo.setRenderer((list, value, index, isSelected, cellHasFocus) -> new NodeLabel(value.getFileName().toString()));

JPanel textPane = new JPanel();
textPane.add(description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import jadx.gui.ui.TabbedPane;
import jadx.gui.ui.panel.ContentPanel;
import jadx.gui.utils.JNodeCache;
import jadx.gui.utils.ui.NodeLabel;

public class QuarkReportPanel extends ContentPanel {
private static final long serialVersionUID = -242266836695889206L;
Expand Down Expand Up @@ -211,7 +212,7 @@ public TextTreeNode bold() {

@Override
public Component render() {
JLabel label = new JLabel(((String) getUserObject()));
JLabel label = new NodeLabel(((String) getUserObject()));
label.setFont(bold ? boldFont : font);
label.setIcon(null);
label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
Expand Down Expand Up @@ -320,7 +321,7 @@ public JMethod getJMethod() {

@Override
public Component render() {
JLabel label = new JLabel(mth.toString());
JLabel label = new NodeLabel(mth.toString());
label.setFont(font);
label.setIcon(jnode.getIcon());
label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
Expand Down
5 changes: 5 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/treemodel/CodeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public String makeLongStringHtml() {
return jNode.makeLongStringHtml();
}

@Override
public boolean disableHtml() {
return jNode.disableHtml();
}

@Override
public String getSyntaxName() {
return jNode.getSyntaxName();
Expand Down
5 changes: 5 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/treemodel/JField.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public String makeDescString() {
return UiUtils.typeStr(field.getType()) + " " + field.getName();
}

@Override
public boolean disableHtml() {
return false;
}

@Override
public boolean hasDescString() {
return false;
Expand Down
5 changes: 5 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public String makeLongStringHtml() {
return UiUtils.typeFormatHtml(name, getReturnType());
}

@Override
public boolean disableHtml() {
return false;
}

@Override
public String makeDescString() {
return UiUtils.typeStr(getReturnType()) + " " + makeBaseString();
Expand Down
4 changes: 4 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public String makeLongStringHtml() {
return makeLongString();
}

public boolean disableHtml() {
return true;
}

public int getPos() {
JavaNode javaNode = getJavaNode();
if (javaNode == null) {
Expand Down
2 changes: 2 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import jadx.gui.utils.fileswatcher.LiveReloadWorker;
import jadx.gui.utils.logs.LogCollector;
import jadx.gui.utils.ui.ActionHandler;
import jadx.gui.utils.ui.NodeLabel;

import static io.reactivex.internal.functions.Functions.EMPTY_RUNNABLE;
import static javax.swing.KeyStroke.getKeyStroke;
Expand Down Expand Up @@ -1281,6 +1282,7 @@ public Component getTreeCellRendererComponent(JTree tree,
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
if (value instanceof JNode) {
JNode jNode = (JNode) value;
NodeLabel.disableHtml(this, jNode.disableHtml());
setText(jNode.makeStringHtml());
setIcon(jNode.getIcon());
setToolTipText(jNode.getTooltip());
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/TabComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import jadx.gui.utils.Icons;
import jadx.gui.utils.NLS;
import jadx.gui.utils.UiUtils;
import jadx.gui.utils.ui.NodeLabel;

public class TabComponent extends JPanel {
private static final long serialVersionUID = -8147035487543610321L;
Expand Down Expand Up @@ -58,7 +59,7 @@ private void init() {
} else {
tabTitle = node.makeLongStringHtml();
}
label = new JLabel(tabTitle);
label = new NodeLabel(tabTitle, node.disableHtml());
label.setFont(getLabelFont());
String toolTip = contentPanel.getTabTooltip();
if (toolTip != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import jadx.gui.utils.JumpPosition;
import jadx.gui.utils.NLS;
import jadx.gui.utils.UiUtils;
import jadx.gui.utils.ui.NodeLabel;

import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
Expand Down Expand Up @@ -402,9 +403,9 @@ public Object getValueAt(int rowIndex, int columnIndex) {
}

protected final class ResultsTableCellRenderer implements TableCellRenderer {
private final JLabel label;
private final NodeLabel label;
private final RSyntaxTextArea codeArea;
private final JLabel emptyLabel;
private final NodeLabel emptyLabel;
private final Color codeSelectedColor;
private final Color codeBackground;

Expand All @@ -414,11 +415,11 @@ public ResultsTableCellRenderer() {
codeArea.setRows(1);
codeBackground = codeArea.getBackground();
codeSelectedColor = codeArea.getSelectionColor();
label = new JLabel();
label = new NodeLabel();
label.setOpaque(true);
label.setFont(codeArea.getFont());
label.setHorizontalAlignment(SwingConstants.LEFT);
emptyLabel = new JLabel();
emptyLabel = new NodeLabel();
emptyLabel.setOpaque(true);
}

Expand Down Expand Up @@ -454,8 +455,9 @@ private void updateSelection(JTable table, Component comp, int column, boolean i
private Component makeCell(JNode node, int column) {
if (column == 0) {
label.setText(node.makeLongStringHtml());
label.setToolTipText(label.getText());
label.setToolTipText(node.getTooltip());
label.setIcon(node.getIcon());
label.disableHtml(node.disableHtml());
return label;
}
if (!node.hasDescString()) {
Expand Down
4 changes: 2 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/ui/dialog/RenameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -60,6 +59,7 @@
import jadx.gui.utils.TextStandardActions;
import jadx.gui.utils.UiUtils;
import jadx.gui.utils.ui.DocumentUpdateListener;
import jadx.gui.utils.ui.NodeLabel;

public class RenameDialog extends JDialog {
private static final long serialVersionUID = -3269715644416902410L;
Expand Down Expand Up @@ -313,7 +313,7 @@ protected JPanel initButtonsPanel() {

private void initUI() {
JLabel lbl = new JLabel(NLS.str("popup.rename"));
JLabel nodeLabel = new JLabel(this.node.makeLongStringHtml(), this.node.getIcon(), SwingConstants.LEFT);
JLabel nodeLabel = NodeLabel.longName(node);
lbl.setLabelFor(nodeLabel);

renameField = new JTextField(40);
Expand Down
4 changes: 2 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/ui/dialog/UsageDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;

import jadx.api.ICodeInfo;
Expand All @@ -31,6 +30,7 @@
import jadx.gui.utils.JNodeCache;
import jadx.gui.utils.NLS;
import jadx.gui.utils.UiUtils;
import jadx.gui.utils.ui.NodeLabel;

public class UsageDialog extends CommonSearchDialog {
private static final long serialVersionUID = -5105405789969134105L;
Expand Down Expand Up @@ -147,7 +147,7 @@ private void initUI() {
Font codeFont = settings.getFont();
JLabel lbl = new JLabel(NLS.str("usage_dialog.label"));
lbl.setFont(codeFont);
JLabel nodeLabel = new JLabel(this.node.makeLongStringHtml(), this.node.getIcon(), SwingConstants.LEFT);
JLabel nodeLabel = NodeLabel.longName(node);
nodeLabel.setFont(codeFont);
lbl.setLabelFor(nodeLabel);

Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/panel/LogcatPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import jadx.gui.device.protocol.ADBDevice;
import jadx.gui.utils.NLS;
import jadx.gui.utils.UiUtils;
import jadx.gui.utils.ui.NodeLabel;

public class LogcatPanel extends JPanel {
private static final Logger LOG = LoggerFactory.getLogger(LogcatPanel.class);
Expand Down Expand Up @@ -301,7 +302,7 @@ public void actionPerformed(ActionEvent e) {
}

public JPanel getContent() {
JLabel label = new JLabel(this.label + ": ");
JLabel label = NodeLabel.noHtml(this.label + ": ");
CheckComboStore[] stores = new CheckComboStore[ids.length];
for (int j = 0; j < ids.length; j++) {
stores[j] = new CheckComboStore(index[j], ids[j], Boolean.TRUE);
Expand Down
47 changes: 47 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/utils/ui/NodeLabel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package jadx.gui.utils.ui;

import javax.swing.JLabel;
import javax.swing.SwingConstants;

import jadx.gui.treemodel.JNode;

public class NodeLabel extends JLabel {

public static NodeLabel longName(JNode node) {
NodeLabel label = new NodeLabel(node.makeLongStringHtml(), node.disableHtml());
label.setIcon(node.getIcon());
label.setHorizontalAlignment(SwingConstants.LEFT);
return label;
}

public static NodeLabel noHtml(String label) {
return new NodeLabel(label, true);
}

public static void disableHtml(JLabel label, boolean disable) {
label.putClientProperty("html.disable", disable);
}

private boolean htmlDisabled = false;

public NodeLabel() {
disableHtml(true);
}

public NodeLabel(String label) {
disableHtml(true);
setText(label);
}

public NodeLabel(String label, boolean disableHtml) {
disableHtml(disableHtml);
setText(label);
}

public void disableHtml(boolean disable) {
if (htmlDisabled != disable) {
htmlDisabled = disable;
disableHtml(this, disable);
}
}
}

4 comments on commit 6844a46

@jpstotz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skylot It seem that you disabled HTML rendering a bit too often. In search dialog the result viewer methods some times the HTML code is now shown:

image

@skylot
Copy link
Owner Author

@skylot skylot commented on 6844a46 Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpstotz
Oh, this is a stupid rendering issue 😭
I commit a fix (4db50fb). Thanks for notice πŸ‘

@Surendrajat
Copy link
Contributor

@Surendrajat Surendrajat commented on 6844a46 Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skylot same issue with user added comments:

image

@skylot
Copy link
Owner Author

@skylot skylot commented on 6844a46 Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Surendrajat thanks! Fixed in 22ed241 πŸ‘

Please sign in to comment.