Mercurial > hg > ccmieditor
view java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/CircleNode.java @ 0:9418ab7b7f3f
Initial import
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Fri, 16 Dec 2011 17:35:51 +0000 |
parents | |
children |
line wrap: on
line source
/* 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.Ellipse2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.InputStream; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; import uk.ac.qmul.eecs.ccmi.diagrammodel.NodeProperties; import uk.ac.qmul.eecs.ccmi.sound.SoundFactory; /** * * A cricle shaped diagram node. * */ @SuppressWarnings("serial") public class CircleNode extends EllipticalNode { public CircleNode(String typeName, NodeProperties properties) { super(typeName, properties); dataDisplayBounds = (Rectangle2D.Double)getMinBounds(); cShape = new Ellipse2D.Double(); cShape.setFrame(dataDisplayBounds); } @Override public Rectangle2D getMinBounds(){ Rectangle2D r = super.getMinBounds(); r.setFrame(r.getX(), r.getY(), r.getHeight(), r.getHeight()); return (Rectangle2D)r; } @Override public Rectangle2D getBounds(){ return cShape.getBounds2D(); } @Override public Shape getShape(){ return cShape; } @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; } cShape.setFrame(cShape.getX() + dx, cShape.getY() + dy, cShape.getWidth(), cShape.getHeight()); super.translateImplementation(p,dx, dy); } @Override protected void reshapeInnerProperties(List<String> insidePropertyTypes){ super.reshapeInnerProperties(insidePropertyTypes); double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight(); Rectangle2D.Double r = new Rectangle2D.Double(); if(diffwh > 0){ r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth()); } else if(diffwh < 0){ r.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight()); }else{ r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight()); } cShape.setFrame(super.anyInsideProperties() ? getOutBounds(r) : r); } @Override public void decode(Document doc, Element nodeTag) throws IOException{ super.decode(doc, nodeTag); double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight(); Rectangle2D.Double r = new Rectangle2D.Double(); if(diffwh > 0){ r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth()); } else if(diffwh < 0){ r.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight()); }else{ r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight()); } cShape.setFrame(super.anyInsideProperties() ? getOutBounds(r) : r); } @Override public ShapeType getShapeType(){ return ShapeType.Circle; } @Override public Object clone(){ CircleNode n = (CircleNode)super.clone(); n.cShape = (Ellipse2D.Double)cShape.clone(); return n; } private Ellipse2D.Double cShape; private static InputStream sound; static{ sound = CircleNode.class.getResourceAsStream("audio/Circle.mp3"); SoundFactory.getInstance().loadSound(sound); } }