| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TextObject |
|
| 1.3333333333333333;1,333 |
| 1 | /* | |
| 2 | * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | ||
| 17 | /* $Id: TextObject.java,v 8afef6dd0d58 2007/09/14 08:29:58 maxberger $ */ | |
| 18 | ||
| 19 | package net.sourceforge.jeuclid.layout; | |
| 20 | ||
| 21 | import java.awt.Color; | |
| 22 | import java.awt.Graphics2D; | |
| 23 | import java.awt.font.TextLayout; | |
| 24 | import java.awt.geom.AffineTransform; | |
| 25 | ||
| 26 | /** | |
| 27 | * @version $Revision: 8afef6dd0d58 $ | |
| 28 | */ | |
| 29 | 209 | public class TextObject implements GraphicsObject { |
| 30 | ||
| 31 | private final TextLayout layout; | |
| 32 | ||
| 33 | private final Color color; | |
| 34 | ||
| 35 | private final float xoffset; | |
| 36 | ||
| 37 | private final float yoffset; | |
| 38 | ||
| 39 | private final AffineTransform trans; | |
| 40 | ||
| 41 | /** | |
| 42 | * Default Constructor. | |
| 43 | * | |
| 44 | * @param textLayout | |
| 45 | * Text Layout. | |
| 46 | * @param xo | |
| 47 | * X-Offset | |
| 48 | * @param textColor | |
| 49 | * text color. | |
| 50 | */ | |
| 51 | public TextObject(final TextLayout textLayout, final float xo, | |
| 52 | 25506 | final Color textColor) { |
| 53 | 25506 | assert textLayout != null; |
| 54 | 25506 | this.layout = textLayout; |
| 55 | 25506 | this.color = textColor; |
| 56 | 25506 | this.xoffset = xo; |
| 57 | 25506 | this.yoffset = 0.0f; |
| 58 | 25506 | this.trans = null; |
| 59 | 25506 | } |
| 60 | ||
| 61 | /** | |
| 62 | * Constructor for more complex texts (operators). | |
| 63 | * | |
| 64 | * @param textLayout | |
| 65 | * Text Layout. | |
| 66 | * @param textColor | |
| 67 | * text color. | |
| 68 | * @param xo | |
| 69 | * X-Offset for drawing. | |
| 70 | * @param yo | |
| 71 | * Y-Offset for drawing. | |
| 72 | * @param transform | |
| 73 | * Transformation to apply before drawing. | |
| 74 | */ | |
| 75 | public TextObject(final TextLayout textLayout, final float xo, | |
| 76 | final float yo, final AffineTransform transform, | |
| 77 | 15466 | final Color textColor) { |
| 78 | 15466 | assert textLayout != null; |
| 79 | 15466 | this.layout = textLayout; |
| 80 | 15466 | this.color = textColor; |
| 81 | 15466 | this.xoffset = xo; |
| 82 | 15466 | this.yoffset = yo; |
| 83 | 15466 | this.trans = transform; |
| 84 | 15466 | } |
| 85 | ||
| 86 | /** {@inheritDoc} */ | |
| 87 | public void paint(final float x, final float y, final Graphics2D g) { | |
| 88 | 38038 | g.setColor(this.color); |
| 89 | 38038 | final AffineTransform oldTrans = g.getTransform(); |
| 90 | 38038 | g.translate(x + this.xoffset, y + this.yoffset); |
| 91 | 38038 | if (this.trans != null) { |
| 92 | 7733 | g.transform(this.trans); |
| 93 | } | |
| 94 | 38038 | this.layout.draw(g, 0, 0); |
| 95 | 38038 | g.setTransform(oldTrans); |
| 96 | 38038 | } |
| 97 | } |