1 19 27 28 package org.netbeans.modules.xml.nbprefuse; 29 30 import java.awt.event.MouseEvent ; 31 import prefuse.Visualization; 32 import prefuse.controls.FocusControl; 33 import prefuse.data.tuple.TupleSet; 34 import prefuse.util.ui.UILib; 35 import prefuse.visual.NodeItem; 36 import prefuse.visual.VisualItem; 37 38 42 public class NbFocusControl extends FocusControl{ 43 44 private String group = Visualization.FOCUS_ITEMS; 45 protected SelectionMode selectionMode = SelectionMode.MULTIPLE; 46 47 public enum SelectionMode {SINGLE, MULTIPLE}; 48 49 53 public NbFocusControl() { 54 super(); 55 56 } 57 58 63 public NbFocusControl(String focusGroup) { 64 super(focusGroup); 65 } 66 67 73 public NbFocusControl(int clicks) { 74 super(clicks); 75 } 76 77 84 public NbFocusControl(String focusGroup, int clicks) { 85 super(focusGroup, clicks); 86 } 87 88 95 public NbFocusControl(int clicks, String act) { 96 super(clicks, act); 97 } 98 99 107 public NbFocusControl(String focusGroup, int clicks, String act) { 108 super(focusGroup, clicks, act); 109 } 110 111 112 115 public void itemClicked(VisualItem item, MouseEvent e) { 116 if ( UILib.isButtonPressed(e, button) && 117 e.getClickCount() == ccount ) { 118 Visualization vis = item.getVisualization(); 120 TupleSet ts = vis.getFocusGroup(group); 121 122 boolean ctrl = e.isControlDown(); 123 if ( !ctrl) { 124 curFocus = item; 125 ts.setTuple(item); 126 } else if ( ts.containsTuple(item) ) { 127 ts.removeTuple(item); 128 if (item instanceof NodeItem && 134 item.canSetBoolean(AnalysisConstants.MOUSEOVER)){ 135 item.setBoolean(AnalysisConstants.MOUSEOVER, false); 136 } 137 } else { 138 if (selectionMode == SelectionMode.MULTIPLE){ 139 ts.addTuple(item); 140 } else { 141 curFocus = item; 142 ts.setTuple(item); 143 } 144 } 145 runActivity(vis); 146 } 148 } 149 150 151 152 153 protected void runActivity(Visualization vis) { 154 if ( activity != null ) { 155 vis.run(activity); 156 } 157 } 158 159 public void setSelectionMode(SelectionMode mode){ 160 this.selectionMode = mode; 161 } 162 163 164 165 public SelectionMode getSelectionMode(){ 166 return this.selectionMode; 167 } 168 169 } 170 | Popular Tags |