/* A Controller class for Grid.java. GridGIS handles passing a filename and render method to the Grid class, which then takes care of the actual data structures and drawing. Pass the file you want to open as an argument to this class. Nathan Merritt - April 1, 2008 */ import java.util.*; import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; public class GridGIS extends JFrame { // window size public static int HEIGHT = 600; public static int WIDTH = 600; // control buttons public JButton renderGray, renderColor; // panel with the control buttons public JPanel optionsPanel; // the grid we'll be rendering Grid grid; public GridGIS (String gridFile) { super("Topographic Grid Mapper"); renderGray = new JButton("Render in Grayscale"); renderGray.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { grid.setRenderMethod("grayscale"); repaint(); } }); renderColor = new JButton("Render in Color"); renderColor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { grid.setRenderMethod("color"); repaint(); } }); optionsPanel = new JPanel(); optionsPanel.add(renderGray); optionsPanel.add(renderColor); getContentPane().add("South", optionsPanel); setSize(WIDTH, HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // load the grid file System.out.println("rendering from " + gridFile); grid = new Grid(gridFile); setVisible(true); } // all drawing negotiated from here: public void paint(Graphics g) { optionsPanel.repaint(); grid.renderGrid(WIDTH, HEIGHT, g); } public static void main(String[] args) { // make a GridGIS for the cli argument - we'll render that map if (args[0] != null) { GridGIS gridController = new GridGIS(args[0]); } } }