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 net.sourceforge.mflow;
   33   
   34   /**
   35    * A JPanel for viewing Msgs
   36    *
   37    * @author <a href="david@carr.name">David Carr</a>
   38    * @todo make it a JDialog?
   39    */
   40   public class MsgViewer extends JPanel {
   41   	/**
   42   	 * Private reference to the Msg
   43   	 */
   44   	private Msg mMsg;
   45   	/**
   46   	 * Private reference to the From box
   47   	 */
   48   	private JTextField mFrom;
   49   	/**
   50   	 * Private reference to the To box
   51   	 */
   52   	private JTextField mTo;
   53   	/**
   54   	 * Private reference to the Subject box
   55   	 */
   56   	private JTextField mSubject;
   57   	/**
   58   	 * Private reference to the Content box
   59   	 */
   60   	private JTextArea mContent;
   61   	/**
   62   	 * Private reference to the Send button
   63   	 */
   64   	private JButton mSend;
   65   	/**
   66   	 * Private reference to listeners collection
   67   	 */
   68   	private Vector mListeners = new Vector();
   69   
   70   	/**
   71   	 * Constructor to view the specified Msg
   72   	 *
   73   	 * @param m the Msg
   74   	 */
   75   	public MsgViewer(Msg m) {
   76   		super(new BorderLayout());
   77   		JPanel labels = new JPanel(new GridLayout(0, 1));
   78   		JPanel headers = new JPanel(new GridLayout(0, 1));
   79   		mMsg = m;
   80   		JPanel headerPane = new JPanel();
   81   		headerPane.add(labels);
   82   		headerPane.add(headers);
   83   		JPanel contentPane = new JPanel(new BorderLayout());
   84   		add(headerPane, BorderLayout.NORTH);
   85   		add(contentPane, BorderLayout.CENTER);
   86   		labels.add(new JLabel("From:"));
   87   		Contact fromContact = m.getFrom();
   88   		if(fromContact != null) {
   89   			mFrom = new JTextField(fromContact.getName());
   90   		} else {
   91   			mFrom = new JTextField();
   92   		}
   93   		mFrom.setEditable(false);
   94   		mFrom.setColumns(20);
   95   		headers.add(mFrom);
   96   		labels.add(new JLabel("To:"));
   97   		ContactMethod[] recips = m.getRecipients();
   98   		String recipsString = "";
   99   		boolean isFirst = true;
  100   		for(int i=0; i<recips.length; i++) {
  101   			if(isFirst) {
  102   				recipsString = recipsString + recips[i].idString();
  103   				isFirst = false;
  104   			} else {
  105   				recipsString = recipsString + "; " + recips[i].idString();
  106   			}
  107   		}
  108   		mTo = new JTextField(recipsString);
  109   		mTo.setColumns(20);
  110   		mTo.setEditable(false);
  111   		headers.add(mTo);
  112   		labels.add(new JLabel("Subject:"));
  113   		mSubject = new JTextField(m.getSubject());
  114   		mSubject.setColumns(20);
  115   		mSubject.setEditable(false);
  116   		headers.add(mSubject);
  117   		mContent = new JTextArea((String)m.getContent());
  118   		mContent.setColumns(20);
  119   		mContent.setRows(15);
  120   		mContent.setEditable(false);
  121   		contentPane.add(new JScrollPane(mContent), BorderLayout.CENTER);
  122   	}
  123   }

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