/*
* JDrawHelper.java
*
* Created on 01.01.2010, 00:36:55
*
* Copyright (C) 01.01.2010, 00:36:55 <reiner>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package shared.swing;
import java.awt.FontMetrics;
import java.awt.Graphics;
final public class JDrawHelper
{
private JDrawHelper()
{}
// y center
public static void drawStringCenter(Graphics g, String str, int xPos, int yPos)
{
FontMetrics fm = g.getFontMetrics();
double strW = fm.stringWidth(str);
g.drawString(str, xPos + (int)(-strW/2.0 + .5), (int)(yPos + fm.getAscent()*.48 + .5));
}
public static void drawStringLeftCenter(Graphics g, String str, int xPos, int yPos)
{
FontMetrics fm = g.getFontMetrics();
double strW = fm.stringWidth(str);
g.drawString(str, xPos, (int)(yPos + fm.getAscent()*.48 + .5));
}
public static void drawStringRightCenter(Graphics g, String str, int xPos, int yPos)
{
FontMetrics fm = g.getFontMetrics();
double strW = fm.stringWidth(str);
g.drawString(str, xPos - (int)(strW +.5), (int)(yPos + fm.getAscent()*.48 + .5));
}
// y top
public static void drawStringTop(Graphics g, String str, int xPos, int yPos)
{
FontMetrics fm = g.getFontMetrics();
double strW = fm.stringWidth(str);
g.drawString(str, xPos + (int)(-strW/2.0 + .5), yPos + fm.getAscent());
}
public static void drawStringLeftTop(Graphics g, String str, int xPos, int yPos)
{
FontMetrics fm = g.getFontMetrics();
double strW = fm.stringWidth(str);
g.drawString(str, xPos, yPos + fm.getAscent());
}
public static void drawStringRightTop(Graphics g, String str, int xPos, int yPos)
{
FontMetrics fm = g.getFontMetrics();
double strW = fm.stringWidth(str);
g.drawString(str, xPos - (int)(strW +.5), yPos + fm.getAscent());
}
// y bottom
public static void drawStringBottom(Graphics g, String str, int xPos, int yPos)
{
FontMetrics fm = g.getFontMetrics();
double strW = fm.stringWidth(str);
g.drawString(str, xPos + (int)(-strW/2.0 + .5), yPos);
}
public static void drawStringLeftBottom(Graphics g, String str, int xPos, int yPos)
{
g.drawString(str, xPos, yPos);
}
public static void drawStringRightBottom(Graphics g, String str, int xPos, int yPos)
{
FontMetrics fm = g.getFontMetrics();
double strW = fm.stringWidth(str);
g.drawString(str, xPos - (int)(strW +.5), yPos);
}
}