1 package org.coach.tracing.server.viewer; 2 3 import java.util.*; 4 import javax.swing.*; 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.awt.geom.*; 8 import org.coach.tracing.api.InteractionPoint; import org.coach.tracing.server.EventRecord; 10 11 public class EventGui extends JComponent { 12 private final JPopupMenu popup; 13 private static Diagram view; 14 private static ScaleManager sm; 15 public final static int min_hsize = 10; 16 public final static int vspace_between = 2; 17 public final static int circle_diam = 10; 18 public final static Color normal_event_color = Color.white; 19 public final static Color oneway_event_color = Color.green; 20 public final static Color exception_event_color = Color.red; 21 public final static Color normal_border_color = Color.black; 22 public final static Color trail_border_color = Color.magenta; 23 24 private int position; 25 private Long eventKey; 26 private Dimension text_dimension; 27 private String opName; 28 private String objectName; 29 private boolean isOneway; 30 private boolean isException; 31 private boolean isReturn; 32 33 private static Stack pool = new Stack(); 34 35 public EventGui(Diagram v) { 36 super(); 37 if (view == null) { 38 view = v; 39 sm = ScaleManager.getScaleManager(); 40 } 41 popup = new JPopupMenu(); 42 JMenuItem menu1 = new JMenuItem("Colour causality chain for this Event"); 43 menu1.addActionListener(new ActionListener() { 44 public void actionPerformed(ActionEvent e) { 45 colour_actionPerformed(e); 46 } 47 }); 48 popup.add(menu1); 49 50 menu1 = new JMenuItem("Browse Event"); 51 menu1.addActionListener(new ActionListener() { 52 public void actionPerformed(ActionEvent e) { 53 browse_actionPerformed(e); 54 } 55 }); 56 popup.add(menu1); 57 58 addMouseListener(new java.awt.event.MouseAdapter () { 59 public void mousePressed(java.awt.event.MouseEvent e) { 60 if (e.isPopupTrigger()) { 61 popup.show(e.getComponent(), e.getX(), e.getY()); 62 } 63 } 64 public void mouseReleased(java.awt.event.MouseEvent e) { 65 if (e.isPopupTrigger()) { 66 popup.show(e.getComponent(), e.getX(), e.getY()); 67 } 68 } 69 }); 70 } 71 72 public static EventGui getEventGui(EventRecord e) { 73 EventGui m = null; 74 if (pool.isEmpty()) { 75 m = new EventGui(view); 76 } else { 77 m = (EventGui)pool.pop(); 78 } 79 m.setEvent(e); 80 return m; 81 } 82 83 public static void releaseEventGui(EventGui m) { 84 pool.push(m); 85 } 86 87 private void setEvent(EventRecord e) { 88 eventKey = e.key(); 89 opName = e.getOpName(); 90 objectName = IdentityNode.getObjectName(e.getIdentityKey()); 91 isException = e.isException(); 92 isOneway = e.isOneway(); 93 isReturn = e.isReturn(); 94 95 float scale = sm.getScale(); 96 text_dimension = sm.getStringDimension("" 97 , this); 98 text_dimension.width += 1; 99 text_dimension.height += 1; 100 setSize(Math.max(text_dimension.width, (int)(min_hsize * scale)) + 1, (int)(text_dimension.height + ((vspace_between + circle_diam) * scale))); 101 102 ToolTipManager.sharedInstance().registerComponent(this); 103 setToolTipText(opName); 104 } 105 106 public boolean isReturn() { 107 return isReturn; 108 } 109 110 public boolean isException() { 111 return isException; 112 } 113 114 public boolean isOneway() { 115 return isOneway; 116 } 117 118 public java.awt.Color getColor() { 119 return view.getColor(eventKey); 120 } 121 122 public String getOpName() { 123 return opName; 124 } 125 126 public String getObjectName() { 127 return objectName; 128 } 129 130 public void setPosition(int p) { 131 position = p; 132 } 133 134 public int getPosition() { 135 return position; 136 } 137 138 public Point getCenter() { 139 float scale = sm.getScale(); 140 return new Point((int)(getX() + (getWidth() / 2)), (int)(getY() + getHeight() - ((circle_diam * scale) / 2))); 141 } 142 143 public int getRadius() { 144 float scale = sm.getScale(); 145 return (int)(scale * circle_diam / 2); 146 } 147 148 public void paint(Graphics g) { 149 super.paint(g); 151 float scale = sm.getScale(); 152 Graphics2D g2 = (Graphics2D)g; 153 g2.setRenderingHints(sm.getHints()); 154 g2.setStroke(sm.getStroke()); 155 g2.setFont(sm.getFont()); 156 158 if (isException) { 159 g2.setColor(exception_event_color); 160 } else if (isOneway) { 161 g2.setColor(oneway_event_color); 162 } else { 163 g2.setColor(normal_event_color); 164 } 165 g2.fillOval((int)((getWidth() - (circle_diam * scale)) / 2), (int)(text_dimension.height + (vspace_between * scale)), (int)(circle_diam * scale), (int)(circle_diam * scale)); 166 BasicStroke s = sm.getStrokeCircle(); 168 169 if (isReturn) { 170 s = sm.getStrokeCircleDashed(); 171 } 172 g2.setStroke(s); 173 if (getColor() != null) { 174 g2.setColor(getColor()); 175 } else { 176 g2.setColor(normal_border_color); 177 } 178 g2.draw(new Ellipse2D.Float((int)((s.getLineWidth() + getWidth() - (circle_diam * scale)) / 2), (int)(text_dimension.height + (vspace_between * scale) + (s.getLineWidth() / 2)), (int)(circle_diam * scale) - (int)(s.getLineWidth()), (int)(circle_diam * scale) - (int)(s.getLineWidth()))); 179 } 180 181 public Long getEventKey() { 182 return eventKey; 183 } 184 185 public void colour_actionPerformed(ActionEvent e) { 186 view.colour_causality_chain(eventKey); 187 } 188 189 public void browse_actionPerformed(ActionEvent e) { 190 view.createEventBrowser(eventKey, getLocationOnScreen()); 191 } 192 } 193 | Popular Tags |