Esempio n. 1
0
  // ds enable display
  public void launch()
      throws CZEPGUIException, HeadlessException, SQLException, CZEPMySQLManagerException {
    System.out.println(
        "[" + CLogger.getStamp() + "]<CGUI>(launch) Loading initial application setup");

    // ds allocate a dialog object to display independently
    final JDialog cDialogLoading = new JDialog(m_cFrame, "ZEP: Zero-Effort Procrastination", false);

    // ds set the option panel without any options
    cDialogLoading.setContentPane(
        new JOptionPane(
            "Loading image data please wait",
            JOptionPane.INFORMATION_MESSAGE,
            JOptionPane.DEFAULT_OPTION,
            null,
            new Object[] {},
            null));

    // ds display the dialog
    cDialogLoading.pack();
    cDialogLoading.setVisible(true);
    cDialogLoading.setLocationRelativeTo(null);

    try {
      // ds fetch initial datapool
      m_cLearner.fetchInitialDataPool();

      // ds try to get the image for first display
      _displayInitialImage(m_cLearner.getFirstDataPoint());
    } catch (Exception e) {
      // ds info
      System.out.println(
          "["
              + CLogger.getStamp()
              + "]<CGUI>(launch) Exception: "
              + e.getMessage()
              + " - could not fetch database");

      // ds dispose loading screen
      cDialogLoading.removeAll();
      cDialogLoading.dispose();

      // ds rethrow
      throw new CZEPGUIException("GUI aborted");
    }

    // ds dispose loading screen
    cDialogLoading.removeAll();
    cDialogLoading.dispose();

    // ds register key listener
    m_cFrame.addKeyListener(this);

    // ds display frame for interaction
    m_cFrame.setVisible(true);
    m_cFrame.setLocationRelativeTo(null);

    // ds request focus for key strokes
    m_cFrame.requestFocus();

    // ds initialize with empty string
    String strUsername = "";

    // ds as long as it is not set
    while (strUsername.isEmpty()) {
      // ds show dialog to enter name
      strUsername =
          JOptionPane.showInputDialog(
              m_cFrame,
              "Please enter your desired username: "******"ZEP: Zero-Effort Procrastination",
              JOptionPane.PLAIN_MESSAGE);

      // ds check if null (cancelled by user)
      if (null == strUsername) {
        // ds escape
        throw new CZEPGUIException("cancelled username setting dialog");
      }

      // ds check if already taken
      if (!strUsername.isEmpty() && !m_cMySQLManager.isUserAvailable(strUsername)) {
        // ds inform
        JOptionPane.showMessageDialog(m_cFrame, "Username already taken - please try again");

        // ds keep looping
        strUsername = "";
      }
    }

    // ds username is fine to set
    m_cLearner.setUsername(strUsername);

    // ds set user active
    m_cMySQLManager.setActiveUser(strUsername);

    // ds and log
    System.out.println(
        "[" + CLogger.getStamp() + "]<CGUI>(launch) Login of: [" + strUsername + "] successful");

    // ds log successful launch
    _logMaster("<CGUI>(launch) launched GUI application");

    // ds request focus for key strokes
    m_cFrame.requestFocus();
  }