/**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;
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import org.apache.log4j.Logger;
import de.axxeed.animosy.gui.GUIEventListener;
import de.axxeed.animosy.gui.MainMenu;
import de.axxeed.animosy.gui.MapPanel;
import de.axxeed.animosy.gui.PanelRepository;
import de.axxeed.animosy.gui.SplashScreen;
import de.axxeed.animosy.gui.StatusPanel;
public class AnImOSY extends JFrame {
/**This is the main method. Called when run as an application
*/
public static void main(String args[])
{
(new SplashScreen()).setVisible(true);
AnImOSY mw = new AnImOSY();
// add a key listener
mw.addKeyListener(GUIEventListener.getInstance());
// and finally: it's showtime!
mw.setVisible(true);
}
// ======================================================================================================
private static final long serialVersionUID = -5110024421111378784L;
private static Logger log = Logger.getLogger(AnImOSY.class);
private MainMenu mainMenu = new MainMenu();
private MapPanel mp = new MapPanel();
private StatusPanel sp = new StatusPanel();
private Container content = new JDesktopPane();
/**
* Creates the main Altera Terra window.
*/
public AnImOSY() {
super("AnImOSY!");
setSize(990, 800);
setLocation(10, 10);
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 main menu
log.debug("Adding main menu...");
mainMenu.setVisible(true);
// springs for the menu
Spring menuWidth = Spring.sum(right, Spring.minus(left));
Spring menuHeight = Spring.constant(20);
content.add(mainMenu, new SpringLayout.Constraints(top,left,menuWidth,menuHeight));
// add the status panel
Spring statusWidth = Spring.constant(146);
Spring statusHeight = Spring.sum(Spring.sum(bottom, Spring.minus(top)), Spring.minus(menuHeight));
Spring statusTop = Spring.sum(bottom, Spring.minus(statusHeight));
Spring statusLeft = Spring.sum(right, Spring.minus(statusWidth));
log.debug("Adding status panel...");
sp.setVisible(true);
content.add(sp, new SpringLayout.Constraints(statusLeft,statusTop,statusWidth,statusHeight));
// put the status panel in the repository
PanelRepository.add(PanelRepository.STATUS_PANEL, sp);
sp.repaint();
// // add the message panel
// log.debug("Adding message panel...");
Spring messHeight = Spring.constant(80);
Spring messTop = Spring.sum(bottom, Spring.minus(messHeight));
Spring messLeft = Spring.sum(left, statusWidth);
Spring messWidth = Spring.sum(right, Spring.minus(messLeft));
// messP.setVisible(true);
// content.add(messP, new SpringLayout.Constraints(messLeft,messTop,messWidth,messHeight));
// PanelRepository.add(PanelRepository.MESSAGE_PANEL, messP);
// finally, add the map panel
log.debug("Adding map panel...");
// map height with message panel:
// Spring mapHeight = Spring.sum(messTop, Spring.minus(Spring.sum(top, menuHeight)));
// map height without message panel:
Spring mapHeight = Spring.sum(bottom, Spring.minus(Spring.sum(top, menuHeight)));
Spring mapTop = Spring.sum(top, menuHeight);
Spring mapLeft = left;
Spring mapWidth = Spring.sum(right, Spring.minus(statusWidth));
mp.setVisible(true);
// mp.addMouseListener(new GUIEventListener());
content.add(mp, new SpringLayout.Constraints(mapLeft,mapTop,mapWidth,mapHeight));
PanelRepository.add(PanelRepository.MAP_PANEL, mp);
// now add all the pane to the window
this.getContentPane().add(content);
PanelRepository.add(PanelRepository.MAIN_WINDOW, this);
}
/**
* 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()<640) {
this.setSize(640, this.getHeight());
log.debug("Resetting Size (x)....");
}
if(this.getHeight()<480) {
this.setSize(this.getWidth(), 480);
log.debug("Resetting Size (y)....");
}
// resetting the sizes of the panels
/*
((MessagePanel) PanelRepository.get("messages")).addMessage("Repaint @ "+System.currentTimeMillis());
((JPanel) PanelRepository.get("map")).setSize(this.getWidth()-108, this.getHeight()-154);
((JPanel) PanelRepository.get("status")).setSize(100, this.getHeight()-20);
((JPanel) PanelRepository.get("messages")).setSize(this.getWidth()-108, 90);
((JPanel) PanelRepository.get("messages")).validate();
((JMenuBar) PanelRepository.get("menu")).setSize(this.getWidth(), 20);
*/
this.validate();
}
}