]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/MonitorClass.java
Removed javax.vecmath from target definitions.
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / elementclass / MonitorClass.java
1 ///*******************************************************************************
2 // * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3 // * in Industry THTH ry.
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
8 // *
9 // * Contributors:
10 // *     VTT Technical Research Centre of Finland - initial API and implementation
11 // *******************************************************************************/
12 //package org.simantics.g2d.elementclass;
13 //
14 //import java.awt.BasicStroke;
15 //import java.awt.Color;
16 //import java.awt.Font;
17 //import java.awt.FontMetrics;
18 //import java.awt.Graphics2D;
19 //import java.awt.Rectangle;
20 //import java.awt.Shape;
21 //import java.awt.event.ActionEvent;
22 //import java.awt.event.ActionListener;
23 //import java.awt.geom.AffineTransform;
24 //import java.awt.geom.Path2D;
25 //import java.awt.geom.Point2D;
26 //import java.awt.geom.Rectangle2D;
27 //import java.util.EnumSet;
28 //import java.util.Map;
29 //
30 //import javax.vecmath.Vector2d;
31 //
32 //import org.simantics.g2d.diagram.IDiagram;
33 //import org.simantics.g2d.element.ElementClass;
34 //import org.simantics.g2d.element.ElementHints;
35 //import org.simantics.g2d.element.ElementUtils;
36 //import org.simantics.g2d.element.IElement;
37 //import org.simantics.g2d.element.SceneGraphNodeKey;
38 //import org.simantics.g2d.element.handler.ElementHandler;
39 //import org.simantics.g2d.element.handler.FillColor;
40 //import org.simantics.g2d.element.handler.InternalSize;
41 //import org.simantics.g2d.element.handler.LifeCycle;
42 //import org.simantics.g2d.element.handler.Move;
43 //import org.simantics.g2d.element.handler.Outline;
44 //import org.simantics.g2d.element.handler.Rotate;
45 //import org.simantics.g2d.element.handler.Scale;
46 //import org.simantics.g2d.element.handler.SceneGraph;
47 //import org.simantics.g2d.element.handler.StaticSymbol;
48 //import org.simantics.g2d.element.handler.Text;
49 //import org.simantics.g2d.element.handler.TextEditor;
50 //import org.simantics.g2d.element.handler.Transform;
51 //import org.simantics.g2d.element.handler.TextEditor.Modifier;
52 //import org.simantics.g2d.element.handler.impl.BorderColorImpl;
53 //import org.simantics.g2d.element.handler.impl.FillColorImpl;
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.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.MonitorNode;
67 //import org.simantics.utils.datastructures.cache.IFactory;
68 //import org.simantics.utils.datastructures.cache.IProvider;
69 //import org.simantics.utils.datastructures.cache.ProvisionException;
70 //import org.simantics.utils.datastructures.hints.IHintContext.Key;
71 //import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
72 //import org.simantics.utils.strings.format.MetricsFormat;
73 //import org.simantics.utils.strings.format.MetricsFormatList;
74 //
75 ///**
76 // * @author Tuukka Lehtonen
77 // */
78 //public class MonitorClass {
79 //
80 //    static final Font        FONT                      = Font.decode("Helvetica 12");
81 //
82 //    /**
83 //     * Back-end specific object describing the monitored component.
84 //     */
85 //    public static final Key  KEY_MONITOR_COMPONENT     = new KeyOf(Object.class, "MONITOR_COMPONENT");
86 //
87 //    /**
88 //     * The valuation suffix string describing the monitored variable of the
89 //     * component described by {@link #KEY_MONITOR_COMPONENT}.
90 //     */
91 //    public static final Key  KEY_MONITOR_SUFFIX        = new KeyOf(String.class, "MONITOR_SUFFIX");
92 //
93 //    public static final Key  KEY_MONITOR_SUBSTITUTIONS = new KeyOf(Map.class, "MONITOR_SUBSTITUTIONS");
94 //    public static final Key  KEY_MONITOR_GC            = new KeyOf(Graphics2D.class, "MONITOR_GC");
95 //    public static final Key  KEY_MONITOR_HEIGHT        = new KeyOf(Double.class, "MONITOR_HEIGHT");
96 //    public static final Key  KEY_NUMBER_FORMAT         = new KeyOf(MetricsFormat.class, "NUMBER_FORMAT");
97 //    public static final Key  KEY_TOOLTIP_TEXT          = new KeyOf(String.class, "TOOLTIP_TEXT");
98 //
99 //    /**
100 //     * If this hint is defined, the monitor will force its x-axis to match this
101 //     * angle. If this hint doesn't exist, the monitor will not force x-axis
102 //     * orientation.
103 //     */
104 //    public static final Key  KEY_DIRECTION             = new KeyOf(Double.class, "MONITOR_DIRECTION");
105 //
106 //    public static final Key  KEY_BORDER_WIDTH          = new KeyOf(Double.class, "MONITOR_BORDER");
107 //
108 //    public static final Key  KEY_SG_NODE               = new SceneGraphNodeKey(Node.class, "MONITOR_SG_NODE");
109 //
110 //    final static BasicStroke STROKE                    = new BasicStroke(1.0f);
111 //
112 //    public final static Alignment DEFAULT_HORIZONTAL_ALIGN  = Alignment.CENTER;
113 //    public final static Alignment DEFAULT_VERTICAL_ALIGN    = Alignment.CENTER;
114 //    public final static MetricsFormat DEFAULT_NUMBER_FORMAT = MetricsFormatList.METRICS_DECIMAL;
115 //
116 //    public final static Color     DEFAULT_FILL_COLOR        = new Color(224, 224, 224);
117 //    public final static Color     DEFAULT_BORDER_COLOR      = Color.BLACK;
118 //
119 //    public final static double    DEFAULT_HORIZONTAL_MARGIN = 5.0;
120 //    public final static double    DEFAULT_VERTICAL_MARGIN   = 2.5;
121 //
122 //    static Alignment getHorizontalAlignment(IElement e) {
123 //        return ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, DEFAULT_HORIZONTAL_ALIGN);
124 //    }
125 //
126 //    static Alignment getVerticalAlignment(IElement e) {
127 //        return ElementUtils.getHintOrDefault(e, ElementHints.KEY_VERTICAL_ALIGN, DEFAULT_VERTICAL_ALIGN);
128 //    }
129 //
130 //    static MetricsFormat getNumberFormat(IElement e) {
131 //        return ElementUtils.getHintOrDefault(e, KEY_NUMBER_FORMAT, DEFAULT_NUMBER_FORMAT);
132 //    }
133 //
134 //    static void setNumberFormat(IElement e, MetricsFormat f) {
135 //        ElementUtils.setOrRemoveHint(e, KEY_NUMBER_FORMAT, f);
136 //    }
137 //
138 //    static double getHorizontalMargin(IElement e) {
139 //        return DEFAULT_HORIZONTAL_MARGIN;
140 //    }
141 //
142 //    static double getVerticalMargin(IElement e) {
143 //        return DEFAULT_VERTICAL_MARGIN;
144 //    }
145 //
146 //    static Font getFont(IElement e) {
147 //        return ElementUtils.getHintOrDefault(e, ElementHints.KEY_FONT, FONT);
148 //    }
149 //
150 //    public static class MonitorHandlerImpl implements MonitorHandler {
151 //        private static final long          serialVersionUID = -4258875745321808416L;
152 //        public static final MonitorHandler INSTANCE         = new MonitorHandlerImpl();
153 //    }
154 //
155 //    static class Initializer implements LifeCycle {
156 //        private static final long serialVersionUID = 4404942036933073584L;
157 //
158 //        IElement parentElement;
159 //        Map<String, String> substitutions;
160 //        Object component;
161 //        String suffix;
162 //        boolean hack;
163 //
164 //        Initializer(IElement parentElement, Map<String, String> substitutions, Object component, String suffix, boolean hack) {
165 //            this.parentElement = parentElement;
166 //            this.substitutions = substitutions;
167 //            this.component = component;
168 //            this.suffix = suffix;
169 //            this.hack = hack;
170 //        }
171 //
172 //        @Override
173 //        public void onElementActivated(IDiagram d, IElement e) {
174 //
175 //            if(!hack) {
176 //
177 //                hack = true;
178 //
179 //                Point2D parentPos = ElementUtils.getPos(parentElement);
180 //                Point2D thisPos = ElementUtils.getPos(e);
181 //
182 //                Move move = e.getElementClass().getSingleItem(Move.class);
183 //                move.moveTo(e, thisPos.getX() - parentPos.getX(), thisPos.getY() - parentPos.getY());
184 //
185 //            }
186 //
187 //        }
188 //        @Override
189 //        public void onElementCreated(IElement e) {
190 //            if(parentElement != null) e.setHint(ElementHints.KEY_PARENT_ELEMENT, parentElement);
191 //            if(substitutions != null) e.setHint(KEY_MONITOR_SUBSTITUTIONS, substitutions);
192 //            if(component != null) e.setHint(KEY_MONITOR_COMPONENT, component);
193 //            if(suffix != null) e.setHint(KEY_MONITOR_SUFFIX, suffix);
194 //
195 //            e.setHint(KEY_DIRECTION, 0.0);
196 //            e.setHint(KEY_NUMBER_FORMAT, DEFAULT_NUMBER_FORMAT);
197 //            //e.setHint(KEY_HORIZONTAL_ALIGN, Alignment.LEADING);
198 //            //e.setHint(KEY_VERTICAL_ALIGN, Alignment.LEADING);
199 //        }
200 //        @Override
201 //        public void onElementDeactivated(IDiagram d, IElement e) {
202 //        }
203 //        @Override
204 //        public void onElementDestroyed(IElement e) {
205 //        }
206 //    };
207 //
208 //    static String finalText(IElement e) {
209 //        String text = e.getElementClass().getSingleItem(Text.class).getText(e);
210 //        if (text == null)
211 //            return null;
212 //        return substitute(text, e);
213 //    }
214 //
215 //    public static String editText(IElement e) {
216 //        return substitute("#v1", e);
217 //    }
218 //
219 //    private static String formValue(IElement e) {
220 //        // TODO: consider using substitute
221 //        Map<String, String> substitutions = e.getHint(KEY_MONITOR_SUBSTITUTIONS);
222 //        if (substitutions != null) {
223 //            String value = substitutions.get("#v1");
224 //            if (substitutions.containsKey("#u1") && substitutions.get("#u1").length() > 0) {
225 //                value += " " + substitutions.get("#u1");
226 //            }
227 //            return value;
228 //        }
229 //        return null;
230 //    }
231 //
232 //    static String substitute(String text, IElement e) {
233 //        Map<String, String> substitutions = e.getHint(KEY_MONITOR_SUBSTITUTIONS);
234 //        return substitute(text, substitutions);
235 //    }
236 //
237 //    static String substitute(String text, Map<String, String> substitutions) {
238 //        if (substitutions != null) {
239 //            // TODO: slow as hell
240 //            for(Map.Entry<String, String> entry : substitutions.entrySet()) {
241 //                if (entry.getValue() != null) {
242 //                    text = text.replace(entry.getKey(), entry.getValue());
243 //                } else {
244 //                    text = text.replace(entry.getKey(), "<null>");
245 //                }
246 //            }
247 //        }
248 //        return text;
249 //    }
250 //
251 //    public static void update(IElement e) {
252 //        MonitorSGNode node = e.getElementClass().getSingleItem(MonitorSGNode.class);
253 //        node.update(e);
254 //    }
255 //
256 //    public static void cleanup(IElement e) {
257 //        MonitorSGNode node = e.getElementClass().getSingleItem(MonitorSGNode.class);
258 //        node.cleanup(e);
259 //    }
260 //
261 //    static final Rectangle2D DEFAULT_BOX = new Rectangle2D.Double(0, 0, 0, 0);
262 //
263 //    static Shape createMonitor(IElement e) {
264 //        Alignment hAlign = getHorizontalAlignment(e);
265 //        Alignment vAlign = getVerticalAlignment(e);
266 //        double hMargin = getHorizontalMargin(e);
267 //        double vMargin = getVerticalMargin(e);
268 //
269 //        String text = finalText(e);
270 //        if(text == null) {
271 //            return align(hMargin, vMargin, hAlign, vAlign, DEFAULT_BOX);
272 //        }
273 //
274 //        Graphics2D g = e.getHint(KEY_MONITOR_GC);
275 //        if(g == null) {
276 //            return align(hMargin, vMargin, hAlign, vAlign, DEFAULT_BOX);
277 //        }
278 //
279 //        Font f = getFont(e);
280 //        FontMetrics fm   = g.getFontMetrics(f);
281 //        Rectangle2D rect = fm.getStringBounds(text, g);
282 //
283 //        return align(hMargin, vMargin, hAlign, vAlign, rect);
284 //    }
285 //
286 //    static Shape align(double hMargin, double vMargin, Alignment hAlign, Alignment vAlign, Rectangle2D rect) {
287 //        //System.out.println("align: " + hMargin + ", " + vMargin + ", " + hAlign + ", " + vAlign + ": " + rect);
288 //        double tx = align(hMargin, hAlign, rect.getMinX(), rect.getMaxX());
289 //        double ty = align(vMargin, vAlign, rect.getMinY(), rect.getMaxY());
290 //        //System.out.println("    translate: " + tx + " "  + ty);
291 //        double nw = rect.getWidth() + 2*hMargin;
292 //        double nh = rect.getHeight() + 2*vMargin;
293 //        return makePath(tx + rect.getMinX(), ty + rect.getMinY(), nw, nh);
294 //    }
295 //
296 //    static double align(double margin, Alignment align, double min, double max) {
297 //        double s = max - min;
298 //        switch (align) {
299 //            case LEADING:
300 //                return -min;
301 //            case TRAILING:
302 //                return -s - 2 * margin - min;
303 //            case CENTER:
304 //                return -0.5 * s - margin - min;
305 //            default:
306 //                return 0;
307 //        }
308 //    }
309 //
310 //    static Path2D makePath(double x, double y, double w, double h) {
311 //        Path2D path = new Path2D.Double();
312 //        path.moveTo(x, y);
313 //        path.lineTo(x+w, y);
314 //        path.lineTo(x+w, y+h);
315 //        path.lineTo(x, y+h);
316 //        path.closePath();
317 //        return path;
318 //    }
319 //
320 //    public static final Shape BOX_SHAPE = new Rectangle(-1, -1, 2, 2);
321 //
322 //    public static class MonitorSGNode implements SceneGraph, InternalSize, Outline {
323 //        private static final long serialVersionUID = -106278359626957687L;
324 //
325 //        static final MonitorSGNode INSTANCE = new MonitorSGNode();
326 //
327 //        @Override
328 //        public void init(final IElement e, final G2DParentNode parent) {
329 //            // Create node if it doesn't exist yet
330 //            MonitorNode node = (MonitorNode)e.getHint(KEY_SG_NODE);
331 //            if(node == null || node.getBounds() == null || node.getParent() != parent) {
332 //                node = parent.addNode(ElementUtils.generateNodeId(e), MonitorNode.class);
333 //                e.setHint(KEY_SG_NODE, node);
334 //
335 //                node.setActionListener(new ActionListener() {
336 //                    @Override
337 //                    public void actionPerformed(ActionEvent event) {
338 //                        TextEditor editor = e.getElementClass().getAtMostOneItemOfClass(TextEditor.class);
339 //                        if (editor != null) {
340 //                            Modifier modifier = editor.getModifier(e);
341 //                            if (modifier != null) {
342 //                                String newValue = event.getActionCommand();
343 //                                String error = modifier.isValid(e, newValue);
344 //
345 //                                if (error == null) {
346 //                                    // Only modify if the modification was not
347 //                                    // cancelled and the value is valid.
348 //                                    modifier.modify(e, newValue);
349 //                                } else {
350 //                                    // TODO: show error somehow, possibly through status bar
351 //
352 //                                    // Make sure that the monitor content gets
353 //                                    // reset to its previous value.
354 //                                    MonitorNode node = e.getHint(KEY_SG_NODE);
355 //                                    if (node != null)
356 //                                        node.setText(formValue(e));
357 //                                }
358 //                            }
359 //                        }
360 //
361 ////                        final Text t = e.getElementClass().getAtMostOneItemOfClass(Text.class);
362 ////                        t.setText(e, event.getActionCommand()); // FIXME
363 //                    }});
364 //                node.setSize(50, 22);
365 //                Double border_width = (Double)e.getHint(KEY_BORDER_WIDTH);
366 //                if(border_width == null) border_width = 0.1;
367 //                
368 //                node.setBorderWidth(border_width);
369 //
370 //                Rectangle2D bounds = (Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS);
371 //                if(bounds != null) node.setBounds(bounds);
372 //            }
373 //            update(e);
374 //        }
375 //
376 //        public void update(IElement e) {
377 //            String value = null;
378 //
379 //            final Text t = e.getElementClass().getAtMostOneItemOfClass(Text.class);
380 //            assert(t != null);
381 //
382 //            value = formValue(e);
383 //
384 //            MonitorNode node = (MonitorNode) e.getHint(KEY_SG_NODE);
385 //            if (node != null && value != null) {
386 //                node.setText(value);
387 //                Object component = e.getHint(KEY_MONITOR_COMPONENT);
388 //                if (component != null) {
389 //                    node.setEditable(true);
390 //                } else {
391 //                    node.setEditable(false);
392 //                }
393 //
394 //                // FIXME: set only if changed .. (but quickfix is not to clone)
395 //                Font font = ElementUtils.getTextFont(e);
396 //                if (node.getFont() != font) { // Don't update if we have a same object
397 //                    node.setFont(font);
398 //                }
399 //                Color color = ElementUtils.getTextColor(e);
400 //                node.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
401 //                String tt = (String) e.getHint(KEY_TOOLTIP_TEXT);
402 //                if (tt != null)
403 //                    node.setToolTipText(new String(tt));
404 //            }
405 //        }
406 //
407 //        @Override
408 //        public void cleanup(IElement e) {
409 //            MonitorNode node = (MonitorNode)e.removeHint(KEY_SG_NODE);
410 //            if (node != null)
411 //                node.remove();
412 //        }
413 //
414 //        @Override
415 //        public Rectangle2D getBounds(IElement e, Rectangle2D size) {
416 //            Rectangle2D shape = new Rectangle2D.Double(0, 0, 0, 0);
417 //
418 //            MonitorNode node = (MonitorNode)e.getHint(KEY_SG_NODE);
419 //            if(node != null && node.getBounds() != null) {
420 //                shape = node.getBounds().getBounds2D();
421 //            }
422 //
423 //            if(size != null) size.setRect(shape);
424 //            return shape;
425 //        }
426 //
427 //        @Override
428 //        public Shape getElementShape(IElement e) {
429 //            Shape shape = new Rectangle2D.Double(0, 0, 0, 0);
430 //
431 //            MonitorNode node = (MonitorNode)e.getHint(KEY_SG_NODE);
432 //            if(node != null && node.getBounds() != null) {
433 //                shape = node.getBounds();
434 //            }
435 //
436 //            return shape;
437 //        }
438 //
439 //    }
440 //
441 //    public static class Transformer implements Transform, Move, Rotate, Scale, LifeCycle {
442 //
443 //        private static final long serialVersionUID = -3704887325602085677L;
444 //
445 //        public static final Transformer INSTANCE = new Transformer(null);
446 //
447 //        Double aspectRatio;
448 //
449 //        public Transformer() {
450 //            this(null);
451 //        }
452 //
453 //        public Transformer(Double aspectRatio) {
454 //            this.aspectRatio = aspectRatio;
455 //        }
456 //
457 //        @Override
458 //        public Double getFixedAspectRatio(IElement e) {
459 //            return aspectRatio;
460 //        }
461 //
462 //        @Override
463 //        public Point2D getScale(IElement e) {
464 //            AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
465 //            return _getScale(at);
466 //        }
467 //
468 //        @Override
469 //        public void setScale(IElement e, Point2D newScale) {
470 //            // Doesn't work for monitors.
471 //            Point2D oldScale = getScale(e);
472 //            double sx = newScale.getX() / oldScale.getX();
473 //            double sy = newScale.getY() / oldScale.getY();
474 //            AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
475 //            at = new AffineTransform(at);
476 //            at.scale(sx, sy);
477 //            e.setHint(ElementHints.KEY_TRANSFORM, at);
478 //        }
479 //
480 //        @Override
481 //        public Point2D getMaximumScale(IElement e) {
482 //            return null;
483 //        }
484 //
485 //        @Override
486 //        public Point2D getMinimumScale(IElement e) {
487 //            return null;
488 //        }
489 //
490 //        private static Point2D _getScale(AffineTransform at) {
491 //            double m00 = at.getScaleX();
492 //            double m11 = at.getScaleY();
493 //            double m10 = at.getShearY();
494 //            double m01 = at.getShearX();
495 //            // Project unit vector to canvas
496 //            double sx = Math.sqrt(m00 * m00 + m10 * m10);
497 //            double sy = Math.sqrt(m01 * m01 + m11 * m11);
498 //            return new Point2D.Double(sx, sy);
499 //        }
500 //
501 //        @Override
502 //        public void rotate(IElement e, double theta, Point2D origin) {
503 //            if (Double.isNaN(theta)) return;
504 //            theta = Math.toDegrees(theta);
505 //            Double angle = e.getHint(KEY_DIRECTION);
506 //            double newAngle = angle != null ? angle+theta : theta;
507 //            newAngle = Math.IEEEremainder(newAngle, 360.0);
508 //            e.setHint(KEY_DIRECTION, newAngle);
509 //        }
510 //
511 //        @Override
512 //        public double getAngle(IElement e) {
513 //            Double angle = e.getHint(KEY_DIRECTION);
514 //            return angle != null ? Math.toRadians(angle) : 0;
515 //        }
516 //
517 //        @Override
518 //        public Point2D getPosition(IElement e) {
519 //            AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
520 //            Point2D p = new Point2D.Double(at.getTranslateX(), at.getTranslateY());
521 //            return p;
522 //        }
523 //
524 //        @Override
525 //        public void moveTo(IElement e, double x, double y) {
526 //            AffineTransform origAt = e.getHint(ElementHints.KEY_TRANSFORM);
527 //            double oldX = origAt.getTranslateX();
528 //            double oldY = origAt.getTranslateY();
529 //            AffineTransform move = AffineTransform.getTranslateInstance(x-oldX, y-oldY);
530 //            AffineTransform at2 = new AffineTransform(origAt);
531 //            at2.preConcatenate(move);
532 //            e.setHint(ElementHints.KEY_TRANSFORM, at2);
533 //        }
534 //
535 //        @Override
536 //        public AffineTransform getTransform(IElement e) {
537 //            AffineTransform at = e.getHint(ElementHints.KEY_TRANSFORM);
538 //
539 //            IElement parentElement = e.getHint(ElementHints.KEY_PARENT_ELEMENT);
540 //            if (parentElement == null)
541 //                return at;
542 //
543 //            Transform parentTransform = parentElement.getElementClass().getSingleItem(Transform.class);
544 //            assert(parentTransform!=null);
545 //
546 //            AffineTransform result = (AffineTransform)at.clone();
547 //            result.preConcatenate(parentTransform.getTransform(parentElement));
548 //
549 //            return result;
550 //        }
551 //
552 //        @Override
553 //        public void setTransform(IElement e, AffineTransform at) {
554 //            e.setHint(ElementHints.KEY_TRANSFORM, at.clone());
555 //        }
556 //
557 //        @Override
558 //        public void onElementActivated(IDiagram d, IElement e) {
559 //        }
560 //
561 //        @Override
562 //        public void onElementCreated(IElement e) {
563 //            e.setHint(ElementHints.KEY_TRANSFORM, new AffineTransform());
564 //        }
565 //
566 //        @Override
567 //        public void onElementDeactivated(IDiagram d, IElement e) {
568 //        }
569 //
570 //        @Override
571 //        public void onElementDestroyed(IElement e) {
572 ////            List<SceneGraph> nodeHandlers = e.getElementClass().getItemsByClass(SceneGraph.class);
573 ////            for(SceneGraph n : nodeHandlers) {
574 ////                System.out.println("element gone:"+e);
575 ////                n.cleanup(e);
576 ////            }
577 //        }
578 //    }
579 //
580 //    static double getOrientationDelta(IElement e, AffineTransform tr) {
581 //        Double angle = e.getHint(KEY_DIRECTION);
582 //        if (angle == null || Double.isNaN(angle))
583 //            return Double.NaN;
584 //        double angrad = Math.toRadians(angle);
585 //
586 //        Vector2d forcedAxis = new Vector2d(Math.cos(angrad), Math.sin(angrad));
587 //        Vector2d x = new Vector2d(tr.getScaleX(), tr.getShearX());
588 //        forcedAxis.normalize();
589 //        x.normalize();
590 //        double cosa = forcedAxis.dot(x);
591 //        double delta = Math.acos(cosa);
592 //        return delta;
593 //    }
594 //
595 //    static class MonitorImageFactory implements IFactory<Image> {
596 //        private double staticScaleX = 1, staticScaleY = 1;
597 //
598 //        public MonitorImageFactory(double staticScaleX, double staticScaleY) {
599 //            this.staticScaleX = staticScaleX;
600 //            this.staticScaleY = staticScaleY;
601 //        }
602 //
603 //        @Override
604 //        public Image get() throws ProvisionException {
605 //            return new AbstractImage() {
606 //                Shape path = align(DEFAULT_HORIZONTAL_MARGIN, DEFAULT_VERTICAL_MARGIN, DEFAULT_HORIZONTAL_ALIGN, DEFAULT_VERTICAL_ALIGN,
607 //                        new Rectangle2D.Double(0, 0, 50*staticScaleX, 22*staticScaleY));
608 //
609 //                @Override
610 //                public Rectangle2D getBounds() {
611 //                    return path.getBounds2D();
612 //                }
613 //
614 //                @Override
615 //                public EnumSet<Feature> getFeatures() {
616 //                    return EnumSet.of(Feature.Vector);
617 //                }
618 //
619 //                @Override
620 //                public Shape getOutline() {
621 //                    return path;
622 //                }
623 //
624 //                @Override
625 //                public Node init(G2DParentNode parent) {
626 //                    MonitorNode node = parent.getOrCreateNode(""+hashCode(), MonitorNode.class);
627 //                    node.setText("");
628 //                    node.setSize(50, 22);
629 //                    node.setBorderWidth(1);
630 //                    node.setText("Drop Me");
631 //                    node.setTransform(AffineTransform.getScaleInstance(staticScaleX, staticScaleY));
632 //                    return node;
633 //                }
634 //            };
635 //        }
636 //    }
637 //
638 //    static final IProvider<Image> MONITOR_IMAGE =
639 //        ProviderUtils.reference(
640 //                ProviderUtils.cache(
641 //                        ProviderUtils.rasterize(
642 //                                new MonitorImageFactory(0.5, 0.5)
643 //                        )));
644 //
645 //    static final StaticSymbol MONITOR_SYMBOL = new StaticSymbolImpl( MONITOR_IMAGE.get() );
646 //
647 //    static final FillColor FILL_COLOR = new FillColorImpl(DEFAULT_FILL_COLOR);
648 //
649 //    public static final ElementClass MONITOR_CLASS =
650 //        ElementClass.compile(
651 //                MonitorHandlerImpl.INSTANCE,
652 //                Transformer.INSTANCE,
653 //                BorderColorImpl.BLACK,
654 //                FILL_COLOR,
655 //                MonitorSGNode.INSTANCE,
656 //                TextImpl.INSTANCE,
657 //                TextEditorImpl.INSTANCE,
658 //                TextFontImpl.DEFAULT,
659 //                TextColorImpl.BLACK,
660 //                SimpleElementLayers.INSTANCE,
661 //                MONITOR_SYMBOL
662 //        );
663 //
664 //    // staticScale{X,Y} define the scale of the static monitor image
665 //    public static ElementClass create(IElement parentElement, Map<String, String> substitutions, Object component, String suffix, double staticScaleX, double staticScaleY, ElementHandler... extraHandlers) {
666 //        // Bit of a hack to be able to define the scale
667 //        IProvider<Image> staticMonitorSymbolProvider = ProviderUtils.reference(
668 //                ProviderUtils.cache(
669 //                        ProviderUtils
670 //                        .rasterize(
671 //                                new MonitorImageFactory(staticScaleX, staticScaleY))));
672 //        StaticSymbol staticMonitorSymbol = new StaticSymbolImpl( staticMonitorSymbolProvider.get() );
673 //        return ElementClass.compile(
674 //                new Initializer(parentElement, substitutions, component, suffix, parentElement != null ? false : true),
675 //                MonitorHandlerImpl.INSTANCE,
676 //                Transformer.INSTANCE,
677 //                BorderColorImpl.BLACK,
678 //                FILL_COLOR,
679 //                MonitorSGNode.INSTANCE,
680 //                TextImpl.INSTANCE,
681 //                TextEditorImpl.INSTANCE,
682 //                TextFontImpl.DEFAULT,
683 //                TextColorImpl.BLACK,
684 //                SimpleElementLayers.INSTANCE,
685 //                staticMonitorSymbol
686 //        ).newClassWith(extraHandlers);
687 //    }
688 //
689 //}