]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils/src/org/simantics/utils/page/MarginUtils.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils / src / org / simantics / utils / page / MarginUtils.java
index 1f35828863e72b7530062b39b701f9a79d2a766c..5e9862c74c92c753bf3208aef5565d3da7139d02 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.utils.page;\r
-\r
-\r
-/**\r
- * \r
- * @See {@link RulerPainter} RulerPainter.RULER_MARGIN5\r
- * @author Toni Kalajainen\r
- */\r
-public class MarginUtils {\r
-\r
-    public static Margin marginOf(double controlRelative, double controlAbsolute, double diagramAbsolute) {\r
-        return new Margin(controlRelative/100, controlAbsolute, diagramAbsolute);\r
-    }\r
-\r
-    /** No margin */\r
-    public static final Margin NO_MARGIN = marginOf(0, 0, 0);\r
-    /** 5% margin */\r
-    public static final Margin MARGIN5 = marginOf(5, 0, 0);\r
-    /** 2% margin */\r
-    public static final Margin MARGIN2 = marginOf(2, 0, 0);\r
-    /** 10mm margin */\r
-    public static final Margin MARGIN_10mm = marginOf(0, 0, 10);\r
-\r
-    \r
-    /** No margins */\r
-    public static final Margins NO_MARGINS = new Margins(NO_MARGIN, NO_MARGIN, NO_MARGIN, NO_MARGIN);\r
-    /** 5% margin */\r
-    public static final Margins MARGINS5 = new Margins(MARGIN5, MARGIN5, MARGIN5, MARGIN5);\r
-    /** 2% margin */\r
-    public static final Margins MARGINS2 = new Margins(MARGIN2, MARGIN2, MARGIN2, MARGIN2);\r
-    /** 10mm margin */\r
-    public static final Margins MARGINS_10mm = new Margins(MARGIN_10mm, MARGIN_10mm, MARGIN_10mm, MARGIN_10mm);\r
-\r
-    /**\r
-     * A margin.\r
-     */\r
-    public static class Margin {\r
-        /** Relative margins 0..100 (in control coordinates) */\r
-        public final double controlRelative;\r
-        /** Margins in absolute values of control units */\r
-        public final double controlAbsolute;\r
-        /** Margins in absolute values of diaram units*/\r
-        public final double diagramAbsolute;\r
-\r
-        public Margin(double controlRelative, double controlAbsolute, double diagramAbsolute) {\r
-            this.controlRelative = controlRelative;\r
-            this.controlAbsolute = controlAbsolute;\r
-            this.diagramAbsolute = diagramAbsolute;\r
-        }\r
-\r
-        @Override\r
-        public String toString() {\r
-            return "(" + controlRelative + " " + controlAbsolute + " " + diagramAbsolute + ")";\r
-        }\r
-\r
-        public boolean isZero() {\r
-            return Math.abs(controlRelative) < Double.MIN_VALUE\r
-            && Math.abs(controlAbsolute) < Double.MIN_VALUE\r
-            && Math.abs(diagramAbsolute) < Double.MIN_VALUE;\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            long temp;\r
-            temp = Double.doubleToLongBits(controlAbsolute);\r
-            result = prime * result + (int) (temp ^ (temp >>> 32));\r
-            temp = Double.doubleToLongBits(controlRelative);\r
-            result = prime * result + (int) (temp ^ (temp >>> 32));\r
-            temp = Double.doubleToLongBits(diagramAbsolute);\r
-            result = prime * result + (int) (temp ^ (temp >>> 32));\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj)\r
-                return true;\r
-            if (obj == null)\r
-                return false;\r
-            if (getClass() != obj.getClass())\r
-                return false;\r
-            Margin other = (Margin) obj;\r
-            if (Double.doubleToLongBits(controlAbsolute) != Double.doubleToLongBits(other.controlAbsolute))\r
-                return false;\r
-            if (Double.doubleToLongBits(controlRelative) != Double.doubleToLongBits(other.controlRelative))\r
-                return false;\r
-            if (Double.doubleToLongBits(diagramAbsolute) != Double.doubleToLongBits(other.diagramAbsolute))\r
-                return false;\r
-            return true;\r
-        }\r
-    }\r
-\r
-    /**\r
-     * 4 margins: top, bottom, left, right\r
-     */\r
-    public static class Margins {\r
-\r
-        public static final int TOP    = 1 << 0;\r
-        public static final int BOTTOM = 1 << 1;\r
-        public static final int LEFT   = 1 << 2;\r
-        public static final int RIGHT  = 1 << 3;\r
-\r
-        public final Margin top;\r
-        public final Margin bottom;\r
-        public final Margin left;\r
-        public final Margin right;\r
-\r
-        public Margins(Margin top, Margin bottom, Margin left, Margin right) {\r
-            assert top != null;\r
-            assert bottom != null;\r
-            assert left != null;\r
-            assert right != null;\r
-\r
-            this.top = top;\r
-            this.bottom = bottom;\r
-            this.left = left;\r
-            this.right = right;\r
-        }\r
-\r
-        /**\r
-         * @param a bitmask consisting of the values {@link #TOP},\r
-         *        {@link #BOTTOM}, {@link #LEFT} and {@link #RIGHT}\r
-         * @param top\r
-         * @return\r
-         */\r
-        public Margins withSide(int side, Margin m) {\r
-            Margin t = ((side & TOP) != 0) ? m : top;\r
-            Margin b = ((side & BOTTOM) != 0) ? m : bottom;\r
-            Margin l = ((side & LEFT) != 0) ? m : left;\r
-            Margin r = ((side & RIGHT) != 0) ? m : right;\r
-            return new Margins(t, b, l, r);\r
-        }\r
-\r
-        public boolean isZero() {\r
-            return top.isZero() && bottom.isZero() && left.isZero() && right.isZero();\r
-        }\r
-\r
-        @Override\r
-        public String toString() {\r
-            return "[top=" + top + ", bottom=" + bottom + ", left=" + left + ", right=" + right + "]";\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            result = prime * result + bottom.hashCode();\r
-            result = prime * result + left.hashCode();\r
-            result = prime * result + right.hashCode();\r
-            result = prime * result + top.hashCode();\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj)\r
-                return true;\r
-            if (obj == null)\r
-                return false;\r
-            if (getClass() != obj.getClass())\r
-                return false;\r
-            Margins other = (Margins) obj;\r
-            if (!top.equals(other.top))\r
-                return false;\r
-            if (!bottom.equals(other.bottom))\r
-                return false;\r
-            if (!left.equals(other.left))\r
-                return false;\r
-            if (!right.equals(other.right))\r
-                return false;\r
-            return true;\r
-        }\r
-    }\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.utils.page;
+
+
+/**
+ * 
+ * @See {@link RulerPainter} RulerPainter.RULER_MARGIN5
+ * @author Toni Kalajainen
+ */
+public class MarginUtils {
+
+    public static Margin marginOf(double controlRelative, double controlAbsolute, double diagramAbsolute) {
+        return new Margin(controlRelative/100, controlAbsolute, diagramAbsolute);
+    }
+
+    /** No margin */
+    public static final Margin NO_MARGIN = marginOf(0, 0, 0);
+    /** 5% margin */
+    public static final Margin MARGIN5 = marginOf(5, 0, 0);
+    /** 2% margin */
+    public static final Margin MARGIN2 = marginOf(2, 0, 0);
+    /** 10mm margin */
+    public static final Margin MARGIN_10mm = marginOf(0, 0, 10);
+
+    
+    /** No margins */
+    public static final Margins NO_MARGINS = new Margins(NO_MARGIN, NO_MARGIN, NO_MARGIN, NO_MARGIN);
+    /** 5% margin */
+    public static final Margins MARGINS5 = new Margins(MARGIN5, MARGIN5, MARGIN5, MARGIN5);
+    /** 2% margin */
+    public static final Margins MARGINS2 = new Margins(MARGIN2, MARGIN2, MARGIN2, MARGIN2);
+    /** 10mm margin */
+    public static final Margins MARGINS_10mm = new Margins(MARGIN_10mm, MARGIN_10mm, MARGIN_10mm, MARGIN_10mm);
+
+    /**
+     * A margin.
+     */
+    public static class Margin {
+        /** Relative margins 0..100 (in control coordinates) */
+        public final double controlRelative;
+        /** Margins in absolute values of control units */
+        public final double controlAbsolute;
+        /** Margins in absolute values of diaram units*/
+        public final double diagramAbsolute;
+
+        public Margin(double controlRelative, double controlAbsolute, double diagramAbsolute) {
+            this.controlRelative = controlRelative;
+            this.controlAbsolute = controlAbsolute;
+            this.diagramAbsolute = diagramAbsolute;
+        }
+
+        @Override
+        public String toString() {
+            return "(" + controlRelative + " " + controlAbsolute + " " + diagramAbsolute + ")";
+        }
+
+        public boolean isZero() {
+            return Math.abs(controlRelative) < Double.MIN_VALUE
+            && Math.abs(controlAbsolute) < Double.MIN_VALUE
+            && Math.abs(diagramAbsolute) < Double.MIN_VALUE;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            long temp;
+            temp = Double.doubleToLongBits(controlAbsolute);
+            result = prime * result + (int) (temp ^ (temp >>> 32));
+            temp = Double.doubleToLongBits(controlRelative);
+            result = prime * result + (int) (temp ^ (temp >>> 32));
+            temp = Double.doubleToLongBits(diagramAbsolute);
+            result = prime * result + (int) (temp ^ (temp >>> 32));
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            Margin other = (Margin) obj;
+            if (Double.doubleToLongBits(controlAbsolute) != Double.doubleToLongBits(other.controlAbsolute))
+                return false;
+            if (Double.doubleToLongBits(controlRelative) != Double.doubleToLongBits(other.controlRelative))
+                return false;
+            if (Double.doubleToLongBits(diagramAbsolute) != Double.doubleToLongBits(other.diagramAbsolute))
+                return false;
+            return true;
+        }
+    }
+
+    /**
+     * 4 margins: top, bottom, left, right
+     */
+    public static class Margins {
+
+        public static final int TOP    = 1 << 0;
+        public static final int BOTTOM = 1 << 1;
+        public static final int LEFT   = 1 << 2;
+        public static final int RIGHT  = 1 << 3;
+
+        public final Margin top;
+        public final Margin bottom;
+        public final Margin left;
+        public final Margin right;
+
+        public Margins(Margin top, Margin bottom, Margin left, Margin right) {
+            assert top != null;
+            assert bottom != null;
+            assert left != null;
+            assert right != null;
+
+            this.top = top;
+            this.bottom = bottom;
+            this.left = left;
+            this.right = right;
+        }
+
+        /**
+         * @param a bitmask consisting of the values {@link #TOP},
+         *        {@link #BOTTOM}, {@link #LEFT} and {@link #RIGHT}
+         * @param top
+         * @return
+         */
+        public Margins withSide(int side, Margin m) {
+            Margin t = ((side & TOP) != 0) ? m : top;
+            Margin b = ((side & BOTTOM) != 0) ? m : bottom;
+            Margin l = ((side & LEFT) != 0) ? m : left;
+            Margin r = ((side & RIGHT) != 0) ? m : right;
+            return new Margins(t, b, l, r);
+        }
+
+        public boolean isZero() {
+            return top.isZero() && bottom.isZero() && left.isZero() && right.isZero();
+        }
+
+        @Override
+        public String toString() {
+            return "[top=" + top + ", bottom=" + bottom + ", left=" + left + ", right=" + right + "]";
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + bottom.hashCode();
+            result = prime * result + left.hashCode();
+            result = prime * result + right.hashCode();
+            result = prime * result + top.hashCode();
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            Margins other = (Margins) obj;
+            if (!top.equals(other.top))
+                return false;
+            if (!bottom.equals(other.bottom))
+                return false;
+            if (!left.equals(other.left))
+                return false;
+            if (!right.equals(other.right))
+                return false;
+            return true;
+        }
+    }
+
+}