001/*
002// $Id: TextBox.java 3 2009-05-11 08:11:57Z jhyde $
003// Clapham generates railroad diagrams to represent computer language grammars.
004// Copyright (C) 2008-2009 Julian Hyde
005// Copyright (c) 2005 Stefan Schoergenhumer, Markus Dopler
006//
007// This program is free software; you can redistribute it and/or modify it
008// under the terms of the GNU General Public License as published by the Free
009// Software Foundation; either version 2 of the License, or (at your option)
010// any later version approved by The Eigenbase Project.
011//
012// This program is distributed in the hope that it will be useful,
013// but WITHOUT ANY WARRANTY; without even the implied warranty of
014// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015// GNU General Public License for more details.
016//
017// You should have received a copy of the GNU General Public License
018// along with this program; if not, write to the Free Software
019// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020*/
021package net.hydromatic.clapham.graph;
022
023import java.awt.*;
024
025/**
026 * TODO:
027 *
028 * @author jhyde
029 * @version $Id: TextBox.java 3 2009-05-11 08:11:57Z jhyde $
030 * @since Sep 1, 2008
031 */
032public class TextBox {
033    private final Chart chart;
034    private final String text;
035    private final Font font;
036    private final Color color;
037    final int width;
038    final int height;
039
040    TextBox(Chart chart, String text, Font font, Color color) {
041        this.chart = chart;
042        this.text = text;
043        this.font = font;
044        this.color = color;
045        this.width = chart.getStringWidth(font, text);
046        this.height = chart.getFontHeight();
047
048    }
049
050    void drawAtCenter(float x1, float y1, float width, float height) {
051        float x = x1 + width / 2f;
052        x -= this.width / 2f;
053        float y = y1 + height / 2f;
054        y += this.height / 2f;
055        chart.drawString(text, font, color, x, y);
056    }
057}
058
059// End TextBox.java