1 19 27 28 package org.netbeans.modules.xml.nbprefuse; 29 30 import java.awt.Cursor ; 31 import java.awt.event.MouseEvent ; 32 import java.awt.geom.Point2D ; 33 import java.util.Iterator ; 34 import javax.swing.SwingUtilities ; 35 import prefuse.Display; 36 import prefuse.controls.ControlAdapter; 37 import prefuse.visual.AggregateItem; 38 import prefuse.visual.VisualItem; 39 40 44 47 public class AggregateDragControl extends ControlAdapter { 48 49 private VisualItem activeItem; 50 protected Point2D down = new Point2D.Double (); 51 protected Point2D temp = new Point2D.Double (); 52 protected boolean dragged; 53 54 58 public AggregateDragControl() { 59 } 60 61 64 public void itemEntered(VisualItem item, MouseEvent e) { 65 Display d = (Display)e.getSource(); 66 d.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 67 activeItem = item; 68 if ( !(item instanceof AggregateItem) ) 69 setFixed(item, true); 70 } 71 72 75 public void itemExited(VisualItem item, MouseEvent e) { 76 if ( activeItem == item ) { 77 activeItem = null; 78 setFixed(item, false); 79 } 80 Display d = (Display)e.getSource(); 81 d.setCursor(Cursor.getDefaultCursor()); 82 } 83 84 87 public void itemPressed(VisualItem item, MouseEvent e) { 88 if (!SwingUtilities.isLeftMouseButton(e)) return; 89 dragged = false; 90 Display d = (Display)e.getComponent(); 91 d.getAbsoluteCoordinate(e.getPoint(), down); 92 if ( item instanceof AggregateItem ) 93 setFixed(item, true); 94 } 95 96 99 public void itemReleased(VisualItem item, MouseEvent e) { 100 if (!SwingUtilities.isLeftMouseButton(e)) return; 101 if ( dragged ) { 102 activeItem = null; 103 setFixed(item, false); 104 dragged = false; 105 item.getVisualization().run(AnalysisConstants.ACTION_UPDATE_AGGREGATE_LAYOUT_REPAINT); 106 } 107 } 108 109 112 public void itemDragged(VisualItem item, MouseEvent e) { 113 if (!SwingUtilities.isLeftMouseButton(e)) return; 114 dragged = true; 115 Display d = (Display)e.getComponent(); 116 d.getAbsoluteCoordinate(e.getPoint(), temp); 117 double dx = temp.getX()-down.getX(); 118 double dy = temp.getY()-down.getY(); 119 120 move(item, dx, dy); 121 122 down.setLocation(temp); 123 item.getVisualization().run(AnalysisConstants.ACTION_UPDATE_AGGREGATE_LAYOUT_REPAINT); 124 } 125 126 protected static void setFixed(VisualItem item, boolean fixed) { 127 if ( item instanceof AggregateItem ) { 128 Iterator items = ((AggregateItem)item).items(); 129 while ( items.hasNext() ) { 130 setFixed((VisualItem)items.next(), fixed); 131 } 132 } else { 133 item.setFixed(fixed); 134 } 135 } 136 137 protected static void move(VisualItem item, double dx, double dy) { 138 if ( item instanceof AggregateItem ) { 139 Iterator items = ((AggregateItem)item).items(); 140 while ( items.hasNext() ) { 141 move((VisualItem)items.next(), dx, dy); 142 } 143 } else { 144 double x = item.getX(); 145 double y = item.getY(); 146 item.setStartX(x); item.setStartY(y); 147 item.setX(x+dx); item.setY(y+dy); 148 item.setEndX(x+dx); item.setEndY(y+dy); 149 } 150 } 151 152 } | Popular Tags |