diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/SquareNode.java	Tue Jul 08 16:28:59 2014 +0100
@@ -0,0 +1,115 @@
+/*  
+ CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
+  
+ Copyright (C) 2011  Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/  
+
+package uk.ac.qmul.eecs.ccmi.simpletemplate;
+
+import java.awt.Shape;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.io.InputStream;
+import java.util.List;
+
+import uk.ac.qmul.eecs.ccmi.diagrammodel.NodeProperties;
+import uk.ac.qmul.eecs.ccmi.sound.SoundFactory;
+
+/**
+ * 
+ * A squared shaped diagram node.
+ *
+ */
+@SuppressWarnings("serial")
+public class SquareNode extends RectangularNode {
+	
+	public SquareNode(String nodeType, NodeProperties properties){
+		super(nodeType, properties);
+		dataDisplayBounds = getMinBounds();
+		sqShape = getMinBounds();
+	}
+	
+	@Override
+	protected void reshapeInnerProperties(List<String> insidePropertyTypes){
+		super.reshapeInnerProperties(insidePropertyTypes);
+		
+		double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight();
+		if(diffwh > 0){
+			sqShape.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth());
+		} else if(diffwh < 0){
+			sqShape.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight());
+		}else{
+			sqShape.setFrame(dataDisplayBounds);
+		}
+	}
+	
+	public Rectangle2D.Double getMinBounds(){
+		Rectangle2D r = super.getMinBounds();
+		r.setFrame(r.getX(), r.getY(), r.getHeight(), r.getHeight());
+		return (Rectangle2D.Double)r;
+	}
+	
+	@Override
+	public ShapeType getShapeType(){
+		return ShapeType.Square;
+	}
+	
+	@Override
+	public InputStream getSound(){
+		return sound;
+	}
+	
+	@Override
+	protected void translateImplementation(Point2D p, double dx, double dy){
+		/* if we clicked on a property node, just move that one */
+		for(List<PropertyNode> pnList : propertyNodesMap.values())
+			for(PropertyNode pn : pnList)
+				if(pn.contains(p)){
+					pn.translate(dx, dy);
+					return;
+				}
+		
+		sqShape.setFrame(sqShape.getX() + dx,
+				sqShape.getY() + dy, 
+				sqShape.getWidth(), 
+				sqShape.getHeight());
+		super.translateImplementation(p,dx, dy);
+	}
+	
+	@Override
+	public Rectangle2D getBounds(){
+		return (Rectangle2D)sqShape.clone();
+	}
+	
+	@Override
+	public Shape getShape(){
+		return sqShape;
+	}
+	
+	@Override
+	public Object clone(){
+		SquareNode n = (SquareNode)super.clone();
+		n.sqShape = (Rectangle2D.Double)sqShape.clone();
+		return n;
+	}
+	private Rectangle2D.Double sqShape;
+	private static InputStream sound;
+	
+	static{
+		sound = SquareNode.class.getResourceAsStream("audio/Square.mp3");
+		SoundFactory.getInstance().loadSound(sound);
+	}
+}