Java Graphics Draw drawStackTrace(Graphics gr, int x, int y, Throwable ex)

Here you can find the source of drawStackTrace(Graphics gr, int x, int y, Throwable ex)

Description

draw Stack Trace

License

Open Source License

Declaration

private static void drawStackTrace(Graphics gr, int x, int y,
            Throwable ex) 

Method Source Code

//package com.java2s;
/* ================================================================
 * Cewolf : Chart enabling Web Objects Framework
 * ================================================================
 *
 * Project Info:  http://cewolf.sourceforge.net
 * Project Lead:  Guido Laures (guido@laures.de);
 *
 * (C) Copyright 2002, by Guido Laures//  www. java 2 s  . com
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */

import java.awt.Graphics;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Enumeration;
import java.util.StringTokenizer;

public class Main {
    private static void drawStackTrace(Graphics gr, int x, int y,
            Throwable ex) {
        final int linePadding = 4;
        int lineHeight = gr.getFont().getSize() + linePadding;
        int currY = y;
        Enumeration lines = new StringTokenizer(getStackTrace(ex), "\n",
                false);
        while (lines.hasMoreElements()) {
            gr.drawString(((String) lines.nextElement()).trim(), x, currY);
            currY += lineHeight;
        }
    }

    private static String getStackTrace(Throwable t) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        pw.close();
        return sw.getBuffer().toString();
    }
}

Related

  1. drawScrollBar(Graphics g, int which, int direction, int x, int y, int fmWidth, int fmHeight, Color fg, Color bg)
  2. drawSelectionBox(Graphics g)
  3. drawSelectionPoint(Graphics g, Point p)
  4. drawSpline(Graphics graphics, int x1, int y1, int x2, int y2, int x3, int y3)
  5. drawSquarePoint(Graphics2D g2, Point2D.Double pt, int ptSize, Color color)
  6. drawStage(Graphics g, int x, int y)
  7. drawStar(Graphics g, int x, int y)
  8. drawTankISPip(Graphics2D g2d, int width, int height)
  9. drawTransparent(Graphics g, int x, int y, int width, int height)