    1   package baseCode.gui;
    2
    3   import java.awt.Color;
    4   import java.awt.Dimension;
    5   import java.awt.FlowLayout;
    6   import java.awt.Toolkit;
    7
    8   import javax.swing.JFrame;
    9   import javax.swing.UIManager;
    10
    11  import baseCode.gui.ColorMap;
    12  import baseCode.gui.JGradientBar;
    13
    14  /***
    15   *
    16   * @author Will Braynen
    17   * @version $Id: GradientBarApp.java,v 1.1 2005/03/17 13:58:42 pavlidis Exp $
    18   */
    19  public class GradientBarApp {
    20
    21     boolean packFrame = false;
    22
    23     /*** Creates a new instance of GradientBarApp */
    24     public GradientBarApp() {
    25
    26        JFrame frame = new JFrame();
    27        frame.getContentPane().setLayout( new FlowLayout() );
    28        frame.setSize( new Dimension( 300, 300 ) );
    29        frame.setTitle( "JGradientBar Test" );
    30
    31        Color[] colorMap = ColorMap.GREENRED_COLORMAP;
    32        JGradientBar gradientBar = new JGradientBar();
    33        gradientBar.setColorMap( colorMap );
    34        gradientBar.setLabels( -2, +2 );
    35
    36        frame.getContentPane().add( gradientBar );
    37
    38        //Validate frames that have preset sizes
    39        //Pack frames that have useful preferred size info, e.g. from their
    40        // layout
    41        if ( packFrame ) {
    42           frame.pack();
    43        } else {
    44           frame.validate();
    45        }
    46        //Center the window
    47        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    48        Dimension frameSize = frame.getSize();
    49        if ( frameSize.height > screenSize.height ) {
    50           frameSize.height = screenSize.height;
    51        }
    52        if ( frameSize.width > screenSize.width ) {
    53           frameSize.width = screenSize.width;
    54        }
    55        frame.setLocation( ( screenSize.width - frameSize.width ) / 2,
    56              ( screenSize.height - frameSize.height ) / 2 );
    57        frame.setVisible( true );
    58
    59     }
    60
    61     //Main method: args[0] can contain the name of the data file
    62     public static void main( String[] args ) {
    63        try {
    64           UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
    65        } catch ( Exception e ) {
    66           e.printStackTrace();
    67        }
    68        new GradientBarApp();
    69     }
    70  }