package de.javasoft.synthetica.democenter.examples.statusbar;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JSeparator;
import javax.swing.UIManager;

import org.jdesktop.swingx.JXStatusBar;
import org.jdesktop.swingx.plaf.basic.BasicStatusBarUI;

/**
 * A simple StatusBar application used to demonstrate and explain  
 * basic functionality.
 */
@SuppressWarnings("serial")
public class SimpleStatusBar extends JFrame
{
  public SimpleStatusBar()
  {
    super("Simple StatusBar");
//@highlight
    //add statusbar at the bottom of the frame (contentpane has BorderLayout)
    add(createStatusBar(), BorderLayout.SOUTH);
//@/highlight
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setSize(640, 480);
    setLocationRelativeTo(null);        //center
    setVisible(true);
  }

//@highlight
  /**
   * Create a simple statusbar.
   */
  private JXStatusBar createStatusBar()
  {
    JXStatusBar statusBar = new JXStatusBar();
    //do not add separators automatically
    statusBar.putClientProperty(BasicStatusBarUI.AUTO_ADD_SEPARATOR, Boolean.FALSE);
    statusBar.add(new JLabel("Ready"));
    //use dummy label to fill empty space
    statusBar.add(new JLabel(""), JXStatusBar.Constraint.ResizeBehavior.FILL);
    //create constraint to add space of 5 at components left and right side 
    JXStatusBar.Constraint ct = new JXStatusBar.Constraint(new Insets(0, 5, 0, 5));
    statusBar.add(new JSeparator(JSeparator.VERTICAL), ct);
    statusBar.add(new JLabel("INS"), ct);
    statusBar.add(new JSeparator(JSeparator.VERTICAL), ct);
    statusBar.add(new JLabel("Load"), ct);
    JProgressBar progressBar = new JProgressBar();
    //use statusbar style if available
    progressBar.setName("StatusProgressBar");    
    statusBar.add(progressBar);
    //add the statusbar to the rootPane - some themes require this for proper appearance
    getRootPane().putClientProperty("Synthetica.statusBar", statusBar);    
    return statusBar;
  }
//@/highlight

  /**
   * Static main method for application startup. 
   */
  public static void main(String[] args)
  {
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        try
        {
          UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel");
          new SimpleStatusBar();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }
}
