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 org.apache.commons.math3.geometry.euclidean.twod.Vector2D;
29 import org.simantics.db.layer0.variable.RVI;
30 import org.simantics.g2d.diagram.IDiagram;
31 import org.simantics.g2d.element.ElementClass;
32 import org.simantics.g2d.element.ElementHints;
33 import org.simantics.g2d.element.ElementUtils;
34 import org.simantics.g2d.element.IElement;
35 import org.simantics.g2d.element.SceneGraphNodeKey;
36 import org.simantics.g2d.element.handler.ElementHandler;
37 import org.simantics.g2d.element.handler.FillColor;
38 import org.simantics.g2d.element.handler.InternalSize;
39 import org.simantics.g2d.element.handler.LifeCycle;
40 import org.simantics.g2d.element.handler.Move;
41 import org.simantics.g2d.element.handler.Outline;
42 import org.simantics.g2d.element.handler.Rotate;
43 import org.simantics.g2d.element.handler.Scale;
44 import org.simantics.g2d.element.handler.SceneGraph;
45 import org.simantics.g2d.element.handler.StaticSymbol;
46 import org.simantics.g2d.element.handler.Text;
47 import org.simantics.g2d.element.handler.TextEditor;
48 import org.simantics.g2d.element.handler.TextEditor.Modifier;
49 import org.simantics.g2d.element.handler.Transform;
50 import org.simantics.g2d.element.handler.impl.BorderColorImpl;
51 import org.simantics.g2d.element.handler.impl.FillColorImpl;
52 import org.simantics.g2d.element.handler.impl.ParentImpl;
53 import org.simantics.g2d.element.handler.impl.SimpleElementLayers;
54 import org.simantics.g2d.element.handler.impl.StaticSymbolImpl;
55 import org.simantics.g2d.element.handler.impl.TextColorImpl;
56 import org.simantics.g2d.element.handler.impl.TextEditorImpl;
57 import org.simantics.g2d.element.handler.impl.TextFontImpl;
58 import org.simantics.g2d.element.handler.impl.TextImpl;
59 import org.simantics.g2d.elementclass.MonitorHandler;
60 import org.simantics.g2d.image.Image;
61 import org.simantics.g2d.image.ProviderUtils;
62 import org.simantics.g2d.image.impl.AbstractImage;
63 import org.simantics.g2d.utils.Alignment;
64 import org.simantics.scenegraph.Node;
65 import org.simantics.scenegraph.g2d.G2DParentNode;
66 import org.simantics.scenegraph.g2d.nodes.ShapeNode;
67 import org.simantics.scl.runtime.function.Function1;
68 import org.simantics.utils.datastructures.cache.IFactory;
69 import org.simantics.utils.datastructures.cache.IProvider;
70 import org.simantics.utils.datastructures.cache.ProvisionException;
71 import org.simantics.utils.datastructures.hints.IHintContext.Key;
72 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
73 import org.simantics.utils.strings.format.MetricsFormat;
74 import org.simantics.utils.strings.format.MetricsFormatList;
77 * @author Tuukka Lehtonen
79 public class MonitorClass {
81 static final Font FONT = Font.decode("Helvetica 12");
84 * Back-end specific object describing the monitored component.
86 public static final Key KEY_MONITOR_COMPONENT = new KeyOf(Object.class, "MONITOR_COMPONENT");
89 * Existence of this hint indicates that the monitor is showing a value that
90 * does not originate from the owner diagram.
92 public static final Key KEY_MONITOR_IS_EXTERNAL = new KeyOf(Boolean.class, "MONITOR_IS_EXTERNAL");
95 * The valuation suffix string describing the monitored variable of the
96 * component described by {@link #KEY_MONITOR_COMPONENT}.
98 public static final Key KEY_MONITOR_SUFFIX = new KeyOf(String.class, "MONITOR_SUFFIX");
100 public static final Key KEY_MONITOR_SUBSTITUTIONS = new KeyOf(Map.class, "MONITOR_SUBSTITUTIONS");
101 public static final Key KEY_MONITOR_GC = new KeyOf(Graphics2D.class, "MONITOR_GC");
102 public static final Key KEY_MONITOR_HEIGHT = new KeyOf(Double.class, "MONITOR_HEIGHT");
103 public static final Key KEY_NUMBER_FORMAT = new KeyOf(MetricsFormat.class, "NUMBER_FORMAT");
104 public static final Key KEY_TOOLTIP_TEXT = new KeyOf(String.class, "TOOLTIP_TEXT");
106 public static final Key KEY_EXPRESSION = new KeyOf(String.class, "EXPRESSION");
107 public static final Key KEY_INPUT_VALIDATOR = new KeyOf(Object.class, "INPUT_VALIDATOR");
108 public static final Key KEY_RVI = new KeyOf(RVI.class, "RVI");
111 * If this hint is defined, the monitor will force its x-axis to match this
112 * angle. If this hint doesn't exist, the monitor will not force x-axis
115 public static final Key KEY_DIRECTION = new KeyOf(Double.class, "MONITOR_DIRECTION");
117 public static final Key KEY_BORDER_WIDTH = new KeyOf(Double.class, "MONITOR_BORDER");
119 public static final Key KEY_SG_NODE = new SceneGraphNodeKey(TextNode.class, "MONITOR_SG_NODE");
120 public static final Key KEY_SG_NODE2 = new SceneGraphNodeKey(ShapeNode.class, "MONITOR_SG_NODE2");
122 final static BasicStroke STROKE = new BasicStroke(1.0f);
124 public final static Alignment DEFAULT_HORIZONTAL_ALIGN = Alignment.CENTER;
125 public final static Alignment DEFAULT_VERTICAL_ALIGN = Alignment.CENTER;
126 public final static MetricsFormat DEFAULT_NUMBER_FORMAT = MetricsFormatList.METRICS_DECIMAL;
128 public final static Color DEFAULT_FILL_COLOR = new Color(224, 224, 224);
129 public final static Color DEFAULT_BORDER_COLOR = Color.BLACK;
131 public final static double DEFAULT_HORIZONTAL_MARGIN = 5.0;
132 public final static double DEFAULT_VERTICAL_MARGIN = 2.5;
134 static Alignment getHorizontalAlignment(IElement e) {
135 return ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, DEFAULT_HORIZONTAL_ALIGN);
138 static Alignment getVerticalAlignment(IElement e) {
139 return ElementUtils.getHintOrDefault(e, ElementHints.KEY_VERTICAL_ALIGN, DEFAULT_VERTICAL_ALIGN);
142 static MetricsFormat getNumberFormat(IElement e) {
143 return ElementUtils.getHintOrDefault(e, KEY_NUMBER_FORMAT, DEFAULT_NUMBER_FORMAT);
146 static void setNumberFormat(IElement e, MetricsFormat f) {
147 ElementUtils.setOrRemoveHint(e, KEY_NUMBER_FORMAT, f);
150 static double getHorizontalMargin(IElement e) {
151 return DEFAULT_HORIZONTAL_MARGIN;
154 static double getVerticalMargin(IElement e) {
155 return DEFAULT_VERTICAL_MARGIN;
158 static Font getFont(IElement e) {
159 return ElementUtils.getHintOrDefault(e, ElementHints.KEY_FONT, FONT);
162 public static class MonitorHandlerImpl implements MonitorHandler {
163 private static final long serialVersionUID = -4258875745321808416L;
164 public static final MonitorHandler INSTANCE = new MonitorHandlerImpl();
167 static class Initializer implements LifeCycle {
168 private static final long serialVersionUID = 4404942036933073584L;
170 IElement parentElement;
171 Map<String, String> substitutions;
176 Initializer(IElement parentElement, Map<String, String> substitutions, Object component, String suffix, boolean hack) {
177 this.parentElement = parentElement;
178 this.substitutions = substitutions;
179 this.component = component;
180 this.suffix = suffix;
185 public void onElementActivated(IDiagram d, IElement e) {
189 Point2D parentPos = ElementUtils.getPos(parentElement);
190 Point2D thisPos = ElementUtils.getPos(e);
192 Move move = e.getElementClass().getSingleItem(Move.class);
193 move.moveTo(e, thisPos.getX() - parentPos.getX(), thisPos.getY() - parentPos.getY());
197 public void onElementCreated(IElement e) {
198 if(parentElement != null) e.setHint(ElementHints.KEY_PARENT_ELEMENT, parentElement);
199 if(substitutions != null) e.setHint(KEY_MONITOR_SUBSTITUTIONS, substitutions);
200 if(component != null) e.setHint(KEY_MONITOR_COMPONENT, component);
201 if(suffix != null) e.setHint(KEY_MONITOR_SUFFIX, suffix);
202 e.setHint(KEY_DIRECTION, 0.0);
203 e.setHint(KEY_NUMBER_FORMAT, DEFAULT_NUMBER_FORMAT);
204 //e.setHint(KEY_HORIZONTAL_ALIGN, Alignment.LEADING);
205 //e.setHint(KEY_VERTICAL_ALIGN, Alignment.LEADING);
209 public void onElementDestroyed(IElement e) {
213 public void onElementDeactivated(IDiagram d, IElement e) {
217 static String finalText(IElement e) {
218 String text = e.getElementClass().getSingleItem(Text.class).getText(e);
221 return substitute(text, e);
224 public static String editText(IElement e) {
225 return substitute("#v1", e);
228 private static String formValue(IElement e) {
229 // TODO: consider using substitute
230 Map<String, String> substitutions = e.getHint(KEY_MONITOR_SUBSTITUTIONS);
231 if (substitutions != null) {
232 String value = substitutions.get("#v1");
233 if (substitutions.containsKey("#u1") && substitutions.get("#u1").length() > 0) {
234 value += " " + substitutions.get("#u1");
238 return ElementUtils.getText(e);
242 static String substitute(String text, IElement e) {
243 Map<String, String> substitutions = e.getHint(KEY_MONITOR_SUBSTITUTIONS);
244 return substitute(text, substitutions);
247 static String substitute(String text, Map<String, String> substitutions) {
248 if (substitutions != null) {
249 // TODO: slow as hell
250 for(Map.Entry<String, String> entry : substitutions.entrySet()) {
251 if (entry.getValue() != null) {
252 text = text.replace(entry.getKey(), entry.getValue());
254 text = text.replace(entry.getKey(), "<null>");
261 public static void update(IElement e) {
262 MonitorSGNode node = e.getElementClass().getSingleItem(MonitorSGNode.class);
266 public static void cleanup(IElement e) {
267 MonitorSGNode node = e.getElementClass().getSingleItem(MonitorSGNode.class);
271 public static boolean hasModifier(IElement e) {
272 TextEditor editor = e.getElementClass().getAtMostOneItemOfClass(TextEditor.class);
273 Modifier modifier = editor != null ? editor.getModifier(e) : null;
274 return modifier != null;
277 static final Rectangle2D DEFAULT_BOX = new Rectangle2D.Double(0, 0, 0, 0);
279 static Shape createMonitor(IElement e) {
280 Alignment hAlign = getHorizontalAlignment(e);
281 Alignment vAlign = getVerticalAlignment(e);
282 double hMargin = getHorizontalMargin(e);
283 double vMargin = getVerticalMargin(e);
285 String text = finalText(e);
287 return align(hMargin, vMargin, hAlign, vAlign, DEFAULT_BOX);
290 Graphics2D g = e.getHint(KEY_MONITOR_GC);
292 return align(hMargin, vMargin, hAlign, vAlign, DEFAULT_BOX);
296 FontMetrics fm = g.getFontMetrics(f);
297 Rectangle2D rect = fm.getStringBounds(text, g);
299 return align(hMargin, vMargin, hAlign, vAlign, rect);
302 static Shape align(double hMargin, double vMargin, Alignment hAlign, Alignment vAlign, Rectangle2D rect) {
303 //System.out.println("align: " + hMargin + ", " + vMargin + ", " + hAlign + ", " + vAlign + ": " + rect);
304 double tx = align(hMargin, hAlign, rect.getMinX(), rect.getMaxX());
305 double ty = align(vMargin, vAlign, rect.getMinY(), rect.getMaxY());
306 //System.out.println(" translate: " + tx + " " + ty);
307 double nw = rect.getWidth() + 2*hMargin;
308 double nh = rect.getHeight() + 2*vMargin;
309 return makePath(tx + rect.getMinX(), ty + rect.getMinY(), nw, nh);
312 static double align(double margin, Alignment align, double min, double max) {
313 double s = max - min;
318 return -s - 2 * margin - min;
320 return -0.5 * s - margin - min;
326 static Path2D makePath(double x, double y, double w, double h) {
327 Path2D path = new Path2D.Double();
330 path.lineTo(x+w, y+h);
336 public static final Shape BOX_SHAPE = new Rectangle(-1, -1, 2, 2);
338 public static class MonitorSGNode implements SceneGraph, InternalSize, Outline {
339 private static final long serialVersionUID = -106278359626957687L;
341 static final MonitorSGNode INSTANCE = new MonitorSGNode();
343 @SuppressWarnings("unchecked")
345 public void init(final IElement e, final G2DParentNode parent) {
346 // Create node if it doesn't exist yet
347 TextNode node = e.getHint(KEY_SG_NODE);
348 String nodeId = null;
349 if(node == null || node.getBounds() == null || node.getParent() != parent) {
350 nodeId = ElementUtils.generateNodeId(e);
351 node = parent.addNode(nodeId, TextNode.class);
352 e.setHint(KEY_SG_NODE, node);
354 node.setTextListener(new ITextListener() {
357 public void textChanged() {}
360 public void textEditingStarted() {}
363 public void textEditingCancelled() {}
365 boolean isEndingEdit = false;
368 public void textEditingEnded() {
369 TextNode node = e.getHint(KEY_SG_NODE);
373 // Prevent recursive execution which will happen
374 // due to the endEdit(node) invocation at the end.
380 TextEditor editor = e.getElementClass().getAtMostOneItemOfClass(TextEditor.class);
381 if (editor != null) {
382 Modifier modifier = editor.getModifier(e);
383 if (modifier != null) {
384 String newValue = node.getText();
385 String error = modifier.isValid(e, newValue);
387 // Only modify if the modification was not
388 // cancelled and the value is valid.
389 modifier.modify(e, newValue);
391 // TODO: show error somehow, possibly through status bar
393 // Make sure that the monitor content gets
394 // reset to its previous value.
395 node.setText(formValue(e));
400 isEndingEdit = false;
405 Object validator = e.getHint(KEY_INPUT_VALIDATOR);
406 if(validator != null) {
407 node.setValidator((Function1<String, String>)validator);
410 RVI rvi = e.getHint(KEY_RVI);
415 Double border_width = (Double)e.getHint(KEY_BORDER_WIDTH);
416 if(border_width == null) border_width = 0.1;
418 node.setBorderWidth(border_width);
420 // Rectangle2D bounds = (Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS);
421 // if(bounds != null) node.setBounds(bounds);
422 Font font = ElementUtils.getTextFont(e);
423 Color color = ElementUtils.getTextColor(e);
424 String text = ElementUtils.getText(e);
425 node.init(text, font, color, 0, 0, 1.0);
428 Boolean isExternal = e.getHint(KEY_MONITOR_IS_EXTERNAL);
429 if (Boolean.TRUE.equals(isExternal)) {
430 ShapeNode shape = e.getHint(KEY_SG_NODE2);
431 if (shape == null || shape.getParent() != parent) {
433 nodeId = ElementUtils.generateNodeId(e);
435 shape = parent.addNode(nodeId, ShapeNode.class);
437 shape.setColor(Color.BLACK);
439 shape.setStroke(null);
440 shape.setShape( arrow(4, 2, 0) );
441 e.setHint(KEY_SG_NODE2, shape);
444 ShapeNode shape = e.getHint(KEY_SG_NODE2);
452 public void update(IElement e) {
455 final Text t = e.getElementClass().getAtMostOneItemOfClass(Text.class);
458 value = formValue(e);
460 TextNode node = (TextNode) e.getHint(KEY_SG_NODE);
461 if (node != null && value != null) {
464 Object component = e.getHint(KEY_MONITOR_COMPONENT);
465 if (component != null && hasModifier(e)) {
466 node.setEditable(true);
468 node.setEditable(false);
471 // FIXME: set only if changed .. (but quickfix is not to clone)
472 Font font = ElementUtils.getTextFont(e);
473 if (node.getFont() != font) { // Don't update if we have a same object
476 Color color = ElementUtils.getTextColor(e);
477 node.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
479 AffineTransform at = ElementUtils.getTransform(e);
481 node.setTransform(at);
483 Alignment halign = e.getHint(ElementHints.KEY_HORIZONTAL_ALIGN);
485 node.setHorizontalAlignment((byte) halign.ordinal());
486 Alignment valign = e.getHint(ElementHints.KEY_VERTICAL_ALIGN);
488 node.setVerticalAlignment((byte) valign.ordinal());
490 // String tt = (String) e.getHint(KEY_TOOLTIP_TEXT);
492 // node.setToolTipText(new String(tt));
494 ShapeNode shape = e.getHint(KEY_SG_NODE2);
496 AffineTransform at2 = new AffineTransform(at);
497 Rectangle2D bounds = node.getBoundsInLocal();
498 at2.translate(bounds.getMinX(), bounds.getCenterY());
499 shape.setTransform(at2);
505 public void cleanup(IElement e) {
506 TextNode node = (TextNode)e.removeHint(KEY_SG_NODE);
512 public Rectangle2D getBounds(IElement e, Rectangle2D size) {
513 TextNode node = (TextNode)e.getHint(KEY_SG_NODE);
515 Rectangle2D bounds = node.getBoundsInLocal();
516 if (bounds != null) {
518 size = new Rectangle2D.Double(0, 0, 0, 0);
519 size.setRect(bounds);
526 public Shape getElementShape(IElement e) {
527 Shape shape = new Rectangle2D.Double(0, 0, 0, 0);
529 TextNode node = (TextNode)e.getHint(KEY_SG_NODE);
530 if(node != null && node.getBoundsInLocal() != null) {
531 shape = node.getBoundsInLocal();
539 public static class Transformer implements Transform, Move, Rotate, Scale, LifeCycle {
541 private static final long serialVersionUID = -3704887325602085677L;
543 public static final Transformer INSTANCE = new Transformer(null);
547 public Transformer() {
551 public Transformer(Double aspectRatio) {
552 this.aspectRatio = aspectRatio;
556 public Double getFixedAspectRatio(IElement e) {
561 public Point2D getScale(IElement e) {
562 AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
563 return _getScale(at);
567 public void setScale(IElement e, Point2D newScale) {
568 // Doesn't work for monitors.
569 Point2D oldScale = getScale(e);
570 double sx = newScale.getX() / oldScale.getX();
571 double sy = newScale.getY() / oldScale.getY();
572 AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
573 at = new AffineTransform(at);
575 e.setHint(ElementHints.KEY_TRANSFORM, at);
579 public Point2D getMaximumScale(IElement e) {
584 public Point2D getMinimumScale(IElement e) {
588 private static Point2D _getScale(AffineTransform at) {
589 double m00 = at.getScaleX();
590 double m11 = at.getScaleY();
591 double m10 = at.getShearY();
592 double m01 = at.getShearX();
593 // Project unit vector to canvas
594 double sx = Math.sqrt(m00 * m00 + m10 * m10);
595 double sy = Math.sqrt(m01 * m01 + m11 * m11);
596 return new Point2D.Double(sx, sy);
600 public void rotate(IElement e, double theta, Point2D origin) {
601 if (Double.isNaN(theta)) return;
602 theta = Math.toDegrees(theta);
603 Double angle = e.getHint(KEY_DIRECTION);
604 double newAngle = angle != null ? angle+theta : theta;
605 newAngle = Math.IEEEremainder(newAngle, 360.0);
606 e.setHint(KEY_DIRECTION, newAngle);
610 public double getAngle(IElement e) {
611 Double angle = e.getHint(KEY_DIRECTION);
612 return angle != null ? Math.toRadians(angle) : 0;
615 public Point2D getPosition(IElement e) {
616 AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
617 Point2D p = new Point2D.Double(at.getTranslateX(), at.getTranslateY());
622 public void moveTo(IElement e, double x, double y) {
623 AffineTransform origAt = e.getHint(ElementHints.KEY_TRANSFORM);
625 AffineTransform result = new AffineTransform(origAt);
626 result.preConcatenate(AffineTransform.getTranslateInstance(x - origAt.getTranslateX(), y - origAt.getTranslateY()));
627 e.setHint(ElementHints.KEY_TRANSFORM, result);
631 public AffineTransform getTransform(IElement e) {
632 AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
634 IElement parentElement = e.getHint(ElementHints.KEY_PARENT_ELEMENT);
635 if (parentElement == null)
638 Transform parentTransform = parentElement.getElementClass().getSingleItem(Transform.class);
639 assert(parentTransform!=null);
641 AffineTransform result = (AffineTransform)at.clone();
642 AffineTransform parentAT = parentTransform.getTransform(parentElement);
643 result.preConcatenate(AffineTransform.getTranslateInstance(parentAT.getTranslateX(), parentAT.getTranslateY()));
649 public void setTransform(IElement e, AffineTransform at) {
650 e.setHint(ElementHints.KEY_TRANSFORM, at.clone());
654 public void onElementActivated(IDiagram d, IElement e) {
658 public void onElementCreated(IElement e) {
659 e.setHint(ElementHints.KEY_TRANSFORM, new AffineTransform());
663 public void onElementDeactivated(IDiagram d, IElement e) {
667 public void onElementDestroyed(IElement e) {
668 // List<SceneGraph> nodeHandlers = e.getElementClass().getItemsByClass(SceneGraph.class);
669 // for(SceneGraph n : nodeHandlers) {
670 // System.out.println("element gone:"+e);
676 static double getOrientationDelta(IElement e, AffineTransform tr) {
677 Double angle = e.getHint(KEY_DIRECTION);
678 if (angle == null || Double.isNaN(angle))
680 double angrad = Math.toRadians(angle);
682 Vector2D forcedAxis = new Vector2D(Math.cos(angrad), Math.sin(angrad));
683 Vector2D x = new Vector2D(tr.getScaleX(), tr.getShearX()).normalize();
684 double cosa = forcedAxis.dotProduct(x);
685 double delta = Math.acos(cosa);
689 static class MonitorImageFactory implements IFactory<Image> {
690 private double staticScaleX = 1, staticScaleY = 1;
692 public MonitorImageFactory(double staticScaleX, double staticScaleY) {
693 this.staticScaleX = staticScaleX;
694 this.staticScaleY = staticScaleY;
698 public Image get() throws ProvisionException {
702 public class Img extends AbstractImage {
704 Shape path = align(DEFAULT_HORIZONTAL_MARGIN, DEFAULT_VERTICAL_MARGIN, DEFAULT_HORIZONTAL_ALIGN, DEFAULT_VERTICAL_ALIGN,
705 new Rectangle2D.Double(0, 0, 50*staticScaleX, 22*staticScaleY));
708 public int hashCode() {
709 long temp = Double.doubleToLongBits(staticScaleX);
710 int result = (int) (temp ^ (temp >>> 32));
711 temp = Double.doubleToLongBits(staticScaleY);
712 result = 31 * result + (int) (temp ^ (temp >>> 32));
717 public boolean equals(Object obj) {
722 if (getClass() != obj.getClass())
724 MonitorImageFactory other = (MonitorImageFactory) obj;
725 return Double.doubleToLongBits(staticScaleX) == Double.doubleToLongBits(other.staticScaleX)
726 && Double.doubleToLongBits(staticScaleY) != Double.doubleToLongBits(other.staticScaleY);
730 public Rectangle2D getBounds() {
731 return path.getBounds2D();
735 public EnumSet<Feature> getFeatures() {
736 return EnumSet.of(Feature.Vector);
740 public Shape getOutline() {
745 public Node init(G2DParentNode parent) {
746 TextNode node = parent.getOrCreateNode(""+hashCode(), TextNode.class);
747 node.init("Drop Me", FONT, Color.BLACK, 0, 0, 0.2);
748 //node.setSize(50, 22);
749 node.setBorderWidth(1);
750 node.setTransform(AffineTransform.getScaleInstance(staticScaleX, staticScaleY));
751 node.setEditable(false);
757 static final IProvider<Image> MONITOR_IMAGE =
758 ProviderUtils.reference(
760 ProviderUtils.rasterize(
761 new MonitorImageFactory(0.5, 0.5)
764 static final StaticSymbol MONITOR_SYMBOL = new StaticSymbolImpl( MONITOR_IMAGE.get() );
766 static final FillColor FILL_COLOR = new FillColorImpl(DEFAULT_FILL_COLOR);
768 static final ElementClass MONITOR_CLASS_BASE =
769 ElementClass.compile(
770 MonitorHandlerImpl.INSTANCE,
771 Transformer.INSTANCE,
772 BorderColorImpl.BLACK,
774 MonitorSGNode.INSTANCE,
775 // ClickableImpl.INSTANCE,
777 TextEditorImpl.INSTANCE,
778 TextFontImpl.DEFAULT,
780 SimpleElementLayers.INSTANCE,
784 // staticScale{X,Y} define the scale of the static monitor image
785 public static ElementClass create(double staticScaleX, double staticScaleY, ElementHandler... extraHandlers) {
786 // Bit of a hack to be able to define the scale
787 IProvider<Image> staticMonitorSymbolProvider = ProviderUtils.reference(
791 new MonitorImageFactory(staticScaleX, staticScaleY))));
792 StaticSymbol staticMonitorSymbol = new StaticSymbolImpl( staticMonitorSymbolProvider.get() );
793 return MONITOR_CLASS_BASE.newClassWith(staticMonitorSymbol).newClassWith(extraHandlers);
796 // staticScale{X,Y} define the scale of the static monitor image
797 public static ElementClass create(IElement parentElement, Map<String, String> substitutions, Object component, String suffix, double staticScaleX, double staticScaleY, ElementHandler... extraHandlers) {
798 return create(staticScaleX, staticScaleY, extraHandlers)
800 new Initializer(parentElement, substitutions, component,
801 suffix, parentElement != null ? false : true));
804 public static Shape arrow(double length, double width, double space) {
805 Path2D.Double path = new Path2D.Double();
806 path.moveTo(-space, 0);
807 path.lineTo(-length - space, -width);
808 path.lineTo(-length - space, +width);