annotate java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/CircleNode.java @ 1:e3935c01cde2 tip

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