package com.mindprod.example;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;

/**
 * demonstrate the use of javax.swing.JLabel
 * <p/>
 * composed with IntelliJ IDEA
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0
 */
public final class TestJLabel
    {
    // ------------------------------ FIELDS ------------------------------

    private static final Color LABEL_FOREGROUND = new Color( 0x0000b0 );

    // --------------------------- main() method ---------------------------

    /**
     * Debugging harness for a Frame
     *
     * @param args command line arguments are ignored.
     */
    public static void main( String args[] )
        {
        SwingUtilities.invokeLater( new Runnable()
        {
        /**
         * fire up a JFrame on the Swing thread
         */
        public void run()
            {
            final JFrame jFrame = new JFrame();
            final Container contentPane = jFrame.getContentPane();
            contentPane.setLayout( new BorderLayout() );

            // typical JLabel
            final JLabel label1 = new JLabel( "this is a TEST" );
            label1.setBackground( Color.BLACK );
            label1.setForeground( Color.YELLOW );
            label1.setOpaque( true );
            label1.setFont( new Font( "Dialog", Font.BOLD, 15 ) );
            label1.setHorizontalAlignment( JTextField.RIGHT );
            label1.setEnabled( true );

            // embedded HTML to underline
            final JLabel label2 =
                    new JLabel( "<html><u>look! underlined!</u></html>" );
            label2.setFont( new Font( "Dialog", Font.BOLD, 15 ) );
            label2.setHorizontalAlignment( JTextField.LEFT );
            label2.setEnabled( true );

            // all the bells and whistles
            final JLabel label3 = new JLabel( "Hello" );
            label3.setHorizontalAlignment( JLabel.RIGHT );
            label3.setHorizontalTextPosition( JLabel.LEFT );
            label3.setBackground( Color.YELLOW );
            label3.setForeground( LABEL_FOREGROUND );
            label3.setOpaque( true );
            label3.setFont( new Font( "Dialog", Font.PLAIN, 15 ) );
            // add an image
            // The jar contains the resource com/mindprod/example/raspberry.png
            final ImageIcon raspberry = new ImageIcon( this.getClass().getResource(
                    "raspberry.png" ) );
            label3.setIcon( raspberry );
            Border border = BorderFactory.createEmptyBorder( 2/*top*/, 2/* left*/, 2/*bottom */, 2/*right*/ );
            label3.setBorder( border );
            label3.setText( "adios" );

            contentPane.add( label1, BorderLayout.NORTH );
            contentPane.add( label2, BorderLayout.CENTER );
            contentPane.add( label3, BorderLayout.SOUTH );

            jFrame.setSize( 150, 150 );
            jFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            jFrame.validate();
            jFrame.setVisible( true );
            }
        } );
        }// end main
    }