*******************************************************************************/
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;
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
*/
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();
}
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;