|
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 java.awt.event.*; |
|
40 |
| import java.awt.*; |
|
41 |
| import java.io.IOException; |
|
42 |
| import java.io.File; |
|
43 |
| import java.util.ArrayList; |
|
44 |
| import java.util.Map; |
|
45 |
| import java.util.HashMap; |
|
46 |
| import javax.swing.*; |
|
47 |
| import javax.swing.event.*; |
|
48 |
| import javax.swing.border.EmptyBorder; |
|
49 |
| |
|
50 |
| import edu.rice.cs.drjava.model.SingleDisplayModel; |
|
51 |
| import edu.rice.cs.drjava.config.OptionParser; |
|
52 |
| import edu.rice.cs.drjava.config.StringOption; |
|
53 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
54 |
| import edu.rice.cs.drjava.ui.config.*; |
|
55 |
| |
|
56 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
57 |
| import edu.rice.cs.plt.collect.CollectUtil; |
|
58 |
| import edu.rice.cs.plt.lambda.Runnable1; |
|
59 |
| import edu.rice.cs.plt.lambda.LambdaUtil; |
|
60 |
| import edu.rice.cs.plt.concurrent.CompletionMonitor; |
|
61 |
| |
|
62 |
| import edu.rice.cs.drjava.DrJava; |
|
63 |
| import edu.rice.cs.util.StringOps; |
|
64 |
| import edu.rice.cs.util.swing.SwingFrame; |
|
65 |
| import edu.rice.cs.util.swing.Utilities; |
|
66 |
| |
|
67 |
| import edu.rice.cs.drjava.ui.predictive.*; |
|
68 |
| import static edu.rice.cs.drjava.ui.predictive.PredictiveInputModel.*; |
|
69 |
| |
|
70 |
| |
|
71 |
| public class ProjectAdvancedPropertiesFrame extends SwingFrame { |
|
72 |
| |
|
73 |
| private static final int FRAME_WIDTH = 503; |
|
74 |
| private static final int FRAME_HEIGHT = 500; |
|
75 |
| |
|
76 |
| private MainFrame _mainFrame; |
|
77 |
| private SwingFrame _parentFrame; |
|
78 |
| private SingleDisplayModel _model; |
|
79 |
| private VectorOptionComponent<PreferencesRecord> _preferencesList; |
|
80 |
| private volatile Map<OptionParser<?>,String> _unmodifiedStoredPreferences = new HashMap<OptionParser<?>,String>(); |
|
81 |
| |
|
82 |
| protected static class PreferencesRecord implements Comparable<PreferencesRecord> { |
|
83 |
| public final OptionParser<?> option; |
|
84 |
| public final String shortDesc; |
|
85 |
| public final String longDesc; |
|
86 |
0
| public PreferencesRecord(OptionParser<?> o, String s, String l) {
|
|
87 |
0
| option = o;
|
|
88 |
0
| shortDesc = s;
|
|
89 |
0
| longDesc = StringOps.removeHTML(l);
|
|
90 |
| } |
|
91 |
0
| public int compareTo(PreferencesRecord other) {
|
|
92 |
0
| return option.getName().compareTo(other.option.getName());
|
|
93 |
| } |
|
94 |
0
| public boolean equals(Object other) {
|
|
95 |
0
| if (other == null || ! (other instanceof PreferencesRecord)) return false;
|
|
96 |
0
| PreferencesRecord o = (PreferencesRecord) other;
|
|
97 |
0
| return option.getName().equals(o.option.getName());
|
|
98 |
| } |
|
99 |
0
| public int hashCode() { return option.getName().hashCode(); }
|
|
100 |
0
| public String toString() { return shortDesc; }
|
|
101 |
| } |
|
102 |
| |
|
103 |
| public static final PredictiveInputModel<PreferencesRecord> STORED_PROPERTIES_PIM = |
|
104 |
| new PredictiveInputModel<PreferencesRecord>(true, new PredictiveInputModel.FragmentStrategy<PreferencesRecord>()); |
|
105 |
| |
|
106 |
| static { |
|
107 |
0
| ArrayList<PreferencesRecord> list = new ArrayList<PreferencesRecord>();
|
|
108 |
0
| for(Map.Entry<OptionParser<?>,String> e: edu.rice.cs.drjava.ui.config.ConfigDescriptions.CONFIG_DESCRIPTIONS.entrySet()) {
|
|
109 |
0
| OptionParser<?> o = e.getKey();
|
|
110 |
0
| String shortDesc = e.getValue();
|
|
111 |
0
| String longDesc = edu.rice.cs.drjava.ui.config.ConfigDescriptions.CONFIG_LONG_DESCRIPTIONS.get(o);
|
|
112 |
0
| list.add(new PreferencesRecord(o, shortDesc, longDesc));
|
|
113 |
| } |
|
114 |
0
| STORED_PROPERTIES_PIM.setItems(list.toArray(new PreferencesRecord[list.size()]));
|
|
115 |
| } |
|
116 |
| |
|
117 |
| private final JButton _okButton; |
|
118 |
| private final JButton _cancelButton; |
|
119 |
| |
|
120 |
| private JPanel _mainPanel; |
|
121 |
| |
|
122 |
| |
|
123 |
0
| public ProjectAdvancedPropertiesFrame(MainFrame mf, SwingFrame parentFrame) {
|
|
124 |
0
| super("Advanced Project Properties");
|
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
0
| _parentFrame = parentFrame;
|
|
129 |
0
| _mainFrame = mf;
|
|
130 |
0
| _model = _mainFrame.getModel();
|
|
131 |
0
| _mainPanel= new JPanel();
|
|
132 |
| |
|
133 |
0
| Action okAction = new AbstractAction("OK") {
|
|
134 |
0
| public void actionPerformed(ActionEvent e) {
|
|
135 |
| |
|
136 |
0
| boolean successful = true;
|
|
137 |
0
| ProjectAdvancedPropertiesFrame.this.setVisible(false);
|
|
138 |
| } |
|
139 |
| }; |
|
140 |
0
| _okButton = new JButton(okAction);
|
|
141 |
| |
|
142 |
0
| Action cancelAction = new AbstractAction("Cancel") {
|
|
143 |
0
| public void actionPerformed(ActionEvent e) { cancel(); }
|
|
144 |
| }; |
|
145 |
0
| _cancelButton = new JButton(cancelAction);
|
|
146 |
| |
|
147 |
0
| init();
|
|
148 |
0
| initDone();
|
|
149 |
| } |
|
150 |
| |
|
151 |
| |
|
152 |
0
| private void init() {
|
|
153 |
0
| _setupPanel(_mainPanel);
|
|
154 |
0
| JScrollPane scrollPane = new JScrollPane(_mainPanel);
|
|
155 |
0
| Container cp = getContentPane();
|
|
156 |
| |
|
157 |
0
| GridBagLayout cpLayout = new GridBagLayout();
|
|
158 |
0
| GridBagConstraints c = new GridBagConstraints();
|
|
159 |
0
| cp.setLayout(cpLayout);
|
|
160 |
| |
|
161 |
0
| c.fill = GridBagConstraints.BOTH;
|
|
162 |
0
| c.anchor = GridBagConstraints.NORTH;
|
|
163 |
0
| c.gridwidth = GridBagConstraints.REMAINDER;
|
|
164 |
0
| c.gridheight = GridBagConstraints.RELATIVE;
|
|
165 |
0
| c.weightx = 1.0;
|
|
166 |
0
| c.weighty = 1.0;
|
|
167 |
0
| cpLayout.setConstraints(scrollPane, c);
|
|
168 |
0
| cp.add(scrollPane);
|
|
169 |
| |
|
170 |
| |
|
171 |
0
| JPanel bottom = new JPanel();
|
|
172 |
0
| bottom.setBorder(new EmptyBorder(5,5,5,5));
|
|
173 |
0
| bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
|
|
174 |
0
| bottom.add(Box.createHorizontalGlue());
|
|
175 |
0
| bottom.add(_okButton);
|
|
176 |
0
| bottom.add(_cancelButton);
|
|
177 |
0
| bottom.add(Box.createHorizontalGlue());
|
|
178 |
| |
|
179 |
0
| c.fill = GridBagConstraints.NONE;
|
|
180 |
0
| c.anchor = GridBagConstraints.SOUTH;
|
|
181 |
0
| c.gridheight = GridBagConstraints.REMAINDER;
|
|
182 |
0
| c.weighty = 0.0;
|
|
183 |
0
| cpLayout.setConstraints(bottom, c);
|
|
184 |
0
| cp.add(bottom);
|
|
185 |
| |
|
186 |
| |
|
187 |
0
| Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
|
188 |
0
| if (dim.width>FRAME_WIDTH) { dim.width = FRAME_WIDTH; }
|
|
189 |
0
| else { dim.width -= 80; }
|
|
190 |
0
| if (dim.height>FRAME_HEIGHT) { dim.height = FRAME_HEIGHT; }
|
|
191 |
0
| else { dim.height -= 80; }
|
|
192 |
0
| setSize(dim);
|
|
193 |
0
| Utilities.setPopupLoc(this, _parentFrame);
|
|
194 |
| } |
|
195 |
| |
|
196 |
| |
|
197 |
0
| public void cancel() {
|
|
198 |
0
| reset();
|
|
199 |
0
| setVisible(false);
|
|
200 |
| } |
|
201 |
| |
|
202 |
0
| public void reset() {
|
|
203 |
0
| setPreferencesStoredInProject(_unmodifiedStoredPreferences);
|
|
204 |
| } |
|
205 |
| |
|
206 |
0
| public void reset(Map<OptionParser<?>,String> sp) {
|
|
207 |
0
| _unmodifiedStoredPreferences = new HashMap<OptionParser<?>,String>(sp);
|
|
208 |
0
| setPreferencesStoredInProject(_unmodifiedStoredPreferences);
|
|
209 |
| } |
|
210 |
| |
|
211 |
0
| @SuppressWarnings("unchecked")
|
|
212 |
| public Map<OptionParser<?>,String> getPreferencesStoredInProject() { |
|
213 |
0
| Map<OptionParser<?>,String> sp = new HashMap<OptionParser<?>,String>();
|
|
214 |
0
| for(PreferencesRecord pr: _preferencesList.getValue()) {
|
|
215 |
0
| sp.put(pr.option, DrJava.getConfig().getOptionMap().getString(pr.option));
|
|
216 |
| } |
|
217 |
0
| return sp;
|
|
218 |
| } |
|
219 |
| |
|
220 |
0
| @SuppressWarnings("unchecked")
|
|
221 |
| public void setPreferencesStoredInProject(Map<OptionParser<?>,String> sp) { |
|
222 |
0
| ArrayList<PreferencesRecord> list = new ArrayList<PreferencesRecord>();
|
|
223 |
0
| for(OptionParser<?> o: sp.keySet()) {
|
|
224 |
0
| list.add(new PreferencesRecord
|
|
225 |
| (o, |
|
226 |
| edu.rice.cs.drjava.ui.config.ConfigDescriptions.CONFIG_DESCRIPTIONS.get(o), |
|
227 |
| edu.rice.cs.drjava.ui.config.ConfigDescriptions.CONFIG_LONG_DESCRIPTIONS.get(o))); |
|
228 |
| } |
|
229 |
0
| _preferencesList.setValue(list);
|
|
230 |
| } |
|
231 |
| |
|
232 |
0
| private void _setupPanel(JPanel panel) {
|
|
233 |
0
| GridBagLayout gridbag = new GridBagLayout();
|
|
234 |
0
| GridBagConstraints c = new GridBagConstraints();
|
|
235 |
0
| panel.setLayout(gridbag);
|
|
236 |
0
| c.fill = GridBagConstraints.HORIZONTAL;
|
|
237 |
0
| Insets labelInsets = new Insets(5, 10, 0, 0);
|
|
238 |
0
| Insets compInsets = new Insets(5, 5, 0, 10);
|
|
239 |
| |
|
240 |
0
| c.weightx = 0.0;
|
|
241 |
0
| c.gridwidth = GridBagConstraints.REMAINDER;
|
|
242 |
0
| c.insets = labelInsets;
|
|
243 |
| |
|
244 |
0
| JLabel descriptionLabel = new JLabel("<html>The current values of the preferences listed here will be<br>"+
|
|
245 |
| "stored in the project file when the project is saved and<br>"+ |
|
246 |
| " restored when the project is loaded again.<br>"+ |
|
247 |
| "Note that the previous values of preferences stored in a project<br>"+ |
|
248 |
| "file will be overwritten when a project is loaded.<br> </html>"); |
|
249 |
0
| gridbag.setConstraints(descriptionLabel, c);
|
|
250 |
0
| panel.add(descriptionLabel);
|
|
251 |
| |
|
252 |
0
| c.weightx = 0.0;
|
|
253 |
0
| c.gridwidth = 1;
|
|
254 |
0
| c.insets = labelInsets;
|
|
255 |
| |
|
256 |
0
| JLabel preferencesLabel = new JLabel("Stored Preferences");
|
|
257 |
0
| preferencesLabel.setToolTipText("<html>The list of preferences that are stored and restored with the project.</html>");
|
|
258 |
0
| gridbag.setConstraints(preferencesLabel, c);
|
|
259 |
0
| panel.add(preferencesLabel);
|
|
260 |
| |
|
261 |
0
| c.weightx = 1.0;
|
|
262 |
0
| c.gridwidth = GridBagConstraints.REMAINDER;
|
|
263 |
0
| c.insets = compInsets;
|
|
264 |
| |
|
265 |
0
| Component preferencesComponent = _preferencesComponent();
|
|
266 |
0
| gridbag.setConstraints(preferencesComponent, c);
|
|
267 |
0
| panel.add(preferencesComponent);
|
|
268 |
| |
|
269 |
0
| c.weightx = 0.0;
|
|
270 |
0
| c.gridwidth = GridBagConstraints.REMAINDER;
|
|
271 |
0
| c.insets = labelInsets;
|
|
272 |
| |
|
273 |
0
| descriptionLabel = new JLabel("<html>To change the preferences, please use the 'Preferences' window<br>"+
|
|
274 |
| "in the 'Edit' menu.</html>"); |
|
275 |
0
| gridbag.setConstraints(descriptionLabel, c);
|
|
276 |
0
| panel.add(descriptionLabel);
|
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
| |
|
281 |
| |
|
282 |
| |
|
283 |
| |
|
284 |
| |
|
285 |
| |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
| |
|
294 |
| |
|
295 |
| |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| } |
|
300 |
| |
|
301 |
0
| public Component _preferencesComponent() {
|
|
302 |
0
| _preferencesList = new VectorOptionComponent<PreferencesRecord>
|
|
303 |
| (null, "Stored Preferences", this, new String[0], |
|
304 |
| "The list of preferences that are stored and restored with the project.",false) { |
|
305 |
0
| protected Action _getAddAction() {
|
|
306 |
0
| return new AbstractAction("Add") {
|
|
307 |
0
| public void actionPerformed(ActionEvent ae) {
|
|
308 |
0
| _mainFrame.removeModalWindowAdapter(ProjectAdvancedPropertiesFrame.this);
|
|
309 |
0
| chooseString();
|
|
310 |
| } |
|
311 |
| }; |
|
312 |
| } |
|
313 |
0
| public void chooseString() {
|
|
314 |
0
| new Thread() {
|
|
315 |
0
| public void run() {
|
|
316 |
0
| final CompletionMonitor cm = new CompletionMonitor();
|
|
317 |
| |
|
318 |
0
| PredictiveInputFrame.InfoSupplier<PreferencesRecord> info =
|
|
319 |
| new PredictiveInputFrame.InfoSupplier<PreferencesRecord>() { |
|
320 |
0
| public String value(PreferencesRecord entry) {
|
|
321 |
0
| return entry.longDesc;
|
|
322 |
| } |
|
323 |
| }; |
|
324 |
0
| PredictiveInputFrame.CloseAction<PreferencesRecord> okAction =
|
|
325 |
| new PredictiveInputFrame.CloseAction<PreferencesRecord>() { |
|
326 |
0
| public String getName() { return "OK"; }
|
|
327 |
0
| public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); }
|
|
328 |
0
| public String getToolTipText() { return null; }
|
|
329 |
0
| public Object value(PredictiveInputFrame<PreferencesRecord> p) {
|
|
330 |
0
| if (p.getItem() != null) {
|
|
331 |
0
| _addValue(p.getItem());
|
|
332 |
| } |
|
333 |
0
| cm.signal();
|
|
334 |
0
| return null;
|
|
335 |
| } |
|
336 |
| }; |
|
337 |
0
| PredictiveInputFrame.CloseAction<PreferencesRecord> cancelAction =
|
|
338 |
| new PredictiveInputFrame.CloseAction<PreferencesRecord>() { |
|
339 |
0
| public String getName() { return "Cancel"; }
|
|
340 |
0
| public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); }
|
|
341 |
0
| public String getToolTipText() { return null; }
|
|
342 |
0
| public Object value(PredictiveInputFrame<PreferencesRecord> p) {
|
|
343 |
0
| cm.signal();
|
|
344 |
0
| return null;
|
|
345 |
| } |
|
346 |
| }; |
|
347 |
| |
|
348 |
0
| ArrayList<MatchingStrategy<PreferencesRecord>> strategies =
|
|
349 |
| new ArrayList<MatchingStrategy<PreferencesRecord>>(); |
|
350 |
0
| strategies.add(new FragmentStrategy<PreferencesRecord>());
|
|
351 |
0
| strategies.add(new PrefixStrategy<PreferencesRecord>());
|
|
352 |
0
| strategies.add(new RegExStrategy<PreferencesRecord>());
|
|
353 |
0
| ArrayList<PredictiveInputFrame.CloseAction<PreferencesRecord>> actions
|
|
354 |
| = new ArrayList<PredictiveInputFrame.CloseAction<PreferencesRecord>>(); |
|
355 |
0
| actions.add(okAction);
|
|
356 |
0
| actions.add(cancelAction);
|
|
357 |
0
| final PredictiveInputFrame<PreferencesRecord> pif = new PredictiveInputFrame<PreferencesRecord>
|
|
358 |
| (ProjectAdvancedPropertiesFrame.this, |
|
359 |
| "Preferences Stored with Project", |
|
360 |
| true, |
|
361 |
| true, |
|
362 |
| info, |
|
363 |
| strategies, |
|
364 |
| actions, 1, |
|
365 |
| new PreferencesRecord(new StringOption("dummy","dummy"), "dummy", "dummy")); |
|
366 |
0
| pif.setModel(true, STORED_PROPERTIES_PIM);
|
|
367 |
0
| Utilities.invokeLater(new Runnable() {
|
|
368 |
0
| public void run() {
|
|
369 |
0
| pif.setVisible(true);
|
|
370 |
| } |
|
371 |
| }); |
|
372 |
0
| cm.attemptEnsureSignaled();
|
|
373 |
0
| Utilities.invokeLater(new Runnable() {
|
|
374 |
0
| public void run() {
|
|
375 |
0
| _mainFrame.installModalWindowAdapter(ProjectAdvancedPropertiesFrame.this, LambdaUtil.NO_OP, CANCEL);
|
|
376 |
| } |
|
377 |
| }); |
|
378 |
| } |
|
379 |
| }.start(); |
|
380 |
| } |
|
381 |
| }; |
|
382 |
0
| _preferencesList.setRows(15,15);
|
|
383 |
0
| return _preferencesList.getComponent();
|
|
384 |
| } |
|
385 |
| |
|
386 |
| |
|
387 |
| protected final Runnable1<WindowEvent> CANCEL = new Runnable1<WindowEvent>() { |
|
388 |
0
| public void run(WindowEvent e) { cancel(); }
|
|
389 |
| }; |
|
390 |
| |
|
391 |
| |
|
392 |
| |
|
393 |
| |
|
394 |
0
| public void setVisible(boolean vis) {
|
|
395 |
0
| assert EventQueue.isDispatchThread();
|
|
396 |
0
| validate();
|
|
397 |
0
| if (vis) {
|
|
398 |
0
| _mainFrame.hourglassOn();
|
|
399 |
0
| _mainFrame.installModalWindowAdapter(this, LambdaUtil.NO_OP, CANCEL);
|
|
400 |
0
| toFront();
|
|
401 |
| } |
|
402 |
| else { |
|
403 |
0
| _mainFrame.removeModalWindowAdapter(this);
|
|
404 |
0
| _mainFrame.hourglassOff();
|
|
405 |
0
| _parentFrame.toFront();
|
|
406 |
| } |
|
407 |
0
| super.setVisible(vis);
|
|
408 |
| } |
|
409 |
| } |