예제 #1
0
 private static int getProgressBarBaseline(JProgressBar pb, int height) {
   if (pb.isStringPainted() && pb.getOrientation() == JProgressBar.HORIZONTAL) {
     FontMetrics metrics = pb.getFontMetrics(pb.getFont());
     Insets insets = pb.getInsets();
     int y = insets.top;
     if (isWindows() && isXP()) {
       if (pb.isIndeterminate()) {
         y = -1;
         height--;
       } else {
         y = 0;
         height -= 3;
       }
     } else if (isGTK()) {
       return (height - metrics.getAscent() - metrics.getDescent()) / 2 + metrics.getAscent();
     } else if (isAqua()) {
       if (pb.isIndeterminate()) {
         // Aqua doesn't appear to support text on indeterminate
         // progress bars.
         return -1;
       }
       y -= 1;
       height -= (insets.top + insets.bottom);
     } else {
       height -= insets.top + insets.bottom;
     }
     return y + (height + metrics.getAscent() - metrics.getLeading() - metrics.getDescent()) / 2;
   }
   return -1;
 }
  /**
   * Designate the place where the progress string will be painted. This implementation places it at
   * the center of the progress bar (in both x and y). Override this if you want to right, left,
   * top, or bottom align the progress string or if you need to nudge it around for any reason.
   */
  protected Point getStringPlacement(
      Graphics g, String progressString, int x, int y, int width, int height) {
    FontMetrics fontSizer = SwingUtilities2.getFontMetrics(progressBar, g, progressBar.getFont());
    int stringWidth = SwingUtilities2.stringWidth(progressBar, fontSizer, progressString);

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      return new Point(
          x + Math.round(width / 2 - stringWidth / 2),
          y
              + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent())
                  / 2));
    } else { // VERTICAL
      return new Point(
          x
              + ((width - fontSizer.getAscent() + fontSizer.getLeading() + fontSizer.getDescent())
                  / 2),
          y + Math.round(height / 2 - stringWidth / 2));
    }
  }
 /**
  * Returns the baseline.
  *
  * @throws NullPointerException {@inheritDoc}
  * @throws IllegalArgumentException {@inheritDoc}
  * @see javax.swing.JComponent#getBaseline(int, int)
  * @since 1.6
  */
 public int getBaseline(JComponent c, int width, int height) {
   super.getBaseline(c, width, height);
   if (progressBar.isStringPainted() && progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
     FontMetrics metrics = progressBar.getFontMetrics(progressBar.getFont());
     Insets insets = progressBar.getInsets();
     int y = insets.top;
     height = height - insets.top - insets.bottom;
     return y + (height + metrics.getAscent() - metrics.getLeading() - metrics.getDescent()) / 2;
   }
   return -1;
 }
예제 #4
0
 /**
  * Converts a line index to a y co-ordinate.
  *
  * @param line The line
  */
 public int lineToY(int line) {
   FontMetrics fm = painter.getFontMetrics();
   return (line - firstLine) * fm.getHeight() - (fm.getLeading() + fm.getMaxDescent());
 }