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