comparison java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/CircleNode.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.Ellipse2D;
24 import java.awt.geom.Point2D;
25 import java.awt.geom.Rectangle2D;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.util.List;
29
30 import org.w3c.dom.Document;
31 import org.w3c.dom.Element;
32
33 import uk.ac.qmul.eecs.ccmi.diagrammodel.NodeProperties;
34 import uk.ac.qmul.eecs.ccmi.sound.SoundFactory;
35
36 /**
37 *
38 * A cricle shaped diagram node.
39 *
40 */
41 @SuppressWarnings("serial")
42 public class CircleNode extends EllipticalNode {
43
44 public CircleNode(String typeName, NodeProperties properties) {
45 super(typeName, properties);
46 dataDisplayBounds = (Rectangle2D.Double)getMinBounds();
47 cShape = new Ellipse2D.Double();
48 cShape.setFrame(dataDisplayBounds);
49 }
50
51 @Override
52 public Rectangle2D getMinBounds(){
53 Rectangle2D r = super.getMinBounds();
54 r.setFrame(r.getX(), r.getY(), r.getHeight(), r.getHeight());
55 return (Rectangle2D)r;
56 }
57
58 @Override
59 public Rectangle2D getBounds(){
60 return cShape.getBounds2D();
61 }
62
63 @Override
64 public Shape getShape(){
65 return cShape;
66 }
67
68 @Override
69 public InputStream getSound(){
70 return sound;
71 }
72
73 @Override
74 protected void translateImplementation(Point2D p, double dx, double dy){
75 /* if we clicked on a property node, just move that one */
76 for(List<PropertyNode> pnList : propertyNodesMap.values())
77 for(PropertyNode pn : pnList)
78 if(pn.contains(p)){
79 pn.translate(dx, dy);
80 return;
81 }
82 cShape.setFrame(cShape.getX() + dx,
83 cShape.getY() + dy,
84 cShape.getWidth(),
85 cShape.getHeight());
86 super.translateImplementation(p,dx, dy);
87 }
88
89 @Override
90 protected void reshapeInnerProperties(List<String> insidePropertyTypes){
91 super.reshapeInnerProperties(insidePropertyTypes);
92 double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight();
93 Rectangle2D.Double r = new Rectangle2D.Double();
94 if(diffwh > 0){
95 r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth());
96 } else if(diffwh < 0){
97 r.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight());
98 }else{
99 r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight());
100 }
101 cShape.setFrame(super.anyInsideProperties() ? getOutBounds(r) : r);
102 }
103
104 @Override
105 public void decode(Document doc, Element nodeTag) throws IOException{
106 super.decode(doc, nodeTag);
107 double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight();
108 Rectangle2D.Double r = new Rectangle2D.Double();
109 if(diffwh > 0){
110 r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth());
111 } else if(diffwh < 0){
112 r.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight());
113 }else{
114 r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight());
115 }
116 cShape.setFrame(super.anyInsideProperties() ? getOutBounds(r) : r);
117
118 }
119
120 @Override
121 public ShapeType getShapeType(){
122 return ShapeType.Circle;
123 }
124
125 @Override
126 public Object clone(){
127 CircleNode n = (CircleNode)super.clone();
128 n.cShape = (Ellipse2D.Double)cShape.clone();
129 return n;
130 }
131
132 private Ellipse2D.Double cShape;
133 private static InputStream sound;
134 static{
135 sound = CircleNode.class.getResourceAsStream("audio/Circle.mp3");
136 SoundFactory.getInstance().loadSound(sound);
137 }
138 }