forked from johnlindquist/angularjs-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGotoAngularModel.java
More file actions
121 lines (100 loc) · 4.17 KB
/
GotoAngularModel.java
File metadata and controls
121 lines (100 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package org.angularjs;
import com.intellij.ide.util.gotoByName.ChooseByNameBase;
import com.intellij.ide.util.gotoByName.SimpleChooseByNameModel;
import com.intellij.openapi.project.Project;
import com.intellij.ui.JBColor;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.speedSearch.SpeedSearchUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: johnlindquist
* Date: 3/26/13
* Time: 1:38 PM
* To change this template use File | Settings | File Templates.
*/
public class GotoAngularModel extends SimpleChooseByNameModel{
private final List<AngularItem> angularItems;
public GotoAngularModel(@NotNull Project project, List<AngularItem> angularItems) {
super(project, "AngularJS", "Help id");
this.angularItems = angularItems;
}
//these are searched
@Override
public String[] getNames() {
List<String> strings = new ArrayList<String>();
for (AngularItem angularItem : angularItems) {
strings.add(angularItem.getKey());
}
return ArrayUtil.toStringArray(strings);
}
//list provided to the item renderer
@Override
protected Object[] getElementsByName(String name, String pattern) {
for (AngularItem angularItem : angularItems) {
if (angularItem.getKey().equals(name)) {
return new Object[]{angularItem};
}
}
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
@Override
public ListCellRenderer getListCellRenderer() {
return new GotoAngularCellRenderer();
}
@Nullable
@Override
public String getElementName(Object element) {
return "Element name!";
}
protected class GotoAngularCellRenderer implements ListCellRenderer {
private final SimpleTextAttributes SELECTED;
private final SimpleTextAttributes PLAIN;
public GotoAngularCellRenderer() {
SELECTED = new SimpleTextAttributes(UIUtil.getListSelectionBackground(),
UIUtil.getListSelectionForeground(),
JBColor.RED,
SimpleTextAttributes.STYLE_PLAIN);
PLAIN = new SimpleTextAttributes(UIUtil.getListBackground(),
UIUtil.getListForeground(),
JBColor.RED,
SimpleTextAttributes.STYLE_PLAIN);
}
@Override
public Component getListCellRendererComponent(JList jList, Object value, int i, boolean sel, boolean focus) {
JPanel jPanel = new JPanel(new BorderLayout());
jPanel.setOpaque(true);
final Color bg = sel ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
final Color fg = sel ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
jPanel.setBackground(bg);
jPanel.setForeground(fg);
SimpleTextAttributes attr = sel ? SELECTED : PLAIN;
if (value instanceof AngularItem) {
AngularItem item = (AngularItem) value;
final SimpleColoredComponent c = new SimpleColoredComponent();
SpeedSearchUtil.appendColoredFragmentForMatcher(" " + item.getItemName(), c, attr, null, bg, sel);
jPanel.add(c, BorderLayout.WEST);
final SimpleColoredComponent group = new SimpleColoredComponent();
SpeedSearchUtil.appendColoredFragmentForMatcher(item.getItemType() + " ", group, attr, null, bg, sel);
final JPanel right = new JPanel(new BorderLayout());
right.setBackground(bg);
right.setForeground(fg);
right.add(group, BorderLayout.CENTER);
jPanel.add(right, BorderLayout.EAST);
}
else {
// E.g. "..." item
return ChooseByNameBase.renderNonPrefixSeparatorComponent(UIUtil.getListBackground());
}
return jPanel;
}
}
}