/**This class provides the GUI interfacing between the user and the machine
*It uses the swing functionality to provide a good interfacing
*@author Shashi Mittal
*@version 1.0(15-03-2003)
*/
package de.axxeed.animosy.sandbox;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import org.apache.log4j.Logger;
public class ScrollBarSandbox extends JFrame {
/**
*
*/
private static final long serialVersionUID = 7553508930351281023L;
private static Logger log = Logger.getLogger(ScrollBarSandbox.class);
private MapPanel mp = new MapPanel();
private Container content = new JDesktopPane();
/**This is the main method.Called when run as an application
*/
public static void main(String args[])
{
ScrollBarSandbox sbs = new ScrollBarSandbox();
// showtime!
sbs.setVisible(true);
}
public ScrollBarSandbox() {
super("ScrollBar Sandbox");
setSize(900, 650);
setLocation(15, 15);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
log.debug("Size after maximize: "+getWidth()+"/"+getHeight());
content.setVisible(true);
SpringLayout sl = new SpringLayout();
content.setLayout(sl);
// defining the basic springs
Spring top = sl.getConstraint(SpringLayout.NORTH, content);
Spring left = sl.getConstraint(SpringLayout.WEST, content);
Spring bottom = sl.getConstraint(SpringLayout.SOUTH, content);
Spring right = sl.getConstraint(SpringLayout.EAST, content);
// add the map panel
log.debug("Adding map panel...");
Spring mapHeight = Spring.sum(bottom, top);
Spring mapTop = top;
Spring mapLeft = left;
Spring mapWidth = Spring.sum(right, Spring.minus(left));
mp.setVisible(true);
content.add(mp, new SpringLayout.Constraints(mapLeft,mapTop,mapWidth,mapHeight));
// now add all the pane to the window
this.getContentPane().add(content);
}
/**
* In addition to the standard paint method, this also checks the reqired minimum size of the window.
* @see java.awt.Container#paint(java.awt.Graphics)
*/
public void paint( Graphics g )
{
super.paint(g);
log.debug("Painting main window ("+this.getWidth()+"x"+this.getHeight()+"), "+this.getComponents().length+" components...");
// if the window has been resized to less than the required size, it will automatically be resized!
if(this.getWidth()<410) {
this.setSize(410, this.getHeight());
log.debug("Resetting Size (x)....");
}
if(this.getHeight()<400) {
this.setSize(this.getWidth(), 400);
log.debug("Resetting Size (y)....");
}
this.validate();
}
}