⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 composemail.java

📁 create the email in the server
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package za.co.halo.SecureCommunications.gui.client2;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.LayoutManager;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.net.MalformedURLException;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.border.BevelBorder;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
import za.co.halo.SecureCommunications.AccountOfClient;
import za.co.halo.SecureCommunications.ClientAccountManager;
import za.co.halo.SecureCommunications.Email;
import za.co.halo.SecureCommunications.client.contact.Contact;
import za.co.halo.SecureCommunications.client.contact.ContactPanel;
import za.co.halo.SecureCommunications.client.contact.InsertContact;
import za.co.halo.SecureCommunications.network.ClientGroupReceiver;
import za.co.halo.SecureCommunications.util.HTMLPane;

public class ComposeMail extends javax.swing.JPanel {
	
	private SendActionListener sendListener = null;
	private JButton ToButton;
	private ViewEmailEditorPane viewEmailPane;
	private JToolBar textTypeToolbar;
	private JRadioButton highPriorityButton;
	private JRadioButton normalPriotityButton;
	private JRadioButton lowPriotityButton;
	private JToolBar priorityToolBar;
	private JButton addressButton;
	private JButton attachButton;
	private JToolBar jToolBar4;
	private JTextField toTextArea;
	private JTextField subjectTextArea;
	private JTextField ccTextF;
	private JButton ccButton;
	private JLabel subjectLabel;
	private JButton sendButton;
	private JToolBar newMailToolbar;
	private ButtonGroup group;
	private Email theEmail;
	private ContactPanel contactPanel;
	private GeneralPanel generalPanel;
	private Client client;
	private int h = 600;
	private int w = 300;
	private ClientAccountManager accountsManager;
	private ClientGroupReceiver clientgroup;
	private JButton Groupbutton;
	private Window parent;
	private JButton ToGroupButton;

	enum Type
	{
		NEW,
		FORWARD,
		REPLY
	}
	
	public static void main(String[] args) {
		ComposeMail inst = new ComposeMail(null);
		inst.setVisible(true);
		
	}
	
	public ComposeMail(Window parent) {
		super();
		initGUI();
	}
	public ComposeMail(Window parent, Email e,Client client,ClientAccountManager accountsManager) {
		super();
		this.accountsManager = accountsManager;
		theEmail = e;
		String server = "";
		if (accountsManager.getDefaultAccount() == null)
		{
			clientgroup = null;
		}
		else if(accountsManager.getDefaultAccount().getType() == AccountOfClient.Types.RMI)
		{
			server = accountsManager.getDefaultAccount().getRmiServer();
			clientgroup = new ClientGroupReceiver(server);
		}
		else if(accountsManager.getDefaultAccount().getType() == AccountOfClient.Types.POPSMTP)
		{
			server = accountsManager.getDefaultAccount().getPop3Server();
			clientgroup = new ClientGroupReceiver(server);
		}
		this.parent=parent;
		this.client = client;
		initGUI();
	
	}
	public void setEmail(Email e)
	{
		theEmail = e;
		
	}
	public ComposeMail(Window parent, Email e, Type t,Client client) {
		super();
		this.parent = parent;
		this.client = client;
	 	if (t == Type.FORWARD)
		{
			 String forwardmessage = "";
			    String from,sent,subject;
			    subject = e.getSubject();
			    sent = e.getTime();
				Vector<String> to;
			    to = e.getCC();
			    from = e.getSender();
			    forwardmessage = "------- Original Message ----------" +"<br>";
			    forwardmessage += "<b>From :</b>" + from + "<br>";
			    forwardmessage += "<b>To : </b>";
			    for (String s : e.getCC())
			    {
			    	 forwardmessage += s + " ,";
			    }
			    forwardmessage +="<br>";
			    forwardmessage += "<b>sent: </b>"+sent+ "<br>"; 
			    forwardmessage += "<b>Subject :</b>" + subject+ "<br>";
			    forwardmessage += "<b>Message :</b>";
			    for (String l : e.getMessage())
			    {
			    	 forwardmessage += l;
			    	 forwardmessage+="<br>";
			    }
			    forwardmessage+="<br>";
			    
			    /* ===========================
			     *       Forward 
			     * 
			    ============================== */
			    
			try {
				this.removeAll();
				
				{
					group = new ButtonGroup();
					LayoutManager jPanel1Layout = null;
					this.setLayout(jPanel1Layout);
					{
						newMailToolbar = new JToolBar();
						this.add(newMailToolbar);
						newMailToolbar.setPreferredSize(new java.awt.Dimension(137, 95));
						newMailToolbar.setBounds(1, 3,200, 30);
						{
							sendButton = new JButton(new SendEmailAction());
							newMailToolbar.add(sendButton);
							
						}
						{
							attachButton = new JButton();
							newMailToolbar.add(attachButton);
							attachButton.setText("Attach");
						}
						{
							addressButton = new JButton(new OpenAddressBookAction());
							newMailToolbar.add(addressButton);
							addressButton.setText("Address Book");
						}
					}
					{
						ccTextF = new JTextField();
						this.add(ccTextF);
						ccTextF.setBackground(new Color(21,118, 146));
						ccTextF.setForeground(Color.WHITE);
						ccTextF.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						ccTextF.setBounds(200,110,w-90,23);
						
					}
					{
						toTextArea = new JTextField();
						this.add(toTextArea);
						toTextArea.setBackground(new Color(21,118, 146));
						toTextArea.setForeground(Color.WHITE);
						toTextArea.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						toTextArea.setBounds(200,68,w-90,23);
						toTextArea.setText("sdfsdfsdf");
						toTextArea.setPreferredSize(new java.awt.Dimension(16, 20));

					}
		
					{
						ToGroupButton = new JButton(new AddGroupAction(toTextArea));
						this.add(ToGroupButton);
						ToGroupButton.setText("Group");
						ToGroupButton.setBounds(60, 68, 68, 23);
					}
					{
						ToButton = new JButton(new AddContactAction(toTextArea));
						this.add(ToButton);
						ToButton.setText("To");
						ToButton.setBounds(3, 68, 57, 23);
					}
					{
						ToGroupButton = new JButton(new AddGroupAction(toTextArea));
						this.add(ToGroupButton);
						ToGroupButton.setText("Group");
						ToGroupButton.setBounds(60, 97, 68, 23);
					}
					{
						
						ccButton = new JButton(new AddContactAction(ccTextF));
						this.add(ccButton);
						ccButton.setText("Cc");
						ccButton.setBounds(3, 97, 57, 23);
					}
					{
						viewEmailPane = new ViewEmailEditorPane();
						this.add(viewEmailPane);
						viewEmailPane.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						viewEmailPane.setBounds(3, 160, w-20,h -200);
						viewEmailPane.setText("<p>" + forwardmessage+"</p>");
					
						
					}
								{
						priorityToolBar = new JToolBar();
						this.add(priorityToolBar);
						
							
						priorityToolBar.setBounds(1, 36, 326, 30);
						{
							lowPriotityButton = new JRadioButton();
							priorityToolBar.add(lowPriotityButton);
						
							lowPriotityButton.setText("Low Priority");
						}
						
					    group.add(lowPriotityButton);
						{
							normalPriotityButton = new JRadioButton();
							priorityToolBar.add(normalPriotityButton);
							normalPriotityButton.setText("Normal Priority");
						}
						group.add(normalPriotityButton);
						{
							highPriorityButton = new JRadioButton();
							priorityToolBar.add(highPriorityButton);
							highPriorityButton.setText("High Priority");
						}
						group.add(highPriorityButton);
					}
					{
						textTypeToolbar = new JToolBar();
						this.add(textTypeToolbar);
						textTypeToolbar.setBounds(328, 36, 105, 30);
						
					}
					
					
					{
						subjectLabel = new JLabel("Subject  ");
						this.add(subjectLabel);
						
						subjectLabel.setBounds(15, 125, 61, 23);
					}
					
					{
						subjectTextArea = new JTextField();
						this.add(subjectTextArea);
						subjectTextArea.setBackground(new Color(21,118, 146));
						subjectTextArea.setForeground(Color.WHITE);
						subjectTextArea.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						String subject2 ="Fw: " + subject;  
						subjectTextArea.setText(subject2);
						subjectTextArea.setBounds(70, 125,w-90,23);
					}
					
				}
			
				
			} catch (Exception ep) {
				ep.printStackTrace();
			}
		}
		else if (t == Type.REPLY)
		{
			String replymessage = "";
		    String from,sent,subject;
		    subject = e.getSubject();
		    sent = e.getTime();
			Vector<String> to;
		    to = e.getCC();
		    from = e.getSender();
		    replymessage +="<br>";
		    replymessage +="<br>";
		    replymessage +="<br>";
		    replymessage += "------- Original Message ----------" +"<br>";
		    replymessage += "<b>From :</b>" + from + "<br>";
		    replymessage += "<b>To : </b>";
		    for (String s : e.getCC())
		    {
		    	replymessage += s + " ,";
		    }
		    replymessage +="<br>";
		    replymessage += "<b>sent:</b>"+sent+ "<br>"; 
		    replymessage += "<b>Subject :</b>" + subject+ "<br>";
		    replymessage += "<b>Message :</b>";
		    for (String l : e.getMessage())
		    {
		    	replymessage += l;
		    	replymessage+="<br>";
		    }
			
			try {
				this.removeAll();
				
				{
					group = new ButtonGroup();
					LayoutManager jPanel1Layout = null;
					this.setLayout(jPanel1Layout);
					{
						newMailToolbar = new JToolBar();
						this.add(newMailToolbar);
						newMailToolbar.setPreferredSize(new java.awt.Dimension(137, 95));
						newMailToolbar.setBounds(1, 3,200, 30);
						{
							sendButton = new JButton(new SendEmailAction());
							newMailToolbar.add(sendButton);
							
						}
						{
							attachButton = new JButton();
							newMailToolbar.add(attachButton);
							attachButton.setText("Attach");
						}
						{
							addressButton = new JButton(new OpenAddressBookAction());
							newMailToolbar.add(addressButton);
							addressButton.setText("Address Book");
						}
					}
					{
						viewEmailPane = new ViewEmailEditorPane();
						this.add(viewEmailPane);
						viewEmailPane.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						viewEmailPane.setBounds(3, 160, w-20,h -200);
						viewEmailPane.setText("<p>" + replymessage+"</p>");
						
						
					}
					
					
					
					{
						priorityToolBar = new JToolBar();
						this.add(priorityToolBar);
						
					
						
						priorityToolBar.setBounds(1, 36, 326, 30);
						{
							lowPriotityButton = new JRadioButton();
							priorityToolBar.add(lowPriotityButton);
							lowPriotityButton.setText("Low Priority");
						}
						
					    group.add(lowPriotityButton);
						{
							normalPriotityButton = new JRadioButton();
							priorityToolBar.add(normalPriotityButton);
							normalPriotityButton.setText("Normal Priority");
						}
						group.add(normalPriotityButton);
						{
							highPriorityButton = new JRadioButton();
							priorityToolBar.add(highPriorityButton);
							highPriorityButton.setText("High Priority");
						}
						group.add(highPriorityButton);
					}
					{
						textTypeToolbar = new JToolBar();
						this.add(textTypeToolbar);
						textTypeToolbar.setBounds(328, 36, 105, 30);
									
					}
					{
						ccTextF = new JTextField();
						this.add(ccTextF);
						ccTextF.setBackground(new Color(21,118, 146));
						ccTextF.setForeground(Color.WHITE);
						ccTextF.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						ccTextF.setBounds(70, 97,w-90,23);
						
					}
					{
						String replyto = ""+ from;
						toTextArea = new JTextField();
						this.add(toTextArea);
						toTextArea.setBackground(new Color(21,118, 146));
						toTextArea.setForeground(Color.WHITE);
						toTextArea.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						toTextArea.setText(from);
						toTextArea.setBounds(70, 68,w-90,23);
					}
					{
						ToButton = new JButton(new AddContactAction(toTextArea));
						this.add(ToButton);
						ToButton.setText("To...");
						ToButton.setEnabled(false);
						ToButton.setBounds(3, 68, 57, 23);
					}
					{
						ToGroupButton = new JButton(new AddGroupAction(toTextArea));
						this.add(ToGroupButton);
						ToGroupButton.setText("Group");
						ToGroupButton.setBounds(60, 68, 68, 23);
					}
					{
						ToGroupButton = new JButton(new AddGroupAction(ccTextF));
						this.add(ToGroupButton);
						ToGroupButton.setText("Group");
						ToGroupButton.setBounds(60, 97, 68, 23);
					}
					{
						ccButton = new JButton(new AddContactAction(ccTextF));
						this.add(ccButton);
						ccButton.setText("Cc");
						ccButton.setBounds(3, 97, 57, 23);
					}
					{
						subjectLabel = new JLabel("Subject  ");
						this.add(subjectLabel);
						
						subjectLabel.setBounds(15, 125, 61, 23);
					}
					
					{
						subjectTextArea = new JTextField();
						this.add(subjectTextArea);
						subjectTextArea.setBackground(new Color(21,118, 146));
						subjectTextArea.setForeground(Color.WHITE);
						subjectTextArea.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						String subject2 ="Re: " + subject;  
						subjectTextArea.setText(subject2);
						subjectTextArea.setBounds(70, 125,w-90,23);
					}
				}
			
				
			} catch (Exception ep) {
				ep.printStackTrace();
			}
		}
		else if (t == Type.NEW)
		{
			try {
				this.removeAll();
				
				{
					group = new ButtonGroup();
					LayoutManager jPanel1Layout = null;
					this.setLayout(jPanel1Layout);
					{
						newMailToolbar = new JToolBar();
						this.add(newMailToolbar);
						newMailToolbar.setPreferredSize(new java.awt.Dimension(137, 95));
						newMailToolbar.setBounds(1, 3,200, 30);
						{
							sendButton = new JButton(new SendEmailAction());
							newMailToolbar.add(sendButton);
							
						}
						{
							attachButton = new JButton();
							newMailToolbar.add(attachButton);
							attachButton.setText("Attach");
						}
						{
							addressButton = new JButton(new OpenAddressBookAction());
							newMailToolbar.add(addressButton);
							addressButton.setText("Address Book");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -