Ejemplo n.º 1
0
 /** positions a label in a particular spot */
 private void position(GLabel label_positioned) {
   GLabel box = label_positioned;
   box.setFont(new Font("Serif", Font.BOLD, FONTSIZE));
   box.setColor(FONTCOLOR);
   add(box);
 }
 /* Draw graph line with the name and rating */
 private void drawEntry(NameSurferEntry entry, int entryNumber) {
   /* Draws graph line */
   for (int i = 0; i < NDECADES - 1; i++) {
     int position1 = entry.getRank(i);
     int position2 = entry.getRank(i + 1);
     double x1 = i * (getWidth() / NDECADES);
     double x2 = (i + 1) * (getWidth() / NDECADES);
     double y1 = 0;
     double y2 = 0;
     if (position1 != 0 && position2 != 0) {
       y1 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position1 / MAX_RANK;
       y2 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position2 / MAX_RANK;
     } else if (position1 == 0 && position2 == 0) {
       y1 = getHeight() - GRAPH_MARGIN_SIZE;
       y2 = y1;
     } else if (position1 == 0) {
       y1 = getHeight() - GRAPH_MARGIN_SIZE;
       y2 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position2 / MAX_RANK;
     } else {
       y1 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position1 / MAX_RANK;
       y2 = getHeight() - GRAPH_MARGIN_SIZE;
     }
     GLine line = new GLine(x1, y1, x2, y2);
     /* Set line color */
     if (entryNumber % 4 == 0) {
       line.setColor(Color.BLUE);
     } else if (entryNumber % 4 == 1) {
       line.setColor(Color.RED);
     } else if (entryNumber % 4 == 2) {
       line.setColor(Color.MAGENTA);
     } else if (entryNumber % 4 == 3) {
       line.setColor(Color.BLACK);
     }
     add(line);
   }
   /* Add label with the name and ranking */
   for (int i = 0; i < NDECADES; i++) {
     String name = entry.getName();
     int position = entry.getRank(i);
     String positionString = Integer.toString(position);
     String label = name + " " + positionString;
     double x = i * (getWidth() / NDECADES) + 10;
     double x1 = x - NDECADES;
     double y;
     int R = 5;
     if (position != 0) {
       y = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position / MAX_RANK;
     } else {
       /* Add "*" if name was not used and remove marker point */
       label = name + " *";
       y = getHeight() - GRAPH_MARGIN_SIZE - 10;
       R = 0;
     }
     /* Add marker point */
     GOval marker = new GOval(x1, y - 2, R, R); /* Got "y-2" by scientific research =) */
     marker.setFilled(true);
     GLabel nameLabel = new GLabel(label, x, y);
     nameLabel.setFont(new Font("Times Roman", Font.BOLD, 12));
     /* Set label color */
     if (entryNumber % 4 == 0) {
       nameLabel.setColor(Color.BLUE);
       marker.setColor(Color.BLUE);
     } else if (entryNumber % 4 == 1) {
       nameLabel.setColor(Color.RED);
       marker.setColor(Color.RED);
     } else if (entryNumber % 4 == 2) {
       nameLabel.setColor(Color.MAGENTA);
       marker.setColor(Color.MAGENTA);
     } else if (entryNumber % 4 == 3) {
       nameLabel.setColor(Color.BLACK);
       marker.setColor(Color.BLACK);
     }
     add(nameLabel);
     add(marker);
   }
 }
Ejemplo n.º 3
0
  /*Place the labels on top */
  private void placeLabels() {
    /*Place label On Rent */
    GLabel onRentLabel = new GLabel("ON RENT");
    onRentLabel.setFont(new Font("Serif", Font.BOLD, BIGFONTSIZE));
    onRentLabel.setColor(FONTCOLOR);
    add(onRentLabel, RENTX + RENTWIDTH / 2 - onRentLabel.getWidth() / 2, RENTY - EQUIPHEIGHT);

    /*Place label Available */
    GLabel availForRentLabel = new GLabel("AVAILABLE FOR RENT");
    availForRentLabel.setFont(new Font("Serif", Font.BOLD, BIGFONTSIZE));
    availForRentLabel.setColor(FONTCOLOR);
    add(
        availForRentLabel,
        AVAILX + AVAILWIDTH / 2 - availForRentLabel.getWidth() / 2,
        AVAILY - EQUIPHEIGHT);

    /*Place label Shop */
    GLabel shopLabel = new GLabel("SHOP");
    shopLabel.setFont(new Font("Serif", Font.BOLD, BIGFONTSIZE));
    shopLabel.setColor(FONTCOLOR);
    add(shopLabel, SHOPX + SHOPWIDTH / 2 - shopLabel.getWidth() / 2, SHOPY - EQUIPHEIGHT * 14);

    /*Place the lost sales label */
    lostSalesLabel1 = new GLabel("Lost Sales HR = " + lostSales.get(0));
    lostSalesLabel2 = new GLabel("Lost Sales MR = " + lostSales.get(1));
    lostSalesLabel3 = new GLabel("Lost Sales LR = " + lostSales.get(2));
    lostSalesLabel1.setFont(new Font("Serif", Font.BOLD, BIGFONTSIZE));
    lostSalesLabel2.setFont(new Font("Serif", Font.BOLD, BIGFONTSIZE));
    lostSalesLabel3.setFont(new Font("Serif", Font.BOLD, BIGFONTSIZE));
    lostSalesLabel1.setColor(FONTCOLOR);
    lostSalesLabel2.setColor(FONTCOLOR);
    lostSalesLabel3.setColor(FONTCOLOR);
    add(lostSalesLabel1, START_X + 4 * EQUIPWIDTH, 4 * EQUIPHEIGHT);
    add(
        lostSalesLabel2,
        START_X + 4 * EQUIPWIDTH,
        4 * EQUIPHEIGHT + lostSalesLabel1.getHeight() * 1.5);
    add(
        lostSalesLabel3,
        START_X + 4 * EQUIPWIDTH,
        4 * EQUIPHEIGHT + lostSalesLabel2.getHeight() * 3);

    /*Place the days elapsed label */
    daysElapsed = 0;
    daysElapsedLabel = new GLabel("DAY" + daysElapsed);
    daysElapsedLabel.setFont(new Font("Serif", Font.BOLD, 24));
    daysElapsedLabel.setColor(Color.red.darker());
    add(daysElapsedLabel, APPLICATION_WIDTH / 2, START_Y / 2);

    /*Place the sales Label */
    sales = 0;
    salesLabel = new GLabel("SALES: $" + sales);
    salesLabel.setFont(new Font("Serif", Font.BOLD, 24));
    salesLabel.setColor(Color.GREEN.darker());
    add(salesLabel, APPLICATION_WIDTH / 2, daysElapsedLabel.getY() + daysElapsedLabel.getY());

    /*Place the capitalInvested Label */
    capitalInvested = 0;
    capitalLabel = new GLabel("Capital Invested: $" + capitalInvested);
    capitalLabel.setFont(new Font("Serif", Font.BOLD, 18));
    capitalLabel.setColor(Color.RED.darker());
    add(
        capitalLabel,
        lostSalesLabel1.getX(),
        lostSalesLabel3.getY() + lostSalesLabel3.getHeight() * 2);
  }