http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/SVGUtil.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/SVGUtil.java b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/SVGUtil.java new file mode 100644 index 0000000..b165bb3 --- /dev/null +++ b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/SVGUtil.java @@ -0,0 +1,477 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph.svg; + +import static java.lang.Float.parseFloat; +import static java.lang.Math.PI; +import static java.lang.Math.atan2; +import static org.apache.batik.dom.svg.SVGDOMImplementation.getDOMImplementation; +import static org.apache.batik.util.SMILConstants.SMIL_ATTRIBUTE_NAME_ATTRIBUTE; +import static org.apache.batik.util.SMILConstants.SMIL_DUR_ATTRIBUTE; +import static org.apache.batik.util.SMILConstants.SMIL_FILL_ATTRIBUTE; +import static org.apache.batik.util.SMILConstants.SMIL_FREEZE_VALUE; +import static org.apache.batik.util.SMILConstants.SMIL_FROM_ATTRIBUTE; +import static org.apache.batik.util.SMILConstants.SMIL_TO_ATTRIBUTE; +import static org.apache.batik.util.SVGConstants.SVG_TYPE_ATTRIBUTE; +import static org.apache.batik.util.SVGConstants.SVG_X1_ATTRIBUTE; +import static org.apache.batik.util.SVGConstants.SVG_X2_ATTRIBUTE; +import static org.apache.batik.util.SVGConstants.SVG_Y1_ATTRIBUTE; +import static org.apache.batik.util.SVGConstants.SVG_Y2_ATTRIBUTE; +import static org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName; + +import java.awt.Color; +import java.awt.Point; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringReader; +import java.util.List; + +import org.apache.taverna.lang.io.StreamDevourer; +import org.apache.taverna.workbench.configuration.workbench.WorkbenchConfiguration; +import org.apache.taverna.workbench.models.graph.GraphShapeElement.Shape; + +import org.apache.batik.dom.svg.SAXSVGDocumentFactory; +import org.apache.batik.dom.svg.SVGDOMImplementation; +import org.apache.batik.dom.svg.SVGOMAnimationElement; +import org.apache.batik.dom.svg.SVGOMPoint; +import org.apache.log4j.Logger; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Element; +import org.w3c.dom.svg.SVGDocument; +import org.w3c.dom.svg.SVGElement; +import org.w3c.dom.svg.SVGLocatable; +import org.w3c.dom.svg.SVGMatrix; +//import org.apache.batik.transcoder.TranscoderException; +//import org.apache.batik.transcoder.svg2svg.PrettyPrinter; + +/** + * Utility methods. + * + * @author David Withers + */ +public class SVGUtil { + private static final String C = "C"; + private static final String M = "M"; + private static final String SPACE = " "; + private static final String COMMA = ","; + public static final String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; + private static final String SVG = "svg"; + private static final Logger logger = Logger.getLogger(SVGUtil.class); + + private static SAXSVGDocumentFactory docFactory; + + static { + String parser = getXMLParserClassName(); + logger.info("Using XML parser " + parser); + docFactory = new SAXSVGDocumentFactory(parser); + } + + /** + * Creates a new SVGDocument. + * + * @return a new SVGDocument + */ + public static SVGDocument createSVGDocument() { + DOMImplementation impl = getDOMImplementation(); + return (SVGDocument) impl.createDocument(svgNS, SVG, null); + } + + /** + * Converts a point in screen coordinates to a point in document + * coordinates. + * + * @param locatable + * @param screenPoint + * the point in screen coordinates + * @return the point in document coordinates + */ + public static SVGOMPoint screenToDocument(SVGLocatable locatable, + SVGOMPoint screenPoint) { + SVGMatrix mat = ((SVGLocatable) locatable.getFarthestViewportElement()) + .getScreenCTM().inverse(); + return (SVGOMPoint) screenPoint.matrixTransform(mat); + } + + /** + * Writes SVG to the console. For debugging only. + * + * @param svgDocument + * the document to output + */ +// public static void writeSVG(SVGDocument svgDocument) { +// writeSVG(svgDocument, new OutputStreamWriter(System.out)); +// } + + /** + * Writes SVG to an output stream. + * + * @param svgDocument + * the document to output + * @param writer + * the stream to write the document to + */ +// public static void writeSVG(SVGDocument svgDocument, Writer writer) { +// StringWriter sw = new StringWriter(); +// try { +// Transformer transformer = TransformerFactory.newInstance().newTransformer(); +// Source src = new DOMSource(svgDocument.getDocumentElement()); +// transformer.transform(src, new StreamResult(sw)); +// +// PrettyPrinter pp = new PrettyPrinter(); +// pp.print(new StringReader(sw.toString()), writer); +// } catch (TransformerException | TranscoderException | IOException e) { +// e.printStackTrace(new PrintWriter(writer)); +// } +// } + + /** + * Generates an SVGDocument from DOT text by calling out to GraphViz. + * + * @param dotText + * @return an SVGDocument + * @throws IOException + */ + public static SVGDocument getSVG(String dotText, + WorkbenchConfiguration workbenchConfiguration) throws IOException { + String dotLocation = (String) workbenchConfiguration + .getProperty("taverna.dotlocation"); + if (dotLocation == null) + dotLocation = "dot"; + logger.debug("Invoking dot..."); + Process dotProcess = exec(dotLocation, "-Tsvg"); + StreamDevourer devourer = new StreamDevourer( + dotProcess.getInputStream()); + devourer.start(); + try (PrintWriter out = new PrintWriter(dotProcess.getOutputStream(), + true)) { + out.print(dotText); + out.flush(); + } + + String svgText = devourer.blockOnOutput(); + /* + * Avoid TAV-424, replace buggy SVG outputted by "modern" GraphViz + * versions. http://www.graphviz.org/bugs/b1075.html + * + * Contributed by Marko Ullgren + */ + svgText = svgText.replaceAll("font-weight:regular", + "font-weight:normal"); + logger.info(svgText); + // Fake URI, just used for internal references like #fish + return docFactory.createSVGDocument( + "http://taverna.sf.net/diagram/generated.svg", + new StringReader(svgText)); + } + + /** + * Generates DOT text with layout information from DOT text by calling out + * to GraphViz. + * + * @param dotText + * dot text + * @return dot text with layout information + * @throws IOException + */ + public static String getDot(String dotText, + WorkbenchConfiguration workbenchConfiguration) throws IOException { + String dotLocation = (String) workbenchConfiguration + .getProperty("taverna.dotlocation"); + if (dotLocation == null) + dotLocation = "dot"; + logger.debug("Invoking dot..."); + Process dotProcess = exec(dotLocation, "-Tdot", "-Glp=0,0"); + StreamDevourer devourer = new StreamDevourer( + dotProcess.getInputStream()); + devourer.start(); + try (PrintWriter out = new PrintWriter(dotProcess.getOutputStream(), + true)) { + out.print(dotText); + out.flush(); + } + + String dot = devourer.blockOnOutput(); + // logger.info(dot); + return dot; + } + + private static Process exec(String...args) throws IOException { + Process p = Runtime.getRuntime().exec(args); + /* + * Must create an error devourer otherwise stderr fills up and the + * process stalls! + */ + new StreamDevourer(p.getErrorStream()).start(); + return p; + } + + /** + * Returns the hex value for a <code>Color</code>. If color is null "none" + * is returned. + * + * @param color + * the <code>Color</code> to convert to hex code + * @return the hex value + */ + public static String getHexValue(Color color) { + if (color == null) + return "none"; + + return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), + color.getBlue()); + } + + /** + * Calculates the angle to rotate an arrow head to be placed on the end of a + * line. + * + * @param line + * the line to calculate the arrow head angle from + * @return the angle to rotate an arrow head + */ + public static double calculateAngle(Element line) { + float x1 = parseFloat(line.getAttribute(SVG_X1_ATTRIBUTE)); + float y1 = parseFloat(line.getAttribute(SVG_Y1_ATTRIBUTE)); + float x2 = parseFloat(line.getAttribute(SVG_X2_ATTRIBUTE)); + float y2 = parseFloat(line.getAttribute(SVG_Y2_ATTRIBUTE)); + return calculateAngle(x1, y1, x2, y2); + } + + /** + * Calculates the angle to rotate an arrow head to be placed on the end of a + * line. + * + * @param pointList + * the list of <code>Point</code>s to calculate the arrow head + * angle from + * @return the angle to rotate an arrow head + */ + public static double calculateAngle(List<Point> pointList) { + double angle = 0d; + if (pointList.size() > 1) { + int listSize = pointList.size(); + Point a = pointList.get(listSize - 2); + Point b = pointList.get(listSize - 1); + /* + * dot sometimes generates paths with the same point repeated at the + * end of the path, so move back along the path until two different + * points are found + */ + while (a.equals(b) && listSize > 2) { + b = a; + a = pointList.get(--listSize - 2); + } + angle = calculateAngle(a.x, a.y, b.x, b.y); + } + return angle; + } + + /** + * Calculates the angle to rotate an arrow head to be placed on the end of a + * line. + * + * @param x1 + * the x coordinate of the start of the line + * @param y1 + * the y coordinate of the start of the line + * @param x2 + * the x coordinate of the end of the line + * @param y2 + * the y coordinate of the end of the line + * @return the angle to rotate an arrow head + */ + public static double calculateAngle(float x1, float y1, float x2, float y2) { + return atan2(y2 - y1, x2 - x1) * 180 / PI; + } + + /** + * Calculates the points that make up the polygon for the specified + * {@link Shape}. + * + * @param shape + * the <code>Shape</code> to calculate points for + * @param width + * the width of the <code>Shape</code> + * @param height + * the height of the <code>Shape</code> + * @return the points that make up the polygon for the specified + * <code>Shape</code> + */ + public static String calculatePoints(Shape shape, int width, int height) { + StringBuilder sb = new StringBuilder(); + switch (shape) { + case BOX: + case RECORD: + addPoint(sb, 0, 0); + addPoint(sb, width, 0); + addPoint(sb, width, height); + addPoint(sb, 0, height); + break; + case HOUSE: + addPoint(sb, width / 2f, 0); + addPoint(sb, width, height / 3f); + addPoint(sb, width, height - 3); + addPoint(sb, 0, height - 3); + addPoint(sb, 0, height / 3f); + break; + case INVHOUSE: + addPoint(sb, 0, 3); + addPoint(sb, width, 3); + addPoint(sb, width, height / 3f * 2f); + addPoint(sb, width / 2f, height); + addPoint(sb, 0, height / 3f * 2f); + break; + case TRIANGLE: + addPoint(sb, width / 2f, 0); + addPoint(sb, width, height); + addPoint(sb, 0, height); + break; + case INVTRIANGLE: + addPoint(sb, 0, 0); + addPoint(sb, width, 0); + addPoint(sb, width / 2f, height); + break; + default: + // Nothing to do for the others + break; + } + return sb.toString(); + } + + /** + * Appends x y coordinates to a <code>StringBuilder</code> in the format + * "x,y ". + * + * @param stringBuilder + * the <code>StringBuilder</code> to append the point to + * @param x + * the x coordinate + * @param y + * the y coordinate + */ + public static void addPoint(StringBuilder stringBuilder, float x, float y) { + stringBuilder.append(x).append(COMMA).append(y).append(SPACE); + } + + /** + * Converts a list of points into a string format for a cubic Bezier curve. + * + * For example, "M100,200 C100,100 250,100 250,200". See + * http://www.w3.org/TR/SVG11/paths.html#PathDataCubicBezierCommands. + * + * @param pointList + * a list of points that describes a cubic Bezier curve + * @return a string that describes a cubic Bezier curve + */ + public static String getPath(List<Point> pointList) { + StringBuilder sb = new StringBuilder(); + if (pointList != null && pointList.size() > 1) { + Point firstPoint = pointList.get(0); + sb.append(M).append(firstPoint.x).append(COMMA) + .append(firstPoint.y); + sb.append(SPACE); + Point secontPoint = pointList.get(1); + sb.append(C).append(secontPoint.x).append(COMMA) + .append(secontPoint.y); + for (int i = 2; i < pointList.size(); i++) { + Point point = pointList.get(i); + sb.append(SPACE).append(point.x).append(COMMA).append(point.y); + } + } + return sb.toString(); + } + + /** + * Creates an animation element. + * + * @param graphController + * the SVGGraphController to use to create the animation element + * @param elementType + * the type of animation element to create + * @param attribute + * the attribute that the animation should affect + * @param transformType + * the type of transform - use null not creating a transform + * animation + * @return an new animation element + */ + public static SVGOMAnimationElement createAnimationElement( + SVGGraphController graphController, String elementType, + String attribute, String transformType) { + SVGOMAnimationElement animationElement = (SVGOMAnimationElement) graphController + .createElement(elementType); + animationElement.setAttribute(SMIL_ATTRIBUTE_NAME_ATTRIBUTE, attribute); + if (transformType != null) + animationElement.setAttribute(SVG_TYPE_ATTRIBUTE, transformType); + animationElement.setAttribute(SMIL_FILL_ATTRIBUTE, SMIL_FREEZE_VALUE); + return animationElement; + } + + /** + * Adds an animation to the SVG element and starts the animation. + * + * @param animate + * that animation element + * @param element + * the element to animate + * @param duration + * the duration of the animation in milliseconds + * @param from + * the starting point for the animation, can be null + * @param to + * the end point for the animation, cannot be null + */ + public static void animate(SVGOMAnimationElement animate, SVGElement element, int duration, + String from, String to) { + animate.setAttribute(SMIL_DUR_ATTRIBUTE, duration + "ms"); + if (from != null) + animate.setAttribute(SMIL_FROM_ATTRIBUTE, from); + animate.setAttribute(SMIL_TO_ATTRIBUTE, to); + element.appendChild(animate); + try { + animate.beginElement(); + } catch (NullPointerException e) { + } + } + + /** + * Adjusts the length of <code>pointList</code> by adding or removing points + * to make the length equal to <code>size</code>. If <code>pointList</code> + * is shorter than <code>size</code> the last point is repeated. If + * <code>pointList</code> is longer than <code>size</code> points at the end + * of the list are removed. + * + * @param pointList + * the path to adjust + * @param size + * the required size for <code>pointList</code> + */ + public static void adjustPathLength(List<Point> pointList, int size) { + if (pointList.size() < size) { + Point lastPoint = pointList.get(pointList.size() - 1); + for (int i = pointList.size(); i < size; i++) + pointList.add(lastPoint); + } else if (pointList.size() > size) { + for (int i = pointList.size(); i > size; i--) + pointList.remove(i - 1); + } + } +}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGEventListener.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGEventListener.java b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGEventListener.java new file mode 100644 index 0000000..e23474a --- /dev/null +++ b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGEventListener.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph.svg.event; + +import static org.apache.taverna.workbench.models.graph.svg.SVGUtil.screenToDocument; +import org.apache.taverna.workbench.models.graph.GraphElement; + +import org.apache.batik.dom.svg.SVGOMPoint; +import org.w3c.dom.events.Event; +import org.w3c.dom.events.EventListener; +import org.w3c.dom.events.MouseEvent; +import org.w3c.dom.svg.SVGLocatable; + +/** + * Abstract superclass for SVG event listeners. + * + * @author David Withers + */ +public abstract class SVGEventListener implements EventListener { + protected GraphElement graphElement; + + public SVGEventListener(GraphElement graphElement) { + this.graphElement = graphElement; + } + + protected abstract void event(SVGOMPoint point, MouseEvent evt); + + @Override + public final void handleEvent(Event evt) { + if (evt instanceof MouseEvent) { + MouseEvent me = (MouseEvent) evt; + SVGOMPoint point = screenToDocument((SVGLocatable) me.getTarget(), + new SVGOMPoint(me.getClientX(), me.getClientY())); + event(point, me); + evt.stopPropagation(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseClickEventListener.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseClickEventListener.java b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseClickEventListener.java new file mode 100644 index 0000000..c9dc258 --- /dev/null +++ b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseClickEventListener.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph.svg.event; + +import org.apache.taverna.workbench.models.graph.GraphElement; + +import org.apache.batik.dom.svg.SVGOMPoint; +import org.w3c.dom.events.MouseEvent; + +/** + * SVG event listener for handling mouse click events. + * + * @author David Withers + */ +public class SVGMouseClickEventListener extends SVGEventListener { + public SVGMouseClickEventListener(GraphElement graphElement) { + super(graphElement); + } + + @Override + protected void event(SVGOMPoint point, MouseEvent evt) { + graphElement.getEventManager().mouseClicked(graphElement, + evt.getButton(), evt.getAltKey(), evt.getCtrlKey(), + evt.getMetaKey(), (int) point.getX(), (int) point.getY(), + evt.getScreenX(), evt.getScreenY()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseDownEventListener.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseDownEventListener.java b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseDownEventListener.java new file mode 100644 index 0000000..d526d14 --- /dev/null +++ b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseDownEventListener.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph.svg.event; + +import org.apache.taverna.workbench.models.graph.GraphElement; + +import org.apache.batik.dom.svg.SVGOMPoint; +import org.w3c.dom.events.MouseEvent; + +/** + * SVG event listener for handling mouse button down events. + * + * @author David Withers + */ +public class SVGMouseDownEventListener extends SVGEventListener { + public SVGMouseDownEventListener(GraphElement graphElement) { + super(graphElement); + } + + @Override + protected void event(SVGOMPoint point, MouseEvent evt) { + graphElement.getEventManager().mouseDown(graphElement, evt.getButton(), + evt.getAltKey(), evt.getCtrlKey(), evt.getMetaKey(), + (int) point.getX(), (int) point.getY(), evt.getScreenX(), + evt.getScreenY()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseMovedEventListener.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseMovedEventListener.java b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseMovedEventListener.java new file mode 100644 index 0000000..0a1a9f9 --- /dev/null +++ b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseMovedEventListener.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph.svg.event; + +import org.apache.taverna.workbench.models.graph.GraphElement; + +import org.apache.batik.dom.svg.SVGOMPoint; +import org.w3c.dom.events.MouseEvent; + +/** + * SVG event listener for handling mouse movement events. + * + * @author David Withers + */ +public class SVGMouseMovedEventListener extends SVGEventListener { + public SVGMouseMovedEventListener(GraphElement graphElement) { + super(graphElement); + } + + @Override + protected void event(SVGOMPoint point, MouseEvent mouseEvent) { + graphElement.getEventManager().mouseMoved(graphElement, + mouseEvent.getButton(), mouseEvent.getAltKey(), + mouseEvent.getCtrlKey(), mouseEvent.getMetaKey(), + (int) point.getX(), (int) point.getY(), + mouseEvent.getScreenX(), mouseEvent.getScreenY()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseOutEventListener.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseOutEventListener.java b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseOutEventListener.java new file mode 100644 index 0000000..28651a7 --- /dev/null +++ b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseOutEventListener.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph.svg.event; + +import org.apache.taverna.workbench.models.graph.GraphElement; + +import org.apache.batik.dom.svg.SVGOMPoint; +import org.w3c.dom.events.MouseEvent; + +/** + * SVG event listener for handling mouse button up events. + * + * @author David Withers + */ +public class SVGMouseOutEventListener extends SVGEventListener { + public SVGMouseOutEventListener(GraphElement graphElement) { + super(graphElement); + } + + @Override + protected void event(SVGOMPoint point, MouseEvent mouseEvent) { + graphElement.getEventManager().mouseOut(graphElement, + mouseEvent.getButton(), mouseEvent.getAltKey(), + mouseEvent.getCtrlKey(), mouseEvent.getMetaKey(), + (int) point.getX(), (int) point.getY(), + mouseEvent.getScreenX(), mouseEvent.getScreenY()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseOverEventListener.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseOverEventListener.java b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseOverEventListener.java new file mode 100644 index 0000000..2478a5d --- /dev/null +++ b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseOverEventListener.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph.svg.event; + +import org.apache.taverna.workbench.models.graph.GraphElement; + +import org.apache.batik.dom.svg.SVGOMPoint; +import org.w3c.dom.events.MouseEvent; + +/** + * SVG event listener for handling mouse button up events. + * + * @author David Withers + */ +public class SVGMouseOverEventListener extends SVGEventListener { + public SVGMouseOverEventListener(GraphElement graphElement) { + super(graphElement); + } + + @Override + protected void event(SVGOMPoint point, MouseEvent mouseEvent) { + graphElement.getEventManager().mouseOver(graphElement, + mouseEvent.getButton(), mouseEvent.getAltKey(), + mouseEvent.getCtrlKey(), mouseEvent.getMetaKey(), + (int) point.getX(), (int) point.getY(), + mouseEvent.getScreenX(), mouseEvent.getScreenY()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseUpEventListener.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseUpEventListener.java b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseUpEventListener.java new file mode 100644 index 0000000..e4a6f86 --- /dev/null +++ b/taverna-graph-model/src/main/java/org/apache/taverna/workbench/models/graph/svg/event/SVGMouseUpEventListener.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph.svg.event; + +import org.apache.taverna.workbench.models.graph.GraphElement; + +import org.apache.batik.dom.svg.SVGOMPoint; +import org.w3c.dom.events.MouseEvent; + +/** + * SVG event listener for handling mouse button up events. + * + * @author David Withers + */ +public class SVGMouseUpEventListener extends SVGEventListener { + public SVGMouseUpEventListener(GraphElement graphElement) { + super(graphElement); + } + + @Override + protected void event(SVGOMPoint point, MouseEvent mouseEvent) { + graphElement.getEventManager().mouseUp(graphElement, + mouseEvent.getButton(), mouseEvent.getAltKey(), + mouseEvent.getCtrlKey(), mouseEvent.getMetaKey(), + (int) point.getX(), (int) point.getY(), + mouseEvent.getScreenX(), mouseEvent.getScreenY()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphControllerTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphControllerTest.java b/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphControllerTest.java deleted file mode 100644 index 8ae5a9f..0000000 --- a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphControllerTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.models.graph; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import net.sf.taverna.t2.workbench.models.graph.GraphController.PortStyle; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import org.apache.taverna.scufl2.api.core.Workflow; - -public class GraphControllerTest { - - Workflow dataflow; - - GraphController graphController; - - @Before - public void setUp() throws Exception { -// System.setProperty("raven.eclipse", "true"); -// setUpRavenRepository(); -// dataflow = WorkflowModelTranslator.doTranslation(loadScufl("nested_iteration.xml")); - graphController = new GraphController(dataflow, null, false, null, null, null, null) { - - @Override - public GraphEdge createGraphEdge() { - return new GraphEdge(this); - } - - @Override - public Graph createGraph() { - return new Graph(this); - } - - @Override - public GraphNode createGraphNode() { - return new GraphNode(this); - } - - @Override - public void redraw() { - - } - - }; - graphController.setPortStyle(PortStyle.NONE); - } - - @Test - @Ignore - public void testGenerateGraph() throws IOException, InterruptedException { - Graph graph = graphController.generateGraph(); - assertEquals(5, graph.getNodes().size()); - assertEquals(9, graph.getEdges().size()); - assertEquals(1, graph.getSubgraphs().size()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphEdgeTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphEdgeTest.java b/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphEdgeTest.java deleted file mode 100644 index 10a3c20..0000000 --- a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphEdgeTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.models.graph; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import net.sf.taverna.t2.workbench.models.graph.GraphEdge.ArrowStyle; - -import org.junit.Before; -import org.junit.Test; - -public class GraphEdgeTest { - - private GraphEdge edge; - - private GraphNode source; - - private GraphNode sink; - - private ArrowStyle arrowHeadStyle; - - private ArrowStyle arrowTailStyle; - - private GraphController graphController; - - @Before - public void setUp() throws Exception { - source = new GraphNode(graphController); - sink = new GraphNode(graphController); - arrowHeadStyle = ArrowStyle.DOT; - arrowTailStyle = ArrowStyle.NORMAL; - edge = new GraphEdge(graphController); - edge.setArrowHeadStyle(arrowHeadStyle); - edge.setArrowTailStyle(arrowTailStyle); - edge.setSink(sink); - edge.setSource(source); - } - - @Test - public void testEdge() { - edge = new GraphEdge(graphController); - assertNull(edge.getSource()); - assertNull(edge.getSink()); - assertNull(edge.getLabel()); - } - - @Test - public void testEdgeNodeNode() { - edge = new GraphEdge(graphController); - edge.setSource(source); - edge.setSink(sink); - assertEquals(source, edge.getSource()); - assertEquals(sink, edge.getSink()); - assertNull(edge.getLabel()); - } - - @Test - public void testGetSource() { - assertEquals(source, edge.getSource()); - } - - @Test - public void testSetSource() { - GraphNode node = new GraphNode(graphController); - edge.setSource(node); - assertEquals(node, edge.getSource()); - edge.setSource(null); - assertNull(edge.getSource()); - } - - @Test - public void testGetSink() { - assertEquals(sink, edge.getSink()); - } - - @Test - public void testSetSink() { - GraphNode node = new GraphNode(graphController); - edge.setSink(node); - assertEquals(node, edge.getSink()); - edge.setSink(null); - assertNull(edge.getSink()); - } - - @Test - public void testGetArrowHeadStyle() { - assertEquals(arrowHeadStyle, edge.getArrowHeadStyle()); - } - - @Test - public void testSetArrowHeadStyle() { - edge.setArrowHeadStyle(ArrowStyle.DOT); - assertEquals(ArrowStyle.DOT, edge.getArrowHeadStyle()); - edge.setArrowHeadStyle(null); - assertNull(edge.getArrowHeadStyle()); - } - - @Test - public void testGetArrowTailStyle() { - assertEquals(arrowTailStyle, edge.getArrowTailStyle()); - } - - @Test - public void testSetArrowTailStyle() { - edge.setArrowTailStyle(ArrowStyle.NORMAL); - assertEquals(ArrowStyle.NORMAL, edge.getArrowTailStyle()); - edge.setArrowTailStyle(null); - assertNull(edge.getArrowTailStyle()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphElementTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphElementTest.java b/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphElementTest.java deleted file mode 100644 index 8d6b7f8..0000000 --- a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphElementTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.models.graph; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.awt.Color; - -import net.sf.taverna.t2.workbench.models.graph.GraphElement.LineStyle; - -import org.junit.Before; -import org.junit.Test; - -public class GraphElementTest { - - private GraphElement element; - - private String id; - - private String label; - - private LineStyle lineStyle; - - private Color color; - - private Color fillColor; - - private GraphElement parent; - - private GraphController graphController; - - @Before - public void setUp() throws Exception { - element = new GraphElement(graphController) {}; - id = "element-id"; - label = "element-label"; - lineStyle = LineStyle.NONE; - color = Color.BLUE; - fillColor = Color.GREEN; - parent = new GraphNode(graphController); - element.setId(id); - element.setLabel(label); - element.setLineStyle(lineStyle); - element.setColor(color); - element.setFillColor(fillColor); - element.setParent(parent); - } - - @Test - public void testGetParent() { - assertEquals(parent, element.getParent()); - } - - @Test - public void testSetParent() { - GraphNode newParent = new GraphNode(graphController); - element.setParent(newParent); - assertEquals(newParent, element.getParent()); - element.setParent(null); - assertNull(element.getParent()); - } - - @Test - public void testGetLabel() { - assertEquals(label, element.getLabel()); - } - - @Test - public void testSetLabel() { - element.setLabel("new-label"); - assertEquals("new-label", element.getLabel()); - element.setLabel(null); - assertNull(element.getLabel()); - } - - @Test - public void testGetId() { - assertEquals(id, element.getId()); - } - - @Test - public void testSetId() { - element.setId("new-id"); - assertEquals("new-id", element.getId()); - element.setId(null); - assertNull(element.getId()); - } - - @Test - public void testGetColor() { - assertEquals(color, element.getColor()); - } - - @Test - public void testSetColor() { - element.setColor(Color.RED); - assertEquals(Color.RED, element.getColor()); - element.setColor(null); - assertNull(element.getColor()); - } - - @Test - public void testGetFillColor() { - assertEquals(fillColor, element.getFillColor()); - } - - @Test - public void testSetFillColor() { - element.setFillColor(Color.RED); - assertEquals(Color.RED, element.getFillColor()); - element.setFillColor(null); - assertNull(element.getFillColor()); - } - - @Test - public void testGetLineStyle() { - assertEquals(lineStyle, element.getLineStyle()); - } - - @Test - public void testSetLineStyle() { - element.setLineStyle(LineStyle.DOTTED); - assertEquals(LineStyle.DOTTED, element.getLineStyle()); - element.setLineStyle(null); - assertNull(element.getLineStyle()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphNodeTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphNodeTest.java b/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphNodeTest.java deleted file mode 100644 index c5bcd6c..0000000 --- a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphNodeTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.models.graph; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.awt.Dimension; - -import net.sf.taverna.t2.workbench.models.graph.GraphShapeElement.Shape; - -import org.junit.Before; -import org.junit.Test; - -public class GraphNodeTest { - - private GraphNode node; - - private Shape shape; - - private Dimension size; - - private Graph graph; - - private boolean expanded; - - private GraphController graphController; - - @Before - public void setUp() throws Exception { - shape = Shape.HOUSE; - size = new Dimension(1, 2); - graph = new Graph(graphController); - expanded = false; - node = new GraphNode(graphController); - node.setShape(shape); - node.setSize(size); - node.setGraph(graph); - node.setExpanded(expanded); - } - - @Test - public void testNode() { - assertNotNull(new GraphNode(graphController)); - } - - @Test - public void testAddSinkNode() { - GraphNode newNode = new GraphNode(graphController); - node.addSinkNode(newNode); - assertEquals(1, node.getSinkNodes().size()); - assertTrue(node.getSinkNodes().contains(newNode)); - assertEquals(node, newNode.getParent()); - } - - @Test - public void testAddSourceNode() { - GraphNode newNode = new GraphNode(graphController); - node.addSourceNode(newNode); - assertEquals(1, node.getSourceNodes().size()); - assertTrue(node.getSourceNodes().contains(newNode)); - assertEquals(node, newNode.getParent()); - } - - @Test - public void testGetGraph() { - assertEquals(graph, node.getGraph()); - } - - @Test - public void testGetHeight() { - assertEquals(size.height, node.getHeight(), 0); - } - - @Test - public void testGetShape() { - assertEquals(shape, node.getShape()); - } - - @Test - public void testGetSinkNodes() { - assertNotNull(node.getSinkNodes()); - assertEquals(0, node.getSinkNodes().size()); - } - - @Test - public void testGetSize() { - assertEquals(size, node.getSize()); - } - - @Test - public void testGetSourceNodes() { - assertNotNull(node.getSourceNodes()); - assertEquals(0, node.getSourceNodes().size()); - } - - @Test - public void testGetWidth() { - assertEquals(size.width, node.getWidth(), 0); - } - - @Test - public void testIsExpanded() { - assertEquals(expanded, node.isExpanded()); - } - - @Test - public void testRemoveSinkNode() { - GraphNode newNode = new GraphNode(graphController); - assertFalse(node.removeSinkNode(newNode)); - node.addSinkNode(newNode); - assertTrue(node.removeSinkNode(newNode)); - assertFalse(node.getSinkNodes().contains(newNode)); - } - - @Test - public void testRemoveSourceNode() { - GraphNode newNode = new GraphNode(graphController); - assertFalse(node.removeSourceNode(newNode)); - node.addSourceNode(newNode); - assertTrue(node.removeSourceNode(newNode)); - assertFalse(node.getSourceNodes().contains(newNode)); - } - - @Test - public void testSetExpanded() { - node.setExpanded(true); - assertEquals(true, node.isExpanded()); - node.setExpanded(false); - assertEquals(false, node.isExpanded()); - } - - @Test - public void testSetGraph() { - Graph newGraph = new Graph(graphController); - node.setGraph(newGraph); - assertEquals(newGraph, node.getGraph()); - node.setGraph(null); - assertNull(node.getGraph()); - } - - @Test - public void testSetShape() { - node.setShape(Shape.INVTRIANGLE); - assertEquals(Shape.INVTRIANGLE, node.getShape()); - node.setShape(Shape.TRIANGLE); - assertEquals(Shape.TRIANGLE, node.getShape()); - } - - @Test - public void testSetSize() { - node.setSize(new Dimension(23, 6)); - assertEquals(new Dimension(23, 6), node.getSize()); - node.setSize(new Dimension(14, 4)); - assertEquals(new Dimension(14, 4), node.getSize()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphTest.java b/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphTest.java deleted file mode 100644 index 44a5aaf..0000000 --- a/taverna-graph-model/src/test/java/net/sf/taverna/t2/workbench/models/graph/GraphTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2007 The University of Manchester - * - * Modifications to the initial code base are copyright of their - * respective authors, or their employers as appropriate. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - ******************************************************************************/ -package net.sf.taverna.t2.workbench.models.graph; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import net.sf.taverna.t2.workbench.models.graph.GraphEdge; -import net.sf.taverna.t2.workbench.models.graph.Graph; -import net.sf.taverna.t2.workbench.models.graph.GraphNode; -import net.sf.taverna.t2.workbench.models.graph.Graph.Alignment; - -import org.junit.Before; -import org.junit.Test; - -public class GraphTest { - - private Graph graph; - - private Alignment alignment; - - private GraphController graphController; - - @Before - public void setUp() throws Exception { - alignment = Alignment.VERTICAL; - graph = new Graph(graphController); - } - - @Test - public void testGraph() { - assertNotNull(new Graph(graphController)); - } - - @Test - public void testAddEdge() { - GraphEdge newEdge = new GraphEdge(graphController); - graph.addEdge(newEdge); - assertEquals(1, graph.getEdges().size()); - assertTrue(graph.getEdges().contains(newEdge)); - } - - @Test - public void testAddNode() { - GraphNode newNode = new GraphNode(graphController); - graph.addNode(newNode); - assertEquals(1, graph.getNodes().size()); - assertTrue(graph.getNodes().contains(newNode)); - assertEquals(graph, newNode.getParent()); - } - - @Test - public void testAddSubgraph() { - Graph newGraph = new Graph(graphController); - graph.addSubgraph(newGraph); - assertEquals(1, graph.getSubgraphs().size()); - assertTrue(graph.getSubgraphs().contains(newGraph)); - assertEquals(graph, newGraph.getParent()); - } - - @Test - public void testGetAlignment() { - assertEquals(alignment, graph.getAlignment()); - } - - @Test - public void testGetEdges() { - assertNotNull(graph.getNodes()); - assertEquals(0, graph.getNodes().size()); - } - - @Test - public void testGetNodes() { - assertNotNull(graph.getEdges()); - assertEquals(0, graph.getEdges().size()); - } - - @Test - public void testGetSubgraphs() { - assertNotNull(graph.getSubgraphs()); - assertEquals(0, graph.getSubgraphs().size()); - } - - @Test - public void testRemoveEdge() { - GraphEdge newEdge = new GraphEdge(graphController); - assertFalse(graph.removeEdge(newEdge)); - graph.addEdge(newEdge); - assertTrue(graph.removeEdge(newEdge)); - assertFalse(graph.getNodes().contains(newEdge)); - } - - @Test - public void testRemoveNode() { - GraphNode newNode = new GraphNode(graphController); - assertFalse(graph.removeNode(newNode)); - graph.addNode(newNode); - assertTrue(graph.removeNode(newNode)); - assertFalse(graph.getNodes().contains(newNode)); - } - - @Test - public void testRemoveSubgraph() { - Graph newGraph = new Graph(graphController); - assertFalse(graph.removeSubgraph(newGraph)); - graph.addSubgraph(newGraph); - assertTrue(graph.removeSubgraph(newGraph)); - assertFalse(graph.getSubgraphs().contains(newGraph)); - } - - @Test - public void testSetAlignment() { - graph.setAlignment(Alignment.VERTICAL); - assertEquals(Alignment.VERTICAL, graph.getAlignment()); - graph.setAlignment(Alignment.HORIZONTAL); - assertEquals(Alignment.HORIZONTAL, graph.getAlignment()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphControllerTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphControllerTest.java b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphControllerTest.java new file mode 100644 index 0000000..cda5aa8 --- /dev/null +++ b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphControllerTest.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph; + +import org.apache.taverna.workbench.models.graph.GraphNode; +import org.apache.taverna.workbench.models.graph.Graph; +import org.apache.taverna.workbench.models.graph.GraphEdge; +import org.apache.taverna.workbench.models.graph.GraphController; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.taverna.workbench.models.graph.GraphController.PortStyle; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import org.apache.taverna.scufl2.api.core.Workflow; + +public class GraphControllerTest { + + Workflow dataflow; + + GraphController graphController; + + @Before + public void setUp() throws Exception { +// System.setProperty("raven.eclipse", "true"); +// setUpRavenRepository(); +// dataflow = WorkflowModelTranslator.doTranslation(loadScufl("nested_iteration.xml")); + graphController = new GraphController(dataflow, null, false, null, null, null, null) { + + @Override + public GraphEdge createGraphEdge() { + return new GraphEdge(this); + } + + @Override + public Graph createGraph() { + return new Graph(this); + } + + @Override + public GraphNode createGraphNode() { + return new GraphNode(this); + } + + @Override + public void redraw() { + + } + + }; + graphController.setPortStyle(PortStyle.NONE); + } + + @Test + @Ignore + public void testGenerateGraph() throws IOException, InterruptedException { + Graph graph = graphController.generateGraph(); + assertEquals(5, graph.getNodes().size()); + assertEquals(9, graph.getEdges().size()); + assertEquals(1, graph.getSubgraphs().size()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphEdgeTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphEdgeTest.java b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphEdgeTest.java new file mode 100644 index 0000000..ba47a35 --- /dev/null +++ b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphEdgeTest.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph; + +import org.apache.taverna.workbench.models.graph.GraphNode; +import org.apache.taverna.workbench.models.graph.GraphEdge; +import org.apache.taverna.workbench.models.graph.GraphController; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import org.apache.taverna.workbench.models.graph.GraphEdge.ArrowStyle; + +import org.junit.Before; +import org.junit.Test; + +public class GraphEdgeTest { + + private GraphEdge edge; + + private GraphNode source; + + private GraphNode sink; + + private ArrowStyle arrowHeadStyle; + + private ArrowStyle arrowTailStyle; + + private GraphController graphController; + + @Before + public void setUp() throws Exception { + source = new GraphNode(graphController); + sink = new GraphNode(graphController); + arrowHeadStyle = ArrowStyle.DOT; + arrowTailStyle = ArrowStyle.NORMAL; + edge = new GraphEdge(graphController); + edge.setArrowHeadStyle(arrowHeadStyle); + edge.setArrowTailStyle(arrowTailStyle); + edge.setSink(sink); + edge.setSource(source); + } + + @Test + public void testEdge() { + edge = new GraphEdge(graphController); + assertNull(edge.getSource()); + assertNull(edge.getSink()); + assertNull(edge.getLabel()); + } + + @Test + public void testEdgeNodeNode() { + edge = new GraphEdge(graphController); + edge.setSource(source); + edge.setSink(sink); + assertEquals(source, edge.getSource()); + assertEquals(sink, edge.getSink()); + assertNull(edge.getLabel()); + } + + @Test + public void testGetSource() { + assertEquals(source, edge.getSource()); + } + + @Test + public void testSetSource() { + GraphNode node = new GraphNode(graphController); + edge.setSource(node); + assertEquals(node, edge.getSource()); + edge.setSource(null); + assertNull(edge.getSource()); + } + + @Test + public void testGetSink() { + assertEquals(sink, edge.getSink()); + } + + @Test + public void testSetSink() { + GraphNode node = new GraphNode(graphController); + edge.setSink(node); + assertEquals(node, edge.getSink()); + edge.setSink(null); + assertNull(edge.getSink()); + } + + @Test + public void testGetArrowHeadStyle() { + assertEquals(arrowHeadStyle, edge.getArrowHeadStyle()); + } + + @Test + public void testSetArrowHeadStyle() { + edge.setArrowHeadStyle(ArrowStyle.DOT); + assertEquals(ArrowStyle.DOT, edge.getArrowHeadStyle()); + edge.setArrowHeadStyle(null); + assertNull(edge.getArrowHeadStyle()); + } + + @Test + public void testGetArrowTailStyle() { + assertEquals(arrowTailStyle, edge.getArrowTailStyle()); + } + + @Test + public void testSetArrowTailStyle() { + edge.setArrowTailStyle(ArrowStyle.NORMAL); + assertEquals(ArrowStyle.NORMAL, edge.getArrowTailStyle()); + edge.setArrowTailStyle(null); + assertNull(edge.getArrowTailStyle()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphElementTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphElementTest.java b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphElementTest.java new file mode 100644 index 0000000..623566a --- /dev/null +++ b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphElementTest.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph; + + +import org.apache.taverna.workbench.models.graph.GraphNode; +import org.apache.taverna.workbench.models.graph.GraphController; +import org.apache.taverna.workbench.models.graph.GraphElement; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.awt.Color; + +import org.apache.taverna.workbench.models.graph.GraphElement.LineStyle; + +import org.junit.Before; +import org.junit.Test; + +public class GraphElementTest { + + private GraphElement element; + + private String id; + + private String label; + + private LineStyle lineStyle; + + private Color color; + + private Color fillColor; + + private GraphElement parent; + + private GraphController graphController; + + @Before + public void setUp() throws Exception { + element = new GraphElement(graphController) {}; + id = "element-id"; + label = "element-label"; + lineStyle = LineStyle.NONE; + color = Color.BLUE; + fillColor = Color.GREEN; + parent = new GraphNode(graphController); + element.setId(id); + element.setLabel(label); + element.setLineStyle(lineStyle); + element.setColor(color); + element.setFillColor(fillColor); + element.setParent(parent); + } + + @Test + public void testGetParent() { + assertEquals(parent, element.getParent()); + } + + @Test + public void testSetParent() { + GraphNode newParent = new GraphNode(graphController); + element.setParent(newParent); + assertEquals(newParent, element.getParent()); + element.setParent(null); + assertNull(element.getParent()); + } + + @Test + public void testGetLabel() { + assertEquals(label, element.getLabel()); + } + + @Test + public void testSetLabel() { + element.setLabel("new-label"); + assertEquals("new-label", element.getLabel()); + element.setLabel(null); + assertNull(element.getLabel()); + } + + @Test + public void testGetId() { + assertEquals(id, element.getId()); + } + + @Test + public void testSetId() { + element.setId("new-id"); + assertEquals("new-id", element.getId()); + element.setId(null); + assertNull(element.getId()); + } + + @Test + public void testGetColor() { + assertEquals(color, element.getColor()); + } + + @Test + public void testSetColor() { + element.setColor(Color.RED); + assertEquals(Color.RED, element.getColor()); + element.setColor(null); + assertNull(element.getColor()); + } + + @Test + public void testGetFillColor() { + assertEquals(fillColor, element.getFillColor()); + } + + @Test + public void testSetFillColor() { + element.setFillColor(Color.RED); + assertEquals(Color.RED, element.getFillColor()); + element.setFillColor(null); + assertNull(element.getFillColor()); + } + + @Test + public void testGetLineStyle() { + assertEquals(lineStyle, element.getLineStyle()); + } + + @Test + public void testSetLineStyle() { + element.setLineStyle(LineStyle.DOTTED); + assertEquals(LineStyle.DOTTED, element.getLineStyle()); + element.setLineStyle(null); + assertNull(element.getLineStyle()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphNodeTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphNodeTest.java b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphNodeTest.java new file mode 100644 index 0000000..20410f7 --- /dev/null +++ b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphNodeTest.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph; + +import org.apache.taverna.workbench.models.graph.GraphNode; +import org.apache.taverna.workbench.models.graph.Graph; +import org.apache.taverna.workbench.models.graph.GraphController; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.awt.Dimension; + +import org.apache.taverna.workbench.models.graph.GraphShapeElement.Shape; + +import org.junit.Before; +import org.junit.Test; + +public class GraphNodeTest { + + private GraphNode node; + + private Shape shape; + + private Dimension size; + + private Graph graph; + + private boolean expanded; + + private GraphController graphController; + + @Before + public void setUp() throws Exception { + shape = Shape.HOUSE; + size = new Dimension(1, 2); + graph = new Graph(graphController); + expanded = false; + node = new GraphNode(graphController); + node.setShape(shape); + node.setSize(size); + node.setGraph(graph); + node.setExpanded(expanded); + } + + @Test + public void testNode() { + assertNotNull(new GraphNode(graphController)); + } + + @Test + public void testAddSinkNode() { + GraphNode newNode = new GraphNode(graphController); + node.addSinkNode(newNode); + assertEquals(1, node.getSinkNodes().size()); + assertTrue(node.getSinkNodes().contains(newNode)); + assertEquals(node, newNode.getParent()); + } + + @Test + public void testAddSourceNode() { + GraphNode newNode = new GraphNode(graphController); + node.addSourceNode(newNode); + assertEquals(1, node.getSourceNodes().size()); + assertTrue(node.getSourceNodes().contains(newNode)); + assertEquals(node, newNode.getParent()); + } + + @Test + public void testGetGraph() { + assertEquals(graph, node.getGraph()); + } + + @Test + public void testGetHeight() { + assertEquals(size.height, node.getHeight(), 0); + } + + @Test + public void testGetShape() { + assertEquals(shape, node.getShape()); + } + + @Test + public void testGetSinkNodes() { + assertNotNull(node.getSinkNodes()); + assertEquals(0, node.getSinkNodes().size()); + } + + @Test + public void testGetSize() { + assertEquals(size, node.getSize()); + } + + @Test + public void testGetSourceNodes() { + assertNotNull(node.getSourceNodes()); + assertEquals(0, node.getSourceNodes().size()); + } + + @Test + public void testGetWidth() { + assertEquals(size.width, node.getWidth(), 0); + } + + @Test + public void testIsExpanded() { + assertEquals(expanded, node.isExpanded()); + } + + @Test + public void testRemoveSinkNode() { + GraphNode newNode = new GraphNode(graphController); + assertFalse(node.removeSinkNode(newNode)); + node.addSinkNode(newNode); + assertTrue(node.removeSinkNode(newNode)); + assertFalse(node.getSinkNodes().contains(newNode)); + } + + @Test + public void testRemoveSourceNode() { + GraphNode newNode = new GraphNode(graphController); + assertFalse(node.removeSourceNode(newNode)); + node.addSourceNode(newNode); + assertTrue(node.removeSourceNode(newNode)); + assertFalse(node.getSourceNodes().contains(newNode)); + } + + @Test + public void testSetExpanded() { + node.setExpanded(true); + assertEquals(true, node.isExpanded()); + node.setExpanded(false); + assertEquals(false, node.isExpanded()); + } + + @Test + public void testSetGraph() { + Graph newGraph = new Graph(graphController); + node.setGraph(newGraph); + assertEquals(newGraph, node.getGraph()); + node.setGraph(null); + assertNull(node.getGraph()); + } + + @Test + public void testSetShape() { + node.setShape(Shape.INVTRIANGLE); + assertEquals(Shape.INVTRIANGLE, node.getShape()); + node.setShape(Shape.TRIANGLE); + assertEquals(Shape.TRIANGLE, node.getShape()); + } + + @Test + public void testSetSize() { + node.setSize(new Dimension(23, 6)); + assertEquals(new Dimension(23, 6), node.getSize()); + node.setSize(new Dimension(14, 4)); + assertEquals(new Dimension(14, 4), node.getSize()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphTest.java ---------------------------------------------------------------------- diff --git a/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphTest.java b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphTest.java new file mode 100644 index 0000000..ec7f251 --- /dev/null +++ b/taverna-graph-model/src/test/java/org/apache/taverna/workbench/models/graph/GraphTest.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (C) 2007 The University of Manchester + * + * Modifications to the initial code base are copyright of their + * respective authors, or their employers as appropriate. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + ******************************************************************************/ +package org.apache.taverna.workbench.models.graph; + +import org.apache.taverna.workbench.models.graph.GraphController; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.apache.taverna.workbench.models.graph.GraphEdge; +import org.apache.taverna.workbench.models.graph.Graph; +import org.apache.taverna.workbench.models.graph.GraphNode; +import org.apache.taverna.workbench.models.graph.Graph.Alignment; + +import org.junit.Before; +import org.junit.Test; + +public class GraphTest { + + private Graph graph; + + private Alignment alignment; + + private GraphController graphController; + + @Before + public void setUp() throws Exception { + alignment = Alignment.VERTICAL; + graph = new Graph(graphController); + } + + @Test + public void testGraph() { + assertNotNull(new Graph(graphController)); + } + + @Test + public void testAddEdge() { + GraphEdge newEdge = new GraphEdge(graphController); + graph.addEdge(newEdge); + assertEquals(1, graph.getEdges().size()); + assertTrue(graph.getEdges().contains(newEdge)); + } + + @Test + public void testAddNode() { + GraphNode newNode = new GraphNode(graphController); + graph.addNode(newNode); + assertEquals(1, graph.getNodes().size()); + assertTrue(graph.getNodes().contains(newNode)); + assertEquals(graph, newNode.getParent()); + } + + @Test + public void testAddSubgraph() { + Graph newGraph = new Graph(graphController); + graph.addSubgraph(newGraph); + assertEquals(1, graph.getSubgraphs().size()); + assertTrue(graph.getSubgraphs().contains(newGraph)); + assertEquals(graph, newGraph.getParent()); + } + + @Test + public void testGetAlignment() { + assertEquals(alignment, graph.getAlignment()); + } + + @Test + public void testGetEdges() { + assertNotNull(graph.getNodes()); + assertEquals(0, graph.getNodes().size()); + } + + @Test + public void testGetNodes() { + assertNotNull(graph.getEdges()); + assertEquals(0, graph.getEdges().size()); + } + + @Test + public void testGetSubgraphs() { + assertNotNull(graph.getSubgraphs()); + assertEquals(0, graph.getSubgraphs().size()); + } + + @Test + public void testRemoveEdge() { + GraphEdge newEdge = new GraphEdge(graphController); + assertFalse(graph.removeEdge(newEdge)); + graph.addEdge(newEdge); + assertTrue(graph.removeEdge(newEdge)); + assertFalse(graph.getNodes().contains(newEdge)); + } + + @Test + public void testRemoveNode() { + GraphNode newNode = new GraphNode(graphController); + assertFalse(graph.removeNode(newNode)); + graph.addNode(newNode); + assertTrue(graph.removeNode(newNode)); + assertFalse(graph.getNodes().contains(newNode)); + } + + @Test + public void testRemoveSubgraph() { + Graph newGraph = new Graph(graphController); + assertFalse(graph.removeSubgraph(newGraph)); + graph.addSubgraph(newGraph); + assertTrue(graph.removeSubgraph(newGraph)); + assertFalse(graph.getSubgraphs().contains(newGraph)); + } + + @Test + public void testSetAlignment() { + graph.setAlignment(Alignment.VERTICAL); + assertEquals(Alignment.VERTICAL, graph.getAlignment()); + graph.setAlignment(Alignment.HORIZONTAL); + assertEquals(Alignment.HORIZONTAL, graph.getAlignment()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponent.java ---------------------------------------------------------------------- diff --git a/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponent.java b/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponent.java index ef1ac2c..dac96ab 100644 --- a/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponent.java +++ b/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponent.java @@ -25,15 +25,15 @@ import static java.awt.BorderLayout.NORTH; import static javax.swing.Action.SHORT_DESCRIPTION; import static javax.swing.Action.SMALL_ICON; import static javax.swing.BoxLayout.PAGE_AXIS; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.allportIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.blobIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.expandNestedIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.horizontalIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.noportIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.refreshIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.verticalIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.zoomInIcon; -import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.zoomOutIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.allportIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.blobIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.expandNestedIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.horizontalIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.noportIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.refreshIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.verticalIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.zoomInIcon; +import static org.apache.taverna.workbench.icons.WorkbenchIcons.zoomOutIcon; import static net.sf.taverna.t2.workbench.views.graph.config.GraphViewConfiguration.ALIGNMENT; import static net.sf.taverna.t2.workbench.views.graph.config.GraphViewConfiguration.ANIMATION_ENABLED; import static net.sf.taverna.t2.workbench.views.graph.config.GraphViewConfiguration.ANIMATION_SPEED; @@ -65,25 +65,25 @@ import javax.swing.border.EmptyBorder; import org.apache.taverna.lang.observer.Observable; import org.apache.taverna.lang.observer.SwingAwareObserver; -import net.sf.taverna.t2.ui.menu.MenuManager; -import net.sf.taverna.t2.workbench.configuration.colour.ColourManager; -import net.sf.taverna.t2.workbench.configuration.workbench.WorkbenchConfiguration; -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.edits.EditManager.AbstractDataflowEditEvent; -import net.sf.taverna.t2.workbench.edits.EditManager.EditManagerEvent; -import net.sf.taverna.t2.workbench.file.FileManager; -import net.sf.taverna.t2.workbench.file.events.ClosedDataflowEvent; -import net.sf.taverna.t2.workbench.file.events.FileManagerEvent; -import net.sf.taverna.t2.workbench.models.graph.Graph.Alignment; -import net.sf.taverna.t2.workbench.models.graph.GraphController; -import net.sf.taverna.t2.workbench.models.graph.GraphController.PortStyle; -import net.sf.taverna.t2.workbench.models.graph.svg.SVGGraphController; -import net.sf.taverna.t2.workbench.selection.SelectionManager; -import net.sf.taverna.t2.workbench.selection.events.SelectionManagerEvent; -import net.sf.taverna.t2.workbench.selection.events.WorkflowBundleSelectionEvent; -import net.sf.taverna.t2.workbench.selection.events.WorkflowSelectionEvent; -import net.sf.taverna.t2.workbench.ui.dndhandler.ServiceTransferHandler; -import net.sf.taverna.t2.workbench.ui.zaria.UIComponentSPI; +import org.apache.taverna.ui.menu.MenuManager; +import org.apache.taverna.workbench.configuration.colour.ColourManager; +import org.apache.taverna.workbench.configuration.workbench.WorkbenchConfiguration; +import org.apache.taverna.workbench.edits.EditManager; +import org.apache.taverna.workbench.edits.EditManager.AbstractDataflowEditEvent; +import org.apache.taverna.workbench.edits.EditManager.EditManagerEvent; +import org.apache.taverna.workbench.file.FileManager; +import org.apache.taverna.workbench.file.events.ClosedDataflowEvent; +import org.apache.taverna.workbench.file.events.FileManagerEvent; +import org.apache.taverna.workbench.models.graph.Graph.Alignment; +import org.apache.taverna.workbench.models.graph.GraphController; +import org.apache.taverna.workbench.models.graph.GraphController.PortStyle; +import org.apache.taverna.workbench.models.graph.svg.SVGGraphController; +import org.apache.taverna.workbench.selection.SelectionManager; +import org.apache.taverna.workbench.selection.events.SelectionManagerEvent; +import org.apache.taverna.workbench.selection.events.WorkflowBundleSelectionEvent; +import org.apache.taverna.workbench.selection.events.WorkflowSelectionEvent; +import org.apache.taverna.workbench.ui.dndhandler.ServiceTransferHandler; +import org.apache.taverna.workbench.ui.zaria.UIComponentSPI; import net.sf.taverna.t2.workbench.views.graph.config.GraphViewConfiguration; import net.sf.taverna.t2.workbench.views.graph.menu.ResetDiagramAction; import net.sf.taverna.t2.workbench.views.graph.menu.ZoomInAction; http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponentFactory.java ---------------------------------------------------------------------- diff --git a/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponentFactory.java b/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponentFactory.java index 388c874..4f603d6 100644 --- a/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponentFactory.java +++ b/taverna-graph-view/src/main/java/net/sf/taverna/t2/workbench/views/graph/GraphViewComponentFactory.java @@ -24,14 +24,14 @@ import javax.swing.ImageIcon; import org.apache.taverna.commons.services.ServiceRegistry; -import net.sf.taverna.t2.ui.menu.MenuManager; -import net.sf.taverna.t2.workbench.configuration.colour.ColourManager; -import net.sf.taverna.t2.workbench.configuration.workbench.WorkbenchConfiguration; -import net.sf.taverna.t2.workbench.edits.EditManager; -import net.sf.taverna.t2.workbench.file.FileManager; -import net.sf.taverna.t2.workbench.selection.SelectionManager; -import net.sf.taverna.t2.workbench.ui.zaria.UIComponentFactorySPI; -import net.sf.taverna.t2.workbench.ui.zaria.UIComponentSPI; +import org.apache.taverna.ui.menu.MenuManager; +import org.apache.taverna.workbench.configuration.colour.ColourManager; +import org.apache.taverna.workbench.configuration.workbench.WorkbenchConfiguration; +import org.apache.taverna.workbench.edits.EditManager; +import org.apache.taverna.workbench.file.FileManager; +import org.apache.taverna.workbench.selection.SelectionManager; +import org.apache.taverna.workbench.ui.zaria.UIComponentFactorySPI; +import org.apache.taverna.workbench.ui.zaria.UIComponentSPI; import net.sf.taverna.t2.workbench.views.graph.config.GraphViewConfiguration; /**
