/* Last Update: 29 Sept 08 - 2000 hrs */
package project;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolBar;
public class MapMaker implements ActionListener{
private JFrame frame;
private JButton button;
private JPanel mainPanel, upPanel, westPanel, eastPanel, centerPanel;
private HashMap<String, ArrayList> items;
public void initializeItems() {
items.put("nature", Nature.initializeTrees());
items.put("road", Road.initializeRoads());
items.put("vehicle", Vehicle.initializeVehicles());
items.put("building", Building.initializeBuildings());
items.put("signs", Signs.initializeSigns());
}
public MapMaker() {
items = new HashMap<String, ArrayList>();
initializeItems();
frame=new JFrame("Countryside Tour Planner") ;
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// create the 2 buttons for TREE and ROAD and add action listeners
MainItemToolBar mobj = new MainItemToolBar();
mobj.makeMainItemToolBar(items);
// this panel will hold TREE and ROAD buttons
upPanel=new JPanel();
upPanel.setLayout(new GridLayout(1, 0));
upPanel.add(mobj.getMainItemToolBar());
ArrayList<JButton> mainToolBarButtons = mobj.getButtons();
for(int i=0; i<mainToolBarButtons.size(); i++)
mainToolBarButtons.get(i).addActionListener(this);
// WEST PANEL holds the sub item icons and is initialized to TREE sub icons
westPanel=new JPanel();
SubItemToolBar sobj = new SubItemToolBar();
sobj.makeSubItemToolBar(items.get("nature"), "nature");
westPanel.add(sobj.getSubItemToolBar());
// EAST PANEL holds the properties window
eastPanel = new JPanel();
Box3D boxObj = new Box3D();
boxObj.setClr("green");
boxObj.setModifiable(true);
boxObj.setVisible(true);
boxObj.setRaised(true);
PropertiesPanel pobj = new PropertiesPanel(boxObj);
eastPanel.add(pobj.getPropertiesToolBar());
// CENTER PANEL holds the canvas for drawing
centerPanel = new JPanel();
Canvas cobj = new Canvas();
cobj.setBackground(Color.WHITE);
centerPanel.add(cobj);
// MAIN PANEL holds all the other panels
mainPanel=new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(upPanel,BorderLayout.NORTH);
mainPanel.add(westPanel,BorderLayout.WEST);
mainPanel.add(eastPanel, BorderLayout.EAST);
// sets the Menu bar for the frame
frame.setJMenuBar(new MenuBar());
// finalize frame and display
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setSize(1000,600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
JButton source = (JButton)e.getSource();
String option = source.getName().toLowerCase();
JToolBar toolbar = new JToolBar();
SubItemToolBar sobj = new SubItemToolBar();
westPanel.removeAll();
if(option.equals("nature")) {
sobj.makeSubItemToolBar(items.get("nature"), "nature");
toolbar = sobj.getSubItemToolBar();
} else if(option.equals("road")) {
sobj.makeSubItemToolBar(items.get("road"), "road");
toolbar = sobj.getSubItemToolBar();
} else if(option.equals("vehicle")) {
sobj.makeSubItemToolBar(items.get("vehicle"), "vehicle");
toolbar = sobj.getSubItemToolBar();
} else if(option.equals("building")) {
sobj.makeSubItemToolBar(items.get("building"), "building");
toolbar = sobj.getSubItemToolBar();
}
else if(option.equals("signs and signals")) {
sobj.makeSubItemToolBar(items.get("signs"), "signs");
toolbar = sobj.getSubItemToolBar();
}
westPanel.add(toolbar);
upPanel.revalidate();
westPanel.repaint();
westPanel.revalidate();
mainPanel.revalidate();
frame.validate();
}
public static void main(String[] args) {
MapMaker test = new MapMaker();
}
}
source