X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fconnection%2FConnectionVisuals.java;h=e7a31692b5ea2cb22a5bda1bd044bdd3a199ad8c;hp=a689460e3b0966462e6b556538744eed2d2d67da;hb=e3f46ffc9d4a6930adc83ebb8e6730f19708cc94;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/connection/ConnectionVisuals.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/connection/ConnectionVisuals.java index a689460e3..e7a31692b 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/connection/ConnectionVisuals.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/connection/ConnectionVisuals.java @@ -1,79 +1,107 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.connection; - -import java.awt.Color; -import java.awt.Stroke; -import java.util.Arrays; - -import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType; - -/** - * @author Tuukka Lehtonen - */ -public class ConnectionVisuals { - - public final float[] color; - public final StrokeType strokeType; - public final Stroke stroke; - - public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke) { - if (color != null && color.length < 3) - throw new IllegalArgumentException("colors must have at least 3 components (rgb), got " + color.length); - this.color = color; - this.strokeType = strokeType; - this.stroke = stroke; - } - - public Color toColor() { - if (color == null) - return null; - if (color.length == 3) - return new Color(color[2], color[1], color[0]); - return new Color(color[2], color[1], color[0], color[3]); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Arrays.hashCode(color); - result = prime * result + ((stroke == null) ? 0 : stroke.hashCode()); - result = prime * result + ((strokeType == null) ? 0 : strokeType.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof ConnectionVisuals)) - return false; - ConnectionVisuals other = (ConnectionVisuals) obj; - if (!Arrays.equals(color, other.color)) - return false; - if (stroke == null) { - if (other.stroke != null) - return false; - } else if (!stroke.equals(other.stroke)) - return false; - if (strokeType == null) { - if (other.strokeType != null) - return false; - } else if (!strokeType.equals(other.strokeType)) - return false; - return true; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.connection; + +import java.awt.Color; +import java.awt.Stroke; +import java.util.Arrays; + +import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType; + +/** + * @author Tuukka Lehtonen + */ +public class ConnectionVisuals { + + public final float[] color; + public final StrokeType strokeType; + public final Stroke stroke; + public final Double branchPointRadius; + public final Double rounding; + public final Double offset; + + public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke, Double rounding) { + this(color, strokeType, stroke, null, rounding); + } + + public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke, Double branchPointRadius, Double rounding) { + this(color, strokeType, stroke, null, rounding, null); + } + + public ConnectionVisuals(float[] color, StrokeType strokeType, Stroke stroke, Double branchPointRadius, Double rounding, Double offset) { + if (color != null && color.length < 3) + throw new IllegalArgumentException("colors must have at least 3 components (rgb), got " + color.length); + this.color = color; + this.strokeType = strokeType; + this.stroke = stroke; + this.branchPointRadius = branchPointRadius; + this.rounding = rounding; + this.offset = offset; + } + + public Color toColor() { + if (color == null) + return null; + if (color.length == 3) + return new Color(color[2], color[1], color[0]); + return new Color(color[2], color[1], color[0], color[3]); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((branchPointRadius == null) ? 0 : branchPointRadius.hashCode()); + result = prime * result + Arrays.hashCode(color); + result = prime * result + ((rounding == null) ? 0 : rounding.hashCode()); + result = prime * result + ((offset == null) ? 0 : offset.hashCode()); + result = prime * result + ((stroke == null) ? 0 : stroke.hashCode()); + result = prime * result + ((strokeType == null) ? 0 : strokeType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ConnectionVisuals other = (ConnectionVisuals) obj; + if (branchPointRadius == null) { + if (other.branchPointRadius != null) + return false; + } else if (!branchPointRadius.equals(other.branchPointRadius)) + return false; + if (!Arrays.equals(color, other.color)) + return false; + if (rounding == null) { + if (other.rounding != null) + return false; + } else if (!rounding.equals(other.rounding)) + return false; + if (offset == null) { + if (other.offset != null) + return false; + } else if (!offset.equals(other.offset)) + return false; + if (stroke == null) { + if (other.stroke != null) + return false; + } else if (!stroke.equals(other.stroke)) + return false; + if (strokeType != other.strokeType) + return false; + return true; + } +}