1 import java.awt.*; 2 import java.awt.event.*; 3 import javax.swing.*; 4 5 import java.util.*; 6 import java.io.*; 7 8 import devisor2.grid.GUI.framework.*; 9 import devisor2.grid.options.*; 10 import devisor2.grid.GUI.help.*; 11 import devisor2.foundation.elements.*; 12 import devisor2.foundation.boundary.*; 13 import devisor2.foundation.base.*; 14 import devisor2.grid.GUI.dialogs.*; 15 import devisor2.grid.backend.undo.*; 16 17 /** 18 * This is the startup program for the DeViSoRGriD 2 application. 19 * In order to work properly, before initializing any GUI, the options 20 * and locale are loaded and linked to a new ControlCenter object. 21 * From there, they can be accessed anytime at runtime. <br> 22 * <br> 23 * But before that, the saved options are loaded, according to the 24 * following search hierarchy (switching to the next step whenever loading 25 * errors occur): <br> 26 * (1) if the user specifies the path to his devisor2settings file 27 * as first argument when executing this class, the given file is loaded 28 * and used to create the Options instance. <br> 29 * Example: <code>java devisorgrid myoptions.conf<\code><br> 30 * (2) the default options file <code>.devisorgrid<\code> or 31 * <code> devisorgrid.conf<\code> is loaded.<br> 32 * (4) the build-in default values are used, using the current directory 33 * as DEVISORHOME. <br> 34 * <br> 35 * Thus, a valid Options instance is created, especially with a valid 36 * DEVISORHOME path. <br> 37 * <br> 38 * After that, the ControlCenter instance (which holds global variables) 39 * is created, thus instanciating the ResourceBundle. To stay conform with 40 * the java styleguide, which options instance to load depends on the 41 * language settings of your operating system. See there for details. <br> 42 * <br> 43 * Finally, the MainFrame instance is created and displayed, and 44 * the user can start to work.<br> 45 * <br> 46 * @see everything else, especially the java tutorial on localization support 47 * and the ControlCenter and MainFrame classes. 48 * 49 * @author Dominik Goeddeke 50 * @version beta, search hierarchy not implemented 51 */ 52 53 public class devisorgrid 54 { 55 56 private static Options options; 57 58 main(String[] args)59 public static void main (String[] args) 60 { 61 long start = System.currentTimeMillis (); 62 System.out.println ("Starting the DeViSoRGriD2 application ..."); 63 System.out.println ("Version: "+InfoDialog.version_level1+"."+InfoDialog.version_level2+"."+InfoDialog.version_level3+" of "+InfoDialog.release_date); 64 System.out.println ("Please stand by while loading Options ..."); 65 boolean optionssuccess = false; 66 // options from command line 67 if (args.length > 0) 68 { 69 options = new Options (); 70 try 71 { 72 options.load (args[0]); 73 optionssuccess = true; 74 } 75 catch (Exception ex1) 76 { 77 System.out.println ("Error while loading the given Options file!"); 78 } 79 80 } 81 // users conf file 82 if (!optionssuccess) 83 { 84 String os = System.getProperty ("os.name").toUpperCase(); 85 if (os.indexOf ("WIN") != -1) 86 { 87 options = new Options (); 88 try 89 { 90 System.out.println (System.getProperty ("user.home")+System.getProperty ("file.separator")+"devisorgrid.conf"); 91 options.load (System.getProperty ("user.home")+System.getProperty ("file.separator")+"devisorgrid.conf"); 92 optionssuccess = true; 93 } 94 catch (Exception ex) 95 { 96 System.out.println ("Could not load user specific options file!"); 97 } 98 } 99 else 100 { 101 options = new Options (); 102 try 103 { 104 options.load (System.getProperty ("user.home")+System.getProperty ("file.separator")+".devisorgrid"); 105 optionssuccess = true; 106 } 107 catch (Exception ex) 108 { 109 System.out.println ("Using factory defaults. Please check paths in OptionsDialog!"); 110 } 111 } 112 } 113 // factory options 114 if (!optionssuccess) 115 { 116 options = new Options (); 117 options.resetToDefaults (); 118 options.set (Options.general_devisorhome, System.getProperty ("devisorgrid.home")); 119 } 120 System.out.println ("Options loaded in " + (System.currentTimeMillis()-start) + "ms."); 121 // control center 122 start = System.currentTimeMillis (); 123 System.out.println ("Loading ControlCenter ..."); 124 start = System.currentTimeMillis (); 125 ControlCenter cc = new ControlCenter (options); 126 System.out.println ("ControlCenter loaded in " + (System.currentTimeMillis()-start) + "ms."); 127 // help frame 128 System.out.println ("Loading the help system ..."); 129 try 130 { 131 cc.help = new HelpFrame (cc.op.get(Options.general_helpfile)); 132 } 133 catch (IOException ex) 134 { 135 System.out.println ("Could not load help file!"); 136 System.out.print ("Make sure the following file exists: "); 137 System.out.println (cc.op.get(Options.general_helpfile)); 138 } 139 try 140 { 141 cc.faq = new FAQFrame (cc.op.get(Options.general_faqfile)); 142 } 143 catch (IOException ex) 144 { 145 System.out.println ("Could not load faq file!"); 146 System.out.print ("Make sure the following file exists: "); 147 System.out.println (cc.op.get(Options.general_faqfile)); 148 } 149 System.out.println ("Help loaded in " + (System.currentTimeMillis()-start) + "ms."); 150 System.out.println ("Creating the GUI and starting up the MainFrame ..."); 151 start = System.currentTimeMillis (); 152 MainFrame frame = new MainFrame (); 153 cc.gc.setMainFrame(frame,cc); 154 frame.pack (); 155 // last but not least, update DrawControl 156 cc.dc.screen_width = frame.getToolkit().getScreenSize().getSize().width; 157 cc.dc.screen_height = frame.getToolkit().getScreenSize().getSize().height; 158 // ok thats it 159 cc.dm = new DialogManager (frame); 160 cc.um = new UndoManager (frame); 161 frame.getMainActionListener().restoreStartUpMode (); 162 cc.gc.setMainFrame(frame,cc); 163 164 frame.getDrawingArea().redraw_enabled=true; 165 166 cc.dc.world_x1=-1*100000; 167 cc.dc.world_y1=-1*100000; 168 cc.dc.world_x2= 1*100000; 169 cc.dc.world_y2= 1*100000; 170 171 cc.dc.act_x1=cc.dc.world_x1; 172 cc.dc.act_x2=cc.dc.world_x2; 173 cc.dc.act_y1=cc.dc.world_y1; 174 cc.dc.act_y2=cc.dc.world_y2; 175 176 cc.gc.setTransformation(); 177 178 cc.d.centerDomain(); 179 180 frame.show (); 181 182 cc.dm.initDialogs (); 183 cc.gc.gtk.updateBoundaryCombos(); 184 cc.dc.tolerance = cc.gc.SingleFromScreenToWorld(cc.dc.tolerance); 185 System.out.println ("MainFrame is up after " + (System.currentTimeMillis()-start) + "ms."); 186 187 188 ReadmeFrame.initialize(cc.gc.mf, "README", "waiting for godot..."); 189 190 int revlevel = 2; 191 String revfile = System.getProperty("user.home")+System.getProperty("file.separator")+".dgm"; 192 193 int cf=DomainIO.checkFile(revfile); 194 if (cf==0) 195 { 196 197 ReadmeFrame.showDialog (); 198 199 try 200 { 201 FileOutputStream writeFile = new FileOutputStream(revfile); 202 DataOutputStream out = new DataOutputStream( writeFile ); 203 out.writeBytes(revlevel+""); 204 out.close(); 205 } 206 catch (IOException ex) 207 { 208 } 209 } 210 else 211 { 212 try 213 { 214 BufferedReader in; 215 StreamTokenizer eingabe; 216 217 in = new BufferedReader(new FileReader(revfile)); 218 219 eingabe = new StreamTokenizer(in); 220 221 eingabe.ordinaryChar('/'); 222 eingabe.slashSlashComments(true); 223 eingabe.slashStarComments(true); 224 eingabe.parseNumbers(); 225 226 int erg=eingabe.nextToken(); 227 228 int number=(int)eingabe.nval; 229 230 in.close(); 231 232 if (number<revlevel) 233 { 234 ReadmeFrame.showDialog (); 235 FileOutputStream writeFile = new FileOutputStream(revfile); 236 DataOutputStream out = new DataOutputStream( writeFile ); 237 out.writeBytes(revlevel+""); 238 out.close(); 239 } 240 } 241 catch (IOException ex) 242 { 243 } 244 } 245 } 246 247 } 248 249 250