-/*******************************************************************************\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
+/*******************************************************************************
+ * 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.scenegraph.g2d.nodes;
-import java.awt.AlphaComposite;\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.Font;\r
-import java.awt.FontMetrics;\r
-import java.awt.Graphics2D;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.Locale;\r
-\r
-import org.simantics.scenegraph.g2d.G2DNode;\r
-import org.simantics.scenegraph.utils.GridUtils;\r
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.util.Locale;
+
+import org.simantics.scenegraph.g2d.G2DNode;
+import org.simantics.scenegraph.utils.GridUtils;
public class RulerNode extends G2DNode {
/**
*
*/
- private static final long serialVersionUID = 2490944880914577411L;\r
-\r
- /**\r
- * FIXME: this is a hack for the map UI that has to be solved some other way.\r
- */\r
- private static final boolean MAP_Y_SCALING = false;\r
-\r
- private static final Color GRAY = new Color(100, 100, 100);\r
-\r
- protected Boolean enabled = true;\r
-\r
- protected double gridSize = 1.0;\r
-\r
- @SyncField("enabled")\r
- public void setEnabled(Boolean enabled) {\r
- this.enabled = enabled;\r
- }\r
-\r
- @SyncField("gridSize")\r
- public void setGridSize(double gridSize) {\r
- if (gridSize < 1e-6)\r
- gridSize = 1e-6;\r
- this.gridSize = gridSize;\r
- }\r
-\r
+ private static final long serialVersionUID = 2490944880914577411L;
+
+ /**
+ * FIXME: this is a hack for the map UI that has to be solved some other way.
+ */
+ private static final boolean MAP_Y_SCALING = false;
+
+ private static final Color GRAY = new Color(100, 100, 100);
+
+ protected Boolean enabled = true;
+
+ protected double gridSize = 1.0;
+
+ @SyncField("enabled")
+ public void setEnabled(Boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @SyncField("gridSize")
+ public void setGridSize(double gridSize) {
+ if (gridSize < 1e-6)
+ gridSize = 1e-6;
+ this.gridSize = gridSize;
+ }
+
@Override
public void render(Graphics2D g) {
- if (!enabled)\r
- return;\r
-\r
+ if (!enabled)
+ return;
+
AffineTransform tr = g.getTransform();
double scaleX = Math.abs(tr.getScaleX());
double scaleY = Math.abs(tr.getScaleY());
// stepX and stepY should be something between 50 and 100
double stepX = 50;
double stepY = 50;
-\r
- stepX = GridUtils.limitedEvenGridSpacing(stepX, scaleX, 100, gridSize, true);\r
- stepY = GridUtils.limitedEvenGridSpacing(stepY, scaleY, 100, gridSize, true);\r
+
+ stepX = GridUtils.limitedEvenGridSpacing(stepX, scaleX, 100, gridSize, true);
+ stepY = GridUtils.limitedEvenGridSpacing(stepY, scaleY, 100, gridSize, true);
//while(stepX * scaleX > 100) stepX /= 2;
//while(stepY * scaleY > 100) stepY /= 2;
while(stepX * scaleX < 50) stepX *= 2;
while(stepY * scaleY < 50) stepY *= 2;
-\r
+
stepX *= scaleX;
stepY *= scaleY;
double previousText = -100;
// Vertical ruler
- for(double x = offsetX%stepX-stepX; x < bounds.getMaxX(); x+=stepX) {\r
+ for(double x = offsetX%stepX-stepX; x < bounds.getMaxX(); x+=stepX) {
if(x > 20) {
String str = formatValue((x-offsetX)/scaleX);
FontMetrics fm = g.getFontMetrics();
}
}
-\r
+
// Horizontal ruler
previousText = -100;
- for(double y = offsetY%stepY-stepY; y < bounds.getMaxY(); y+=stepY) {\r
- if(y > 20) {\r
- double val = (y-offsetY)/scaleY;\r
- if (MAP_Y_SCALING)\r
- val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val))));\r
+ for(double y = offsetY%stepY-stepY; y < bounds.getMaxY(); y+=stepY) {
+ if(y > 20) {
+ double val = (y-offsetY)/scaleY;
+ if (MAP_Y_SCALING)
+ val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val))));
String str = formatValue(val);
FontMetrics fm = g.getFontMetrics();
Rectangle2D r = fm.getStringBounds(str, g);
}
g.setTransform(tr);
- }\r
+ }
private static final transient int MAX_DIGITS = 5;
private static final transient double EPSILON = 0.01;