Here you can find the source of drawPowerScaleLabel(Graphics g, int base, int power, int x, int y, boolean yAxisP)
Draws a scale label of the form of the base base take to the power of power with the power displayed as a superscript of the base using the graphics in the Graphics
object g.
Parameter | Description |
---|---|
g | <code>java.awt.Graphics</code> object to the graphics. |
base | int base. |
power | int power. |
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 drawPowerScaleLabel(Graphics g, int base, int power, int x, int y, boolean yAxisP)
//package com.java2s; /**//from w w w.j a v a2s. 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 a scale label of the form of the base base take to the power of * power with the power displayed as a superscript of the base 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 base * int base. * @param power * int power. * @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 drawPowerScaleLabel(Graphics g, int base, int power, int x, int y, boolean yAxisP) { if (g == null) { // If the graphics is null, then quit. return; } // Get the string for the base String baseString = Integer.toString(base); // Get the string for the power String powerString = Integer.toString(power); // 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 base string in the current font int baseWidth = metrics.stringWidth(baseString); // Get the width of the power string in the current font int powerWidth = metrics.stringWidth(powerString); if (yAxisP) { // If the scale label is for the y-axis, then draw the base and // power strings centered around the y-coordinate with the right at // the x-coordinate. g.drawString(baseString, x - (baseWidth + powerWidth), y + (int) ((double) fontHeight * 0.75d)); g.drawString(powerString, x - powerWidth, y + (int) ((double) fontHeight * 0.25d)); } else { // Otherwise, the scale label is for the x-axis, so draw the base // and power strings centered around the x-coordinate with the top // at the y-coordinate g.drawString(baseString, x - ((baseWidth + powerWidth) / 2), y + fontHeight + fontHeight / 2); g.drawString(powerString, x - ((baseWidth + powerWidth) / 2) + baseWidth, y + fontHeight); } } }