tn5250j/src/org/tn5250j/mailtools SendEMail.java,1.9,1.10 SMTPConfig.java,1.4,1.5 SendEMailDialog.java,1.10,1.11

[email protected]
Newsgroups gmane.comp.java.tn5250j.cvs
Message-ID <[email protected]>
Update of /cvsroot/tn5250j/tn5250j/src/org/tn5250j/mailtools
In directory sc8-pr-cvs1:/tmp/cvs-serv7845/src/org/tn5250j/mailtools

Modified Files:
	SendEMail.java SMTPConfig.java SendEMailDialog.java 
Log Message:
Update related to send screen through email + fix for the title and the
focus-problem when starting new session.

Index: SendEMail.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/mailtools/SendEMail.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SendEMail.java	9 Jul 2003 18:55:41 -0000	1.9
--- SendEMail.java	28 Nov 2003 13:21:02 -0000	1.10
***************
*** 40,43 ****
--- 40,44 ----
     private String to;
     private String from;
+    private String pers;
     private String cc;
     private String subject;
***************
*** 126,147 ****
     private boolean loadConfig(String name) throws Exception {
  
- //      boolean rc = false;
- 
- //      SMTPProperties = new java.util.Properties();
- //      if (name == null || name == "")
- //         name = ConfigureFactory.getInstance().settingsDirectory()
- //                                    +  "SMTPProperties.cfg";
- //
- //      try {
- //         FileInputStream in = new FileInputStream(name);
- //
- //         SMTPProperties.load(in);
- //         rc = true;
- //      }
- //      catch (IOException ioe) {System.out.println(ioe.getMessage());}
- //      catch (SecurityException se) {
- //         System.out.println(se.getMessage());
- //      }
- //
        SMTPProperties = ConfigureFactory.getInstance().getProperties("smtp",
                             "SMTPProperties.cfg");
--- 127,130 ----
***************
*** 198,203 ****
              msg.setSubject(subject.trim());
  
!          if (from != null && from.length() > 0)
!             msg.setFrom(new InternetAddress(from));
  
           if (message != null && message.length() > 0) {
--- 181,191 ----
              msg.setSubject(subject.trim());
  
!          if (from == null)
!             from = SMTPProperties.getProperty("mail.smtp.from");
! 
!          if (from != null && from.length() > 0) {
!          	pers = SMTPProperties.getProperty("mail.smtp.realname");
!          	if (pers != null) msg.setFrom(new InternetAddress(from, pers));
!          }
  
           if (message != null && message.length() > 0) {
***************
*** 255,264 ****
           showFailedException(sfe);
        }
- //      catch (AddressException ae) {
- //
- //      }
- //      catch ( MessagingException me) {
- //
- //      }
        return false;
     }
--- 243,246 ----
***************
*** 276,281 ****
        Address[] ia = sfe.getInvalidAddresses();
  
!       for (int x = 0; x < ia.length; x++) {
!          error += "Invalid Address: " + ia[x].toString() + "\n";
        }
  
--- 258,265 ----
        Address[] ia = sfe.getInvalidAddresses();
  
!       if (ia != null) {
!          for (int x = 0; x < ia.length; x++) {
!             error += "Invalid Address: " + ia[x].toString() + "\n";
!          }
        }
  

Index: SMTPConfig.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/mailtools/SMTPConfig.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SMTPConfig.java	9 Jul 2003 18:55:41 -0000	1.4
--- SMTPConfig.java	28 Nov 2003 13:21:03 -0000	1.5
***************
*** 33,206 ****
  
  import org.tn5250j.interfaces.ConfigureFactory;
- import org.tn5250j.tools.AlignLayout;
  import org.tn5250j.tools.LangTool;
  
  public class SMTPConfig extends JDialog {
  
!    JPanel mainPanel = new JPanel();
!    BorderLayout borderLayout1 = new BorderLayout();
!    AlignLayout alignLayout = new AlignLayout(2,5,5);
!    JPanel configPanel = new JPanel();
!    JPanel optionsPanel = new JPanel();
!    JLabel labelHost = new JLabel();
!    JTextField fieldHost = new JTextField();
!    JLabel labelPort = new JLabel();
!    JTextField fieldPort = new JTextField();
!    JLabel labelFrom = new JLabel();
!    JTextField fieldFrom = new JTextField();
!    JButton optDone = new JButton();
!    JButton optCancel = new JButton();
!    JLabel labelFileName = new JLabel();
!    JTextField fieldFileName = new JTextField();
!    Properties SMTPProperties;
! //   String fileName;
  
!    private static final String smtpFileName = "SMTPProperties.cfg";
  
!    public SMTPConfig(Frame frame, String title, boolean modal) {
!       super(frame, title, modal);
!       try {
!          jbInit();
!          pack();
!       }
!       catch(Exception ex) {
!          ex.printStackTrace();
!       }
!    }
  
!    public SMTPConfig() {
!       this(null, "", false);
!    }
  
!    void jbInit() throws Exception {
  
!       setTitle(LangTool.getString("em.configTitle"));
!       mainPanel.setLayout(borderLayout1);
!       labelHost.setText(LangTool.getString("em.labelHost"));
!       fieldHost.setColumns(20);
!       labelPort.setText(LangTool.getString("em.labelPort"));
!       fieldPort.setColumns(5);
!       labelFrom.setText(LangTool.getString("em.labelFrom"));
!       fieldFrom.setColumns(20);
!       optDone.setText(LangTool.getString("em.optDone"));
!       optDone.addActionListener(new java.awt.event.ActionListener() {
!          public void actionPerformed(ActionEvent e) {
!             optDone_actionPerformed(e);
!          }
!       });
  
!       optCancel.setText(LangTool.getString("em.optCancelLabel"));
!       optCancel.addActionListener(new java.awt.event.ActionListener() {
!          public void actionPerformed(ActionEvent e) {
!             optCancel_actionPerformed(e);
!          }
!       });
  
!       labelFileName.setText(LangTool.getString("em.labelFileName"));
!       fieldFileName.setText("tn5250j.txt");
!       fieldFileName.setColumns(20);
!       optionsPanel.add(optDone, null);
!       optionsPanel.add(optCancel, null);
!       getContentPane().add(mainPanel);
  
!       mainPanel.add(configPanel, BorderLayout.CENTER);
!       configPanel.add(labelHost, null);
!       mainPanel.add(optionsPanel,  BorderLayout.SOUTH);
!       configPanel.add(fieldHost, null);
!       configPanel.add(labelPort, null);
!       configPanel.add(fieldPort, null);
!       configPanel.add(labelFrom, null);
!       configPanel.add(fieldFrom, null);
!       configPanel.add(labelFileName, null);
!       configPanel.add(fieldFileName, null);
!       configPanel.setLayout(alignLayout);
  
!       if (loadConfig(null)) {
  
!          setProperties();
  
!       }
  
!       centerMe();
  
!    }
  
!    private void centerMe() {
!       pack();
  
!       //Center the window
!       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
!       Dimension frameSize = getSize();
!       if (frameSize.height > screenSize.height)
!          frameSize.height = screenSize.height;
!       if (frameSize.width > screenSize.width)
!          frameSize.width = screenSize.width;
  
!       setLocation((screenSize.width - frameSize.width) / 2,
!                      (screenSize.height - frameSize.height) / 2);
  
!    }
  
!    private void setProperties() {
  
!    //   mail.smtp.host=            Fill in the host name or ip address of your SMTP
!    //                              mail server.
!    //
!    //   mail.smtp.port=            Fill in the port to use to connect
!    //
!    //   mail.smtp.from=            This is the e-mail address from.  For example I would
!    //                              place [email protected] here as follows:
!    //
!    //                              [email protected]
  
!       fieldHost.setText(SMTPProperties.getProperty("mail.smtp.host"));
!       fieldPort.setText(SMTPProperties.getProperty("mail.smtp.port"));
!       fieldFrom.setText(SMTPProperties.getProperty("mail.smtp.from"));
  
!       // file name
!       fieldFileName.setText(SMTPProperties.getProperty("fileName"));
  
!    }
  
!    /**
!     * <p>Loads the given configuration file.
!     *
!     * @param name Configuration file name
!     * @return true if the configuration file was loaded
!     */
!    private boolean loadConfig(String name) throws Exception {
  
!       SMTPProperties = ConfigureFactory.getInstance().getProperties("smtp",
!                            smtpFileName);
  
!       if (SMTPProperties.size() > 0)
!          return true;
!       else
!          return false;
!     }
  
!    void optDone_actionPerformed(ActionEvent e) {
  
!       SMTPProperties.setProperty("mail.smtp.host",fieldHost.getText());
!       SMTPProperties.setProperty("mail.smtp.port",fieldPort.getText());
!       SMTPProperties.setProperty("mail.smtp.from",fieldFrom.getText());
  
!       // file name
!       SMTPProperties.setProperty("fileName",fieldFileName.getText());
  
!       for (Enumeration x = SMTPProperties.propertyNames();x.hasMoreElements();)
!          System.out.println(SMTPProperties.get(x.nextElement()));
  
!       ConfigureFactory.getInstance().saveSettings("smtp", smtpFileName,
!                                  "------ SMTP Defaults --------");
!       this.setVisible(false);
  
!    }
  
!    void optCancel_actionPerformed(ActionEvent e) {
  
!       this.setVisible(false);
  
!    }
  
  }
--- 33,281 ----
  
  import org.tn5250j.interfaces.ConfigureFactory;
  import org.tn5250j.tools.LangTool;
  
  public class SMTPConfig extends JDialog {
  
! 	JPanel mainPanel = new JPanel();
! 	BorderLayout borderLayout1 = new BorderLayout();
! 	JPanel configPanel = new JPanel(new GridBagLayout());
! 	GridBagConstraints gbc;
! 	JPanel optionsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
! 	JLabel labelHost = new JLabel();
! 	JTextField fieldHost = new JTextField();
! 	JLabel labelPort = new JLabel();
! 	JTextField fieldPort = new JTextField();
! 	JLabel labelDefault = new JLabel();
! 	JLabel labelName = new JLabel();
! 	JTextField fieldName = new JTextField();
! 	JLabel labelFrom = new JLabel();
! 	JTextField fieldFrom = new JTextField();
! 	JButton optDone = new JButton();
! 	JButton optCancel = new JButton();
! 	JLabel labelFileName = new JLabel();
! 	JTextField fieldFileName = new JTextField();
! 	Properties SMTPProperties;
! 	//   String fileName;
  
! 	private static final String smtpFileName = "SMTPProperties.cfg";
  
! 	public SMTPConfig(Frame frame, String title, boolean modal) {
! 		super(frame, title, modal);
! 		try {
! 			jbInit();
! 			pack();
! 		} catch (Exception ex) {
! 			ex.printStackTrace();
! 		}
! 	}
  
! 	public SMTPConfig() {
! 		this(null, "", false);
! 	}
  
! 	void jbInit() throws Exception {
  
! 		setTitle(LangTool.getString("em.configTitle"));
! 		mainPanel.setLayout(borderLayout1);
! 		labelHost.setText(LangTool.getString("em.labelHost"));
! 		fieldHost.setColumns(20);
! 		labelPort.setText(LangTool.getString("em.labelPort"));
! 		fieldPort.setColumns(3);
! 		labelDefault.setText(LangTool.getString("em.labelDefault"));
! 		labelName.setText(LangTool.getString("em.labelName"));
! 		fieldName.setColumns(20);
! 		labelFrom.setText(LangTool.getString("em.labelFrom"));
! 		fieldFrom.setColumns(20);
! 		optDone.setPreferredSize(new Dimension(100, 27));
! 		optDone.setText(LangTool.getString("em.optDone"));
! 		optDone.addActionListener(new java.awt.event.ActionListener() {
! 			public void actionPerformed(ActionEvent e) {
! 				optDone_actionPerformed(e);
! 			}
! 		});
  
! 		optCancel.setPreferredSize(new Dimension(100, 27));
! 		optCancel.setText(LangTool.getString("em.optCancelLabel"));
! 		optCancel.addActionListener(new java.awt.event.ActionListener() {
! 			public void actionPerformed(ActionEvent e) {
! 				optCancel_actionPerformed(e);
! 			}
! 		});
  
! 		labelFileName.setText(LangTool.getString("em.labelFileName"));
! 		fieldFileName.setText("tn5250j.txt");
! 		fieldFileName.setColumns(20);
  
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0;
! 		gbc.gridy = 0;
! 		//gbc.gridwidth = 1;
! 		gbc.insets = new Insets(10, 10, 5, 5);
! 		gbc.anchor = GridBagConstraints.WEST;
! 		configPanel.add(labelHost, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 1;
! 		gbc.gridy = 0;
! 		gbc.gridwidth = 2;
! 		gbc.insets = new Insets(10, 5, 5, 10);
! 		gbc.anchor = GridBagConstraints.WEST;
! 		configPanel.add(fieldHost, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0;
! 		gbc.gridy = 1;
! 		gbc.insets = new Insets(5, 10, 5, 5);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(labelPort, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 1;
! 		gbc.gridy = 1;
! 		gbc.insets = new Insets(5, 5, 5, 5);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(fieldPort, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 2;
! 		gbc.gridy = 1;
! 		gbc.insets = new Insets(5, 15, 5, 10);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(labelDefault, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0;
! 		gbc.gridy = 2;
! 		gbc.insets = new Insets(5, 10, 5, 5);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(labelName, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 1;
! 		gbc.gridy = 2;
! 		gbc.gridwidth = 2;
! 		gbc.insets = new Insets(5, 5, 5, 10);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(fieldName, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0;
! 		gbc.gridy = 3;
! 		gbc.insets = new Insets(5, 10, 5, 5);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(labelFrom, gbc);
! 		gbc.gridx = 1;
! 		gbc.gridy = 3;
! 		gbc.gridwidth = 2;
! 		gbc.insets = new Insets(5, 5, 5, 10);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(fieldFrom, gbc);
! 		gbc.gridx = 0;
! 		gbc.gridy = 4;
! 		gbc.gridwidth = 1;
! 		gbc.insets = new Insets(5, 10, 0, 5);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(labelFileName, gbc);
! 		gbc.gridx = 1;
! 		gbc.gridy = 4;
! 		gbc.gridwidth = 2;
! 		gbc.insets = new Insets(5, 5, 0, 10);
! 		gbc.anchor = GridBagConstraints.WEST;		
! 		configPanel.add(fieldFileName, gbc);
  
! 		mainPanel.add(configPanel, BorderLayout.NORTH);
! 		optionsPanel.add(optDone);
! 		optionsPanel.add(optCancel);
! 		mainPanel.add(optionsPanel, BorderLayout.SOUTH);
  
! 		getContentPane().add(mainPanel);
  
! 		if (loadConfig(null)) {
  
! 			setProperties();
  
! 		}
  
! 		centerMe();
  
! 	}
  
! 	private void centerMe() {
! 		pack();
  
! 		//Center the window
! 		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
! 		Dimension frameSize = getSize();
! 		if (frameSize.height > screenSize.height)
! 			frameSize.height = screenSize.height;
! 		if (frameSize.width > screenSize.width)
! 			frameSize.width = screenSize.width;
  
! 		setLocation(
! 			(screenSize.width - frameSize.width) / 2,
! 			(screenSize.height - frameSize.height) / 2);
  
! 	}
  
! 	private void setProperties() {
  
! 		//   mail.smtp.host=            Fill in the host name or ip address of your SMTP
! 		//                              mail server.
! 		//
! 		//   mail.smtp.port=            Fill in the port to use to connect
! 		//
! 		//   mail.smtp.from=            This is the e-mail address from.  For example I would
! 		//                              place [email protected] here as follows:
! 		//
! 		//                              [email protected]
  
! 		fieldHost.setText(SMTPProperties.getProperty("mail.smtp.host"));
! 		fieldPort.setText(SMTPProperties.getProperty("mail.smtp.port"));
! 		fieldFrom.setText(SMTPProperties.getProperty("mail.smtp.from"));
! 		fieldName.setText(SMTPProperties.getProperty("mail.smtp.realname"));
  
! 		// file name
! 		fieldFileName.setText(SMTPProperties.getProperty("fileName"));
  
! 	}
  
! 	/**
! 	 * <p>Loads the given configuration file.
! 	 *
! 	 * @param name Configuration file name
! 	 * @return true if the configuration file was loaded
! 	 */
! 	private boolean loadConfig(String name) throws Exception {
  
! 		SMTPProperties =
! 			ConfigureFactory.getInstance().getProperties("smtp", smtpFileName);
  
! 		if (SMTPProperties.size() > 0)
! 			return true;
! 		else
! 			return false;
! 	}
  
! 	void optDone_actionPerformed(ActionEvent e) {
  
! 		SMTPProperties.setProperty("mail.smtp.host", fieldHost.getText());
! 		SMTPProperties.setProperty("mail.smtp.port", fieldPort.getText());
! 		SMTPProperties.setProperty("mail.smtp.from", fieldFrom.getText());
! 		SMTPProperties.setProperty("mail.smtp.realname", fieldName.getText());
  
! 		// file name
! 		SMTPProperties.setProperty("fileName", fieldFileName.getText());
  
! 		for (Enumeration x = SMTPProperties.propertyNames();
! 			x.hasMoreElements();
! 			)
! 			System.out.println(SMTPProperties.get(x.nextElement()));
  
! 		ConfigureFactory.getInstance().saveSettings(
! 			"smtp",
! 			smtpFileName,
! 			"------ SMTP Defaults --------");
! 		this.setVisible(false);
  
! 	}
  
! 	void optCancel_actionPerformed(ActionEvent e) {
! 
! 		this.setVisible(false);
! 
! 	}
  
  }

Index: SendEMailDialog.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/mailtools/SendEMailDialog.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** SendEMailDialog.java	18 Feb 2003 22:58:10 -0000	1.10
--- SendEMailDialog.java	28 Nov 2003 13:21:03 -0000	1.11
***************
*** 27,39 ****
  package org.tn5250j.mailtools;
  
! import javax.swing.*;
! import java.io.*;
! import java.awt.*;
! import java.util.*;
  
  import org.tn5250j.Screen5250;
  import org.tn5250j.Session;
  import org.tn5250j.SessionConfig;
! import org.tn5250j.tools.*;
  
  /**
--- 27,55 ----
  package org.tn5250j.mailtools;
  
! import java.awt.Dimension;
! import java.awt.Frame;
! import java.awt.GridBagLayout;
! import java.awt.GridBagConstraints;
! import java.awt.Insets;
! import java.io.File;
! import java.io.IOException;
! import java.util.StringTokenizer;
! 
! import javax.swing.ButtonGroup;
! import javax.swing.JComboBox;
! import javax.swing.JFrame;
! import javax.swing.JLabel;
! import javax.swing.JOptionPane;
! import javax.swing.JPanel;
! import javax.swing.JRadioButton;
! import javax.swing.JScrollPane;
! import javax.swing.JTextArea;
! import javax.swing.JTextField;
  
  import org.tn5250j.Screen5250;
  import org.tn5250j.Session;
  import org.tn5250j.SessionConfig;
! import org.tn5250j.tools.LangTool;
! import org.tn5250j.tools.encoder.EncodeComponent;
  
  /**
***************
*** 42,403 ****
  public class SendEMailDialog {
  
!    JComboBox toAddress;
!    JTextField subject;
!    JTextArea bodyText;
!    JTextField attachmentName;
!    SessionConfig config;
!    Session session;
!    String fileName;
  
!    /**
!     * Constructor to send the screen information
!     *
!     * @param parent
!     * @param session
!     */
!    public SendEMailDialog(Frame parent, Session session ) {
  
!       if (!isEMailAvailable()) {
  
!          JOptionPane.showMessageDialog(parent,
!                                        LangTool.getString("messages.noEmailAPI"),
!                                        "Error",
!                                        JOptionPane.ERROR_MESSAGE,null);
  
!       }
!       else {
  
!          this.session = session;
!          Screen5250 screen = session.getScreen();
  
!          Object[]      message = new Object[1];
!          message[0] = setupMailPanel("tn5250j.txt");
  
!          String[] options = new String[3];
  
!          int result = 0;
!          while (result == 0 || result == 2) {
  
!             // setup the dialog options
!             setOptions(options);
  
!             result = JOptionPane.showOptionDialog(
!                 parent,                            // the parent that the dialog blocks
!                 message,                           // the dialog message array
!                 LangTool.getString("em.title"),    // the title of the dialog window
!                 JOptionPane.DEFAULT_OPTION,        // option type
!                 JOptionPane.QUESTION_MESSAGE,      // message type
!                 null,                              // optional icon, use null to use the default icon
!                 options,                           // options string array, will be made into buttons//
!                 options[0]                         // option that should be made into a default button
!             );
  
!             switch(result) {
!                case 0: // Send it
!                   SendEMail sem = new SendEMail();
!                   sem.setConfigFile("SMTPProperties.cfg");
!                   sem.setTo((String)toAddress.getSelectedItem());
!                   sem.setSubject(subject.getText());
!                   if (bodyText.getText().length() >0)
!                      sem.setMessage(bodyText.getText());
  
!                   if (attachmentName.getText().length() > 0)
!                      sem.setAttachmentName(attachmentName.getText());
  
!                   StringBuffer sb = new StringBuffer();
!                   char[] s = screen.getScreenAsChars();
!                   int c = screen.getCols();
!                   int l = screen.getRows() * c;
!                   int col = 0;
!                   for (int x = 0; x < l; x++,col++) {
!                      sb.append(s[x]);
!                      if (col == c) {
!                         sb.append('\n');
!                         col = 0;
!                      }
!                   }
  
!                   sem.setAttachment(sb.toString());
  
!                   // send the information
!                   sendIt(parent,sem);
  
!                   sem.release();
!                   sem = null;
  
  
!                   break;
!                case 1: // Cancel
!       //		      System.out.println("Cancel");
!                   break;
!                case 2: // Configure SMTP
!                   configureSMTP(parent);
!       //		      System.out.println("Cancel");
!                   break;
!                default:
!                   break;
!             }
!          }
!       }
!    }
  
!    /**
!     * Constructor to send a file
!     *
!     * @param parent
!     * @param session
!     */
!    public SendEMailDialog(Frame parent, Session session, String fileName ) {
  
!       if (!isEMailAvailable()) {
  
!          JOptionPane.showMessageDialog(parent,
!                "The Java E-Mail API can not be found or is not installed\n" +
!                   "Please read e-mail.txt file for installation instructions." ,"Error",
!                JOptionPane.ERROR_MESSAGE,null);
  
!       }
!       else {
  
!          this.session = session;
!          Screen5250 screen = session.getScreen();
  
!          Object[]      message = new Object[1];
!          message[0] = setupMailPanel(fileName);
!          String[] options = new String[3];
  
  
!          int result = 0;
!          while (result == 0 || result == 2) {
  
!             // setup the dialog options
!             setOptions(options);
  
!             result = JOptionPane.showOptionDialog(
!                 parent,                            // the parent that the dialog blocks
!                 message,                           // the dialog message array
!                 LangTool.getString("em.titleFileTransfer"),    // the title of the dialog window
!                 JOptionPane.DEFAULT_OPTION,        // option type
!                 JOptionPane.QUESTION_MESSAGE,      // message type
!                 null,                              // optional icon, use null to use the default icon
!                 options,                           // options string array, will be made into buttons//
!                 options[0]                         // option that should be made into a default button
!             );
  
!             switch(result) {
!                case 0: // Send it
  
!                   SendEMail sem = new SendEMail();
!                   sem.setConfigFile("SMTPProperties.cfg");
!                   sem.setTo((String)toAddress.getSelectedItem());
!                   sem.setSubject(subject.getText());
!                   if (bodyText.getText().length() >0)
!                      sem.setMessage(bodyText.getText());
  
!                   if (attachmentName.getText().length() > 0)
!                      sem.setAttachmentName(attachmentName.getText());
  
!                   if (fileName != null && fileName.length() > 0)
!                      sem.setFileName(fileName);
  
!                   // send the information
!                   sendIt(parent,sem);
  
!                   sem.release();
!                   sem = null;
  
!                   break;
!                case 1: // Cancel
!       //		      System.out.println("Cancel");
!                   break;
!                case 2: // Configure SMTP
!                   configureSMTP(parent);
!       //		      System.out.println("Cancel");
!                   break;
!                default:
!                   break;
!             }
!          }
!       }
!    }
  
!    /**
!     * Send the e-mail on its way.
!     * @param sem
!     */
!    private void sendIt (Frame parent, SendEMail sem) {
  
!       if (parent == null)
!          parent = new JFrame();
  
!       try {
!          if (sem.send()) {
  
!             JOptionPane.showMessageDialog(parent,
!                                              LangTool.getString("em.confirmationMessage") +
!                                              " " + (String)toAddress.getSelectedItem(),
!                                              LangTool.getString("em.titleConfirmation"),
!                                              JOptionPane.INFORMATION_MESSAGE);
  
!             if (session != null) {
!                config.setProperty("emailTo",
!                      getToTokens(config.getStringProperty("emailTo"),
!                                     toAddress));
!                config.saveSessionProps();
!                setToCombo(config.getStringProperty("emailTo"),toAddress);
!             }
!          }
!       }
!       catch (IOException ioe) {
!          System.out.println(ioe.getMessage());
!       }
!       catch (Exception ex) {
!          System.out.println(ex.getMessage());
!       }
!    }
  
!    /**
!     * Configure the SMTP server information
!     *
!     * @param parent
!     */
!    private void configureSMTP(Frame parent) {
  
!       if (parent == null)
!          parent = new JFrame();
  
!       SMTPConfig smtp = new SMTPConfig(parent,"",true);
!       smtp.setVisible(true);
!       smtp.dispose();
  
!    }
  
!    /**
!     * Create the main e-mail panel for display
!     *
!     * @param fileName
!     * @return
!     */
!    private JPanel setupMailPanel (String fileName) {
  
!       JPanel semp = new JPanel();
!       semp.setLayout(new AlignLayout(2,5,5));
  
!       JLabel tol = new JLabel(LangTool.getString("em.to"));
!       JLabel subl = new JLabel(LangTool.getString("em.subject"));
!       JLabel bodyl = new JLabel(LangTool.getString("em.body"));
!       JLabel fnl = new JLabel(LangTool.getString("em.fileName"));
  
!       toAddress = new JComboBox();
!       toAddress.setEditable(true);
  
!       subject = new JTextField(30);
!       bodyText = new JTextArea(6,30);
!       JScrollPane bodyScrollPane = new JScrollPane(bodyText);
!       bodyScrollPane.setHorizontalScrollBarPolicy(
!       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
!       bodyScrollPane.setVerticalScrollBarPolicy(
!       JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
!       attachmentName = new JTextField(fileName,30);
  
!       config = null;
  
!       if (session != null) {
!          config = session.getConfiguration();
  
!          if (config.isPropertyExists("emailTo")) {
!             setToCombo(config.getStringProperty("emailTo"),toAddress);
!          }
!       }
  
!       semp.add(tol);
!       semp.add(toAddress);
!       semp.add(subl);
!       semp.add(subject);
!       semp.add(bodyl);
!       semp.add(bodyScrollPane);
!       semp.add(fnl);
!       semp.add(attachmentName);
  
!       return semp;
  
!    }
  
!    private void setOptions(String[] options) {
  
  
!       options[0] = LangTool.getString("em.optSendLabel");
!       options[1] = LangTool.getString("em.optCancelLabel");
  
!       File smtp = new File("SMTPProperties.cfg");
  
!       if (smtp.exists())
!          options[2] = LangTool.getString("em.optEditLabel");
!       else
!          options[2] = LangTool.getString("em.optConfigureLabel");
  
  
  
!    }
  
!    /**
!     * Set the combo box items to the string token from to.
!     * The separator is a '|' character.
!     *
!     * @param to
!     * @param boxen
!     */
!    private void setToCombo(String to, JComboBox boxen) {
  
!       StringTokenizer tokenizer = new StringTokenizer(to, "|");
  
!       boxen.removeAllItems();
  
!       while(tokenizer.hasMoreTokens())  {
!          boxen.addItem(tokenizer.nextToken());
!       }
!    }
  
!    /**
!     * Creates string of tokens from the combobox items.
!     * The separator is a '|' character.  It does not save duplicate items.
!     *
!     * @param to
!     * @param boxen
!     * @return
!     */
!    private String getToTokens(String to, JComboBox boxen) {
  
!       StringBuffer sb = new StringBuffer();
!       String selected = (String)boxen.getSelectedItem();
  
!       sb.append(selected + '|');
  
!       int c = boxen.getItemCount();
  
!       for (int x = 0; x < c; x++) {
!          if (!selected.equals((String)boxen.getItemAt(x)))
!             sb.append((String)boxen.getItemAt(x) + '|');
!       }
!       return sb.toString();
!    }
  
!    /**
!     * Checks to make sure that the e-mail api's are available
!     *
!     * @return whether or not the e-mail api's are available or not.
!     */
!    private boolean isEMailAvailable() {
  
!       try {
!          Class.forName("javax.mail.Message");
!          return true;
!       }
!       catch (Exception ex) {
!          System.out.println(" not there " + ex.getMessage());
!          return false;
!       }
  
!    }
  
  }
--- 58,532 ----
  public class SendEMailDialog {
  
! 	JComboBox toAddress;
! 	JTextField subject;
! 	JTextArea bodyText;
! 	JTextField attachmentName;
! 	SessionConfig config;
! 	Session session;
! 	String fileName;
! 	JRadioButton text;
! 	JRadioButton graphic;
! 	GridBagConstraints gbc;
  
! 	/**
! 	 * Constructor to send the screen information
! 	 *
! 	 * @param parent
! 	 * @param session
! 	 */
! 	public SendEMailDialog(Frame parent, Session session) {
  
! 		if (!isEMailAvailable()) {
  
! 			JOptionPane.showMessageDialog(
! 				parent,
! 				LangTool.getString("messages.noEmailAPI"),
! 				"Error",
! 				JOptionPane.ERROR_MESSAGE,
! 				null);
  
! 		} 
! 		else {
  
! 			this.session = session;
! 			Screen5250 screen = session.getScreen();
  
! 			Object[] message = new Object[1];
! 			message[0] = setupMailPanel("tn5250j.txt");
  
! 			String[] options = new String[3];
  
! 			int result = 0;
! 			while (result == 0 || result == 2) {
  
! 				// setup the dialog options
! 				setOptions(options);
  
! 				result = JOptionPane.showOptionDialog(parent,
! 					// the parent that the dialog blocks
! 					message, // the dialog message array
! 					LangTool.getString("em.title"), 
! 					// the title of the dialog window
! 					JOptionPane.DEFAULT_OPTION, // option type
! 					JOptionPane.PLAIN_MESSAGE, // message type
! 					null, // optional icon, use null to use the default icon
! 					options, // options string array, will be made into buttons
! 					options[0] // option that should be made into a default btn
! 				);
  
! 				switch (result) {
! 					case 0 : // Send it
! 						SendEMail sem = new SendEMail();
! 						sem.setConfigFile("SMTPProperties.cfg");
! 						sem.setTo((String) toAddress.getSelectedItem());
! 						sem.setSubject(subject.getText());
! 						if (bodyText.getText().length() > 0)
! 							sem.setMessage(bodyText.getText());
  
! 						if (attachmentName.getText().length() > 0)
! 							sem.setAttachmentName(attachmentName.getText());
  
! 						if (text.isSelected()) {
  
! 							StringBuffer sb = new StringBuffer();
! 							char[] s = screen.getScreenAsChars();
! 							int c = screen.getCols();
! 							int l = screen.getRows() * c;
! 							int col = 0;
! 							for (int x = 0; x < l; x++, col++) {
! 								sb.append(s[x]);
! 								if (col == c) {
! 									sb.append('\n');
! 									col = 0;
! 								}
! 							}
  
! 							sem.setAttachment(sb.toString());
! 						} else {
  
! 							File dir = new File(System.getProperty("user.dir"));
  
+ 							//  setup the temp file name
+ 							String tempFile = "tn5250jTemp";
  
! 							try {
! 								// create the temporary file
! 								File f =
! 									File.createTempFile(tempFile, ".png", dir);
  
! 								System.out.println(f.getName());
! 								System.out.println(f.getCanonicalPath());
  
! 								// set it to delete on exit
! 								f.deleteOnExit();
  
! 								EncodeComponent.encode(
! 									EncodeComponent.PNG,
! 									session,
! 									f);
! 								sem.setFileName(f.getName());
! 							} catch (Exception ex) {
! 								System.out.println(ex.getMessage());
! 							}
  
! 						}
  
! 						// send the information
! 						sendIt(parent, sem);
  
! 						sem.release();
! 						sem = null;
  
+ 						break;
+ 					case 1 : // Cancel
+ 						//		      System.out.println("Cancel");
+ 						break;
+ 					case 2 : // Configure SMTP
+ 						configureSMTP(parent);
+ 						//		      System.out.println("Cancel");
+ 						break;
+ 					default :
+ 						break;
+ 				}
+ 			}
+ 		}
+ 	}
  
! 	/**
! 	 * Constructor to send a file
! 	 *
! 	 * @param parent
! 	 * @param session
! 	 */
! 	public SendEMailDialog(Frame parent, Session session, String fileName) {
  
! 		if (!isEMailAvailable()) {
  
! 			JOptionPane.showMessageDialog(parent,
! 				"The Java E-Mail API can not be found or is not installed\n"
! 				+ "Please read e-mail.txt file for installation instructions.",
! 				"Error", JOptionPane.ERROR_MESSAGE, null);
! 		} 
! 		else {
  
! 			this.session = session;
! 			Screen5250 screen = session.getScreen();
  
! 			Object[] message = new Object[1];
! 			message[0] = setupMailPanel(fileName);
! 			String[] options = new String[3];
  
! 			int result = 0;
! 			while (result == 0 || result == 2) {
  
! 				// setup the dialog options
! 				setOptions(options);
! 				result = JOptionPane.showOptionDialog(parent,
! 				// the parent that the dialog blocks
! 				message, // the dialog message array
! 				LangTool.getString("em.titleFileTransfer"),
! 				// the title of the dialog window
! 				JOptionPane.DEFAULT_OPTION, // option type
! 				JOptionPane.PLAIN_MESSAGE, // message type
! 				null, // optional icon, use null to use the default icon
! 				options, // options string array, will be made into buttons//
! 				options[0] // option that should be made into a default button
! 			);
  
! 				switch (result) {
! 					case 0 : // Send it
  
! 						SendEMail sem = new SendEMail();
! 						sem.setConfigFile("SMTPProperties.cfg");
! 						sem.setTo((String) toAddress.getSelectedItem());
! 						sem.setSubject(subject.getText());
! 						if (bodyText.getText().length() > 0)
! 							sem.setMessage(bodyText.getText());
  
! 						if (attachmentName.getText().length() > 0)
! 							sem.setAttachmentName(attachmentName.getText());
  
! 						if (fileName != null && fileName.length() > 0)
! 							sem.setFileName(fileName);
  
! 						// send the information
! 						sendIt(parent, sem);
  
! 						sem.release();
! 						sem = null;
  
! 						break;
! 					case 1 : // Cancel
! 						//		      System.out.println("Cancel");
! 						break;
! 					case 2 : // Configure SMTP
! 						configureSMTP(parent);
! 						//		      System.out.println("Cancel");
! 						break;
! 					default :
! 						break;
! 				}
! 			}
! 		}
! 	}
  
! 	/**
! 	 * Send the e-mail on its way.
! 	 * @param sem
! 	 */
! 	private void sendIt(Frame parent, SendEMail sem) {
  
! 		if (parent == null)
! 			parent = new JFrame();
  
! 		try {
! 			if (sem.send()) {
  
! 				JOptionPane.showMessageDialog(
! 					parent,
! 					LangTool.getString("em.confirmationMessage")
! 						+ " "
! 						+ (String) toAddress.getSelectedItem(),
! 					LangTool.getString("em.titleConfirmation"),
! 					JOptionPane.INFORMATION_MESSAGE);
  
! 				if (session != null) {
! 					config.setProperty(
! 						"emailTo",
! 						getToTokens(
! 							config.getStringProperty("emailTo"),
! 							toAddress));
! 					config.saveSessionProps();
! 					setToCombo(config.getStringProperty("emailTo"), toAddress);
! 				}
! 			}
! 		} catch (IOException ioe) {
! 			System.out.println(ioe.getMessage());
! 		} catch (Exception ex) {
! 			System.out.println(ex.getMessage());
! 		}
! 	}
  
! 	/**
! 	 * Configure the SMTP server information
! 	 *
! 	 * @param parent
! 	 */
! 	private void configureSMTP(Frame parent) {
  
! 		if (parent == null)
! 			parent = new JFrame();
  
! 		SMTPConfig smtp = new SMTPConfig(parent, "", true);
! 		smtp.setVisible(true);
! 		smtp.dispose();
  
! 	}
  
! 	/**
! 	 * Create the main e-mail panel for display
! 	 *
! 	 * @param fileName
! 	 * @return
! 	 */
! 	private JPanel setupMailPanel(String fileName) {
  
! 		JPanel semp = new JPanel();
! 		semp.setLayout(new GridBagLayout());
  
! 		text = new JRadioButton(LangTool.getString("em.text"));
! 		graphic = new JRadioButton(LangTool.getString("em.graphic"));
  
! 		// Group the radio buttons.
! 		ButtonGroup tGroup = new ButtonGroup();
! 		tGroup.add(text);
! 		tGroup.add(graphic);
  
! 		text.setSelected(true);
  
! 		JLabel screenDump = new JLabel(LangTool.getString("em.screendump"));
! 		JLabel tol = new JLabel(LangTool.getString("em.to"));
! 		JLabel subl = new JLabel(LangTool.getString("em.subject"));
! 		JLabel bodyl = new JLabel(LangTool.getString("em.body"));
! 		JLabel fnl = new JLabel(LangTool.getString("em.fileName"));
  
! 		toAddress = new JComboBox();
! 		toAddress.setPreferredSize(new Dimension(175, 25));
! 		toAddress.setEditable(true);
  
! 		subject = new JTextField(30);
! 		bodyText = new JTextArea(6, 30);
! 		JScrollPane bodyScrollPane = new JScrollPane(bodyText);
! 		bodyScrollPane.setHorizontalScrollBarPolicy(
! 			JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
! 		bodyScrollPane.setVerticalScrollBarPolicy(
! 			JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
! 		attachmentName = new JTextField(fileName, 30);
! 
! 		text.addItemListener(new java.awt.event.ItemListener() {
! 			public void itemStateChanged(java.awt.event.ItemEvent e) {
! 				setAttachmentName();
! 			}
! 		});
  
+ 		config = null;
  
! 		if (session != null) {
! 			config = session.getConfiguration();
  
! 			if (config.isPropertyExists("emailTo")) {
! 				setToCombo(config.getStringProperty("emailTo"), toAddress);
! 			}
! 		}
  
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0; gbc.gridy = 0;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(0, 10, 5, 5);
! 		semp.add(screenDump, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 1; gbc.gridy = 0;
! 		gbc.anchor = GridBagConstraints.CENTER;
! 		gbc.insets = new Insets(0, 5, 5, 5);
! 		semp.add(text, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 2; gbc.gridy = 0;
! 		gbc.anchor = GridBagConstraints.CENTER;
! 		gbc.insets = new Insets(0, 5, 5, 10);
! 		semp.add(graphic, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0; gbc.gridy = 1;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(5, 10, 5, 5);						
! 		semp.add(tol, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 1; gbc.gridy = 1;
! 		gbc.gridwidth = 2;
! 		gbc.fill = GridBagConstraints.HORIZONTAL;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(5, 5, 5, 10);		
! 		semp.add(toAddress, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0; gbc.gridy = 2;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(5, 10, 5, 5);		
! 		semp.add(subl, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 1; gbc.gridy = 2;
! 		gbc.gridwidth = 2;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(5, 5, 5, 10);		
! 		semp.add(subject, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0; gbc.gridy = 4;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(5, 10, 5, 5);		
! 		semp.add(bodyl, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 1; gbc.gridy = 3;
! 		gbc.gridwidth = 2; gbc.gridheight = 3;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(5, 5, 5, 10);		
! 		semp.add(bodyScrollPane, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 0; gbc.gridy = 6;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(5, 10, 5, 5);		
! 		semp.add(fnl, gbc);
! 		gbc = new GridBagConstraints();
! 		gbc.gridx = 1; gbc.gridy = 6;
! 		gbc.gridwidth = 2;
! 		gbc.anchor = GridBagConstraints.WEST;
! 		gbc.insets = new Insets(5, 5, 5, 10);		
! 		semp.add(attachmentName, gbc);
  
+ 		return semp;
  
+ 	}
  
! 	private void setAttachmentName() {
  
! 		if (text.isSelected()) {
! 			attachmentName.setText("tn5250j.txt");
  
! 		} else {
  
! 			attachmentName.setText("tn5250j.png");
  
! 		}
! 	}
  
! 	private void setOptions(String[] options) {
  
! 		options[0] = LangTool.getString("em.optSendLabel");
! 		options[1] = LangTool.getString("em.optCancelLabel");
  
! 		File smtp = new File("SMTPProperties.cfg");
  
! 		if (smtp.exists())
! 			options[2] = LangTool.getString("em.optEditLabel");
! 		else
! 			options[2] = LangTool.getString("em.optConfigureLabel");
  
! 	}
  
! 	/**
! 	 * Set the combo box items to the string token from to.
! 	 * The separator is a '|' character.
! 	 *
! 	 * @param to
! 	 * @param boxen
! 	 */
! 	private void setToCombo(String to, JComboBox boxen) {
  
! 		StringTokenizer tokenizer = new StringTokenizer(to, "|");
  
! 		boxen.removeAllItems();
! 
! 		while (tokenizer.hasMoreTokens()) {
! 			boxen.addItem(tokenizer.nextToken());
! 		}
! 	}
! 
! 	/**
! 	 * Creates string of tokens from the combobox items.
! 	 * The separator is a '|' character.  It does not save duplicate items.
! 	 *
! 	 * @param to
! 	 * @param boxen
! 	 * @return
! 	 */
! 	private String getToTokens(String to, JComboBox boxen) {
! 
! 		StringBuffer sb = new StringBuffer();
! 		String selected = (String) boxen.getSelectedItem();
! 
! 		sb.append(selected + '|');
! 
! 		int c = boxen.getItemCount();
! 
! 		for (int x = 0; x < c; x++) {
! 			if (!selected.equals((String) boxen.getItemAt(x)))
! 				sb.append((String) boxen.getItemAt(x) + '|');
! 		}
! 		return sb.toString();
! 	}
! 
! 	/**
! 	 * Checks to make sure that the e-mail api's are available
! 	 *
! 	 * @return whether or not the e-mail api's are available or not.
! 	 */
! 	private boolean isEMailAvailable() {
! 
! 		try {
! 			Class.forName("javax.mail.Message");
! 			return true;
! 		} catch (Exception ex) {
! 			System.out.println(" not there " + ex.getMessage());
! 			return false;
! 		}
! 
! 	}
  
  }




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.