]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.maps/src/org/simantics/maps/sg/MapAttributionNode.java
Optimization of district scene graph node rendering
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / sg / MapAttributionNode.java
index b2d28c0b7575491bdd0e3d690c19fbf42fc30ccc..97706d23c6404ef88f00281c98e2e9f0915a0f83 100644 (file)
@@ -1,84 +1,56 @@
 package org.simantics.maps.sg;
 
-import java.awt.AlphaComposite;
-import java.awt.BasicStroke;
 import java.awt.Color;
-import java.awt.Font;
+import java.awt.Composite;
 import java.awt.FontMetrics;
 import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 
-import org.simantics.scenegraph.g2d.G2DNode;
-import org.simantics.scenegraph.utils.DPIUtil;
-
-public class MapAttributionNode extends G2DNode {
+public class MapAttributionNode extends MapInfoNode {
 
     private static final long serialVersionUID = 7994492218791569147L;
 
-    private static final Color GRAY              = new Color(100, 100, 100);
-
-    protected boolean enabled = true;
-
     @Override
     public void render(Graphics2D g2d) {
         if (!enabled)
             return;
-        
+
         AffineTransform ot = g2d.getTransform();
-        Color originalColor = g2d.getColor();
-        g2d.transform(transform);
-        
         g2d.setTransform(new AffineTransform());
-        // do the rendering magic
-        
-        Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9));
-        
-        //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        g2d.setStroke(new BasicStroke(1));
-        g2d.setColor(new Color(0.9f, 0.9f, 0.9f, 0.75f));
-        
-        Rectangle2D bounds = g2d.getClipBounds();
-        if (bounds == null)
+
+        Rectangle2D controlBounds = g2d.getClipBounds();
+        if (controlBounds == null)
             return; // FIXME
 
-        String str = "Map data \u00A9 OpenStreetMap contributors";
-        
-        g2d.setFont(rulerFont);
+        g2d.setFont(MapInfoConstants.getInfoFont());
+
         FontMetrics fm = g2d.getFontMetrics();
-        Rectangle2D r = fm.getStringBounds(str, g2d);
+        Rectangle2D r = fm.getStringBounds(MapInfoConstants.ATTRIBUTION, g2d);
+
+        double yOffsetFromBottom = getMapInfoNextY(g2d);
+        double frameMaxX = controlBounds.getMaxX();
+        double frameMaxY = controlBounds.getMaxY() - yOffsetFromBottom;
+        int frameWidth = (int) Math.ceil(r.getWidth()) + MapInfoConstants.TEXT_HORIZONTAL_MARGIN * 2;
+        int frameHeight = (int) Math.ceil(r.getHeight()) + MapInfoConstants.TEXT_VERTICAL_MARGIN * 2;
+
+        Composite oc = g2d.getComposite();
+        g2d.setComposite(MapInfoConstants.INFO_COMPOSITE);
+        g2d.setStroke(MapInfoConstants.INFO_STROKE);
+
+        g2d.setColor(MapInfoConstants.TEXT_BG_COLOR);
+        rect.setFrameFromDiagonal(frameMaxX - frameWidth, frameMaxY - frameHeight, frameMaxX, frameMaxY);
+        g2d.fill(rect);
 
-        double pixels = r.getWidth();
-        double scaleRight = bounds.getMaxX();
-        double newScaleLeft = scaleRight - pixels;
-        double y = bounds.getMaxY();
-        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
-        
-        
-        Rectangle2D vertical = new Rectangle2D.Double(newScaleLeft - 10, y - 15, pixels + 10, 15);
-        g2d.fill(vertical);
-        
-        g2d.setColor(GRAY);
-        g2d.setFont(rulerFont);
-        
-        
         g2d.setColor(Color.BLACK);
-        g2d.drawString(str, (int)newScaleLeft - 5, (int)y - 5);
-        
-        g2d.setColor(originalColor);
-        g2d.setTransform(ot);
-    }
+        g2d.drawString(MapInfoConstants.ATTRIBUTION,
+                (int) rect.getMinX() + MapInfoConstants.TEXT_HORIZONTAL_MARGIN,
+                (int) frameMaxY - fm.getMaxDescent() - MapInfoConstants.TEXT_VERTICAL_MARGIN);
 
-    @Override
-    public Rectangle2D getBoundsInLocal() {
-        return null;
-    }
+        g2d.setComposite(oc);
+        g2d.setTransform(ot);
 
-    public boolean isEnabled() {
-        return enabled;
+        setMapInfoNextY(g2d, yOffsetFromBottom + rect.getHeight() + MapInfoConstants.INFO_ROW_SPACING);
     }
 
-    public void setEnabled(boolean enabled) {
-        this.enabled = enabled;
-    }
 }