1
- // The MIT License (MIT)
2
- //
3
- // Copyright (c) 2015, 2016 Arian Fornaris
4
- //
5
- // Permission is hereby granted, free of charge, to any person obtaining a
6
- // copy of this software and associated documentation files (the
7
- // "Software"), to deal in the Software without restriction, including
8
- // without limitation the rights to use, copy, modify, merge, publish,
9
- // distribute, sublicense, and/or sell copies of the Software, and to permit
10
- // persons to whom the Software is furnished to do so, subject to the
11
- // following conditions: The above copyright notice and this permission
12
- // notice shall be included in all copies or substantial portions of the
13
- // Software.
14
- //
15
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- package phasereditor .canvas .ui .editors ;
23
-
24
- import java .util .Arrays ;
25
- import java .util .List ;
26
-
27
- import javafx .geometry .Bounds ;
28
- import javafx .geometry .Point2D ;
29
- import javafx .scene .layout .Border ;
30
- import javafx .scene .layout .BorderStroke ;
31
- import javafx .scene .layout .BorderStrokeStyle ;
32
- import javafx .scene .layout .BorderWidths ;
33
- import javafx .scene .layout .Pane ;
34
- import javafx .scene .paint .Color ;
35
- import javafx .scene .shape .StrokeLineCap ;
36
- import javafx .scene .shape .StrokeLineJoin ;
37
- import javafx .scene .shape .StrokeType ;
38
- import phasereditor .canvas .core .GroupModel ;
39
- import phasereditor .canvas .ui .shapes .IObjectNode ;
40
-
41
- /**
42
- * @author arian
43
- *
44
- */
45
- @ SuppressWarnings ("boxing" )
46
- public class SelectionNode extends Pane {
47
-
48
- private static Border _borderSprite ;
49
- private static Border _borderGroup ;
50
-
51
- static {
52
- BorderWidths bw = new BorderWidths (1 );
53
-
54
- List <Double > dashed = Arrays .asList (5d , 2d );
55
- BorderStrokeStyle style1 = new BorderStrokeStyle (StrokeType .INSIDE , StrokeLineJoin .MITER , StrokeLineCap .BUTT ,
56
- 10 , 10 , dashed );
57
- BorderStrokeStyle style2 = new BorderStrokeStyle (StrokeType .INSIDE , StrokeLineJoin .MITER , StrokeLineCap .BUTT ,
58
- 10 , 0 , dashed );
59
-
60
- BorderStroke s1 = new BorderStroke (Color .WHITE , style1 , null , bw );
61
- BorderStroke s2 = new BorderStroke (Color .BLACK , style2 , null , bw );
62
- BorderStroke s3 = new BorderStroke (Color .BLACK , style2 , null , new BorderWidths (2 ));
63
-
64
- _borderSprite = new Border (s1 , s2 );
65
-
66
- _borderGroup = new Border (s1 , s3 );
67
- }
68
-
69
- private IObjectNode _objectNode ;
70
- protected Bounds _rect ;
71
- private ObjectCanvas _canvas ;
72
-
73
- public SelectionNode (ObjectCanvas canvas , IObjectNode inode , Bounds rect ) {
74
- _objectNode = inode ;
75
- _rect = rect ;
76
- _canvas = canvas ;
77
-
78
- updateFromZoomAndPanVariables ();
79
-
80
- setBorder (inode .getModel () instanceof GroupModel ? _borderGroup : _borderSprite );
81
- }
82
-
83
- public static final int HANDLER_SIZE = 10 ;
84
-
85
- public ObjectCanvas getCanvas () {
86
- return _canvas ;
87
- }
88
-
89
- public void setObjectNode (IObjectNode objectNode ) {
90
- _objectNode = objectNode ;
91
- }
92
-
93
- public void updateBounds (Bounds rect ) {
94
- _rect = rect ;
95
- updateFromZoomAndPanVariables ();
96
- }
97
-
98
- public void updateFromZoomAndPanVariables () {
99
- double scale = _canvas .getZoomBehavior ().getScale ();
100
-
101
- Point2D translate = _canvas .getZoomBehavior ().getTranslate ();
102
-
103
- double x = translate .getX () + _rect .getMinX () * scale ;
104
- double y = translate .getY () + _rect .getMinY () * scale ;
105
-
106
- double h = _rect .getHeight () * scale ;
107
- double w = _rect .getWidth () * scale ;
108
-
109
- relocate (x , y );
110
- setMinSize (w , h );
111
- setMaxSize (w , h );
112
-
113
- }
114
-
115
- public IObjectNode getObjectNode () {
116
- return _objectNode ;
117
- }
1
+ // The MIT License (MIT)
2
+ //
3
+ // Copyright (c) 2015, 2016 Arian Fornaris
4
+ //
5
+ // Permission is hereby granted, free of charge, to any person obtaining a
6
+ // copy of this software and associated documentation files (the
7
+ // "Software"), to deal in the Software without restriction, including
8
+ // without limitation the rights to use, copy, modify, merge, publish,
9
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
10
+ // persons to whom the Software is furnished to do so, subject to the
11
+ // following conditions: The above copyright notice and this permission
12
+ // notice shall be included in all copies or substantial portions of the
13
+ // Software.
14
+ //
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ package phasereditor .canvas .ui .editors ;
23
+
24
+ import javafx .geometry .Bounds ;
25
+ import javafx .geometry .Point2D ;
26
+ import javafx .scene .effect .DropShadow ;
27
+ import javafx .scene .layout .Border ;
28
+ import javafx .scene .layout .BorderStroke ;
29
+ import javafx .scene .layout .BorderStrokeStyle ;
30
+ import javafx .scene .layout .BorderWidths ;
31
+ import javafx .scene .layout .CornerRadii ;
32
+ import javafx .scene .layout .Pane ;
33
+ import javafx .scene .paint .Color ;
34
+ import phasereditor .canvas .ui .shapes .IObjectNode ;
35
+
36
+ /**
37
+ * @author arian
38
+ *
39
+ */
40
+ public class SelectionNode extends Pane {
41
+
42
+ // private static Border _borderSprite;
43
+ // private static Border _borderGroup;
44
+
45
+ // static {
46
+ // BorderWidths bw = new BorderWidths(1);
47
+ //
48
+ // List<Double> dashed = Arrays.asList(5d, 2d);
49
+ // BorderStrokeStyle style1 = new BorderStrokeStyle(StrokeType.INSIDE, StrokeLineJoin.MITER, StrokeLineCap.BUTT,
50
+ // 10, 10, dashed);
51
+ // BorderStrokeStyle style2 = new BorderStrokeStyle(StrokeType.INSIDE, StrokeLineJoin.MITER, StrokeLineCap.BUTT,
52
+ // 10, 0, dashed);
53
+ //
54
+ // BorderStroke s1 = new BorderStroke(Color.WHITE, style1, null, bw);
55
+ // BorderStroke s2 = new BorderStroke(Color.BLACK, style2, null, bw);
56
+ // BorderStroke s3 = new BorderStroke(Color.BLACK, style2, null, new BorderWidths(2));
57
+ //
58
+ // _borderSprite = new Border(s1, s2);
59
+ //
60
+ // _borderGroup = new Border(s1, s3);
61
+ // }
62
+
63
+ private IObjectNode _objectNode ;
64
+ protected Bounds _rect ;
65
+ private ObjectCanvas _canvas ;
66
+
67
+ public SelectionNode (ObjectCanvas canvas , IObjectNode inode , Bounds rect ) {
68
+ _objectNode = inode ;
69
+ _rect = rect ;
70
+ _canvas = canvas ;
71
+
72
+ updateFromZoomAndPanVariables ();
73
+
74
+ //setBorder(inode.getModel() instanceof GroupModel ? _borderGroup : _borderSprite);
75
+ setEffect (new DropShadow ());
76
+ setBorder (new Border (new BorderStroke (Color .GREENYELLOW , BorderStrokeStyle .SOLID , CornerRadii .EMPTY , new BorderWidths (2 ))));
77
+ }
78
+
79
+ public static final int HANDLER_SIZE = 10 ;
80
+
81
+ public ObjectCanvas getCanvas () {
82
+ return _canvas ;
83
+ }
84
+
85
+ public void setObjectNode (IObjectNode objectNode ) {
86
+ _objectNode = objectNode ;
87
+ }
88
+
89
+ public void updateBounds (Bounds rect ) {
90
+ _rect = rect ;
91
+ updateFromZoomAndPanVariables ();
92
+ }
93
+
94
+ public void updateFromZoomAndPanVariables () {
95
+ double scale = _canvas .getZoomBehavior ().getScale ();
96
+
97
+ Point2D translate = _canvas .getZoomBehavior ().getTranslate ();
98
+
99
+ double x = translate .getX () + _rect .getMinX () * scale ;
100
+ double y = translate .getY () + _rect .getMinY () * scale ;
101
+
102
+ double h = _rect .getHeight () * scale ;
103
+ double w = _rect .getWidth () * scale ;
104
+
105
+ relocate (x , y );
106
+ setMinSize (w , h );
107
+ setMaxSize (w , h );
108
+
109
+ }
110
+
111
+ public IObjectNode getObjectNode () {
112
+ return _objectNode ;
113
+ }
118
114
}
0 commit comments