/**
   * Descripción de Método
   *
   * @param index
   */
  private void displayData(int index) {
    MAttachmentEntry entry = m_attachment.getEntry(index);

    log.config("Index=" + index + " - " + entry);

    // Reset UI

    gifPanel.setImage(null);
    graphPanel.removeAll();

    //

    bDelete.setEnabled(false);
    bOpen.setEnabled(false);
    bSave.setEnabled(false);

    Dimension size = null;

    // no attachment

    if ((entry == null) || (entry.getData() == null)) {
      info.setText("-");
    } else {
      bOpen.setEnabled(true);
      bSave.setEnabled(true);
      bDelete.setEnabled(true);
      log.config(entry.toStringX());

      //

      info.setText(entry.toStringX());

      if (entry.isPDF()) {
        try {
          graphPanel.getInsets();

          PdfPanel pdfpanel =
              PdfPanel.loadPdf(entry.getFile(), graphPanel, false, false, true, true, true, true);

          size = pdfpanel.getSize();

          //

        } catch (Exception e) {
          log.log(Level.SEVERE, "(pdf)", e);
        }
      } else if (entry.isGraphic()) {

        // Can we display it

        Image image = Toolkit.getDefaultToolkit().createImage(entry.getData());

        if (image != null) {
          gifPanel.setImage(image);
          size = gifPanel.getPreferredSize();

          if ((size.width == -1) && (size.height == -1)) {
            log.log(Level.SEVERE, "Invalid Image");
          } else {

            // size.width += 40;
            // size.height += 40;

            graphPanel.add(gifScroll, BorderLayout.CENTER);
          }
        } else {
          log.log(Level.SEVERE, "Could not create image");
        }
      }
    }

    if (graphPanel.getComponentCount() == 0) {
      graphPanel.add(info, BorderLayout.CENTER);
    }

    log.config("Size=" + size);

    // graphPanel.setPreferredSize(size);
    // centerPane.setDividerLocation(size.width+30);
    // size.width += 100;
    // size.height += 100;
    // centerPane.setPreferredSize(size);

    pack();
  } // displayData
Exemple #2
0
  /**
   * Descripción de Método
   *
   * @param index
   */
  private void displayData(int index) {
    MAttachmentEntry entry = m_attachment.getEntry(index);

    log.config("Index=" + index + " - " + entry);

    // Reset UI

    gifPanel.setImage(null);
    graphPanel.removeAll();

    //

    bDelete.setEnabled(false);
    bOpen.setEnabled(false);
    bSave.setEnabled(false);

    Dimension size = null;

    // no attachment

    if ((entry == null) || (entry.getData() == null)) {
      info.setText("-");
    } else {
      bOpen.setEnabled(true);
      bSave.setEnabled(true);
      bDelete.setEnabled(true);
      log.config(entry.toStringX());

      //

      info.setText(entry.toStringX());

      if (entry.isPDF()) {
        try {
          graphPanel.getInsets();

          PdfPanel pdfpanel =
              PdfPanel.loadPdf(entry.getFile(), graphPanel, false, false, true, true, true, true);

          size = pdfpanel.getSize();

          //

        } catch (Exception e) {
          log.log(Level.SEVERE, "(is pdf):" + e.getMessage(), e);
        }
      } else if (entry.isGraphic()) {

        // Can we display it

        /*
         * ---------------------------------------------------------------------------------
         * Modified by Matías Cap - Disytel
         * ---------------------------------------------------------------------------------
         *
         * Image no permite manipular imágenes en formato bmp. Se debió utilizar
         * BufferedImage (extensión de Image) para usar ImageIO. ImageIo.read(f) lee el archivo
         * a adjuntar y devuelve un BufferedImage de ese archivo leído en su formato original.
         *
         * ---------------------------------------------------------------------------------
         * Código anterior
         * ---------------------------------------------------------------------------------
         *
         * Image image = Toolkit.getDefaultToolkit().createImage( entry.getData());
         *
         *
         */

        File f = entry.getFile();
        BufferedImage bufImg = null;
        try {
          bufImg = ImageIO.read(f);
        } catch (Exception e) {
          log.log(Level.SEVERE, "Invalid Image");
        }
        /*
         * ---------------------------------------------------------------------------------
         * Fin modificación Matías Cap - Disytel
         * ---------------------------------------------------------------------------------
         */

        if (bufImg != null) {
          gifPanel.setImage(bufImg);
          size = gifPanel.getPreferredSize();

          if ((size.width == -1) && (size.height == -1)) {
            log.log(Level.SEVERE, "Invalid Image");
          } else {

            // size.width += 40;
            // size.height += 40;

            graphPanel.add(gifScroll, BorderLayout.CENTER);
          }
        } else {
          log.log(Level.SEVERE, "Could not create image");
        }
      } else if (entry.isHTML() || entry.isText() || entry.isRTF()) {
        try {
          JEditorPane textPanel;
          if (entry.isRTF())
            textPanel = new RTFScaledEditorPane(entry.getInputStream(), graphPanel);
          else {
            textPanel = new JEditorPane("file:///" + entry.getFile().getAbsolutePath());
            JScrollPane jScrollPane = new JScrollPane();
            textPanel.setEditable(false);
            jScrollPane.setViewportView(textPanel);
            textPanel.setPreferredSize(new Dimension(800, 600));
            graphPanel.add(jScrollPane, BorderLayout.CENTER);
          }
        } catch (Exception e) {
          log.severe("txt html rtf attachment Exception:" + e.getMessage());
        }
      }
    }

    if (graphPanel.getComponentCount() == 0) {
      graphPanel.add(info, BorderLayout.CENTER);
    }

    log.config("Size=" + size);

    // graphPanel.setPreferredSize(size);
    // centerPane.setDividerLocation(size.width+30);
    // size.width += 100;
    // size.height += 100;
    // centerPane.setPreferredSize(size);

    pack();
  } // displayData