Here you can find the source of drawScaleLabel(Graphics g, String label, int x, int y, boolean yAxisP)
Draws the scale label in the String
label using the graphics in the Graphics
object g.
Parameter | Description |
---|---|
g | <code>java.awt.Graphics</code> object to the graphics. |
label | <code>String</code> label of the scale label. |
x | int x-coordinate of the scale label. |
y | int y-coordinate of the scale label. |
yAxisP | boolean flag indicating whether the scale label is for the y-axis. |
private static void drawScaleLabel(Graphics g, String label, int x, int y, boolean yAxisP)
//package com.java2s; /**//from w w w .j a v a 2s .c o m * PlotUtilities.java * * * Cytobank (TM) is server and client software for web-based management, analysis, * and sharing of flow cytometry data. * * Copyright (C) 2009 Cytobank, Inc. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Cytobank, Inc. * 659 Oak Grove Avenue #205 * Menlo Park, CA 94025 * * http://www.cytobank.org */ import java.awt.*; public class Main { /** * <p> * Draws the scale label in the <code>String</code> label using the graphics * in the <code>Graphics</code> object g. * </p> * * <p> * The scale label is drawn using the current font in the graphics in the * <code>Graphics</code> object g. * </p> * * @param g * <code>java.awt.Graphics</code> object to the graphics. * @param label * <code>String</code> label of the scale label. * @param x * int x-coordinate of the scale label. * @param y * int y-coordinate of the scale label. * @param yAxisP * boolean flag indicating whether the scale label is for the * y-axis. */ private static void drawScaleLabel(Graphics g, String label, int x, int y, boolean yAxisP) { if ((g == null) || (label == null) || (label.length() <= 0)) { // If the graphics is null or the label is null or empty, then quit. return; } // Get the font metrics of the current font FontMetrics metrics = g.getFontMetrics(); // Get the height of the current font int fontHeight = metrics.getHeight(); // Get the width of the label in the current font int fontWidth = metrics.stringWidth(label); if (yAxisP) { // If the scale label is for the y-axis, then draw the label // centered around the y-coordinate with the right at the // x-coordinate. g.drawString(label, x - fontWidth, y + (fontHeight / 2)); } else { // Otherwise, the scale label is for the x-axis, so draw the label // centered around the x-coordinate with the top at the // y-coordinate. g.drawString(label, x - (fontWidth / 2), y + fontHeight); } } }