Пример #1
0
  /**
   * This method handles the loading of an existing project into a new DrawingArea. Gives feedback
   * to the user if project is not found or incompatible with the current version
   *
   * @param projectName Name of project to load
   */
  private void loadDrawing(String projectName) {
    if (firstStartup) {
      dailyTips();
      firstStartup = false;
    }

    drawingArea = new DrawingArea(toolbox, toolSettings, activeColorSettings);
    drawingArea.setProjectName(projectName.toLowerCase());

    try {
      serialization.load(drawingArea, projectName.toLowerCase());

      Dimension desktopSize = jDesktopPane.getSize();
      Dimension jInternalFrameSize = drawingArea.getSize();
      drawingArea.setLocation(
          (desktopSize.width - jInternalFrameSize.width) / 2,
          (desktopSize.height - jInternalFrameSize.height) / 2);

      drawingArea.setTitle("Prosjekt: " + projectName);

      drawingArea.setVisible(true);

      jDesktopPane.add(drawingArea);

    } catch (StorageException ex) {
      // ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
      JOptionPane.showMessageDialog(
          null, "Fant ikke prosjektet på serveren.", "Feil", JOptionPane.ERROR_MESSAGE);

    } catch (IOException ex) {
      // ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
      JOptionPane.showMessageDialog(
          null,
          "Dette prosjektet ble laget på en eldre versjon av programmet.\n"
              + "Dessverre er det ikke kompatibelt med nåværende versjon.",
          "Gammel versjon",
          JOptionPane.ERROR_MESSAGE);

    } catch (URISyntaxException | ClassNotFoundException ex) {
      ex.printStackTrace();
    }

    try {
      drawingArea.setSelected(true);
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }
  }
Пример #2
0
  /** Creates the dialoge for opening an existing project. */
  void openProjectDialog() {

    String[] array = serialization.getStringArrayOfProjects();

    projectName =
        (String)
            JOptionPane.showInputDialog(
                null,
                "Velg prosjekt:",
                "Åpne prosjekt",
                JOptionPane.QUESTION_MESSAGE,
                null,
                array,
                array[0]);

    if ((projectName != null) && (projectName.length() > 0)) {
      loadDrawing(projectName);
    }
  }
Пример #3
0
  /**
   * Creates the dialoge for new projects. It checks if the project already exists on the server and
   * gives the user options to load or overwrite the existing if it does.
   */
  void newProject() {

    projectName =
        JOptionPane.showInputDialog(
            null,
            "Angi navnet på det nye prosjektet:",
            "Nytt prosjekt",
            JOptionPane.INFORMATION_MESSAGE);

    if ((projectName != null) && (projectName.length() > 0)) {
      String[] array = serialization.getStringArrayOfProjects();
      boolean projectExists = false;
      for (String storedProject : array) {
        if (projectName.toLowerCase().equals(storedProject)) {
          projectExists = true;

          Object[] options = {"Åpne", "Overskriv", "Avbryt"};
          int n =
              JOptionPane.showOptionDialog(
                  null,
                  "Navnet du anga eksisterer fra før.",
                  "Prosjektet eksisterer",
                  JOptionPane.YES_NO_CANCEL_OPTION,
                  JOptionPane.INFORMATION_MESSAGE,
                  null,
                  options,
                  options[0]);

          if (n == 0) {
            loadDrawing(projectName);
          } else if (n == 1) {
            createDrawing(projectName);
          } else if (n == 2) {
            break;
          }
        }
      }

      if (!projectExists) {
        createDrawing(projectName);
      }
    }
  }