예제 #1
0
  /**
   * Draws the specified string.
   *
   * @param g graphics reference
   * @param s text
   * @param x x coordinate
   * @param y y coordinate
   * @param w width
   * @param fs font size
   */
  public static void chopString(
      final Graphics g, final byte[] s, final int x, final int y, final int w, final int fs) {

    if (w < 12) return;
    final int[] cw = fontWidths(g.getFont());

    int j = s.length;
    try {
      int l = 0;
      int fw = 0;
      for (int k = 0; k < j; k += l) {
        final int ww = width(g, cw, cp(s, k));
        if (fw + ww >= w - 4) {
          j = Math.max(1, k - l);
          if (k > 1) fw -= width(g, cw, cp(s, k - 1));
          g.drawString("..", x + fw, y + fs);
          break;
        }
        fw += ww;
        l = cl(s, k);
      }
    } catch (final Exception ex) {
      Util.debug(ex);
    }
    g.drawString(string(s, 0, j), x, y + fs);
  }
예제 #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);
 }
예제 #3
0
 /**
  * Returns the width of the specified text. Cached font widths are used to speed up calculation.
  *
  * @param g graphics reference
  * @param s string to be evaluated
  * @return string width
  */
 public static int width(final Graphics g, final byte[] s) {
   final int[] cw = fontWidths(g.getFont());
   final int l = s.length;
   int fw = 0;
   try {
     // ignore faulty character sets
     for (int k = 0; k < l; k += cl(s, k)) fw += width(g, cw, cp(s, k));
   } catch (final Exception ex) {
     Util.debug(ex);
   }
   return fw;
 }
예제 #4
0
  @Override
  public void paintComponent(final Graphics g) {
    super.paintComponent(g);

    final int w = getWidth();
    final int h = getHeight();
    final int hh = h / 2;
    final int s = (int) (3 * GUIConstants.SCALE);

    g.setColor(hasFocus() ? GUIConstants.BACK : GUIConstants.lgray);
    g.fillRect(0, hh - s, w, s * 2 - 1);
    g.setColor(GUIConstants.TEXT);
    g.drawLine(0, hh - s, w, hh - s);
    g.drawLine(0, hh - s, 0, hh + s - 1);
    g.setColor(GUIConstants.gray);
    g.drawLine(w - 1, hh - s, w - 1, hh + s - 1);
    g.drawLine(0, hh + s - 1, w, hh + s - 1);

    final double x = (value - min) * (w - SLIDERW) / (max - min);
    BaseXLayout.drawCell(g, (int) x, (int) (x + SLIDERW), hh - s * 2, hh + s * 2, oldValue != -1);
  }
예제 #5
0
  /**
   * Draws a colored cell.
   *
   * @param g graphics reference
   * @param xs horizontal start position
   * @param xe horizontal end position
   * @param ys vertical start position
   * @param ye vertical end position
   * @param focus highlighting flag
   */
  public static void drawCell(
      final Graphics g,
      final int xs,
      final int xe,
      final int ys,
      final int ye,
      final boolean focus) {

    g.setColor(gray);
    g.drawRect(xs, ys, xe - xs - 1, ye - ys - 1);
    g.setColor(BACK);
    g.drawRect(xs + 1, ys + 1, xe - xs - 3, ye - ys - 3);
    g.setColor(focus ? lgray : BACK);
    g.fillRect(xs + 1, ys + 1, xe - xs - 2, ye - ys - 2);
  }
예제 #6
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];
 }
예제 #7
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);
 }
예제 #8
0
 /**
  * Draws a centered string to the panel.
  *
  * @param g graphics reference
  * @param text text to be painted
  * @param w panel width
  * @param y vertical position
  */
 public static void drawCenter(final Graphics g, final String text, final int w, final int y) {
   g.drawString(text, (w - width(g, text)) / 2, y);
 }