1 package fr.ove.openmath.jome.ctrlview.bidim.selection;
2
3 import java.util.Vector;
4 import java.util.Enumeration;
5 import fr.ove.openmath.jome.ctrlview.bidim.Display;
6 import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
7 import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEventListener;
8
9
10 /***
11 * This class manages a list of selected elements.
12 *
13 * @author © 1998 DIRAT Laurent
14 * @version 1.0 30/06/98
15 */
16 public class SelectionManager implements SelectionEventListener {
17 /***
18 * The list of selected elements.
19 */
20 private Vector selected;
21
22 /***
23 * The constructor.
24 */
25 public SelectionManager() {
26 selected = new Vector();
27 }
28
29 /***
30 * Consumes (i.e. treats) the event received.
31 * @param selectionEvent the event to consume.
32 */
33 public void consumeSelectionEvent(SelectionEvent selectionEvent) {
34 switch (selectionEvent.getAction()) {
35 case SelectionEvent.PURGE :
36 selected.setSize(0);
37 selected.trimToSize();
38 break;
39 case SelectionEvent.REMOVE :
40 selected.removeElement(selectionEvent.getArgument());
41 break;
42 case SelectionEvent.ADD :
43 selected.addElement(selectionEvent.getArgument());
44 break;
45 case SelectionEvent.GET_SELECTION_SIZE :
46 selectionEvent.setArgument(new Integer(selected.size()));
47 break;
48 case SelectionEvent.GET_SELECTION :
49 selectionEvent.setArgument(selected.clone());
50 break;
51 case SelectionEvent.LIST :
52
53 System.out.println(" I've got "+ selected.size() + " selected elements");
54 for (Enumeration e = selected.elements(); e.hasMoreElements(); )
55 ((Display) e.nextElement()).whoAmI();
56 break;
57 }
58 }
59 }