Skip to content

Commit

Permalink
gui: fix results render issues is search dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Sep 23, 2015
1 parent 895ddfa commit 6d963b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 14 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/ui/CommonSearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public void actionPerformed(ActionEvent event) {
}

protected JPanel initResultsTable() {
resultsModel = new ResultsModel();
ResultsTableCellRenderer renderer = new ResultsTableCellRenderer();
resultsModel = new ResultsModel(renderer);
resultsTable = new ResultsTable(resultsModel);
resultsTable.setShowHorizontalLines(false);
resultsTable.setDragEnabled(false);
Expand All @@ -167,7 +168,6 @@ protected JPanel initResultsTable() {
resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
resultsTable.setAutoscrolls(false);

ResultsTableCellRenderer renderer = new ResultsTableCellRenderer();
Enumeration<TableColumn> columns = resultsTable.getColumnModel().getColumns();
while (columns.hasMoreElements()) {
TableColumn column = columns.nextElement();
Expand Down Expand Up @@ -257,8 +257,13 @@ protected static class ResultsModel extends AbstractTableModel {
private static final String[] COLUMN_NAMES = {"Node", "Code"};

private final List<JNode> rows = new ArrayList<JNode>();
private final ResultsTableCellRenderer renderer;
private boolean addDescColumn;

public ResultsModel(ResultsTableCellRenderer renderer) {
this.renderer = renderer;
}

protected void addAll(Iterable<? extends JNode> nodes) {
for (JNode node : nodes) {
int size = getRowCount();
Expand All @@ -282,6 +287,7 @@ private void add(JNode node) {
public void clear() {
addDescColumn = false;
rows.clear();
renderer.clear();
}

public boolean isAddDescColumn() {
Expand Down Expand Up @@ -312,11 +318,13 @@ public Object getValueAt(int rowIndex, int columnIndex) {
protected class ResultsTableCellRenderer implements TableCellRenderer {
private final Color selectedBackground;
private final Color selectedForeground;
private final Color foreground;

private Map<Integer, Component> componentCache = new HashMap<Integer, Component>();

public ResultsTableCellRenderer() {
UIDefaults defaults = UIManager.getDefaults();
foreground = defaults.getColor("List.foreground");
selectedBackground = defaults.getColor("List.selectionBackground");
selectedForeground = defaults.getColor("List.selectionForeground");
}
Expand All @@ -342,6 +350,7 @@ private void updateSelection(Component comp, boolean isSelected) {
comp.setForeground(selectedForeground);
} else {
comp.setBackground(ContentArea.BACKGROUND);
comp.setForeground(foreground);
}
}

Expand Down Expand Up @@ -372,6 +381,9 @@ protected Component makeCell(JNode node, int column) {
return null;
}

public void clear() {
componentCache.clear();
}
}

private class LoadTask extends SwingWorker<Void, Void> {
Expand Down
2 changes: 2 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/SearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ private synchronized void performSearch() {
resultsModel.clear();
String text = searchField.getText();
if (text == null || text.isEmpty() || options.isEmpty()) {
resultsTable.updateTable();
return;
}
cache.setLastSearch(text);
TextSearchIndex index = cache.getTextIndex();
if (index == null) {
resultsTable.updateTable();
return;
}
if (options.contains(SearchOptions.CLASS)) {
Expand Down

0 comments on commit 6d963b3

Please sign in to comment.