From 6844a46c93a4c911196b47ad3492da15935711b9 Mon Sep 17 00:00:00 2001 From: Skylot Date: Thu, 20 Oct 2022 15:58:23 +0100 Subject: [PATCH] fix: disable HTML rendering in labels if not needed --- .../jadx/gui/plugins/quark/QuarkDialog.java | 3 +- .../gui/plugins/quark/QuarkReportPanel.java | 5 +- .../java/jadx/gui/treemodel/CodeNode.java | 5 ++ .../main/java/jadx/gui/treemodel/JField.java | 5 ++ .../main/java/jadx/gui/treemodel/JMethod.java | 5 ++ .../main/java/jadx/gui/treemodel/JNode.java | 4 ++ .../src/main/java/jadx/gui/ui/MainWindow.java | 2 + .../main/java/jadx/gui/ui/TabComponent.java | 3 +- .../gui/ui/dialog/CommonSearchDialog.java | 12 +++-- .../java/jadx/gui/ui/dialog/RenameDialog.java | 4 +- .../java/jadx/gui/ui/dialog/UsageDialog.java | 4 +- .../java/jadx/gui/ui/panel/LogcatPanel.java | 3 +- .../java/jadx/gui/utils/ui/NodeLabel.java | 47 +++++++++++++++++++ 13 files changed, 88 insertions(+), 14 deletions(-) create mode 100644 jadx-gui/src/main/java/jadx/gui/utils/ui/NodeLabel.java diff --git a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkDialog.java b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkDialog.java index 2ac4137430b..abeee831aac 100644 --- a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkDialog.java +++ b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkDialog.java @@ -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; @@ -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); diff --git a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportPanel.java b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportPanel.java index 8507cc39f70..552008a7c0c 100644 --- a/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportPanel.java +++ b/jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportPanel.java @@ -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; @@ -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)); @@ -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)); diff --git a/jadx-gui/src/main/java/jadx/gui/treemodel/CodeNode.java b/jadx-gui/src/main/java/jadx/gui/treemodel/CodeNode.java index f8461160c56..2ae107eca2f 100644 --- a/jadx-gui/src/main/java/jadx/gui/treemodel/CodeNode.java +++ b/jadx-gui/src/main/java/jadx/gui/treemodel/CodeNode.java @@ -71,6 +71,11 @@ public String makeLongStringHtml() { return jNode.makeLongStringHtml(); } + @Override + public boolean disableHtml() { + return jNode.disableHtml(); + } + @Override public String getSyntaxName() { return jNode.getSyntaxName(); diff --git a/jadx-gui/src/main/java/jadx/gui/treemodel/JField.java b/jadx-gui/src/main/java/jadx/gui/treemodel/JField.java index 676786c5ca7..0d03bceda93 100644 --- a/jadx-gui/src/main/java/jadx/gui/treemodel/JField.java +++ b/jadx-gui/src/main/java/jadx/gui/treemodel/JField.java @@ -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; diff --git a/jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java b/jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java index 01586153278..95e004c382c 100644 --- a/jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java +++ b/jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java @@ -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(); diff --git a/jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java b/jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java index f974e5e74f9..7ab949c2535 100644 --- a/jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java +++ b/jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java @@ -81,6 +81,10 @@ public String makeLongStringHtml() { return makeLongString(); } + public boolean disableHtml() { + return true; + } + public int getPos() { JavaNode javaNode = getJavaNode(); if (javaNode == null) { diff --git a/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java b/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java index 75fea8b2693..d2e17e7c81a 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java @@ -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; @@ -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()); diff --git a/jadx-gui/src/main/java/jadx/gui/ui/TabComponent.java b/jadx-gui/src/main/java/jadx/gui/ui/TabComponent.java index 277a98f583e..db8c9d793ca 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/TabComponent.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/TabComponent.java @@ -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; @@ -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) { diff --git a/jadx-gui/src/main/java/jadx/gui/ui/dialog/CommonSearchDialog.java b/jadx-gui/src/main/java/jadx/gui/ui/dialog/CommonSearchDialog.java index eb62a2df7db..6e1cd7700e0 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/dialog/CommonSearchDialog.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/dialog/CommonSearchDialog.java @@ -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; @@ -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; @@ -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); } @@ -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()) { diff --git a/jadx-gui/src/main/java/jadx/gui/ui/dialog/RenameDialog.java b/jadx-gui/src/main/java/jadx/gui/ui/dialog/RenameDialog.java index 0fa1888559c..63e0a49f77d 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/dialog/RenameDialog.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/dialog/RenameDialog.java @@ -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; @@ -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; @@ -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); diff --git a/jadx-gui/src/main/java/jadx/gui/ui/dialog/UsageDialog.java b/jadx-gui/src/main/java/jadx/gui/ui/dialog/UsageDialog.java index 4febed33aff..57014b2a5e6 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/dialog/UsageDialog.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/dialog/UsageDialog.java @@ -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; @@ -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; @@ -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); diff --git a/jadx-gui/src/main/java/jadx/gui/ui/panel/LogcatPanel.java b/jadx-gui/src/main/java/jadx/gui/ui/panel/LogcatPanel.java index 77b748fde5f..f20834d2f7d 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/panel/LogcatPanel.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/panel/LogcatPanel.java @@ -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); @@ -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); diff --git a/jadx-gui/src/main/java/jadx/gui/utils/ui/NodeLabel.java b/jadx-gui/src/main/java/jadx/gui/utils/ui/NodeLabel.java new file mode 100644 index 00000000000..abd69e7a37c --- /dev/null +++ b/jadx-gui/src/main/java/jadx/gui/utils/ui/NodeLabel.java @@ -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); + } + } +}