예제 #1
0
  /**
   * This method starts the process of editing a new slide show. If a pose is already being edited,
   * it will prompt the user to save it first.
   */
  public void handleNewSlideShowRequest() {
    try {
      // WE MAY HAVE TO SAVE CURRENT WORK
      boolean continueToMakeNew = true;
      if (!saved) {
        // THE USER CAN OPT OUT HERE WITH A CANCEL
        continueToMakeNew = promptToSave();
      }

      // IF THE USER REALLY WANTS TO MAKE A NEW COURSE
      if (continueToMakeNew) {
        // RESET THE DATA, WHICH SHOULD TRIGGER A RESET OF THE UI
        SlideShowModel slideShow = ui.getSlideShow();
        slideShow.reset();
        saved = false;

        // REFRESH THE GUI, WHICH WILL ENABLE AND DISABLE
        // THE APPROPRIATE CONTROLS
        ui.updateToolbarControls(saved);

        // MAKE SURE THE TITLE CONTROLS ARE ENABLED
        ui.reloadTitleControls();
      }
    } catch (IOException ioe) {
      ErrorHandler eH = ui.getErrorHandler();
      eH.processError(LanguagePropertyType.ERROR_UNEXPECTED);
    }
  }
예제 #2
0
  /**
   * This helper method verifies that the user really wants to save their unsaved work, which they
   * might not want to do. Note that it could be used in multiple contexts before doing other
   * actions, like creating a new pose, or opening another pose, or exiting. Note that the user will
   * be presented with 3 options: YES, NO, and CANCEL. YES means the user wants to save their work
   * and continue the other action (we return true to denote this), NO means don't save the work but
   * continue with the other action (true is returned), CANCEL means don't save the work and don't
   * continue with the other action (false is retuned).
   *
   * @return true if the user presses the YES option to save, true if the user presses the NO option
   *     to not save, false if the user presses the CANCEL option to not continue.
   */
  private boolean promptToSave() throws IOException {
    // PROMPT THE USER TO SAVE UNSAVED WORK
    boolean saveWork = true;

    // IF THE USER SAID YES, THEN SAVE BEFORE MOVING ON
    if (saveWork) {
      SlideShowModel slideShow = ui.getSlideShow();
      slideShowIO.saveSlideShow(slideShow);
      saved = true;
    } // IF THE USER SAID CANCEL, THEN WE'LL TELL WHOEVER
    // CALLED THIS THAT THE USER IS NOT INTERESTED ANYMORE
    else if (!true) {
      return false;
    }

    // IF THE USER SAID NO, WE JUST GO ON WITHOUT SAVING
    // BUT FOR BOTH YES AND NO WE DO WHATEVER THE USER
    // HAD IN MIND IN THE FIRST PLACE
    return true;
  }
예제 #3
0
  /**
   * This helper method asks the user for a file to open. The user-selected file is then loaded and
   * the GUI updated. Note that if the user cancels the open process, nothing is done. If an error
   * occurs loading the file, a message is displayed, but nothing changes.
   */
  private void promptToOpen() {
    // AND NOW ASK THE USER FOR THE COURSE TO OPEN
    FileChooser slideShowFileChooser = new FileChooser();
    slideShowFileChooser.setInitialDirectory(new File(PATH_SLIDE_SHOWS));
    File selectedFile = slideShowFileChooser.showOpenDialog(ui.getWindow());

    // ONLY OPEN A NEW FILE IF THE USER SAYS OK
    if (selectedFile != null) {
      try {
        SlideShowModel slideShowToLoad = ui.getSlideShow();
        slideShowIO.loadSlideShow(slideShowToLoad, selectedFile.getAbsolutePath());
        ui.reloadSlideShowPane();
        saved = true;
        ui.updateToolbarControls(saved);
      } catch (Exception e) {
        ErrorHandler eH = ui.getErrorHandler();
        eH.processError(LanguagePropertyType.ERROR_UNEXPECTED);
      }
    }
  }
예제 #4
0
  /**
   * This method will save the current slideshow to a file. Note that we already know the name of
   * the file, so we won't need to prompt the user.
   */
  public boolean handleSaveSlideShowRequest() {
    try {
      // GET THE SLIDE SHOW TO SAVE
      SlideShowModel slideShowToSave = ui.getSlideShow();

      // SAVE IT TO A FILE
      slideShowIO.saveSlideShow(slideShowToSave);

      // MARK IT AS SAVED
      saved = true;

      // AND REFRESH THE GUI, WHICH WILL ENABLE AND DISABLE
      // THE APPROPRIATE CONTROLS
      ui.updateToolbarControls(saved);
      return true;
    } catch (IOException ioe) {
      ErrorHandler eH = ui.getErrorHandler();
      eH.processError(LanguagePropertyType.ERROR_UNEXPECTED);
      return false;
    }
  }