Exemple #1
0
  // ds event invoked function
  public void actionPerformed(ActionEvent p_cEvent) {
    // ds get the event source
    final Object cSource = p_cEvent.getSource();

    try {
      // ds determine event (big if/else tree)
      if (cSource == m_cButtonLike) {
        _displayImage(
            m_cLearner.getNextPattern(CLearnerBayes.ELearnerLabel.LIKE, m_cCurrentPattern));
      } else if (cSource == m_cButtonDislike) {
        _displayImage(
            m_cLearner.getNextPattern(CLearnerBayes.ELearnerLabel.DISLIKE, m_cCurrentPattern));
      } else if (cSource == m_cButtonPrevious) {
        _displayImage(m_cLearner.getPreviousPattern());
      } else if (cSource == m_cButtonReset) {
        // ds reset the learning process
        m_cLearner.reset();

        // ds get a new image
        _displayImage(m_cLearner.getFirstDataPoint());
      }
    } catch (SQLException e) {
      _logMaster("<CGUI>(actionPerformed) SQLException: " + e.getMessage());
      System.out.println(
          "[" + CLogger.getStamp() + "]<CGUI>(actionPerformed) SQLException: " + e.getMessage());

      // ds no previous image available
      JOptionPane.showMessageDialog(m_cFrame, "Could not load image from MySQL database");
    } catch (CZEPnpIException e) {
      _logMaster("<CGUI>(actionPerformed) CZEPnpIException: " + e.getMessage());
      System.out.println(
          "["
              + CLogger.getStamp()
              + "]<CGUI>(actionPerformed) CZEPnpIException: "
              + e.getMessage());

      // ds no previous image available
      JOptionPane.showMessageDialog(
          m_cFrame,
          "No previous image available - please use Like/Dislike to classify the first image");
    } catch (CZEPMySQLManagerException e) {
      _logMaster("<CGUI>(actionPerformed) CZEPMySQLManagerException: " + e.getMessage());
      System.out.println(
          "["
              + CLogger.getStamp()
              + "]<CGUI>(actionPerformed) CZEPMySQLManagerException: "
              + e.getMessage());

      // ds no previous image available
      JOptionPane.showMessageDialog(m_cFrame, "Could not load image from MySQL database");
    } catch (MalformedURLException e) {
      _logMaster("<CGUI>(actionPerformed) MalformedURLException: " + e.getMessage());
      System.out.println(
          "["
              + CLogger.getStamp()
              + "]<CGUI>(actionPerformed) MalformedURLException: "
              + e.getMessage());

      // ds no previous image available
      JOptionPane.showMessageDialog(m_cFrame, "Could not load image from MySQL database");
    } catch (CZEPEoIException e) {
      _logMaster("<CGUI>(actionPerformed) CZEPEoIException: " + e.getMessage());
      System.out.println(
          "["
              + CLogger.getStamp()
              + "]<CGUI>(actionPerformed) CZEPEoIException: "
              + e.getMessage());

      // ds no previous image available
      JOptionPane.showMessageDialog(m_cFrame, "Could not load image from MySQL database");
    }
  }
Exemple #2
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();
  }