/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 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
import org.simantics.g2d.canvas.impl.HintReflection.HintListener;
import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;
import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
+import org.simantics.g2d.participant.RulerPainter;
import org.simantics.g2d.utils.Alignment;
import org.simantics.layer0.Layer0;
import org.simantics.modeling.ModelingResources;
import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.utils.DPIUtil;
import org.simantics.structural.stubs.StructuralResource2;
import org.simantics.utils.datastructures.hints.IHintContext;
import org.simantics.utils.datastructures.hints.IHintContext.Key;
Resource input;
IsInActiveModelListener listener;
TextNode bannerNode;
+ Rectangle2D bounds;
+ boolean rulerVisible = false;
+ double rulerSize = 0;
public DiagramModelActivityTracker(Resource input) {
if (input == null)
@HintListener(Class=Hints.class, Field="KEY_CONTROL_BOUNDS")
public void controlBoundsChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
+ bounds = (Rectangle2D) newValue;
+ resetBannerNode(bounds, rulerVisible, rulerSize);
+ }
+
+ @HintListener(Class=RulerPainter.class, Field="KEY_RULER_ENABLED")
+ public void rulerToggled(IHintObservable sender, Key key, Object oldValue, Object newValue) {
+ rulerVisible = Boolean.TRUE.equals(newValue);
+ resetBannerNode(bounds, rulerVisible, rulerSize);
+ }
+
+ @HintListener(Class=RulerPainter.class, Field="KEY_RULER_SIZE")
+ public void rulerSizeChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
+ rulerSize = newValue != null ? (Double) newValue : 0.0;
+ resetBannerNode(bounds, rulerVisible, rulerSize);
+ }
+
+ private void resetBannerNode(Rectangle2D bounds, boolean rulerVisible, double rulerSize) {
if (bannerNode == null)
return;
- if (newValue != null) {
- Rectangle2D bounds = (Rectangle2D) newValue;
+ if (bounds != null) {
AffineTransform at = new AffineTransform();
at.translate(5,5);
-// at.translate(bounds.getWidth() / 2, bounds.getHeight() / 2);
-// at.scale(2, 2);
-// at.rotate(-Math.PI/6);
-// at.translate(bounds.getWidth() - 150, bounds.getHeight() - 30);
-// at.scale(1, 1);
+ if (rulerVisible) {
+ double s = DPIUtil.upscale(rulerSize);
+ at.translate(s, s);
+ }
bannerNode.setTransform(at);
+ bannerNode.setColor(Color.BLACK);
} else {
// Disable rendering
bannerNode.setColor(null);
public void addedToContext(ICanvasContext ctx) {
super.addedToContext(ctx);
+ rulerVisible = Boolean.TRUE.equals(getHint(RulerPainter.KEY_RULER_ENABLED));
+ Double rs = getHint(RulerPainter.KEY_RULER_SIZE);
+ rulerSize = rs != null ? rs : 0;
+
listener = new IsInActiveModelListener(ctx);
Simantics.getSession().async(new IsActiveDiagram(input), listener);
bannerNode.setVerticalAlignment((byte) Alignment.LEADING.ordinal());
//bannerNode.setText("Model is not active.");
bannerNode.setText("");
- bannerNode.setFont(Font.decode("Arial 16"));
+ int fontSize = DPIUtil.upscale(16);
+ bannerNode.setFont(new Font("Tahoma", Font.PLAIN, fontSize));
//bannerNode.setBackgroundColor(new Color(192, 192, 192, 128));
bannerNode.setPadding(10, 10);
bannerNode.setBorderColor(Color.GRAY);
bannerNode.setBorderWidth(0);
bannerNode.setEditable(false);
+ bannerNode.setColor(Color.BLACK);
}
@SGCleanup