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