www.pudn.com > MUMail.rar > MailPanel.java
/* * Copyright (C) 1998-2001 Mark Tuempfel and Uli Luckas * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * To reach the Authors you can send E-Mail to: * Mark Tuempfel* Uli Luckas * */ package mumail.gui; import java.awt.*; import java.awt.event.*; import java.beans.*; import java.io.IOException; import mumail.mime.*; import mumail.net.*; public class MailPanel extends Panel implements ItemListener, ActionListener, PropertyChangeListener, MailListener{ MyList HeaderList = new MyList(mumail.MUMail.headerListRows, false); ButtonPanel MyButtonPanel; Panel MyBodyPanel = new Panel(); //DownloadStatusPanel downloadStatusPanel = new DownloadStatusPanel(); StatusPanel statusPanel = new StatusPanel(); MailQueue mq; public mimeMail mo; private int downloadInProgress = -1; ActionListener actionListener; Button cancelDownload = new Button("Cancel"); boolean downloading = false; public MailPanel(MailQueue mq, ActionListener listener) throws IOException { super(); this.mq = mq; mq.addPropertyChangeListener(this); mq.addPropertyChangeListener(statusPanel); MyButtonPanel = new ButtonPanel(listener); MyButtonPanel.setConnected(mq.isConnected()); MyBodyPanel.setLayout(new BorderLayout(0,0)); GridBagLayout gb = new GridBagLayout(); GridBagConstraints gc = new GridBagConstraints(); setLayout(gb); gc.fill=GridBagConstraints.HORIZONTAL; gc.insets=new Insets(0,0,0,0); gc.ipadx=0; gc.ipady=0; gc.anchor=GridBagConstraints.CENTER; gc.weightx=0.0; gc.weighty=0.0; gc.gridwidth=GridBagConstraints.REMAINDER; gc.gridheight=1; gb.setConstraints(HeaderList, gc); add(HeaderList); gb.setConstraints(MyButtonPanel, gc); add(MyButtonPanel); gc.fill=GridBagConstraints.BOTH; gc.weighty=1.0; gc.weightx=1.0; gb.setConstraints(MyBodyPanel, gc); add(MyBodyPanel); gc.gridheight=GridBagConstraints.REMAINDER; gc.fill=GridBagConstraints.HORIZONTAL; gc.weighty=0.0; gc.weightx=1.0; gb.setConstraints(statusPanel, gc); add(statusPanel); this.addActionListener(listener); HeaderList.addItemListener(this); MyButtonPanel.DeleteButton.addActionListener(this); MyButtonPanel.CheckNewButton.addActionListener(this); MyButtonPanel.CloseButton.addActionListener(this); //setBackground(Color.red); cancelDownload.setActionCommand("I18N_CANCEL_DOWNLOAD"); cancelDownload.addActionListener(this); } public void propertyChange(PropertyChangeEvent propertyChangeEvent) { //System.out.print("Got event: "); if (propertyChangeEvent.getSource() == mq) { if (propertyChangeEvent.getPropertyName().equals(mq.pn_Connected)) { MyButtonPanel.setConnected(mq.isConnected()); if (mq.isConnected()) { System.out.println("Connected"); try { DisplayHeaders(); } catch (IOException e1) { e1.printStackTrace(); } } else { System.out.println("Disconnected"); } } } } public synchronized void setDownloading(boolean isDownloading) { if (downloading != isDownloading) { if (isDownloading) { MyButtonPanel.getCustomContainer().add(cancelDownload); } else { MyButtonPanel.getCustomContainer().remove(cancelDownload); } HeaderList.setEnabled(!isDownloading); downloading = isDownloading; } } public void DisplayHeaders() throws IOException { int i; mimeHeader mh; String out; String fromout; String subjectout; int fromwidth=0, subjectwidth=0; int wasSelected = HeaderList.getSelectedIndex(); int messageCount = mq.getCount(); if(HeaderList.getItemCount()!=0){ //System.out.println("clearing list"); HeaderList.removeAll(); } FontMetrics fm = HeaderList.getFontMetrics(HeaderList.getFont()); if(fm!=null){ for(i = 0; i < messageCount; i++){ fromwidth=Math.max(fromwidth,fm.stringWidth(mq.getHeader(i).getFrom())); subjectwidth=Math.max(subjectwidth,fm.stringWidth(mq.getHeader(i).getSubject())); } } for(i=0; i < messageCount; i++){ mh = mq.getHeader(i); fromout = mh.getFrom(); subjectout = mh.getSubject(); if(fm!=null){ while(fm.stringWidth(fromout)