Beispiel #1
0
  /** Descripción de Método */
  private void loadAttachments() {
    log.config("");

    // Set Text/Description

    String sText = m_attachment.getTextMsg();

    if (sText == null) {
      text.setText("");
    } else {
      text.setText(sText);
    }

    // Set Combo

    int size = m_attachment.getEntryCount();

    for (int i = 0; i < size; i++) {
      cbContent.addItem(m_attachment.getEntryName(i));
    }

    if (size > 0) {
      cbContent.setSelectedIndex(0);
    } else {
      displayData(0);
    }
  } // loadAttachment
Beispiel #2
0
  /** Descripción de Método */
  private void deleteAttachment() {
    log.info("");

    if (ADialog.ask(m_WindowNo, this, "AttachmentDelete?")) {
      m_attachment.delete(true);
    }
  } // deleteAttachment
Beispiel #3
0
  /** Descripción de Método */
  private void loadFile() {
    log.info("");

    JFileChooser chooser = new JFileChooser();

    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "AttachmentNew"));

    int returnVal = chooser.showOpenDialog(this);

    if (returnVal != JFileChooser.APPROVE_OPTION) {
      return;
    }

    //

    String fileName = chooser.getSelectedFile().getName();

    log.config(fileName);

    File file = chooser.getSelectedFile();

    if (m_attachment.addEntry(file)) {
      cbContent.addItem(fileName);
      cbContent.setSelectedIndex(cbContent.getItemCount() - 1);
      m_change = true;
    }
  } // getFileName
Beispiel #4
0
  /**
   * Descripción de Método
   *
   * @return
   */
  private boolean openAttachment() {
    int index = cbContent.getSelectedIndex();
    byte[] data = m_attachment.getEntryData(index);

    if (data == null) {
      return false;
    }

    try {
      String fileName = System.getProperty("java.io.tmpdir") + m_attachment.getEntryName(index);
      File tempFile = new File(fileName);

      m_attachment.getEntryFile(index, tempFile);

      if (isWindows()) {

        // Runtime.getRuntime().exec ("rundll32 url.dll,FileProtocolHandler " + url);

        Process p =
            Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL \"" + tempFile + "\"");

        // p.waitFor();

        return true;
      } else if (isMac()) {
        String[] cmdArray = new String[] {"open", tempFile.getAbsolutePath()};
        Process p = Runtime.getRuntime().exec(cmdArray);

        // p.waitFor();

        return true;
      } else // other OS
      {
      }
    } catch (Exception e) {
      log.log(Level.SEVERE, "openFile", e);
    }

    return false;
  } // openFile
Beispiel #5
0
  /** Descripción de Método */
  private void saveAttachmentToFile() {
    int index = cbContent.getSelectedIndex();

    log.info("index=" + index);

    if (m_attachment.getEntryCount() < index) {
      return;
    }

    String fileName = getFileName(index);
    String ext = fileName.substring(fileName.lastIndexOf("."));

    log.config("Ext=" + ext);

    JFileChooser chooser = new JFileChooser();

    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "AttachmentSave"));

    File f = new File(fileName);

    chooser.setSelectedFile(f);

    // Show dialog

    int returnVal = chooser.showSaveDialog(this);

    if (returnVal != JFileChooser.APPROVE_OPTION) {
      return;
    }

    File saveFile = chooser.getSelectedFile();

    if (saveFile == null) {
      return;
    }

    log.config("Save to " + saveFile.getAbsolutePath());
    m_attachment.getEntryFile(index, saveFile);
  } // saveAttachmentToFile
Beispiel #6
0
  /** Descripción de Método */
  private void deleteAttachmentEntry() {
    log.info("");

    int index = cbContent.getSelectedIndex();
    String fileName = getFileName(index);

    if (fileName == null) {
      return;
    }

    //

    if (ADialog.ask(m_WindowNo, this, "AttachmentDeleteEntry?", fileName)) {
      if (m_attachment.deleteEntry(index)) {
        cbContent.removeItemAt(index);
      }

      m_change = true;
    }
  } // deleteAttachment
Beispiel #7
0
  /**
   * Descripción de Método
   *
   * @param e
   */
  public void actionPerformed(ActionEvent e) {

    // log.config( "Attachment.actionPerformed - " + e.getActionCommand());
    // Save and Close

    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
      String newText = text.getText();

      if (newText == null) {
        newText = "";
      }

      String oldText = m_attachment.getTextMsg();

      if (oldText == null) {
        oldText = "";
      }

      if (!m_change) {
        m_change = !newText.equals(oldText);
      }

      if ((newText.length() > 0) || (m_attachment.getEntryCount() > 0)) {
        if (m_change) {
          m_attachment.setTextMsg(text.getText());
          m_attachment.save();
        }
      } else {
        m_attachment.delete(true);
      }

      dispose();
    }

    // Cancel

    else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
      dispose();
    }

    // Delete Attachment

    else if (e.getSource() == bDeleteAll) {
      deleteAttachment();
      dispose();
    }

    // Delete individual entry and Return

    else if (e.getSource() == bDelete) {
      deleteAttachmentEntry();

      // Show Data

    } else if (e.getSource() == cbContent) {
      displayData(cbContent.getSelectedIndex());

      // Load Attachment

    } else if (e.getSource() == bLoad) {
      loadFile();

      // Open Attachment

    } else if (e.getSource() == bSave) {
      saveAttachmentToFile();

      // Open Attachment

    } else if (e.getSource() == bOpen) {
      if (!openAttachment()) {
        saveAttachmentToFile();
      }
    }
  } // actionPerformed
Beispiel #8
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