improved undo/redo , able to load xpad command into scilab -nw
[scilab.git] / scilab / modules / xpad / src / java / org / scilab / modules / xpad / Xpad.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12
13 package org.scilab.modules.xpad;
14
15 import java.awt.Color;
16 import java.io.File;
17 import java.io.FileWriter;
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.Scanner;
21
22 import javax.swing.BorderFactory;
23 import javax.swing.JFileChooser;
24 import javax.swing.JOptionPane;
25 import javax.swing.JScrollPane;
26 import javax.swing.JTabbedPane;
27 import javax.swing.JTextPane;
28 import javax.swing.undo.CannotRedoException;
29 import javax.swing.undo.CannotUndoException;
30 import javax.swing.undo.UndoManager;
31
32 import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
33 import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
34 import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
35 import org.scilab.modules.gui.filechooser.Juigetfile;
36 import org.scilab.modules.gui.filechooser.ScilabFileChooser;
37 import org.scilab.modules.gui.menu.Menu;
38 import org.scilab.modules.gui.menu.ScilabMenu;
39 import org.scilab.modules.gui.menubar.MenuBar;
40 import org.scilab.modules.gui.menubar.ScilabMenuBar;
41 import org.scilab.modules.gui.tab.SimpleTab;
42 import org.scilab.modules.gui.tab.Tab;
43 import org.scilab.modules.gui.textbox.ScilabTextBox;
44 import org.scilab.modules.gui.textbox.TextBox;
45 import org.scilab.modules.gui.toolbar.ScilabToolBar;
46 import org.scilab.modules.gui.toolbar.ToolBar;
47 import org.scilab.modules.gui.window.ScilabWindow;
48 import org.scilab.modules.gui.window.Window;
49 import org.scilab.modules.xpad.actions.ASCIIEncodingAction;
50 import org.scilab.modules.xpad.actions.AboutAction;
51 import org.scilab.modules.xpad.actions.AutoIndentAction;
52 import org.scilab.modules.xpad.actions.CloseAction;
53 import org.scilab.modules.xpad.actions.ColorizeAction;
54 import org.scilab.modules.xpad.actions.CommentAction;
55 import org.scilab.modules.xpad.actions.CopyAction;
56 import org.scilab.modules.xpad.actions.CutAction;
57 import org.scilab.modules.xpad.actions.DeleteAction;
58 import org.scilab.modules.xpad.actions.EvaluateSelectionAction;
59 import org.scilab.modules.xpad.actions.ExitAction;
60 import org.scilab.modules.xpad.actions.FindAction;
61 import org.scilab.modules.xpad.actions.GotoLineAction;
62 import org.scilab.modules.xpad.actions.HelpAction;
63 import org.scilab.modules.xpad.actions.HighlightCurrentLineAction;
64 import org.scilab.modules.xpad.actions.IndentAction;
65 import org.scilab.modules.xpad.actions.LineNumbersAction;
66 import org.scilab.modules.xpad.actions.LoadIntoScilabAction;
67 import org.scilab.modules.xpad.actions.NewAction;
68 import org.scilab.modules.xpad.actions.OpenAction;
69 import org.scilab.modules.xpad.actions.PageSetupAction;
70 import org.scilab.modules.xpad.actions.PasteAction;
71 import org.scilab.modules.xpad.actions.PrintAction;
72 import org.scilab.modules.xpad.actions.PrintPreviewAction;
73 import org.scilab.modules.xpad.actions.RecentFileAction;
74 import org.scilab.modules.xpad.actions.RedoAction;
75 import org.scilab.modules.xpad.actions.ResetFontAction;
76 import org.scilab.modules.xpad.actions.SaveAction;
77 import org.scilab.modules.xpad.actions.SaveAsAction;
78 import org.scilab.modules.xpad.actions.ScilabStyleAction;
79 import org.scilab.modules.xpad.actions.SelectAllAction;
80 import org.scilab.modules.xpad.actions.SetColorsAction;
81 import org.scilab.modules.xpad.actions.SetFontAction;
82 import org.scilab.modules.xpad.actions.ShowToolBarAction;
83 import org.scilab.modules.xpad.actions.TextStyleAction;
84 import org.scilab.modules.xpad.actions.UTF8EncodingAction;
85 import org.scilab.modules.xpad.actions.UnCommentAction;
86 import org.scilab.modules.xpad.actions.UndoAction;
87 import org.scilab.modules.xpad.actions.WordWrapAction;
88 import org.scilab.modules.xpad.actions.XMLStyleAction;
89 import org.scilab.modules.xpad.style.ScilabStyleDocument;
90 import org.scilab.modules.xpad.utils.ConfigXpadManager;
91 import org.scilab.modules.xpad.utils.XpadMessages;
92
93 public class Xpad extends SwingScilabTab implements Tab { 
94
95         private final Window parentWindow;
96         private JTabbedPane tabPane;
97         private JTextPane textPane;
98         private JScrollPane scrollingText;
99         private XpadLineNumberPanel xln;
100         private  Menu recentsMenu ;
101
102         private static Xpad editor = null;
103
104         public static void main(String[] args) {
105                 xpad();
106         }
107
108         public static void xpad() {
109                 Xpad editor = launchXpad();
110                 editor.addEmptyTab();
111         }
112
113         public static void xpad(String filePath) {
114                 Xpad editor = launchXpad();
115                 File f= new File(filePath) ;
116                 
117                 editor.readFile(f);
118                 
119         
120         }
121
122         private static Xpad launchXpad() {
123                 if (editor == null) {
124                         editor = createEditor();
125                 }
126                 return editor;
127         }
128
129         public static void closeXpad() {
130                 for ( int i = 0 ; i < editor.getTabPane().getComponentCount() ; i++){
131                 
132                         editor.closeTabAt(i);
133                         
134                 }
135                         
136                 editor = null;
137         }
138
139         private static Xpad createEditor() {
140                 ConfigXpadManager.createUserCopy();     
141                 ArrayList<File> recentFiles = ConfigXpadManager.getAllRecentOpenedFiles() ;
142
143                 Window mainWindow = ScilabWindow.createWindow();
144                 Xpad editor = new Xpad(mainWindow);
145
146                 mainWindow.setTitle("Xpad");
147                 mainWindow.addTab(editor);
148
149                 // Set Xpad Window position /size 
150                 mainWindow.setPosition( ConfigXpadManager.getMainWindowPosition());
151                 mainWindow.setDims(ConfigXpadManager.getMainWindowSize());
152
153                 MenuBar menuBar = ScilabMenuBar.createMenuBar();
154                 //Create FILE menubar
155                 Menu fileMenu = ScilabMenu.createMenu();
156                 fileMenu.setText(XpadMessages.FILE);
157                 fileMenu.setMnemonic('F');
158                 fileMenu.add(NewAction.createMenu(editor));
159                 fileMenu.add(OpenAction.createMenu(editor));
160         //               recentsMenu = ScilabMenu.createMenu();
161                 editor.recentsMenu.setText("Recent Files");
162                 for (int i = 0 ; i < recentFiles.size() ; i++ ){
163                         editor.recentsMenu.add( RecentFileAction.createMenu(editor , recentFiles.get(i)));
164                 }
165                 
166                 fileMenu.add(editor.recentsMenu);
167                 
168                 fileMenu.addSeparator();
169                 fileMenu.add(SaveAction.createMenu(editor));
170                 fileMenu.add(SaveAsAction.createMenu(editor));
171                 fileMenu.addSeparator();
172                 fileMenu.add(PageSetupAction.createMenu(editor));
173                 fileMenu.add(PrintPreviewAction.createMenu(editor));
174                 fileMenu.add(PrintAction.createMenu(editor));
175                 fileMenu.addSeparator();
176                 fileMenu.add(CloseAction.createMenu(editor));
177                 fileMenu.addSeparator();
178                 fileMenu.add(ExitAction.createMenu(editor));
179                 menuBar.add(fileMenu);
180
181                 //Create EDIT menubar
182                 Menu editMenu = ScilabMenu.createMenu();
183                 editMenu.setText(XpadMessages.EDIT); 
184                 editMenu.setMnemonic('E');
185                 editMenu.add(UndoAction.createMenu(editor));
186                 editMenu.add(RedoAction.createMenu(editor));
187                 editMenu.addSeparator(); 
188                 editMenu.add(CutAction.createMenu(editor));
189                 editMenu.add(CopyAction.createMenu(editor));
190                 editMenu.add(PasteAction.createMenu(editor));
191                 editMenu.addSeparator(); 
192                 editMenu.add(SelectAllAction.createMenu(editor));
193                 editMenu.add(DeleteAction.createMenu(editor));
194                 editMenu.addSeparator();
195                 editMenu.add(CommentAction.createMenu(editor));
196                 editMenu.add(UnCommentAction.createMenu(editor));
197                 editMenu.addSeparator();
198                 editMenu.add(IndentAction.createMenu(editor));
199                 menuBar.add(editMenu);
200
201                 // Create SEARCH menubar
202                 Menu searchMenu = ScilabMenu.createMenu(); 
203                 searchMenu.setText(XpadMessages.SEARCH);
204                 searchMenu.setMnemonic('S');
205                 searchMenu.add(FindAction.createMenu(editor));
206                 searchMenu.add(GotoLineAction.createMenu(editor));
207                 menuBar.add(searchMenu);
208
209                 // Create VIEW Menubar
210                 Menu viewMenu = ScilabMenu.createMenu();
211                 viewMenu.setText(XpadMessages.VIEW);
212                 viewMenu.add(ShowToolBarAction.createCheckBoxMenu(editor));
213                 viewMenu.addSeparator();
214                 viewMenu.add(HighlightCurrentLineAction.createCheckBoxMenu(editor));
215                 viewMenu.add(WordWrapAction.createCheckBoxMenu(editor));
216                 viewMenu.add(LineNumbersAction.createCheckBoxMenu(editor));
217                 viewMenu.add(SetColorsAction.createMenu(editor));
218                 viewMenu.add(SetFontAction.createMenu(editor));
219                 viewMenu.add(ResetFontAction.createMenu(editor));
220                 menuBar.add(viewMenu);
221
222                 // Create DOCUMENT MenuBar
223                 Menu documentMenu = ScilabMenu.createMenu();
224                 documentMenu.setText(XpadMessages.DOCUMENT);
225                 Menu syntaxTypeMenu = ScilabMenu.createMenu();
226                 syntaxTypeMenu.setText("Syntax Type");
227                 documentMenu.add(syntaxTypeMenu);
228                 syntaxTypeMenu.add(TextStyleAction.createCheckBoxMenu(editor));
229                 syntaxTypeMenu.add(ScilabStyleAction.createCheckBoxMenu(editor));
230                 syntaxTypeMenu.add(XMLStyleAction.createCheckBoxMenu(editor));
231                 documentMenu.addSeparator();
232                 Menu encodingTypeMenu = ScilabMenu.createMenu();
233                 encodingTypeMenu.setText("Encoding Type");
234                 documentMenu.add(encodingTypeMenu);
235                 encodingTypeMenu.add(ASCIIEncodingAction.createCheckBoxMenu(editor));
236                 encodingTypeMenu.add(UTF8EncodingAction.createCheckBoxMenu(editor));
237                 documentMenu.addSeparator();
238                 documentMenu.add(ColorizeAction.createMenu(editor));
239                 documentMenu.add(AutoIndentAction.createCheckBoxMenu(editor));
240                 menuBar.add(documentMenu);
241
242                 // Create EXECUTE menubar
243                 Menu executeMenu = ScilabMenu.createMenu();
244                 executeMenu.setText(XpadMessages.EXECUTE);
245                 executeMenu.setMnemonic('e');
246                 executeMenu.add(LoadIntoScilabAction.createMenu(editor));
247                 executeMenu.add(EvaluateSelectionAction.createMenu(editor));
248                 menuBar.add(executeMenu);
249
250                 //Create HELP menubar
251                 Menu helpMenu = ScilabMenu.createMenu();
252                 helpMenu.setText("?");
253                 helpMenu.add(HelpAction.createMenu(editor));
254                 helpMenu.add(AboutAction.createMenu(editor));
255                 menuBar.add(helpMenu);
256
257                 // Create TOOLBAR
258                 ToolBar toolBar = ScilabToolBar.createToolBar();
259                 toolBar.add(NewAction.createButton(editor)); // NEW
260                 toolBar.add(OpenAction.createButton(editor)); // OPEN
261                 toolBar.addSeparator();
262                 toolBar.add(SaveAction.createButton(editor)); // SAVE
263                 //toolBar.add(SaveAsAction.createButton(editor)); // SAVE AS
264                 toolBar.addSeparator();
265                 //toolBar.add(PrintPreviewAction.createButton(editor)); // PRINT PREVIEW
266                 toolBar.add(PrintAction.createButton(editor)); // PRINT
267                 toolBar.addSeparator();
268                 toolBar.add(UndoAction.createButton(editor)); // UNDO
269                 toolBar.add(RedoAction.createButton(editor)); // REDO
270                 toolBar.addSeparator();
271                 toolBar.add(CutAction.createButton(editor)); // CUT
272                 toolBar.add(CopyAction.createButton(editor)); // COPY
273                 toolBar.add(PasteAction.createButton(editor)); // PASTE
274                 toolBar.addSeparator();
275                 toolBar.add(FindAction.createButton(editor)); // FIND / REPLACE
276                 
277                 
278                 TextBox infoBar = ScilabTextBox.createTextBox();
279                 
280                 
281                 editor.setMenuBar(menuBar);
282                 editor.setToolBar(toolBar);
283                 editor.setInfoBar(infoBar);
284                 mainWindow.setTitle("XPad");
285                 mainWindow.setVisible(true);
286                 editor.setCallback(ExitAction.createMenu(editor).getCallback());
287                 return editor;
288         }
289
290         public Xpad(Window parentWindow) {
291                 super("Xpad");
292                 this.parentWindow = parentWindow;
293                 recentsMenu = ScilabMenu.createMenu(); ;
294                 tabPane = new JTabbedPane();
295                 this.setContentPane(tabPane);
296         }
297
298         public void closeCurrentTab() {
299                 closeTabAt( tabPane.getSelectedIndex() );
300
301         }
302
303         public void closeTabAt (int indexTab ){
304 //              JScrollPane pouet  = (JScrollPane) tabPane.getTabComponentAt(indexTab) ;
305 //               pouet.getViewport().getComponent(0);
306                 JTextPane textPane = (JTextPane) ((JScrollPane) tabPane.getComponentAt(indexTab)).getViewport().getComponent(0) ;
307                 
308                 if (  ((ScilabStyleDocument) textPane.getStyledDocument()).isContentModified() ){
309                         int choice = JOptionPane.showConfirmDialog(this, "This file has been modified since last save\nsave it?");
310                         
311                         if (choice == 0){
312                                         save (textPane);
313                         }else if (choice == 1){
314                                 tabPane.remove(tabPane.getSelectedComponent());
315                                 
316                         }else if (choice == 2){
317                                 // if cancel we do nothing
318                         }
319                         
320                 }else {
321                         tabPane.remove(tabPane.getSelectedComponent());
322                 }
323                 
324         }
325         
326         
327         public boolean save ( JTextPane textPane ) {
328                 
329                 //JTextPane textPane =(JTextPane) ((JScrollPane) tabPane.getTabComponentAt(indexTab)).getViewport().getComponent(0) ;
330                 boolean isSuccess = false ;
331                 if (textPane.getName() != null ){
332                         try {
333                                 File newSavedFiled = new File(textPane.getName());
334                                 
335                                 String doc = textPane.getText();
336
337                                 FileWriter writer = new FileWriter(newSavedFiled);
338                                 writer.write(doc);
339                                 writer.flush();
340                                 writer.close();
341                                 
342                                 ((ScilabStyleDocument) textPane.getStyledDocument()).setContentModified(false);
343                                 
344                                 int index = getTabPane().getSelectedIndex();
345                     getTabPane().setTitleAt( index  , newSavedFiled.getName() );
346
347                     isSuccess = true ;
348
349                         } catch (Exception ioex) {
350                             JOptionPane.showMessageDialog(this, ioex);
351                         }
352                 }else{
353                          isSuccess = saveAs (textPane ); 
354                         
355                 }
356                 
357                 return isSuccess ;
358         }
359         
360         public boolean saveAs (JTextPane textPane){
361                 
362                 boolean isSuccess = false ;
363                 
364                 
365                 String[] mask = Juigetfile.DEFAULT_MASK ;
366                 
367                 SwingScilabFileChooser _fileChooser = ((SwingScilabFileChooser) ScilabFileChooser.createFileChooser().getAsSimpleFileChooser());
368                  
369                  _fileChooser .setAcceptAllFileFilterUsed(true);
370                  _fileChooser .addMask(mask , new String[0]);           
371                  _fileChooser .setInitialDirectory( System.getProperty("user.dir"));            
372                  _fileChooser .setUiDialogType(Juigetfile.SAVE_DIALOG);         
373                 //ssfc.displayAndWait();        
374                 
375                 
376                 int retval =_fileChooser.showSaveDialog(this) ;
377                 
378                 //JTextPane textPane =(JTextPane) ((JScrollPane) tabPane.getTabComponentAt(indexTab)).getViewport().getComponent(0) ;
379                 
380                 if (retval == JFileChooser.APPROVE_OPTION) {
381                         File f = _fileChooser.getSelectedFile() ;
382                         try {
383
384                                 String doc = this.getTextPane().getText();
385                                 
386                                 
387                                 /*we test if the file has already a scilab extension*/
388                                 boolean hasNoExtension = true ;
389                                 
390                                 for ( int i = 0 ; i < Juigetfile.DEFAULT_MASK.length ; i++ ){
391                                         if (f.getName().endsWith(Juigetfile.DEFAULT_MASK[i])){
392                                                 hasNoExtension = false;
393                                                 break ;
394                                         }
395                                         
396                                 }
397                                 /*if no extension , we add it */
398                                 if ( hasNoExtension ){
399                                         f = new File (f.getPath() + ".sci");
400                                 }
401                                 
402                                 FileWriter writer = new FileWriter(f);
403                                 writer.write(doc);
404                                 writer.flush();
405                                 writer.close();
406                                 
407                                 
408                                 ConfigXpadManager.saveToRecentOpenedFiles(f.getPath());
409                                 textPane.setName(f.getPath());
410                                 getTabPane().setTitleAt(getTabPane().getSelectedIndex() , f.getName());
411                                 updateRecentOpenedFilesMenu();
412                                 
413                                 ((ScilabStyleDocument) textPane.getStyledDocument()).setContentModified(false);
414                                 
415                                 isSuccess = true ;
416                                 
417                         } catch (Exception ioex) {
418                             JOptionPane.showMessageDialog(this, ioex);
419                         }
420                         
421                 }
422                 return isSuccess ;
423         }
424
425         public JTextPane addTab(String title) {
426                 textPane = new JTextPane();
427 // {
428 //                      public boolean getScrollableTracksViewportWidth() {
429 //                              return false;
430 //                      };
431 //              };
432
433                 scrollingText = new JScrollPane(textPane);
434                 
435                 // Panel of line number for the text pane
436                 xln = new XpadLineNumberPanel(textPane);
437                 scrollingText.setRowHeaderView(xln);
438                 
439                 tabPane.add(title, scrollingText);
440                 tabPane.setSelectedIndex(tabPane.getTabCount() - 1);
441                 this.setContentPane(tabPane);
442                 textPane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
443                 textPane.setFont(ConfigXpadManager.getFont());
444
445                 textPane.setBackground(ConfigXpadManager.getXpadBackgroundColor());
446                 textPane.setCaretColor(Color.BLACK);
447                 textPane.setStyledDocument(new ScilabStyleDocument(this));
448                 textPane.setCharacterAttributes(textPane.getStyle("Default"), true);
449
450                 textPane.setFocusable(true);
451
452                 return textPane;
453         }
454
455         public JTextPane addEmptyTab() {
456                 return addTab("Untitled");
457         }
458
459         public void setAutoIndent(boolean b) {
460                 ((ScilabStyleDocument) getTextPane().getStyledDocument()).setAutoIndent(b);
461         }
462
463         public void undo() {
464                 UndoManager undo = ((ScilabStyleDocument) getTextPane().getStyledDocument()).getUndoManager();
465                 
466                 if(undo.canUndo()){
467                         try {
468                                         System.out.println(undo.canUndo());
469                                         System.err.println("Will undo "+undo.getUndoPresentationName());
470                                         undo.undo();
471                                 
472                         } catch (CannotUndoException ex) {
473                                 System.out.println("Unable to undo: " + ex);
474                                 ex.printStackTrace();
475                         }
476                 };
477         }
478
479         public void redo() {
480                 UndoManager redo = ((ScilabStyleDocument) getTextPane().getStyledDocument()).getUndoManager();
481                 if ( redo.canRedo()){
482                         try {
483                                 System.err.println("Will redo "+redo.getRedoPresentationName());
484                                 redo.redo();
485                         } catch (CannotRedoException ex) {
486                                 System.out.println("Unable to redo: " + ex);
487                                 ex.printStackTrace();
488                         }
489                 }
490         }
491
492         public void readFile(File f) {
493                 /* First try to open file before creating tab */
494                 try {
495                         StringBuilder contents = new StringBuilder();
496                         Scanner scanner = new Scanner(f);
497                         while (scanner.hasNextLine()) {
498                                 contents.append(scanner.nextLine());
499                                 contents.append(System.getProperty("line.separator"));
500                         }
501                         JTextPane textPane = addTab(f.getName()); 
502                         System.out.println("File = "+f.getAbsolutePath());
503                         textPane.setName(f.getAbsolutePath());
504
505                         ((ScilabStyleDocument) textPane.getStyledDocument()).disableUpdaters(); 
506                         textPane.setText(contents.toString());
507                         if (((ScilabStyleDocument) textPane.getStyledDocument()).getColorize()) {
508                                 ((ScilabStyleDocument) textPane.getStyledDocument()).colorize();
509                         }
510                         if (((ScilabStyleDocument) textPane.getStyledDocument()).getAutoIndent()) {
511                                 ((ScilabStyleDocument) textPane.getStyledDocument()).indent();
512                         }
513                         ((ScilabStyleDocument) textPane.getStyledDocument()).enableUpdaters();
514                         
515                         getTabPane().setTitleAt(getTabPane().getSelectedIndex() , f.getName());
516                         ((ScilabStyleDocument) getTextPane().getStyledDocument()).setContentModified(false);
517                         
518                 } catch (IOException ioex) {
519
520                         int choice = JOptionPane.showConfirmDialog(this, "This file doesn't exist\n Do you want to create it?");
521                         //JOptionPane.showMessageDialog(this, ioex.getMessage());
522                         if (choice  == 0){
523
524                                 try {
525                                                 FileWriter writer = new FileWriter(f);
526                                                 writer.write("");
527                                                 writer.flush();
528                                                 writer.close();
529                                                 
530                                                 readFile(f);
531                                 }catch (Exception ioexc) {
532                                     JOptionPane.showMessageDialog(this , ioexc);
533                                 }
534                         }       
535                 }
536         }
537
538         public JTextPane getTextPane() {
539                 return (JTextPane) ((JScrollPane) tabPane.getSelectedComponent()).getViewport().getComponent(0);
540         }
541
542         public SimpleTab getAsSimpleTab() {
543                 return this;
544         }
545
546         public Window getParentWindow() {
547                 return parentWindow;
548         }
549
550         public void addInfoBar(TextBox infoBarToAdd) {
551                 setInfoBar(infoBarToAdd);
552         }
553
554         public void addMenuBar(MenuBar menuBarToAdd) {
555                 setMenuBar(menuBarToAdd);
556         }
557
558         public void addToolBar(ToolBar toolBarToAdd) {
559                 setToolBar(toolBarToAdd);
560         }
561
562         public JTabbedPane getTabPane() {
563                 return tabPane;
564         }
565
566         public void setTabPane(JTabbedPane tabPane) {
567                 this.tabPane = tabPane;
568         }
569
570         public XpadLineNumberPanel getXln() {
571                 return xln;
572         }
573
574         public void setXln(XpadLineNumberPanel xln) {
575                 this.xln = xln;
576         }
577         
578         public Menu getRecentsMenu(){
579                 return  this.recentsMenu ;
580         }
581         
582         public void displayLineNumbers(boolean display) {
583                 if (display) {
584                         scrollingText.setRowHeaderView(xln);
585                         repaint();
586                 } else {
587                         scrollingText.setRowHeaderView(null);
588                         repaint();
589                 }
590         }
591         
592         public void enableLineHighlight(boolean display) {
593                 xln.setCurrentLineHighlightColor(display);
594                 repaint();
595         }
596         
597         public void updateRecentOpenedFilesMenu () {
598                 ArrayList<File> recentFiles = ConfigXpadManager.getAllRecentOpenedFiles() ;
599                 
600                 ((SwingScilabMenu)getRecentsMenu().getAsSimpleMenu()).removeAll();
601                         for (int i = 0 ; i < recentFiles.size() ; i++ ){
602                                 getRecentsMenu().add( RecentFileAction.createMenu(editor , recentFiles.get(i)));
603                         }
604                         
605         }
606
607 }