Ejemplo n.º 1
0
 /**
  * Displays a message dialog containing the error specified in parameter.
  *
  * @param error a String representing an error message to display.
  */
 private void displayError(String error) {
   JOptionPane.showMessageDialog(
       mailsListPane.getParent(),
       error,
       String.format(
           i18n.get("mailslist.err.title"), Configuration.INSTANCE.get("application.name")),
       JOptionPane.ERROR_MESSAGE);
 }
Ejemplo n.º 2
0
  /**
   * Creates the table and sets its cells as non editable.
   *
   * <p>Adds some mouse events on the table, to display emails, when a user clicks on a specific
   * row.<br>
   * If the email can't be found, an error message will be displayed.<br>
   * The table will reset the size of its column every time the size of the table changed (for
   * example when the user maximizes the window).
   */
  public MailsListPane() {
    // Init desktop (Java 6 Desktop API)
    if (Desktop.isDesktopSupported()) {
      desktop = Desktop.getDesktop();
    }

    if (!ArgsHandler.INSTANCE.memoryModeEnabled()) {
      table.addMouseListener(
          new MouseListener() {
            @Override
            public void mouseReleased(MouseEvent e) {}

            @Override
            public void mousePressed(MouseEvent e) {}

            @Override
            public void mouseExited(MouseEvent e) {}

            @Override
            public void mouseEntered(MouseEvent e) {}

            @Override
            public void mouseClicked(MouseEvent e) {

              String emlViewer = ArgsHandler.INSTANCE.getEmlViewer();

              if (e.getClickCount() == 2 && (emlViewer != null || desktop != null)) {
                File file = null;
                JTable target = (JTable) e.getSource();
                String fileName = UIModel.INSTANCE.getListMailsMap().get(target.getSelectedRow());
                if (fileName == null) {
                  LOGGER.error(
                      "Can't find any associated email for row #{}", target.getSelectedRow());
                } else {
                  file = new File(fileName);
                }

                if (file != null && file.exists()) {
                  try {
                    if (emlViewer != null) {
                      Runtime.getRuntime().exec(emlViewer + " " + file.getAbsolutePath());
                    } else {
                      desktop.open(file);
                    }
                  } catch (IOException ioe) {
                    LOGGER.error("", ioe);
                    displayError(
                        String.format(i18n.get("mailslist.err.open"), file.getAbsolutePath()));
                  }
                } else {
                  displayError(
                      String.format(i18n.get("mailslist.err.find"), file.getAbsolutePath()));
                }
              }
            }
          });
    }

    // Auto scroll tab to bottom when a new element is inserted
    table.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            table.scrollRectToVisible(new Rectangle(table.getCellRect(nbElements, 0, true)));
          }
        });

    model.addColumn(i18n.get("mailslist.col.received"));
    model.addColumn(i18n.get("mailslist.col.from"));
    model.addColumn(i18n.get("mailslist.col.to"));
    model.addColumn(i18n.get("mailslist.col.subject"));
    table.setModel(model);

    mailsListPane.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            // When the width of a column is changed, only the columns to the left and right of the
            // margin change
            table.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);

            // Set width for each column
            int total = 0;
            int length = widths.length;
            for (int i = 0; i < length; i++) {
              table.getColumnModel().getColumn(i).setPreferredWidth(widths[i]);
              total += widths[i];
            }
            table.getColumnModel().getColumn(length).setPreferredWidth(table.getWidth() - total);
          }
        });
    mailsListPane.getViewport().add(table, null);
  }