fiore@0
|
1 /*
|
fiore@0
|
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
|
fiore@0
|
3
|
fiore@0
|
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
|
fiore@0
|
5
|
fiore@0
|
6 This program is free software: you can redistribute it and/or modify
|
fiore@0
|
7 it under the terms of the GNU General Public License as published by
|
fiore@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
fiore@0
|
9 (at your option) any later version.
|
fiore@0
|
10
|
fiore@0
|
11 This program is distributed in the hope that it will be useful,
|
fiore@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
fiore@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
fiore@0
|
14 GNU General Public License for more details.
|
fiore@0
|
15
|
fiore@0
|
16 You should have received a copy of the GNU General Public License
|
fiore@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
fiore@0
|
18 */
|
fiore@0
|
19
|
fiore@0
|
20 package uk.ac.qmul.eecs.ccmi.simpletemplate;
|
fiore@0
|
21
|
fiore@0
|
22 import java.awt.Shape;
|
fiore@0
|
23 import java.awt.geom.Point2D;
|
fiore@0
|
24 import java.awt.geom.Rectangle2D;
|
fiore@0
|
25 import java.io.InputStream;
|
fiore@0
|
26 import java.util.List;
|
fiore@0
|
27
|
fiore@0
|
28 import uk.ac.qmul.eecs.ccmi.diagrammodel.NodeProperties;
|
fiore@0
|
29 import uk.ac.qmul.eecs.ccmi.sound.SoundFactory;
|
fiore@0
|
30
|
fiore@0
|
31 /**
|
fiore@0
|
32 *
|
fiore@0
|
33 * A squared shaped diagram node.
|
fiore@0
|
34 *
|
fiore@0
|
35 */
|
fiore@0
|
36 @SuppressWarnings("serial")
|
fiore@0
|
37 public class SquareNode extends RectangularNode {
|
fiore@0
|
38
|
fiore@0
|
39 public SquareNode(String nodeType, NodeProperties properties){
|
fiore@0
|
40 super(nodeType, properties);
|
fiore@0
|
41 dataDisplayBounds = getMinBounds();
|
fiore@0
|
42 sqShape = getMinBounds();
|
fiore@0
|
43 }
|
fiore@0
|
44
|
fiore@0
|
45 @Override
|
fiore@0
|
46 protected void reshapeInnerProperties(List<String> insidePropertyTypes){
|
fiore@0
|
47 super.reshapeInnerProperties(insidePropertyTypes);
|
fiore@0
|
48
|
fiore@0
|
49 double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight();
|
fiore@0
|
50 if(diffwh > 0){
|
fiore@0
|
51 sqShape.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth());
|
fiore@0
|
52 } else if(diffwh < 0){
|
fiore@0
|
53 sqShape.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight());
|
fiore@0
|
54 }else{
|
fiore@0
|
55 sqShape.setFrame(dataDisplayBounds);
|
fiore@0
|
56 }
|
fiore@0
|
57 }
|
fiore@0
|
58
|
fiore@0
|
59 public Rectangle2D.Double getMinBounds(){
|
fiore@0
|
60 Rectangle2D r = super.getMinBounds();
|
fiore@0
|
61 r.setFrame(r.getX(), r.getY(), r.getHeight(), r.getHeight());
|
fiore@0
|
62 return (Rectangle2D.Double)r;
|
fiore@0
|
63 }
|
fiore@0
|
64
|
fiore@0
|
65 @Override
|
fiore@0
|
66 public ShapeType getShapeType(){
|
fiore@0
|
67 return ShapeType.Square;
|
fiore@0
|
68 }
|
fiore@0
|
69
|
fiore@0
|
70 @Override
|
fiore@0
|
71 public InputStream getSound(){
|
fiore@0
|
72 return sound;
|
fiore@0
|
73 }
|
fiore@0
|
74
|
fiore@0
|
75 @Override
|
fiore@0
|
76 protected void translateImplementation(Point2D p, double dx, double dy){
|
fiore@0
|
77 /* if we clicked on a property node, just move that one */
|
fiore@0
|
78 for(List<PropertyNode> pnList : propertyNodesMap.values())
|
fiore@0
|
79 for(PropertyNode pn : pnList)
|
fiore@0
|
80 if(pn.contains(p)){
|
fiore@0
|
81 pn.translate(dx, dy);
|
fiore@0
|
82 return;
|
fiore@0
|
83 }
|
fiore@0
|
84
|
fiore@0
|
85 sqShape.setFrame(sqShape.getX() + dx,
|
fiore@0
|
86 sqShape.getY() + dy,
|
fiore@0
|
87 sqShape.getWidth(),
|
fiore@0
|
88 sqShape.getHeight());
|
fiore@0
|
89 super.translateImplementation(p,dx, dy);
|
fiore@0
|
90 }
|
fiore@0
|
91
|
fiore@0
|
92 @Override
|
fiore@0
|
93 public Rectangle2D getBounds(){
|
fiore@0
|
94 return (Rectangle2D)sqShape.clone();
|
fiore@0
|
95 }
|
fiore@0
|
96
|
fiore@0
|
97 @Override
|
fiore@0
|
98 public Shape getShape(){
|
fiore@0
|
99 return sqShape;
|
fiore@0
|
100 }
|
fiore@0
|
101
|
fiore@0
|
102 @Override
|
fiore@0
|
103 public Object clone(){
|
fiore@0
|
104 SquareNode n = (SquareNode)super.clone();
|
fiore@0
|
105 n.sqShape = (Rectangle2D.Double)sqShape.clone();
|
fiore@0
|
106 return n;
|
fiore@0
|
107 }
|
fiore@0
|
108 private Rectangle2D.Double sqShape;
|
fiore@0
|
109 private static InputStream sound;
|
fiore@0
|
110
|
fiore@0
|
111 static{
|
fiore@0
|
112 sound = SquareNode.class.getResourceAsStream("audio/Square.mp3");
|
fiore@0
|
113 SoundFactory.getInstance().loadSound(sound);
|
fiore@0
|
114 }
|
fiore@0
|
115 }
|