1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.elements;
\r
14 import java.awt.Color;
\r
15 import java.awt.Font;
\r
16 import java.awt.geom.AffineTransform;
\r
17 import java.awt.geom.Rectangle2D;
\r
19 import org.simantics.diagram.elements.TextElementNoBounds;
\r
20 import org.simantics.diagram.elements.TextNode;
\r
21 import org.simantics.g2d.element.ElementHints;
\r
22 import org.simantics.g2d.element.ElementUtils;
\r
23 import org.simantics.g2d.element.IElement;
\r
24 import org.simantics.g2d.utils.Alignment;
\r
25 import org.simantics.scenegraph.g2d.G2DParentNode;
\r
26 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
27 import org.simantics.utils.datastructures.hints.IHintListener;
\r
28 import org.simantics.utils.datastructures.hints.IHintObservable;
\r
31 * Multi-line text element
\r
33 * @author Teemu Lempinen
\r
36 public class MultilineTextElement extends TextElementNoBounds {
\r
38 public MultilineTextElement(double originX, double originY, Alignment horizontalAlignment, double borderWidth, double paddingX, double paddingY, boolean editable) {
\r
39 super(originX, originX, horizontalAlignment, borderWidth, paddingX, paddingY, editable);
\r
42 private static final long serialVersionUID = -8558567466321214111L;
\r
45 public void init(final IElement e, G2DParentNode parent) {
\r
46 MultilineTextNode node = e.getHint(SG_NODE);
\r
48 node = parent.addNode(MultilineTextNode.class);
\r
49 e.setHint(SG_NODE, node);
\r
52 Font font = ElementUtils.getTextFont(e);
\r
53 Color color = ElementUtils.getTextColor(e);
\r
54 Color fillColor = ElementUtils.getFillColor(e);
\r
55 Color borderColor = ElementUtils.getBorderColor(e, Color.GRAY);
\r
56 String text = ElementUtils.getText(e);
\r
57 AffineTransform at = ElementUtils.getTransform(e);
\r
58 Alignment hAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, horizontalAlignment);
\r
59 node.init(text, font, color, originX, originY, 0.235);
\r
60 node.setBackgroundColor(fillColor);
\r
61 node.setBorderColor(borderColor);
\r
62 node.setHorizontalAlignment((byte) hAlign.ordinal());
\r
63 node.setPadding(paddingX, paddingY);
\r
64 node.setBorderWidth((float) 1);
\r
65 node.setEditable(false); // Multiline text fields are not editable
\r
67 Rectangle2D bounds = ElementUtils.getElementBounds(e);
\r
68 node.setBounds(new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight())); // Multiline text fields have fixed bounds
\r
70 node.setTransform(at);
\r