1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.elements;
14 import java.awt.BasicStroke;
15 import java.awt.Color;
17 import java.awt.FontMetrics;
18 import java.awt.Graphics2D;
19 import java.awt.Rectangle;
20 import java.awt.Shape;
21 import java.awt.geom.AffineTransform;
22 import java.awt.geom.Path2D;
23 import java.awt.geom.Point2D;
24 import java.awt.geom.Rectangle2D;
25 import java.util.EnumSet;
28 import javax.vecmath.Vector2d;
30 import org.simantics.db.layer0.variable.RVI;
31 import org.simantics.g2d.diagram.IDiagram;
32 import org.simantics.g2d.element.ElementClass;
33 import org.simantics.g2d.element.ElementHints;
34 import org.simantics.g2d.element.ElementUtils;
35 import org.simantics.g2d.element.IElement;
36 import org.simantics.g2d.element.SceneGraphNodeKey;
37 import org.simantics.g2d.element.handler.ElementHandler;
38 import org.simantics.g2d.element.handler.FillColor;
39 import org.simantics.g2d.element.handler.InternalSize;
40 import org.simantics.g2d.element.handler.LifeCycle;
41 import org.simantics.g2d.element.handler.Move;
42 import org.simantics.g2d.element.handler.Outline;
43 import org.simantics.g2d.element.handler.Rotate;
44 import org.simantics.g2d.element.handler.Scale;
45 import org.simantics.g2d.element.handler.SceneGraph;
46 import org.simantics.g2d.element.handler.StaticSymbol;
47 import org.simantics.g2d.element.handler.Text;
48 import org.simantics.g2d.element.handler.TextEditor;
49 import org.simantics.g2d.element.handler.TextEditor.Modifier;
50 import org.simantics.g2d.element.handler.Transform;
51 import org.simantics.g2d.element.handler.impl.BorderColorImpl;
52 import org.simantics.g2d.element.handler.impl.FillColorImpl;
53 import org.simantics.g2d.element.handler.impl.ParentImpl;
54 import org.simantics.g2d.element.handler.impl.SimpleElementLayers;
55 import org.simantics.g2d.element.handler.impl.StaticSymbolImpl;
56 import org.simantics.g2d.element.handler.impl.TextColorImpl;
57 import org.simantics.g2d.element.handler.impl.TextEditorImpl;
58 import org.simantics.g2d.element.handler.impl.TextFontImpl;
59 import org.simantics.g2d.element.handler.impl.TextImpl;
60 import org.simantics.g2d.elementclass.MonitorHandler;
61 import org.simantics.g2d.image.Image;
62 import org.simantics.g2d.image.ProviderUtils;
63 import org.simantics.g2d.image.impl.AbstractImage;
64 import org.simantics.g2d.utils.Alignment;
65 import org.simantics.scenegraph.Node;
66 import org.simantics.scenegraph.g2d.G2DParentNode;
67 import org.simantics.scenegraph.g2d.nodes.ShapeNode;
68 import org.simantics.scl.runtime.function.Function1;
69 import org.simantics.utils.datastructures.cache.IFactory;
70 import org.simantics.utils.datastructures.cache.IProvider;
71 import org.simantics.utils.datastructures.cache.ProvisionException;
72 import org.simantics.utils.datastructures.hints.IHintContext.Key;
73 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
74 import org.simantics.utils.strings.format.MetricsFormat;
75 import org.simantics.utils.strings.format.MetricsFormatList;
78 * @author Tuukka Lehtonen
80 public class MonitorClass {
82 static final Font FONT = Font.decode("Helvetica 12");
85 * Back-end specific object describing the monitored component.
87 public static final Key KEY_MONITOR_COMPONENT = new KeyOf(Object.class, "MONITOR_COMPONENT");
90 * Existence of this hint indicates that the monitor is showing a value that
91 * does not originate from the owner diagram.
93 public static final Key KEY_MONITOR_IS_EXTERNAL = new KeyOf(Boolean.class, "MONITOR_IS_EXTERNAL");
96 * The valuation suffix string describing the monitored variable of the
97 * component described by {@link #KEY_MONITOR_COMPONENT}.
99 public static final Key KEY_MONITOR_SUFFIX = new KeyOf(String.class, "MONITOR_SUFFIX");
101 public static final Key KEY_MONITOR_SUBSTITUTIONS = new KeyOf(Map.class, "MONITOR_SUBSTITUTIONS");
102 public static final Key KEY_MONITOR_GC = new KeyOf(Graphics2D.class, "MONITOR_GC");
103 public static final Key KEY_MONITOR_HEIGHT = new KeyOf(Double.class, "MONITOR_HEIGHT");
104 public static final Key KEY_NUMBER_FORMAT = new KeyOf(MetricsFormat.class, "NUMBER_FORMAT");
105 public static final Key KEY_TOOLTIP_TEXT = new KeyOf(String.class, "TOOLTIP_TEXT");
107 public static final Key KEY_EXPRESSION = new KeyOf(String.class, "EXPRESSION");
108 public static final Key KEY_INPUT_VALIDATOR = new KeyOf(Object.class, "INPUT_VALIDATOR");
109 public static final Key KEY_RVI = new KeyOf(RVI.class, "RVI");
112 * If this hint is defined, the monitor will force its x-axis to match this
113 * angle. If this hint doesn't exist, the monitor will not force x-axis
116 public static final Key KEY_DIRECTION = new KeyOf(Double.class, "MONITOR_DIRECTION");
118 public static final Key KEY_BORDER_WIDTH = new KeyOf(Double.class, "MONITOR_BORDER");
120 public static final Key KEY_SG_NODE = new SceneGraphNodeKey(TextNode.class, "MONITOR_SG_NODE");
121 public static final Key KEY_SG_NODE2 = new SceneGraphNodeKey(ShapeNode.class, "MONITOR_SG_NODE2");
123 final static BasicStroke STROKE = new BasicStroke(1.0f);
125 public final static Alignment DEFAULT_HORIZONTAL_ALIGN = Alignment.CENTER;
126 public final static Alignment DEFAULT_VERTICAL_ALIGN = Alignment.CENTER;
127 public final static MetricsFormat DEFAULT_NUMBER_FORMAT = MetricsFormatList.METRICS_DECIMAL;
129 public final static Color DEFAULT_FILL_COLOR = new Color(224, 224, 224);
130 public final static Color DEFAULT_BORDER_COLOR = Color.BLACK;
132 public final static double DEFAULT_HORIZONTAL_MARGIN = 5.0;
133 public final static double DEFAULT_VERTICAL_MARGIN = 2.5;
135 static Alignment getHorizontalAlignment(IElement e) {
136 return ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, DEFAULT_HORIZONTAL_ALIGN);
139 static Alignment getVerticalAlignment(IElement e) {
140 return ElementUtils.getHintOrDefault(e, ElementHints.KEY_VERTICAL_ALIGN, DEFAULT_VERTICAL_ALIGN);
143 static MetricsFormat getNumberFormat(IElement e) {
144 return ElementUtils.getHintOrDefault(e, KEY_NUMBER_FORMAT, DEFAULT_NUMBER_FORMAT);
147 static void setNumberFormat(IElement e, MetricsFormat f) {
148 ElementUtils.setOrRemoveHint(e, KEY_NUMBER_FORMAT, f);
151 static double getHorizontalMargin(IElement e) {
152 return DEFAULT_HORIZONTAL_MARGIN;
155 static double getVerticalMargin(IElement e) {
156 return DEFAULT_VERTICAL_MARGIN;
159 static Font getFont(IElement e) {
160 return ElementUtils.getHintOrDefault(e, ElementHints.KEY_FONT, FONT);
163 public static class MonitorHandlerImpl implements MonitorHandler {
164 private static final long serialVersionUID = -4258875745321808416L;
165 public static final MonitorHandler INSTANCE = new MonitorHandlerImpl();
168 static class Initializer implements LifeCycle {
169 private static final long serialVersionUID = 4404942036933073584L;
171 IElement parentElement;
172 Map<String, String> substitutions;
177 Initializer(IElement parentElement, Map<String, String> substitutions, Object component, String suffix, boolean hack) {
178 this.parentElement = parentElement;
179 this.substitutions = substitutions;
180 this.component = component;
181 this.suffix = suffix;
186 public void onElementActivated(IDiagram d, IElement e) {
190 Point2D parentPos = ElementUtils.getPos(parentElement);
191 Point2D thisPos = ElementUtils.getPos(e);
193 Move move = e.getElementClass().getSingleItem(Move.class);
194 move.moveTo(e, thisPos.getX() - parentPos.getX(), thisPos.getY() - parentPos.getY());
198 public void onElementCreated(IElement e) {
199 if(parentElement != null) e.setHint(ElementHints.KEY_PARENT_ELEMENT, parentElement);
200 if(substitutions != null) e.setHint(KEY_MONITOR_SUBSTITUTIONS, substitutions);
201 if(component != null) e.setHint(KEY_MONITOR_COMPONENT, component);
202 if(suffix != null) e.setHint(KEY_MONITOR_SUFFIX, suffix);
203 e.setHint(KEY_DIRECTION, 0.0);
204 e.setHint(KEY_NUMBER_FORMAT, DEFAULT_NUMBER_FORMAT);
205 //e.setHint(KEY_HORIZONTAL_ALIGN, Alignment.LEADING);
206 //e.setHint(KEY_VERTICAL_ALIGN, Alignment.LEADING);
210 public void onElementDestroyed(IElement e) {
214 public void onElementDeactivated(IDiagram d, IElement e) {
218 static String finalText(IElement e) {
219 String text = e.getElementClass().getSingleItem(Text.class).getText(e);
222 return substitute(text, e);
225 public static String editText(IElement e) {
226 return substitute("#v1", e);
229 private static String formValue(IElement e) {
230 // TODO: consider using substitute
231 Map<String, String> substitutions = e.getHint(KEY_MONITOR_SUBSTITUTIONS);
232 if (substitutions != null) {
233 String value = substitutions.get("#v1");
234 if (substitutions.containsKey("#u1") && substitutions.get("#u1").length() > 0) {
235 value += " " + substitutions.get("#u1");
239 return ElementUtils.getText(e);
243 static String substitute(String text, IElement e) {
244 Map<String, String> substitutions = e.getHint(KEY_MONITOR_SUBSTITUTIONS);
245 return substitute(text, substitutions);
248 static String substitute(String text, Map<String, String> substitutions) {
249 if (substitutions != null) {
250 // TODO: slow as hell
251 for(Map.Entry<String, String> entry : substitutions.entrySet()) {
252 if (entry.getValue() != null) {
253 text = text.replace(entry.getKey(), entry.getValue());
255 text = text.replace(entry.getKey(), "<null>");
262 public static void update(IElement e) {
263 MonitorSGNode node = e.getElementClass().getSingleItem(MonitorSGNode.class);
267 public static void cleanup(IElement e) {
268 MonitorSGNode node = e.getElementClass().getSingleItem(MonitorSGNode.class);
272 public static boolean hasModifier(IElement e) {
273 TextEditor editor = e.getElementClass().getAtMostOneItemOfClass(TextEditor.class);
274 Modifier modifier = editor != null ? editor.getModifier(e) : null;
275 return modifier != null;
278 static final Rectangle2D DEFAULT_BOX = new Rectangle2D.Double(0, 0, 0, 0);
280 static Shape createMonitor(IElement e) {
281 Alignment hAlign = getHorizontalAlignment(e);
282 Alignment vAlign = getVerticalAlignment(e);
283 double hMargin = getHorizontalMargin(e);
284 double vMargin = getVerticalMargin(e);
286 String text = finalText(e);
288 return align(hMargin, vMargin, hAlign, vAlign, DEFAULT_BOX);
291 Graphics2D g = e.getHint(KEY_MONITOR_GC);
293 return align(hMargin, vMargin, hAlign, vAlign, DEFAULT_BOX);
297 FontMetrics fm = g.getFontMetrics(f);
298 Rectangle2D rect = fm.getStringBounds(text, g);
300 return align(hMargin, vMargin, hAlign, vAlign, rect);
303 static Shape align(double hMargin, double vMargin, Alignment hAlign, Alignment vAlign, Rectangle2D rect) {
304 //System.out.println("align: " + hMargin + ", " + vMargin + ", " + hAlign + ", " + vAlign + ": " + rect);
305 double tx = align(hMargin, hAlign, rect.getMinX(), rect.getMaxX());
306 double ty = align(vMargin, vAlign, rect.getMinY(), rect.getMaxY());
307 //System.out.println(" translate: " + tx + " " + ty);
308 double nw = rect.getWidth() + 2*hMargin;
309 double nh = rect.getHeight() + 2*vMargin;
310 return makePath(tx + rect.getMinX(), ty + rect.getMinY(), nw, nh);
313 static double align(double margin, Alignment align, double min, double max) {
314 double s = max - min;
319 return -s - 2 * margin - min;
321 return -0.5 * s - margin - min;
327 static Path2D makePath(double x, double y, double w, double h) {
328 Path2D path = new Path2D.Double();
331 path.lineTo(x+w, y+h);
337 public static final Shape BOX_SHAPE = new Rectangle(-1, -1, 2, 2);
339 public static class MonitorSGNode implements SceneGraph, InternalSize, Outline {
340 private static final long serialVersionUID = -106278359626957687L;
342 static final MonitorSGNode INSTANCE = new MonitorSGNode();
344 @SuppressWarnings("unchecked")
346 public void init(final IElement e, final G2DParentNode parent) {
347 // Create node if it doesn't exist yet
348 TextNode node = e.getHint(KEY_SG_NODE);
349 String nodeId = null;
350 if(node == null || node.getBounds() == null || node.getParent() != parent) {
351 nodeId = ElementUtils.generateNodeId(e);
352 node = parent.addNode(nodeId, TextNode.class);
353 e.setHint(KEY_SG_NODE, node);
355 node.setTextListener(new ITextListener() {
358 public void textChanged() {}
361 public void textEditingStarted() {}
364 public void textEditingCancelled() {}
366 boolean isEndingEdit = false;
369 public void textEditingEnded() {
370 TextNode node = e.getHint(KEY_SG_NODE);
374 // Prevent recursive execution which will happen
375 // due to the endEdit(node) invocation at the end.
381 TextEditor editor = e.getElementClass().getAtMostOneItemOfClass(TextEditor.class);
382 if (editor != null) {
383 Modifier modifier = editor.getModifier(e);
384 if (modifier != null) {
385 String newValue = node.getText();
386 String error = modifier.isValid(e, newValue);
388 // Only modify if the modification was not
389 // cancelled and the value is valid.
390 modifier.modify(e, newValue);
392 // TODO: show error somehow, possibly through status bar
394 // Make sure that the monitor content gets
395 // reset to its previous value.
396 node.setText(formValue(e));
401 isEndingEdit = false;
406 Object validator = e.getHint(KEY_INPUT_VALIDATOR);
407 if(validator != null) {
408 node.setValidator((Function1<String, String>)validator);
411 RVI rvi = e.getHint(KEY_RVI);
416 Double border_width = (Double)e.getHint(KEY_BORDER_WIDTH);
417 if(border_width == null) border_width = 0.1;
419 node.setBorderWidth(border_width);
421 // Rectangle2D bounds = (Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS);
422 // if(bounds != null) node.setBounds(bounds);
423 Font font = ElementUtils.getTextFont(e);
424 Color color = ElementUtils.getTextColor(e);
425 String text = ElementUtils.getText(e);
426 node.init(text, font, color, 0, 0, 1.0);
429 Boolean isExternal = e.getHint(KEY_MONITOR_IS_EXTERNAL);
430 if (Boolean.TRUE.equals(isExternal)) {
431 ShapeNode shape = e.getHint(KEY_SG_NODE2);
432 if (shape == null || shape.getParent() != parent) {
434 nodeId = ElementUtils.generateNodeId(e);
436 shape = parent.addNode(nodeId, ShapeNode.class);
438 shape.setColor(Color.BLACK);
440 shape.setStroke(null);
441 shape.setShape( arrow(4, 2, 0) );
442 e.setHint(KEY_SG_NODE2, shape);
445 ShapeNode shape = e.getHint(KEY_SG_NODE2);
453 public void update(IElement e) {
456 final Text t = e.getElementClass().getAtMostOneItemOfClass(Text.class);
459 value = formValue(e);
461 TextNode node = (TextNode) e.getHint(KEY_SG_NODE);
462 if (node != null && value != null) {
465 Object component = e.getHint(KEY_MONITOR_COMPONENT);
466 if (component != null && hasModifier(e)) {
467 node.setEditable(true);
469 node.setEditable(false);
472 // FIXME: set only if changed .. (but quickfix is not to clone)
473 Font font = ElementUtils.getTextFont(e);
474 if (node.getFont() != font) { // Don't update if we have a same object
477 Color color = ElementUtils.getTextColor(e);
478 node.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
480 AffineTransform at = ElementUtils.getTransform(e);
482 node.setTransform(at);
484 Alignment halign = e.getHint(ElementHints.KEY_HORIZONTAL_ALIGN);
486 node.setHorizontalAlignment((byte) halign.ordinal());
487 Alignment valign = e.getHint(ElementHints.KEY_VERTICAL_ALIGN);
489 node.setVerticalAlignment((byte) valign.ordinal());
491 // String tt = (String) e.getHint(KEY_TOOLTIP_TEXT);
493 // node.setToolTipText(new String(tt));
495 ShapeNode shape = e.getHint(KEY_SG_NODE2);
497 AffineTransform at2 = new AffineTransform(at);
498 Rectangle2D bounds = node.getBoundsInLocal();
499 at2.translate(bounds.getMinX(), bounds.getCenterY());
500 shape.setTransform(at2);
506 public void cleanup(IElement e) {
507 TextNode node = (TextNode)e.removeHint(KEY_SG_NODE);
513 public Rectangle2D getBounds(IElement e, Rectangle2D size) {
514 TextNode node = (TextNode)e.getHint(KEY_SG_NODE);
516 Rectangle2D bounds = node.getBoundsInLocal();
517 if (bounds != null) {
519 size = new Rectangle2D.Double(0, 0, 0, 0);
520 size.setRect(bounds);
527 public Shape getElementShape(IElement e) {
528 Shape shape = new Rectangle2D.Double(0, 0, 0, 0);
530 TextNode node = (TextNode)e.getHint(KEY_SG_NODE);
531 if(node != null && node.getBoundsInLocal() != null) {
532 shape = node.getBoundsInLocal();
540 public static class Transformer implements Transform, Move, Rotate, Scale, LifeCycle {
542 private static final long serialVersionUID = -3704887325602085677L;
544 public static final Transformer INSTANCE = new Transformer(null);
548 public Transformer() {
552 public Transformer(Double aspectRatio) {
553 this.aspectRatio = aspectRatio;
557 public Double getFixedAspectRatio(IElement e) {
562 public Point2D getScale(IElement e) {
563 AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
564 return _getScale(at);
568 public void setScale(IElement e, Point2D newScale) {
569 // Doesn't work for monitors.
570 Point2D oldScale = getScale(e);
571 double sx = newScale.getX() / oldScale.getX();
572 double sy = newScale.getY() / oldScale.getY();
573 AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
574 at = new AffineTransform(at);
576 e.setHint(ElementHints.KEY_TRANSFORM, at);
580 public Point2D getMaximumScale(IElement e) {
585 public Point2D getMinimumScale(IElement e) {
589 private static Point2D _getScale(AffineTransform at) {
590 double m00 = at.getScaleX();
591 double m11 = at.getScaleY();
592 double m10 = at.getShearY();
593 double m01 = at.getShearX();
594 // Project unit vector to canvas
595 double sx = Math.sqrt(m00 * m00 + m10 * m10);
596 double sy = Math.sqrt(m01 * m01 + m11 * m11);
597 return new Point2D.Double(sx, sy);
601 public void rotate(IElement e, double theta, Point2D origin) {
602 if (Double.isNaN(theta)) return;
603 theta = Math.toDegrees(theta);
604 Double angle = e.getHint(KEY_DIRECTION);
605 double newAngle = angle != null ? angle+theta : theta;
606 newAngle = Math.IEEEremainder(newAngle, 360.0);
607 e.setHint(KEY_DIRECTION, newAngle);
611 public double getAngle(IElement e) {
612 Double angle = e.getHint(KEY_DIRECTION);
613 return angle != null ? Math.toRadians(angle) : 0;
616 public Point2D getPosition(IElement e) {
617 AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
618 Point2D p = new Point2D.Double(at.getTranslateX(), at.getTranslateY());
623 public void moveTo(IElement e, double x, double y) {
624 AffineTransform origAt = e.getHint(ElementHints.KEY_TRANSFORM);
626 AffineTransform result = new AffineTransform(origAt);
627 result.preConcatenate(AffineTransform.getTranslateInstance(x - origAt.getTranslateX(), y - origAt.getTranslateY()));
628 e.setHint(ElementHints.KEY_TRANSFORM, result);
632 public AffineTransform getTransform(IElement e) {
633 AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
635 IElement parentElement = e.getHint(ElementHints.KEY_PARENT_ELEMENT);
636 if (parentElement == null)
639 Transform parentTransform = parentElement.getElementClass().getSingleItem(Transform.class);
640 assert(parentTransform!=null);
642 AffineTransform result = (AffineTransform)at.clone();
643 AffineTransform parentAT = parentTransform.getTransform(parentElement);
644 result.preConcatenate(AffineTransform.getTranslateInstance(parentAT.getTranslateX(), parentAT.getTranslateY()));
650 public void setTransform(IElement e, AffineTransform at) {
651 e.setHint(ElementHints.KEY_TRANSFORM, at.clone());
655 public void onElementActivated(IDiagram d, IElement e) {
659 public void onElementCreated(IElement e) {
660 e.setHint(ElementHints.KEY_TRANSFORM, new AffineTransform());
664 public void onElementDeactivated(IDiagram d, IElement e) {
668 public void onElementDestroyed(IElement e) {
669 // List<SceneGraph> nodeHandlers = e.getElementClass().getItemsByClass(SceneGraph.class);
670 // for(SceneGraph n : nodeHandlers) {
671 // System.out.println("element gone:"+e);
677 static double getOrientationDelta(IElement e, AffineTransform tr) {
678 Double angle = e.getHint(KEY_DIRECTION);
679 if (angle == null || Double.isNaN(angle))
681 double angrad = Math.toRadians(angle);
683 Vector2d forcedAxis = new Vector2d(Math.cos(angrad), Math.sin(angrad));
684 Vector2d x = new Vector2d(tr.getScaleX(), tr.getShearX());
685 forcedAxis.normalize();
687 double cosa = forcedAxis.dot(x);
688 double delta = Math.acos(cosa);
692 static class MonitorImageFactory implements IFactory<Image> {
693 private double staticScaleX = 1, staticScaleY = 1;
695 public MonitorImageFactory(double staticScaleX, double staticScaleY) {
696 this.staticScaleX = staticScaleX;
697 this.staticScaleY = staticScaleY;
701 public Image get() throws ProvisionException {
705 public class Img extends AbstractImage {
707 Shape path = align(DEFAULT_HORIZONTAL_MARGIN, DEFAULT_VERTICAL_MARGIN, DEFAULT_HORIZONTAL_ALIGN, DEFAULT_VERTICAL_ALIGN,
708 new Rectangle2D.Double(0, 0, 50*staticScaleX, 22*staticScaleY));
711 public int hashCode() {
712 long temp = Double.doubleToLongBits(staticScaleX);
713 int result = (int) (temp ^ (temp >>> 32));
714 temp = Double.doubleToLongBits(staticScaleY);
715 result = 31 * result + (int) (temp ^ (temp >>> 32));
720 public boolean equals(Object obj) {
725 if (getClass() != obj.getClass())
727 MonitorImageFactory other = (MonitorImageFactory) obj;
728 return Double.doubleToLongBits(staticScaleX) == Double.doubleToLongBits(other.staticScaleX)
729 && Double.doubleToLongBits(staticScaleY) != Double.doubleToLongBits(other.staticScaleY);
733 public Rectangle2D getBounds() {
734 return path.getBounds2D();
738 public EnumSet<Feature> getFeatures() {
739 return EnumSet.of(Feature.Vector);
743 public Shape getOutline() {
748 public Node init(G2DParentNode parent) {
749 TextNode node = parent.getOrCreateNode(""+hashCode(), TextNode.class);
750 node.init("Drop Me", FONT, Color.BLACK, 0, 0, 0.2);
751 //node.setSize(50, 22);
752 node.setBorderWidth(1);
753 node.setTransform(AffineTransform.getScaleInstance(staticScaleX, staticScaleY));
754 node.setEditable(false);
760 static final IProvider<Image> MONITOR_IMAGE =
761 ProviderUtils.reference(
763 ProviderUtils.rasterize(
764 new MonitorImageFactory(0.5, 0.5)
767 static final StaticSymbol MONITOR_SYMBOL = new StaticSymbolImpl( MONITOR_IMAGE.get() );
769 static final FillColor FILL_COLOR = new FillColorImpl(DEFAULT_FILL_COLOR);
771 static final ElementClass MONITOR_CLASS_BASE =
772 ElementClass.compile(
773 MonitorHandlerImpl.INSTANCE,
774 Transformer.INSTANCE,
775 BorderColorImpl.BLACK,
777 MonitorSGNode.INSTANCE,
778 // ClickableImpl.INSTANCE,
780 TextEditorImpl.INSTANCE,
781 TextFontImpl.DEFAULT,
783 SimpleElementLayers.INSTANCE,
787 // staticScale{X,Y} define the scale of the static monitor image
788 public static ElementClass create(double staticScaleX, double staticScaleY, ElementHandler... extraHandlers) {
789 // Bit of a hack to be able to define the scale
790 IProvider<Image> staticMonitorSymbolProvider = ProviderUtils.reference(
794 new MonitorImageFactory(staticScaleX, staticScaleY))));
795 StaticSymbol staticMonitorSymbol = new StaticSymbolImpl( staticMonitorSymbolProvider.get() );
796 return MONITOR_CLASS_BASE.newClassWith(staticMonitorSymbol).newClassWith(extraHandlers);
799 // staticScale{X,Y} define the scale of the static monitor image
800 public static ElementClass create(IElement parentElement, Map<String, String> substitutions, Object component, String suffix, double staticScaleX, double staticScaleY, ElementHandler... extraHandlers) {
801 return create(staticScaleX, staticScaleY, extraHandlers)
803 new Initializer(parentElement, substitutions, component,
804 suffix, parentElement != null ? false : true));
807 public static Shape arrow(double length, double width, double space) {
808 Path2D.Double path = new Path2D.Double();
809 path.moveTo(-space, 0);
810 path.lineTo(-length - space, -width);
811 path.lineTo(-length - space, +width);