C:\Java WorkShop\Lexx\src\lexx\gui\EditorFrame.java

1    package lexx.gui; 
2     
3    import java.io.File; 
4    import java.util.List; 
5     
6    import java.awt.BorderLayout; 
7    import java.awt.Component; 
8    import java.awt.Dimension; 
9    import java.awt.Graphics; 
10   import java.awt.Image; 
11   import java.awt.event.ActionEvent; 
12   import java.awt.event.ActionListener; 
13   import java.awt.event.MouseEvent; 
14   import java.awt.event.MouseListener; 
15   import java.awt.event.WindowAdapter; 
16   import java.awt.event.WindowEvent; 
17   import javax.swing.ImageIcon; 
18   import javax.swing.JButton; 
19   import javax.swing.JCheckBoxMenuItem; 
20   import javax.swing.JFrame; 
21   import javax.swing.JLabel; 
22   import javax.swing.JMenu; 
23   import javax.swing.JMenuBar; 
24   import javax.swing.JMenuItem; 
25   import javax.swing.JOptionPane; 
26   import javax.swing.JPanel; 
27   import javax.swing.JPopupMenu; 
28   import javax.swing.JScrollPane; 
29   import javax.swing.JSplitPane; 
30   import javax.swing.JTabbedPane; 
31   import javax.swing.JTextPane; 
32   import javax.swing.JToggleButton; 
33   import javax.swing.JToolBar; 
34   import javax.swing.JTree; 
35   import javax.swing.event.DocumentEvent; 
36   import javax.swing.event.DocumentListener; 
37   import javax.swing.event.TreeSelectionEvent; 
38   import javax.swing.event.TreeSelectionListener; 
39   import javax.swing.text.StyledDocument; 
40   import javax.swing.tree.DefaultMutableTreeNode; 
41    
42   import de.calcom.cclib.text.FindReplaceDialog; 
43   import de.calcom.cclib.text.FindReplaceEvent; 
44   import de.calcom.cclib.text.FindReplaceListener; 
45   import lexx.api.ClassName; 
46   import lexx.api.JavaPackages; 
47   import lexx.api.Packages; 
48   import lexx.gui.editor.EditorPanel; 
49   import lexx.images.Icons; 
50   import lexx.oldversion.parser.JavaParser; 
51   import lexx.oldversion.parser.Line; 
52   import lexx.oldversion.parser.NestCode; 
53   import lexx.oldversion.syntax.SyntaxColours; 
54   import lexx.parser.ParserListener; 
55   import lexx.plugins.ant.ShowJava; 
56   import lexx.plugins.refactory.Refactory; 
57   import lexx.utils.Config; 
58    
59   /** 
60    * <p>The main screen (GUI) for the Lexx IDE</p> 
61    * <p>This method handles the GUI for nearly all the modules </p> 
62    * <p>Copyright (c) 2002-2003</p> 
63    * @since 20/03/2003 
64    * @author Mohammed Imran 
65    * @version 1.0 
66    */ 
67   public final class EditorFrame extends JFrame implements ShowJava 
68   { 
69     private static final org.apache.log4j.Logger log = org.apache.log4j.Logger. 
70         getLogger(EditorFrame.class); 
71    
72     private final JTabbedPane tabPane = new JTabbedPane(); 
73     private final PMD pmd = new PMD(this); 
74     private lexx.gui.run.RunPanel runPanel = null; 
75     private final JTabbedPane lowerTabPane = new JTabbedPane(); 
76     private final JPanel toolPanel = new JPanel(); 
77     private final JButton openButton = new JButton(Icons.getImageIcon("open.gif")); 
78     private final lexx.plugins.javadoc.JavadocViewer docViewer = new lexx.plugins. 
79         javadoc.JavadocViewer(); 
80     private final JButton saveButton = new JButton(Icons.getImageIcon("save.gif")); 
81     private final JButton redoButton = new JButton(Icons.getImageIcon( 
82         "Redo24.gif")); 
83     private final JButton undoButton = new JButton(Icons.getImageIcon( 
84         "Undo24.gif")); 
85     private final JButton classMapButton = new JButton(Icons.getImageIcon( 
86         "Search24.gif")); 
87     private final JMenuBar menuBar = new JMenuBar(); 
88     private lexx.plugins.ant.BuildProject build = null; 
89    
90     private JTree tree; //used in debugging or for showing files in source code 
91     private Packages pack; 
92     private final JPanel sidePanel = new JPanel(new BorderLayout()); 
93     private final JPanel statusBar = new JPanel(new BorderLayout()); 
94     private final JLabel statusLabel = new JLabel(""); 
95     private final JToggleButton debugAST = new JToggleButton(); 
96     private final JButton compileButton = new JButton(Icons.getImageIcon( 
97         "Application24.gif")); 
98     private final JButton rebuildButton = new JButton(Icons.getImageIcon( 
99         "ApplicationDeploy24.gif")); 
100    private String projectPath = null; 
101    private final JButton saveAllButton = new JButton(Icons.getImageIcon( 
102        "SaveAll24.gif")); 
103    private final JButton javadocButton = new JButton(Icons.getImageIcon( 
104        "dukebook.gif")); 
105    private final JMenu fileMenu = new JMenu(); 
106    private final JMenuItem exitMenu = new JMenuItem(Icons.getImageIcon( 
107        "close.png")); 
108    private final JMenu helpMenu = new JMenu(); 
109    private final JMenuItem aboutMenu = new JMenuItem(Icons.getImageIcon( 
110        "About24.gif")); 
111    private final JButton newButton = new JButton(Icons.getImageIcon("new.gif")); 
112    private final JToggleButton loggerButton = new JToggleButton(Icons. 
113        getImageIcon("dukeSnooze.gif")); 
114    private final JButton refactoryButton = new JButton(Icons.getImageIcon( 
115        "duke2.gif")); 
116    private final JButton copyButton = new JButton(Icons.getImageIcon("copy.gif")); 
117    private final JButton pasteButton = new JButton(Icons.getImageIcon( 
118        "paste.gif")); 
119    private final JButton cutButton = new JButton(Icons.getImageIcon("cut.gif")); 
120    private final JMenuItem newMenu = new JMenuItem(Icons.getImageIcon("new.gif")); 
121    private final JMenuItem importMenu = new JMenuItem(Icons.getImageIcon( 
122        "open.gif")); 
123    private final JMenuItem saveMenu = new JMenuItem(Icons.getImageIcon( 
124        "save.gif")); 
125    private final JMenuItem saveAllMenu = new JMenuItem(Icons.getImageIcon( 
126        "SaveAll24.gif")); 
127    private final JMenuItem closeMenu = new JMenuItem(Icons.getImageIcon( 
128        "Error.gif")); 
129    private final JMenuItem closeMenuCopy = new JMenuItem(Icons.getImageIcon( 
130        "Error.gif")); 
131    private final JMenu editMenu = new JMenu(); 
132    private final JMenuItem undoMenu = new JMenuItem(Icons.getImageIcon( 
133        "Undo24.gif")); 
134    private final JMenuItem redoMenu = new JMenuItem(Icons.getImageIcon( 
135        "Redo24.gif")); 
136    private final JMenuItem cutMenu = new JMenuItem(Icons.getImageIcon("cut.gif")); 
137    private final JMenuItem copyMenu = new JMenuItem(Icons.getImageIcon( 
138        "copy.gif")); 
139    private final JMenuItem pasteMenu = new JMenuItem(Icons.getImageIcon( 
140        "paste.gif")); 
141    private final JMenuItem selectAllMenu = new JMenuItem(); 
142    private final JMenu viewMenu = new JMenu(); 
143    private final JCheckBoxMenuItem showTextMenu = new JCheckBoxMenuItem(); 
144    private final JMenu runMenu = new JMenu(); 
145    private final JMenuItem compileMenu = new JMenuItem(Icons.getImageIcon( 
146        "Application24.gif")); 
147    private final JMenuItem rebuildMenu = new JMenuItem(Icons.getImageIcon( 
148        "ApplicationDeploy24.gif")); 
149    private final JMenuItem runJavaMenu = new JMenuItem(Icons.getImageIcon( 
150        "Play24.gif")); 
151    private final JMenuItem debugMenu = new JMenuItem(Icons.getImageIcon( 
152        "StepForward24.gif")); 
153    private final JMenuItem javadocMenu = new JMenuItem(Icons.getImageIcon( 
154        "dukebook.gif")); 
155    private final JMenu runnableFileMenu = new JMenu(); 
156    private final JMenu advanceMenu = new JMenu(); 
157    private final JMenuItem loggerMenu = new JMenuItem(Icons.getImageIcon( 
158        "dukeSnooze.gif")); 
159    private final JMenuItem classMapMenu = new JMenuItem(Icons.getImageIcon( 
160        "Search24.gif")); 
161    private final JMenuItem refreshMenu = new JMenuItem(Icons.getImageIcon( 
162        "Refresh24.gif")); 
163    private final JMenuItem refactorMenu = new JMenuItem(Icons.getImageIcon( 
164        "duke2.gif")); 
165    final static JMenu otherThemeMenu = new JMenu(); 
166    private final JButton styleButton = new JButton(Icons.getImageIcon( 
167        "Edit24.gif")); 
168    private final JMenuItem styleMenu = new JMenuItem(Icons.getImageIcon( 
169        "Edit24.gif")); 
170    private final JButton findButton = new JButton(Icons.getImageIcon( 
171        "Find24.gif")); 
172    private final JMenuItem findMenu = new JMenuItem(Icons.getImageIcon( 
173        "Find24.gif")); 
174    private final JCheckBoxMenuItem beepMenuItem = new JCheckBoxMenuItem(); 
175   
176    private void cut() 
177    { 
178      if(this.getEditorPanel() != null) 
179      { 
180        this.getEditorPanel().getTextPane().cut(); 
181      } 
182    } 
183   
184    private void paste() 
185    { 
186      if(this.getEditorPanel() != null) 
187      { 
188        this.getEditorPanel().getTextPane().paste(); 
189      } 
190    } 
191   
192    private void copy() 
193    { 
194      if(this.getEditorPanel() != null) 
195      { 
196        this.getEditorPanel().getTextPane().copy(); 
197      } 
198    } 
199   
200    /** 
201     * Used to compile work or produce java doc 
202     * @return BuildProject which is also a GUI component 
203     */ 
204    public final lexx.plugins.ant.BuildProject getBuild() 
205    { 
206      return build; 
207    } 
208   
209    /** 
210     * Sets up the GUI 
211     * @param configFile the file name containing the configuration of the project 
212     * the file should be end with config.lexx 
213     * @param packages required for autocompletion 
214     */ 
215    public EditorFrame(String configFile, Packages packages) 
216    { 
217      super("Lexx IDE"); 
218      this.setSize( (int)this.getToolkit().getScreenSize().getWidth(), 
219                   (int)this.getToolkit().getScreenSize().getHeight() - 30); 
220   
221      try 
222      { 
223        Config.setupConfig(configFile, statusLabel, this); 
224        Config.setPackages(packages); 
225        pack = packages; 
226        projectPath = lexx.utils.Config.getProjectPath(); 
227        lexx.trie.TrieNode.clearMutableObjectList(); 
228        build = new lexx.plugins.ant.BuildProject(this); 
229  //    lexx.trie.TrieDebug.showTree(pack.getObjectEnvironment() ); 
230  //    setupTree(); //used in debugging 
231        setup(); 
232   
233        lexx.plugins.javadoc.JavaDoc.setupJavaDoc(); 
234      } 
235      catch(Exception ex) 
236      { 
237        log.fatal(ex, ex); 
238      } 
239      //pack.setupTree(tree, this); //used to test the packages if it imported the classse correctly 
240   
241      this.check(); 
242      LookAndFeel.setupLook(this); 
243   
244      // how to maximise a frame -- help from http://www.rgagnon.com/javadetails/java-0222.html 
245      this.setExtendedState(JFrame.MAXIMIZED_BOTH); 
246      this.setVisible(true); 
247    } 
248   
249    /** 
250     * Converts a physical file to a full object name for example if you had the file 
251     * C:\javawork\src\tester\Test1.java this would convert it to tester.Test1 
252     * @param fullPath the filename 
253     * @param projectPath the directory the project is in 
254     * @return correct object name such as javax.swing.JFrame 
255     */ 
256    public static String getJavaName(String fullPath, String projectPath) 
257    { 
258      String s = ""; 
259   
260      for(int i = 0; i < fullPath.length(); i++) 
261      { 
262        if(fullPath.charAt(i) == '\\' || fullPath.charAt(i) == '/') 
263        { 
264          s += '.'; 
265        } 
266        else 
267        { 
268          s += fullPath.charAt(i); 
269        } 
270      } 
271      try 
272      { 
273        return s.substring(projectPath.length() + "/src/".length(), s.length()); 
274      } 
275      catch(Exception ex) 
276      { 
277        log.fatal(ex, ex); 
278        if(s.startsWith(".")) 
279        { 
280          return s.substring(2, s.length() - 2); 
281        } 
282        else 
283        { 
284          return s; 
285        } 
286      } 
287    } 
288   
289    /** 
290     * Converts a physical file to a full object name for example if you had the file 
291     * C:\javawork\build\tester\Test1.class this would convert it to tester.Test1 
292     * @param fullPath the filename 
293     * @param projectPath the directory the project is in 
294     * @return correct object name such as javax.swing.JFrame 
295     */ 
296    public static String getClassName(String fullPath, String projectPath) 
297    { 
298      String s = ""; 
299   
300      for(int i = 0; i < fullPath.length(); i++) 
301      { 
302        if(fullPath.charAt(i) == '\\' || fullPath.charAt(i) == '/') 
303        { 
304          s += '.'; 
305        } 
306        else 
307        { 
308          s += fullPath.charAt(i); 
309        } 
310      } 
311      try 
312      { 
313        return s.substring(projectPath.length() + "/build/".length(), s.length()); 
314      } 
315      catch(Exception ex) 
316      { 
317        log.fatal(ex, ex); 
318        if(s.startsWith(".")) 
319        { 
320          return s.substring(2, s.length() - 2); 
321        } 
322        else 
323        { 
324          return s; 
325        } 
326      } 
327    } 
328   
329    private void setup() throws Exception 
330    { 
331      this.setIconImage(Icons.getImage("dukebook.gif")); 
332   
333      saveButton.setEnabled(false); 
334      saveButton.setToolTipText("Save current file"); 
335      saveButton.addActionListener(new java.awt.event.ActionListener() 
336      { 
337        public void actionPerformed(ActionEvent e) 
338        { 
339          saveButton_actionPerformed(); 
340        } 
341      }); 
342      redoButton.setEnabled(false); 
343      redoButton.setToolTipText("Redo"); 
344      redoButton.addActionListener(new java.awt.event.ActionListener() 
345      { 
346        public void actionPerformed(ActionEvent e) 
347        { 
348          redoButton_actionPerformed(e); 
349        } 
350      }); 
351      undoButton.setEnabled(false); 
352      undoButton.setToolTipText("Undo"); 
353      undoButton.addActionListener(new java.awt.event.ActionListener() 
354      { 
355        public void actionPerformed(ActionEvent e) 
356        { 
357          undoButton_actionPerformed(e); 
358        } 
359      }); 
360      classMapButton.addActionListener(new java.awt.event.ActionListener() 
361      { 
362        public void actionPerformed(ActionEvent e) 
363        { 
364          classMapButton_actionPerformed(); 
365        } 
366      }); 
367   
368      debugAST.addActionListener(new java.awt.event.ActionListener() 
369      { 
370        public void actionPerformed(ActionEvent e) 
371        { 
372          debugAST_actionPerformed(); 
373        } 
374      }); 
375      compileButton.addActionListener(new java.awt.event.ActionListener() 
376      { 
377        public void actionPerformed(ActionEvent e) 
378        { 
379          compileButton_actionPerformed(); 
380        } 
381      }); 
382      rebuildButton.addActionListener(new java.awt.event.ActionListener() 
383      { 
384        public void actionPerformed(ActionEvent e) 
385        { 
386          rebuildButton_actionPerformed(); 
387        } 
388      }); 
389      saveAllButton.addActionListener(new java.awt.event.ActionListener() 
390      { 
391        public void actionPerformed(ActionEvent e) 
392        { 
393          saveAllButton_actionPerformed(); 
394        } 
395      }); 
396      javadocButton.addActionListener(new java.awt.event.ActionListener() 
397      { 
398        public void actionPerformed(ActionEvent e) 
399        { 
400          javadocButton_actionPerformed(); 
401        } 
402      }); 
403      this.setJMenuBar(menuBar); 
404      fileMenu.setMnemonic('F'); 
405      fileMenu.setText("File"); 
406      exitMenu.setMnemonic('X'); 
407      exitMenu.setText("Exit"); 
408      exitMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(88, 
409          java.awt.event.KeyEvent.CTRL_MASK | java.awt.event.KeyEvent.ALT_MASK, false)); 
410   
411      this.addWindowListener(new WindowAdapter() 
412      { 
413        public void windowClosing(WindowEvent e) 
414        { 
415          close(); 
416        } 
417      }); 
418   
419      exitMenu.addActionListener(new java.awt.event.ActionListener() 
420      { 
421        public void actionPerformed(ActionEvent e) 
422        { 
423          close(); 
424        } 
425      }); 
426      helpMenu.setMnemonic('H'); 
427      helpMenu.setText("Help"); 
428      aboutMenu.setMnemonic('A'); 
429      aboutMenu.setText("About"); 
430      aboutMenu.addActionListener(new java.awt.event.ActionListener() 
431      { 
432        public void actionPerformed(ActionEvent e) 
433        { 
434          aboutMenu_actionPerformed(); 
435        } 
436      }); 
437      newButton.addActionListener(new java.awt.event.ActionListener() 
438      { 
439        public void actionPerformed(ActionEvent e) 
440        { 
441          newButton_actionPerformed(); 
442        } 
443      }); 
444   
445      loggerButton.addActionListener(new java.awt.event.ActionListener() 
446      { 
447        public void actionPerformed(ActionEvent e) 
448        { 
449          loggerButton_actionPerformed(); 
450        } 
451      }); 
452      refactoryButton.addActionListener(new java.awt.event.ActionListener() 
453      { 
454        public void actionPerformed(ActionEvent e) 
455        { 
456          refactoryButton_actionPerformed(); 
457        } 
458      }); 
459      copyButton.addActionListener(new java.awt.event.ActionListener() 
460      { 
461        public void actionPerformed(ActionEvent e) 
462        { 
463          copy(); 
464        } 
465      }); 
466      pasteButton.addActionListener(new java.awt.event.ActionListener() 
467      { 
468        public void actionPerformed(ActionEvent e) 
469        { 
470          paste(); 
471        } 
472      }); 
473      cutButton.addActionListener(new java.awt.event.ActionListener() 
474      { 
475        public void actionPerformed(ActionEvent e) 
476        { 
477          cut(); 
478        } 
479      }); 
480   
481      runPanel = new lexx.gui.run.RunPanel(projectPath, this, runnableFileMenu); 
482   
483      this.setToolbarText(); 
484   
485      toolPanel.removeAll(); 
486      JToolBar toolBar = new JToolBar(); 
487      openButton.addActionListener(new java.awt.event.ActionListener() 
488      { 
489        public void actionPerformed(ActionEvent e) 
490        { 
491          importMenu_actionPerformed(); 
492        } 
493      }); 
494      styleMenu.setMnemonic('S'); 
495      styleMenu.setText("Check Style Of Code"); 
496      styleMenu.addActionListener(new java.awt.event.ActionListener() 
497      { 
498        public void actionPerformed(ActionEvent e) 
499        { 
500          styleButton_actionPerformed(); 
501        } 
502      }); 
503      styleButton.addActionListener(new java.awt.event.ActionListener() 
504      { 
505        public void actionPerformed(ActionEvent e) 
506        { 
507          styleButton_actionPerformed(); 
508        } 
509      }); 
510      findButton.addActionListener(new java.awt.event.ActionListener() 
511      { 
512        public void actionPerformed(ActionEvent e) 
513        { 
514          findButton_actionPerformed(); 
515        } 
516      }); 
517      findMenu.setMnemonic('F'); 
518      findMenu.setText("Find/Replace"); 
519      findMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(70, 
520          java.awt.event.KeyEvent.CTRL_MASK, false)); 
521      findMenu.addActionListener(new java.awt.event.ActionListener() 
522      { 
523        public void actionPerformed(ActionEvent e) 
524        { 
525          findButton_actionPerformed(); 
526        } 
527      }); 
528      importMenu.setMnemonic('O'); 
529      importMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(79, 
530          java.awt.event.KeyEvent.CTRL_MASK, false)); 
531      newMenu.setMnemonic('N'); 
532      newMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78, 
533          java.awt.event.KeyEvent.CTRL_MASK, false)); 
534      saveMenu.setMnemonic('S'); 
535      saveMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(83, 
536          java.awt.event.KeyEvent.CTRL_MASK, false)); 
537      closeMenu.setMnemonic('C'); 
538      closeMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(67, 
539          java.awt.event.KeyEvent.CTRL_MASK | java.awt.event.KeyEvent.ALT_MASK, false)); 
540      saveAllMenu.setMnemonic('A'); 
541      editMenu.setMnemonic('E'); 
542      undoMenu.setMnemonic('U'); 
543      undoMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(90, 
544          java.awt.event.KeyEvent.CTRL_MASK, false)); 
545      redoMenu.setMnemonic('R'); 
546      redoMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(89, 
547          java.awt.event.KeyEvent.CTRL_MASK, false)); 
548      cutMenu.setMnemonic('U'); 
549      cutMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(88, 
550          java.awt.event.KeyEvent.CTRL_MASK, false)); 
551      copyMenu.setMnemonic('O'); 
552      copyMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(67, 
553          java.awt.event.KeyEvent.CTRL_MASK, false)); 
554      pasteMenu.setMnemonic('P'); 
555      pasteMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(86, 
556          java.awt.event.KeyEvent.CTRL_MASK, false)); 
557      selectAllMenu.setMnemonic('A'); 
558      selectAllMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(65, 
559          java.awt.event.KeyEvent.CTRL_MASK, false)); 
560      viewMenu.setMnemonic('V'); 
561      showTextMenu.setMnemonic('T'); 
562      LookAndFeel.lookAndFeel(this); 
563      compileMenu.setMnemonic('C'); 
564      compileMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(116, 0, false)); 
565      runMenu.setMnemonic('R'); 
566      rebuildMenu.setMnemonic('R'); 
567      rebuildMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(116, 
568          java.awt.event.KeyEvent.SHIFT_MASK, false)); 
569      runnableFileMenu.setMnemonic('F'); 
570      refreshMenu.setMnemonic('E'); 
571      refreshMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(115, 0, false)); 
572      runJavaMenu.setMnemonic('R'); 
573      runJavaMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(117, 0, false)); 
574      debugMenu.setMnemonic('D'); 
575      debugMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(118, 0, false)); 
576      javadocMenu.setMnemonic('J'); 
577      javadocMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(119, 0, false)); 
578      advanceMenu.setMnemonic('A'); 
579      loggerMenu.setMnemonic('L'); 
580      classMapMenu.setMnemonic('C'); 
581   
582      if(lexx.utils.Config.enableIncompleteComponents()) 
583      { 
584        refactorMenu.setMnemonic('R'); 
585      } 
586      beepMenuItem.addActionListener(new java.awt.event.ActionListener() 
587      { 
588        public void actionPerformed(ActionEvent e) 
589        { 
590          beepMenuItem_actionPerformed(); 
591        } 
592      }); 
593      beepMenuItem.setText("Beep On Errors"); 
594      toolPanel.add(toolBar); 
595   
596      toolBar.add(newButton, null); 
597      toolBar.add(openButton, null); 
598      toolBar.add(saveButton, null); 
599      toolBar.add(saveAllButton, null); 
600   
601      toolBar.addSeparator(); 
602      toolBar.add(undoButton, null); 
603      toolBar.add(redoButton, null); 
604      toolBar.add(copyButton, null); 
605      toolBar.add(pasteButton, null); 
606      toolBar.add(cutButton, null); 
607      toolBar.add(findButton, null); 
608   
609      toolBar.addSeparator(); 
610      toolBar.add(classMapButton, null); 
611      toolBar.add(loggerButton, null); 
612      if(lexx.utils.Config.isJDKInstalled() && 
613         lexx.utils.Config.enableIncompleteComponents()) 
614      { 
615        toolBar.add(refactoryButton, null); 
616      } 
617      toolBar.add(pmd.reviewButton, null); 
618   
619      if(lexx.utils.Config.enableIncompleteComponents()) 
620      { 
621        toolBar.add(styleButton, null); 
622      } 
623      toolBar.add(javadocButton, null); 
624   
625      toolBar.addSeparator(); 
626      toolBar.add(compileButton, null); 
627      toolBar.add(rebuildButton, null); 
628      toolBar.addSeparator(); 
629      toolBar.add(runPanel, null); 
630   
631      if(Config.isDebug()) 
632      { 
633        debugAST.setText("Debug AST"); 
634        toolBar.addSeparator(); 
635        toolBar.add(debugAST, null); 
636      } 
637   
638      newButton.setToolTipText("Create a new java file"); 
639      openButton.setToolTipText("Import java/class/jar file to project"); 
640      saveAllButton.setToolTipText("Save All files"); 
641      refactoryButton.setToolTipText( 
642          "This performs Refactorying. Achieved by using JREfactory"); 
643      copyButton.setToolTipText("Copy"); 
644      pasteButton.setToolTipText("Paste"); 
645      cutButton.setToolTipText("Cut"); 
646      classMapButton.setToolTipText( 
647          "Shows all java classes. If you click on a java class it will decompile " + 
648          "the code for you. Decompiling achieved by JODE"); 
649      loggerButton.setToolTipText( 
650          "To enable/disable logger which replaces the System.out with log. " + 
651          "Which can be used when you run your code. Achieved by using external " + 
652          "component LumberMill from http://traxel.com/lumbermill/"); 
653      javadocButton.setToolTipText("Compiles javadoc for your source code"); 
654      rebuildButton.setToolTipText("Compiles your work from scratch"); 
655      compileButton.setToolTipText("Compiles your work. Achieved by using Apache ANT from http://jakarta.apache.org/ant/"); 
656      debugAST.setToolTipText("Debug AST"); 
657      newMenu.setText("New"); 
658      newMenu.addActionListener(new java.awt.event.ActionListener() 
659      { 
660        public void actionPerformed(ActionEvent e) 
661        { 
662          newButton_actionPerformed(); 
663        } 
664      }); 
665      importMenu.setText("Import"); 
666      importMenu.addActionListener(new java.awt.event.ActionListener() 
667      { 
668        public void actionPerformed(ActionEvent e) 
669        { 
670          importMenu_actionPerformed(); 
671        } 
672      }); 
673      saveMenu.setText("Save"); 
674      saveMenu.addActionListener(new java.awt.event.ActionListener() 
675      { 
676        public void actionPerformed(ActionEvent e) 
677        { 
678          saveButton_actionPerformed(); 
679        } 
680      }); 
681      saveAllMenu.setText("Save All"); 
682      saveAllMenu.addActionListener(new java.awt.event.ActionListener() 
683      { 
684        public void actionPerformed(ActionEvent e) 
685        { 
686          saveAllButton_actionPerformed(); 
687        } 
688      }); 
689      closeMenu.setText("Close"); 
690      closeMenuCopy.setText("Close"); 
691      editMenu.setText("Edit"); 
692      undoMenu.setText("Undo"); 
693      undoMenu.addActionListener(new java.awt.event.ActionListener() 
694      { 
695        public void actionPerformed(ActionEvent e) 
696        { 
697          undoButton_actionPerformed(e); 
698        } 
699      }); 
700      redoMenu.setText("Redo"); 
701      redoMenu.addActionListener(new java.awt.event.ActionListener() 
702      { 
703        public void actionPerformed(ActionEvent e) 
704        { 
705          redoButton_actionPerformed(e); 
706        } 
707      }); 
708      cutMenu.setText("Cut"); 
709      cutMenu.addActionListener(new java.awt.event.ActionListener() 
710      { 
711        public void actionPerformed(ActionEvent e) 
712        { 
713          cut(); 
714        } 
715      }); 
716      copyMenu.setText("Copy"); 
717      copyMenu.addActionListener(new java.awt.event.ActionListener() 
718      { 
719        public void actionPerformed(ActionEvent e) 
720        { 
721          copy(); 
722        } 
723      }); 
724      pasteMenu.setText("Paste"); 
725      pasteMenu.addActionListener(new java.awt.event.ActionListener() 
726      { 
727        public void actionPerformed(ActionEvent e) 
728        { 
729          paste(); 
730        } 
731      }); 
732      selectAllMenu.setText("Select All"); 
733      selectAllMenu.addActionListener(new java.awt.event.ActionListener() 
734      { 
735        public void actionPerformed(ActionEvent e) 
736        { 
737          selectAllMenu_actionPerformed(); 
738        } 
739      }); 
740      viewMenu.setText("View"); 
741      showTextMenu.setText("Show Text on Toolbars"); 
742      showTextMenu.setState(Boolean.valueOf(lexx.utils.Config.getProperty( 
743          "Toolbar.showText")).booleanValue()); 
744      showTextMenu.addActionListener(new java.awt.event.ActionListener() 
745      { 
746        public void actionPerformed(ActionEvent e) 
747        { 
748          showTextMenu_actionPerformed(); 
749        } 
750      }); 
751      runMenu.setText("Run"); 
752      compileMenu.setText("Compile"); 
753      compileMenu.addActionListener(new java.awt.event.ActionListener() 
754      { 
755        public void actionPerformed(ActionEvent e) 
756        { 
757          compileButton_actionPerformed(); 
758        } 
759      }); 
760      rebuildMenu.setText("Rebuild"); 
761      rebuildMenu.addActionListener(new java.awt.event.ActionListener() 
762      { 
763        public void actionPerformed(ActionEvent e) 
764        { 
765          rebuildButton_actionPerformed(); 
766        } 
767      }); 
768      runJavaMenu.setText("Run"); 
769      runJavaMenu.addActionListener(new java.awt.event.ActionListener() 
770      { 
771        public void actionPerformed(ActionEvent e) 
772        { 
773          runPanel.runButton_actionPerformed(false); 
774        } 
775      }); 
776      debugMenu.setText("Debug"); 
777      debugMenu.addActionListener(new java.awt.event.ActionListener() 
778      { 
779        public void actionPerformed(ActionEvent e) 
780        { 
781          runPanel.runButton_actionPerformed(true); 
782        } 
783      }); 
784      javadocMenu.setText("JavaDoc"); 
785      javadocMenu.addActionListener(new java.awt.event.ActionListener() 
786      { 
787        public void actionPerformed(ActionEvent e) 
788        { 
789          javadocButton_actionPerformed(); 
790        } 
791      }); 
792      runnableFileMenu.setText("Files"); 
793      advanceMenu.setText("Advance"); 
794      loggerMenu.setText("Logger"); 
795      loggerMenu.addActionListener(new java.awt.event.ActionListener() 
796      { 
797        public void actionPerformed(ActionEvent e) 
798        { 
799          loggerButton_actionPerformed(); 
800        } 
801      }); 
802      classMapMenu.setText("Class Map"); 
803      classMapMenu.addActionListener(new java.awt.event.ActionListener() 
804      { 
805        public void actionPerformed(ActionEvent e) 
806        { 
807          classMapButton_actionPerformed(); 
808        } 
809      }); 
810      refreshMenu.setText("Refresh files"); 
811      refreshMenu.addActionListener(new java.awt.event.ActionListener() 
812      { 
813        public void actionPerformed(ActionEvent e) 
814        { 
815          runPanel.refreshButtonPressed(); 
816        } 
817      }); 
818      refactorMenu.setText("Refactoring/UML"); 
819      refactorMenu.addActionListener(new java.awt.event.ActionListener() 
820      { 
821        public void actionPerformed(ActionEvent e) 
822        { 
823          refactoryButton_actionPerformed(); 
824        } 
825      }); 
826   
827      JPanel tmp = new JPanel(new BorderLayout()); 
828      tmp.add(toolPanel, BorderLayout.WEST); 
829      this.getContentPane().add(tmp, BorderLayout.NORTH); 
830      this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE ); 
831      tree = new FileTree(projectPath + "/src"); 
832      tree.addTreeSelectionListener(new TreeSelectionListener() 
833      { 
834        public void valueChanged(TreeSelectionEvent e) 
835        { 
836          try 
837          { 
838            Object obj = tree.getSelectionPath().getLastPathComponent(); 
839            if(obj instanceof File) 
840            { 
841              File f = (File) obj; 
842              if(f.isFile()) 
843              { 
844                addJavaFile(f); 
845              } 
846            } 
847          } 
848          catch(Exception ex) 
849          { 
850            log.fatal(ex); 
851          } 
852        } 
853      }); 
854      sidePanel.add(new JScrollPane(tree)); 
855      new Close().setupCloseButton(tabPane); 
856      tabPane.addTab("Welcome", Close.closeIcon, new JLabel() 
857      { 
858        public void paint(Graphics g) 
859        { 
860          Image image = new ImageIcon(lexx.gui.EditorFrame.class. 
861                                      getResource("image.gif")).getImage(); 
862          g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this); 
863        } 
864      }, "Welcome to Lexx IDE"); 
865      JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, 
866                                        sidePanel, tabPane); 
867      split.setOneTouchExpandable(true); 
868      JSplitPane lowerSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, 
869                                             split, getLowerTabPane()); 
870      lowerSplit.setOneTouchExpandable(true); 
871   
872      getLowerTabPane().setTabPlacement(JTabbedPane.BOTTOM); 
873      lowerSplit.setDividerLocation(500); 
874      this.getContentPane().add(lowerSplit, BorderLayout.CENTER); 
875      this.getContentPane().add(statusBar, BorderLayout.SOUTH); 
876   
877      if(Config.isDebug()) 
878      { 
879        statusBar.add(new MemoryPanel(), BorderLayout.EAST); 
880   
881      } 
882      statusBar.add(statusLabel, BorderLayout.CENTER); 
883      statusBar.add(new JLabel("status: "), BorderLayout.WEST); 
884      menuBar.add(fileMenu); 
885      menuBar.add(editMenu); 
886      menuBar.add(viewMenu); 
887      menuBar.add(runMenu); 
888      menuBar.add(advanceMenu); 
889      menuBar.add(helpMenu); 
890      fileMenu.add(newMenu); 
891      fileMenu.add(importMenu); 
892      fileMenu.add(saveMenu); 
893      fileMenu.add(saveAllMenu); 
894      fileMenu.addSeparator(); 
895      fileMenu.add(closeMenu); 
896      fileMenu.add(exitMenu); 
897      helpMenu.add(aboutMenu); 
898      editMenu.add(undoMenu); 
899      editMenu.add(redoMenu); 
900      editMenu.addSeparator(); 
901      editMenu.add(cutMenu); 
902      editMenu.add(copyMenu); 
903      editMenu.add(pasteMenu); 
904      editMenu.addSeparator(); 
905      editMenu.add(selectAllMenu); 
906      editMenu.add(findMenu); 
907      viewMenu.add(beepMenuItem); 
908      viewMenu.add(showTextMenu); 
909      viewMenu.addSeparator(); 
910      viewMenu.add(LookAndFeel.lookFeelMenu); 
911      runMenu.add(compileMenu); 
912      runMenu.add(rebuildMenu); 
913      runMenu.addSeparator(); 
914      runMenu.add(runnableFileMenu); 
915      runMenu.add(refreshMenu); 
916      runMenu.add(runJavaMenu); 
917   
918      //as debugging is still in development 
919      if(lexx.utils.Config.enableIncompleteComponents()) 
920      { 
921        runMenu.add(debugMenu); 
922   
923      } 
924      runMenu.addSeparator(); 
925      runMenu.add(javadocMenu); 
926      advanceMenu.add(loggerMenu); 
927      advanceMenu.add(classMapMenu); 
928      advanceMenu.add(pmd.pmdMenu); 
929   
930      if(lexx.utils.Config.enableIncompleteComponents()) 
931      { 
932        advanceMenu.add(refactorMenu); 
933   
934      } 
935      LookAndFeel.lookFeelMenu.add(otherThemeMenu); 
936   
937      if(lexx.utils.Config.enableIncompleteComponents()) 
938      { 
939        advanceMenu.add(styleMenu); 
940      } 
941      otherThemeMenu.add(LookAndFeel.aquaTheme); 
942      otherThemeMenu.add(LookAndFeel.bbjTheme); 
943      otherThemeMenu.add(LookAndFeel.beOSTheme); 
944      otherThemeMenu.add(LookAndFeel.macOSXTheme); 
945      otherThemeMenu.add(LookAndFeel.modernTheme); 
946      otherThemeMenu.add(LookAndFeel.whistlerTheme); 
947      otherThemeMenu.add(LookAndFeel.xpTheme); 
948      getLowerTabPane().addTab("Build", Icons.getImageIcon("dukemuscle.gif"), 
949                               build, "This compiles and produces your javadoc"); 
950      getLowerTabPane().addTab("Doc", Icons.getImageIcon("dukediploma.gif"), 
951                               docViewer,"This allows you to view javadoc"); 
952   
953      if(Config.getClient() != null) 
954      { 
955        getLowerTabPane().addTab("Chat", Icons.getImageIcon("talk.gif"), 
956                                 Config.getClient().getPanel(), 
957                                 "This allows you to chat to other users on-line" ); 
958   
959      } 
960      getLowerTabPane().setSelectedComponent(docViewer); 
961   
962      closeMenu.addActionListener(new ActionListener() 
963      { 
964        public void actionPerformed(ActionEvent ex) 
965        { 
966          if(tabPane.getSelectedComponent()instanceof EditorPanel) 
967          { 
968            if( ( (EditorPanel) tabPane.getSelectedComponent()).close()) 
969            { 
970              tabPane.removeTabAt(tabPane.getSelectedIndex()); 
971            } 
972          } 
973          else 
974          { 
975            tabPane.removeTabAt(tabPane.getSelectedIndex()); 
976          } 
977        } 
978      }); 
979   
980      closeMenuCopy.addActionListener(new ActionListener() 
981      { 
982        public void actionPerformed(ActionEvent ex) 
983        { 
984          if(getLowerTabPane().getSelectedComponent() == build || 
985             getLowerTabPane().getSelectedComponent() == docViewer) 
986          { 
987            return; 
988          } 
989   
990          if(getLowerTabPane().getSelectedComponent()instanceof Closeable) 
991          { 
992            if( ( (Closeable) getLowerTabPane().getSelectedComponent()).close()) 
993            { 
994              getLowerTabPane().removeTabAt(getLowerTabPane().getSelectedIndex()); 
995            } 
996          } 
997          else 
998          { 
999            getLowerTabPane().removeTabAt(getLowerTabPane().getSelectedIndex()); 
1000         } 
1001       } 
1002     }); 
1003  
1004     new Close().setupCloseButton(getLowerTabPane()); 
1005  
1006     MouseListener closer = new MouseListener() 
1007     { 
1008       public void mouseClicked(MouseEvent e) 
1009       { 
1010         if(tabPane.getSelectedComponent()instanceof com.traxel.lm. 
1011            LumbermillPanel) 
1012         { 
1013           return; 
1014         } 
1015  
1016         if(e.getButton() != e.BUTTON1) 
1017         { 
1018           JPopupMenu pop = new JPopupMenu(); 
1019           pop.add(closeMenu); 
1020           pop.show(e.getComponent(), -100, -100); 
1021           pop.show(e.getComponent(), e.getPoint().x, 
1022                    e.getPoint().y - pop.getHeight()); 
1023         } 
1024         check(); 
1025       } 
1026  
1027       public void mousePressed(MouseEvent e) 
1028       {} 
1029  
1030       public void mouseEntered(MouseEvent e) 
1031       {} 
1032  
1033       public void mouseExited(MouseEvent e) 
1034       {} 
1035  
1036       public void mouseReleased(MouseEvent e) 
1037       {} 
1038     }; 
1039  
1040     MouseListener closerBottom = new MouseListener() 
1041     { 
1042       public void mouseClicked(MouseEvent e) 
1043       { 
1044         if(getLowerTabPane().getSelectedComponent() == build || 
1045            getLowerTabPane().getSelectedComponent() == docViewer) 
1046         { 
1047           return; 
1048         } 
1049  
1050         if(e.getButton() != e.BUTTON1) 
1051         { 
1052           JPopupMenu pop = new JPopupMenu(); 
1053           pop.add(closeMenuCopy); 
1054           pop.show(e.getComponent(), -100, -100); 
1055           pop.show(e.getComponent(), e.getPoint().x, 
1056                    e.getPoint().y - pop.getHeight()); 
1057         } 
1058         check(); 
1059       } 
1060  
1061       public void mousePressed(MouseEvent e) 
1062       {} 
1063  
1064       public void mouseEntered(MouseEvent e) 
1065       {} 
1066  
1067       public void mouseExited(MouseEvent e) 
1068       {} 
1069  
1070       public void mouseReleased(MouseEvent e) 
1071       {} 
1072     }; 
1073  
1074     new Thread() 
1075     { 
1076       public void run() 
1077       { 
1078         this.setPriority(Thread.MIN_PRIORITY ); 
1079         while( true ) 
1080         { 
1081           if(getEditorPanel() != null && getEditorPanel().getTextPane().getSelectedText() != null && 
1082              getEditorPanel().getTextPane().getSelectedText().length() > 0) 
1083           { 
1084             copyButton.setEnabled(true); 
1085             cutButton.setEnabled(true); 
1086             copyMenu.setEnabled(true); 
1087             cutMenu.setEnabled(true); 
1088           } 
1089           else 
1090           { 
1091             copyButton.setEnabled(false); 
1092             cutButton.setEnabled(false); 
1093             copyMenu.setEnabled(false); 
1094             cutMenu.setEnabled(false); 
1095           } 
1096           try 
1097           { 
1098             this.sleep(1000); 
1099           } 
1100           catch(InterruptedException ex) 
1101           { 
1102           } 
1103         } 
1104       } 
1105     }.start(); 
1106  
1107     tabPane.addMouseListener(closer); 
1108     getLowerTabPane().addMouseListener(closerBottom); 
1109   } 
1110  
1111   /** 
1112    * Sends all files that are being edited to the server 
1113    */ 
1114   public final void sendOpenFilesToServer() 
1115   { 
1116     for(int i = 0; i < tabPane.getTabCount(); i++) 
1117     { 
1118       if(tabPane.getComponentAt(i)instanceof EditorPanel) 
1119       { 
1120         EditorPanel ep = (EditorPanel) tabPane.getComponentAt(i); 
1121         ep.sendFileToServer(); 
1122       } 
1123     } 
1124   } 
1125  
1126   /** 
1127    * Sets a specific component as visible component as the bottom JTabbedPane 
1128    * @param c the component you wish to select 
1129    */ 
1130   public final void setLowerTabSelect(Component c) 
1131   { 
1132     getLowerTabPane().setSelectedComponent(c); 
1133   } 
1134  
1135   private void addJavaFile(File f) 
1136   { 
1137     log.info("addJavaFile called with file " + f); 
1138     //class files - NO need to check with server 
1139     if(f.getName().toLowerCase().endsWith("class")) 
1140     { 
1141       //first check if tab panel is alraedy enabled 
1142       for(int i = 0; i < tabPane.getTabCount(); i++) 
1143       { 
1144         if(tabPane.getComponentAt(i)instanceof EditorPanel) 
1145         { 
1146           EditorPanel ep = (EditorPanel) tabPane.getComponentAt(i); 
1147           if(f.equals(ep.getFileName())) 
1148           { 
1149             tabPane.setSelectedComponent(tabPane.getComponentAt(i)); 
1150             return; 
1151           } 
1152         } 
1153       } 
1154       EditorPanel ep = new EditorPanel(pack, f, 
1155                                        this.getJavaName(f.toString(), 
1156           projectPath)); 
1157       tabPane.addTab(f.getName().substring(0, 
1158                                            f.getName().length() - 
1159                                            ".class".length() ), 
1160                      Close.closeIcon, ep, "This is decompiled class"); 
1161       tabPane.setSelectedComponent(ep); 
1162     } 
1163     else 
1164     { 
1165       //checks if file is a text file 
1166       if(!lexx.utils.Utilities.isTextFile(f.toString())) 
1167       { 
1168         log.info(f + " isn't a text file"); 
1169         return; 
1170       } 
1171  
1172       //first check if tab panel is alraedy enabled 
1173       for(int i = 0; i < tabPane.getTabCount(); i++) 
1174       { 
1175         if(tabPane.getComponentAt(i)instanceof EditorPanel) 
1176         { 
1177           EditorPanel ep = (EditorPanel) tabPane.getComponentAt(i); 
1178           if(f.equals(ep.getFileName())) 
1179           { 
1180             tabPane.setSelectedComponent(tabPane.getComponentAt(i)); 
1181             log.info(f + " is already been displayed"); 
1182             return; 
1183           } 
1184         } 
1185         if(tabPane.getComponentAt(i)instanceof JLabel) 
1186         { 
1187           tabPane.remove(tabPane.getComponentAt(i)); 
1188         } 
1189       } 
1190  
1191       //want to load in file 
1192       boolean canContinue = false; 
1193       if(Config.getClient() != null) 
1194       { 
1195         if(Config.getClient().requestFile(f.toString())) 
1196         { 
1197           canContinue = true; 
1198         } 
1199         else 
1200         { 
1201           JOptionPane.showMessageDialog(lexx.utils.Config.getFrameForDialog(), 
1202                                         "<html>Sorry can't open <b>" + f.toString() + "</b> as its been opened by another user.<br>" + 
1203                                         "Please use the chat dialogue to speak directly to the person opening that file</html>", 
1204                                         "Unable to open file", 
1205                                         JOptionPane.ERROR_MESSAGE); 
1206         } 
1207       } 
1208       else 
1209       { 
1210         canContinue = true; 
1211       } 
1212  
1213       if(!canContinue) 
1214       { 
1215         log.debug("Can't contintue"); 
1216         return; 
1217       } 
1218  
1219       EditorPanel ep = new EditorPanel(pack, f, 
1220                                        this.getJavaName(f.toString(), 
1221           projectPath)); 
1222       if( f.getName().toLowerCase().endsWith(".java") ) 
1223         tabPane.addTab(f.getName().substring(0, 
1224                                              f.getName().length() - 
1225                                              ".JAVA".length()), 
1226                        Close.closeIcon, ep, "This is a java editor with auto-completion"); 
1227       else 
1228           tabPane.addTab(f.getName(), Close.closeIcon, ep, 
1229                          "This is a text editor"); 
1230  
1231       tabPane.setSelectedComponent(ep); 
1232  
1233       ep.getTextPane().getStyledDocument().addDocumentListener(new 
1234           DocumentListener() 
1235       { 
1236         public void insertUpdate(DocumentEvent e) 
1237         { 
1238           check(); 
1239         } 
1240  
1241         public void removeUpdate(DocumentEvent e) 
1242         { 
1243           check(); 
1244         } 
1245  
1246         public void changedUpdate(DocumentEvent e) 
1247         { 
1248           check(); 
1249         } 
1250  
1251       }); 
1252     } 
1253   } 
1254  
1255   private void setToolbarText() 
1256   { 
1257     if(Boolean.valueOf(lexx.utils.Config.getProperty("Toolbar.showText")). 
1258        booleanValue()) 
1259     { 
1260       newButton.setText("New"); 
1261       loggerButton.setText("Logger"); 
1262       refactoryButton.setText("Refactoring"); 
1263       copyButton.setText("Copy"); 
1264       pmd.reviewButton.setText("Analyse Code"); 
1265       openButton.setText("Import"); 
1266       saveButton.setText("Save"); 
1267       redoButton.setText("Redo"); 
1268       undoButton.setText("Undo"); 
1269       classMapButton.setText("Class Map"); 
1270       compileButton.setText("Compile"); 
1271       rebuildButton.setText("Rebuild"); 
1272       saveAllButton.setText("Save All"); 
1273       javadocButton.setText("JavaDoc"); 
1274       pasteButton.setText("Paste"); 
1275       cutButton.setText("Cut"); 
1276       styleButton.setText("Style"); 
1277       findButton.setText("Find/Replace"); 
1278     } 
1279     else 
1280     { 
1281       newButton.setText(""); 
1282       loggerButton.setText(""); 
1283       refactoryButton.setText(""); 
1284       copyButton.setText(""); 
1285       pmd.reviewButton.setText(""); 
1286       debugAST.setText(""); 
1287       openButton.setText(""); 
1288       saveButton.setText(""); 
1289       redoButton.setText(""); 
1290       undoButton.setText(""); 
1291       classMapButton.setText(""); 
1292       compileButton.setText(""); 
1293       rebuildButton.setText(""); 
1294       saveAllButton.setText(""); 
1295       javadocButton.setText(""); 
1296       pasteButton.setText(""); 
1297       cutButton.setText(""); 
1298       styleButton.setText(""); 
1299       findButton.setText(""); 
1300     } 
1301     runPanel.showText(Boolean.valueOf(lexx.utils.Config.getProperty( 
1302         "Toolbar.showText")).booleanValue()); 
1303     toolPanel.updateUI(); 
1304   } 
1305  
1306   /** 
1307    * This method updates the tree 
1308    */ 
1309   private void checkFiles() 
1310   { 
1311     if(tree.getClass().equals(FileTree.class)) 
1312     { 
1313       ( (FileTree) tree).update(); 
1314     } 
1315     else 
1316     { 
1317       tree.treeDidChange(); 
1318       tree.validate(); 
1319       tree.updateUI(); 
1320     } 
1321   } 
1322  
1323   private void check() 
1324   { 
1325     new Thread() 
1326     { 
1327       public void run() 
1328       { 
1329         this.setPriority(Thread.MIN_PRIORITY); 
1330         if(getEditorPanel() == null) 
1331         { 
1332           closeMenu.setEnabled(false); 
1333           saveAllMenu.setEnabled(false); 
1334           saveButton.setEnabled(false); 
1335           saveAllButton.setEnabled(false); 
1336           cutMenu.setEnabled(false); 
1337           cutButton.setEnabled(false); 
1338           copyMenu.setEnabled(false); 
1339           copyButton.setEnabled(false); 
1340           undoMenu.setEnabled(false); 
1341           undoButton.setEnabled(false); 
1342           redoMenu.setEnabled(false); 
1343           redoButton.setEnabled(false); 
1344           findMenu.setEnabled(false); 
1345           findButton.setEnabled(false); 
1346           return; 
1347         } 
1348         else 
1349         { 
1350           closeMenu.setEnabled(true); 
1351           findMenu.setEnabled(true); 
1352           findButton.setEnabled(true); 
1353         } 
1354  
1355         if(getEditorPanel().hasChanged()) 
1356         { 
1357           saveButton.setEnabled(true); 
1358           saveMenu.setEnabled(true); 
1359         } 
1360         else 
1361         { 
1362           saveButton.setEnabled(false); 
1363           saveMenu.setEnabled(false); 
1364         } 
1365  
1366         if(getEditorPanel().getUndo().canUndo()) 
1367         { 
1368           undoButton.setEnabled(true); 
1369           undoMenu.setEnabled(true); 
1370         } 
1371         else 
1372         { 
1373           undoButton.setEnabled(false); 
1374           undoMenu.setEnabled(false); 
1375         } 
1376  
1377         if(getEditorPanel().getUndo().canRedo()) 
1378         { 
1379           redoButton.setEnabled(true); 
1380           redoMenu.setEnabled(true); 
1381         } 
1382         else 
1383         { 
1384           redoButton.setEnabled(false); 
1385           redoMenu.setEnabled(false); 
1386         } 
1387  
1388         boolean canSaveAll = false; 
1389         for(int i = 0; i < tabPane.getTabCount(); i++) 
1390         { 
1391           try 
1392           { 
1393             if(tabPane.getComponentAt(i)instanceof EditorPanel) 
1394             { 
1395               EditorPanel ep = (EditorPanel) tabPane.getComponentAt(i); 
1396               String text = "<html>"; 
1397               if(ep.hasChanged()) 
1398               { 
1399                 text += "<font color = \"#FF0000\">"; 
1400                 canSaveAll = true; 
1401               } 
1402               else 
1403               { 
1404                 text += "<font color = \"#000000\">"; 
1405  
1406               } 
1407               text += ep.getFileName().getName().substring(0, 
1408                   ep.getFileName().getName().length() - ".JAVA".length()) + 
1409                   "</font></html>"; 
1410               tabPane.setTitleAt(i, text); 
1411             } 
1412           } 
1413           catch(Exception ex) 
1414           { 
1415             log.fatal(ex, ex); 
1416           } 
1417         } 
1418         saveAllMenu.setEnabled(canSaveAll); 
1419         saveAllButton.setEnabled(canSaveAll); 
1420       } 
1421     }.start(); 
1422   } 
1423  
1424   /** 
1425    * Loads up a file into the editor and goes to a specific line 
1426    * @param fileName the name of the file you wish to edit 
1427    * @param lineNum the line number you wish to go to 
1428    */ 
1429   public final void gotoFile(String fileName, int lineNum) 
1430   { 
1431     try 
1432     { 
1433       File f = new File(fileName).getCanonicalFile(); 
1434       File proj = new File(Config.getSourceCodePath()).getCanonicalFile(); 
1435       String javaName = f.toString().substring(proj.toString().length() + 1, 
1436                                                f.toString().length()); 
1437       this.gotoLine(javaName, lineNum); 
1438     } 
1439     catch(Exception ex) 
1440     { 
1441       log.fatal(ex, ex); 
1442     } 
1443   } 
1444  
1445   /** 
1446    * Loads up a java file into the editor and goes to a specific line 
1447    * @param javaName the name of the class you wish to edit 
1448    * @param lineNum the line number you wish to go to 
1449    */ 
1450   public final void gotoLine(String javaName, int lineNum) 
1451   { 
1452     try 
1453     { 
1454       //first check if tab panel is alraedy enabled 
1455       for(int i = 0; i < tabPane.getTabCount(); i++) 
1456       { 
1457         if(tabPane.getComponentAt(i)instanceof EditorPanel) 
1458         { 
1459           EditorPanel ep = (EditorPanel) tabPane.getComponentAt(i); 
1460           if(ep.getJavaName().equals(javaName) || 
1461              ep.getJavaName().endsWith(javaName)) 
1462           { 
1463             tabPane.setSelectedComponent(tabPane.getComponentAt(i)); 
1464             ep.gotoLine(lineNum); 
1465             return; 
1466           } 
1467         } 
1468       } 
1469  
1470       //need to load java file into path 
1471       File f = new File(projectPath + "/src/" + javaName); 
1472       if(f.exists()) 
1473       { 
1474         this.addJavaFile(f); 
1475         this.getEditorPanel().gotoLine(lineNum); 
1476         return; 
1477       } 
1478  
1479       //check if file is a class 
1480       String s = ""; 
1481       for(int i = 0; i < javaName.length(); i++) 
1482       { 
1483         if(javaName.charAt(i) == '\\' || javaName.charAt(i) == '/') 
1484         { 
1485           s += '.'; 
1486         } 
1487         else 
1488         { 
1489           s += javaName.charAt(i); 
1490         } 
1491       } 
1492       javaName = s; 
1493  
1494       if(javaName.endsWith(".java")) 
1495       { 
1496         javaName = javaName.substring(0, javaName.length() - ".java".length()); 
1497  
1498       } 
1499       lexx.trie.Trie n = pack.getEveryPossibleClass().getNode(javaName); 
1500       if(n != null) 
1501       { 
1502         if(n.isLeaf()) 
1503         { 
1504           List vec = n.getCurrentObjects(); 
1505           for(int x = 0; x < vec.size(); x++) 
1506           { 
1507             ClassName cl = (ClassName) vec.get(x); 
1508             String tmp = cl.getFullName(); 
1509             String newName = ""; 
1510  
1511             //need to load java file into path 
1512             for(int i = 0; i < tmp.length(); i++) 
1513             { 
1514               if(tmp.charAt(i) == '.') 
1515               { 
1516                 newName += '/'; 
1517               } 
1518               else 
1519               { 
1520                 newName += tmp.charAt(i); 
1521               } 
1522             } 
1523             File f1 = new File(projectPath + "/src/" + newName + ".java"); 
1524             if(f1.exists()) 
1525             { 
1526               this.addJavaFile(f1); 
1527               this.getEditorPanel().gotoLine(lineNum); 
1528               return; 
1529             } 
1530             this.addClass(cl); 
1531  
1532             if(this.getEditorPanel() != null) 
1533             { 
1534               this.getEditorPanel().gotoLine(lineNum); 
1535             } 
1536             return; 
1537           } 
1538         } 
1539       } 
1540     } 
1541     catch(Exception ex) 
1542     { 
1543       log.fatal(ex,ex); 
1544     } 
1545   } 
1546  
1547   /** 
1548    * Decompiles a class file and loads the source code into the editor 
1549    * @param cn The class you wish to add 
1550    */ 
1551   public final void addClass(ClassName cn) 
1552   { 
1553     //first check if tab panel is alraedy enabled 
1554     for(int i = 0; i < tabPane.getTabCount(); i++) 
1555     { 
1556       if(tabPane.getComponentAt(i)instanceof EditorPanel) 
1557       { 
1558         EditorPanel ep = (EditorPanel) tabPane.getComponentAt(i); 
1559         if(cn.getName().equals(ep.getFileName())) 
1560         { 
1561           tabPane.setSelectedComponent(tabPane.getComponentAt(i)); 
1562           return; 
1563         } 
1564       } 
1565     } 
1566  
1567     lexx.plugins.decompiler.Decompiler dc = new lexx.plugins.decompiler. 
1568                                             Decompiler(cn.getFullName(), 
1569         (JavaPackages) pack); 
1570     String data = dc.getDecompiledString(); 
1571  
1572     if(data != null && !"".equals(data.trim())) 
1573     { 
1574       EditorPanel ep = new EditorPanel(pack, cn, cn.getFullName()); 
1575       tabPane.addTab(cn.toString(), Close.closeIcon, ep, 
1576                      "This is a decompiled class file"); 
1577       tabPane.setSelectedComponent(ep); 
1578     } 
1579   } 
1580  
1581   /** 
1582    * This method is used in testing allow you to see how the JavaParser has broken 
1583    * down the code for you, and when you click on a tree actually highlights the text 
1584    * in the textpane 
1585    */ 
1586   private void setupTree() 
1587   { 
1588     //sets up tree 
1589     DefaultMutableTreeNode top = new DefaultMutableTreeNode("Java Class"); 
1590     JavaParser jp = new JavaParser(); 
1591     jp.parse(getEditorPanel().getTextPane().getText().replaceAll("\r\n", "\n")); //since TextPane uses only \n there position of text will be different 
1592     this.setupTree(top, jp.getCode()); 
1593     tree = new JTree(top); 
1594     tree.setPreferredSize(new Dimension(500, 500)); 
1595     tree.setMaximumSize(new Dimension(500, Integer.MAX_VALUE)); 
1596  
1597     tree.addTreeSelectionListener(new TreeSelectionListener() 
1598     { 
1599       public void valueChanged(TreeSelectionEvent e) 
1600       { 
1601         DefaultMutableTreeNode node = (DefaultMutableTreeNode) 
1602                                       tree.getLastSelectedPathComponent(); 
1603  
1604         if(node == null) 
1605         { 
1606           return; 
1607         } 
1608  
1609         Object nodeInfo = node.getUserObject(); 
1610         JTextPane textPane = getEditorPanel().getTextPane(); 
1611         StyledDocument doc = textPane.getStyledDocument(); 
1612         textPane.getStyledDocument().setCharacterAttributes(0, 
1613             textPane.getText().length(), doc.getStyle(SyntaxColours.DEFAULT), true); 
1614         textPane.getStyledDocument().setCharacterAttributes( ( (JavaParser) 
1615             nodeInfo).getStartPosition(), 
1616             ( (JavaParser) nodeInfo).getEndPosition() - 
1617             ( (JavaParser) nodeInfo).getStartPosition(), 
1618             doc.getStyle(SyntaxColours.BRACEMATCH), true); 
1619       } 
1620     }); 
1621     this.getContentPane().add(new JScrollPane(tree), BorderLayout.WEST); 
1622   } 
1623  
1624   /** 
1625    * @return the current selected EditorPanel 
1626    */ 
1627   public final EditorPanel getEditorPanel() 
1628   { 
1629     if(tabPane.getSelectedComponent()instanceof EditorPanel) 
1630     { 
1631       return(EditorPanel) tabPane.getSelectedComponent(); 
1632     } 
1633     else 
1634     { 
1635       return null; 
1636     } 
1637   } 
1638  
1639   /** 
1640    * This is a helper method for setupTree 
1641    */ 
1642   private void setupTree(DefaultMutableTreeNode top, List code) 
1643   { 
1644     for(int i = 0; i < code.size(); i++) 
1645     { 
1646       DefaultMutableTreeNode tmp = new DefaultMutableTreeNode(code.get(i)); 
1647       top.add(tmp); 
1648       if(code.get(i)instanceof NestCode) 
1649       { 
1650         setupTree(tmp, ( (NestCode) (code.get(i))).getCode()); 
1651       } 
1652       if(code.get(i)instanceof Line) 
1653       { 
1654         setupTree(tmp, ( (Line) (code.get(i))).getCode()); 
1655       } 
1656     } 
1657   } 
1658  
1659   /** 
1660    * Performs undo 
1661    * @param e action event 
1662    */ 
1663   private void undoButton_actionPerformed(ActionEvent e) 
1664   { 
1665     getEditorPanel().getUndoAction().actionPerformed(e); 
1666   } 
1667  
1668   /** 
1669    * Performs redo 
1670    * @param e action event 
1671    */ 
1672   private void redoButton_actionPerformed(ActionEvent e) 
1673   { 
1674     getEditorPanel().getRedoAction().actionPerformed(e); 
1675   } 
1676  
1677   private void classMapButton_actionPerformed() 
1678   { 
1679     if(sidePanel.getComponentCount() == 1) 
1680     { 
1681       Component old = sidePanel.getComponent(0); 
1682       sidePanel.remove(old); 
1683       JTree classMapTree = pack.setupTree(this); 
1684       JScrollPane sPane = new JScrollPane(classMapTree); 
1685       JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, old, 
1686                                         sPane); 
1687       sidePanel.add(split); 
1688       sidePanel.updateUI(); 
1689       sPane.updateUI(); 
1690     } 
1691   } 
1692  
1693   private void debugAST_actionPerformed() 
1694   { 
1695     ParserListener d = this.getEditorPanel().getParserListener(); 
1696   } 
1697  
1698   private void compileButton_actionPerformed() 
1699   { 
1700     new Thread() 
1701     { 
1702       public void run() 
1703       { 
1704         getLowerTabPane().setSelectedComponent(build); 
1705         saveAllButton_actionPerformed(); 
1706         check(); 
1707         build.compileAndWait(null); 
1708         runPanel.refreshButtonPressed(); 
1709       } 
1710     }.start(); 
1711   } 
1712  
1713   private void rebuildButton_actionPerformed() 
1714   { 
1715     new Thread() 
1716     { 
1717       public void run() 
1718       { 
1719         getLowerTabPane().setSelectedComponent(build); 
1720         saveAllButton_actionPerformed(); 
1721         check(); 
1722         build.clean(null); 
1723         build.compile(null); 
1724       } 
1725     }.start(); 
1726   } 
1727  
1728   private void saveButton_actionPerformed() 
1729   { 
1730     this.getEditorPanel().saveFile(); 
1731     this.check(); 
1732   } 
1733  
1734   private void saveAllButton_actionPerformed() 
1735   { 
1736     for(int i = 0; i < tabPane.getTabCount(); i++) 
1737     { 
1738       if(tabPane.getComponentAt(i)instanceof EditorPanel) 
1739       { 
1740         EditorPanel ep = (EditorPanel) tabPane.getComponentAt(i); 
1741         ep.saveFile(); 
1742       } 
1743     } 
1744     this.check(); 
1745   } 
1746  
1747   /** 
1748    * Runs the users work 
1749    * @param fileName the name of the class you wish to run for example lexx.RunApp 
1750    * @param debug this should always be false, as debugger has not been implemented yet 
1751    */ 
1752   public final void run(String fileName, boolean debug) 
1753   { 
1754     lexx.plugins.ant.BuildProject run = new lexx.plugins.ant.BuildProject(this); 
1755     getLowerTabPane().addTab(fileName, Close.closeIcon, run, 
1756                              "This is running your java work"); 
1757     getLowerTabPane().setSelectedComponent(run); 
1758     this.saveAllButton_actionPerformed(); 
1759     this.check(); 
1760     run.runFile(null, null, fileName, null, debug); 
1761   } 
1762  
1763   private void javadocButton_actionPerformed() 
1764   { 
1765     getLowerTabPane().setSelectedComponent(build); 
1766     this.saveAllButton_actionPerformed(); 
1767     this.check(); 
1768     build.javadoc(null); 
1769   } 
1770  
1771   private void aboutMenu_actionPerformed() 
1772   { 
1773     JOptionPane.showMessageDialog(this, 
1774         "This is a java IDE written by Mohammed Imran"); 
1775   } 
1776  
1777   private void newButton_actionPerformed() 
1778   { 
1779     lexx.gui.newclass.CreateClass newClass = new lexx.gui.newclass.CreateClass(this, 
1780         "Wizard", true, projectPath); 
1781     if(newClass.getOutPutFile() != null) 
1782     { 
1783       this.addJavaFile(new File(newClass.getOutPutFile())); 
1784       newClass.setOutPutFile(null); 
1785     } 
1786     this.checkFiles(); 
1787   } 
1788  
1789   private void loggerButton_actionPerformed() 
1790   { 
1791     if(loggerButton.isSelected()) 
1792     { //turn on 
1793       com.traxel.lm.LumbermillPanel logGUI = new com.traxel.lm.LumbermillPanel(); 
1794       tabPane.addTab("Logger", logGUI); 
1795       tabPane.setSelectedComponent(logGUI); 
1796     } 
1797     else 
1798     { 
1799       Component[] comp = tabPane.getComponents(); 
1800       for(int i = 0; i < comp.length; i++) 
1801       { 
1802         if(comp[i].getClass().equals(com.traxel.lm.LumbermillPanel.class)) 
1803         { 
1804           tabPane.remove(comp[i]); 
1805           com.traxel.lm.LumbermillPanel lum = (com.traxel.lm.LumbermillPanel) 
1806                                               comp[i]; 
1807           lum.close(); 
1808         } 
1809       } 
1810     } 
1811   } 
1812  
1813   /** 
1814    * This closes down the IDE 
1815    */ 
1816   private void close() 
1817   { 
1818     Component[] comp = tabPane.getComponents(); 
1819     for(int i = 0; i < comp.length; i++) 
1820     { 
1821       try 
1822       { 
1823         Object obj = comp[i]; 
1824         if( ( ( (Closeable) obj).close())) 
1825         { 
1826           tabPane.remove(comp[i]); 
1827         } 
1828       } 
1829       catch(Exception ex) 
1830       { 
1831         log.fatal(ex, ex); 
1832         tabPane.remove(comp[i]); 
1833       } 
1834     } 
1835  
1836     comp = getLowerTabPane().getComponents(); 
1837     for(int i = 0; i < comp.length; i++) 
1838     { 
1839       try 
1840       { 
1841         Object obj = comp[i]; 
1842         if( ( ( (Closeable) obj).close())) 
1843         { 
1844           tabPane.remove(comp[i]); 
1845         } 
1846       } 
1847       catch(Exception ex) 
1848       { 
1849         log.fatal(ex, ex); 
1850         tabPane.remove(comp[i]); 
1851       } 
1852     } 
1853  
1854     if((getLowerTabPane().getComponentCount() <= 2 && 
1855        tabPane.getComponentCount() == 0) || 
1856        getLowerTabPane().getComponentCount() <= 3 && Config.getClient() != null && 
1857        tabPane.getComponentCount() == 0) 
1858     { 
1859       this.dispose(); 
1860       this.removeAll(); 
1861       System.runFinalization(); 
1862 //      pack.close(); 
1863 //      System.exit(0); 
1864     } 
1865   } 
1866  
1867   private void refactoryButton_actionPerformed() 
1868   { 
1869     new Thread() 
1870     { 
1871       public void run() 
1872       { 
1873         saveAllButton_actionPerformed(); 
1874         check(); 
1875         getLowerTabPane().setSelectedComponent(build); 
1876         int exitValue = build.compileAndWait(null); 
1877         if(exitValue == 0) //success 
1878         { 
1879           new Thread() 
1880           { 
1881             public void run() 
1882             { 
1883               String[] args = new String[1]; 
1884               args[0] = lexx.utils.Config.getSourceCodePath(); 
1885               Refactory.main(args); 
1886               Refactory.waitUntilFinished(); 
1887               reloadAll(); 
1888               check(); 
1889             } 
1890           }.start(); 
1891         } 
1892         else 
1893         { 
1894           lexx.utils.Config.getStatusLabel().setText( 
1895               "Unable to preform refactoring until source code is correct"); 
1896         } 
1897       } 
1898     }.start(); 
1899   } 
1900  
1901   private void reloadAll() 
1902   { 
1903     new Thread() 
1904     { 
1905       public void run() 
1906       { 
1907         for(int i = 0; i < tabPane.getTabCount(); i++) 
1908         { 
1909           if(tabPane.getComponentAt(i)instanceof EditorPanel) 
1910           { 
1911             EditorPanel ep = (EditorPanel) tabPane.getComponentAt(i); 
1912             File f = ep.getFileName(); 
1913             if(f != null && 
1914                !ep.getTextPane().getText().equals(lexx.utils. 
1915                                                   FileUtil.readFile(f.toString()))) 
1916             { 
1917               tabPane.remove(tabPane.getComponentAt(i)); 
1918               ep.close(); 
1919               addJavaFile(f); 
1920             } 
1921           } 
1922         } 
1923       } 
1924     }.start(); 
1925   } 
1926  
1927   private void importMenu_actionPerformed() 
1928   { 
1929     new ImportDialog(this, "Import files", true); 
1930     this.checkFiles(); 
1931   } 
1932  
1933   private void selectAllMenu_actionPerformed() 
1934   { 
1935     getEditorPanel().getTextPane().selectAll(); 
1936   } 
1937  
1938   private void showTextMenu_actionPerformed() 
1939   { 
1940     Config.insert("Toolbar.showText", "" + showTextMenu.getState()); 
1941     this.setToolbarText(); 
1942   } 
1943  
1944   private void styleButton_actionPerformed() 
1945   { 
1946     new Thread() 
1947     { 
1948       public void run() 
1949       { 
1950         saveAllButton_actionPerformed(); 
1951         build.checkStyle(); 
1952         build.waitUntilStartAndFinished(); 
1953         reloadAll(); 
1954       } 
1955     }.start(); 
1956   } 
1957  
1958   /** 
1959    * Loads a webpage into the javadoc module 
1960    * @param address web address 
1961    */ 
1962   public final void loadPage(String address) 
1963   { 
1964     docViewer.loadPage(address); 
1965     getLowerTabPane().setSelectedComponent(docViewer); 
1966   } 
1967  
1968   private void findButton_actionPerformed() 
1969   { 
1970     new FindReplaceDialog(this, 
1971                           getEditorPanel().getTextPane(), 
1972                           new FindReplaceListener() 
1973     { 
1974       public void getNextDocument(FindReplaceEvent e) 
1975       { 
1976         ( (FindReplaceDialog) e.getSource()).terminateOperation(); 
1977       } 
1978  
1979       public void getFirstDocument(FindReplaceEvent e) 
1980       { 
1981         ( (FindReplaceDialog) e.getSource()).resumeOperation(); 
1982       } 
1983     }); 
1984   } 
1985  
1986   JTabbedPane getLowerTabPane() 
1987   { 
1988     return lowerTabPane; 
1989   } 
1990  
1991   void beepMenuItem_actionPerformed() 
1992   { 
1993     Config.setBeepOnErrors(!Config.beepOnErrors()); 
1994   } 
1995 }