Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: fzi/injectj/config/panel/ScriptChoosePanel.java


1   // This file is part of the Inject/J project
2   // (C) 1999-2001 Forschungszentrum Informatik (FZI) Karlsruhe
3   // Please visit our website at http://injectj.fzi.de
4   
5   package fzi.injectj.config.panel;
6   
7   import java.awt.*;
8   import java.awt.event.*;
9   import javax.swing.*;
10  import java.io.*;
11  import java.util.*;
12  import fzi.injectj.config.*;
13  import fzi.injectj.Main;
14  import fzi.injectj.language.*;
15  import fzi.injectj.node.ScriptDeclaration;
16  import fzi.injectj.node.AliasDeclaration;
17  import fzi.injectj.node.SourceFile;
18  import fzi.injectj.parser.*;
19  import fzi.injectj.preprocessor.*;
20  import fzi.injectj.util.*;
21  
22  /** Panel to choose script source files. If the user hits the "Next"-button, the
23    * script source files will be parsed.
24    *
25    * @author Volker Kuttruff
26    */
27  public class ScriptChoosePanel extends JPanel implements InjectJPanel
28  {
29  
30    private boolean veto;
31    private String warningsText;
32  
33    protected MainWindow mainWindow;
34  
35    JButton nextButton = new JButton();
36    JButton helpButton = new JButton();
37    JButton prevButton = new JButton();
38    JButton quitButton = new JButton();
39    JTextField scriptSourceField = new JTextField();
40    JButton chooseScriptSourceButton = new JButton();
41    JButton addScriptSourceButton = new JButton();
42    JScrollPane scriptListScrollPane = new JScrollPane();
43    JList scriptSourceList = new JList();
44    JLabel scriptSourceFieldLabel = new JLabel();
45    JLabel scriptListLabel = new JLabel();
46    JButton upButton = new JButton();
47    JButton downButton = new JButton();
48    JButton removeButton = new JButton();
49  
50    Vector scriptSources = new Vector();
51    Vector isParsedVector = new Vector();
52    Hashtable parsedScriptFiles = new Hashtable();
53  
54    protected int unparsedFilesCount;
55  
56    public void newProjectCreated() {
57      scriptSourceField.setText("");
58      if (scriptSourceList.getModel()!=null) scriptSourceList.setListData(new Object[0]);
59      if (scriptSources!=null) scriptSources.removeAllElements();
60      if (isParsedVector!=null) isParsedVector.removeAllElements();
61      if (parsedScriptFiles!=null) parsedScriptFiles.clear();
62      unparsedFilesCount = 0;
63    }
64  
65  
66    public ScriptChoosePanel(MainWindow mainWindow)
67    {
68      try
69      {
70        this.mainWindow = mainWindow;
71        unparsedFilesCount = 0;
72        jbInit();
73      }
74      catch(Exception ex)
75      {
76        ex.printStackTrace();
77      }
78    }
79  
80    public ScriptChoosePanel()
81    {
82      this(null);
83    }
84  
85    public void setMainWindow(MainWindow mainWindow) {
86      this.mainWindow = mainWindow;
87    }
88  
89    private void jbInit() throws Exception
90    {
91      this.setLayout(null);
92      this.setPreferredSize(new Dimension(600, 400));
93  
94      prevButton.setText("<<Previous");
95      prevButton.setBounds(new Rectangle(270 ,360, 100, 30));
96      prevButton.addActionListener(new java.awt.event.ActionListener()
97      {
98  
99        public void actionPerformed(ActionEvent e)
100       {
101         prevButton_actionPerformed(e);
102       }
103     });
104 
105     nextButton.setText("Next >>");
106     nextButton.setBounds(new Rectangle(385, 360, 100, 30));
107     nextButton.addActionListener(new java.awt.event.ActionListener()
108     {
109 
110       public void actionPerformed(ActionEvent e)
111       {
112         nextButton_actionPerformed(e);
113       }
114     });
115 
116     helpButton.setText("Help");
117     helpButton.setBounds(new Rectangle(500, 360, 75, 30));
118     helpButton.addActionListener(new java.awt.event.ActionListener()
119     {
120 
121       public void actionPerformed(ActionEvent e)
122       {
123         helpButton_actionPerformed(e);
124       }
125     });
126 
127     scriptSourceFieldLabel.setText("Please enter name of next script source file");
128     scriptSourceFieldLabel.setBounds(new Rectangle(25, 285, 450, 25));
129     scriptSourceField.setBounds(new Rectangle(25, 310, 400, 25));
130     scriptSourceField.addKeyListener(new java.awt.event.KeyListener() {
131       public void keyPressed(KeyEvent e) {}
132       public void keyTyped(KeyEvent e) {}
133       public void keyReleased(KeyEvent e) {
134         if (e.getKeyCode()==KeyEvent.VK_ENTER) {
135           addScriptSourceButton_actionPerformed(null);
136         }
137       }
138     });
139 
140     chooseScriptSourceButton.setText("...");
141     chooseScriptSourceButton.setBounds(new Rectangle(425, 310, 25, 25));
142     chooseScriptSourceButton.addActionListener(new java.awt.event.ActionListener()
143     {
144 
145       public void actionPerformed(ActionEvent e)
146       {
147         chooseScriptSourceButton_actionPerformed(e);
148       }
149     });
150     addScriptSourceButton.setText("Add");
151     addScriptSourceButton.setBounds(new Rectangle(475, 310, 100, 25));
152     addScriptSourceButton.addActionListener(new java.awt.event.ActionListener()
153     {
154 
155       public void actionPerformed(ActionEvent e)
156       {
157         addScriptSourceButton_actionPerformed(e);
158       }
159     });
160 
161     scriptListLabel.setText("Script source files");
162     scriptListLabel.setBounds(new Rectangle(25, 15, 450, 25));
163     scriptListScrollPane.setBounds(new Rectangle(25, 40, 425, 230));
164     scriptSourceList.addKeyListener(new java.awt.event.KeyListener() {
165       public void keyPressed(KeyEvent e) {}
166       public void keyTyped(KeyEvent e) {}
167       public void keyReleased(KeyEvent e) {
168         if (e.getKeyChar()=='+') {
169           downButton_actionPerformed(null);
170         }
171         if (e.getKeyChar()=='-') {
172           upButton_actionPerformed(null);
173         }
174       }
175     });
176 
177     upButton.setText("Up");
178     upButton.setBounds(new Rectangle(475, 40, 100, 25));
179     upButton.addActionListener(new java.awt.event.ActionListener()
180     {
181 
182       public void actionPerformed(ActionEvent e)
183       {
184         upButton_actionPerformed(e);
185       }
186     });
187     downButton.setText("Down");
188     downButton.setBounds(new Rectangle(475, 80, 100, 25));
189     downButton.addActionListener(new java.awt.event.ActionListener()
190     {
191 
192       public void actionPerformed(ActionEvent e)
193       {
194         downButton_actionPerformed(e);
195       }
196     });
197 
198     removeButton.setText("Remove");
199     removeButton.setBounds(new Rectangle(475, 245, 100, 25));
200     removeButton.addActionListener(new java.awt.event.ActionListener()
201     {
202 
203       public void actionPerformed(ActionEvent e)
204       {
205         removeButton_actionPerformed(e);
206       }
207     });
208 
209     quitButton.setText("Quit");
210     quitButton.setBounds(new Rectangle(25, 360, 150, 30));
211     quitButton.addActionListener(new java.awt.event.ActionListener()
212     {
213 
214       public void actionPerformed(ActionEvent e)
215       {
216         quitButton_actionPerformed(e);
217       }
218     });
219 
220     this.add(prevButton, null);
221     this.add(nextButton, null);
222     this.add(helpButton, null);
223     this.add(quitButton, null);
224     this.add(scriptSourceField, null);
225     this.add(chooseScriptSourceButton, null);
226     this.add(scriptListScrollPane, null);
227     this.add(addScriptSourceButton, null);
228     this.add(scriptSourceFieldLabel, null);
229     this.add(scriptListLabel, null);
230     this.add(upButton, null);
231     this.add(downButton, null);
232     this.add(removeButton, null);
233     scriptListScrollPane.getViewport().add(scriptSourceList, null);
234 
235   }
236 
237   /** Updates the look&feel of the given component. Subcomponents are
238     * recursively updated.
239     *
240     * @param component the component to update its look&feel
241     */
242   protected void updateComponentUI(JComponent component) {
243     component.updateUI();
244     Component[] components = component.getComponents();
245     for (int i=0; i<components.length; i++) {
246       if(components[i] instanceof JComponent) {
247         updateComponentUI((JComponent) components[i]);
248       }
249     }
250   }
251 
252   /** Updates labels of all buttons */
253   protected void updateLabels() {
254     quitButton.setText(CodeMapper.getText(LabelCode.QUIT_BUTTON));
255     helpButton.setText(CodeMapper.getText(LabelCode.HELP_BUTTON));
256     prevButton.setText(CodeMapper.getText(LabelCode.PREVIOUS_BUTTON));
257     nextButton.setText(CodeMapper.getText(LabelCode.NEXT_BUTTON));
258     upButton.setText(CodeMapper.getText(LabelCode.UP_BUTTON));
259     downButton.setText(CodeMapper.getText(LabelCode.DOWN_BUTTON));
260     removeButton.setText(CodeMapper.getText(LabelCode.REMOVE_BUTTON));
261     addScriptSourceButton.setText(CodeMapper.getText(LabelCode.ADD_BUTTON));
262     scriptSourceFieldLabel.setText(CodeMapper.getText(LabelCode.SCRIPTTEXTFIELD_LABEL));
263     scriptListLabel.setText(CodeMapper.getText(LabelCode.SCRIPTLIST_LABEL));
264   }
265 
266   public void updateAll() {
267     updateLabels();
268     updateComponentUI(this);
269   }
270 
271   public void setWindowTitle() {
272     if(mainWindow!=null) mainWindow.setTitle(CodeMapper.getText(LabelCode.SCRIPTCHOOSE_TITLE));
273   }
274 
275   public boolean panelActivated(boolean fromPreviousPanel) {
276     if (fromPreviousPanel) {
277       if (mainWindow.getCurrentProject().getScriptSources()!=null &&
278           mainWindow.getCurrentProject().hasChanged()) {
279         Vector newScriptSources = mainWindow.getCurrentProject().getScriptSources();
280         Vector newIsParsedVector = new Vector(newScriptSources.size());
281         newIsParsedVector.setSize(newScriptSources.size());
282         for (int j=0; j<newScriptSources.size(); j++) {
283           if (newScriptSources.elementAt(j)==null) continue;
284           String scriptSourceFile = (String) newScriptSources.elementAt(j);
285           int index = scriptSources.indexOf(scriptSourceFile);
286           if (index!=-1 && ((Boolean)isParsedVector.elementAt(index)).booleanValue()) {
287             newIsParsedVector.setElementAt(new Boolean(true), j);
288           }
289           else {
290             newIsParsedVector.setElementAt(new Boolean(false), j);
291           }
292         }
293         this.scriptSources = newScriptSources;
294         this.isParsedVector = newIsParsedVector;
295         scriptSourceList.setListData(scriptSources);
296         scriptSourceField.setText("");
297       }
298     }
299     setWindowTitle();
300     return false;
301   }
302 
303   /** Called if panel is to be deactivated. If switching to next panel, the
304     * script source files are parsed (if not done before).
305     *
306     * @param toNextPanel true if switching to next panel, false otherwise
307     * @return true, if an error occured (for example a parse error), false otherwise
308     */
309   public boolean panelDeactivated(boolean toNextPanel) {
310 
311     // if switching to previous panel, no veto checking is needed
312     if (!toNextPanel) return false;
313 
314     final ProjectConfig config = mainWindow.getCurrentProject();
315     if (config==null) {
316       Main.err.println("No config object available!");
317       return false;
318     }
319 
320     veto = false;
321     warningsText = "";
322 
323     mainWindow.setWaitCursor();
324 
325     if (mainWindow.isQuietMode()) {
326       Main.messages.println("Parsing script files...");
327       veto = parseSelectedFiles(null, config);
328     }
329     else {
330       final ModalProgressFrame progressFrame = new ModalProgressFrame(mainWindow,"Progress",true);
331       Thread parseThread = new Thread(new Runnable() {
332           public void run() {
333             veto = parseSelectedFiles(progressFrame, config);
334             progressFrame.dispose();
335           } // run()
336         }); // new Thread();
337 
338       parseThread.start();
339       progressFrame.show();
340     }
341 
342     mainWindow.setDefaultCursor();
343     if (warningsText!=null && !warningsText.equals("")) {
344       String warningTitle = CodeMapper.getText(LabelCode.WARNING_LABEL);
345       MessageDialog dlg = new MessageDialog(mainWindow,warningTitle, true);
346       dlg.setMessage(warningsText,true);
347       if (!mainWindow.isQuietMode()) dlg.show();
348       else Main.err.println(warningsText);
349     }
350     unparsedFilesCount = 0;
351     config.setScriptSources(scriptSources);
352     return veto;
353   }
354 
355   /** Parses selected script source files.
356     *
357     * @param progressFrame a progress frame to show progress of parsing activity
358     * @param config the project to store parsed scripts in
359     * @return true, if an error occured (veto), false otherwise
360     */
361   private boolean parseSelectedFiles(ModalProgressFrame progressFrame, ProjectConfig config) {
362     boolean result = false;
363     SourceFile sourceFile;
364     double step = 0;
365     double numberOfSteps = (double) unparsedFilesCount;
366     if (unparsedFilesCount==0) numberOfSteps = 1.0;
367 
368     for (int i=0; i<scriptSources.size(); i++) {
369       String fileName = (String) scriptSources.elementAt(i);
370       if (fileName!=null) {
371 
372         fileName = GlobalSettings.getAbsolutePath(config.getProjectPath(), fileName);
373 
374         Boolean bool = (Boolean) isParsedVector.elementAt(i);
375 
376         // if file is parsed before, then check if modified
377         if (bool.booleanValue()) {
378           File file = new File(fileName);
379           sourceFile = (SourceFile) parsedScriptFiles.get(fileName);
380           if(sourceFile!=null) {
381             if(sourceFile.getTimestamp()!=file.lastModified()) {
382               Main.messages.println("Reloading file '"+fileName+"'");
383               bool = new Boolean(false);
384               parsedScriptFiles.remove(fileName);
385               Vector scripts = sourceFile.getScriptDeclarations();
386               Enumeration enum = scripts.elements();
387               while (enum.hasMoreElements()) {
388                 ScriptDeclaration temp = (ScriptDeclaration) enum.nextElement();
389                 config.removeScript(temp.getName());
390               }
391               unparsedFilesCount = unparsedFilesCount + 1;
392             }
393           }
394         }
395 
396         // if false isn't parsed before, then parse it now
397         if(!bool.booleanValue()) {
398           String progressText = CodeMapper.getText(LabelCode.PARSINGFILE_LABEL);
399           progressText = StringUtil.replace(progressText,"%1",fileName);
400           if (progressFrame!=null) progressFrame.setMessageText(progressText);
401           sourceFile = parseFile(fileName);
402           step = step + 1.0;
403           if (progressFrame!=null) progressFrame.setProgressBar(100.0 * step/numberOfSteps);
404           if (sourceFile!=null) {
405             Vector scripts = sourceFile.getScriptDeclarations();
406             Enumeration scriptEnum = scripts.elements();
407             while (scriptEnum.hasMoreElements()) {
408               ScriptDeclaration temp = (ScriptDeclaration) scriptEnum.nextElement();
409               config.addScript(temp);
410             }
411             isParsedVector.setElementAt(new Boolean(true),i);
412             parsedScriptFiles.put(fileName,sourceFile);
413             unparsedFilesCount = unparsedFilesCount - 1;
414           }
415           else {
416             //if a file can't be parsed, then veto against switching to next panel
417             return true;
418           }
419         }
420       }
421     }
422     // no errors occured
423     return false;
424   }
425 
426   void prevButton_actionPerformed(ActionEvent e)
427   {
428     mainWindow.switchToPrevious();
429   }
430 
431   void nextButton_actionPerformed(ActionEvent e)
432   {
433     mainWindow.switchToNext();
434   }
435 
436   void chooseScriptSourceButton_actionPerformed(ActionEvent e)
437   {
438     JFileChooser fileChooser;
439     if (GlobalSettings.scriptBaseDir!=null) fileChooser = new JFileChooser(GlobalSettings.scriptBaseDir);
440     else fileChooser = new JFileChooser();
441     InjectJFileFilter fileFilter = new InjectJFileFilter("ij",
442       CodeMapper.getText(LabelCode.SCRIPTFILE_DESCRIPT));
443     fileChooser.addChoosableFileFilter(fileFilter);
444     fileChooser.setFileFilter(fileFilter);
445     fileChooser.setMultiSelectionEnabled(false);
446     fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
447 
448     int result = fileChooser.showOpenDialog(this);
449     if (result==JFileChooser.APPROVE_OPTION) {
450       File file = fileChooser.getSelectedFile();
451       if(file.isDirectory()) return;
452       String name = null;
453       if (file.exists() && file.isFile()) {
454         try {
455           name = file.getCanonicalPath();
456         }
457         catch (IOException ioe) {
458           ioe.printStackTrace();
459         }
460       }
461       name = name.replace('\\','/');
462       if(name!=null && (!name.equals(""))) {
463         scriptSourceField.setText(name);
464         addScriptSourceButton_actionPerformed(null);
465       }
466     }
467   }
468 
469   void addScriptSourceButton_actionPerformed(ActionEvent e)
470   {
471     String fileName = scriptSourceField.getText();
472     if (fileName==null) return;
473     fileName.trim();
474     if (fileName.equals("")) return;
475 
476     // Check if filename represents a real file
477     File file = new File(fileName);
478     if (!file.exists()) {
479       String errorTitle = CodeMapper.getText(LabelCode.ERROR_LABEL);
480       MessageDialog dlg = new MessageDialog(mainWindow,errorTitle,true);
481       String msgText = CodeMapper.getText(ErrorCode.FILENOTEXISTS_ERROR);
482       msgText = StringUtil.replace(msgText,"%1",fileName);
483       dlg.setMessage(msgText,false);
484       dlg.show();
485       scriptSourceField.selectAll();
486       return;
487     }
488     if (!file.isFile()) {
489       String errorTitle = CodeMapper.getText(LabelCode.ERROR_LABEL);
490       MessageDialog dlg = new MessageDialog(mainWindow,errorTitle,true);
491       String msgText = CodeMapper.getText(ErrorCode.FILEISNOTREADABLE_ERROR);
492       msgText = StringUtil.replace(msgText,"%1",fileName);
493       dlg.setMessage(msgText, false);
494       dlg.show();
495       scriptSourceField.selectAll();
496       return;
497     }
498 
499     String rootPath = null;
500     if (mainWindow.getCurrentProject()!=null) {
501       rootPath = mainWindow.getCurrentProject().getProjectPath();
502     }
503 
504     fileName = GlobalSettings.getRelativePath(rootPath, fileName);
505 
506     boolean updateList = false;
507     if (!scriptSources.contains(fileName)) {
508       scriptSources.addElement(fileName);
509       isParsedVector.addElement(new Boolean(false));
510       unparsedFilesCount = unparsedFilesCount + 1;
511       updateList = true;
512     }
513     if (updateList) {
514       scriptSourceList.setListData(scriptSources);
515       scriptSourceField.setText("");
516       mainWindow.getCurrentProject().setChanged();
517     }
518     else {
519       scriptSourceField.selectAll();
520     }
521   }
522 
523   void upButton_actionPerformed(ActionEvent e)
524   {
525     boolean canMove = true;
526     int lastIndex = 0;
527     int indices[] = scriptSourceList.getSelectedIndices();
528     int toBeSelected[] = new int[indices.length];
529     for (int i=0; i<indices.length; i++) {
530       int index = indices[i];
531       if (index==0) {
532         canMove = false;
533         lastIndex = index;
534         toBeSelected[i] = index;
535         continue;
536       }
537       if (!canMove && ((lastIndex+1)==index) ) {
538         lastIndex = index;
539         toBeSelected[i] = index;
540         continue;
541       }
542       canMove = true;
543       Object temp = scriptSources.elementAt(index-1);
544       Object bool = isParsedVector.elementAt(index-1);
545       scriptSources.setElementAt(scriptSources.elementAt(index), index-1);
546       scriptSources.setElementAt(temp, index);
547       isParsedVector.setElementAt(isParsedVector.elementAt(index), index-1);
548       isParsedVector.setElementAt(bool, index);
549       toBeSelected[i] = index-1;
550     }
551     scriptSourceList.setListData(scriptSources);
552     scriptSourceList.setSelectedIndices(toBeSelected);
553     mainWindow.getCurrentProject().setChanged();
554   }
555 
556   void downButton_actionPerformed(ActionEvent e)
557   {
558     boolean canMove = true;
559     int lastIndex = scriptSources.size();
560     int indices[] = scriptSourceList.getSelectedIndices();
561     int toBeSelected[] = new int[indices.length];
562     for (int i=indices.length-1; i>=0; i--) {
563       int index = indices[i];
564       if (index>=scriptSources.size()-1) {
565         canMove=false;
566         lastIndex = index;
567         toBeSelected[i] = index;
568         continue;
569       }
570       if (!canMove && ((lastIndex-1) == index)) {
571         lastIndex = index;
572         toBeSelected[i] = index;
573         continue;
574       }
575 
576       canMove = true;
577       Object temp = scriptSources.elementAt(index+1);
578       Object bool = isParsedVector.elementAt(index+1);
579       scriptSources.setElementAt(scriptSources.elementAt(index), index+1);
580       scriptSources.setElementAt(temp, index);
581       isParsedVector.setElementAt(isParsedVector.elementAt(index), index+1);
582       isParsedVector.setElementAt(bool, index);
583       toBeSelected[i] = index+1;
584     }
585 
586     scriptSourceList.setListData(scriptSources);
587     scriptSourceList.setSelectedIndices(toBeSelected);
588     mainWindow.getCurrentProject().setChanged();
589   }
590 
591   void removeButton_actionPerformed(ActionEvent e)
592   {
593     Object selectedValues[] = scriptSourceList.getSelectedValues();
594     ProjectConfig config = mainWindow.getCurrentProject();
595     if (config==null) {
596       Main.err.println("Can't remove file: No config object");
597       return;
598     }
599     for (int i=0; i<selectedValues.length; i++) {
600       Object selectedObject = selectedValues[i];
601       int index = scriptSources.indexOf(selectedObject);
602       String scriptFileName = (String) scriptSources.elementAt(index);
603       scriptSources.removeElementAt(index);
604       Boolean isParsed = (Boolean) isParsedVector.elementAt(index);
605       isParsedVector.removeElementAt(index);
606       if (isParsed.booleanValue()) {
607         SourceFile sourceFile = (SourceFile) parsedScriptFiles.get(scriptFileName);
608         Vector scripts = sourceFile.getScriptDeclarations();
609         Enumeration enum = scripts.elements();
610         while (enum.hasMoreElements()) {
611           ScriptDeclaration temp = (ScriptDeclaration) enum.nextElement();
612           config.removeScript(temp.getName());
613         }
614         parsedScriptFiles.remove(scriptFileName);
615       }
616       else {
617         unparsedFilesCount = unparsedFilesCount - 1;
618       }
619     }
620     scriptSourceList.setListData(scriptSources);
621     mainWindow.getCurrentProject().setChanged();
622   }
623 
624   /** Parses the given script file
625     *
626     * @param filename the file to parse
627     * @return the parsed AST of the script source file, or null if an error occured
628     */
629   protected SourceFile parseFile(String filename) {
630 
631     Main.messages.println("Parsing script file '"+filename+"'");
632     InputStream preProcessorOutput;
633     // PreProcessor
634     try {
635       PreProcessorParser preProcessor = GlobalSettings.getPreProcessor(new FileInputStream(filename));
636       preProcessorOutput = preProcessor.preProcess();
637       String warningText = "";
638       Enumeration enum = preProcessor.getWarnings();
639       if (enum.hasMoreElements()) {
640         warningText = CodeMapper.getText(LabelCode.INFILE_LABEL);
641         warningText = " "+StringUtil.replace(warningText,"%1",filename)+"\n";
642       }
643       while(enum.hasMoreElements()) {
644         Warning warning = (Warning) enum.nextElement();
645         warningText = warningText + StringUtil.insertSpaceAtLineBegin(warning.getMessage(),4)+"\n";
646       }
647       if (!warningText.equals("")) {
648         warningsText = warningsText + warningText;
649       }
650     }
651     catch (FileNotFoundException e) {
652       Main.err.println("Preprocessor:  File "+filename+" not found.");
653       return null;
654     }
655     catch (fzi.injectj.preprocessor.ParseException e) {
656       String errorTitle = CodeMapper.getText(LabelCode.ERROR_LABEL);
657       String introText = CodeMapper.getText(ErrorCode.PP_ERROR_INTRO);
658       MessageDialog dlg = new MessageDialog(mainWindow,errorTitle,true);
659       dlg.setMessage(introText+"\n"+e.getMessage(), true);
660       dlg.show();
661       return null;
662     }
663     catch (PreProcessorException e) {
664       String errorTitle = CodeMapper.getText(LabelCode.ERROR_LABEL);
665       String introText = CodeMapper.getText(ErrorCode.PP_ERROR_INTRO);
666       MessageDialog dlg = new MessageDialog(mainWindow,errorTitle,true);
667       dlg.setMessage(introText+"\n"+e.getMessage(), true);
668       dlg.show();
669       return null;
670     }
671     catch (Exception e) {
672       Main.err.println("Exception during preprocessing:\n"+e.getMessage());
673       e.printStackTrace();
674       return null;
675     }
676 
677     // Parser
678     ScriptParser parser = null;
679     try {
680       parser = GlobalSettings.getParser(preProcessorOutput);
681       SourceFile parsedFile = parser.parse();
682       File file = new File(filename);
683       parsedFile.setTimestamp(file.lastModified());
684       return parsedFile;
685     }
686     catch (fzi.injectj.parser.ParseException e) {
687       String errorTitle = CodeMapper.getText(LabelCode.ERROR_LABEL);
688       String introText = CodeMapper.getText(ErrorCode.P_ERROR_INTRO);
689       MessageDialog dlg = new MessageDialog(mainWindow,errorTitle,true);
690       dlg.setMessage(introText+"\n"+e.getMessage(), false);
691       dlg.show();
692     }
693     catch (Exception e) {
694       Main.err.println("Exception during parse:\n"+e.getMessage());
695       e.printStackTrace();
696     }
697     catch (Error e) {
698       Main.err.println(e.getMessage());
699       Main.err.println("Parser:  Encountered errors during parse (line "+parser.getLastLine()+").");
700     }
701     return null;
702  }
703 
704   void helpButton_actionPerformed(ActionEvent e)
705   {
706     mainWindow.showHelp();
707   }
708 
709   void quitButton_actionPerformed(ActionEvent e)
710   {
711     if(mainWindow!=null) mainWindow.dispose();
712     mainWindow.exit();
713   }
714 
715   public String helpFilename() {
716     return "scriptsources.html";
717   }
718 
719 }