Save This Page
Home » openjdk-7 » net.sourceforge » mflow » ui » [javadoc | source]
    1   /*
    2    *   (C) 2002 David Carr  david@carr.name
    3    *
    4    *   This program is free software; you can redistribute it and/or modify
    5    *   it under the terms of the GNU General Public License as published by
    6    *   the Free Software Foundation; either version 2 of the License, or
    7    *   (at your option) any later version.
    8    *
    9    *   This program is distributed in the hope that it will be useful,
   10    *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   11    *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12    *   GNU General Public License for more details.
   13    *
   14    *   You should have received a copy of the GNU General Public License
   15    *   along with this program; if not, write to the Free Software
   16    *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17    *
   18    */
   19   
   20   package net.sourceforge.mflow.ui;
   21   
   22   import javax.swing.JPanel;
   23   import java.awt.BorderLayout;
   24   import javax.swing.JTextField;
   25   import javax.swing.JTextArea;
   26   import javax.swing.JLabel;
   27   import javax.swing.JScrollPane;
   28   import javax.swing.JButton;
   29   import javax.swing.BoxLayout;
   30   import java.awt.GridLayout;
   31   import java.util.Vector;
   32   import java.awt.event.ActionListener;
   33   import java.awt.event.ActionEvent;
   34   import java.util.Date;
   35   import net.sourceforge.mflow;
   36   import net.sourceforge.mflow.folder;
   37   import javax.swing.JComboBox;
   38   import javax.swing.DefaultListCellRenderer;
   39   import java.awt.Component;
   40   import javax.swing.JList;
   41   
   42   /**
   43    * A JPanel for writing new Msgs
   44    *
   45    * @author <a href="david@carr.name">David Carr</a>
   46    * @todo make it a JDialog?
   47    */
   48   public class MsgWriter extends JPanel {
   49   	/**
   50   	 * Private reference to the Msg
   51   	 */
   52   	private Msg mMsg;
   53   	/**
   54   	 * Private reference to the From box
   55   	 */
   56   	private JTextField mFrom;
   57   	/**
   58   	 * Private reference to the To box
   59   	 */
   60   	private JTextField mTo;
   61   	/**
   62   	 * Private reference to the Subject box
   63   	 */
   64   	private JTextField mSubject;
   65   	/**
   66   	 * Private reference to the Content box
   67   	 */
   68   	private JTextArea mContent;
   69   	/**
   70   	 * Private reference to the Send button
   71   	 */
   72   	private JButton mSend;
   73   	/**
   74   	 * Private reference to listeners collection
   75   	 */
   76   	private Vector mListeners = new Vector();
   77   	/**
   78   	 * Private reference to the SendFolder combobox
   79   	 */
   80   	private JComboBox cmbSendFolder;
   81   
   82   	/**
   83   	 * Default constructor, starts with a blank Msg
   84   	 */
   85   	public MsgWriter() {
   86   		this(new Msg());
   87   	}
   88   
   89   	/**
   90   	 * Constructor starting with the specified Msg
   91   	 *
   92   	 * @param m the Msg
   93   	 */
   94   	public MsgWriter(Msg m) {
   95   		super(new BorderLayout());
   96   		JPanel head = new JPanel(new GridLayout(0, 2));
   97   		mMsg = m;
   98   		JPanel contentPane = new JPanel(new BorderLayout());
   99   		add(head, BorderLayout.NORTH);
  100   		add(contentPane, BorderLayout.CENTER);
  101   		head.add(new JLabel("From:"));
  102   		mFrom = new JTextField(m.getFrom().getName());
  103   		mFrom.setColumns(20);
  104   		mFrom.setEditable(false);
  105   		head.add(mFrom);
  106   		head.add(new JLabel("To:"));
  107   		ContactMethod[] recips = m.getRecipients();
  108   		String recipsString = "";
  109   		boolean isFirst = true;
  110   		for(int i=0; i<recips.length; i++) {
  111   			if(isFirst) {
  112   				recipsString = recipsString + recips[i].idString();
  113   				isFirst = false;
  114   			} else {
  115   				recipsString = recipsString + "; " + recips[i].idString();
  116   			}
  117   		}
  118   		mTo = new JTextField(recipsString);
  119   		mTo.setColumns(20);
  120   		head.add(mTo);
  121   		head.add(new JLabel("Subject:"));
  122   		mSubject = new JTextField(m.getSubject());
  123   		mSubject.setColumns(20);
  124   		head.add(mSubject);
  125   
  126   		head.add(new JLabel("Send using:"));
  127   		SendFolder[] sendFolders = MFlow.getSendFolders();
  128   		cmbSendFolder = new JComboBox(sendFolders);
  129   		cmbSendFolder.setRenderer(new DefaultListCellRenderer() {
  130   			public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  131   				if(value instanceof MsgFlowComponent) {
  132   					MsgFlowComponent c = (MsgFlowComponent)value;
  133   					return super.getListCellRendererComponent(list, c.getName(), index, isSelected, cellHasFocus);
  134   				} else {
  135   					return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  136   				}
  137   			}
  138   		});
  139   		head.add(cmbSendFolder);
  140   
  141   		mContent = new JTextArea((String)m.getContent());
  142   		mContent.setColumns(20);
  143   		mContent.setRows(15);
  144   		contentPane.add(new JScrollPane(mContent), BorderLayout.CENTER);
  145   		mSend = new JButton("Send");
  146   		mSend.addActionListener(new ActionListener() {
  147   			public void actionPerformed(ActionEvent ae) {
  148   				SendFolder f = (SendFolder) cmbSendFolder.getSelectedItem();
  149   				mMsg.setSentDate(new Date());
  150   				mMsg.setSubject(mSubject.getText());
  151   
  152   //				mMsg.setRecipients(		//TODO!!!
  153   				mMsg.setContent(mContent.getText());
  154   				f.sendMsg(mMsg);
  155   				for(int i=0; i<mListeners.size(); i++) {
  156   					ActionListener al = (ActionListener) mListeners.get(i);
  157   					al.actionPerformed(new ActionEvent(MsgWriter.this, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers()));
  158   				}
  159   			}
  160   		});
  161   		JPanel bPanel = new JPanel(new BorderLayout());
  162   		bPanel.add(mSend, BorderLayout.EAST);
  163   		contentPane.add(bPanel, BorderLayout.SOUTH);
  164   
  165   //		labels.add(new ContactComponent(MFlow.getMyContact()));
  166   //		labels.add(new ContactComponent(new Contact("George")));
  167   //		ContactHolder ch = new ContactHolder();
  168   //		ch.addContact(new Contact("Phil"));
  169   //		ch.addContact(new Contact("Jill"));
  170   //		labels.add(ch);
  171   	}
  172   
  173   	/**
  174   	 * Adds a listener
  175   	 *
  176   	 * @param al the listener
  177   	 */
  178   	public void addActionListener(ActionListener al) {
  179   		mListeners.add(al);
  180   	}
  181   
  182   	/**
  183   	 * Removes a listener
  184   	 *
  185   	 * @param al the listener
  186   	 */
  187   	public void removeActionListener(ActionListener al) {
  188   		mListeners.remove(al);
  189   	}
  190   }

Save This Page
Home » openjdk-7 » net.sourceforge » mflow » ui » [javadoc | source]