root/www.mail/JavaPopWeb/src/jp/ac/nime/computer/mailsim/SendMailDialog.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. SendMailDialog
  2. setData
  3. makeLayout
  4. actionPerformed

package jp.ac.nime.computer.mailsim;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import jp.ac.nime.computer.*;

/**
 * MAILシミュレータ メール送信ダイアログ
 * 
 * @version 1.00 2003/03/31
 * @author Toshikazu Matsumoto Avion Corp.
 */
public class SendMailDialog extends JDialog implements ActionListener
{
        public final static int DIALOG_MODE_SEND = 1;
        public final static int DIALOG_MODE_VIEW = 2;
        
        private MailSim         m_Applet;       //メインアプレットクラス
        private PcItem m_Item;                  //呼び出しもとPCオブジェクト
        private JTextField m_tfTo;              //TOテキストフィールド
        private JTextField m_tfCc;              //CCテキストフィールド
        private JTextField m_tfBcc;             //BCCテキストフィールド
        private JTextArea m_taData;             //メール本文入力テキストエリア
        
        private JButton m_btSend;               //送信ボタン
        private JButton m_btJisSend;    //JISに変換して送信ボタン
        private JButton m_btCancel;             //キャンセルボタン
        
        private int             m_nMode;                //メール送信か閲覧かのモード
        
        /**
         * クラスコンストラクタ
         * @param root 親フレームクラス
         * @param applet メインアプレットクラス
         * @param item 呼び出し元PCオブジェクトクラス
         * @param nMode 送信か閲覧かのモード
         */     
        public SendMailDialog(Frame root,MailSim applet,PcItem item,int nMode)
        {
                super(root,"メール送信");
                this.m_Applet=applet;
                this.m_Item=item;
                this.m_nMode=nMode;
                
                this.m_tfTo=new JTextField(30);
                this.m_tfCc=new JTextField(30);
                this.m_tfBcc=new JTextField(30);
                this.m_taData=new JTextArea();
                this.m_taData.setRows(10);
                
                if(nMode==DIALOG_MODE_VIEW)
                {
                        this.m_tfTo.setEnabled(false);
                        this.m_tfCc.setEnabled(false);
                        this.m_tfBcc.setEnabled(false);
                        this.m_taData.setEnabled(false);
                }
                
                this.m_btSend=new JButton("送信");
                this.m_btJisSend=new JButton("JISに変換して送信");
                this.m_btCancel=new JButton("キャンセル");
                
                this.m_btSend.addActionListener(this);
                this.m_btJisSend.addActionListener(this);
                
                this.m_btCancel.addActionListener(this);
                
                this.makeLayout();
                this.pack();
                Toolkit tool=Toolkit.getDefaultToolkit();
                Dimension d=tool.getScreenSize();
                
                this.setLocation(new Point((d.width-this.getSize().width)/2,(d.height-this.getSize().height)/2));
                //this.show();
        }
        /**
         * 各フィールドにデータのセット
         * @param objMail セットするメールデータオブジェクト
         */
        public void setData(MailDataObject objMail)
        {
                this.m_tfTo.setText(objMail.getTo());
                this.m_tfCc.setText(objMail.getCc());
                this.m_tfBcc.setText(objMail.getBcc());
                
                
                //if(objMail.isJisEnc()==true)
                //{
                try
                {
                        String sData=new String(objMail.getBody().getBytes("8859_1"),"ISO2022JP");
                        this.m_taData.setText(sData);
                }
                catch(UnsupportedEncodingException e)
                {
                        return;
                }
                //}
                //else
                //{
                //      this.m_taData.setText(objMail.getBody());
                //}
        }
        /**
         * レイアウトの構築
         */
        private void makeLayout()
        {
                Panel pText=new Panel();
                GridBagLayout layout=new GridBagLayout();
                GridBagConstraints c=new GridBagConstraints();
                pText.setLayout(layout);
                
                c.fill = GridBagConstraints.BOTH;
                c.weightx = 1.0;
                c.gridwidth = GridBagConstraints.RELATIVE;
                JLabel lto=new JLabel("TO:");
                layout.setConstraints(lto,c);
                pText.add(lto);
                c.gridwidth = GridBagConstraints.REMAINDER;
                layout.setConstraints(this.m_tfTo, c);
                pText.add(this.m_tfTo);
                
                c.weightx = 0.0;
                c.gridwidth = GridBagConstraints.RELATIVE;
                JLabel lcc=new JLabel("CC:");
                layout.setConstraints(lcc,c);
                pText.add(lcc);
                c.gridwidth = GridBagConstraints.REMAINDER;
                layout.setConstraints(this.m_tfCc, c);
                pText.add(this.m_tfCc);

                c.weightx = 0.0;
                c.gridwidth = GridBagConstraints.RELATIVE;
                JLabel lbcc=new JLabel("BCC:");
                layout.setConstraints(lbcc,c);
                pText.add(lbcc);
                c.gridwidth = GridBagConstraints.REMAINDER;
                layout.setConstraints(this.m_tfBcc, c);
                pText.add(this.m_tfBcc);
                
                Panel pButton=new Panel();
                pButton.setLayout(new FlowLayout(FlowLayout.CENTER));
                pButton.add(this.m_btSend);
                pButton.add(this.m_btJisSend);
                pButton.add(this.m_btCancel);
                                
                this.getContentPane().setLayout(new BorderLayout());
                this.getContentPane().add("North",pText);
                this.getContentPane().add("Center",this.m_taData);
                
                if(this.m_nMode==DIALOG_MODE_SEND)
                {
                        this.getContentPane().add("South",pButton);
                }
        }
        /**
         * 各ボタン押下時のアクション
         */
        public void actionPerformed(ActionEvent evt)
        {
                //送信ボタン押下時
                if(evt.getSource() == this.m_btSend)
                {
                        MailDataObject objMail=new MailDataObject((Component)m_Applet,this.m_Applet.getImageArray(3),this.m_tfTo.getText());
                        objMail.setFrom(this.m_Item.getAccount());
                        objMail.setCc(this.m_tfCc.getText());
                        objMail.setBcc(this.m_tfBcc.getText());
                        objMail.setBody(this.m_taData.getText());
                        objMail.makeHeader();
                        objMail.setMoveObject((MachineItem)this.m_Item,this.m_Item.getTarget(0));
                        this.m_Applet.addPacket(objMail);
                        objMail.startThread();
                        this.dispose();
                }
                //JISに変換して送信ボタン押下時
                else if(evt.getSource() == this.m_btJisSend)
                {
                        MailDataObject objMail=new MailDataObject((Component)m_Applet,this.m_Applet.getImageArray(3),this.m_tfTo.getText());
                        objMail.setFrom(this.m_Item.getAccount());
                        objMail.setCc(this.m_tfCc.getText());
                        objMail.setBcc(this.m_tfBcc.getText());
                        try
                        {
                                String sBody=new String(this.m_taData.getText().getBytes("ISO2022JP"),"8859_1");
                                objMail.setBody(sBody);
                        }
                        catch(UnsupportedEncodingException e)
                        {
                                objMail.setBody(this.m_taData.getText());
                        }
                        objMail.setJisEnc(true);
                        objMail.makeHeader();
                        objMail.setMoveObject((MachineItem)this.m_Item,this.m_Item.getTarget(0));
                        this.m_Applet.addPacket(objMail);
                        objMail.startThread();
                        this.dispose();
                }
                //キャンセルボタン押下時
                else if(evt.getSource() == this.m_btCancel)
                {
                        this.dispose();
                }
        }
}

/* [<][>][^][v][top][bottom][index][help] */