annotate java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/SquareNode.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.Point2D;
f@0 24 import java.awt.geom.Rectangle2D;
f@0 25 import java.io.InputStream;
f@0 26 import java.util.List;
f@0 27
f@0 28 import uk.ac.qmul.eecs.ccmi.diagrammodel.NodeProperties;
f@0 29 import uk.ac.qmul.eecs.ccmi.sound.SoundFactory;
f@0 30
f@0 31 /**
f@0 32 *
f@0 33 * A squared shaped diagram node.
f@0 34 *
f@0 35 */
f@0 36 @SuppressWarnings("serial")
f@0 37 public class SquareNode extends RectangularNode {
f@0 38
f@0 39 public SquareNode(String nodeType, NodeProperties properties){
f@0 40 super(nodeType, properties);
f@0 41 dataDisplayBounds = getMinBounds();
f@0 42 sqShape = getMinBounds();
f@0 43 }
f@0 44
f@0 45 @Override
f@0 46 protected void reshapeInnerProperties(List<String> insidePropertyTypes){
f@0 47 super.reshapeInnerProperties(insidePropertyTypes);
f@0 48
f@0 49 double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight();
f@0 50 if(diffwh > 0){
f@0 51 sqShape.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth());
f@0 52 } else if(diffwh < 0){
f@0 53 sqShape.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight());
f@0 54 }else{
f@0 55 sqShape.setFrame(dataDisplayBounds);
f@0 56 }
f@0 57 }
f@0 58
f@0 59 public Rectangle2D.Double getMinBounds(){
f@0 60 Rectangle2D r = super.getMinBounds();
f@0 61 r.setFrame(r.getX(), r.getY(), r.getHeight(), r.getHeight());
f@0 62 return (Rectangle2D.Double)r;
f@0 63 }
f@0 64
f@0 65 @Override
f@0 66 public ShapeType getShapeType(){
f@0 67 return ShapeType.Square;
f@0 68 }
f@0 69
f@0 70 @Override
f@0 71 public InputStream getSound(){
f@0 72 return sound;
f@0 73 }
f@0 74
f@0 75 @Override
f@0 76 protected void translateImplementation(Point2D p, double dx, double dy){
f@0 77 /* if we clicked on a property node, just move that one */
f@0 78 for(List<PropertyNode> pnList : propertyNodesMap.values())
f@0 79 for(PropertyNode pn : pnList)
f@0 80 if(pn.contains(p)){
f@0 81 pn.translate(dx, dy);
f@0 82 return;
f@0 83 }
f@0 84
f@0 85 sqShape.setFrame(sqShape.getX() + dx,
f@0 86 sqShape.getY() + dy,
f@0 87 sqShape.getWidth(),
f@0 88 sqShape.getHeight());
f@0 89 super.translateImplementation(p,dx, dy);
f@0 90 }
f@0 91
f@0 92 @Override
f@0 93 public Rectangle2D getBounds(){
f@0 94 return (Rectangle2D)sqShape.clone();
f@0 95 }
f@0 96
f@0 97 @Override
f@0 98 public Shape getShape(){
f@0 99 return sqShape;
f@0 100 }
f@0 101
f@0 102 @Override
f@0 103 public Object clone(){
f@0 104 SquareNode n = (SquareNode)super.clone();
f@0 105 n.sqShape = (Rectangle2D.Double)sqShape.clone();
f@0 106 return n;
f@0 107 }
f@0 108 private Rectangle2D.Double sqShape;
f@0 109 private static InputStream sound;
f@0 110
f@0 111 static{
f@0 112 sound = SquareNode.class.getResourceAsStream("audio/Square.mp3");
f@0 113 SoundFactory.getInstance().loadSound(sound);
f@0 114 }
f@0 115 }