*******************************************************************************/\r
package org.simantics.sysdyn.ui.elements2;\r
\r
+import java.awt.Font;\r
+import java.awt.font.FontRenderContext;\r
+import java.awt.font.TextLayout;\r
+import java.awt.geom.AffineTransform;\r
import java.awt.geom.Rectangle2D;\r
\r
+import org.simantics.g2d.element.ElementHints;\r
import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.element.handler.InternalSize;\r
import org.simantics.g2d.utils.Alignment;\r
public class HoverTextElementHandler extends HoverTextElementNoBounds implements InternalSize {\r
\r
private static final long serialVersionUID = 8800738238681432901L;\r
- \r
+\r
public static final HoverTextElementHandler INSTANCE = new HoverTextElementHandler();\r
\r
public HoverTextElementHandler() {\r
size = new Rectangle2D.Double();\r
if (node != null)\r
size.setRect(node.getBoundsInLocal());\r
- else\r
- size.setFrame(0, 0, 0, 0);\r
+ else {\r
+ String text = e.getHint(ElementHints.KEY_TEXT);\r
+ Font font = e.getHint(ElementHints.KEY_FONT);\r
+ if(text == null || font == null)\r
+ size.setFrame(0, 0, 0, 0);\r
+ else {\r
+ FontRenderContext FRC = new FontRenderContext(new AffineTransform(), true, true);\r
+ TextLayout tl = new TextLayout(text, font, FRC);\r
+ Rectangle2D bounds = tl.getLogicalHighlightShape(0, text.length()).getBounds2D(); \r
+ size.setFrame(\r
+ bounds.getX() * SCALE - paddingX,\r
+ bounds.getY() * SCALE -paddingY, \r
+ bounds.getWidth()* SCALE + paddingX + paddingX, \r
+ bounds.getHeight()* SCALE + paddingY + paddingY);\r
+ }\r
+ }\r
return size;\r
}\r
}\r
}\r
};\r
}\r
+ \r
+ public static double SCALE = 0.235;\r
\r
@Override\r
public void init(final IElement e, G2DParentNode parent) {\r
String text = ElementUtils.getText(e);\r
AffineTransform at = ElementUtils.getTransform(e);\r
Alignment hAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, horizontalAlignment);\r
- node.init(text, font, color, originX, originY, 0.235);\r
+ node.init(text, font, color, originX, originY, SCALE);\r
node.setBackgroundColor(fillColor);\r
node.setBorderColor(borderColor);\r
node.setHorizontalAlignment((byte) hAlign.ordinal());\r
* An element class for Sysdyn Flow elements.\r
* Copied from RouteGraphConnectionClassFactory and adapted to Flow needs\r
* \r
- * @author Tuukka Lehtonen\r
+ * @author Teemu Lempinen\r
* \r
- * \r
- * \r
-ts. oma ehdotukseni on tämä:\r
-- etsi miten pystyt syöttämään jokaiselle sysdynin "terminaalille" oman ILineEndStyle:n joka sisältää viitteen mokkulan mittoihin\r
-- lisää direction-parametri getLineEndLength:iin niin että voit palauttaa siellä mokkulan mittojen mukaisen etäisyyden\r
*/\r
public class RouteFlowConnectionFactory extends SyncElementFactory {\r
\r
// Get element bounds to decide allowed terminal direction(s)\r
IElement te = graph.syncRequest(DiagramRequests.getElement(canvas, diagram, terminalElement, null));\r
\r
- \r
ElementUtils.getElementBounds(te, bounds);\r
+ \r
{\r
Shape shp = org.simantics.g2d.utils.GeometryUtils.transformShape(bounds, terminalElementTr);\r
bounds.setFrame(shp.getBounds2D());\r
}\r
}\r
\r
-// private int directionSetToToDirectionMask(DirectionSet directions) {\r
-// if (directions == DirectionSet.ANY)\r
-// return 0xf;\r
-// int mask = 0;\r
-// for (Double d : directions) {\r
-// mask |= compassAngleToToDirectionMask(d);\r
-// }\r
-// return mask;\r
-// }\r
-//\r
-// private int compassAngleToToDirectionMask(double compassAngle) {\r
-// Double d = DirectionSet.NESW.getClosestDirection(compassAngle);\r
-// int id = (int) Math.round(d);\r
-// // bits:\r
-// // 0 right (1,0)\r
-// // 1 down (0,1)\r
-// // 2 left (-1,0)\r
-// // 3 up (0,-1)\r
-// switch (id) {\r
-// case 0: return (1 << 3);\r
-// case 90: return (1 << 2);\r
-// case 180: return (1 << 1);\r
-// case 270: return (1 << 0);\r
-// }\r
-// return 0xf;\r
-// }\r
\r
protected void scheduleSynchronize(Session session, Resource connection, RouteGraphChangeEvent event) {\r
session.asyncRequest(RouteGraphConnection.synchronizer(connection, event));\r