Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

GetMailApp Class Reference

Simple POP3 get mail application that demonstrates usage of the MessageStore class (based on Javamail package), which instances are used to retrieve e-mail messages from the pop3 store in background. More...

Inheritance diagram for GetMailApp:
Inheritance graph
[legend]
Collaboration diagram for GetMailApp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 GetMailApp ()
 Creates an instance of the get mail application GUI.
void actionPerformed (ActionEvent evt)
 Handles buttonReceive events.
void onGetMessagesCompleted (StringBuffer outs)
 Call-back from the MessageStore instance.

Static Public Member Functions

static void main (String args[])
 Main entry point.

Private Member Functions

void formWindowClosing (WindowEvent evt)
 Closes application.

Private Attributes

JButton buttonReceive
 GUI components.
JLabel labelServer
JTextField fieldServer
JLabel labelUsername
JTextField fieldUsername
JLabel labelPassword
JTextField fieldPassword
JScrollPane messageScrollPane
JEditorPane messageContents
JCheckBox showContents

Static Private Attributes

static final long serialVersionUID = -5231008427555021088L
 Implements java.io.Serializable interface.
static final String appTitle = "IP1-6.2: POP3 Get Mail"
 Common application title prefix.

Detailed Description

Simple POP3 get mail application that demonstrates usage of the MessageStore class (based on Javamail package), which instances are used to retrieve e-mail messages from the pop3 store in background.

Author:
Mikica B Kocic

Definition at line 32 of file GetMailApp.java.


Constructor & Destructor Documentation

GetMailApp.GetMailApp (  )

Creates an instance of the get mail application GUI.

Definition at line 62 of file GetMailApp.java.

References appTitle, buttonReceive, fieldPassword, fieldServer, fieldUsername, formWindowClosing(), labelPassword, labelServer, labelUsername, messageContents, messageScrollPane, and showContents.

Referenced by main().

    {
        super( appTitle );
            
        setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
        
        /////////////////////////////////////////////////////// GUI COMPONENTS ///////////
        
        addWindowListener( new java.awt.event.WindowAdapter () {
            public void windowClosing( java.awt.event.WindowEvent evt ) {
                formWindowClosing( evt );
            }
        });

        buttonReceive  = new JButton ();
        labelServer    = new JLabel( "POP3 Server:" );
        fieldServer    = new JTextField ();
        labelUsername  = new JLabel( "Username:" );
        fieldUsername  = new JTextField ();
        labelPassword  = new JLabel( "Password:" );
        fieldPassword  = new JTextField ();
        showContents   = new JCheckBox( "Contents" );

        messageContents = new JEditorPane ();
        messageContents.setEditable( false );

        messageScrollPane = new JScrollPane ();
        messageScrollPane.setViewportView( messageContents );

        buttonReceive.setText( "Receive" );
        buttonReceive.addActionListener( this );
        
        showContents.setSelected( false );

        /////////////////////////////////////////////////////// FONTS ////////////////////

        Font btnFont  = new Font( Font.SANS_SERIF, Font.BOLD,  12 );
        Font textFont = new Font( Font.SANS_SERIF, Font.PLAIN, 12 );
        Font monoFont = new Font( Font.MONOSPACED, Font.PLAIN, 14 );
        
        buttonReceive.setFont( btnFont );
        labelServer.setFont( textFont );
        labelUsername.setFont( textFont );
        labelPassword.setFont( textFont );
        fieldServer.setFont( textFont );
        fieldUsername.setFont( textFont );
        fieldPassword.setFont( textFont );
        messageContents.setFont( monoFont );
        messageContents.setBackground( new Color( 255, 255, 240 ) );

        /////////////////////////////////////////////////////// COMPONENTS LAYOUT ////////

        JPanel authenticationPane = new JPanel (); 
        authenticationPane.setBorder( new MetalBorders.Flush3DBorder() );
        
        //////////////////////////////////////////////////////////////////////////////////
        
        /* Layout (self explained?): 
         *     Upper: fieldServer, fieldUsername, fieldPassword, buttonReceive,
         *            showContents checkbox
         *     Lower: messageContents scroll pane
         */
        GroupLayout layout = new GroupLayout( getContentPane () );
        getContentPane().setLayout( layout );
        layout.setAutoCreateContainerGaps( true );
        layout.setAutoCreateGaps( true );

        layout.setHorizontalGroup
        (
            layout
            .createParallelGroup( Alignment.LEADING )
            .addGroup
            ( 
                layout
                .createSequentialGroup ()
                .addGroup
                ( 
                    layout
                    .createParallelGroup( Alignment.LEADING )
                    .addGroup
                    (
                        Alignment.TRAILING, 
                        layout
                        .createSequentialGroup ()
                        .addComponent( labelServer )
                        .addGap( 5 )
                        .addComponent( fieldServer, 120, 120, 2000  )
                        .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED )
                        .addComponent( labelUsername )
                        .addGap( 5 )
                        .addComponent( fieldUsername )
                        .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED )
                        .addComponent( labelPassword )
                        .addGap( 5 )
                        .addComponent( fieldPassword )
                        .addGap( 25 )
                        .addComponent( buttonReceive )
                        .addGap( 5 )
                        .addComponent( showContents )
                    )
                    .addComponent( messageScrollPane )
                )
            )
        );
        
        layout.setVerticalGroup
        (
            layout
            .createParallelGroup( Alignment.LEADING )
            .addGroup
            (
                layout
                .createSequentialGroup ()
                .addGroup
                (
                    layout
                    .createParallelGroup( Alignment.CENTER )
                    .addComponent( labelServer )
                    .addComponent( fieldServer, Alignment.CENTER, 25, 25, 25 )
                    .addComponent( labelUsername )
                    .addComponent( fieldUsername, Alignment.CENTER, 25, 25, 25 )
                    .addComponent( labelPassword )
                    .addComponent( fieldPassword, Alignment.CENTER, 25, 25, 25 )
                    .addComponent( buttonReceive, Alignment.CENTER, 25, 25, 25 )
                    .addComponent( showContents )
                )
                .addPreferredGap( LayoutStyle.ComponentPlacement.UNRELATED )
                .addComponent( messageScrollPane )
            )
        );
        
        pack();
        
        /////////////////////////////////////////////////////// WINDOW PLACEMENT /////////
        
        /* Adjust window dimensions not to exceed screen dimensions ...
         */
        Dimension win = new Dimension( 1024, 600 );
        Dimension scsz = Toolkit.getDefaultToolkit().getScreenSize();
        win.width  = Math.min( win.width, scsz.width );
        win.height = Math.min( win.height, scsz.height - 40 );
        setSize( win );
        setMinimumSize( new Dimension( 700, 500 ) );
        
        /* ... then center window on the screen.
         */
        setLocation( ( scsz.width - win.width )/2, ( scsz.height - 40 - win.height )/2 );
        
        /* Show usage...
         */
        messageContents.setForeground( Color.BLUE );
        messageContents.setText( "\n"
                + "  To get messages from POP3 server:\n\n"
                + "    1) Enter server's hostname or IP address\n" 
                + "    2) Enter your credentials\n"
                + "    3) Click 'Receive'.\n\n"
                + "  By default, messages' contents is not displayed.\n"
                + "  To display the contents, turn on the 'Contents' check-box.\n"
                );

        /* Ready for user to type in...
         */
        fieldServer.requestFocus ();
    }

Member Function Documentation

void GetMailApp.actionPerformed ( ActionEvent  evt )

Handles buttonReceive events.

Definition at line 240 of file GetMailApp.java.

References buttonReceive, fieldPassword, fieldServer, fieldUsername, messageContents, and showContents.

    {
        if ( fieldServer.getText().isEmpty () || fieldUsername.getText().isEmpty () ) {
            return;
        }

        messageContents.setContentType( "text/html" );
        messageContents.setText( 
                "<html><head></head><body><h3>Receiving...</h3></body></html>" );
        buttonReceive.setEnabled( false );

        new MessageStore (
                this,
                fieldServer.getText (),
                fieldUsername.getText (),
                fieldPassword.getText (),
                showContents.isSelected ()
                );
    }
void GetMailApp.formWindowClosing ( WindowEvent  evt ) [private]

Closes application.

Parameters:
evt

Definition at line 232 of file GetMailApp.java.

Referenced by GetMailApp().

    {
        System.exit( 0 );
    }
static void GetMailApp.main ( String  args[] ) [static]

Main entry point.

Creates instance of GetMailApp application.

Parameters:
argsthe command line arguments

Definition at line 282 of file GetMailApp.java.

References GetMailApp().

    {
        java.awt.EventQueue.invokeLater( 
                new Runnable() {
                    public void run() {
                        new GetMailApp ().setVisible( true );
                    }
                }
            );
    }
void GetMailApp.onGetMessagesCompleted ( StringBuffer  outs )

Call-back from the MessageStore instance.

Displays HTML formatted contents of the MessageStore (that might have error messages).

Definition at line 264 of file GetMailApp.java.

References buttonReceive, and messageContents.

Referenced by MessageStore.dumpAll(), and MessageStore.run().

    {
        final String str = outs.toString ();

        SwingUtilities.invokeLater( new Runnable () {
            public void run () {
                messageContents.setContentType( "text/html" );
                messageContents.setText( str );
                buttonReceive.setEnabled( true );
            }
        } );
    }

Member Data Documentation

final String GetMailApp.appTitle = "IP1-6.2: POP3 Get Mail" [static, private]

Common application title prefix.

Definition at line 43 of file GetMailApp.java.

Referenced by GetMailApp().

JButton GetMailApp.buttonReceive [private]

GUI components.

Definition at line 48 of file GetMailApp.java.

Referenced by actionPerformed(), GetMailApp(), and onGetMessagesCompleted().

JTextField GetMailApp.fieldPassword [private]

Definition at line 54 of file GetMailApp.java.

Referenced by actionPerformed(), and GetMailApp().

JTextField GetMailApp.fieldServer [private]

Definition at line 50 of file GetMailApp.java.

Referenced by actionPerformed(), and GetMailApp().

JTextField GetMailApp.fieldUsername [private]

Definition at line 52 of file GetMailApp.java.

Referenced by actionPerformed(), and GetMailApp().

JLabel GetMailApp.labelPassword [private]

Definition at line 53 of file GetMailApp.java.

Referenced by GetMailApp().

JLabel GetMailApp.labelServer [private]

Definition at line 49 of file GetMailApp.java.

Referenced by GetMailApp().

JLabel GetMailApp.labelUsername [private]

Definition at line 51 of file GetMailApp.java.

Referenced by GetMailApp().

JEditorPane GetMailApp.messageContents [private]

Definition at line 56 of file GetMailApp.java.

Referenced by actionPerformed(), GetMailApp(), and onGetMessagesCompleted().

JScrollPane GetMailApp.messageScrollPane [private]

Definition at line 55 of file GetMailApp.java.

Referenced by GetMailApp().

final long GetMailApp.serialVersionUID = -5231008427555021088L [static, private]

Implements java.io.Serializable interface.

Definition at line 38 of file GetMailApp.java.

JCheckBox GetMailApp.showContents [private]

Definition at line 57 of file GetMailApp.java.

Referenced by actionPerformed(), and GetMailApp().


The documentation for this class was generated from the following file: