Пример #1
0
  void onOpenFileClicked() {
    if (!maybeSave()) {
      return;
    }

    try {
      JFileChooser fc = new JFileChooser();
      FileNameExtensionFilter filter1 =
          new FileNameExtensionFilter(strings.getString("filetype." + EXTENSION), EXTENSION);
      fc.setFileFilter(filter1);

      int rv = fc.showOpenDialog(this);
      if (rv == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        Tournament t = new Tournament();
        t.loadFile(file);

        setTournament(file, t);
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE);
    }
  }
Пример #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    Intent i = getIntent();

    // initialize variables from intent
    tournament = (Tournament) i.getSerializableExtra("Tournament");
    round = (Round) i.getSerializableExtra("Round");
    teamList = round.getTeamList();
    winningTeamList = round.getRoundWinners();
    currentRoundIndex = round.getRoundNumber();
    nextRoundIndex = currentRoundIndex + 1;
    numOfRounds = tournament.getNumberOfRounds();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_results);

    if (currentRoundIndex == numOfRounds - 1) {

      Button btn = (Button) findViewById(R.id.buttonContinue);
      btn.setText("View stats");
    }

    populateListView();
  }
Пример #3
0
  /** @return true if file was saved, false if user canceled */
  boolean onSaveFileClicked() {
    if (currentFile == null) {
      return onSaveAsFileClicked();
    }

    try {
      tournament.saveFile(currentFile);
      return true;
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE);
    }
    return false;
  }
Пример #4
0
  boolean maybeSave() {
    if (tournament.isDirty()) {

      int rv =
          JOptionPane.showConfirmDialog(
              this,
              strings.getString("main.save_query"),
              PRODUCT_NAME,
              JOptionPane.YES_NO_CANCEL_OPTION,
              JOptionPane.WARNING_MESSAGE);
      if (rv == JOptionPane.CANCEL_OPTION) return false;

      if (rv == JOptionPane.YES_OPTION) {
        return onSaveFileClicked();
      }
    }
    return true;
  }
Пример #5
0
  // go to next round when clicked
  public void gotToNextRoundClick(View view) {

    if (tournament.getType().equals("Round Robin")) {

      if (currentRoundIndex < numOfRounds - 1) tournament.initializeRound(nextRoundIndex, teamList);

    } else if (tournament.getType().equals("Knockout")) {

      if (currentRoundIndex < numOfRounds - 1)
        tournament.initializeRound(nextRoundIndex, winningTeamList);

    } else {

      if (currentRoundIndex < numOfRounds - 1) {

        if (currentRoundIndex < teamList.size() - 1)
          tournament.initializeRound(nextRoundIndex, teamList);
        else tournament.initializeRound(nextRoundIndex, winningTeamList);
      }
    }

    Intent intent;

    if (currentRoundIndex == numOfRounds - 1) {

      // sets tournament to inactive
      tournament.setIsActive(false);

      intent = new Intent(this, StatisticsActivity.class);
      intent.putExtra("Tournament", tournament);

    } else {

      intent = new Intent(this, RoundActivity.class);
      intent.putExtra("Tournament", tournament);
      intent.putExtra("roundIndex", nextRoundIndex);
    }

    startActivity(intent);
  }
Пример #6
0
 void doSave(File file) throws IOException {
   currentFile = file;
   tournament.saveFile(file);
 }