001         package com.croftsoft.apps.agoracast.c2p;
002    
003         import java.awt.*;
004         import java.awt.event.*;
005         import java.io.*;
006         import javax.swing.*;
007    
008         import com.croftsoft.core.gui.ButtonPanel2;
009         import com.croftsoft.core.gui.LabeledFieldsPanel2;
010         import com.croftsoft.core.lang.NullArgumentException;
011         import com.croftsoft.core.lang.Pair;
012         import com.croftsoft.core.net.news.UsenetMessage;
013         import com.croftsoft.core.text.sml.*;
014         import com.croftsoft.core.util.log.Log;
015         import com.croftsoft.core.util.pubsub.Subscriber;
016    
017         /*********************************************************************
018         *
019         * <p />
020         *
021         * @version
022         *   2002-02-02
023         * @since
024         *   2001-07-25
025         * @author
026         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
027         *********************************************************************/
028    
029         public final class  AgoracastPostPanel
030           extends JPanel
031           implements Subscriber
032         //////////////////////////////////////////////////////////////////////
033         //////////////////////////////////////////////////////////////////////
034         {
035    
036         private final AgoracastMediator       agoracastMediator;
037    
038         private final CardLayout              cardLayout;
039    
040         private final AgoracastPrepPanel      agoracastPrepPanel;
041    
042         private final AgoracastTextPanel      agoracastTextPanel;
043    
044         private final AgoracastConfirmPanel   agoracastConfirmPanel;
045    
046         private final AgoracastSendPanel      agoracastSendPanel;
047    
048         private final AgoracastFieldsPanel    agoracastFieldsPanel;
049    
050         //
051    
052         private UsenetMessage  usenetMessage;
053    
054         //////////////////////////////////////////////////////////////////////
055         //////////////////////////////////////////////////////////////////////
056    
057         public  AgoracastPostPanel ( AgoracastMediator  agoracastMediator )
058         //////////////////////////////////////////////////////////////////////
059         {
060           super ( true ); // isDoubleBuffered
061    
062           NullArgumentException.check (
063             this.agoracastMediator = agoracastMediator );
064    
065           AgoracastLib.setColor ( this, agoracastMediator );
066    
067           agoracastPrepPanel
068             = new AgoracastPrepPanel     ( agoracastMediator, this );
069    
070           agoracastTextPanel
071             = new AgoracastTextPanel     ( agoracastMediator, this );
072    
073           agoracastConfirmPanel
074             = new AgoracastConfirmPanel  ( agoracastMediator, this );
075    
076           agoracastSendPanel
077             = new AgoracastSendPanel     ( agoracastMediator, this );
078    
079           agoracastFieldsPanel
080             = new AgoracastFieldsPanel   ( agoracastMediator, this );
081    
082           cardLayout = new CardLayout ( );
083    
084           setLayout ( cardLayout );
085    
086           add ( agoracastPrepPanel    , "1" );
087    
088           add ( agoracastTextPanel    , "2" );
089    
090           add ( agoracastConfirmPanel , "3" );
091    
092           add ( agoracastSendPanel    , "4" );
093    
094           add ( agoracastFieldsPanel  , "5" );
095         }
096    
097         //////////////////////////////////////////////////////////////////////
098         //////////////////////////////////////////////////////////////////////
099    
100         public void  cancel ( )
101         //////////////////////////////////////////////////////////////////////
102         {
103           cardLayout.show ( this, "1" );
104         }
105    
106         public void  describe ( UsenetMessage  usenetMessage )
107         //////////////////////////////////////////////////////////////////////
108         {
109           agoracastTextPanel.setUsenetMessage ( usenetMessage );
110    
111           cardLayout.show ( this, "2" );
112         }
113    
114         public void  confirm ( UsenetMessage  usenetMessage )
115         //////////////////////////////////////////////////////////////////////
116         {
117           this.usenetMessage = usenetMessage;
118    
119           String  text = usenetMessage.toString ( );
120    
121           // strip off the end-of-message-body period for display purposes
122    
123           text = text.substring ( 0, text.length ( ) - 5 );
124    
125           agoracastConfirmPanel.setText ( text );
126    
127           cardLayout.show ( this, "3" );
128         }
129    
130         public void  post ( )
131         //////////////////////////////////////////////////////////////////////
132         {
133           cardLayout.show ( this, "4" );
134    
135           agoracastSendPanel.send ( usenetMessage );
136         }
137    
138         public void  addFields ( String [ ]  selectedFieldNames )
139         //////////////////////////////////////////////////////////////////////
140         {
141           cardLayout.show ( this, "5" );
142    
143           agoracastFieldsPanel.setSelectedFieldNames ( selectedFieldNames );       
144         }
145    
146         //////////////////////////////////////////////////////////////////////
147         //////////////////////////////////////////////////////////////////////
148    
149         public synchronized void  receive ( Object  message )
150         //////////////////////////////////////////////////////////////////////
151         {
152           if ( message == AgoracastFieldsPanel.DONE_BUTTON_EVENT )
153           {
154             agoracastPrepPanel.setSelectedFieldNames (
155               agoracastFieldsPanel.getSelectedFieldNames ( ) );
156    
157             cardLayout.show ( this, "1" );
158           }
159         }
160    
161         //////////////////////////////////////////////////////////////////////
162         //////////////////////////////////////////////////////////////////////
163         }