Beispiel #1
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);
  }
Beispiel #2
0
  private void drawContainers(Graphics g, int index1, int index2) {
    // calculate dimensions and starting points for drawing
    steps.array.bucket.Container[] containers =
        ((Containers) _steps[index1][index2]).getContainers();
    int totalWidth = CONTAINER_SPACING;
    int totalHeight = 0;
    for (int i = 0; i < containers.length; i++) {
      totalWidth += getContainerDimensions(g, containers[i]).width + CONTAINER_SPACING;
      totalHeight = getContainerDimensions(g, containers[i]).height;
    }
    int x = (_panel.getWidth() - totalWidth) / 2, y = (_panel.getHeight() / 2 - totalHeight) / 2;

    // draw the containers
    g.setColor(Color.black);
    ContainerLocation[] locs = createLocations(g, containers);
    for (int i = 0; i < locs.length; i++) {
      if (containers[i].theValues.length > 0 && locs[i] != null)
        drawContainer(containers[i], g, locs[i].X, locs[i].Y);
    }
  }
Beispiel #3
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);
 }