예제 #1
0
  private void drawPageIndicator(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws a page indicator above the OK button. The filled in circle represents which
        //        page we're currently on.
      {
    int x1; // First x coordinate for drawing area.
    int y1; // First y coordinate for drawing area.
    int x2; // Second x coordinate for drawing area.
    int y2; // Second y coordinate for drawing area.
    int width; // Width of drawing area.
    int height; // Height of drawing area.
    int offset; // Offset between circles.
    Graphics2D g2; // Graphics2D to change brush stroke.

    x1 = ScaledPoint.scalerToX(0.275);
    x2 = ScaledPoint.scalerToX(0.325);
    y1 = ScaledPoint.scalerToY(0.85);
    y2 = ScaledPoint.scalerToY(0.89);

    width = (x2 - x1) / 2;
    height = y2 - y1;

    offset = ScaledPoint.scalerToX(0.005) / 2;

    g2 = (Graphics2D) g;

    g2.setColor(Color.WHITE);
    g2.setStroke(new BasicStroke(1));

    if (currentPage == 0) // if we are on the first page
    {
      g.fillOval(x1 - offset, y1, width, height);
      g.drawOval(x1 + width + offset, y1, width, height);
    } else // if we are on the second page.
    {
      g.drawOval(x1 - offset, y1, width, height);
      g.fillOval(x1 + width + offset, y1, width, height);
    }
  }
예제 #2
0
  private void drawInventory(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws the inventory of the store if mode == 0, else draws the players inventory.
        //        If an item is selected, its border is highlighted white.
      {
    Graphics2D g2; // Graphics 2D object to allow for different brush stroke widths.
    Color start; // The start color for the inventory window gradient.
    Color end; // The end color for the inventory window gradient.
    int x1; // Upper-left x coordinate.
    int y1; // Upper-left y coordinate.
    int x2; // Bottom-right x coordinate.
    int y2; // Bottom-right y coordinate.
    int width; // Width of the inventory box.
    int height; // Height of the inventory box.
    int itemHeight; // The height of an item box.
    int itemY; // The y coordinate of the item.
    Item currentItem; // Item to store the current item

    g2 = (Graphics2D) g;
    start = new Color(120, 120, 220);
    end = new Color(50, 50, 150);

    x1 = inventoryPos[0].getScaledX();
    y1 = inventoryPos[0].getScaledY();
    x2 = inventoryPos[1].getScaledX();
    y2 = inventoryPos[1].getScaledY();
    width = x2 - x1;
    height = y2 - y1;

    while (height % ITEMSPERPAGE != 0) // ensure that the item boxes do not fall short of the window
    {
      height = ++y2 - y1;
    }

    itemHeight = height / ITEMSPERPAGE;

    Drawing.drawGradient(g2, start, end, x1, y1, width, height / 2);
    Drawing.drawGradient(g2, end, start, x1, y1 + height / 2, width, height / 2);

    g2.setColor(Color.BLACK);
    g2.setStroke(new BasicStroke(3));
    g2.drawRect(--x1, --y1, ++width, height);
    g2.setColor(Color.WHITE);

    switch (store) // Chooses the current store
    {
      case 0:
        connectItems(getUserItems("Weapon", orderToSort));
        break;
      case 1:
        connectItems(getUserItems("ArmorSmith", orderToSort));
        break;
      case 2:
        connectItems(getUserItems("Accessory", orderToSort));
        break;
      case 3:
        connectItems(getUserItems("General", orderToSort));
        break;
    }

    if (mode) // Sets mode to true for user inventory and displays
    {
      connectItems(getUserItems("Player", orderToSort));
    }

    int count = 0;
    // count = currentPage * ITEMSPERPAGE ;

    try // Try loading 10 items per page
    {

      currentItem = null;
      count = currentPage * ITEMSPERPAGE;
      for (int i = 0; i < ITEMSPERPAGE; i++) // draw each item into the window
      {
        if (i > itemsArray.length - 1) // Check if i excceds the array size
        {
          return;
        }
        itemY = y1 + (itemHeight) * i;

        currentItem = itemsArray[count];

        if (itemSelected == i) // if the item was selected, highlight it
        {
          g2.drawRect(x1, itemY, width, itemHeight);
        }

        drawItem(g2, i, currentItem);

        count++;
      }

    } catch (Exception e) // Catch generic exception and print it out
    {
      System.err.println(e.toString());
      System.err.println("Oh no, not like this...");
    }
  }
예제 #3
0
  public int print(Graphics g, PageFormat pf, int pageIndex) {
    Font f1 = new Font("SERIF", Font.PLAIN, 8);
    FontMetrics metric = g.getFontMetrics(f1);
    int lineHeight = metric.getHeight();

    if (pageBreak == null) {
      initLines();
      int s = (numLines % 3);
      if (s > 0) numLines = numLines + (3 - s);
      numLines /= 3;

      int linesPerPage = (int) (pf.getImageableHeight() / lineHeight);
      int numBreaks = (numLines / linesPerPage);
      pageBreak = new int[numBreaks];
      for (int b = 0; b < numBreaks; b++) {
        pageBreak[b] = (b + 1) * linesPerPage;
      }
    }

    if (pageIndex > pageBreak.length) {
      return NO_SUCH_PAGE;
    }

    Graphics2D g2d = (Graphics2D) g;
    g2d.translate(pf.getImageableX(), pf.getImageableY());

    int y = 0;

    g.setFont(new Font("SERIF", Font.PLAIN, 9));

    int start = 0;
    if (pageIndex == 0) start = 0;
    else start = pageBreak[pageIndex - 1];

    int end = 0;

    if (pageIndex == pageBreak.length) end = numLines;
    else end = pageBreak[pageIndex];

    if (chk % 2 == 1 && (end - start) != lineHeight) {

      for (int line = start; line < end && i < x; line += 9) {
        y += (2 * lineHeight);
        g.drawString("" + textLines[i][0], 30, y);
        g.drawString(textLines[i][1], 30, y + lineHeight);
        g.drawString(textLines[i][2], 30, y + 2 * lineHeight);
        g.drawString(textLines[i][3], 30, y + 3 * lineHeight);
        g.drawString(textLines[i][4], 30, y + 4 * lineHeight);
        g.drawString(textLines[i][5], 30, y + 5 * lineHeight);
        g.drawString(textLines[i][6], 30, y + 6 * lineHeight);

        if ((i + 1) < x) {
          g.drawString(textLines[i + 1][0], 225, y);
          g.drawString(textLines[i + 1][1], 225, y + lineHeight);
          g.drawString(textLines[i + 1][2], 225, y + 2 * lineHeight);
          g.drawString(textLines[i + 1][3], 225, y + 3 * lineHeight);
          g.drawString(textLines[i + 1][4], 225, y + 4 * lineHeight);
          g.drawString(textLines[i + 1][5], 225, y + 5 * lineHeight);
          g.drawString(textLines[i + 1][6], 225, y + 6 * lineHeight);
        }
        if ((i + 2) < x) {
          g.drawString(textLines[i + 2][0], 415, y);
          g.drawString(textLines[i + 2][1], 415, y + lineHeight);
          g.drawString(textLines[i + 2][2], 415, y + 2 * lineHeight);
          g.drawString(textLines[i + 2][3], 415, y + 3 * lineHeight);
          g.drawString(textLines[i + 2][4], 415, y + 4 * lineHeight);
          g.drawString(textLines[i + 2][5], 415, y + 5 * lineHeight);
          g.drawString(textLines[i + 2][6], 415, y + 6 * lineHeight);
        }
        y += 7 * lineHeight;
        i += 3;
      }

    } else {

      for (int line = start; line < end && i < x; line += 8) {}
    }
    chk++;

    return PAGE_EXISTS;
  }