| AVR Z-LINKŪ |

# MainFrame.java

Go to the documentation of this file.

    00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
    00002 package gui;
    00003
    00004 import java.awt.Dimension;
    00005 import java.awt.event.ActionEvent;
    00006 import java.awt.event.ActionListener;
    00007 import java.net.URL;
    00008
    00009 import javax.swing.ImageIcon;
    00010 import javax.swing.JButton;
    00011 import javax.swing.JFrame;
    00012 import javax.swing.JLabel;
    00013 import javax.swing.JPanel;
    00014 import javax.swing.JScrollPane;
    00015 import javax.swing.JTabbedPane;
    00016 import javax.swing.JTextArea;
    00017 import javax.swing.event.EventListenerList;
    00018
    00019
    00037 public class MainFrame extends JFrame implements ActionListener{
    00038
    00039         private static final long serialVersionUID = 1L;
    00040
    00041         private JTabbedPane
    00042                 background = new JTabbedPane( );
    00043         private JButton
    00044                 connect    = new JButton( "Connect" ),
    00045                 disconnect = new JButton( "Disconnect" ),
    00046                 clearDebug = new JButton( "Clear" );
    00047
    00048         private JTextArea
    00049                 debugMessages = new JTextArea( " Welcome. Thank you for choosing AVR and the new AT86RF230.\r\n" +
    00050                                                                    "\r\n Instructions:\r\n" +
    00051                                                " 1. Program the AVR.\r\n" +
    00052                                                " 2. Connect it to the PC.\r\n" +
    00053                                                " 3. Turn power on.\r\n" +
    00054                                                " 4. Press the Connect button. Enjoy.\r\n\r\n" );
    00055         private JLabel imageAVR;
    00056         private JLabel imageAtmel;
    00057
    00058         private EventListenerList MainFrameEventListeners = new EventListenerList( );
    00059
    00069         public MainFrame(  ){
    00070
    00071 //              Set name on frame.
    00072                 super( "AVR414: Peer-to-Peer Chat Application" );
    00073             this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    00074                 this.setSize( new Dimension( 600, 400 ) );
    00075                 this.setResizable( false );
    00076
    00077                 JPanel connectAndDebug = new JPanel( );
    00078                 connectAndDebug.setSize( new Dimension( 600, 400 ) );
    00079                 connectAndDebug.setLayout( null );
    00080                 connectAndDebug.setOpaque(true);
    00081
    00082                 //Add action Listeners
    00083                 connect.setBounds( 8, 200, 135, 20 );
    00084                 connect.addActionListener( this );
    00085
    00086                 disconnect.setBounds( 8, 225, 135, 20 );
    00087                 disconnect.addActionListener( this );
    00088
    00089                 clearDebug.setBounds( 8, 250, 135, 20 );
    00090                 clearDebug.addActionListener( this );
    00091
    00092                 URL avrLogoURL = gui.MainFrame.class.getResource( "AVR_logo_black.gif" );
    00093
    00094                 ImageIcon avrLogo = new ImageIcon( avrLogoURL );
    00095
    00096                 imageAVR = new JLabel( avrLogo );
    00097                 imageAVR.setBounds( 8, 100, 135, 97 );
    00098
    00099                 URL atmelURL = MainFrame.class.getResource( "Atmel_logo_black.gif" );
    00100
    00101                 ImageIcon atmelLogo = new ImageIcon( atmelURL );
    00102                 imageAtmel = new JLabel( atmelLogo );
    00103                 imageAtmel.setBounds( 8, 0, 135, 97 );
    00104
    00105                 debugMessages.setEditable( false );
    00106                 JScrollPane right = new JScrollPane( debugMessages );
    00107                 right.setBounds( 151, 10, 399, 260 );
    00108
    00109                 connectAndDebug.add( connect );
    00110                 connectAndDebug.add( disconnect );
    00111                 connectAndDebug.add( clearDebug );
    00112                 connectAndDebug.add( right );
    00113                 connectAndDebug.add( imageAVR );
    00114                 connectAndDebug.add( imageAtmel );
    00115
    00116                 background.addTab( "Debug", connectAndDebug);
    00117
    00118                 this.add( background );
    00119                 this.setVisible( true );
    00120
    00121                 this.repaint( );
    00122         }
    00123
    00135         public void actionPerformed( ActionEvent ae ) {
    00136                 //Read out event string.
    00137                 int eventType;
    00138                 String event = ae.getActionCommand( ).toString( );
    00139
    00140
    00141                 //Connect button.
    00142                 if( event.equals( "Connect" ) ){
    00143
    00144                         eventType = MainFrameEvent.CONNECT;
    00145                 }
    00146                 //Disconnect button.
    00147                 else if( event.equals( "Disconnect" ) ){
    00148
    00149                         eventType = MainFrameEvent.DISCONNECT;
    00150                 }
    00151                 //Clear button.
    00152                 else{
    00153
    00154                         eventType = MainFrameEvent.CLEAR_DEBUG;
    00155                 }
    00156
    00157                 fireMainFrameEvent( new MainFrameEvent( eventType ) );
    00158         }
    00159
    00167         public void addChatTab( ChatWindow chatTab ){
    00168
    00169                 background.addTab( "Chat", chatTab );
    00170                 background.setSelectedComponent( chatTab );
    00171         }
    00172
    00180         public void closeChatTab( ChatWindow chatTab ){
    00181
    00182                 chatTab.clearConversation( );
    00183                 chatTab.clearMessage( );
    00184                 background.remove( chatTab );
    00185         }
    00186
    00192         public void clearDebugMesasges( ){
    00193                 debugMessages.setText( "" );
    00194         }
    00195
    00203         public void appendDebugMessage( String msg ){
    00204                 debugMessages.append( "[DEBUG] " + msg + "\r\n" );
    00205         }
    00206
    00213         public void appendLiveTrafficIn( String msg ){
    00214                 debugMessages.append( "[Traffic <- ] " + msg + "\r\n" );
    00215         }
    00216
    00223         public void appendLiveTrafficOut( String msg ){
    00224                 debugMessages.append( "[Traffic -> ] " + msg + "\r\n" );
    00225         }
    00226
    00235         public void addMainFrameEventListener( MainFrameEventListener mfeListener ){
    00236                 MainFrameEventListeners.add( MainFrameEventListener.class, mfeListener );
    00237         }
    00238
    00247         public void removeMainFrameEventListener( MainFrameEventListener mfeListener ){
    00248                 MainFrameEventListeners.remove( MainFrameEventListener.class, mfeListener );
    00249         }
    00250
    00259         protected void fireMainFrameEvent( MainFrameEvent event ){
    00260
    00261                 Object[ ] listeners = MainFrameEventListeners.getListenerList( );
    00262                 int numberOfListeners = listeners.length;
    00263
    00264                 for( int i = 0; i < numberOfListeners; i+=2 ){
    00265
    00266                         if( listeners[ i ] == MainFrameEventListener.class ){
    00267                                 ( (MainFrameEventListener)listeners[ i + 1 ] ).MainFrameEvent( event );
    00268                         }
    00269                 }
    00270         }
    00271 }

@DOC_TITLE@