]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/participant/PageBorderParticipant.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / participant / PageBorderParticipant.java
index a783b5473e05e73f3e0d8a02a745dbb498bc0a10..6d1021fe3ed8bfc883bf132c332ac5c8f444a8d2 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g2d.participant;\r
-\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.g2d.canvas.Hints;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
-import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;\r
-import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.nodes.PageBorderNode;\r
-import org.simantics.utils.datastructures.hints.HintListenerAdapter;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-import org.simantics.utils.datastructures.hints.IHintListener;\r
-import org.simantics.utils.datastructures.hints.IHintObservable;\r
-import org.simantics.utils.page.MarginUtils.Margins;\r
-import org.simantics.utils.page.PageDesc;\r
-\r
-/**\r
- * Paints borders or a page according to Page\r
- *\r
- * @author Tuukka Lehtonen\r
- */\r
-public class PageBorderParticipant extends AbstractCanvasParticipant {\r
-\r
-    IHintListener hintListener = new HintListenerAdapter() {\r
-        @Override\r
-        public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
-            if (key == Hints.KEY_PAGE_DESC) {\r
-                //System.out.println("PAGE DESC CHANGED FROM " + oldValue + " to " + newValue);\r
-                updateNode(true);\r
-            } else if (key == Hints.KEY_DISPLAY_PAGE) {\r
-                //System.out.println("DISPLAY PAGE CHANGED: " + oldValue + " TO " + newValue);\r
-                updateNode(true);\r
-            } else if (key == Hints.KEY_DISPLAY_MARGINS) {\r
-                //System.out.println("DISPLAY MARGINS CHANGED: " + oldValue + " TO " + newValue);\r
-                updateNode(true);\r
-            } else if (key == Hints.KEY_DISABLE_PAINTING) {\r
-                updateNode(true);\r
-            }\r
-        }\r
-    };\r
-\r
-    @Override\r
-    public void addedToContext(ICanvasContext ctx) {\r
-        super.addedToContext(ctx);\r
-        getHintStack().addKeyHintListener(getThread(), Hints.KEY_PAGE_DESC, hintListener);\r
-        getHintStack().addKeyHintListener(getThread(), Hints.KEY_DISPLAY_PAGE, hintListener);\r
-        getHintStack().addKeyHintListener(getThread(), Hints.KEY_DISPLAY_MARGINS, hintListener);\r
-        getHintStack().addKeyHintListener(getThread(), Hints.KEY_DISABLE_PAINTING, hintListener);\r
-    }\r
-\r
-    @Override\r
-    public void removedFromContext(ICanvasContext ctx) {\r
-        getHintStack().removeKeyHintListener(getThread(), Hints.KEY_PAGE_DESC, hintListener);\r
-        getHintStack().removeKeyHintListener(getThread(), Hints.KEY_DISPLAY_PAGE, hintListener);\r
-        getHintStack().removeKeyHintListener(getThread(), Hints.KEY_DISPLAY_MARGINS, hintListener);\r
-        getHintStack().removeKeyHintListener(getThread(), Hints.KEY_DISABLE_PAINTING, hintListener);\r
-        super.removedFromContext(ctx);\r
-    }\r
-\r
-    protected void updateNode(boolean markDirty) {\r
-        boolean displayPage = !Boolean.FALSE.equals(getHint(Hints.KEY_DISPLAY_PAGE));\r
-        boolean displayMargins = !Boolean.FALSE.equals(getHint(Hints.KEY_DISPLAY_MARGINS));\r
-        boolean enabled = !Boolean.TRUE.equals(getHint(Hints.KEY_DISABLE_PAINTING));\r
-\r
-        Rectangle2D border = new Rectangle2D.Double();\r
-        Rectangle2D margin = new Rectangle2D.Double();\r
-\r
-        PageDesc desc = getHint(Hints.KEY_PAGE_DESC);\r
-        //System.out.println("updateNode: " + desc + ", " + displayPage + ", " + displayMargins);\r
-        if (desc != null) {\r
-            if (displayPage)\r
-                desc.getPageRectangle(border);\r
-\r
-            Margins margins = desc.getMargins();\r
-            boolean marginsZero = margins.isZero();\r
-            //System.out.println("Margins: " + margins + ": zero: " + marginsZero);\r
-            if (displayMargins && !marginsZero) {\r
-                double mlx = desc.getLeftEdgePos() + margins.left.diagramAbsolute;\r
-                double mty = desc.getTopEdgePos() + margins.top.diagramAbsolute;\r
-                double w = desc.getOrientedWidth() - (margins.left.diagramAbsolute + margins.right.diagramAbsolute);\r
-                double h = desc.getOrientedHeight() - (margins.top.diagramAbsolute + margins.bottom.diagramAbsolute);\r
-                margin.setFrame(mlx, mty, w, h);\r
-            }\r
-        }\r
-\r
-        node.init(border, margin, enabled);\r
-\r
-        if (markDirty)\r
-            setDirty();\r
-    }\r
-\r
-    protected PageBorderNode node = null;\r
-\r
-    @SGInit\r
-    public void initSG(G2DParentNode parent) {\r
-        node = parent.addNode("page border", PageBorderNode.class);\r
-        node.setZIndex(-1000);\r
-        updateNode(false);\r
-    }\r
-\r
-    @SGCleanup\r
-    public void cleanupSG() {\r
-        node.remove();\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g2d.participant;
+
+import java.awt.geom.Rectangle2D;
+
+import org.simantics.g2d.canvas.Hints;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
+import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;
+import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.nodes.PageBorderNode;
+import org.simantics.utils.datastructures.hints.HintListenerAdapter;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintListener;
+import org.simantics.utils.datastructures.hints.IHintObservable;
+import org.simantics.utils.page.MarginUtils.Margins;
+import org.simantics.utils.page.PageDesc;
+
+/**
+ * Paints borders or a page according to Page
+ *
+ * @author Tuukka Lehtonen
+ */
+public class PageBorderParticipant extends AbstractCanvasParticipant {
+
+    IHintListener hintListener = new HintListenerAdapter() {
+        @Override
+        public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
+            if (key == Hints.KEY_PAGE_DESC) {
+                //System.out.println("PAGE DESC CHANGED FROM " + oldValue + " to " + newValue);
+                updateNode(true);
+            } else if (key == Hints.KEY_DISPLAY_PAGE) {
+                //System.out.println("DISPLAY PAGE CHANGED: " + oldValue + " TO " + newValue);
+                updateNode(true);
+            } else if (key == Hints.KEY_DISPLAY_MARGINS) {
+                //System.out.println("DISPLAY MARGINS CHANGED: " + oldValue + " TO " + newValue);
+                updateNode(true);
+            } else if (key == Hints.KEY_DISABLE_PAINTING) {
+                updateNode(true);
+            }
+        }
+    };
+
+    @Override
+    public void addedToContext(ICanvasContext ctx) {
+        super.addedToContext(ctx);
+        getHintStack().addKeyHintListener(getThread(), Hints.KEY_PAGE_DESC, hintListener);
+        getHintStack().addKeyHintListener(getThread(), Hints.KEY_DISPLAY_PAGE, hintListener);
+        getHintStack().addKeyHintListener(getThread(), Hints.KEY_DISPLAY_MARGINS, hintListener);
+        getHintStack().addKeyHintListener(getThread(), Hints.KEY_DISABLE_PAINTING, hintListener);
+    }
+
+    @Override
+    public void removedFromContext(ICanvasContext ctx) {
+        getHintStack().removeKeyHintListener(getThread(), Hints.KEY_PAGE_DESC, hintListener);
+        getHintStack().removeKeyHintListener(getThread(), Hints.KEY_DISPLAY_PAGE, hintListener);
+        getHintStack().removeKeyHintListener(getThread(), Hints.KEY_DISPLAY_MARGINS, hintListener);
+        getHintStack().removeKeyHintListener(getThread(), Hints.KEY_DISABLE_PAINTING, hintListener);
+        super.removedFromContext(ctx);
+    }
+
+    protected void updateNode(boolean markDirty) {
+        boolean displayPage = !Boolean.FALSE.equals(getHint(Hints.KEY_DISPLAY_PAGE));
+        boolean displayMargins = !Boolean.FALSE.equals(getHint(Hints.KEY_DISPLAY_MARGINS));
+        boolean enabled = !Boolean.TRUE.equals(getHint(Hints.KEY_DISABLE_PAINTING));
+
+        Rectangle2D border = new Rectangle2D.Double();
+        Rectangle2D margin = new Rectangle2D.Double();
+
+        PageDesc desc = getHint(Hints.KEY_PAGE_DESC);
+        //System.out.println("updateNode: " + desc + ", " + displayPage + ", " + displayMargins);
+        if (desc != null) {
+            if (displayPage)
+                desc.getPageRectangle(border);
+
+            Margins margins = desc.getMargins();
+            boolean marginsZero = margins.isZero();
+            //System.out.println("Margins: " + margins + ": zero: " + marginsZero);
+            if (displayMargins && !marginsZero) {
+                double mlx = desc.getLeftEdgePos() + margins.left.diagramAbsolute;
+                double mty = desc.getTopEdgePos() + margins.top.diagramAbsolute;
+                double w = desc.getOrientedWidth() - (margins.left.diagramAbsolute + margins.right.diagramAbsolute);
+                double h = desc.getOrientedHeight() - (margins.top.diagramAbsolute + margins.bottom.diagramAbsolute);
+                margin.setFrame(mlx, mty, w, h);
+            }
+        }
+
+        node.init(border, margin, enabled);
+
+        if (markDirty)
+            setDirty();
+    }
+
+    protected PageBorderNode node = null;
+
+    @SGInit
+    public void initSG(G2DParentNode parent) {
+        node = parent.addNode("page border", PageBorderNode.class);
+        node.setZIndex(-1000);
+        updateNode(false);
+    }
+
+    @SGCleanup
+    public void cleanupSG() {
+        node.remove();
+    }
+}