Enable Toolbar, mutualize methods for buttons and menus
Bruno JOFRET [Fri, 11 Sep 2009 05:34:01 +0000 (07:34 +0200)]
46 files changed:
scilab/modules/xpad/src/java/org/scilab/modules/xpad/Xpad.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/ASCIIEncodingAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/AboutAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/AutoIndentAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/CloseAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/ColorizeAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/CommentAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/CopyAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/CutAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/DefaultAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/DefaultCheckAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/DeleteAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/EvaluateSelectionAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/ExitAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/FindAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/GotoLineAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/HelpAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/HighlightCurrentLineAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/IndentAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/LineNumbersAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/LoadIntoScilabAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/NewAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/NextTabAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/OpenAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/PageSetupAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/PasteAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/PreviousTabAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/PrintAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/PrintPreviewAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/RecentFileAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/RedoAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/ResetFontAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/SaveAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/SaveAsAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/ScilabStyleAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/SelectAllAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/SetColorsAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/SetFontAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/ShowToolBarAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/TextStyleAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/UTF8EncodingAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/UnCommentAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/UndoAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/WordWrapAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/actions/XMLStyleAction.java
scilab/modules/xpad/src/java/org/scilab/modules/xpad/utils/ConfigXpadManager.java

index 0acdfe3..7069542 100644 (file)
@@ -13,8 +13,6 @@
 package org.scilab.modules.xpad;
 
 import java.awt.Color;
-import java.awt.Event;
-import java.awt.event.KeyEvent;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -25,7 +23,6 @@ import javax.swing.JOptionPane;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
 import javax.swing.JTextPane;
-import javax.swing.KeyStroke;
 import javax.swing.undo.CannotRedoException;
 import javax.swing.undo.CannotUndoException;
 import javax.swing.undo.UndoManager;
@@ -37,7 +34,9 @@ import org.scilab.modules.gui.menubar.MenuBar;
 import org.scilab.modules.gui.menubar.ScilabMenuBar;
 import org.scilab.modules.gui.tab.SimpleTab;
 import org.scilab.modules.gui.tab.Tab;
+import org.scilab.modules.gui.textbox.ScilabTextBox;
 import org.scilab.modules.gui.textbox.TextBox;
+import org.scilab.modules.gui.toolbar.ScilabToolBar;
 import org.scilab.modules.gui.toolbar.ToolBar;
 import org.scilab.modules.gui.window.ScilabWindow;
 import org.scilab.modules.gui.window.Window;
@@ -53,8 +52,6 @@ import org.scilab.modules.xpad.actions.DeleteAction;
 import org.scilab.modules.xpad.actions.EvaluateSelectionAction;
 import org.scilab.modules.xpad.actions.ExitAction;
 import org.scilab.modules.xpad.actions.FindAction;
-import org.scilab.modules.xpad.actions.FindNextAction;
-import org.scilab.modules.xpad.actions.FindPreviousAction;
 import org.scilab.modules.xpad.actions.GotoLineAction;
 import org.scilab.modules.xpad.actions.HelpAction;
 import org.scilab.modules.xpad.actions.HighlightCurrentLineAction;
@@ -85,6 +82,7 @@ import org.scilab.modules.xpad.actions.WordWrapAction;
 import org.scilab.modules.xpad.actions.XMLStyleAction;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 import org.scilab.modules.xpad.utils.ConfigXpadManager;
+import org.scilab.modules.xpad.utils.XpadMessages;
 
 public class Xpad extends SwingScilabTab implements Tab { 
 
@@ -138,117 +136,137 @@ public class Xpad extends SwingScilabTab implements Tab {
                MenuBar menuBar = ScilabMenuBar.createMenuBar();
                //Create FILE menubar
                Menu fileMenu = ScilabMenu.createMenu();
-               fileMenu.setText("File");
+               fileMenu.setText(XpadMessages.FILE);
                fileMenu.setMnemonic('F');
-               fileMenu.add(new NewAction(editor));
-               fileMenu.add(new OpenAction(editor));
+               fileMenu.add(NewAction.createMenu(editor));
+               fileMenu.add(OpenAction.createMenu(editor));
                Menu recentsMenu = ScilabMenu.createMenu();
                recentsMenu.setText("Recent Files");
                for (int i = 0 ; i < recentFiles.size() ; i++ ){
-                       recentsMenu.add(new RecentFileAction(editor , recentFiles.get(i)));
+                       recentsMenu.add(RecentFileAction.createMenu(editor , recentFiles.get(i)));
                }
                
-               
                fileMenu.add(recentsMenu);
                
                fileMenu.addSeparator();
-               fileMenu.add(new SaveAction(editor));
-               fileMenu.add(new SaveAsAction(editor));
-               
+               fileMenu.add(SaveAction.createMenu(editor));
+               fileMenu.add(SaveAsAction.createMenu(editor));
                fileMenu.addSeparator();
-               fileMenu.add(new PageSetupAction(editor));
-               fileMenu.add(new PrintPreviewAction(editor));
-               fileMenu.add(new PrintAction(editor));
-               
+               fileMenu.add(PageSetupAction.createMenu(editor));
+               fileMenu.add(PrintPreviewAction.createMenu(editor));
+               fileMenu.add(PrintAction.createMenu(editor));
                fileMenu.addSeparator();
-               fileMenu.add(new CloseAction(editor));
-               
+               fileMenu.add(CloseAction.createMenu(editor));
                fileMenu.addSeparator();
-               fileMenu.add(new ExitAction(editor));
+               fileMenu.add(ExitAction.createMenu(editor));
                menuBar.add(fileMenu);
 
                //Create EDIT menubar
                Menu editMenu = ScilabMenu.createMenu();
-               editMenu.setText("Edit"); 
+               editMenu.setText(XpadMessages.EDIT); 
                editMenu.setMnemonic('E');
-               editMenu.add(new UndoAction(editor));
-               editMenu.add(new RedoAction(editor));
+               editMenu.add(UndoAction.createMenu(editor));
+               editMenu.add(RedoAction.createMenu(editor));
                editMenu.addSeparator(); 
-               editMenu.add(new CutAction(editor));
-               editMenu.add(new CopyAction(editor));
-               editMenu.add(new PasteAction(editor));
+               editMenu.add(CutAction.createMenu(editor));
+               editMenu.add(CopyAction.createMenu(editor));
+               editMenu.add(PasteAction.createMenu(editor));
                editMenu.addSeparator(); 
-               editMenu.add(new SelectAllAction(editor));
-               editMenu.add(new DeleteAction(editor));
+               editMenu.add(SelectAllAction.createMenu(editor));
+               editMenu.add(DeleteAction.createMenu(editor));
                editMenu.addSeparator();
-               editMenu.add(new CommentAction(editor));
-               editMenu.add(new UnCommentAction(editor));
+               editMenu.add(CommentAction.createMenu(editor));
+               editMenu.add(UnCommentAction.createMenu(editor));
                editMenu.addSeparator();
-               editMenu.add(new IndentAction(editor));
+               editMenu.add(IndentAction.createMenu(editor));
                menuBar.add(editMenu);
 
                // Create SEARCH menubar
                Menu searchMenu = ScilabMenu.createMenu(); 
-               searchMenu.setText("Search");
+               searchMenu.setText(XpadMessages.SEARCH);
                searchMenu.setMnemonic('S');
-               searchMenu.add(new FindAction(editor));
-               searchMenu.add(new FindNextAction(editor));
-               searchMenu.add(new FindPreviousAction(editor));
-               searchMenu.add(new GotoLineAction(editor));
+               searchMenu.add(FindAction.createMenu(editor));
+               searchMenu.add(GotoLineAction.createMenu(editor));
                menuBar.add(searchMenu);
 
                // Create VIEW Menubar
                Menu viewMenu = ScilabMenu.createMenu();
-               viewMenu.setText("View");
-               viewMenu.add(new ShowToolBarAction(editor));
+               viewMenu.setText(XpadMessages.VIEW);
+               viewMenu.add(ShowToolBarAction.createCheckBoxMenu(editor));
                viewMenu.addSeparator();
-               viewMenu.add(new HighlightCurrentLineAction(editor));
-               viewMenu.add(new WordWrapAction(editor));
-               viewMenu.add(new LineNumbersAction(editor));
-               viewMenu.add(new SetColorsAction(editor));
-               viewMenu.add(new SetFontAction(editor));
-               viewMenu.add(new ResetFontAction(editor));
+               viewMenu.add(HighlightCurrentLineAction.createCheckBoxMenu(editor));
+               viewMenu.add(WordWrapAction.createCheckBoxMenu(editor));
+               viewMenu.add(LineNumbersAction.createCheckBoxMenu(editor));
+               viewMenu.add(SetColorsAction.createMenu(editor));
+               viewMenu.add(SetFontAction.createMenu(editor));
+               viewMenu.add(ResetFontAction.createMenu(editor));
                menuBar.add(viewMenu);
 
                // Create DOCUMENT MenuBar
                Menu documentMenu = ScilabMenu.createMenu();
-               documentMenu.setText("Document");
+               documentMenu.setText(XpadMessages.DOCUMENT);
                Menu syntaxTypeMenu = ScilabMenu.createMenu();
                syntaxTypeMenu.setText("Syntax Type");
                documentMenu.add(syntaxTypeMenu);
-               syntaxTypeMenu.add(new TextStyleAction(editor));
-               syntaxTypeMenu.add(new ScilabStyleAction(editor));
-               syntaxTypeMenu.add(new XMLStyleAction(editor));
+               syntaxTypeMenu.add(TextStyleAction.createCheckBoxMenu(editor));
+               syntaxTypeMenu.add(ScilabStyleAction.createCheckBoxMenu(editor));
+               syntaxTypeMenu.add(XMLStyleAction.createCheckBoxMenu(editor));
                documentMenu.addSeparator();
                Menu encodingTypeMenu = ScilabMenu.createMenu();
                encodingTypeMenu.setText("Encoding Type");
                documentMenu.add(encodingTypeMenu);
-               encodingTypeMenu.add(new ASCIIEncodingAction(editor));
-               encodingTypeMenu.add(new UTF8EncodingAction(editor));
+               encodingTypeMenu.add(ASCIIEncodingAction.createCheckBoxMenu(editor));
+               encodingTypeMenu.add(UTF8EncodingAction.createCheckBoxMenu(editor));
                documentMenu.addSeparator();
-               documentMenu.add(new ColorizeAction(editor));
-               documentMenu.add(new AutoIndentAction(editor));
+               documentMenu.add(ColorizeAction.createMenu(editor));
+               documentMenu.add(AutoIndentAction.createCheckBoxMenu(editor));
                menuBar.add(documentMenu);
 
                // Create EXECUTE menubar
                Menu executeMenu = ScilabMenu.createMenu();
-               executeMenu.setText("Execute");
+               executeMenu.setText(XpadMessages.EXECUTE);
                executeMenu.setMnemonic('e');
-               executeMenu.add(new LoadIntoScilabAction(editor));
-               executeMenu.add(new EvaluateSelectionAction(editor));
+               executeMenu.add(LoadIntoScilabAction.createMenu(editor));
+               executeMenu.add(EvaluateSelectionAction.createMenu(editor));
                menuBar.add(executeMenu);
 
                //Create HELP menubar
                Menu helpMenu = ScilabMenu.createMenu();
                helpMenu.setText("?");
-               helpMenu.add(new HelpAction(editor));
-               helpMenu.add(new AboutAction(editor));
+               helpMenu.add(HelpAction.createMenu(editor));
+               helpMenu.add(AboutAction.createMenu(editor));
                menuBar.add(helpMenu);
 
+               // Create TOOLBAR
+               ToolBar toolBar = ScilabToolBar.createToolBar();
+               toolBar.add(NewAction.createButton(editor)); // NEW
+               toolBar.add(OpenAction.createButton(editor)); // OPEN
+               toolBar.addSeparator();
+               toolBar.add(SaveAction.createButton(editor)); // SAVE
+               //toolBar.add(SaveAsAction.createButton(editor)); // SAVE AS
+               toolBar.addSeparator();
+               //toolBar.add(PrintPreviewAction.createButton(editor)); // PRINT PREVIEW
+               toolBar.add(PrintAction.createButton(editor)); // PRINT
+               toolBar.addSeparator();
+               toolBar.add(UndoAction.createButton(editor)); // UNDO
+               toolBar.add(RedoAction.createButton(editor)); // REDO
+               toolBar.addSeparator();
+               toolBar.add(CutAction.createButton(editor)); // CUT
+               toolBar.add(CopyAction.createButton(editor)); // COPY
+               toolBar.add(PasteAction.createButton(editor)); // PASTE
+               toolBar.addSeparator();
+               toolBar.add(FindAction.createButton(editor)); // FIND / REPLACE
+               
+               
+               TextBox infoBar = ScilabTextBox.createTextBox();
+               
+               
                editor.setMenuBar(menuBar);
+               editor.setToolBar(toolBar);
+               editor.setInfoBar(infoBar);
                mainWindow.setTitle("XPad");
                mainWindow.setVisible(true);
-               editor.setCallback((new ExitAction(editor)).getCallback());
+               editor.setCallback(ExitAction.createMenu(editor).getCallback());
                return editor;
        }
 
@@ -290,14 +308,6 @@ public class Xpad extends SwingScilabTab implements Tab {
 
                textPane.setFocusable(true);
 
-               KeyStroke key;
-               key = KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK);
-               textPane.getInputMap().put(key, new UndoAction(this));
-               key = KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK);
-               textPane.getInputMap().put(key, new RedoAction(this));
-               key = KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK);
-               textPane.getInputMap().put(key, new FindAction(this));
-               
                return textPane;
        }
 
index 6302daf..35c8b4d 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class ASCIIEncodingAction extends DefaultCheckAction {
 
-    public ASCIIEncodingAction(Xpad editor) {
+    private ASCIIEncodingAction(Xpad editor) {
        super("ASCII Encoding", editor);
     }
     
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("ASCII Encoding", null, new ASCIIEncodingAction(editor), null);
+    }
+    
 }
index ab7864e..f67d24c 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class AboutAction extends DefaultAction {
 
-    public AboutAction(Xpad editor) {
+    private AboutAction(Xpad editor) {
        super("About...", editor);
     }
 
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("About...", null, new AboutAction(editor), null);
+    }
 }
index 2fff7a9..f67cdb4 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class AutoIndentAction extends DefaultCheckAction  {
 
 
-    public AutoIndentAction(Xpad editor) {
+    private AutoIndentAction(Xpad editor) {
        super("Auto Indent", editor);
-       setState(false);
     }
 
     public void doAction() {
        getEditor().setAutoIndent(this.getState());
     }
 
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("Auto Indent", null, new AutoIndentAction(editor), null);
+    }
 
 }
index 4b9fe12..42d08c4 100644 (file)
@@ -18,18 +18,21 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class CloseAction extends DefaultAction {
     
-    public CloseAction(Xpad editor) {
+    private CloseAction(Xpad editor) {
         super("Close", editor);
-        //setMnemonic('W');
-        setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));
     }
     
     public void doAction() {
        getEditor().closeCurrentTab();
        Xpad.closeXpad();
     }
+    
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Close", null, new CloseAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));
+    }
 }
\ No newline at end of file
index 8e0e0d6..2aa032b 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
+import javax.swing.KeyStroke;
+
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 
 public class ColorizeAction extends DefaultAction {
 
-       public ColorizeAction(Xpad editor) {
+       private ColorizeAction(Xpad editor) {
                super("Colorize", editor);
-               //setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_, ActionEvent.CTRL_MASK));
        }
 
        public void doAction() {
                ((ScilabStyleDocument) getEditor().getTextPane().getStyledDocument()).colorize();
        }
 
+       public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Colorize", null, new ColorizeAction(editor), null);
+        }
 }
index c02313f..fbcaa48 100644 (file)
@@ -17,14 +17,14 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 
 public class CommentAction extends DefaultAction {
 
-       public CommentAction(Xpad editor) {
+       private CommentAction(Xpad editor) {
                super("Comment Selection", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
        }
        
        public void doAction() {
@@ -33,4 +33,8 @@ public class CommentAction extends DefaultAction {
                
                ((ScilabStyleDocument) getEditor().getTextPane().getStyledDocument()).commentText(start_position, end_position);
        }
+       
+       public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Comment Selection", null, new CommentAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
+        }
 }
index 5a64e37..5cff698 100644 (file)
@@ -18,18 +18,25 @@ import java.awt.event.KeyEvent;
 import javax.swing.KeyStroke;
 import javax.swing.text.DefaultEditorKit;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class CopyAction extends DefaultAction {
 
-    public CopyAction(Xpad editor) {
+    private CopyAction(Xpad editor) {
        super("Copy", editor);
-       //setMnemonic('c');
-       setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
     }
     
     public void doAction() {
        getEditor().getTextPane().getActionMap().get(DefaultEditorKit.copyAction).actionPerformed(null);
     }
-
+    
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Copy", null, new CopyAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
+    }
+    
+    public static PushButton createButton(Xpad editor) {
+       return createButton("Copy", "edit-copy.png", new CopyAction(editor));
+    }
 }
index cf20c4b..8ccf89f 100644 (file)
@@ -18,18 +18,26 @@ import java.awt.event.KeyEvent;
 import javax.swing.KeyStroke;
 import javax.swing.text.DefaultEditorKit;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class CutAction extends DefaultAction {
 
-    public CutAction(Xpad editor) {
+    private CutAction(Xpad editor) {
        super("Cut", editor);
-       //setMnemonic('c');
-       setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
     }
     
     public void doAction() {
        getEditor().getTextPane().getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null);
     }
 
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Cut", null, new CutAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
+    }
+    
+    public static PushButton createButton(Xpad editor) {
+       return createButton("Cut", "edit-cut.png", new CutAction(editor));
+    }
+    
 }
index 109c50f..829214c 100644 (file)
 package org.scilab.modules.xpad.actions;
 
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 
+import javax.swing.ImageIcon;
 import javax.swing.JOptionPane;
+import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.bridge.checkboxmenuitem.SwingScilabCheckBoxMenuItem;
 import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
-import org.scilab.modules.gui.events.callback.CallBack;
-import org.scilab.modules.gui.menu.SimpleMenu;
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
+import org.scilab.modules.gui.checkboxmenuitem.ScilabCheckBoxMenuItem;
 import org.scilab.modules.gui.menuitem.MenuItem;
-import org.scilab.modules.gui.menuitem.SimpleMenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
 import org.scilab.modules.xpad.Xpad;
 
-public class DefaultAction extends SwingScilabMenuItem implements MenuItem {
+public class DefaultAction implements ActionListener {
     private Xpad _editor;
 
-    public DefaultAction(Xpad editor) {
-       super();
-       setText("Default...");
+    private DefaultAction(Xpad editor) {
        _editor = editor;
-       setCallback(new CallBack("Default...") {
-
-           public void callBack() {
-               doAction();
-           }
-
-           public void actionPerformed(ActionEvent e) {
-               callBack();
-           } 
-       });
     }
 
     protected DefaultAction(String label, Xpad editor) {
-       super();
-       setText(label);
        _editor = editor;
-       setCallback(new CallBack("Default...") {
-           public void callBack() {
-               doAction();
-           }
-
-           public void actionPerformed(ActionEvent e) {
-               callBack();
-           } 
-       });
     }
 
     public Xpad getEditor() {
        return _editor;
     }
 
-    public SimpleMenuItem getAsSimpleMenuItem() {
-       return (SwingScilabMenuItem) this;
+    protected static PushButton createButton(String title, String icon, ActionListener listener) {
+       PushButton button = ScilabPushButton.createPushButton(); 
+       ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(listener);
+        button.setToolTipText(title);
+        if (icon == null) {
+           button.setText(title);
+       }
+       else {
+           ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(new ImageIcon(System.getenv("SCI")+"/modules/gui/images/icons/"+icon));
+       }
+       
+       return button;
+    }
+
+    protected static MenuItem createMenu(String title, String icon, ActionListener listener, KeyStroke keyStroke) {
+       MenuItem menu = ScilabMenuItem.createMenuItem();
+       ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).addActionListener(listener);
+       menu.setText(title);
+       
+       if (keyStroke != null) {
+           ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(keyStroke);
+       }
+       
+       return menu;
     }
 
     public void doAction() {
          JOptionPane.showMessageDialog(getEditor(), "Not Implemented Now !!!", null, JOptionPane.ERROR_MESSAGE);
     }
 
-    public SimpleMenu getAsSimpleMenu() {
-       return null;
+    public void actionPerformed(ActionEvent arg0) {
+       doAction();
     }
 
 }
index 1e36be2..73ac141 100644 (file)
 package org.scilab.modules.xpad.actions;
 
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 
 import javax.swing.JOptionPane;
+import javax.swing.KeyStroke;
 
 import org.scilab.modules.gui.bridge.checkboxmenuitem.SwingScilabCheckBoxMenuItem;
 import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
@@ -24,7 +26,7 @@ import org.scilab.modules.gui.menu.SimpleMenu;
 import org.scilab.modules.gui.menuitem.SimpleMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
-public class DefaultCheckAction extends SwingScilabCheckBoxMenuItem implements CheckBoxMenuItem {
+public class DefaultCheckAction extends SwingScilabCheckBoxMenuItem implements CheckBoxMenuItem, ActionListener {
     private Xpad _editor;
 
     public DefaultCheckAction(Xpad editor) {
@@ -60,24 +62,40 @@ public class DefaultCheckAction extends SwingScilabCheckBoxMenuItem implements C
        });
     }
 
+  
+    
     public Xpad getEditor() {
        return _editor;
     }
 
+    public void doAction() {
+         JOptionPane.showMessageDialog(getEditor(), "Not Implemented Now !!! (state = "+getState()+")", null, JOptionPane.ERROR_MESSAGE);
+    }
+
+    public void actionPerformed(ActionEvent arg0) {
+       doAction();
+    }
+    
+    protected static CheckBoxMenuItem createCheckBoxMenu(String title, String icon, DefaultCheckAction defaultCheckAction, KeyStroke keyStroke) {
+       defaultCheckAction.setText(title);
+       defaultCheckAction.setChecked(false);
+       if (keyStroke != null) {
+           ((SwingScilabCheckBoxMenuItem) defaultCheckAction.getAsSimpleCheckBoxMenuItem()).setAccelerator(keyStroke);
+       }
+       
+       return defaultCheckAction;
+       
+    }
+
     public SimpleCheckBoxMenuItem getAsSimpleCheckBoxMenuItem() {
-       return (SwingScilabCheckBoxMenuItem) this;
+       return this;
     }
 
     public SimpleMenuItem getAsSimpleMenuItem() {
        return null;
     }
 
-    public void doAction() {
-         JOptionPane.showMessageDialog(getEditor(), "Not Implemented Now !!! (state = "+getState()+")", null, JOptionPane.ERROR_MESSAGE);
-    }
-
     public SimpleMenu getAsSimpleMenu() {
        return null;
     }
-
 }
index 3afbbb5..9e44c60 100644 (file)
@@ -14,11 +14,12 @@ package org.scilab.modules.xpad.actions;
 
 import javax.swing.text.DefaultEditorKit;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class DeleteAction extends DefaultAction {
 
-    public DeleteAction(Xpad editor) {
+    private DeleteAction(Xpad editor) {
        super("Delete", editor);
     }
     
@@ -26,4 +27,8 @@ public class DeleteAction extends DefaultAction {
        getEditor().getTextPane().getActionMap().get(DefaultEditorKit.deleteNextCharAction).actionPerformed(null);
     }
 
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Delete", null, new DeleteAction(editor), null);
+    }
+    
 }
index 850ffa5..fa78edb 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.gui.console.ScilabConsole;
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 
 public class EvaluateSelectionAction extends DefaultAction {
 
-       public EvaluateSelectionAction(Xpad editor) {
+       private EvaluateSelectionAction(Xpad editor) {
                super("Evaluate Selection", editor);
        }
 
@@ -28,4 +28,8 @@ public class EvaluateSelectionAction extends DefaultAction {
            //InterpreterManagement.requestScilabExec(getEditor().getTextPane().getText());
            ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(getEditor().getTextPane().getSelectedText(), true, false);
        }
+       
+        public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Evaluate Selection", null, new EvaluateSelectionAction(editor), null);
+        }
 }
index 0ab5dec..3cc32ea 100644 (file)
@@ -18,16 +18,15 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.utils.UIElementMapper;
 import org.scilab.modules.gui.window.ScilabWindow;
 import org.scilab.modules.xpad.Xpad;
 
 public class ExitAction extends DefaultAction {
 
-    public ExitAction(Xpad editor) {
+    private ExitAction(Xpad editor) {
        super("Exit", editor);
-       //setMnemonic('X');
-       setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
     }
 
     public void doAction() {
@@ -36,4 +35,8 @@ public class ExitAction extends DefaultAction {
        xpadWindow.getAsSimpleWindow().removeTab(getEditor());
        Xpad.closeXpad();
     }
+    
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Exit", null, new ExitAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
+    }
 }
\ No newline at end of file
index 5dd048f..0feb50c 100644 (file)
@@ -45,6 +45,8 @@ import javax.swing.text.DefaultHighlighter;
 import javax.swing.text.Highlighter;
 import javax.swing.text.Highlighter.Highlight;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 
@@ -84,10 +86,8 @@ public class FindAction extends DefaultAction {
        int endFindSelection ;
 
 
-       public FindAction(Xpad editor) {
+       private FindAction(Xpad editor) {
                super("Find/Replace...", editor);
-               //setMnemonic('F');
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
        }
 
        public void doAction() {
@@ -95,6 +95,14 @@ public class FindAction extends DefaultAction {
                findReplaceBox();
        }
 
+        public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Find/Replace...", null, new FindAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
+        }
+        
+        public static PushButton createButton(Xpad editor) {
+            return createButton("Find/Replace...", "edit-find-replace.png", new FindAction(editor));
+        }
+       
        public void findReplaceBox() {
 
                //Find & Replace Frame
index 9e57e58..59c38a9 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
+import javax.swing.KeyStroke;
+
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class GotoLineAction extends DefaultAction {
 
-       public GotoLineAction(Xpad editor) {
+       private GotoLineAction(Xpad editor) {
                super("Goto Line...", editor);
        }
+       
+       public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Goto Line...", null, new GotoLineAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK));
+        }
+        
 }
index 88ac0f5..d189d1a 100644 (file)
 package org.scilab.modules.xpad.actions;
 
 import org.scilab.modules.action_binding.InterpreterManagement;
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class HelpAction extends DefaultAction {
 
-    public HelpAction(Xpad editor) {
+    private HelpAction(Xpad editor) {
        super("Help...", editor);
     }
     
@@ -25,4 +26,7 @@ public class HelpAction extends DefaultAction {
        InterpreterManagement.requestScilabExec("help('xpad')");
     }
 
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Help...", null, new HelpAction(editor), null);
+    }
 }
index 9c19295..2cf4323 100644 (file)
@@ -16,17 +16,21 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class HighlightCurrentLineAction extends DefaultCheckAction {
 
-    public HighlightCurrentLineAction(Xpad editor) {
+    private HighlightCurrentLineAction(Xpad editor) {
        super("Highlight current line", editor);
-       setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK));
        setState(false);
     }
-    
-       public void doAction() {
-               getEditor().enableLineHighlight(this.getState());
-       }
+
+    public void doAction() {
+       getEditor().enableLineHighlight(this.getState());
+    }
+
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("Highlight current line", null, new HighlightCurrentLineAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK));
+    }
 }
index c94d5b3..c0d3ccd 100644 (file)
@@ -17,14 +17,14 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 
 public class IndentAction extends DefaultAction {
        
-       public IndentAction(Xpad editor) {
+       private IndentAction(Xpad editor) {
                super("Indent", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK));
        }
        
        public void doAction() {
@@ -33,7 +33,10 @@ public class IndentAction extends DefaultAction {
                ((ScilabStyleDocument) getEditor().getTextPane().getStyledDocument()).indent();
                
                getEditor().getTextPane().setCaretPosition(initial_caret_position);
-               
        }
 
+        public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Indent", null, new IndentAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK));
+        }
+       
 }
index 88802b9..21c41d9 100644 (file)
@@ -16,16 +16,21 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class LineNumbersAction extends DefaultCheckAction {
 
-    public LineNumbersAction(Xpad editor) {
+    private LineNumbersAction(Xpad editor) {
        super("Line Numbers", editor);
        setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK));
     }
-    
-       public void doAction() {
-               getEditor().displayLineNumbers(this.getState());
-       }
+
+    public void doAction() {
+       getEditor().displayLineNumbers(this.getState());
+    }
+
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("Line Numbers", null, new LineNumbersAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK));
+    }
 }
index 45e78d5..85fa408 100644 (file)
 package org.scilab.modules.xpad.actions;
 
 import org.scilab.modules.gui.console.ScilabConsole;
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class LoadIntoScilabAction extends DefaultAction {
 
-       public LoadIntoScilabAction(Xpad editor) {
+       private LoadIntoScilabAction(Xpad editor) {
                super("Load Into Scilab", editor);
        }
 
@@ -26,4 +27,8 @@ public class LoadIntoScilabAction extends DefaultAction {
            //InterpreterManagement.requestScilabExec(getEditor().getTextPane().getText());
            ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(getEditor().getTextPane().getText(), true, false);
        }
+       
+       public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Load Into Scilab", null, new LoadIntoScilabAction(editor), null);
+        }
 }
index f736161..7d9842b 100644 (file)
@@ -17,17 +17,25 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class NewAction extends DefaultAction {
 
-       public NewAction(Xpad editor) {
-               super("New...", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
-       }
-
-       public void doAction() {
-           getEditor().addEmptyTab();
-       }
-
+    private NewAction(Xpad editor) {
+       super("New...", editor);
+    }
+
+    public void doAction() {
+       getEditor().addEmptyTab();
+    }
+    
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("New...", null, new NewAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
+    }
+    
+    public static PushButton createButton(Xpad editor) {
+       return createButton("New...", "document-new.png", new NewAction(editor));
+    }
 }
index 3349513..015d0b4 100644 (file)
@@ -17,17 +17,22 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class NextTabAction extends DefaultAction {
 
-       public NextTabAction(Xpad editor) {
+       private NextTabAction(Xpad editor) {
                super("Next tab", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, ActionEvent.CTRL_MASK));
        }
        
        public void doAction() {
                int index = this.getEditor().getTabPane().getSelectedIndex();
                System.out.println(index);
        }
+       
+       public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Next tab", null, new NextTabAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_TAB, ActionEvent.CTRL_MASK));
+        }
+       
 }
index b75bdef..0d1f0f5 100644 (file)
@@ -19,15 +19,15 @@ import java.io.File;
 import javax.swing.JFileChooser;
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.utils.ConfigXpadManager;
 
 public class OpenAction extends DefaultAction {
 
-    public OpenAction(Xpad editor) {
+    private OpenAction(Xpad editor) {
        super("Open...", editor);
-       //setMnemonic('O');
-       setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
     }
 
     public void doAction() {
@@ -41,5 +41,12 @@ public class OpenAction extends DefaultAction {
            
        }
     }
-
+    
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Open...", null, new OpenAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
+    }
+    
+    public static PushButton createButton(Xpad editor) {
+       return createButton("Open...", "document-open.png", new OpenAction(editor));
+    }
 }
index 8fffdf1..b689874 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class PageSetupAction extends DefaultAction {
 
-       public PageSetupAction(Xpad editor) {
+       private PageSetupAction(Xpad editor) {
                super("Page Setup...", editor);
        }
 
+        public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Page Setup...", null, new PageSetupAction(editor), null);
+        }
 }
index cc0255c..8736539 100644 (file)
@@ -18,18 +18,25 @@ import java.awt.event.KeyEvent;
 import javax.swing.KeyStroke;
 import javax.swing.text.DefaultEditorKit;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class PasteAction extends DefaultAction {
 
-    public PasteAction(Xpad editor) {
+    private PasteAction(Xpad editor) {
        super("Paste", editor);
-       //setMnemonic('c');
-       setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
     }
     
     public void doAction() {
        getEditor().getTextPane().getActionMap().get(DefaultEditorKit.pasteAction).actionPerformed(null);
     }
 
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Paste", null, new PasteAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
+    }
+    
+    public static PushButton createButton(Xpad editor) {
+       return createButton("Paste", "edit-paste.png", new PasteAction(editor));
+    }
 }
index 9271b6c..4b1dd54 100644 (file)
@@ -17,17 +17,21 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class PreviousTabAction extends DefaultAction {
 
-       public PreviousTabAction(Xpad editor) {
+       private PreviousTabAction(Xpad editor) {
                super("Previous tab", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SHIFT & KeyEvent.VK_TAB, ActionEvent.CTRL_MASK));
        }
        
        public void doAction() {
                int index = this.getEditor().getTabPane().getSelectedIndex();
                System.out.println(index);
        }
+
+       public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Save", null, new PreviousTabAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_TAB, ActionEvent.CTRL_MASK+ActionEvent.SHIFT_MASK));
+        }
 }
index b9eabf6..4f4bde9 100644 (file)
@@ -17,13 +17,22 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class PrintAction extends DefaultAction {
 
-       public PrintAction(Xpad editor) {
+       private PrintAction(Xpad editor) {
                super("Print...", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
        }
 
+       public static MenuItem createMenu(Xpad editor) {
+           return createMenu("Print...", null, new PrintAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
+       }
+
+       public static PushButton createButton(Xpad editor) {
+           return createButton("Print...", "document-print.png", new PrintAction(editor));
+       }
+       
 }
index 8ce2a0a..439b996 100644 (file)
@@ -17,12 +17,22 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class PrintPreviewAction extends DefaultAction {
 
-    public PrintPreviewAction(Xpad editor) {
+    private PrintPreviewAction(Xpad editor) {
        super("Print Preview...", editor);
     }
     
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Print Preview...", null, new PrintPreviewAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK+ActionEvent.SHIFT_MASK));
+    }
+    
+    public static PushButton createButton(Xpad editor) {
+       return createButton("Print Preview...", "document-print-preview.png", new PrintPreviewAction(editor));
+    }
+    
 }
index c8197ea..52d800d 100644 (file)
 package org.scilab.modules.xpad.actions;
 import java.io.File;
 
-import javax.swing.KeyStroke;
-
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.utils.ConfigXpadManager;
 
-
-
 public class RecentFileAction extends DefaultAction {
        
        private File recentFile ;
 
-       public RecentFileAction(Xpad editor , File f) {
+       private RecentFileAction(Xpad editor , File f) {
                super(f.getName(), editor);
                recentFile = f ;
-               //setMnemonic('S');
-               
        }
        
        public void doAction() {
                ConfigXpadManager.saveToRecentOpenedFiles(recentFile.getPath());
                getEditor().readFile(recentFile);
-               
-               
-               
        };
 
-
-
+       public static MenuItem createMenu(Xpad editor, File f) {
+           return createMenu(f.getName(), null, new RecentFileAction(editor, f), null);
+       }
 }
\ No newline at end of file
index 11d6f5a..439456e 100644 (file)
@@ -17,16 +17,25 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class RedoAction extends DefaultAction {
 
-       public RedoAction(Xpad editor) {
+       private RedoAction(Xpad editor) {
                super("Redo", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK));
        }
 
        public void doAction() {
                getEditor().redo();
        }
+       
+       public static MenuItem createMenu(Xpad editor) {
+           return createMenu("Redo", null, new RedoAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK));
+       }
+
+       public static PushButton createButton(Xpad editor) {
+           return createButton("Redo", "edit-redo.png", new RedoAction(editor));
+       }
 }
index 0b2c513..b91e405 100644 (file)
@@ -1,22 +1,20 @@
 package org.scilab.modules.xpad.actions;
 
 import java.awt.Font;
-import java.io.File;
 import java.util.ArrayList;
 
-import javax.swing.JFileChooser;
 import javax.swing.text.Style;
 import javax.swing.text.StyleConstants;
 
-import org.scilab.modules.gui.bridge.fontchooser.SwingScilabFontChooser;
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 import org.scilab.modules.xpad.utils.ConfigXpadManager;
 
 public class ResetFontAction extends DefaultAction {
 
-    public ResetFontAction(Xpad editor) {
-       super("Reset default font...", editor);
+    private ResetFontAction(Xpad editor) {
+       super("Reset default font", editor);
     }
     
     public void doAction() {
@@ -54,5 +52,9 @@ public class ResetFontAction extends DefaultAction {
                
                ConfigXpadManager.saveFont(oldFont);
        }
+    
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Reset default font", null, new ResetFontAction(editor), null);
+ }
        
     }
index f668fca..72f576b 100644 (file)
@@ -14,23 +14,25 @@ package org.scilab.modules.xpad.actions;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
-import java.io.File;
-import java.io.FileWriter;
 
-import javax.swing.JFileChooser;
-import javax.swing.JOptionPane;
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class SaveAction extends DefaultAction {
 
-       public SaveAction(Xpad editor) {
+       private SaveAction(Xpad editor) {
                super("Save", editor);
-               //setMnemonic('S');
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
        }
 
-
+        public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Save", null, new SaveAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
+        }
+        
+        public static PushButton createButton(Xpad editor) {
+            return createButton("Save", "media-floppy.png", new SaveAction(editor));
+        }
 
 }
\ No newline at end of file
index 035f925..0127180 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
 import java.io.File;
 import java.io.FileWriter;
 
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
+import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.utils.ConfigXpadManager;
 
 public class SaveAsAction extends DefaultAction {
 
-       public SaveAsAction(Xpad editor) {
+       private SaveAsAction(Xpad editor) {
                super("Save As...", editor);
        }
 
@@ -48,4 +53,12 @@ public class SaveAsAction extends DefaultAction {
                        }
                }
        }
+       
+        public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Save As...", null, new SaveAsAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK+ActionEvent.SHIFT_MASK));
+        }
+        
+        public static PushButton createButton(Xpad editor) {
+            return createButton("Save As...", "document-save-as.png", new SaveAsAction(editor));
+        }
 }
index 5261216..fe8fc69 100644 (file)
  */
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class ScilabStyleAction extends DefaultCheckAction {
 
-    public ScilabStyleAction(Xpad editor) {
+    private ScilabStyleAction(Xpad editor) {
        super("Scilab", editor);
     }
+    
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("Scilab", null, new ScilabStyleAction(editor), null);
+    }
 }
index 463f620..11300e4 100644 (file)
@@ -18,17 +18,21 @@ import java.awt.event.KeyEvent;
 import javax.swing.KeyStroke;
 import javax.swing.text.DefaultEditorKit;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class SelectAllAction extends DefaultAction {
 
-    public SelectAllAction(Xpad editor) {
+    private SelectAllAction(Xpad editor) {
        super("Select All", editor);
-       setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
     }
     
     public void doAction() {
        getEditor().getTextPane().getActionMap().get(DefaultEditorKit.selectAllAction).actionPerformed(null);
     }
 
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Select All", null, new SelectAllAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
+    }
+
 }
index d792579..febf847 100644 (file)
 package org.scilab.modules.xpad.actions;
 
 import java.awt.Color;
-import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
-import java.awt.GridLayout;
 import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -26,11 +24,11 @@ import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
-import javax.swing.SpringLayout;
 import javax.swing.text.Style;
 import javax.swing.text.StyleConstants;
 
 import org.scilab.modules.gui.bridge.colorchooser.SwingScilabColorChooser;
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 import org.scilab.modules.xpad.utils.ConfigXpadManager;
@@ -45,18 +43,20 @@ public class SetColorsAction extends DefaultAction {
        private int numberOfStyles ;
        Hashtable<String, Color> allStylesColor ;
        
-    public SetColorsAction(Xpad editor) {
+    private SetColorsAction(Xpad editor) {
        super("Set Colors...", editor);
     }
     
     
     public void doAction() {
        changeColorsBox ();
-
+    }
     
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Set Colors...", null, new SetColorsAction(editor), null);
     }
     
-    public void changeColorsBox () {
+    private void changeColorsBox () {
        
                frame = new JFrame();
                JPanel panel = new JPanel(new GridBagLayout( ));
index 75360b9..72c62ab 100644 (file)
@@ -1,21 +1,20 @@
 package org.scilab.modules.xpad.actions;
 
 import java.awt.Font;
-import java.io.File;
 import java.util.ArrayList;
 
-import javax.swing.JFileChooser;
 import javax.swing.text.Style;
 import javax.swing.text.StyleConstants;
 
 import org.scilab.modules.gui.bridge.fontchooser.SwingScilabFontChooser;
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 import org.scilab.modules.xpad.utils.ConfigXpadManager;
 
 public class SetFontAction extends DefaultAction {
 
-    public SetFontAction(Xpad editor) {
+    private SetFontAction(Xpad editor) {
        super("Set Font...", editor);
     }
     
@@ -58,5 +57,9 @@ public class SetFontAction extends DefaultAction {
        }
        
     }
+    
+    public static MenuItem createMenu(Xpad editor) {
+       return createMenu("Set Font...", null, new SetFontAction(editor), null);
+    }
 
 }
index 9bc2242..ca00b78 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class ShowToolBarAction extends DefaultCheckAction {
 
-    public ShowToolBarAction(Xpad editor) {
+    private ShowToolBarAction(Xpad editor) {
        super("Show/Hide ToolBar", editor);
     }
     
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("Show/Hide ToolBar", null, new ShowToolBarAction(editor), null);
+    }
+    
 }
index ec74abb..68e3618 100644 (file)
  */
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class TextStyleAction extends DefaultCheckAction {
 
-    public TextStyleAction(Xpad editor) {
+    private TextStyleAction(Xpad editor) {
        super("Plain Text", editor);
     }
+    
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("Plain Text", null, new TextStyleAction(editor), null);
+    }
 }
index 7d65774..2107d6a 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class UTF8EncodingAction extends DefaultCheckAction {
 
-    public UTF8EncodingAction(Xpad editor) {
+    private UTF8EncodingAction(Xpad editor) {
        super("UTF-8 Encoding", editor);
     }
+    
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("UTF-8 Encoding", null, new UTF8EncodingAction(editor), null);
+    }
 }
index 7de5f0c..e1de776 100644 (file)
@@ -17,14 +17,14 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xpad.Xpad;
 import org.scilab.modules.xpad.style.ScilabStyleDocument;
 
 public class UnCommentAction extends DefaultAction {
 
-       public UnCommentAction(Xpad editor) {
+       private UnCommentAction(Xpad editor) {
                super("Uncomment Selection", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
        }
        
        public void doAction() {
@@ -33,4 +33,8 @@ public class UnCommentAction extends DefaultAction {
                
                ((ScilabStyleDocument) getEditor().getTextPane().getStyledDocument()).commentText(start_position, end_position);
        }
+       
+        public static MenuItem createMenu(Xpad editor) {
+               return createMenu("Uncomment Selection", null, new UnCommentAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
+        }
 }
index 5dd7533..0cf1ae9 100644 (file)
@@ -17,16 +17,26 @@ import java.awt.event.KeyEvent;
 
 import javax.swing.KeyStroke;
 
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xpad.Xpad;
 
 public class UndoAction extends DefaultAction {
 
-       public UndoAction(Xpad editor) {
+       private UndoAction(Xpad editor) {
                super("Undo", editor);
-               setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
        }
 
        public void doAction() {
                getEditor().undo();
        }
+
+       public static MenuItem createMenu(Xpad editor) {
+           return createMenu("Undo", null, new UndoAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
+       }
+
+       public static PushButton createButton(Xpad editor) {
+           return createButton("Undo", "edit-undo.png", new UndoAction(editor));
+       }
+
 }
index 3cac440..37a4685 100644 (file)
  */
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class WordWrapAction extends DefaultCheckAction {
     
-    public WordWrapAction(Xpad editor) {
+    private WordWrapAction(Xpad editor) {
        super("Word Wrap", editor);
     }
     
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("Word Wrap", null, new WordWrapAction(editor), null);
+    }
+    
 }
index 46caa26..eee395e 100644 (file)
 
 package org.scilab.modules.xpad.actions;
 
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
 import org.scilab.modules.xpad.Xpad;
 
 public class XMLStyleAction extends DefaultCheckAction {
 
-    public XMLStyleAction(Xpad editor) {
+    private  XMLStyleAction(Xpad editor) {
        super("XML", editor);
     }
+    
+    public static CheckBoxMenuItem createCheckBoxMenu(Xpad editor) {
+       return createCheckBoxMenu("XML", null, new XMLStyleAction(editor), null);
+    }
 }
index b2d8594..de70640 100644 (file)
@@ -619,23 +619,23 @@ public class ConfigXpadManager {
 
 
                Element root = (Element )document.getDocumentElement().getElementsByTagName("recentFiles").item(0);
-               NodeList recentFiles= root.getElementsByTagName("document");
-               
-               for (int i = 0; i < recentFiles.getLength() ; ++i){
+               if(root != null) {
+                   NodeList recentFiles= root.getElementsByTagName("document");
+
+                   for (int i = 0; i < recentFiles.getLength() ; ++i){
                        Element style =(Element) recentFiles.item(i);
-               
-                       
+
                        File temp = new File(style.getAttribute("path") ) ;
-                       
+
                        if (temp.exists())
-                               files.add(temp);
+                           files.add(temp);
                        else
-                               root.removeChild((Node)style );
-                       
+                           root.removeChild((Node)style );
+
                        /* Save changes */
                        writeDocument();
-                       
-               }               
+                   }           
+               }
                return files ;
        }