Esempio n. 1
0
  // ds update GUI with new image
  private void _displayInitialImage(final CPattern p_cPattern) throws CZEPMySQLManagerException {
    // ds update active datapoint
    m_cCurrentPattern = p_cPattern;

    // ds if we got a gif we take the image as is
    if (p_cPattern.isAnimated()) {
      // ds set the icon
      m_cLabelImage.setIcon(m_cMySQLManager.getImageIcon(p_cPattern));
    } else {
      // ds set the image to the GUI field (resized)
      m_cLabelImage.setIcon(
          new ImageIcon(
              CImageHandler.getResizedImage(
                  m_cMySQLManager.getBufferedImage(p_cPattern),
                  m_iWindowWidth - 25,
                  m_iWindowHeight - 125)));
    }

    // ds update image info
    m_cTextFieldTitle.setText(p_cPattern.getTitle());
    // m_cTextFieldURL.setText( p_cPattern.getURL( ).toString( ) );
    // m_cTextFieldTags.setText( p_cPattern.getTags( ).toString( ) );

    // ds datapoint properties
    // m_cTextFieldImageID.setText( Integer.toString( p_cPattern.getID( ) ) );
    // m_cTextFieldType.setText( p_cPattern.getType( ) );
    // m_cTextFieldLikes.setText( Integer.toString( p_cPattern.getLikes( ) ) );
    // m_cTextFieldDislikes.setText( Integer.toString( p_cPattern.getDislikes( ) ) );

    /*ds check if gif
    if( p_cPattern.isAnimated( ) )
    {
        //ds no detection done
        m_cTextFieldTextPercent.setText( "" );
        m_cTextFieldIsPhoto.setText( "" );
    }
    else
    {
        //ds get the values
        m_cTextFieldTextPercent.setText( Boolean.toString( p_cPattern.isAnimated( ) ) );
        m_cTextFieldIsPhoto.setText( Boolean.toString( p_cPattern.isPhoto( ) ) );
    }*/

    // m_cTextFieldComments.setText( Integer.toString( p_cPattern.getCountComments( ) ) );
    // m_cTextFieldTagsCount.setText( Integer.toString( p_cPattern.getCountTags( ) ) );

    // ds learner
    // m_cTextFieldVisits.setText( Integer.toString( m_cLearner.getNumberOfVisits( ) ) );
    // m_cTextFieldDatasetSize.setText( Integer.toString( m_cLearner.getOperations( ) ) );
    // m_cTextFieldTotalLikes.setText( Integer.toString( m_cLearner.getNumberOfLikes( ) ) );
  }
Esempio n. 2
0
  // ds MySQL logger
  private final void _logMaster(final String p_strInfo) {
    // ds get username and session id
    final String strUsername = m_cLearner.getUsername();
    final int iSessionID = m_cLearner.getSessionID();

    // ds if set
    if (null != strUsername) {
      try {
        // ds log
        m_cMySQLManager.logMaster(strUsername, iSessionID, p_strInfo);
      } catch (SQLException e) {
        System.out.println(
            "["
                + CLogger.getStamp()
                + "]<CGUI>(_logMaster) SQLException: "
                + e.getMessage()
                + " could not log to MySQL master");
      }
    } else {
      System.out.println(
          "["
              + CLogger.getStamp()
              + "]<CGUI>(_logMaster) could not log to master because of empty username");
    }
  }
Esempio n. 3
0
  // ds update GUI with new image
  private void _displayImage(final CPattern p_cPattern) throws CZEPMySQLManagerException {
    // ds update active datapoint
    m_cCurrentPattern = p_cPattern;

    // ds if we got a gif we take the image as is
    if (p_cPattern.isAnimated()) {
      // ds set the icon
      m_cLabelImage.setIcon(m_cMySQLManager.getImageIcon(p_cPattern));
    } else {
      // ds set the image to the GUI field (resized)
      m_cLabelImage.setIcon(
          new ImageIcon(
              CImageHandler.getResizedImage(
                  m_cMySQLManager.getBufferedImage(p_cPattern),
                  m_cPanelCImage.getWidth() - 5,
                  m_cPanelCImage.getHeight() - 5)));
    }

    // ds update image info
    m_cTextFieldTitle.setText(p_cPattern.getTitle());
  }
Esempio n. 4
0
  // ds close GUI
  public void close() {
    // ds get username
    final String strUsername = m_cLearner.getUsername();

    // ds if username is set
    if (null != strUsername) {
      // ds log
      _logMaster("<CGUI>(close) closed GUI application");

      try {
        // ds remove user from active list
        m_cMySQLManager.removeActiveUser(strUsername);

        // ds log
        System.out.println(
            "["
                + CLogger.getStamp()
                + "]<CGUI>(close) Logout of: ["
                + strUsername
                + "] successful");
      } catch (Exception e) {
        // ds could not remove
        System.out.println(
            "["
                + CLogger.getStamp()
                + "]<CGUI>(close) Could not remove user: ["
                + strUsername
                + "] from active users list - please check database");
      }
    }

    // ds only if active
    if (isActive()) {
      // ds dispose frame completely
      m_cFrame.removeAll();
      m_cFrame.dispose();
    }

    // ds info
    System.out.println("[" + CLogger.getStamp() + "]<CGUI>(close) Closing of GUI complete");
  }
Esempio n. 5
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();
  }