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.Ellipse2D; f@0: import java.awt.geom.Point2D; f@0: import java.awt.geom.Rectangle2D; f@0: import java.io.IOException; f@0: import java.io.InputStream; f@0: import java.util.List; f@0: f@0: import org.w3c.dom.Document; f@0: import org.w3c.dom.Element; 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 cricle shaped diagram node. f@0: * f@0: */ f@0: @SuppressWarnings("serial") f@0: public class CircleNode extends EllipticalNode { f@0: f@0: public CircleNode(String typeName, NodeProperties properties) { f@0: super(typeName, properties); f@0: dataDisplayBounds = (Rectangle2D.Double)getMinBounds(); f@0: cShape = new Ellipse2D.Double(); f@0: cShape.setFrame(dataDisplayBounds); f@0: } f@0: f@0: @Override f@0: public Rectangle2D getMinBounds(){ f@0: Rectangle2D r = super.getMinBounds(); f@0: r.setFrame(r.getX(), r.getY(), r.getHeight(), r.getHeight()); f@0: return (Rectangle2D)r; f@0: } f@0: f@0: @Override f@0: public Rectangle2D getBounds(){ f@0: return cShape.getBounds2D(); f@0: } f@0: f@0: @Override f@0: public Shape getShape(){ f@0: return cShape; 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: cShape.setFrame(cShape.getX() + dx, f@0: cShape.getY() + dy, f@0: cShape.getWidth(), f@0: cShape.getHeight()); f@0: super.translateImplementation(p,dx, dy); f@0: } f@0: f@0: @Override f@0: protected void reshapeInnerProperties(List insidePropertyTypes){ f@0: super.reshapeInnerProperties(insidePropertyTypes); f@0: double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight(); f@0: Rectangle2D.Double r = new Rectangle2D.Double(); f@0: if(diffwh > 0){ f@0: r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth()); f@0: } else if(diffwh < 0){ f@0: r.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight()); f@0: }else{ f@0: r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight()); f@0: } f@0: cShape.setFrame(super.anyInsideProperties() ? getOutBounds(r) : r); f@0: } f@0: f@0: @Override f@0: public void decode(Document doc, Element nodeTag) throws IOException{ f@0: super.decode(doc, nodeTag); f@0: double diffwh = dataDisplayBounds.getWidth() - dataDisplayBounds.getHeight(); f@0: Rectangle2D.Double r = new Rectangle2D.Double(); f@0: if(diffwh > 0){ f@0: r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY()-diffwh/2,dataDisplayBounds.getWidth(),dataDisplayBounds.getWidth()); f@0: } else if(diffwh < 0){ f@0: r.setFrame(dataDisplayBounds.getX()+diffwh/2,dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight()); f@0: }else{ f@0: r.setFrame(dataDisplayBounds.getX(),dataDisplayBounds.getY(),dataDisplayBounds.getHeight(),dataDisplayBounds.getHeight()); f@0: } f@0: cShape.setFrame(super.anyInsideProperties() ? getOutBounds(r) : r); f@0: f@0: } f@0: f@0: @Override f@0: public ShapeType getShapeType(){ f@0: return ShapeType.Circle; f@0: } f@0: f@0: @Override f@0: public Object clone(){ f@0: CircleNode n = (CircleNode)super.clone(); f@0: n.cShape = (Ellipse2D.Double)cShape.clone(); f@0: return n; f@0: } f@0: f@0: private Ellipse2D.Double cShape; f@0: private static InputStream sound; f@0: static{ f@0: sound = CircleNode.class.getResourceAsStream("audio/Circle.mp3"); f@0: SoundFactory.getInstance().loadSound(sound); f@0: } f@0: }