Commit 895ddfa3 authored by Skylot's avatar Skylot

gui: cache renderer results in find/usage dialogs

parent 28e334a0
...@@ -23,6 +23,7 @@ import javax.swing.JTable; ...@@ -23,6 +23,7 @@ import javax.swing.JTable;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants; import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import javax.swing.UIDefaults; import javax.swing.UIDefaults;
import javax.swing.UIManager; import javax.swing.UIManager;
...@@ -43,13 +44,16 @@ import java.awt.event.MouseAdapter; ...@@ -43,13 +44,16 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.SearchContext; import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine; import org.fife.ui.rtextarea.SearchEngine;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -309,7 +313,9 @@ public abstract class CommonSearchDialog extends JDialog { ...@@ -309,7 +313,9 @@ public abstract class CommonSearchDialog extends JDialog {
private final Color selectedBackground; private final Color selectedBackground;
private final Color selectedForeground; private final Color selectedForeground;
ResultsTableCellRenderer() { private Map<Integer, Component> componentCache = new HashMap<Integer, Component>();
public ResultsTableCellRenderer() {
UIDefaults defaults = UIManager.getDefaults(); UIDefaults defaults = UIManager.getDefaults();
selectedBackground = defaults.getColor("List.selectionBackground"); selectedBackground = defaults.getColor("List.selectionBackground");
selectedForeground = defaults.getColor("List.selectionForeground"); selectedForeground = defaults.getColor("List.selectionForeground");
...@@ -318,22 +324,33 @@ public abstract class CommonSearchDialog extends JDialog { ...@@ -318,22 +324,33 @@ public abstract class CommonSearchDialog extends JDialog {
@Override @Override
public Component getTableCellRendererComponent(JTable table, Object obj, boolean isSelected, public Component getTableCellRendererComponent(JTable table, Object obj, boolean isSelected,
boolean hasFocus, int row, int column) { boolean hasFocus, int row, int column) {
if (!(obj instanceof JNode)) { int id = (row << 2) | column;
return null; Component comp = componentCache.get(id);
if (comp == null && (obj instanceof JNode)) {
comp = makeCell((JNode) obj, column);
componentCache.put(id, comp);
}
if (comp != null) {
updateSelection(comp, isSelected);
}
return comp;
} }
JNode node = (JNode) obj;
if (column == 0) { private void updateSelection(Component comp, boolean isSelected) {
JLabel label = new JLabel();
label.setOpaque(true);
if (isSelected) { if (isSelected) {
label.setBackground(selectedBackground); comp.setBackground(selectedBackground);
label.setForeground(selectedForeground); comp.setForeground(selectedForeground);
} else { } else {
label.setBackground(ContentArea.BACKGROUND); comp.setBackground(ContentArea.BACKGROUND);
} }
label.setIcon(node.getIcon()); }
label.setText(node.makeLongString() + " ");
@Nullable
protected Component makeCell(JNode node, int column) {
if (column == 0) {
JLabel label = new JLabel(node.makeLongString() + " ", node.getIcon(), SwingConstants.LEFT);
label.setOpaque(true);
label.setToolTipText(label.getText());
return label; return label;
} }
if (node.hasDescString()) { if (node.hasDescString()) {
...@@ -341,7 +358,6 @@ public abstract class CommonSearchDialog extends JDialog { ...@@ -341,7 +358,6 @@ public abstract class CommonSearchDialog extends JDialog {
textArea.setFont(codeFont); textArea.setFont(codeFont);
textArea.setEditable(false); textArea.setEditable(false);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
textArea.setBackground(isSelected ? selectedBackground : ContentArea.BACKGROUND);
textArea.setText(" " + node.makeDescString()); textArea.setText(" " + node.makeDescString());
textArea.setRows(1); textArea.setRows(1);
textArea.setColumns(textArea.getText().length()); textArea.setColumns(textArea.getText().length());
...@@ -355,6 +371,7 @@ public abstract class CommonSearchDialog extends JDialog { ...@@ -355,6 +371,7 @@ public abstract class CommonSearchDialog extends JDialog {
} }
return null; return null;
} }
} }
private class LoadTask extends SwingWorker<Void, Void> { private class LoadTask extends SwingWorker<Void, Void> {
......
...@@ -36,7 +36,9 @@ public class Utils { ...@@ -36,7 +36,9 @@ public class Utils {
} }
public static String typeFormat(String name, ArgType type) { public static String typeFormat(String name, ArgType type) {
return "<html>" + name + "<span style='color:#888888;'> : " + typeStr(type) + "</span></html>"; return "<html><body><nobr>" + name
+ "<span style='color:#888888;'> : " + typeStr(type) + "</span>"
+ "</nobr></body></html>";
} }
public static String typeStr(ArgType type) { public static String typeStr(ArgType type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment