/* GridInt * Lab 7 * April 3, 2008 * Charles H C Meyer * CompSci 210 */ /* This program is deisgned to utilize the GridInt and GridFloat classes * a more user friendly way then the main statements. Basically does nothing * more then take arguments and put out a grid class based on them, sortof an * oversize main statement that an run two classes instead fo one. In the * future, it would be nice if it had a GUI. Note that as of april 3'rd, * the GridFloat class does not actually work, however I left it in here * in case I fix it later. */ //syntax: GridGIS // [-m < min color height>] [ -w ] [-f] // //-f uses a float version as oposed to an int version import java.awt.*; import javax.swing.*; public class GridGIS extends JFrame{ public GridGIS(String[] args) { //the user gave no arguments if (args.length == 0) { printSyntax(); } //sets of the initial, non optional, items String fileName = args[0]; int colorScheme = stringToInt(args[1]); int maxColorHeight = stringToInt(args[2]); //these are tripped if certain optional componenets //are included in the arguments boolean mSwitch = false; boolean wSwitch = false; boolean fSwitch = false; //the variables that will be aclled in the constructor, they are given values //to keep java from getting angry that they may not have been initialized int minColor = 0; int windowX = 0; int windowY = 0; //this cycles through the arguments and pulls out any of the optional parts for (int k = 3; k < args.length; k++) { //the user has specified the min Height if (args[k].equals("-m")) { mSwitch = true; k++; minColor = stringToInt(args[k]); } //the user has specified a window size else if (args[k].equals("-w")) { wSwitch = true; k++; windowX = stringToInt(args[k]); k++; windowY = stringToInt(args[k]); } //the user wishes to use the float version of grid else if (args[k].equals("-f")) { fSwitch = true; } //the user put something else in the arguments else { printSyntax(); } } //runs the int version, if (!fSwitch) { GridInt data = new GridInt(fileName); //these set values data.setColorScheme(colorScheme); data.setMaxHeight(maxColorHeight); //these set any optional values if (mSwitch) { data.setMinHeight(minColor); } if (wSwitch) { data.setWindow(windowX,windowY); } data.renderGrid(); } //runs the float version, same idea as above if (fSwitch) { GridFloat data = new GridFloat(fileName); data.setColorScheme(colorScheme); data.setMaxHeight(maxColorHeight); if (mSwitch) { data.setMinHeight(minColor); } if (wSwitch) { data.setWindow(windowX,windowY); } data.renderGrid(); } } //turns a string that is a number into and int, //used to convert atgument items, only take positive ints private int stringToInt(String inString) { int toReturn = 0; //this just cycles throguh every digit int k = 0; while (k < inString.length()) { //adds the apropriate value for this int toReturn += ((int)inString.charAt(inString.length()-k-1)-48)*Math.pow(10,k); k++; } return toReturn; } //prints out the information on the sysntax private void printSyntax() { System.out.println("syntax: GridGIS " + "[-m < min color height>] [ -w ] [-f]"); System.out.println("used to render a terain into an image"); System.out.println(); System.out.println("the color scheme is the type of colors used to represent height"); System.out.println("1 is grayscale, 2 fades from red to green to blue"); System.out.println("3 shifts abrubtly from red to green to blue"); System.out.println(); System.out.println("the max color height is the height that the highest color is set to"); System.out.println("the min color height is the minimum equivalent, default is 0"); System.out.println(); System.out.println("-w is used to change the window dimensions, default is the terrain size"); System.out.println(); System.out.println("-f uses a float version as oposed to an int"); System.out.println("although right now only the int works"); } //syntax: GridGIS // [-m < min color height>] [ -w ] [-f] // //-f uses a float version as oposed to an int public static void main(String[] args) { //basically, this just passes through all of the arguments to the constructor new GridGIS(args); } }