Java Graphics Draw String drawLineDrawChar(Graphics g, int x, int y, int bi, char c, int charWidth, int charHeight)

Here you can find the source of drawLineDrawChar(Graphics g, int x, int y, int bi, char c, int charWidth, int charHeight)

Description

draw Line Draw Char

License

Open Source License

Declaration

protected static void drawLineDrawChar(Graphics g, int x, int y, int bi, char c, int charWidth,
            int charHeight) 

Method Source Code

//package com.java2s;
/******************************************************************************
 *
 * Copyright (c) 1999-2011 Cryptzone Group AB. All Rights Reserved.
 * /*from  w ww.j a v a 2s .  com*/
 * This file contains Original Code and/or Modifications of Original Code as
 * defined in and that are subject to the MindTerm Public Source License,
 * Version 2.0, (the 'License'). You may not use this file except in compliance
 * with the License.
 * 
 * You should have received a copy of the MindTerm Public Source License
 * along with this software; see the file LICENSE.  If not, write to
 * Cryptzone Group AB, Drakegatan 7, SE-41250 Goteborg, SWEDEN
 *
 *****************************************************************************/

import java.awt.Font;
import java.awt.Graphics;

public class Main {
    protected static void drawLineDrawChar(Graphics g, int x, int y, int bi, char c, int charWidth,
            int charHeight) {
        int x2 = (x + (charWidth / 2));
        int y2 = (y + (charHeight / 2));
        int xx = (x + charWidth);
        int yy = (y + charHeight);

        switch (c) {
        case ' ': // Blank
        case '_': // Blank
            break;
        case '`': // Diamond
            int[] polyX = new int[4];
            int[] polyY = new int[4];
            polyX[0] = x2;
            polyY[0] = y;
            polyX[1] = xx;
            polyY[1] = y2;
            polyX[2] = x2;
            polyY[2] = yy;
            polyX[3] = x;
            polyY[3] = y2;
            g.fillPolygon(polyX, polyY, 4);
            break;
        case 'a': // Checker board (stipple)
            for (int i = x; i < xx; i++) {
                for (int j = y; j < yy; j++) {
                    if (((i + j) % 2) == 0) {
                        g.fillRect(i, j, 1, 1);
                    }
                }
            }
            break;
        case 'b': // Horizontal tab
            drawTuplet(g, x, y, x2, y2, bi, "H", "T");
            break;
        case 'c': // Form Feed
            drawTuplet(g, x, y, x2, y2, bi, "F", "F");
            break;
        case 'd': // Carriage Return
            drawTuplet(g, x, y, x2, y2, bi, "C", "R");
            break;
        case 'e': // Line Feed
            drawTuplet(g, x, y, x2, y2, bi, "L", "F");
            break;
        case 'f': { // Degrees
            char[] ca = new char[1];
            ca[0] = (char) 0x00b0;
            g.drawChars(ca, 0, 1, x, y + bi);
            break;
        }
        case 'g': { // Plus/Minus
            char[] ca = new char[1];
            ca[0] = (char) 0x00b1;
            g.drawChars(ca, 0, 1, x, y + bi);
            break;
        }
        case 'h': // New line
            drawTuplet(g, x, y, x2, y2, bi, "N", "L");
            break;
        case 'i': // Vertical Tab
            drawTuplet(g, x, y, x2, y2, bi, "V", "T");
            break;
        case 'j': // Lower right corner
            g.drawLine(x2, y, x2, y2);
            g.drawLine(x2, y2, x, y2);
            break;
        case 'k': // Upper right corner
            g.drawLine(x, y2, x2, y2);
            g.drawLine(x2, y2, x2, yy);
            break;
        case 'l': // Upper left corner
            g.drawLine(x2, yy, x2, y2);
            g.drawLine(x2, y2, xx, y2);
            break;
        case 'm': // Lower left corner
            g.drawLine(x2, y, x2, y2);
            g.drawLine(x2, y2, xx, y2);
            break;
        case 'n': // Cross center lines
            g.drawLine(x2, y, x2, yy);
            g.drawLine(x, y2, xx, y2);
            break;
        case 'o': // Horizontal line (top)
            g.drawLine(x, y, xx, y);
            break;
        case 'p': // Horizontal line (top-half)
            g.drawLine(x, (y + y2) / 2, xx, (y + y2) / 2);
            break;
        case 'q': // Horizontal line (center)
            g.drawLine(x, y2, xx, y2);
            break;
        case 'r': // Horizontal line (bottom-half)
            g.drawLine(x, (yy + y2) / 2, xx, (yy + y2) / 2);
            break;
        case 's': // Horizontal line (bottom)
            g.drawLine(x, yy, xx, yy);
            break;
        case 't': // Left tee
            g.drawLine(x2, y, x2, yy);
            g.drawLine(x2, y2, xx, y2);
            break;
        case 'u': // Right tee
            g.drawLine(x2, y, x2, yy);
            g.drawLine(x, y2, x2, y2);
            break;
        case 'v': // Bottom tee
            g.drawLine(x, y2, xx, y2);
            g.drawLine(x2, y2, x2, y);
            break;
        case 'w': // Top tee
            g.drawLine(x, y2, xx, y2);
            g.drawLine(x2, y2, x2, yy);
            break;
        case 'x': // Vertical line
            g.drawLine(x2, y, x2, yy);
            break;
        case 'y': { // Less than or equal
            int dx = charWidth / 5;
            int dy = charHeight / 5;
            g.drawLine(x + dx, y2, xx - dx, y + 2 * dy);
            g.drawLine(x + dx, y2, xx - dx, yy - 2 * dy);
            g.drawLine(x + dx, y2 + dy, xx - dx, yy - dy);
            break;
        }
        case 'z': { // Greater than or equal
            int dx = charWidth / 5;
            int dy = charHeight / 5;
            g.drawLine(xx - dx, y2, x + dx, y + 2 * dy);
            g.drawLine(xx - dx, y2, x + dx, yy - 2 * dy);
            g.drawLine(xx - dx, y2 + dy, x + dx, yy - dy);
            break;
        }
        case '{': { // Pi
            char[] ca = new char[1];
            ca[0] = (char) 0x03c0;
            g.drawChars(ca, 0, 1, x, y + bi);
            break;
        }
        case '|': { // Not equal
            char[] ca = new char[1];
            ca[0] = (char) 0x2260;
            g.drawChars(ca, 0, 1, x, y + bi);
            break;
        }
        case '}': { // UK pound
            char[] ca = new char[1];
            ca[0] = (char) 0x00a3;
            g.drawChars(ca, 0, 1, x, y + bi);
            break;
        }
        case '~': { // Center dot
            char[] ca = new char[1];
            ca[0] = (char) 0x00b7;
            g.drawChars(ca, 0, 1, x, y + bi);
            break;
        }
        default:
            break;
        }
    }

    private static void drawTuplet(Graphics g, int x, int y, int x2, int y2, int bi, String s1, String s2) {
        Font font = g.getFont();
        g.setFont(new Font(font.getName(), font.getStyle(), font.getSize() / 2));
        g.drawString(s1, x + 1, y + 1 + bi / 2);
        g.drawString(s2, x2, y2 + bi / 2);
        g.setFont(font);
    }
}

Related

  1. drawFitText(Graphics2D g2, int x, int y, int width, int height, String text)
  2. drawFormattedString(Graphics2D g2, String htmlStr, int x, int y, int w, int h)
  3. drawGradient(Graphics g, JComponent c, String prefix)
  4. drawGradientText(Graphics g, String text, int x, int y, Color c)
  5. drawLine(String pLine, Graphics2D pG, int pX, int pY, int pWidth, String pJustification)
  6. drawMessage(Graphics2D g, String message)
  7. drawRightJustifiedText(String text, int right, int y, Graphics g)
  8. drawRightText(Graphics g, String str, int x, int y, int width, int height)
  9. drawRotatedShape(final Shape shape, final Graphics2D g2, final float x, final float y, final double angle)