예제 #1
0
 private Dimension getContainerDimensions(Graphics g, steps.array.bucket.Container c) {
   int spacingWidth =
       (int) g.getFontMetrics(g.getFont()).getStringBounds(CONTAINER_VALUE_SPACING, g).getHeight();
   int totalWidth = spacingWidth;
   int totalHeight = 0;
   for (int i = 0; i < c.theValues.length; i++) {
     totalHeight =
         (int) g.getFontMetrics(g.getFont()).getStringBounds("" + c.theValues[0], g).getHeight()
             * 2;
     totalWidth +=
         (int) g.getFontMetrics(g.getFont()).getStringBounds("" + c.theValues[i], g).getWidth();
     totalWidth += spacingWidth;
   }
   return new Dimension(totalWidth, totalHeight);
 }
예제 #2
0
  private void drawContainer(steps.array.bucket.Container c, Graphics g, int x, int y) {
    // calculate the size of all the printed values
    Dimension dims = getContainerDimensions(g, c);
    int totalWidth = dims.width, totalHeight = dims.height;
    String allValues = CONTAINER_VALUE_SPACING;
    for (int i = 0; i < c.theValues.length; i++) {
      allValues += c.theValues[i] + CONTAINER_VALUE_SPACING;
    }
    int textWidth =
        (int) g.getFontMetrics(g.getFont()).getStringBounds("" + allValues, g).getWidth();

    // draw a rectangle to fit them all
    g.drawRoundRect(x, y, totalWidth, totalHeight, ARC_RADIUS, ARC_RADIUS);

    // print the values in it
    g.drawString(allValues, x + (totalWidth - textWidth) / 2, y + 3 * totalHeight / 4);
  }