X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fnodes%2FTextNode.java;fp=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fnodes%2FTextNode.java;h=b7bd4810091bede5a01d65a891bedcca51c53719;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=15076e6295ccd7cba71bae4121b4d3a8dfd3fe53;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/TextNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/TextNode.java index 15076e629..b7bd48100 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/TextNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/TextNode.java @@ -1,37 +1,37 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.scenegraph.g2d.nodes; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics2D; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.io.IOException; - -import org.simantics.scenegraph.ExportableWidget.OutputWidget; -import org.simantics.scenegraph.g2d.G2DNode; -import org.simantics.scenegraph.g2d.G2DPDFRenderingHints; - -import com.lowagie.text.DocumentException; -import com.lowagie.text.Element; -import com.lowagie.text.Rectangle; -import com.lowagie.text.pdf.FontMapper; -import com.lowagie.text.pdf.PdfFormField; -import com.lowagie.text.pdf.PdfWriter; -import com.lowagie.text.pdf.TextField; - +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.io.IOException; + +import org.simantics.scenegraph.ExportableWidget.OutputWidget; +import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.g2d.G2DPDFRenderingHints; + +import com.lowagie.text.DocumentException; +import com.lowagie.text.Element; +import com.lowagie.text.Rectangle; +import com.lowagie.text.pdf.FontMapper; +import com.lowagie.text.pdf.PdfFormField; +import com.lowagie.text.pdf.PdfWriter; +import com.lowagie.text.pdf.TextField; + @OutputWidget("text") public class TextNode extends G2DNode { @@ -57,22 +57,22 @@ public class TextNode extends G2DNode { this.text = text; } - public String getText() { - return this.text; - } - + public String getText() { + return this.text; + } + @SyncField("color") public void setColor(Color color) { this.color = color; } @Override - public void render(Graphics2D g) { - if (text == null || bounds == null || font == null || color == null) - return; - -// PdfWriter writer = (PdfWriter) g.getRenderingHint(G2DPDFRenderingHints.KEY_PDF_WRITER); -// if ( writer == null ) { + public void render(Graphics2D g) { + if (text == null || bounds == null || font == null || color == null) + return; + +// PdfWriter writer = (PdfWriter) g.getRenderingHint(G2DPDFRenderingHints.KEY_PDF_WRITER); +// if ( writer == null ) { // Write to Graphics2D g.setFont(font); g.setColor(color); @@ -80,62 +80,62 @@ public class TextNode extends G2DNode { FontMetrics fm = g.getFontMetrics(font); Rectangle2D rect = fm.getStringBounds(text, g); float x = (float) ((bounds.getWidth() - rect.getWidth())/2 + bounds.getMinX()); - float y = (float) ((bounds.getHeight() - rect.getHeight())/2 + bounds.getMinY()); - - AffineTransform at = g.getTransform(); + float y = (float) ((bounds.getHeight() - rect.getHeight())/2 + bounds.getMinY()); + + AffineTransform at = g.getTransform(); g.transform(getTransform()); - g.drawString(text, x, (float)(y+rect.getHeight())); - g.setTransform(at); -// } else { - /* - try { - // Write to PDF - FontMapper mapper = (FontMapper) g.getRenderingHint(G2DPDFRenderingHints.KEY_PDF_FONTMAPPER); - //text.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED); - AffineTransform at = g.getTransform(); - FontMetrics fm = g.getFontMetrics(font); - Rectangle2D rect = fm.getStringBounds(text, g); - float x = (float) ((bounds.getWidth() - rect.getWidth())/2 + bounds.getMinX()); - float y = (float) ((bounds.getHeight() - rect.getHeight())/2 + bounds.getMinY()); - - Point2D pt1 = at.transform(new Point2D.Float(x, y+(float)rect.getHeight()), null); - Point2D pt2 = at.transform(new Point2D.Float(x+(float)rect.getWidth(), y), null); - Rectangle rectangle = new Rectangle( - (float) pt1.getX(), - (float) pt1.getY(), - (float) pt2.getX(), - (float) pt2.getY()); - TextField text = new TextField(writer, rectangle, "approvedBy"); - text.setText(this.text); - text.setFont(mapper.awtToPdf(font)); - text.setFontSize(0); - text.setAlignment(Element.ALIGN_LEFT); - text.setRotation(90); - text.setOptions(TextField.READ_ONLY); - PdfFormField field = text.getTextField(); - writer.addAnnotation(field); - } catch (IOException e) { - e.printStackTrace(); - } catch (DocumentException e) { - e.printStackTrace(); - } - */ + g.drawString(text, x, (float)(y+rect.getHeight())); + g.setTransform(at); +// } else { + /* + try { + // Write to PDF + FontMapper mapper = (FontMapper) g.getRenderingHint(G2DPDFRenderingHints.KEY_PDF_FONTMAPPER); + //text.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED); + AffineTransform at = g.getTransform(); + FontMetrics fm = g.getFontMetrics(font); + Rectangle2D rect = fm.getStringBounds(text, g); + float x = (float) ((bounds.getWidth() - rect.getWidth())/2 + bounds.getMinX()); + float y = (float) ((bounds.getHeight() - rect.getHeight())/2 + bounds.getMinY()); + + Point2D pt1 = at.transform(new Point2D.Float(x, y+(float)rect.getHeight()), null); + Point2D pt2 = at.transform(new Point2D.Float(x+(float)rect.getWidth(), y), null); + Rectangle rectangle = new Rectangle( + (float) pt1.getX(), + (float) pt1.getY(), + (float) pt2.getX(), + (float) pt2.getY()); + TextField text = new TextField(writer, rectangle, "approvedBy"); + text.setText(this.text); + text.setFont(mapper.awtToPdf(font)); + text.setFontSize(0); + text.setAlignment(Element.ALIGN_LEFT); + text.setRotation(90); + text.setOptions(TextField.READ_ONLY); + PdfFormField field = text.getTextField(); + writer.addAnnotation(field); + } catch (IOException e) { + e.printStackTrace(); + } catch (DocumentException e) { + e.printStackTrace(); + } + */ // } } // @Override // public Rectangle2D getBoundsInLocal() { // return bounds; -// } - - @Override - public Rectangle2D getBoundsInLocal() { - return bounds; - } - - @Override - public Rectangle2D getBounds() { - return null; - } +// } + + @Override + public Rectangle2D getBoundsInLocal() { + return bounds; + } + + @Override + public Rectangle2D getBounds() { + return null; + } }