]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
TextGrid changes for Solvo
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 15 Jun 2020 05:36:01 +0000 (08:36 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Wed, 29 Jul 2020 15:16:11 +0000 (18:16 +0300)
Change-Id: Ibccd48e98a68ce15cb2d9735ae9198f08388112d

bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextGridNode.java
bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java

index 3b8de909280becba65a9c80090d203f3381d0aa7..afd9772db217cff501f82f360d1f9ecc6013d438 100644 (file)
  *******************************************************************************/
 package org.simantics.diagram.elements;
 
-import gnu.trove.map.TIntObjectMap;
-import gnu.trove.map.TMap;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.map.hash.TIntObjectHashMap;
-import gnu.trove.procedure.TObjectProcedure;
-
 import java.awt.Color;
 import java.awt.Font;
-import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
@@ -42,6 +35,12 @@ import org.simantics.scenegraph.g2d.nodes.Decoration;
 import org.simantics.scenegraph.utils.NodeUtil;
 import org.simantics.scl.runtime.function.Function1;
 
+import gnu.trove.map.TIntObjectMap;
+import gnu.trove.map.TMap;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import gnu.trove.procedure.TObjectProcedure;
+
 /**
  * TODO: does not work remotely, e.g. rowIds 
  */
@@ -264,13 +263,41 @@ public class TextGridNode extends G2DParentNode implements Decoration {
         return rowIds.get(y);
     }
     
+    class FontSizeSum implements TObjectProcedure<Cell> {
+        
+        final double[] hs;
+        
+        FontSizeSum(int maxY) {
+            hs = new double[maxY+1];
+        }
+        
+        @Override
+        public boolean execute(Cell key) {
+            A a = nodes.get(key);
+            int h = a.getFont().getSize();
+            if(h > hs[key.y])
+                hs[key.y] = h;
+            return true;
+        }
+        
+        public double getH() {
+            double result = 0;
+            for(int i=0;i<hs.length;i++)
+                result += hs[i];
+            return result;
+        }
+        
+    }
+
     @Override
     public void refresh() {
+        FontSizeSum fss = new FontSizeSum(computeRows());
+        nodes.forEachKey(fss);
         Vec2d delta = getDelta(FACTOR);
         if(delta != null)
-            setTransform(AffineTransform.getTranslateInstance(delta.x, delta.y-2.1*computeRows()*(up ? 1.0 : 0.0)));
+            setTransform(AffineTransform.getTranslateInstance(delta.x, delta.y-0.15*fss.getH()*(up ? 1.0 : 0.0)));
         else
-            setTransform(AffineTransform.getTranslateInstance(0, -2.1*computeRows()*(up ? 1.0 : 0.0)));
+            setTransform(AffineTransform.getTranslateInstance(0, -0.15*fss.getH()*(up ? 1.0 : 0.0)));
         super.refresh();
     }
     
@@ -350,8 +377,8 @@ public class TextGridNode extends G2DParentNode implements Decoration {
        Rectangle2D bounds = super.getBoundsInLocal(false);
        if(bounds == null) return false;
        Point2D localPos = NodeUtil.worldToLocal(this, event.controlPosition, new Point2D.Double());
-       double x = localPos.getX();
-       double y = localPos.getY()+2.1*computeRows()*(up ? 1.0 : 0.0);
+        double x = localPos.getX();
+       double y = localPos.getY()+(up ? bounds.getHeight() : 0.0);
        boolean hit = bounds.contains(x, y);
        return hit;
        
index bf1bf563b32c9f9e89c2c2355902d2a5b5f1ef02..7c684f30b372b6d915baa9c74f7bb4c675856720 100644 (file)
@@ -632,7 +632,7 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
         boolean hover = hasState(STATE_HOVER);
         boolean editing = hasState(STATE_EDITING);
 
-        if (!isSelected && hover) {
+        if (!isSelected && hover && textListener != null) {
             color = add(color, 120, 120, 120);
         }