1 6 7 package com.thoughtriver.open.vectorvisuals.ui; 8 9 import java.util.*; 10 11 import com.thoughtriver.open.vectorvisuals.*; 12 13 21 public class SelectionManager { 22 23 24 static private SelectionManager singleton = null; 25 26 32 static synchronized public SelectionManager getSharedInstance() { 33 34 if (singleton == null) { 35 singleton = new SelectionManager(); 36 } 37 38 return singleton; 39 } 40 41 42 private List<SelectionListener> listeners = null; 43 44 45 private VisualObject selection = null; 46 47 51 public SelectionManager() { 52 listeners = new LinkedList<SelectionListener>(); 53 } 54 55 61 public void addSelectionListener(final SelectionListener listener) { 62 listeners.add(listener); 63 } 64 65 71 public void removeSelectionListener(final SelectionListener listener) { 72 listeners.remove(listener); 73 } 74 75 84 synchronized public void setSelectedObject(final VisualObject obj) { 85 86 VisualObject oldSelection = getSelectedObject(); 87 VisualObject newSelection = obj; 88 89 if (oldSelection == newSelection) { 91 return; 92 } 93 boolean transition = ((oldSelection != null) && (newSelection != null)) ? true : false; 94 95 SelectionEvent event = null; 97 if (oldSelection != null) { 98 event = new SelectionEvent(oldSelection, false, transition); 99 100 for (SelectionListener listener : listeners) { 101 listener.selectionChanged(event); 102 } 103 } 104 selection = newSelection; 105 106 if (newSelection != null) { 108 event = new SelectionEvent(newSelection, true, transition); 109 for (SelectionListener listener : listeners) { 110 listener.selectionChanged(event); 111 } 112 } 113 114 } 115 116 121 public VisualObject getSelectedObject() { 122 return selection; 123 } 124 125 } 126 | Popular Tags |