Esempio n. 1
0
 /**
  * Returns the width of the specified codepoint.
  *
  * @param g graphics reference
  * @param cp character
  * @return width
  */
 private int charW(final Graphics g, final int cp) {
   return cp < ' ' || g == null
       ? cp == '\t' ? fwidth[' '] * BaseXTextTokens.TAB : 0
       : cp < 256
           ? fwidth[cp]
           : cp >= 0xD800 && cp <= 0xDC00 ? 0 : g.getFontMetrics().charWidth(cp);
 }
Esempio n. 2
0
 /**
  * Draws a visualization tooltip.
  *
  * @param g graphics reference
  * @param tt tooltip label
  * @param x horizontal position
  * @param y vertical position
  * @param w width
  * @param c color color depth
  */
 public static void drawTooltip(
     final Graphics g, final String tt, final int x, final int y, final int w, final int c) {
   final int tw = width(g, tt);
   final int th = g.getFontMetrics().getHeight();
   final int xx = Math.min(w - tw - 8, x);
   g.setColor(color(c));
   g.fillRect(xx - 1, y - th, tw + 4, th);
   g.setColor(BACK);
   g.drawString(tt, xx, y - 4);
 }
Esempio n. 3
0
  @Override
  public void paintComponent(final Graphics g) {
    super.paintComponent(g);

    final Runtime rt = Runtime.getRuntime();
    final long max = rt.maxMemory();
    final long total = rt.totalMemory();
    final long used = total - rt.freeMemory();
    final int ww = getWidth();
    final int hh = getHeight();

    // draw memory box
    g.setColor(Color.white);
    g.fillRect(0, 0, ww - 3, hh - 3);
    g.setColor(GRAY);
    g.drawLine(0, 0, ww - 4, 0);
    g.drawLine(0, 0, 0, hh - 4);
    g.drawLine(ww - 3, 0, ww - 3, hh - 3);
    g.drawLine(0, hh - 3, ww - 3, hh - 3);

    // show total memory usage
    g.setColor(color1);
    g.fillRect(2, 2, Math.max(1, (int) (total * (ww - 6) / max)), hh - 6);

    // show current memory usage
    final boolean full = used * 6 / 5 > max;
    g.setColor(full ? colormark4 : color3);
    g.fillRect(2, 2, Math.max(1, (int) (used * (ww - 6) / max)), hh - 6);

    // print current memory usage
    final FontMetrics fm = g.getFontMetrics();
    final String mem = Performance.format(used, true);
    final int fw = (ww - fm.stringWidth(mem)) / 2;
    final int h = fm.getHeight() - 3;
    g.setColor(full ? colormark3 : DGRAY);
    g.drawString(mem, fw, h);
  }
Esempio n. 4
0
 /**
  * Returns the character width of the specified character.
  *
  * @param g graphics reference
  * @param cw array with character widths
  * @param c character
  * @return character width
  */
 public static int width(final Graphics g, final int[] cw, final int c) {
   return c >= cw.length ? g.getFontMetrics().charWidth(c) : cw[c];
 }
Esempio n. 5
0
 /**
  * Returns the width of the specified text.
  *
  * @param g graphics reference
  * @param s string to be evaluated
  * @return string width
  */
 public static int width(final Graphics g, final String s) {
   return g.getFontMetrics().stringWidth(s);
 }