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

📄 composemail.java

📁 create the email in the server
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						}
					}
					{
						viewEmailPane = new ViewEmailEditorPane();
						this.add(viewEmailPane);
						viewEmailPane.setBorder(BorderFactory.createBevelBorder(
							BevelBorder.LOWERED,
							null,
							null,
							null,
							null));
						viewEmailPane.setBounds(3, 160, w-20,h -200);
											
					}
					{
						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);
					}
					{
						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);
						
					}
					{
						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(70, 68,w-90,23);
					}
					{
						textTypeToolbar = new JToolBar();
						this.add(textTypeToolbar);
						textTypeToolbar.setBounds(328, 36, 105, 30);
						
					}
					{
						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, 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));
						subjectTextArea.setBounds(70, 125,w-90,23);
					}
						
				}
			
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}
	
	private void initGUI() {
		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);
						sendButton.setText("Send");
					}
					{
						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);
									
				}
				{
					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);
				}
				{
					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);
					
				}
				{
					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(70, 68,w-90,23);
				}
				{
					textTypeToolbar = new JToolBar();
					this.add(textTypeToolbar);
					textTypeToolbar.setBounds(328, 36, 105, 30);
					
				}
				{
					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, 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));
					subjectTextArea.setBounds(70, 125,w-90,23);
				}
				{
					jToolBar4 = new JToolBar();
					this.add(jToolBar4);
				}	
			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void changed()
	{
		viewEmailPane.setBounds(3, 160, w-20,h-300);
		toTextArea.setBounds(130, 68,w-150,23);
		subjectTextArea.setBounds(130, 125,w-150,23);
		ccTextF.setBounds(130, 97,w-150,23);
		doLayout();
	}
	
	public void resize(int width, int height)
	{
		this.w = width;
		this.h = height;
		changed();
	}
	
	class ViewEmailEditorPane extends JEditorPane
	{
		public ViewEmailEditorPane()
		{
			
			HTMLEditorKit kit = new HTMLEditorKit();
            StyleSheet style = new StyleSheet();
            try {
           	 File f = new File("emailstylesheet.css");
           	 
				style.importStyleSheet(f.toURL());
			      } 
            catch (MalformedURLException e1) 
            {
				e1.printStackTrace();
			 }
            kit.setStyleSheet(style);
            setEditorKit(kit);

		}
		
		public void setText(Email e)
		{
            String message = "<html>\n<body>";
            message+="<h1><em>"+e.getSubject()+"</em></h1>\n";
            message+="<h2><b> From : </b>"+e.getSender()+"</h2>\n";
            message+="<h3>Priority Medium</h3>";
            message+= "<h4><b>To : </b>";
            for (String s : e.getReceiver())
            {
           	 message += "<a href='mailto:"+s+"'>"+s+"</a>; ";
            }
            message+= "</h4>";
            message+= "<h5><b>Cc : </b> ";
            for (String s : e.getCC())
            {
           	 message += "<a href='mailto:"+s+"'>"+s+"</a>; ";
            }
            message+= "</h5>";
            message+="<hr>";
            String message2="";
            for (String s : e.getMessage())
            {
           	 message2 += s;
            }
            message+= "<h1>Message </h1><br><h6>"+message2+"</h6>";
            message+="</body></html>";
            setEditable(false);
            if (e.getPriority() == Email.PRIORITY.LOW)
            	lowPriotityButton.setSelected(true);
            else if (e.getPriority() == Email.PRIORITY.MEDIUM)
            	normalPriotityButton.setSelected(true);
            else if (e.getPriority() == Email.PRIORITY.HIGH)
            	highPriorityButton.setSelected(true);
            setText(message);
       }
	}

	class OpenAddressBookAction extends AbstractAction {
		OpenAddressBookAction() {
			super("Open AddressBook");
		}

		public void actionPerformed(ActionEvent arg0) {
			generalPanel = new GeneralPanel(GeneralPanel.Images.NEW_EMAIL);
			contactPanel = new ContactPanel();
			generalPanel.add(contactPanel, BorderLayout.CENTER);
			JDialog dialog = new JDialog();
			dialog.addComponentListener(client.new DialogListener());
			dialog.setLayout(new BorderLayout());
			dialog.add(generalPanel, BorderLayout.CENTER);
			dialog.setSize(600, 550);
			contactPanel.setSize(dialog.getSize().width,dialog.getSize().height);
			dialog.setTitle("AddressBook ");
			dialog.setVisible(true);
		}
	}

	public class SendEmailAction extends AbstractAction
	{
		SendEmailAction()
		{
			super("Send");
		}

		public void actionPerformed(ActionEvent e) {
			System.out.println("Sending email:"+getEmail());
			if (sendListener != null)
				sendListener.send(getEmail());
			if (parent != null)
				parent.dispose();
		}

	}
	
	public class AddGroupAction extends AbstractAction
	{
		private JTextField textfield;
		AddGroupAction(JTextField textfield)
		{
			super("Add Group");
			this.textfield = textfield;
		}

		public void actionPerformed(ActionEvent e) {
			if (clientgroup == null)
			{
				JOptionPane.showMessageDialog(null,"Could not get a list from server.","No server specified",JOptionPane.ERROR_MESSAGE);
				return;
			}
			clientgroup.connect();
			GroupContainerFrame chooseGroups = new GroupContainerFrame(clientgroup.getGroups(),textfield);
		}
	}
	
	public class AddContactAction extends AbstractAction
	{
		private JTextField textfield;
		AddContactAction(JTextField textfield)
		{
			super("Add Contact");
			this.textfield = textfield;
		}

		public void actionPerformed(ActionEvent e) {
			Contact contact = new Contact();
			contact.load();
			InsertContact list = new InsertContact(contact);
			list.setTextField(textfield);
			list.ShowDialog();
		}

	}

	
	public void setSendActionListener(SendActionListener l)
	{
		sendListener = l;
	}
	
	public Email getEmail()
	{
		String subject = subjectTextArea.getText();
		String sender = "";
		String to = toTextArea.getText();
		Vector<String> to2 = new Vector<String>(10);
		StringTokenizer tokenizer = new StringTokenizer(to,";");
		while (tokenizer.hasMoreTokens())
			to2.addElement(tokenizer.nextToken().trim());
		String message = viewEmailPane.getText();
		Vector<String> message2 = new Vector<String>(10);
		StringTokenizer tokenizer2 = new StringTokenizer(message,"\n");
		while (tokenizer2.hasMoreTokens())
			message2.addElement(tokenizer2.nextToken());
		Vector<String> bccs = new Vector<String>();
		Vector<String> ccs = new Vector<String>();
		String time = Email.getTodayDate();//wed, 17 aug 2005 hh:mm:ss +0200 <SAST>
		Email e = new Email(subject, sender, to2, bccs, ccs, sender, message2, time, "");
		if (lowPriotityButton.isSelected())
			e.setPriority(Email.PRIORITY.LOW);
		else if (normalPriotityButton.isSelected())
			e.setPriority(Email.PRIORITY.MEDIUM);
		if (highPriorityButton.isSelected())
			e.setPriority(Email.PRIORITY.HIGH);
		return e;
	}

	
	class PrintAction extends AbstractAction
	{
		public String getText(Email e)
		{
            String message = "<html>\n<body>";
            message+="<h1><em>"+e.getSubject()+"</em></h1>\n";
            message+="<h2><b> From : </b>"+e.getSender()+"</h2>\n";
            message+="<h3>Priority Medium</h3>";
            message+= "<h4><b>To : </b>";
            for (String s : e.getReceiver())
            {
           	 message += "<a href='mailto:"+s+"'>"+s+"</a>; ";
            }
            message+= "</h4>";
            message+= "<h5><b>Cc : </b> ";
            for (String s : e.getCC())
            {
           	 message += "<a href='mailto:"+s+"'>"+s+"</a>; ";
            }
            message+= "</h5>";
            message+="<hr>";
            String message2="";
            for (String s : e.getMessage())
            {
           	 message2 += s;
            }
            message+= "<h1>Message </h1><br><h6>"+message2+"</h6>";
            message+="</body></html>";
            if (e.getPriority() == Email.PRIORITY.LOW)
            	lowPriotityButton.setSelected(true);
            else if (e.getPriority() == Email.PRIORITY.MEDIUM)
            	normalPriotityButton.setSelected(true);
            else if (e.getPriority() == Email.PRIORITY.HIGH)
            	highPriorityButton.setSelected(true);
            return (message);
       }
		
		public void print()
		{
			String s = getText(getEmail());
			HTMLPane pane = new HTMLPane(s);
			
			PrinterJob printerJob = PrinterJob.getPrinterJob();
			PageFormat page = new PageFormat();
			Book book = new Book();
			page = printerJob.pageDialog(page);
			book.append(pane,page);
			printerJob.setPageable(book);
			
			if(printerJob.printDialog() == true)
			{
				try
				{
					printerJob.print();
				}
				catch (PrinterException e)
				{
					e.printStackTrace();
				}
			}
		}

		public void actionPerformed(ActionEvent arg0) {
			print();
		}
	}
	
}

⌨️ 快捷键说明

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