|
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.util.swing; |
|
38 |
| |
|
39 |
| import javax.swing.*; |
|
40 |
| import java.awt.*; |
|
41 |
| import java.awt.event.*; |
|
42 |
| import java.util.*; |
|
43 |
| |
|
44 |
| import javax.swing.table.AbstractTableModel; |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| public class ScrollableListSelectionDialog extends JDialog { |
|
67 |
| |
|
68 |
| |
|
69 |
| public enum SelectionState { |
|
70 |
| |
|
71 |
| SELECTED, |
|
72 |
| |
|
73 |
| UNSELECTED |
|
74 |
| }; |
|
75 |
| |
|
76 |
| |
|
77 |
| private static final int DEFAULT_WIDTH = 400; |
|
78 |
| |
|
79 |
| private static final int DEFAULT_HEIGHT = 450; |
|
80 |
| |
|
81 |
| |
|
82 |
| private static final double WIDTH_RATIO = .75; |
|
83 |
| |
|
84 |
| private static final double HEIGHT_RATIO = .50; |
|
85 |
| |
|
86 |
| |
|
87 |
| protected final JTable table; |
|
88 |
| |
|
89 |
| protected final AbstractTableModel tableModel; |
|
90 |
| |
|
91 |
| |
|
92 |
| private static final int NUM_COLUMNS = 2; |
|
93 |
| |
|
94 |
| private static final int CHECKBOXES_COLUMN_INDEX = 0; |
|
95 |
| |
|
96 |
| private static final int STRINGS_COLUMN_INDEX = 1; |
|
97 |
| |
|
98 |
| |
|
99 |
| protected final Vector<String> dataAsStrings; |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| protected final Vector<Boolean> selectedItems; |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
2
| public ScrollableListSelectionDialog(final Frame owner,
|
|
124 |
| final String dialogTitle, |
|
125 |
| final String leaderText, |
|
126 |
| final Collection<?> listItems, |
|
127 |
| final String itemDescription) { |
|
128 |
2
| this(owner, dialogTitle, leaderText, listItems, itemDescription, SelectionState.SELECTED, JOptionPane.PLAIN_MESSAGE);
|
|
129 |
| } |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
9
| public ScrollableListSelectionDialog(final Frame owner,
|
|
155 |
| final String dialogTitle, |
|
156 |
| final String leaderText, |
|
157 |
| final Collection<?> listItems, |
|
158 |
| final String itemDescription, |
|
159 |
| final SelectionState defaultSelection, |
|
160 |
| final int messageType) { |
|
161 |
9
| this(owner,
|
|
162 |
| dialogTitle, |
|
163 |
| leaderText, |
|
164 |
| listItems, |
|
165 |
| itemDescription, |
|
166 |
| defaultSelection, |
|
167 |
| messageType, |
|
168 |
| DEFAULT_WIDTH, |
|
169 |
| DEFAULT_HEIGHT, |
|
170 |
| null, |
|
171 |
| true); |
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
0
| public ScrollableListSelectionDialog(final Frame owner,
|
|
201 |
| final String dialogTitle, |
|
202 |
| final String leaderText, |
|
203 |
| final Collection<?> listItems, |
|
204 |
| final String itemDescription, |
|
205 |
| final SelectionState defaultSelection, |
|
206 |
| final int messageType, |
|
207 |
| final int width, |
|
208 |
| final int height, |
|
209 |
| final Icon icon) { |
|
210 |
0
| this(owner,
|
|
211 |
| dialogTitle, |
|
212 |
| leaderText, |
|
213 |
| listItems, |
|
214 |
| itemDescription, |
|
215 |
| defaultSelection, |
|
216 |
| messageType, |
|
217 |
| width, |
|
218 |
| height, |
|
219 |
| icon, |
|
220 |
| false); |
|
221 |
| } |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
| |
|
227 |
| |
|
228 |
| |
|
229 |
| |
|
230 |
| |
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
| |
|
235 |
| |
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
| |
|
240 |
| |
|
241 |
| |
|
242 |
| |
|
243 |
| |
|
244 |
| |
|
245 |
| |
|
246 |
| |
|
247 |
| |
|
248 |
| |
|
249 |
| |
|
250 |
| |
|
251 |
12
| private ScrollableListSelectionDialog(final Frame owner,
|
|
252 |
| final String dialogTitle, |
|
253 |
| final String leaderText, |
|
254 |
| final Collection<?> listItems, |
|
255 |
| final String itemDescription, |
|
256 |
| final SelectionState defaultSelection, |
|
257 |
| final int messageType, |
|
258 |
| final int width, |
|
259 |
| final int height, |
|
260 |
| final Icon icon, |
|
261 |
| final boolean fitToScreen) { |
|
262 |
12
| super(owner, dialogTitle, true);
|
|
263 |
| |
|
264 |
12
| if (!_isknownMessageType(messageType)) {
|
|
265 |
2
| throw new IllegalArgumentException("The message type \"" + messageType + "\" is unknown");
|
|
266 |
| } |
|
267 |
| |
|
268 |
10
| if (listItems == null) {
|
|
269 |
1
| throw new IllegalArgumentException("listItems cannot be null");
|
|
270 |
| } |
|
271 |
| |
|
272 |
| |
|
273 |
9
| JLabel dialogIconLabel = null;
|
|
274 |
9
| if (icon != null) {
|
|
275 |
| |
|
276 |
0
| dialogIconLabel = new JLabel(icon);
|
|
277 |
| } else { |
|
278 |
| |
|
279 |
9
| Icon messageIcon = _getIcon(messageType);
|
|
280 |
9
| if (messageIcon != null) {
|
|
281 |
4
| dialogIconLabel = new JLabel(messageIcon);
|
|
282 |
| } |
|
283 |
| } |
|
284 |
| |
|
285 |
9
| final JPanel leaderPanel = new JPanel();
|
|
286 |
9
| final JLabel leaderLabel = new JLabel(leaderText);
|
|
287 |
9
| leaderPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
|
|
288 |
9
| if (dialogIconLabel != null) {
|
|
289 |
4
| leaderPanel.add(dialogIconLabel);
|
|
290 |
| } |
|
291 |
9
| leaderPanel.add(leaderLabel);
|
|
292 |
| |
|
293 |
| |
|
294 |
| |
|
295 |
9
| dataAsStrings = new Vector<String>(listItems.size());
|
|
296 |
9
| for (Object obj : listItems) {
|
|
297 |
18
| if (obj != null) {
|
|
298 |
18
| final String objAsString = obj.toString();
|
|
299 |
18
| dataAsStrings.add(objAsString);
|
|
300 |
| } |
|
301 |
| } |
|
302 |
9
| dataAsStrings.trimToSize();
|
|
303 |
| |
|
304 |
9
| final int numItems = dataAsStrings.size();
|
|
305 |
| |
|
306 |
9
| selectedItems = new Vector<Boolean>(numItems);
|
|
307 |
9
| synchronized(selectedItems) {
|
|
308 |
9
| for (int i = 0; i < numItems; ++i) {
|
|
309 |
18
| selectedItems.add(i, defaultSelection == SelectionState.SELECTED);
|
|
310 |
| } |
|
311 |
9
| selectedItems.trimToSize();
|
|
312 |
| } |
|
313 |
9
| assert selectedItems.size() == dataAsStrings.size();
|
|
314 |
| |
|
315 |
9
| tableModel = new AbstractTableModel() {
|
|
316 |
| |
|
317 |
0
| public int getRowCount() {
|
|
318 |
0
| return numItems;
|
|
319 |
| } |
|
320 |
| |
|
321 |
| |
|
322 |
27
| public int getColumnCount() {
|
|
323 |
27
| return NUM_COLUMNS;
|
|
324 |
| } |
|
325 |
| |
|
326 |
| |
|
327 |
0
| public Object getValueAt(int row, int column) {
|
|
328 |
0
| if (column == CHECKBOXES_COLUMN_INDEX) {
|
|
329 |
0
| assert row >= 0;
|
|
330 |
0
| assert row < numItems;
|
|
331 |
0
| synchronized(selectedItems) { return selectedItems.get(row); }
|
|
332 |
0
| } else if (column == STRINGS_COLUMN_INDEX) {
|
|
333 |
0
| assert row >= 0;
|
|
334 |
0
| assert row < numItems;
|
|
335 |
0
| return dataAsStrings.get(row);
|
|
336 |
| } else { |
|
337 |
| assert false; |
|
338 |
0
| return null;
|
|
339 |
| } |
|
340 |
| } |
|
341 |
| |
|
342 |
18
| @Override
|
|
343 |
| public String getColumnName(int column) { |
|
344 |
18
| if (column == CHECKBOXES_COLUMN_INDEX) {
|
|
345 |
9
| return "";
|
|
346 |
9
| } else if (column == STRINGS_COLUMN_INDEX) {
|
|
347 |
9
| return itemDescription;
|
|
348 |
| } else { |
|
349 |
| assert false; |
|
350 |
0
| return "";
|
|
351 |
| } |
|
352 |
| } |
|
353 |
| |
|
354 |
0
| @Override
|
|
355 |
| public Class<?> getColumnClass(final int columnIndex) { |
|
356 |
0
| if (columnIndex == CHECKBOXES_COLUMN_INDEX) {
|
|
357 |
0
| return Boolean.class;
|
|
358 |
0
| } else if (columnIndex == STRINGS_COLUMN_INDEX) {
|
|
359 |
0
| return String.class;
|
|
360 |
| } else { |
|
361 |
| assert false; |
|
362 |
0
| return Object.class;
|
|
363 |
| } |
|
364 |
| } |
|
365 |
| |
|
366 |
0
| @Override
|
|
367 |
| public boolean isCellEditable(final int rowIndex, final int columnIndex) { |
|
368 |
0
| return columnIndex == CHECKBOXES_COLUMN_INDEX;
|
|
369 |
| } |
|
370 |
| |
|
371 |
0
| @Override
|
|
372 |
| public void setValueAt(final Object newValue, final int rowIndex, final int columnIndex) { |
|
373 |
0
| assert columnIndex == CHECKBOXES_COLUMN_INDEX;
|
|
374 |
0
| assert rowIndex >= 0;
|
|
375 |
0
| assert rowIndex < numItems;
|
|
376 |
0
| assert newValue instanceof Boolean;
|
|
377 |
| |
|
378 |
0
| final Boolean booleanValue = (Boolean)newValue;
|
|
379 |
| |
|
380 |
0
| synchronized(selectedItems) { selectedItems.set(rowIndex, booleanValue); }
|
|
381 |
| } |
|
382 |
| }; |
|
383 |
| |
|
384 |
9
| table = new JTable(tableModel);
|
|
385 |
| |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
| |
|
390 |
9
| table.addMouseListener(new MouseAdapter() {
|
|
391 |
0
| @Override
|
|
392 |
| public void mouseClicked(final MouseEvent e) { |
|
393 |
0
| final Point clickPoint = e.getPoint();
|
|
394 |
| |
|
395 |
0
| final int clickColumn = table.columnAtPoint(clickPoint);
|
|
396 |
| |
|
397 |
0
| if (clickColumn == STRINGS_COLUMN_INDEX) {
|
|
398 |
| |
|
399 |
| |
|
400 |
0
| final int clickRow = table.rowAtPoint(clickPoint);
|
|
401 |
| |
|
402 |
0
| if (clickRow >= 0 && clickRow < numItems) {
|
|
403 |
0
| synchronized(selectedItems) {
|
|
404 |
0
| final boolean currentValue = selectedItems.get(clickRow);
|
|
405 |
0
| final boolean newValue = !currentValue;
|
|
406 |
| |
|
407 |
0
| selectedItems.set(clickRow, newValue);
|
|
408 |
| |
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
| |
|
415 |
| |
|
416 |
| |
|
417 |
| |
|
418 |
| |
|
419 |
0
| tableModel.fireTableCellUpdated(clickRow, CHECKBOXES_COLUMN_INDEX);
|
|
420 |
| } |
|
421 |
| } |
|
422 |
| } |
|
423 |
| } |
|
424 |
| }); |
|
425 |
| |
|
426 |
| |
|
427 |
9
| table.getColumnModel().getColumn(CHECKBOXES_COLUMN_INDEX).setMinWidth(15);
|
|
428 |
9
| table.getColumnModel().getColumn(CHECKBOXES_COLUMN_INDEX).setMaxWidth(30);
|
|
429 |
9
| table.getColumnModel().getColumn(CHECKBOXES_COLUMN_INDEX).setPreferredWidth(20);
|
|
430 |
9
| table.getColumnModel().getColumn(CHECKBOXES_COLUMN_INDEX).sizeWidthToFit();
|
|
431 |
| |
|
432 |
| |
|
433 |
9
| final JScrollPane scrollPane = new JScrollPane(table);
|
|
434 |
| |
|
435 |
| |
|
436 |
9
| final JPanel selectButtonsPanel = new JPanel();
|
|
437 |
9
| selectButtonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
|
438 |
9
| _addSelectButtons(selectButtonsPanel);
|
|
439 |
| |
|
440 |
| |
|
441 |
9
| final JPanel buttonPanel = new JPanel();
|
|
442 |
9
| buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
|
443 |
| |
|
444 |
9
| _addButtons(buttonPanel);
|
|
445 |
| |
|
446 |
| |
|
447 |
| |
|
448 |
9
| final JPanel centerPanel = new JPanel();
|
|
449 |
9
| centerPanel.setLayout(new BorderLayout());
|
|
450 |
9
| centerPanel.add(selectButtonsPanel, BorderLayout.NORTH);
|
|
451 |
9
| centerPanel.add(scrollPane, BorderLayout.CENTER);
|
|
452 |
| |
|
453 |
| |
|
454 |
9
| final JPanel contentPanel = new JPanel();
|
|
455 |
9
| contentPanel.setLayout(new BorderLayout(10, 5));
|
|
456 |
9
| contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
|
|
457 |
| |
|
458 |
9
| contentPanel.add(leaderPanel, BorderLayout.NORTH);
|
|
459 |
9
| contentPanel.add(centerPanel, BorderLayout.CENTER);
|
|
460 |
9
| contentPanel.add(buttonPanel, BorderLayout.SOUTH);
|
|
461 |
| |
|
462 |
9
| getContentPane().add(contentPanel);
|
|
463 |
| |
|
464 |
| |
|
465 |
9
| final Dimension dialogSize = new Dimension();
|
|
466 |
| |
|
467 |
9
| if (fitToScreen) {
|
|
468 |
| |
|
469 |
9
| final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
470 |
9
| int screenBasedWidth = (int) (WIDTH_RATIO * screenSize.getWidth());
|
|
471 |
9
| int screenBasedHeight = (int) (HEIGHT_RATIO * screenSize.getHeight());
|
|
472 |
| |
|
473 |
9
| dialogSize.setSize(Math.max(DEFAULT_WIDTH, screenBasedWidth),
|
|
474 |
| Math.max(DEFAULT_HEIGHT, screenBasedHeight)); |
|
475 |
| } else { |
|
476 |
| |
|
477 |
0
| dialogSize.setSize(width, height);
|
|
478 |
| } |
|
479 |
| |
|
480 |
9
| setSize(dialogSize);
|
|
481 |
| } |
|
482 |
| |
|
483 |
| |
|
484 |
| |
|
485 |
| |
|
486 |
| |
|
487 |
| |
|
488 |
| |
|
489 |
21
| private boolean _isknownMessageType(final int messageType) {
|
|
490 |
21
| return messageType == JOptionPane.ERROR_MESSAGE ||
|
|
491 |
| messageType == JOptionPane.INFORMATION_MESSAGE || |
|
492 |
| messageType == JOptionPane.WARNING_MESSAGE || |
|
493 |
| messageType == JOptionPane.QUESTION_MESSAGE || |
|
494 |
| messageType == JOptionPane.PLAIN_MESSAGE; |
|
495 |
| } |
|
496 |
| |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
| |
|
502 |
| |
|
503 |
| |
|
504 |
9
| private Icon _getIcon(final int messageType) {
|
|
505 |
9
| assert _isknownMessageType(messageType);
|
|
506 |
| |
|
507 |
| |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
9
| if (messageType == JOptionPane.ERROR_MESSAGE) {
|
|
512 |
1
| return UIManager.getIcon("OptionPane.errorIcon");
|
|
513 |
8
| } else if (messageType == JOptionPane.INFORMATION_MESSAGE) {
|
|
514 |
1
| return UIManager.getIcon("OptionPane.informationIcon");
|
|
515 |
7
| } else if (messageType == JOptionPane.WARNING_MESSAGE) {
|
|
516 |
1
| return UIManager.getIcon("OptionPane.warningIcon");
|
|
517 |
6
| } else if (messageType == JOptionPane.QUESTION_MESSAGE) {
|
|
518 |
1
| return UIManager.getIcon("OptionPane.questionIcon");
|
|
519 |
5
| } else if (messageType == JOptionPane.PLAIN_MESSAGE) {
|
|
520 |
5
| return null;
|
|
521 |
| } else { |
|
522 |
| |
|
523 |
| assert false; |
|
524 |
| } |
|
525 |
| |
|
526 |
0
| return null;
|
|
527 |
| } |
|
528 |
| |
|
529 |
| |
|
530 |
| |
|
531 |
| |
|
532 |
| |
|
533 |
| |
|
534 |
9
| private void _addSelectButtons(final JPanel selectButtonsPanel) {
|
|
535 |
9
| final JButton selectAllButton = new JButton("Select All");
|
|
536 |
9
| edu.rice.cs.drjava.platform.PlatformFactory.ONLY.setMnemonic(selectAllButton,KeyEvent.VK_A);
|
|
537 |
9
| selectAllButton.addActionListener(new SelectAllNoneActionListener(SelectionState.SELECTED));
|
|
538 |
9
| selectButtonsPanel.add(selectAllButton);
|
|
539 |
| |
|
540 |
9
| final JButton selectNoneButton = new JButton("Select None");
|
|
541 |
9
| edu.rice.cs.drjava.platform.PlatformFactory.ONLY.setMnemonic(selectNoneButton,KeyEvent.VK_N);
|
|
542 |
9
| selectNoneButton.addActionListener(new SelectAllNoneActionListener(SelectionState.UNSELECTED));
|
|
543 |
9
| selectButtonsPanel.add(selectNoneButton);
|
|
544 |
| } |
|
545 |
| |
|
546 |
| |
|
547 |
| |
|
548 |
| |
|
549 |
| |
|
550 |
| |
|
551 |
| |
|
552 |
| |
|
553 |
| |
|
554 |
| |
|
555 |
| |
|
556 |
9
| protected void _addButtons(final JPanel buttonPanel) {
|
|
557 |
9
| final JButton okButton = new JButton("OK");
|
|
558 |
9
| okButton.addActionListener(new ActionListener() {
|
|
559 |
0
| public void actionPerformed(ActionEvent notUsed) {
|
|
560 |
0
| closeDialog();
|
|
561 |
| } |
|
562 |
| }); |
|
563 |
| |
|
564 |
9
| buttonPanel.add(okButton);
|
|
565 |
9
| getRootPane().setDefaultButton(okButton);
|
|
566 |
| } |
|
567 |
| |
|
568 |
| |
|
569 |
| |
|
570 |
| |
|
571 |
0
| public void showDialog() {
|
|
572 |
0
| pack();
|
|
573 |
0
| Utilities.setPopupLoc(this, getOwner());
|
|
574 |
0
| setVisible(true);
|
|
575 |
| } |
|
576 |
| |
|
577 |
| |
|
578 |
| |
|
579 |
| |
|
580 |
0
| protected void closeDialog() {
|
|
581 |
0
| setVisible(false);
|
|
582 |
| } |
|
583 |
| |
|
584 |
| |
|
585 |
| |
|
586 |
| |
|
587 |
| |
|
588 |
| |
|
589 |
| |
|
590 |
| |
|
591 |
| |
|
592 |
| |
|
593 |
| |
|
594 |
3
| public java.util.List<String> selectedItems() {
|
|
595 |
3
| final java.util.List<String> results = new ArrayList<String>();
|
|
596 |
| |
|
597 |
3
| synchronized(selectedItems) {
|
|
598 |
| |
|
599 |
| |
|
600 |
| |
|
601 |
3
| for (int i = 0; i < dataAsStrings.size(); ++i) {
|
|
602 |
6
| if (selectedItems.get(i)) {
|
|
603 |
4
| results.add(dataAsStrings.get(i));
|
|
604 |
| } |
|
605 |
| } |
|
606 |
| } |
|
607 |
| |
|
608 |
3
| return Collections.unmodifiableList(results);
|
|
609 |
| } |
|
610 |
| |
|
611 |
| |
|
612 |
| |
|
613 |
| |
|
614 |
| |
|
615 |
| private class SelectAllNoneActionListener implements ActionListener { |
|
616 |
| |
|
617 |
| |
|
618 |
| private final boolean _setToValue; |
|
619 |
| |
|
620 |
| |
|
621 |
| |
|
622 |
| |
|
623 |
| |
|
624 |
| |
|
625 |
| |
|
626 |
18
| public SelectAllNoneActionListener(SelectionState setToState) {
|
|
627 |
18
| _setToValue = setToState == SelectionState.SELECTED;
|
|
628 |
| } |
|
629 |
| |
|
630 |
| |
|
631 |
| |
|
632 |
| |
|
633 |
| |
|
634 |
| |
|
635 |
| |
|
636 |
| |
|
637 |
0
| public void actionPerformed(ActionEvent notUsed) {
|
|
638 |
| |
|
639 |
| |
|
640 |
| |
|
641 |
0
| synchronized(selectedItems) {
|
|
642 |
0
| for (int i = 0; i < selectedItems.size(); ++i) {
|
|
643 |
0
| selectedItems.set(i, _setToValue);
|
|
644 |
| } |
|
645 |
0
| tableModel.fireTableRowsUpdated(0, Math.max(0, selectedItems.size() - 1));
|
|
646 |
| } |
|
647 |
| } |
|
648 |
| } |
|
649 |
| |
|
650 |
| |
|
651 |
| |
|
652 |
| |
|
653 |
| |
|
654 |
0
| public static void main(String args[]) {
|
|
655 |
0
| final Collection<String> data = new java.util.ArrayList<String>();
|
|
656 |
0
| data.add("how");
|
|
657 |
0
| data.add("now");
|
|
658 |
0
| data.add("brown");
|
|
659 |
0
| data.add("cow");
|
|
660 |
| |
|
661 |
0
| EventQueue.invokeLater(new Runnable() {
|
|
662 |
0
| public void run() {
|
|
663 |
0
| ScrollableListSelectionDialog ld =
|
|
664 |
| new ScrollableListSelectionDialog(null, "TITLE", "LEADER", data, "Words", SelectionState.SELECTED, |
|
665 |
| JOptionPane.ERROR_MESSAGE) { |
|
666 |
0
| @Override
|
|
667 |
| protected void closeDialog() { |
|
668 |
0
| super.closeDialog();
|
|
669 |
0
| Collection<String> si = selectedItems();
|
|
670 |
0
| for (String i : si) {
|
|
671 |
0
| System.out.println(i);
|
|
672 |
| } |
|
673 |
| } |
|
674 |
| }; |
|
675 |
0
| ld.pack();
|
|
676 |
0
| ld.setVisible(true);
|
|
677 |
| } |
|
678 |
| }); |
|
679 |
| } |
|
680 |
| } |