f@0: /* f@0: accessPD - An accessible PD patches editor f@0: f@0: Copyright (C) 2014 Fiore Martin 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.pdsupport; f@0: f@0: import java.awt.Graphics2D; f@0: import java.awt.Stroke; f@0: import java.awt.geom.Line2D; f@0: import java.awt.geom.Rectangle2D; f@0: import java.io.InputStream; f@0: f@0: import uk.ac.qmul.eecs.ccmi.gui.Edge; f@0: import uk.ac.qmul.eecs.ccmi.gui.GraphElement; f@0: import uk.ac.qmul.eecs.ccmi.gui.LineStyle; f@0: import uk.ac.qmul.eecs.ccmi.gui.Node; f@0: import uk.ac.qmul.eecs.ccmi.sound.SoundFactory; f@0: f@0: public class PdConnection extends Edge implements PdElement{ f@0: private static final long serialVersionUID = 1L; f@0: private static InputStream sound; f@0: private static String FROM = "from"; f@0: private static String TO = "to"; f@0: f@0: static{ f@0: sound = PdConnection.class.getResourceAsStream("audio/PdConnection.mp3"); f@0: SoundFactory.getInstance().loadSound(sound); f@0: } f@0: f@0: public PdConnection(){ f@0: super("Connection", new String[] {FROM, TO}, 2, 2, LineStyle.Solid); f@0: } f@0: f@0: f@0: @Override f@0: public void draw(Graphics2D g2) { f@0: /* use this edge stroke */ f@0: Stroke oldStroke = g2.getStroke(); f@0: g2.setStroke(getStyle().getStroke()); f@0: /* straight line */ f@0: f@0: if(points.isEmpty()){ f@0: /* just one line from one node to the other */ f@0: Line2D line = getSegment(getNodeAt(0),getNodeAt(1)); f@0: g2.draw(line); f@0: }else{ f@0: /* the edge has been bended into more lines. * f@0: * for every inner point neighbour draw a line * f@0: * and draw the inner point itself */ f@0: for(InnerPoint p : points){ f@0: for(GraphElement ge : p.getNeighbours()){ f@0: g2.draw(getSegment(p,ge)); f@0: } f@0: p.draw(g2); f@0: } f@0: f@0: } f@0: f@0: /* restore old stroke of g2 */ f@0: g2.setStroke(oldStroke); f@0: } f@0: f@0: @Override f@0: public Rectangle2D getBounds() { f@0: Rectangle2D bounds = (Rectangle2D)getNodeAt(0).getBounds(); f@0: f@0: for(int i=1; i< getNodesNum(); i++) f@0: bounds.add(getNodeAt(i).getBounds()); f@0: f@0: for(InnerPoint p : points){ f@0: bounds.add(p.getBounds()); f@0: } f@0: f@0: return bounds; f@0: } f@0: f@0: @Override f@0: public InputStream getSound() { f@0: return sound; f@0: } f@0: f@0: f@0: @Override f@0: public String toPdFile() { f@0: f@0: Node n0 = getNodeAt(0); f@0: Node n1 = getNodeAt(1); f@0: f@0: PdElement elemFrom = (PdElement) ( FROM.equals(this.getEndDescription(n0)) ? n0 : n1); f@0: PdElement elemTo = (PdElement) ( TO.equals(this.getEndDescription(n0)) ? n0 : n1); f@0: f@0: return getChunckType() + f@0: " connect " + f@0: elemFrom.getOrderNumber()+ f@0: " 0 " + f@0: elemTo.getOrderNumber() + f@0: " 0" f@0: ; f@0: } f@0: f@0: f@0: @Override f@0: public String getChunckType() { f@0: return "#X"; f@0: } f@0: f@0: @Override f@0: public int getOrderNumber(){ f@0: throw new UnsupportedOperationException(); f@0: } f@0: f@0: public Object clone(){ f@0: f@0: return new PdConnection(); f@0: } f@0: f@0: }