Added
Link Here
|
1 |
/* |
2 |
* The contents of this file are subject to the terms of the Common Development |
3 |
* and Distribution License (the License). You may not use this file except in |
4 |
* compliance with the License. |
5 |
* |
6 |
* You can obtain a copy of the License at http://www.netbeans.org/cddl.html |
7 |
* or http://www.netbeans.org/cddl.txt. |
8 |
* |
9 |
* When distributing Covered Code, include this CDDL Header Notice in each file |
10 |
* and include the License file at http://www.netbeans.org/cddl.txt. |
11 |
* If applicable, add the following below the CDDL Header, with the fields |
12 |
* enclosed by brackets [] replaced by your own identifying information: |
13 |
* "Portions Copyrighted [year] [name of copyright owner]" |
14 |
* |
15 |
* The Original Software is NetBeans. The Initial Developer of the Original |
16 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun |
17 |
* Microsystems, Inc. All Rights Reserved. |
18 |
*/ |
19 |
package org.netbeans.modules.visual.anchor; |
20 |
|
21 |
import org.netbeans.api.visual.anchor.AnchorShape; |
22 |
|
23 |
import java.awt.*; |
24 |
import java.awt.geom.GeneralPath; |
25 |
|
26 |
/** |
27 |
* @author Antonio |
28 |
*/ |
29 |
public class ArrowAnchorShape implements AnchorShape { |
30 |
|
31 |
private static final Stroke STROKE = new BasicStroke (1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); |
32 |
|
33 |
private GeneralPath path; |
34 |
private int size; |
35 |
|
36 |
public ArrowAnchorShape (int degrees, int size) { |
37 |
this.size = size; |
38 |
path = new GeneralPath (); |
39 |
|
40 |
double radians = Math.PI * degrees / 360.0; |
41 |
double cos = Math.cos (radians); |
42 |
double sin = -size * Math.sqrt (1 - cos * cos); |
43 |
cos *= size; |
44 |
|
45 |
path.moveTo (0.0f, 0.0f); |
46 |
path.lineTo ((float) cos, (float) -sin); |
47 |
path.moveTo (0.0f, 0.0f); |
48 |
path.lineTo ((float) cos, (float) sin); |
49 |
} |
50 |
|
51 |
public boolean isLineOriented () { |
52 |
return true; |
53 |
} |
54 |
|
55 |
public int getRadius () { |
56 |
return size + 1; |
57 |
} |
58 |
|
59 |
public double getCutDistance () { |
60 |
return 0; |
61 |
} |
62 |
|
63 |
public void paint (Graphics2D graphics, boolean source) { |
64 |
Stroke previousStroke = graphics.getStroke (); |
65 |
graphics.setStroke (STROKE); |
66 |
graphics.draw (path); |
67 |
graphics.setStroke (previousStroke); |
68 |
} |
69 |
|
70 |
} |