X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fnodes%2FDistrictNetworkVertexNode.java;h=8dcd5183a6cb1545ad201b681f45fefbe9d5adc6;hb=16ee01dc5a40981c58fd5b478b89552e5814e8bb;hp=a126ee5942a841f50a2108684a364a78052a4554;hpb=9dace20146d19dd0541480a80fd289de45b6cfc8;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java index a126ee59..8dcd5183 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java @@ -11,21 +11,27 @@ import java.awt.geom.Rectangle2D; import org.simantics.district.network.ui.adapters.DistrictNetworkVertex; import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.utils.GeometryUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class DistrictNetworkVertexNode extends G2DNode { + private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkVertexNode.class); + private static final long serialVersionUID = -2641639101400236719L; private DistrictNetworkVertex vertex; + + private static final double left = -0.5; + private static final double top = -0.5; + private static final double width = 1; + private static final double height = 1; - private static final double scale = 1; - - private double left = -0.5; - private double top = -0.5; - private double width = 1; - private double height = 1; + private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height); + private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 2, top * 2, width * 2, height * 2); private Stroke stroke = new BasicStroke(2); private boolean scaleStroke = true; + private boolean hover; @Override public void init() { @@ -48,18 +54,24 @@ public class DistrictNetworkVertexNode extends G2DNode { Stroke oldStroke = g2d.getStroke(); g2d.setColor(Color.RED); - if (stroke != null) { - if (scaleStroke && stroke instanceof BasicStroke) { - BasicStroke bs = GeometryUtils.scaleStroke(stroke, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform()))); - g2d.setStroke(bs); - } else { - g2d.setStroke(stroke); - } + + double scaleRecip = 1; + if (scaleStroke) { + double scale = GeometryUtils.getScale(g2d.getTransform()); + + //System.out.println("scale: " + scale); + scaleRecip = 1.0 / scale; } - // render + scaleRecip = 8.0 * scaleRecip; - Rectangle2D.Double rect = new Rectangle2D.Double(left / scale, top / scale, width / scale, height / scale); - g2d.draw(rect); + Rectangle2D toDraw; + if (hover) { + toDraw = new Rectangle2D.Double(HOVERED.getX() * scaleRecip, HOVERED.getY() * scaleRecip, HOVERED.getWidth() * scaleRecip, HOVERED.getHeight() * scaleRecip); + } else { + toDraw = new Rectangle2D.Double(NORMAL.getX() * scaleRecip, NORMAL.getY() * scaleRecip, NORMAL.getWidth() * scaleRecip, NORMAL.getHeight() * scaleRecip); + } + // render + g2d.fill(toDraw); // Reset stats g2d.setColor(oldColor); @@ -73,11 +85,22 @@ public class DistrictNetworkVertexNode extends G2DNode { @Override public Rectangle2D getBoundsInLocal() { - return new Rectangle2D.Double(left / scale, top / scale, width / scale, height / scale); + return NORMAL; } public void setVertex(DistrictNetworkVertex vertex) { this.vertex = vertex; } + public boolean hover(boolean hover) { +// if (hover && LOGGER.isDebugEnabled()) +// LOGGER.debug("Hovering " + this); + boolean changed = false; + if (this.hover != hover) { + this.hover = hover; + changed = true; + } + return changed; + } + }