|
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 |
| package edu.rice.cs.drjava.ui; |
|
38 |
| |
|
39 |
| import javax.swing.*; |
|
40 |
| import javax.swing.border.LineBorder; |
|
41 |
| import javax.swing.border.EmptyBorder; |
|
42 |
| import java.awt.*; |
|
43 |
| import java.util.LinkedList; |
|
44 |
| import edu.rice.cs.drjava.model.OpenDefinitionsDocument; |
|
45 |
| import edu.rice.cs.drjava.DrJava; |
|
46 |
| import edu.rice.cs.drjava.config.*; |
|
47 |
| import edu.rice.cs.util.swing.DisplayManager; |
|
48 |
| import edu.rice.cs.util.swing.Utilities; |
|
49 |
| |
|
50 |
| |
|
51 |
| public class RecentDocFrame extends JWindow { |
|
52 |
| |
|
53 |
| MainFrame _frame; |
|
54 |
| |
|
55 |
| |
|
56 |
| DisplayManager<OpenDefinitionsDocument> _displayManager = MainFrame.getOddDisplayManager30(); |
|
57 |
| |
|
58 |
| |
|
59 |
| JLabel _label; |
|
60 |
| |
|
61 |
| JPanel _panel; |
|
62 |
| |
|
63 |
| JTextPane _textpane; |
|
64 |
| |
|
65 |
| JScrollPane _scroller; |
|
66 |
| |
|
67 |
| int _current = 0; |
|
68 |
| |
|
69 |
| int _padding = 4; |
|
70 |
| |
|
71 |
| LinkedList<OpenDefinitionsDocument> _docs = new LinkedList<OpenDefinitionsDocument>(); |
|
72 |
| |
|
73 |
| private OptionListener<Color> _colorListener = new OptionListener<Color>() { |
|
74 |
0
| public void optionChanged(OptionEvent<Color> oce) { updateFontColor(); }
|
|
75 |
| }; |
|
76 |
| |
|
77 |
| private OptionListener<Font> _fontListener = new OptionListener<Font>() { |
|
78 |
0
| public void optionChanged(OptionEvent<Font> oce) { updateFontColor(); }
|
|
79 |
| }; |
|
80 |
| |
|
81 |
| private OptionListener<Boolean> _antialiasListener = new OptionListener<Boolean>() { |
|
82 |
0
| public void optionChanged(OptionEvent<Boolean> oce) { updateFontColor(); }
|
|
83 |
| }; |
|
84 |
| |
|
85 |
| private OptionListener<Boolean> _showSourceListener = new OptionListener<Boolean>() { |
|
86 |
0
| public void optionChanged(OptionEvent<Boolean> oce) { _showSource = oce.value; }
|
|
87 |
| }; |
|
88 |
| |
|
89 |
| |
|
90 |
| boolean _antiAliasText = false; |
|
91 |
| |
|
92 |
| |
|
93 |
| boolean _showSource; |
|
94 |
| |
|
95 |
38
| public RecentDocFrame(MainFrame f) {
|
|
96 |
38
| super();
|
|
97 |
38
| _frame = f;
|
|
98 |
38
| _current = 0;
|
|
99 |
38
| _label = new JLabel("...") {
|
|
100 |
| |
|
101 |
0
| protected void paintComponent(Graphics g) {
|
|
102 |
0
| if (_antiAliasText && g instanceof Graphics2D) {
|
|
103 |
0
| Graphics2D g2d = (Graphics2D)g;
|
|
104 |
0
| g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
105 |
| } |
|
106 |
0
| super.paintComponent(g);
|
|
107 |
| } |
|
108 |
| }; |
|
109 |
38
| _panel = new JPanel();
|
|
110 |
38
| _scroller = new JScrollPane();
|
|
111 |
38
| _textpane = new JTextPane() {
|
|
112 |
| |
|
113 |
0
| protected void paintComponent(Graphics g) {
|
|
114 |
0
| if (_antiAliasText && g instanceof Graphics2D) {
|
|
115 |
0
| Graphics2D g2d = (Graphics2D)g;
|
|
116 |
0
| g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
117 |
| } |
|
118 |
0
| super.paintComponent(g);
|
|
119 |
| } |
|
120 |
| }; |
|
121 |
| |
|
122 |
38
| _textpane.setText("...");
|
|
123 |
38
| _scroller.getViewport().add(_textpane);
|
|
124 |
38
| _scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
|
125 |
38
| _scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
126 |
38
| _scroller.setMaximumSize(new Dimension(300,200));
|
|
127 |
| |
|
128 |
38
| _panel.setLayout(new BorderLayout());
|
|
129 |
38
| _panel.add(_label, BorderLayout.NORTH);
|
|
130 |
38
| _panel.add(_scroller, BorderLayout.SOUTH);
|
|
131 |
| |
|
132 |
38
| getContentPane().add(_panel);
|
|
133 |
38
| pack();
|
|
134 |
38
| updateFontColor();
|
|
135 |
38
| _showSource = DrJava.getConfig().getSetting(OptionConstants.SHOW_SOURCE_WHEN_SWITCHING);
|
|
136 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.DEFINITIONS_BACKGROUND_COLOR, _colorListener);
|
|
137 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.DEFINITIONS_NORMAL_COLOR, _colorListener);
|
|
138 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.FONT_MAIN, _fontListener);
|
|
139 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.TEXT_ANTIALIAS, _antialiasListener);
|
|
140 |
38
| DrJava.getConfig().addOptionListener(OptionConstants.SHOW_SOURCE_WHEN_SWITCHING, _showSourceListener);
|
|
141 |
| } |
|
142 |
| |
|
143 |
38
| private void updateFontColor() {
|
|
144 |
38
| Font mainFont = DrJava.getConfig().getSetting(OptionConstants.FONT_MAIN);
|
|
145 |
38
| Color backColor = DrJava.getConfig().getSetting(OptionConstants.DEFINITIONS_BACKGROUND_COLOR);
|
|
146 |
38
| Color fontColor = DrJava.getConfig().getSetting(OptionConstants.DEFINITIONS_NORMAL_COLOR);
|
|
147 |
| |
|
148 |
38
| Font titleFont = mainFont.deriveFont((float) (mainFont.getSize() + 3));
|
|
149 |
38
| _antiAliasText = DrJava.getConfig().getSetting(OptionConstants.TEXT_ANTIALIAS).booleanValue();
|
|
150 |
| |
|
151 |
38
| _label.setForeground(fontColor);
|
|
152 |
38
| _panel.setBackground(backColor);
|
|
153 |
38
| _label.setFont(titleFont);
|
|
154 |
38
| _textpane.setForeground(fontColor);
|
|
155 |
38
| _textpane.setFont(mainFont);;
|
|
156 |
38
| _textpane.setBackground(backColor);
|
|
157 |
38
| _scroller.setBackground(backColor);
|
|
158 |
38
| _scroller.setBorder(new EmptyBorder(0,0,0,0));
|
|
159 |
38
| _panel.setBorder(new LineBorder(fontColor, 1));
|
|
160 |
| } |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
102
| public void pokeDocument(OpenDefinitionsDocument d) {
|
|
165 |
102
| if (_docs.contains(d)) {
|
|
166 |
14
| _current = _docs.indexOf(d);
|
|
167 |
14
| reset();
|
|
168 |
| } |
|
169 |
88
| else _docs.addFirst(d);
|
|
170 |
| } |
|
171 |
| |
|
172 |
| |
|
173 |
38
| public void closeDocument(OpenDefinitionsDocument d) { _docs.remove(d); }
|
|
174 |
| |
|
175 |
0
| private void show(int _current) {
|
|
176 |
0
| OpenDefinitionsDocument doc = _docs.get(_current);
|
|
177 |
| |
|
178 |
0
| String text = getTextFor(doc);
|
|
179 |
| |
|
180 |
0
| _label.setText(_displayManager.getName(doc));
|
|
181 |
0
| _label.setIcon(_displayManager.getIcon(doc));
|
|
182 |
| |
|
183 |
0
| if (text.length() > 0) {
|
|
184 |
| |
|
185 |
0
| _textpane.setText(text);
|
|
186 |
0
| _scroller.setPreferredSize(_textpane.getPreferredScrollableViewportSize());
|
|
187 |
0
| if (_scroller.getPreferredSize().getHeight() > 200)
|
|
188 |
0
| _scroller.setPreferredSize(new Dimension((int)_scroller.getPreferredSize().getWidth(), 200));
|
|
189 |
| |
|
190 |
0
| _scroller.setVisible(_showSource);
|
|
191 |
| } |
|
192 |
0
| else _scroller.setVisible(false);
|
|
193 |
| |
|
194 |
0
| Dimension d = _label.getMinimumSize();
|
|
195 |
0
| d.setSize(d.getWidth() + _padding*2, d.getHeight() + _padding*2);
|
|
196 |
0
| _label.setPreferredSize(d);
|
|
197 |
0
| _label.setHorizontalAlignment(SwingConstants.CENTER);
|
|
198 |
0
| _label.setVerticalAlignment(SwingConstants.CENTER);
|
|
199 |
0
| pack();
|
|
200 |
0
| centerH();
|
|
201 |
| } |
|
202 |
| |
|
203 |
| |
|
204 |
0
| public void next() {
|
|
205 |
0
| if (_docs.size() > 0) {
|
|
206 |
0
| _current++;
|
|
207 |
0
| if (_current >= _docs.size()) _current = 0;
|
|
208 |
0
| show(_current);
|
|
209 |
| } |
|
210 |
| } |
|
211 |
| |
|
212 |
| |
|
213 |
0
| public void prev() {
|
|
214 |
0
| if (_docs.size() > 0) {
|
|
215 |
0
| _current--;
|
|
216 |
0
| if (_current < 0) _current = _docs.size() - 1;
|
|
217 |
0
| show(_current);
|
|
218 |
| } |
|
219 |
| } |
|
220 |
| |
|
221 |
0
| private String getTextFor(OpenDefinitionsDocument doc) {
|
|
222 |
0
| DefinitionsPane pane = _frame.getDefPaneGivenODD(doc);
|
|
223 |
0
| String endl = "\n";
|
|
224 |
0
| int loc = pane.getCaretPosition();
|
|
225 |
0
| int start = loc;
|
|
226 |
0
| int end = loc;
|
|
227 |
0
| String text;
|
|
228 |
0
| text = doc.getText();
|
|
229 |
| |
|
230 |
| |
|
231 |
0
| for (int i = 0; i < 4; i++) {
|
|
232 |
0
| if (start > 0) start = text.lastIndexOf(endl, start-endl.length());
|
|
233 |
| } |
|
234 |
0
| if (start == -1) start = 0;
|
|
235 |
| |
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
0
| if (doc.getLength() >= endl.length() && text.substring(start, start+endl.length()).equals(endl))
|
|
240 |
0
| start += endl.length();
|
|
241 |
| |
|
242 |
0
| int index;
|
|
243 |
0
| for (int i = 0; i < 4; i++) {
|
|
244 |
0
| if (end < doc.getLength()) {
|
|
245 |
0
| index = text.indexOf(endl, end + endl.length());
|
|
246 |
0
| if (index != -1) end = index;
|
|
247 |
| } |
|
248 |
| } |
|
249 |
0
| if (end < start) end = start;
|
|
250 |
0
| text = text.substring(start, end);
|
|
251 |
0
| return text;
|
|
252 |
| } |
|
253 |
| |
|
254 |
| |
|
255 |
0
| public void first() {
|
|
256 |
0
| _current = 0;
|
|
257 |
0
| next();
|
|
258 |
| } |
|
259 |
| |
|
260 |
0
| public void refreshColor() { }
|
|
261 |
| |
|
262 |
| |
|
263 |
0
| public void setVisible(boolean v) {
|
|
264 |
0
| centerH();
|
|
265 |
0
| if (_docs.size() > 0) {
|
|
266 |
0
| if (v) {
|
|
267 |
0
| centerV();
|
|
268 |
0
| refreshColor();
|
|
269 |
0
| first();
|
|
270 |
| } |
|
271 |
0
| else reset();
|
|
272 |
0
| super.setVisible(v);
|
|
273 |
| } |
|
274 |
| } |
|
275 |
| |
|
276 |
| |
|
277 |
0
| private void centerH() { Utilities.setPopupLoc(this, _frame); }
|
|
278 |
| |
|
279 |
| |
|
280 |
0
| private void centerV() {
|
|
281 |
0
| Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
282 |
0
| Dimension frameSize = getSize();
|
|
283 |
0
| setLocation((int)getLocation().getX(), (screenSize.height - frameSize.height) / 2);
|
|
284 |
| } |
|
285 |
| |
|
286 |
| |
|
287 |
14
| public void reset() {
|
|
288 |
14
| if (_current < _docs.size()) _docs.addFirst(_docs.remove(_current));
|
|
289 |
| } |
|
290 |
| |
|
291 |
| |
|
292 |
0
| public OpenDefinitionsDocument getDocument() {
|
|
293 |
0
| if (_docs.size() > 0) return _docs.getFirst();
|
|
294 |
0
| return null;
|
|
295 |
| } |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| } |