예제 #1
0
  /**
   * Updates the stored user with any not null information in the passed user
   *
   * @param u The user to update from.
   * @throws InvalidFieldException Thrown if anything is of the wrong format.
   */
  public void update(User u) throws InvalidFieldException {
    if (u.getFirstName() != null) {
      setFirstName(u.getFirstName());
    }

    if (u.getLastName() != null) {
      setLastName(u.getLastName());
    }

    if (u.getID() != null) {
      setID(u.getID());
    }

    if (u.getPoints() != getPoints()) {
      setPoints(u.getPoints());
    }

    if (u.getWeeklyPick() != null && !u.getWeeklyPick().isNull()) {
      setWeeklyPick(u.getWeeklyPick());
    }

    if (u.getUltimatePick() != null && !u.getUltimatePick().isNull()) {
      setUltimatePickNoSetPts(u.getUltimatePick());
    }

    if (u.getUltimatePoints() != getUltimatePoints()) {
      setUltimatePoints(u.getUltimatePoints());
    }
  }
  public PickScreen(int voteType) {
    super();
    this.voteType = voteType;

    VerticalFieldManager vertFieldManager =
        new VerticalFieldManager(
            VerticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.VERTICAL_SCROLLBAR) {
          // Override the paint method to draw the background image.
          public void paint(Graphics graphics) {
            graphics.setColor(Color.BLACK);
            graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
            super.paint(graphics);
          }
        };
    ;

    try { // set up the smaller list font
      ff1 = FontFamily.forName("Verdana");
      font2 = ff1.getFont(Font.BOLD, 20);
    } catch (final ClassNotFoundException cnfe) {
    }

    Vector contList = GameData.getCurrentGame().getActiveContestants();

    Contestant[] contArray = new Contestant[contList.size()];
    contList.copyInto(contArray);
    ocfActiveContestant = new ObjectChoiceField(" Cast your " + voteType + " vote: ", contArray);
    User user = GameData.getCurrentGame().getCurrentUser();
    if (voteType == T_WEEKLY && user.getWeeklyPick() != null) {
      ocfActiveContestant.setSelectedIndex(user.getWeeklyPick());
    } else if (voteType == T_ULTIMATE && user.getUltimatePick() != null) {
      ocfActiveContestant.setSelectedIndex(user.getUltimatePick());
    }

    list = new RichList(vertFieldManager, true, 3, 0);

    // get all contestants for list
    contList = GameData.getCurrentGame().getAllContestants();
    for (int i = 0; i < contList.size(); i++) {
      Contestant cont = (Contestant) contList.elementAt(i);
      /* list contains labels so that the text colour can change */
      lblContName =
          new LabelField(cont.getFirstName() + " " + cont.getLastName(), LabelField.ELLIPSIS) {
            public void paint(Graphics g) {
              g.setColor(Color.WHITE);
              super.paint(g);
            }
          };
      lblContName.setFont(font2);

      labelContTribe =
          new LabelField(cont.getTribe(), LabelField.ELLIPSIS) {
            public void paint(Graphics g) {
              g.setColor(Color.WHITE);
              super.paint(g);
            }
          };
      lblContName.setFont(font2);

      String tempString = "";

      if (cont.isCastOff()) tempString = "Castoff";
      else tempString = "Active";

      labelTempStatus =
          new LabelField(tempString, LabelField.ELLIPSIS) {
            public void paint(Graphics g) {
              g.setColor(Color.WHITE);
              super.paint(g);
            }
          };
      lblContName.setFont(font2);
      Bitmap imgContestant = getImage(cont.getPicture());
      list.add(new Object[] {imgContestant, lblContName, labelContTribe, labelTempStatus});
    }

    HorizontalFieldManager horFieldManager =
        new HorizontalFieldManager(
            HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.FIELD_HCENTER) {
          // Override the paint method to draw the background image.
          public void paint(Graphics graphics) {
            graphics.setColor(Color.GREEN);
            graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
            super.paint(graphics);
          }
        };
    ;

    String voted = "Vote";
    user = GameData.getCurrentGame().getCurrentUser();
    System.out.println(user.getWeeklyPick() + " " + this.voteType);
    if ((this.voteType == T_WEEKLY && user.getWeeklyPick() != null)
        || (this.voteType == T_ULTIMATE && user.getUltimatePick() != null)) voted = "Revote";
    btnVoted = new ButtonField(voted);
    btnVoted.setChangeListener(this);

    horFieldManager.add(btnVoted);
    horFieldManager.add(ocfActiveContestant);
    horFieldManager.setFont(font2);

    this.setTitle(horFieldManager);
    this.add(vertFieldManager);
    this.setStatus(Common.getToolbar("Log Out"));
    vertFieldManager.setFocus(); // THIS NEEDS TO BE HERE. APP CRASHES WITHOUT IT
  }