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

import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

import de.javasoft.swing.JYTabbedPane;

/**
 * Demonstrates tab sizing and alignments.  
 */
@SuppressWarnings("serial")
public class AlignedAndSizedTabs extends JFrame
{
  public AlignedAndSizedTabs()
  {
    super("Aligned And Sized Tabs");
    
    final JYTabbedPane tabbedPane = new JYTabbedPane();

    tabbedPane.addTab("Short", new JScrollPane(new JTextArea("Component A")));
    tabbedPane.addTab("Longer tab text", new JScrollPane(new JTextArea("Component B")));
    tabbedPane.addTab("Much longer tab text to see truncation effect", new JScrollPane(new JTextArea("Component C")));
    
    tabbedPane.setIconAt(0, new ImageIcon(getClass().getResource("/resources/icons/tip.png")));
    tabbedPane.setIconAt(1, new ImageIcon(getClass().getResource("/resources/icons/wizard.png")));
    tabbedPane.setIconAt(2, new ImageIcon(getClass().getResource("/resources/icons/clock.png")));
    
//@highlight
    //tabs size settings - stretch small tabs, truncate large tabs
    tabbedPane.setMinimumTabSize(100);
    tabbedPane.setMaximumTabSize(100);
    
    //center all tabs horizontal
    tabbedPane.setHorizontalTabAlignment(SwingConstants.CENTER);
    
    //center label within tab - if label is smaller than tab
    for (int i=0; i<tabbedPane.getTabCount(); i++)
      tabbedPane.getTabLabelAt(i).setHorizontalAlignment(SwingConstants.CENTER);

    //center icon and tab text
    for (int i=0; i<tabbedPane.getTabCount(); i++)
      tabbedPane.getTabLabelAt(i).setHorizontalTextPosition(SwingConstants.CENTER);
    
    //icon on top
    for (int i=0; i<tabbedPane.getTabCount(); i++)
      tabbedPane.getTabLabelAt(i).setVerticalTextPosition(SwingConstants.BOTTOM);
//@/highlight

    add(tabbedPane);
    
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setSize(600, 400);
    setLocationRelativeTo(null);        //center
    setVisible(true);
  }

  /**
   * 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 AlignedAndSizedTabs();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }  
}
