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

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;

import de.javasoft.swing.JYScrollPaneMap;

/**
 * Demonstrates the ScrollPaneMap.  
 */
@SuppressWarnings("serial")
public class SimpleScrollPaneMap extends JFrame
{
  public SimpleScrollPaneMap()
  {
    super("Simple JYScrollPaneMap Demo");

    JPanel view = new JPanel(new BorderLayout()){
      @Override
      protected void paintComponent(Graphics g)
      {
        Graphics2D graphics = (Graphics2D) g.create();
        graphics.setPaint(new GradientPaint(0, 0, new Color(0x40FF40), getWidth(), getHeight(), new Color(0xFF4040)));
        graphics.fillRect(0, 0, getWidth(), getHeight());
        graphics.dispose();
      }      
    }; 
    view.setPreferredSize(new Dimension(1200, 800));

    JScrollPane scroller = new JScrollPane();
//@highlight
    scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    JYScrollPaneMap map = new JYScrollPaneMap(scroller);
    map.setToolTipText("Keep the mouse button pressed to display the map.");
    scroller.setCorner(JScrollPane.LOWER_TRAILING_CORNER, map);
//@/highlight
    scroller.setViewportView(view);        
    add(scroller);
    
    //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 SimpleScrollPaneMap();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }  
}
