Mercurial > hg > graal-compiler
annotate src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/DiagramConnectionWidget.java @ 1552:c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair
author | trims |
---|---|
date | Thu, 27 May 2010 19:08:38 -0700 |
parents | 30369db7f5d2 |
children |
rev | line source |
---|---|
220 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
220
diff
changeset
|
2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
220 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
220
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
220
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
220
diff
changeset
|
21 * questions. |
220 | 22 * |
23 */ | |
24 package com.sun.hotspot.igv.view.widgets; | |
25 | |
26 import com.sun.hotspot.igv.graph.Connection; | |
27 import com.sun.hotspot.igv.graph.Figure; | |
28 import com.sun.hotspot.igv.view.DiagramScene; | |
29 import java.awt.BasicStroke; | |
30 import java.awt.Color; | |
31 import java.awt.Composite; | |
32 import java.awt.Graphics2D; | |
33 import java.awt.Point; | |
34 import java.awt.Rectangle; | |
35 import java.awt.Stroke; | |
36 import java.util.ArrayList; | |
37 import java.util.List; | |
38 import org.netbeans.api.visual.anchor.AnchorShape; | |
39 import org.netbeans.api.visual.model.ObjectState; | |
40 import org.netbeans.api.visual.widget.ConnectionWidget; | |
41 import org.netbeans.api.visual.widget.Scene; | |
42 | |
43 /** | |
44 * | |
45 * @author Thomas Wuerthinger | |
46 */ | |
47 public class DiagramConnectionWidget extends ConnectionWidget { | |
48 | |
49 private static Stroke DASHED_STROKE = new BasicStroke( | |
50 1, | |
51 BasicStroke.CAP_BUTT, | |
52 BasicStroke.JOIN_ROUND, | |
53 0, | |
54 new float[]{2}, | |
55 0); | |
56 private static Stroke NORMAL_STROKE = new BasicStroke(1); | |
57 private static Stroke BOLD_STROKE = new BasicStroke(3); | |
58 public static int WHITE_FACTOR = 5; | |
59 private Connection connection; | |
60 private Color color; | |
61 private Point lastSourceAnchor; | |
62 private Point lastTargetAnchor; | |
63 private List<Point> controlPoints; | |
64 private Rectangle clientArea; | |
65 private boolean split; | |
66 private int[] xPoints; | |
67 private int[] yPoints; | |
68 private int pointCount; | |
69 | |
70 /** Creates a new instance of ConnectionWidget */ | |
71 public DiagramConnectionWidget(Connection connection, Scene scene) { | |
72 super(scene); | |
73 this.connection = connection; | |
74 color = connection.getColor(); | |
75 if (connection.getStyle() == Connection.ConnectionStyle.DASHED) { | |
76 this.setStroke(DASHED_STROKE); | |
77 } else if (connection.getStyle() == Connection.ConnectionStyle.BOLD) { | |
78 this.setStroke(BOLD_STROKE); | |
79 } else { | |
80 this.setStroke(NORMAL_STROKE); | |
81 } | |
82 this.setCheckClipping(true); | |
83 clientArea = new Rectangle(); | |
84 updateControlPoints(); | |
85 } | |
86 | |
87 public Connection getConnection() { | |
88 return connection; | |
89 } | |
90 | |
91 public void updateControlPoints() { | |
92 List<Point> newControlPoints = connection.getControlPoints(); | |
93 Connection c = connection; | |
94 Figure f = c.getInputSlot().getFigure(); | |
95 Point p = new Point(f.getPosition()); | |
96 p.translate(c.getInputSlot().getRelativePosition().x, f.getSize().height / 2); | |
97 Point p4 = new Point(f.getPosition()); | |
98 p4.translate(c.getInputSlot().getRelativePosition().x, c.getInputSlot().getRelativePosition().y); | |
99 | |
100 Figure f2 = c.getOutputSlot().getFigure(); | |
101 Point p2 = new Point(f2.getPosition()); | |
102 p2.translate(c.getOutputSlot().getRelativePosition().x, f2.getSize().height / 2); | |
103 Point p3 = new Point(f2.getPosition()); | |
104 p3.translate(c.getOutputSlot().getRelativePosition().x, c.getOutputSlot().getRelativePosition().y); | |
105 | |
106 /*if(controlPoints.size() >= 2) { | |
107 String className = Preferences.userNodeForPackage(PreferenceConstants.class).get(PreferenceConstants.KEY_LINE_GENERATOR, PreferenceConstants.DEFAULT_LINE_GENERATOR); | |
108 try { | |
109 LineGenerator lg = (LineGenerator)Class.forName(className).newInstance(); | |
110 controlPoints = lg.createLine(controlPoints, p2, p); | |
111 } catch (InstantiationException ex) { | |
112 } catch (IllegalAccessException ex) { | |
113 } catch (ClassNotFoundException ex) { | |
114 } | |
115 }*/ | |
116 | |
117 this.controlPoints = newControlPoints; | |
118 pointCount = newControlPoints.size(); | |
119 xPoints = new int[pointCount]; | |
120 yPoints = new int[pointCount]; | |
121 int minX = Integer.MAX_VALUE; | |
122 int maxX = Integer.MIN_VALUE; | |
123 int minY = Integer.MAX_VALUE; | |
124 int maxY = Integer.MIN_VALUE; | |
125 split = false; | |
126 for (int i = 0; i < pointCount; i++) { | |
127 if (newControlPoints.get(i) == null) { | |
128 split = true; | |
129 } else { | |
130 int curX = newControlPoints.get(i).x; | |
131 int curY = newControlPoints.get(i).y; | |
132 this.xPoints[i] = curX; | |
133 this.yPoints[i] = curY; | |
134 minX = Math.min(minX, curX); | |
135 maxX = Math.max(maxX, curX); | |
136 minY = Math.min(minY, curY); | |
137 maxY = Math.max(maxY, curY); | |
138 } | |
139 } | |
140 | |
141 this.clientArea = new Rectangle(minX, minY, maxX - minX, maxY - minY); | |
142 } | |
143 | |
144 @Override | |
145 protected void paintWidget() { | |
146 Graphics2D g = this.getGraphics(); | |
147 | |
148 if (xPoints.length == 0 || Math.abs(xPoints[0] - xPoints[xPoints.length - 1]) > 2000) { | |
149 return; | |
150 } | |
151 | |
152 //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); | |
153 //g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); | |
154 //g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); | |
155 | |
156 DiagramScene ds = (DiagramScene) this.getScene(); | |
157 boolean shouldHide = false;//ds.getShouldHide(this); | |
158 | |
159 Composite oldComposite = null; | |
160 if (shouldHide) { | |
161 Color c = new Color(255 - (255 - color.getRed()) / WHITE_FACTOR, 255 - (255 - color.getGreen()) / WHITE_FACTOR, 255 - (255 - color.getBlue()) / WHITE_FACTOR); | |
162 g.setPaint(c); | |
163 } else { | |
164 g.setPaint(color); | |
165 } | |
166 | |
167 if (split) { | |
168 for (int i = 1; i < controlPoints.size(); i++) { | |
169 Point prev = controlPoints.get(i - 1); | |
170 Point cur = controlPoints.get(i); | |
171 if (cur == null || prev == null) { | |
172 continue; | |
173 } | |
174 | |
175 g.drawLine(prev.x, prev.y, cur.x, cur.y); | |
176 } | |
177 } else { | |
178 g.drawPolyline(xPoints, yPoints, pointCount); | |
179 } | |
180 | |
181 /*for(int i=0; i<xPoints.length; i++) { | |
182 int x = xPoints[i]; | |
183 int y = yPoints[i]; | |
184 g.fillOval(x - 2, y - 2, 4, 4); | |
185 }*/ | |
186 | |
187 if (xPoints.length >= 2) { | |
188 Graphics2D g2 = (Graphics2D) g.create(); | |
189 int xOff = xPoints[xPoints.length - 2] - xPoints[xPoints.length - 1]; | |
190 int yOff = yPoints[yPoints.length - 2] - yPoints[yPoints.length - 1]; | |
191 if (xOff == 0 && yOff == 0 && yPoints.length >= 3) { | |
192 xOff = xPoints[xPoints.length - 3] - xPoints[xPoints.length - 1]; | |
193 yOff = yPoints[yPoints.length - 3] - yPoints[yPoints.length - 1]; | |
194 } | |
195 g2.translate(xPoints[xPoints.length - 1], yPoints[yPoints.length - 1]); | |
196 g2.rotate(Math.atan2(yOff, xOff)); | |
197 | |
198 g2.scale(0.55, 0.80); | |
199 AnchorShape.TRIANGLE_FILLED.paint(g2, false); | |
200 } | |
201 } | |
202 | |
203 @Override | |
204 public void notifyStateChanged(ObjectState previousState, ObjectState state) { | |
205 | |
206 if (previousState.isHovered() != state.isHovered()) { | |
207 color = connection.getColor(); | |
208 if (state.isHovered()) { | |
209 this.setStroke(BOLD_STROKE); | |
210 } else { | |
211 this.setStroke(NORMAL_STROKE); | |
212 } | |
213 | |
214 if (state.isHovered()) { | |
215 this.setStroke(BOLD_STROKE); | |
216 } else { | |
217 this.setStroke(NORMAL_STROKE); | |
218 } | |
219 | |
220 repaint(); | |
221 } | |
222 super.notifyStateChanged(previousState, state); | |
223 } | |
224 | |
225 @Override | |
226 public List<Point> getControlPoints() { | |
227 if (split) { | |
228 ArrayList<Point> result = new ArrayList<Point>(); | |
229 for (Point p : controlPoints) { | |
230 if (p != null) { | |
231 result.add(p); | |
232 } | |
233 } | |
234 return result; | |
235 } else { | |
236 return controlPoints; | |
237 } | |
238 } | |
239 | |
240 @Override | |
241 public String toString() { | |
242 return "ConnectionWidget[" + connection + "]"; | |
243 } | |
244 | |
245 @Override | |
246 protected Rectangle calculateClientArea() { | |
247 Rectangle result = new Rectangle(clientArea); | |
248 result.grow(10, 10); | |
249 return result; | |
250 } | |
251 } |