<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
- <comment>Map between action and keys</comment>
+ <comment>
+ Map between action and keys
+ If no path is given, org.scilab.modules.scinotes.actions will be choosen
+ </comment>
- <entry key="ActivateHelpOnTypingAction">control alt H</entry>
- <entry key="GenerateHelpFromFunctionAction">control alt G</entry>
+ <entry key="ActivateHelpOnTypingAction">control H</entry>
+ <entry key="GenerateHelpFromFunctionAction">control shift G</entry>
<entry key="TabifyAction">TAB</entry>
<entry key="UnTabifyAction">shift TAB</entry>
<entry key="IndentAction">control I</entry>
<entry key="CommentAction">control D</entry>
<entry key="UnCommentAction">control shift D</entry>
- <entry key="RemoveTrailingWhiteAction">control alt W</entry>
+ <entry key="RemoveTrailingWhiteAction">control shift W</entry>
<entry key="SelectAllAction">control A</entry>
- <entry key="OpenTabInNewWindowAction">control alt T</entry>
- <entry key="CCloseTabInNewWindowAction">control alt C</entry>
+ <entry key="OpenTabInNewWindowAction">control shift T</entry>
+ <entry key="CCloseTabInNewWindowAction">control shift C</entry>
<entry key="CopyAction">control C</entry>
<entry key="CutAction">control X</entry>
<entry key="NewAction">control N</entry>
<entry key="OpenAction">control O</entry>
<entry key="OpenURLAction">control U</entry>
- <entry key="OpenSourceFileOnKeywordAction">control alt O</entry>
+ <entry key="OpenSourceFileOnKeywordAction">control shift O</entry>
<entry key="SaveAction">control S</entry>
- <entry key="SaveAsAction">control alt S</entry>
- <entry key="SaveAllAction">control shift S</entry>
- <entry key="OverwriteAction">control shift O</entry>
+ <entry key="SaveAsAction">control shift S</entry>
+ <entry key="SaveAction"></entry>
+ <entry key="OverwriteAction">control shift M</entry>
<entry key="ReloadAction">control shift R</entry>
<entry key="PrintPreviewAction">control shift P</entry>
<entry key="PrintAction">control P</entry>
<entry key="SciNotesCompletionAction">control SPACE</entry>
- <entry key="SplitHorizontallyAction">alt H</entry>
- <entry key="SplitVerticallyAction">alt V</entry>
- <entry key="NoSplitAction">alt N</entry>
+ <entry key="SplitHorizontallyAction">control shift H</entry>
+ <entry key="SplitVerticallyAction">control shift V</entry>
+ <entry key="NoSplitAction">control shift N</entry>
+
+ <entry key="HelpAction">F1</entry>
+ <entry key="AboutAction">shift F1</entry>
+
+ <entry key="NextTabAction">ctrl UP</entry>
+ <entry key="PreviousTabAction">ctrl DOWN</entry>
</properties>
<HorizontalWrapAllowed useCache="true" value="false"/>
<AutoIndent default="true" useCache="true" value="true"/>
<AutoColorize default="true" useCach="true" value="true"/>
- <DefaultEncoding value="UTF-8"/> <!-- Initialized to system default at first launch -->
+ <DefaultEncoding value="utf-8"/> <!-- Initialized to system default at first launch -->
<!-- linecolor or contourcolor can be "null" to be transparent -->
<LineHighlighter value="false" linecolor="#e4e9f4" contourcolor="#323232"/>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<Configuration>
+
+ <MenuBar>
+ <menu label="File" mnemonic="F">
+ <menuitem action="NewAction" label="New"/>
+ <menuitem action="OpenAction" label="Open"/>
+ <menuitem action="OpenSourceFileOnKeywordAction" label="Open function source file"/>
+ <menuitem action="OpenURLAction" label="Open URL"/>
+ <menuitem action="RecentFileAction" label="Recent Files"/>
+ <separator/>
+ <menuitem action="SaveAction" label="Save"/>
+ <menuitem action="SaveAsAction" label="Save as"/>
+ <menuitem action="SaveAllAction" label="Save All"/>
+ <separator/>
+ <menuitem action="OverwriteAction" label="Overwrite"/>
+ <menuitem action="ReloadAction" label="Reload"/>
+ <separator/>
+ <menuitem action="PageSetupAction" label="Page Setup"/>
+ <menuitem action="PrintPreviewAction" label="Print Preview"/>
+ <menuitem action="PrintAction" label="Print"/>
+ <separator/>
+ <menuitem action="CloseAction" label="Close"/>
+ <menuitem action="CloseAllAction" label="Close All"/>
+ <menuitem action="CloseAllButThisAction" label="Close All But This"/>
+ <separator/>
+ <menuitem action="ExitAction" label="Exit"/>
+ </menu>
+
+ <menu label="Edition" mnemonic="E">
+ <menuitem action="UndoAction" label="Undo"/>
+ <menuitem action="RedoAction" label="Redo"/>
+ <separator/>
+ <menuitem action="CutAction" label="Cut"/>
+ <menuitem action="CopyAction" label="Copy"/>
+ <menuitem action="PasteAction" label="Paste"/>
+ <separator/>
+ <menuitem action="SelectAllAction" label="Select All"/>
+ <menuitem action="DeleteAction" label="Delete"/>
+ </menu>
+
+ <menu label="Tools" mnemonic="T">
+ <menuitem action="ActivateHelpOnTypingAction" label="Help on typing"/>
+ <separator/>
+ <menuitem action="OpenTabInNewWindowAction" label="Clone tab in new window"/>
+ <menuitem action="CCloseTabInNewWindowAction" label="Clone and close tab"/>
+ <separator/>
+ <menuitem action="CommentAction" label="Comment Selection"/>
+ <menuitem action="UnCommentAction" label="Uncomment Selection"/>
+ <separator/>
+ <menuitem action="IndentAction" label="Correct Indentation"/>
+ <menuitem action="TabifyAction" label="Shift Right"/>
+ <menuitem action="UnTabifyAction" label="Shift Left"/>
+ <separator/>
+ <menuitem action="GenerateHelpFromFunctionAction" label="Generate help from function"/>
+ <separator/>
+ <menuitem action="RemoveTrailingWhiteAction" label="Remove trailing whitespaces"/>
+ </menu>
+
+ <menu label="Search" mnemonic="S">
+ <menuitem action="FindAction" label="Find/Replace"/>
+ <menuitem action="FindNextAction" label="Find Next"/>
+ <menuitem action="FindPreviousAction" label="Find Previous"/>
+ <menuitem action="CodeNavigatorAction" label="Code Navigator"/>
+ </menu>
+
+ <menu label="View" mnemonic="V">
+ <menuitem action="HighlightCurrentLineAction" label="Highlight current line"/>
+ <menuitem action="LineNumbersAction" label="Whereami Line Numbering;Normal Line Numbering;No Line Numbering"/>
+ <menuitem action="SetColorsAction" label="Set Colors"/>
+ <menuitem action="SetFontAction" label="Set Font"/>
+ <menuitem action="ResetFontAction" label="Reset default font"/>
+ <separator/>
+ <menuitem action="SplitVerticallyAction" label="Split vertically"/>
+ <menuitem action="SplitHorizontallyAction" label="Split horizontally"/>
+ <menuitem action="NoSplitAction" label="No split"/>
+ </menu>
+
+ <menu label="Document" mnemonic="D">
+ <menuitem action="EncodingAction" label="Encoding"/>
+ <menuitem action="EndOfLineAction" label="Line Endings"/>
+ <separator/>
+ <menuitem action="AutoIndentAction" label="Enable Auto Reformat"/>
+ </menu>
+
+ <menu label="Execute" mnemonic="E">
+ <menuitem action="LoadIntoScilabAction" label="Load Into Scilab"/>
+ <menuitem action="EvaluateSelectionAction" label="Evaluate Selection;Evaluate from beginning"/>
+ <menuitem action="ExecuteFileIntoScilabAction" label="Execute File Into Scilab"/>
+ </menu>
+
+ <menu label="?">
+ <menuitem action="HelpAction" label="SciNotes help"/>
+ <menuitem action="HelpOnKeywordAction" label="Help on the current keyword"/>
+ <menuitem action="AboutAction" label="About"/>
+ </menu>
+ </MenuBar>
+
+ <RightClickMenu>
+ <menuitem action="EvaluateSelectionAction" label="Evaluate Selection;Evaluate from beginning"/>
+ <menuitem action="CopySelectionInNewTabAction" label="Copy selection in a new tab"/>
+ <menuitem action="SciNotesCompletionAction" label="Complete"/>
+ <separator/>
+ <menuitem action="SelectAllAction" label="Select All"/>
+ <menuitem action="CopyAction" label="Copy"/>
+ <menuitem action="CutAction" label="Cut"/>
+ <menuitem action="PasteAction" label="Paste"/>
+ <separator/>
+ <menuitem action="HelpOnKeywordAction" label="Help on the current keyword"/>
+ <menuitem action="OpenSourceFileOnKeywordAction" label="Open function source file"/>
+ <menuitem action="OpenURLAction" label="Open URL"/>
+ </RightClickMenu>
+
+ <ToolBar>
+ <button action="NewAction" tooltip="New" icon="document-new.png"/>
+ <button action="OpenAction" tooltip="Open" icon="document-open.png"/>
+ <separator/>
+ <button action="SaveAction" tooltip="Save" icon="media-floppy.png"/>
+ <button action="SaveAsAction" tooltip="Save as" icon="document-save-as.png"/>
+ <separator/>
+ <button action="PrintAction" tooltip="Print" icon="document-print.png"/>
+ <separator/>
+ <button action="UndoAction" tooltip="Undo" icon="edit-undo.png"/>
+ <button action="RedoAction" tooltip="Redo" icon="edit-redo.png"/>
+ <separator/>
+ <button action="CutAction" tooltip="Cut" icon="edit-cut.png"/>
+ <button action="CopyAction" tooltip="Copy" icon="edit-copy.png"/>
+ <button action="PasteAction" tooltip="Paste" icon="edit-paste.png"/>
+ <separator/>
+ <button action="FindAction" tooltip="Find/Replace" icon="edit-find-replace.png"/>
+ <separator/>
+ <button action="ExecuteFileIntoScilabAction" tooltip="Execute" icon="media-playback-start.png"/>
+ </ToolBar>
+
+</Configuration>
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Iterator;
import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import org.apache.commons.logging.LogFactory;
import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
-import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
import org.scilab.modules.gui.events.callback.CallBack;
import org.scilab.modules.gui.filechooser.Juigetfile;
import org.scilab.modules.gui.filechooser.ScilabFileChooser;
-import org.scilab.modules.gui.menu.Menu;
-import org.scilab.modules.gui.menu.ScilabMenu;
import org.scilab.modules.gui.menubar.MenuBar;
import org.scilab.modules.gui.messagebox.MessageBox;
import org.scilab.modules.gui.messagebox.ScilabMessageBox;
import org.scilab.modules.gui.utils.Size;
import org.scilab.modules.gui.window.ScilabWindow;
import org.scilab.modules.gui.window.Window;
-import org.scilab.modules.scinotes.actions.CopyAction;
-import org.scilab.modules.scinotes.actions.CutAction;
import org.scilab.modules.scinotes.actions.ExitAction;
import org.scilab.modules.scinotes.actions.FindAction;
-import org.scilab.modules.scinotes.actions.FindNextAction;
-import org.scilab.modules.scinotes.actions.FindPreviousAction;
-import org.scilab.modules.scinotes.actions.HighlightCurrentLineAction;
+import org.scilab.modules.scinotes.actions.SetColorsAction;
import org.scilab.modules.scinotes.actions.LineBeautifierAction;
-import org.scilab.modules.scinotes.actions.PasteAction;
import org.scilab.modules.scinotes.actions.RecentFileAction;
-import org.scilab.modules.scinotes.actions.RedoAction;
import org.scilab.modules.scinotes.actions.SciNotesCompletionAction;
-import org.scilab.modules.scinotes.actions.SelectAllAction;
-import org.scilab.modules.scinotes.actions.SetColorsAction;
-import org.scilab.modules.scinotes.actions.TabifyAction;
-import org.scilab.modules.scinotes.actions.UnTabifyAction;
-import org.scilab.modules.scinotes.actions.UndoAction;
+import org.scilab.modules.scinotes.actions.EncodingAction;
+import org.scilab.modules.scinotes.actions.EndOfLineAction;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
import org.scilab.modules.scinotes.utils.DropFilesListener;
import org.scilab.modules.scinotes.utils.SaveFile;
private static final String TIRET = " - ";
private static final String DOT = ".";
+ private static final String DEFAULTACTIONPATH = "org.scilab.modules.scinotes.actions";
+
private static final int ZERO = 0;
private static final int ONE = 1;
private static final int TWO = 2;
private static List<SciNotes> scinotesList = new ArrayList();
private static SciNotes editor;
- private static SciNotesGUI scinotesGUI;
private final Window parentWindow;
private JTabbedPane tabPane;
private ScilabEditorPane textPane;
private JScrollPane scrollingText;
- private Menu recentsMenu;
private int numberOfUntitled;
private EditorKit editorKit;
private Object synchro = new Object();
super(SCINOTES);
scinotesList.add(this);
this.parentWindow = parentWindow;
- recentsMenu = ScilabMenu.createMenu();
numberOfUntitled = 0;
editorKit = new ScilabEditorKit();
setDefaultHighlight();
getTextPane().updateInfosWhenFocused();
// Update encoding menu
- scinotesGUI.updateEncodingMenu((ScilabDocument) getTextPane().getDocument());
+ EncodingAction.updateEncodingMenu((ScilabDocument) getTextPane().getDocument());
// Update End Of Line menu
- scinotesGUI.updateEolMenu((ScilabDocument) getTextPane().getDocument());
+ EndOfLineAction.updateEolMenu((ScilabDocument) getTextPane().getDocument());
setTitle(tabPane.getTitleAt(tabPane.getSelectedIndex()) + path + TIRET + SciNotesMessages.SCILAB_EDITOR);
}
}
this.setContentPane(tabPane);
}
+ /**
+ * {@inheritDoc}
+ */
public void setTitle(String title) {
super.setTitle(title);
final SwingScilabWindow window = (SwingScilabWindow) SwingUtilities
}
/**
- * Return the text editor GUI.
- * @return The text editor gui
- */
- public final SciNotesGUI getSciNotesGUI() {
- return scinotesGUI;
- }
-
- /**
* Launch SciNotes from command line.
* @param args command line args
*/
/**
* Launch SciNotes with an empty file
- * @throws RuntimeException on problem
*
* This method *must not* be called on the EDT thread.
*/
- public static void scinotes() throws RuntimeException {
+ public static void scinotes() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
LogFactory.getLog(SciNotes.class).error(e);
+ e.printStackTrace();
throw new RuntimeException(e);
}
-
}
/**
* Launch SciNotes with a file name to open.
* @param filePath the name of the file to open
- * @throws RuntimeException on problem
*
* This method *must not* be called on the EDT thread.
*/
- public static void scinotes(final String filePath) throws RuntimeException {
+ public static void scinotes(final String filePath) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
/**
* Launch SciNotes with a file name to open and a line to highlight.
* @param filePath the name of the file to open
- * @param lineNumber the line to highlight
+ * @param option such as 'readonly'
*
* This method *must not* be called on the EDT thread.
*/
}
ConfigSciNotesManager.saveToRecentOpenedFiles(filePath);
- updateRecentOpenedFilesMenu();
+ RecentFileAction.updateRecentOpenedFilesMenu(this);
readFileAndWait(f);
getTextPane().scrollTextToLineNumber(lineNumber);
if (option != null && "readonly".equals(option.toLowerCase())) {
final SciNotes editorInstance = new SciNotes(mainWindow);
- scinotesGUI = new SciNotesGUI(mainWindow, editorInstance, SCINOTES);
+ SciNotesGUI.init(mainWindow, editorInstance, SCINOTES);
editorInstance.setCallback(new CallBack(SciNotesMessages.DEFAULT + SciNotesMessages.DOTS) {
/**
* serialVersionUID
getTextPane().setName(f.getPath());
getTabPane().setTitleAt(getTabPane().getSelectedIndex() , f.getName());
setTitle(f.getPath() + TIRET + SciNotesMessages.SCILAB_EDITOR);
- updateRecentOpenedFilesMenu();
+ RecentFileAction.updateRecentOpenedFilesMenu(this);
styledDocument.setContentModified(false);
getTextPane().setLastModified(f.lastModified());
public ScilabEditorPane addTab(String title, int index) {
ScilabEditorPane sep = new ScilabEditorPane(this);
initPane(sep);
- index = Math.min(Math.max(0, index), tabPane.getTabCount());
- tabPane.insertTab(title, null, sep.getParentComponent(), "", index);
- tabPane.setSelectedIndex(index);
+ int ind = Math.min(Math.max(0, index), tabPane.getTabCount());
+ tabPane.insertTab(title, null, sep.getParentComponent(), "", ind);
+ tabPane.setSelectedIndex(ind);
setContentPane(tabPane);
initInputMap(sep);
setTitle(title + TIRET + SciNotesMessages.SCILAB_EDITOR);
DropFilesListener dndTarget = new DropFilesListener(pane);
- SciNotesGUI.createPopupMenu(pane, this);
+ pane.setComponentPopupMenu(SciNotesGUI.generateRightClickPopup(this));
}
/**
* @param pane the EditorPane
*/
public void initInputMap(ScilabEditorPane pane) {
- Map<String, KeyStroke> map = new HashMap();
- ConfigSciNotesManager.addMapActionNameKeys(map);
- TabifyAction.putInInputMap(pane, this, map.get("TabifyAction"));
- UndoAction.putInInputMap(pane, this, map.get("UndoAction"));
- RedoAction.putInInputMap(pane, this, map.get("RedoAction"));
- PasteAction.putInInputMap(pane, this, map.get("PasteAction"));
- CopyAction.putInInputMap(pane, this, map.get("CopyAction"));
- CutAction.putInInputMap(pane, this, map.get("CutAction"));
- UnTabifyAction.putInInputMap(pane, this, map.get("UnTabifyAction"));
- FindNextAction.putInInputMap(pane, this, map.get("FindNextAction"));
- FindPreviousAction.putInInputMap(pane, this, map.get("FindPreviousAction"));
- HighlightCurrentLineAction.putInInputMap(pane, this, map.get("HighlightCurrentLineAction"));
- SelectAllAction.putInInputMap(pane, this, map.get("SelectAllAction"));
+ setKeyStrokeAction(pane, this);
LineBeautifierAction.putInInputMap(pane);
- SciNotesCompletionAction.putInInputMap(pane, this, map.get("SciNotesCompletionAction"));
}
/**
/**
* Load a file inside SciNotes.
- * @param f the file to open
+ * @param file the file to open
*/
- public void readFileAndWait(File f) {
+ public void readFileAndWait(File file) {
/** Is this file already opened */
+ File f = file;
boolean alreadyOpened = false;
int index = -1;
for (int i = 0; i < tabPane.getTabCount(); i++) {
}
/**
- * Get recent file menu.
- * @return the menu
- */
- public Menu getRecentsMenu() {
- return this.recentsMenu;
- }
-
- /**
- * Update menu displaying recent opened files.
- */
- public void updateRecentOpenedFilesMenu() {
- List<File> recentFiles = ConfigSciNotesManager.getAllRecentOpenedFiles();
-
- ((SwingScilabMenu) getRecentsMenu().getAsSimpleMenu()).removeAll();
- for (int i = recentFiles.size() - 1; i >= 0; i--) {
- getRecentsMenu().add(RecentFileAction.createMenu(this, recentFiles.get(i)));
- }
- }
-
- /**
* Return the Full path of the file.
* @return the full path
*/
return fileFullPath;
}
+ /**
+ * Load a file and add it at the end
+ * @param f the file to load
+ */
public void loadFile(File f) {
loadFile(f, -1);
}
+ /**
+ * Load a file and add it at the index
+ * @param f the file to load
+ * @param index the index where to put the file
+ */
public void loadFile(File f, int index) {
setFileToEncode(f);
getInfoBar().setText(SciNotesMessages.LOADING);
}
getInfoBar().setText(theTextPane.getInfoBarText());
- scinotesGUI.updateEncodingMenu((ScilabDocument) getTextPane().getDocument());
+ EncodingAction.updateEncodingMenu((ScilabDocument) getTextPane().getDocument());
// Empty the undo Manager
UndoManager undo = ((ScilabDocument) getTextPane().getDocument()).getUndoManager();
}
}
+ /**
+ * Creates a file if it doesn't exist
+ * @param f the file to create
+ */
public void createNewFile(File f) {
ScilabEditorPane theTextPane = addEmptyTab();
ScilabDocument styleDocument = null;
theTextPane.setName(f.getPath());
getTabPane().setTitleAt(getTabPane().getSelectedIndex() , f.getName());
setTitle(f.getPath() + TIRET + SciNotesMessages.SCILAB_EDITOR);
- updateRecentOpenedFilesMenu();
+ RecentFileAction.updateRecentOpenedFilesMenu(this);
styleDocument.setContentModified(false);
styleDocument.enableUndoManager();
}
/**
- * @param editor the focused editor
+ * @param scinotes the focused editor
*/
public static void setEditor(SciNotes scinotes) {
editor = scinotes;
}
/**
+ * @param f the file
* @return the canonical file if possible
*/
public static File fileToCanonicalFile(File f) {
/* Fix bug 5648 */
try {
return f.getCanonicalFile();
- } catch(IOException e) {
+ } catch (IOException e) {
return f;
}
}
+
+ /**
+ * Set the shortcuts in the pane relatively to the file keysConfiguration.xml
+ * @param sep the textpane
+ * @param ed the SciNotes editor
+ */
+ private static void setKeyStrokeAction(ScilabEditorPane sep, SciNotes ed) {
+ Map<String, KeyStroke> map = new HashMap();
+ ConfigSciNotesManager.addMapActionNameKeys(map);
+
+ ClassLoader loader = ClassLoader.getSystemClassLoader();
+ Iterator<String> iter = map.keySet().iterator();
+ while (iter.hasNext()) {
+ String action = iter.next();
+ if (!action.equals("SciNotesCompletionAction")) {
+ String className;
+ if (action.lastIndexOf(DOT) != -1) {
+ className = action;
+ } else {
+ className = DEFAULTACTIONPATH + DOT + action;
+ }
+ try {
+ Class clazz = loader.loadClass(className);
+ Constructor constructor = clazz.getConstructor(new Class[]{String.class, SciNotes.class});
+ Object act = constructor.newInstance(new Object[]{"", ed});
+ sep.getInputMap().put(map.get(action), act);
+ } catch (ClassNotFoundException e) {
+ System.err.println("No action: " + className);
+ } catch (InstantiationException e) {
+ System.err.println("Problem to instantiate in action: " + className);
+ } catch (NoSuchMethodException e) {
+ System.err.println("No valid constructor in action: " + className);
+ } catch (IllegalAccessException e) {
+ System.err.println("The constructor must be public: " + className);
+ } catch (InvocationTargetException e) {
+ System.err.println("The constructor in " + className + " threw an exception :");
+ e.printStackTrace();
+ }
+ } else {
+ sep.getInputMap().put(map.get(action), new SciNotesCompletionAction(sep, ed));
+ }
+ }
+ }
}
package org.scilab.modules.scinotes;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.nio.charset.Charset;
-import java.util.List;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Map;
import java.util.HashMap;
-import java.util.TreeMap;
-import java.util.Iterator;
+import java.io.File;
import java.io.IOException;
-import javax.swing.ButtonGroup;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JEditorPane;
-import javax.swing.text.DefaultEditorKit;
-import javax.swing.text.BadLocationException;
import javax.swing.KeyStroke;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
-import org.scilab.modules.action_binding.InterpreterManagement;
-import org.scilab.modules.gui.console.ScilabConsole;
import org.scilab.modules.gui.menu.Menu;
import org.scilab.modules.gui.menu.ScilabMenu;
+import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
import org.scilab.modules.gui.menubar.MenuBar;
import org.scilab.modules.gui.menubar.ScilabMenuBar;
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
+import org.scilab.modules.gui.bridge.checkboxmenuitem.SwingScilabCheckBoxMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
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.Window;
-import org.scilab.modules.scinotes.actions.SplitHorizontallyAction;
-import org.scilab.modules.scinotes.actions.SplitVerticallyAction;
-import org.scilab.modules.scinotes.actions.NoSplitAction;
-import org.scilab.modules.scinotes.actions.ActivateHelpOnTypingAction;
-import org.scilab.modules.scinotes.actions.GenerateHelpFromFunctionAction;
-import org.scilab.modules.scinotes.actions.AboutAction;
-import org.scilab.modules.scinotes.actions.AutoIndentAction;
-import org.scilab.modules.scinotes.actions.CloseAction;
-import org.scilab.modules.scinotes.actions.CloseAllAction;
-import org.scilab.modules.scinotes.actions.CloseAllButThisAction;
-import org.scilab.modules.scinotes.actions.CommentAction;
-import org.scilab.modules.scinotes.actions.UnCommentAction;
-import org.scilab.modules.scinotes.actions.RemoveTrailingWhiteAction;
-import org.scilab.modules.scinotes.actions.CopyAction;
-import org.scilab.modules.scinotes.actions.CutAction;
-import org.scilab.modules.scinotes.actions.DeleteAction;
-import org.scilab.modules.scinotes.actions.EncodingAction;
-import org.scilab.modules.scinotes.actions.EndOfLineAction;
-import org.scilab.modules.scinotes.actions.EvaluateSelectionAction;
-import org.scilab.modules.scinotes.actions.ExecuteFileIntoScilabAction;
-import org.scilab.modules.scinotes.actions.ExitAction;
-import org.scilab.modules.scinotes.actions.OpenTabInNewWindowAction;
-import org.scilab.modules.scinotes.actions.CCloseTabInNewWindowAction;
-import org.scilab.modules.scinotes.actions.FindAction;
-import org.scilab.modules.scinotes.actions.FindNextAction;
-import org.scilab.modules.scinotes.actions.FindPreviousAction;
-import org.scilab.modules.scinotes.actions.CodeNavigatorAction;
-import org.scilab.modules.scinotes.actions.OverwriteAction;
-import org.scilab.modules.scinotes.actions.ReloadAction;
-import org.scilab.modules.scinotes.actions.HelpAction;
-import org.scilab.modules.scinotes.actions.HelpOnKeywordAction;
-import org.scilab.modules.scinotes.actions.HighlightCurrentLineAction;
-import org.scilab.modules.scinotes.actions.IndentAction;
-import org.scilab.modules.scinotes.actions.LineNumbersAction;
-import org.scilab.modules.scinotes.actions.LoadIntoScilabAction;
-import org.scilab.modules.scinotes.actions.NewAction;
-import org.scilab.modules.scinotes.actions.OpenAction;
-import org.scilab.modules.scinotes.actions.OpenURLAction;
-import org.scilab.modules.scinotes.actions.OpenSourceFileOnKeywordAction;
-import org.scilab.modules.scinotes.actions.PageSetupAction;
-import org.scilab.modules.scinotes.actions.PasteAction;
-import org.scilab.modules.scinotes.actions.PrintAction;
-import org.scilab.modules.scinotes.actions.PrintPreviewAction;
-import org.scilab.modules.scinotes.actions.RedoAction;
-import org.scilab.modules.scinotes.actions.ResetFontAction;
-import org.scilab.modules.scinotes.actions.SaveAction;
-import org.scilab.modules.scinotes.actions.SaveAllAction;
-import org.scilab.modules.scinotes.actions.SaveAsAction;
-import org.scilab.modules.scinotes.actions.SelectAllAction;
-import org.scilab.modules.scinotes.actions.SetColorsAction;
-import org.scilab.modules.scinotes.actions.SetFontAction;
-import org.scilab.modules.scinotes.actions.TabifyAction;
-import org.scilab.modules.scinotes.actions.UnTabifyAction;
-import org.scilab.modules.scinotes.actions.UndoAction;
-import org.scilab.modules.scinotes.actions.SciNotesCompletionAction;
+import org.scilab.modules.localization.Messages;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Class SciNotesGUI handles menus, bar, ...
*/
-public class SciNotesGUI {
+public final class SciNotesGUI {
+
+ private static final String MENU_CONF = System.getenv("SCI") + "/modules/scinotes/etc/scinotesGUIConfiguration.xml";
+ private static final String ERROR_READ = "Could not load file: ";
+ private static final String MENUBAR = "MenuBar";
+ private static final String TOOLBAR = "ToolBar";
+ private static final String RIGHTCLICKMENU = "RightClickMenu";
+ private static final String MENU = "menu";
+ private static final String MNEMONIC = "mnemonic";
+ private static final String LABEL = "label";
+ private static final String MENUITEM = "menuitem";
+ private static final String ACTION = "action";
+ private static final String SEPARATOR = "separator";
+ private static final String TOOLTIP = "tooltip";
+ private static final String ICON = "icon";
+ private static final String BUTTON = "button";
+ private static final String DOT = ".";
+
+ private static final String DEFAULTACTIONPATH = "org.scilab.modules.scinotes.actions";
- private static JRadioButtonMenuItem[] radioTypes;
- private static JRadioButtonMenuItem[] radioEolTypes;
private static TextBox infoBar;
private static Map<String, KeyStroke> map = new HashMap();
+ private static Document menuConf;
static {
ConfigSciNotesManager.addMapActionNameKeys(map);
}
/**
- * Constructor
+ * initialize the window
* @param mainWindow Windows
* @param editorInstance SciNotes
* @param title the title
*/
- public SciNotesGUI(Window mainWindow, final SciNotes editorInstance, String title) {
+ public static void init(Window mainWindow, final SciNotes editorInstance, String title) {
mainWindow.setTitle(title);
mainWindow.addTab(editorInstance);
mainWindow.setPosition(ConfigSciNotesManager.getMainWindowPosition());
mainWindow.setDims(ConfigSciNotesManager.getMainWindowSize());
- MenuBar menuBar = ScilabMenuBar.createMenuBar();
- //Create FILE menubar
- Menu fileMenu = ScilabMenu.createMenu();
- createFileMenu(fileMenu, editorInstance);
- menuBar.add(fileMenu);
-
- //Create EDIT menubar
- Menu editMenu = ScilabMenu.createMenu();
- createEditMenu(editMenu, editorInstance);
- menuBar.add(editMenu);
-
- Menu toolsMenu = ScilabMenu.createMenu();
- createToolsMenu(toolsMenu, editorInstance);
- menuBar.add(toolsMenu);
-
- // Create SEARCH menubar
- Menu searchMenu = ScilabMenu.createMenu();
- searchMenu.setText(SciNotesMessages.SEARCH);
- searchMenu.setMnemonic('S');
- searchMenu.add(FindAction.createMenu(editorInstance, map.get("FindAction")));
- searchMenu.add(FindNextAction.createMenu(editorInstance, map.get("FindNextAction")));
- searchMenu.add(FindPreviousAction.createMenu(editorInstance, map.get("FindPreviousAction")));
- searchMenu.add(CodeNavigatorAction.createMenu(editorInstance, map.get("CodeNavigatorAction")));
- menuBar.add(searchMenu);
-
- // Create VIEW Menubar
- Menu viewMenu = ScilabMenu.createMenu();
- viewMenu.setText(SciNotesMessages.VIEW);
- viewMenu.setMnemonic('S');
- viewMenu.add(HighlightCurrentLineAction.createCheckBoxMenu(editorInstance, map.get("HighlightCurrentLineAction")));
- viewMenu.add(LineNumbersAction.createMenu(editorInstance, map.get("LineNumbersAction")));
- viewMenu.add(SetColorsAction.createMenu(editorInstance));
- viewMenu.add(SetFontAction.createMenu(editorInstance));
- viewMenu.add(ResetFontAction.createMenu(editorInstance));
- viewMenu.addSeparator();
- viewMenu.add(SplitVerticallyAction.createMenu(editorInstance, map.get("SplitVerticallyAction")));
- viewMenu.add(SplitHorizontallyAction.createMenu(editorInstance, map.get("SplitHorizontallyAction")));
- viewMenu.add(NoSplitAction.createMenu(editorInstance, map.get("NoSplitAction")));
- menuBar.add(viewMenu);
-
- // Create DOCUMENT MenuBar
- Menu documentMenu = ScilabMenu.createMenu();
- documentMenu.setText(SciNotesMessages.DOCUMENT);
- documentMenu.setMnemonic('D');
- Menu syntaxTypeMenu = ScilabMenu.createMenu();
-
- createEncodingSubMenu(documentMenu, editorInstance);
- createEolSubMenu(documentMenu, editorInstance);
-
- documentMenu.addSeparator();
- documentMenu.add(AutoIndentAction.createCheckBoxMenu(editorInstance));
- menuBar.add(documentMenu);
-
- // Create EXECUTE menubar
- Menu executeMenu = ScilabMenu.createMenu();
- executeMenu.setText(SciNotesMessages.EXECUTE);
- executeMenu.setMnemonic('e');
- executeMenu.add(LoadIntoScilabAction.createMenu(editorInstance, map.get("LoadIntoScilabAction")));
- final MenuItem evaluateSelectionMenuItem = EvaluateSelectionAction.createMenu(editorInstance, map.get("EvaluateSelectionAction"));
- if (!ScilabConsole.isExistingConsole()) { /* Only available in STD mode */
- ((JMenuItem) evaluateSelectionMenuItem.getAsSimpleMenuItem()).setEnabled(false);
- }
- PropertyChangeListener listenerEvalItem = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- String select = editorInstance.getTextPane().getSelectedText();
- if (select == null) {
- evaluateSelectionMenuItem.setText(SciNotesMessages.EVALUATE_FROM_BEGINNING);
- } else {
- evaluateSelectionMenuItem.setText(SciNotesMessages.EVALUATE_SELECTION);
- }
- }
- };
- ((JMenuItem) evaluateSelectionMenuItem.getAsSimpleMenuItem()).addPropertyChangeListener(listenerEvalItem);
- executeMenu.add(evaluateSelectionMenuItem);
- executeMenu.add(ExecuteFileIntoScilabAction.createMenu(editorInstance, map.get("ExecuteFileIntoScilabAction")));
- menuBar.add(executeMenu);
-
- //Create HELP menubar
- Menu helpMenu = ScilabMenu.createMenu();
- helpMenu.setText(SciNotesMessages.QUESTION_MARK);
- helpMenu.add(HelpAction.createMenu(editorInstance));
- helpMenu.add(HelpOnKeywordAction.createMenu(editorInstance, map.get("HelpOnKeywordAction")));
- helpMenu.add(AboutAction.createMenu(editorInstance));
- menuBar.add(helpMenu);
-
- // Create Toolbar
- createToolBar(editorInstance);
-
infoBar = ScilabTextBox.createTextBox();
- editorInstance.setMenuBar(menuBar);
+ editorInstance.setMenuBar(generateMenuBar(editorInstance));
+ editorInstance.setToolBar(generateToolBar(editorInstance));
editorInstance.setInfoBar(infoBar);
mainWindow.setTitle(title);
mainWindow.setVisible(true);
}
/**
- * Update the selected item in the encoding pull down menu of the document.
- * @param scilabDocument the document for which the encoding menu should
- * be updated
+ * @param editor the editor
+ * @return the JPopupMenu read in the conf file
*/
- public void updateEncodingMenu(ScilabDocument scilabDocument) {
- if (radioTypes != null) {
- for (int k = 0; k < radioTypes.length; k++) {
- if (scilabDocument.getEncoding().equals(radioTypes[k].getText())) {
- radioTypes[k].setSelected(true);
+ public static JPopupMenu generateRightClickPopup(SciNotes editor) {
+ readMenusConf();
+ JPopupMenu popup = new JPopupMenu();
+ Element root = menuConf.getDocumentElement();
+ Element rightmenu = (Element) root.getElementsByTagName(RIGHTCLICKMENU).item(0);
+ NodeList menus = rightmenu.getChildNodes();
+ for (int i = 0; i < menus.getLength(); i++) {
+ Node item = menus.item(i);
+ if (MENUITEM.equals(item.getNodeName())) {
+ Element elem = (Element) item;
+ Object menuitem = getMenuItem(elem.getAttribute(ACTION), elem.getAttribute(LABEL), editor);
+ if (menuitem != null) {
+ if (menuitem instanceof CheckBoxMenuItem) {
+ SwingScilabCheckBoxMenuItem checkbox = (SwingScilabCheckBoxMenuItem) ((CheckBoxMenuItem) menuitem).getAsSimpleCheckBoxMenuItem();
+ popup.add(checkbox);
+ } else if (menuitem instanceof MenuItem) {
+ SwingScilabMenuItem smi = (SwingScilabMenuItem) ((MenuItem) menuitem).getAsSimpleMenuItem();
+ popup.add(smi);
+ } else if (menuitem instanceof Menu) {
+ SwingScilabMenu sm = (SwingScilabMenu) ((Menu) menuitem).getAsSimpleMenu();
+ popup.add(sm);
+ }
}
+ } else if (SEPARATOR.equals(item.getNodeName())) {
+ popup.addSeparator();
+ } else if (MENU.equals(item.getNodeName())) {
+ SwingScilabMenu sm = (SwingScilabMenu) getMenu(editor, (Element) item).getAsSimpleMenu();
+ popup.add(sm);
}
}
+
+ return popup;
}
/**
- * Update the selected item in the EOL pull down menu of the document.
- * @param scilabDocument the document for which the End Of Line menu should
- * be updated
+ * @param editor the editor
+ * @return the ToolBar read in the conf file
*/
- public void updateEolMenu(ScilabDocument scilabDocument) {
- String eolLinux = ScilabDocument.EOLUNIX;
- String eolMacOs = ScilabDocument.EOLMAC;
- String eolWindows = ScilabDocument.EOLWIN;
-
- String eolUsedLabel = SciNotesMessages.EOL_LINUX;
- String eolUsed = scilabDocument.getEOL();
-
- if (eolUsed.compareTo(eolLinux) == 0) {
- eolUsedLabel = SciNotesMessages.EOL_LINUX;
- }
-
- if (eolUsed.compareTo(eolMacOs) == 0) {
- eolUsedLabel = SciNotesMessages.EOL_MACOS;
- }
-
- if (eolUsed.compareTo(eolWindows) == 0) {
- eolUsedLabel = SciNotesMessages.EOL_WINDOWS;
- }
-
- for (int k = 0; k < radioEolTypes.length; k++) {
- if (radioEolTypes[k].getText().compareTo(eolUsedLabel) == 0) {
- radioEolTypes[k].setSelected(true);
+ public static ToolBar generateToolBar(SciNotes editor) {
+ readMenusConf();
+ ToolBar toolBar = ScilabToolBar.createToolBar();
+ Element root = menuConf.getDocumentElement();
+ Element toolbar = (Element) root.getElementsByTagName(TOOLBAR).item(0);
+ NodeList buttons = toolbar.getChildNodes();
+ for (int i = 0; i < buttons.getLength(); i++) {
+ Node node = buttons.item(i);
+ if (BUTTON.equals(node.getNodeName())) {
+ Element elem = (Element) node;
+ PushButton pb = (PushButton) getButton(elem.getAttribute(ACTION), elem.getAttribute(TOOLTIP), elem.getAttribute(ICON), editor);
+ toolBar.add(pb);
+ } else if (SEPARATOR.equals(node.getNodeName())) {
+ toolBar.addSeparator();
}
}
+
+ return toolBar;
}
/**
- * create End Of Line sub Menu
- * @param documentMenu Menu
- * @param editorInstance SciNotes
+ * @param editor the editor
+ * @return the MenuBar read in the conf file
*/
- private void createEolSubMenu(Menu documentMenu, SciNotes editorInstance) {
- String eolLinux = ScilabDocument.EOLUNIX;
- String eolMacOs = ScilabDocument.EOLMAC;
- String eolWindows = ScilabDocument.EOLWIN;
- String defaultEolLabel = SciNotesMessages.EOL_LINUX;
-
- // selected by default O.S
- String systemEolValue = System.getProperty("line.separator");
-
- if (systemEolValue.compareTo(eolLinux) == 0) {
- defaultEolLabel = SciNotesMessages.EOL_LINUX;
- }
-
- if (systemEolValue.compareTo(eolWindows) == 0) {
- defaultEolLabel = SciNotesMessages.EOL_WINDOWS;
- }
-
- if (systemEolValue.compareTo(eolMacOs) == 0) {
- defaultEolLabel = SciNotesMessages.EOL_MACOS;
- }
-
- Menu eolTypeMenu = ScilabMenu.createMenu();
- eolTypeMenu.setText(SciNotesMessages.EOL_TYPE);
- documentMenu.add(eolTypeMenu);
-
- radioEolTypes = new JRadioButtonMenuItem[3];
- ButtonGroup groupEol = new ButtonGroup();
-
- radioEolTypes[0] = (new EndOfLineAction(SciNotesMessages.EOL_LINUX, editorInstance)).createRadioButtonMenuItem(editorInstance);
- groupEol.add(radioEolTypes[0]);
- ((JMenu) eolTypeMenu.getAsSimpleMenu()).add(radioEolTypes[0]);
-
- radioEolTypes[1] = (new EndOfLineAction(SciNotesMessages.EOL_WINDOWS, editorInstance)).createRadioButtonMenuItem(editorInstance);
- groupEol.add(radioEolTypes[1]);
- ((JMenu) eolTypeMenu.getAsSimpleMenu()).add(radioEolTypes[1]);
-
- radioEolTypes[2] = (new EndOfLineAction(SciNotesMessages.EOL_MACOS, editorInstance)).createRadioButtonMenuItem(editorInstance);
- groupEol.add(radioEolTypes[2]);
- ((JMenu) eolTypeMenu.getAsSimpleMenu()).add(radioEolTypes[2]);
-
- // selected menu
- for (int k = 0; k < radioEolTypes.length; k++) {
- if (radioEolTypes[k].getText().compareTo(defaultEolLabel) == 0) {
- radioEolTypes[k].setSelected(true);
+ public static MenuBar generateMenuBar(SciNotes editor) {
+ readMenusConf();
+ MenuBar menuBar = ScilabMenuBar.createMenuBar();
+ Element root = menuConf.getDocumentElement();
+ Element menubar = (Element) root.getElementsByTagName(MENUBAR).item(0);
+ NodeList menus = menubar.getChildNodes();
+ for (int i = 0; i < menus.getLength(); i++) {
+ Node node = menus.item(i);
+ if (MENU.equals(node.getNodeName())) {
+ menuBar.add(getMenu(editor, (Element) node));
}
}
- }
- /**
- * Create TOOLBAR
- * @param editorInstance SciNotes
- */
- private void createToolBar(SciNotes editorInstance) {
- ToolBar toolBar = ScilabToolBar.createToolBar();
- toolBar.add(NewAction.createButton(editorInstance)); // NEW
- toolBar.add(OpenAction.createButton(editorInstance)); // OPEN
- toolBar.addSeparator();
- toolBar.add(SaveAction.createButton(editorInstance)); // SAVE
- toolBar.add(SaveAsAction.createButton(editorInstance)); // SAVE AS
- toolBar.addSeparator();
- toolBar.add(PrintAction.createButton(editorInstance)); // PRINT
- toolBar.addSeparator();
- toolBar.add(UndoAction.createButton(editorInstance));
- toolBar.add(RedoAction.createButton(editorInstance));
- toolBar.addSeparator();
- toolBar.add(CutAction.createButton(editorInstance)); // CUT
- toolBar.add(CopyAction.createButton(editorInstance)); // COPY
- toolBar.add(PasteAction.createButton(editorInstance)); // PASTE
- toolBar.addSeparator();
- toolBar.add(FindAction.createButton(editorInstance)); // FIND / REPLACE
- toolBar.addSeparator();
- toolBar.add(ExecuteFileIntoScilabAction.createButton(editorInstance)); // EXECUTE FILE
-
- editorInstance.setToolBar(toolBar);
- }
-
- /**
- * createEditMenu
- * @param editMenu Menu
- * @param editorInstance SciNotes
- */
- private void createEditMenu(Menu editMenu, SciNotes editorInstance) {
- editMenu.setText(SciNotesMessages.EDIT);
- editMenu.setMnemonic('E');
- editMenu.add(UndoAction.createMenu(editorInstance, map.get("UndoAction")));
- editMenu.add(RedoAction.createMenu(editorInstance, map.get("RedoAction")));
- editMenu.addSeparator();
- editMenu.add(CutAction.createMenu(editorInstance, map.get("CutAction")));
- editMenu.add(CopyAction.createMenu(editorInstance, map.get("CopyAction")));
- editMenu.add(PasteAction.createMenu(editorInstance, map.get("PasteAction")));
- editMenu.addSeparator();
- editMenu.add(SelectAllAction.createMenu(editorInstance, map.get("SelectAllAction")));
- editMenu.add(DeleteAction.createMenu(editorInstance));
+ return menuBar;
}
/**
- * createToolsMenu
- * @param toolsMenu Menu
- * @param editorInstance SciNotes
+ * Read the conf file
*/
- private void createToolsMenu(Menu toolsMenu, SciNotes editorInstance) {
- toolsMenu.setText(SciNotesMessages.TOOLS);
- toolsMenu.setMnemonic('o');
- toolsMenu.add(ActivateHelpOnTypingAction.createCheckBoxMenu(editorInstance, map.get("ActivateHelpOnTypingAction")));
- toolsMenu.addSeparator();
- toolsMenu.add(OpenTabInNewWindowAction.createMenu(editorInstance, map.get("OpenTabInNewWindowAction")));
- toolsMenu.add(CCloseTabInNewWindowAction.createMenu(editorInstance, map.get("CCloseTabInNewWindowAction")));
- toolsMenu.addSeparator();
- toolsMenu.add(CommentAction.createMenu(editorInstance, map.get("CommentAction")));
- toolsMenu.add(UnCommentAction.createMenu(editorInstance, map.get("UnCommentAction")));
- toolsMenu.addSeparator();
- toolsMenu.add(TabifyAction.createMenu(editorInstance, map.get("TabifyAction")));
- toolsMenu.add(UnTabifyAction.createMenu(editorInstance, map.get("UnTabifyAction")));
- toolsMenu.addSeparator();
- toolsMenu.add(IndentAction.createMenu(editorInstance, map.get("IndentAction")));
- toolsMenu.addSeparator();
- toolsMenu.add(GenerateHelpFromFunctionAction.createMenu(editorInstance, map.get("GenerateHelpFromFunctionAction")));
- toolsMenu.addSeparator();
- toolsMenu.add(RemoveTrailingWhiteAction.createMenu(editorInstance, map.get("RemoveTrailingWhiteAction")));
+ private static void readMenusConf() {
+ File xml = null;
+ DocumentBuilder docBuilder = null;
+
+ try {
+ if (menuConf == null) {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ docBuilder = factory.newDocumentBuilder();
+ xml = new File(MENU_CONF);
+ menuConf = docBuilder.parse(xml);
+ }
+ } catch (ParserConfigurationException pce) {
+ System.err.println(ERROR_READ + MENU_CONF);
+ } catch (SAXException se) {
+ System.err.println(ERROR_READ + MENU_CONF);
+ } catch (IOException ioe) {
+ System.err.println(ERROR_READ + MENU_CONF);
+ }
}
/**
- * createFileMenu
- * @param fileMenu Menu
- * @param editorInstance SciNotes
+ * @param editor the editor
+ * @param node the node containing the informations
+ * @return the Menu
*/
- private void createFileMenu(Menu fileMenu, final SciNotes editorInstance) {
- fileMenu.setText(SciNotesMessages.FILE);
- fileMenu.setMnemonic('F');
- fileMenu.add(NewAction.createMenu(editorInstance, map.get("NewAction")));
- fileMenu.add(OpenAction.createMenu(editorInstance, map.get("OpenAction")));
- final MenuItem openSource = OpenSourceFileOnKeywordAction.createMenu(editorInstance, map.get("OpenSourceFileOnKeywordAction"));
- ((JMenuItem) openSource.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- String keyword = editorInstance.getTextPane().getSelectedText();
- if (keyword == null) {
- KeywordEvent kwe = editorInstance.getTextPane().getKeywordEvent();
- openSource.setEnabled(ScilabLexerConstants.isOpenable(kwe.getType()));
- }
- }
- });
- fileMenu.add(openSource);
-
- final MenuItem openUrl = OpenURLAction.createMenu(editorInstance, map.get("OpenURLAction"));
- ((JMenuItem) openUrl.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- String keyword = editorInstance.getTextPane().getSelectedText();
- if (keyword == null) {
- KeywordEvent kwe = editorInstance.getTextPane().getKeywordEvent();
- openUrl.setEnabled(ScilabLexerConstants.URL == kwe.getType() || ScilabLexerConstants.MAIL == kwe.getType());
+ private static Menu getMenu(SciNotes editor, Element node) {
+ Menu menu = ScilabMenu.createMenu();
+ menu.setText(Messages.gettext(node.getAttribute(LABEL)));
+ String mnemonic = node.getAttribute(MNEMONIC);
+ if (mnemonic != null && mnemonic.length() != 0) {
+ menu.setMnemonic(mnemonic.charAt(0));
+ }
+ NodeList elements = node.getChildNodes();
+ for (int i = 0; i < elements.getLength(); i++) {
+ Node item = elements.item(i);
+ if (MENUITEM.equals(item.getNodeName())) {
+ Element elem = (Element) item;
+ Object menuitem = getMenuItem(elem.getAttribute(ACTION), elem.getAttribute(LABEL), editor);
+ if (menuitem != null) {
+ if (menuitem instanceof CheckBoxMenuItem) {
+ menu.add((CheckBoxMenuItem) menuitem);
+ } else if (menuitem instanceof MenuItem) {
+ menu.add((MenuItem) menuitem);
+ } else if (menuitem instanceof Menu) {
+ menu.add((Menu) menuitem);
}
}
- });
-
- fileMenu.add(openUrl);
-
- Menu recentsMenu = editorInstance.getRecentsMenu();
- recentsMenu.setText(SciNotesMessages.RECENT_FILES);
- editorInstance.updateRecentOpenedFilesMenu();
- fileMenu.add(recentsMenu);
-
- fileMenu.addSeparator();
- fileMenu.add(SaveAction.createMenu(editorInstance, map.get("SaveAction")));
- fileMenu.add(SaveAsAction.createMenu(editorInstance, map.get("SaveAsAction")));
- fileMenu.add(SaveAllAction.createMenu(editorInstance, map.get("SaveAllAction")));
- fileMenu.addSeparator();
- final MenuItem overitem = OverwriteAction.createMenu(editorInstance, map.get("OverwriteAction"));
- ((JMenuItem) overitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- overitem.setEnabled(editorInstance.getTextPane().checkExternalModif());
- }
- });
- fileMenu.add(overitem);
-
- final MenuItem reloaditem = ReloadAction.createMenu(editorInstance, map.get("ReloadAction"));
- ((JMenuItem) reloaditem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- reloaditem.setEnabled(editorInstance.getTextPane().checkExternalModif());
- }
- });
- fileMenu.add(reloaditem);
+ } else if (SEPARATOR.equals(item.getNodeName())) {
+ menu.addSeparator();
+ } else if (MENU.equals(item.getNodeName())) {
+ menu.add(getMenu(editor, (Element) item));
+ }
+ }
- fileMenu.addSeparator();
- fileMenu.add(PageSetupAction.createMenu(editorInstance));
- fileMenu.add(PrintPreviewAction.createMenu(editorInstance, map.get("PrintPreviewAction")));
- fileMenu.add(PrintAction.createMenu(editorInstance, map.get("PrintAction")));
- fileMenu.addSeparator();
- fileMenu.add(CloseAction.createMenu(editorInstance, map.get("CloseAction")));
- fileMenu.add(CloseAllAction.createMenu(editorInstance));
- fileMenu.add(CloseAllButThisAction.createMenu(editorInstance));
- fileMenu.addSeparator();
- fileMenu.add(ExitAction.createMenu(editorInstance, map.get("ExitAction")));
+ return menu;
}
/**
- * createEncodingSubMenu
- * @param documentMenu Menu
- * @param editorInstance SciNotes
+ * @param action a string with the action associated with the button
+ * @param label the title of the menu
+ * @param editor the editor
+ * @return a MenuItem or a CheckBoxMenuItem or a Menu
*/
- private void createEncodingSubMenu(Menu documentMenu, SciNotes editorInstance) {
-
- Menu encodingTypeMenu = ScilabMenu.createMenu();
- encodingTypeMenu.setText(SciNotesMessages.ENCODING_TYPE);
- documentMenu.add(encodingTypeMenu);
-
- Map<String, List<String>> languages = new TreeMap(EncodingAction.getEncodings());
- Iterator<String> iter = languages.keySet().iterator();
- int size = 0;
- while (iter.hasNext()) {
- size += languages.get(iter.next()).size();
- }
-
- radioTypes = new JRadioButtonMenuItem[size];
- ButtonGroup group = new ButtonGroup();
-
- iter = languages.keySet().iterator();
- int psize = 0;
- while (iter.hasNext()) {
- String lang = iter.next();
- List<String> encodings = languages.get(lang);
- Menu langMenu = ScilabMenu.createMenu();
- langMenu.setText(lang);
- encodingTypeMenu.add(langMenu);
- for (int i = 0; i < encodings.size(); i++) {
- radioTypes[psize + i] = (new EncodingAction(encodings.get(i), editorInstance)).createRadioButtonMenuItem(editorInstance);
- group.add(radioTypes[psize + i]);
- ((JMenu) langMenu.getAsSimpleMenu()).add(radioTypes[psize + i]);
-
- if (encodings.get(i).toUpperCase().equals(Charset.defaultCharset().toString().toUpperCase())) {
- radioTypes[psize + i].setSelected(true);
- }
+ private static Object getMenuItem(String action, String label, SciNotes editor) {
+ ClassLoader loader = ClassLoader.getSystemClassLoader();
+ String className = "";
+ try {
+ if (action.lastIndexOf(DOT) != -1) {
+ className = action;
+ } else {
+ className = DEFAULTACTIONPATH + DOT + action;
}
- psize += encodings.size();
+ Class clazz = loader.loadClass(className);
+ Method method = clazz.getMethod("createMenu", new Class[]{String.class, SciNotes.class, KeyStroke.class});
+ return method.invoke(null, new Object[]{Messages.gettext(label), editor, map.get(action)});
+ } catch (ClassNotFoundException e) {
+ System.err.println("No action: " + className);
+ } catch (NoSuchMethodException e) {
+ System.err.println("No valid method createMenu in action: " + className);
+ } catch (IllegalAccessException e) {
+ System.err.println("The method createMenu must be public: " + className);
+ } catch (InvocationTargetException e) {
+ System.err.println("The method createMenu in " + className + " threw an exception :");
+ e.printStackTrace();
}
+
+ return null;
}
/**
- * Create the popup menu on the help
- * @param c The graphic component
- * @param editor the editor where the popup will occur
+ * @param action a string with the action associated with the button
+ * @param tooltip a string with the tooltip
+ * @param icon the icon name
+ * @param editor the editor
+ * @return the button
*/
- public static void createPopupMenu(final JEditorPane c, final SciNotes editor) {
- final JPopupMenu popup = new JPopupMenu();
- final JMenuItem evalMenuItem = new JMenuItem(SciNotesMessages.EVALUATE_SELECTION);
- JMenuItem menuItem = null;
-
- /* Execute into Scilab */
- ActionListener actionListenerExecuteIntoScilab = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- String selection = ((ScilabEditorPane) c).getCodeToExecute();
- if (selection == null) {
- infoBar.setText(SciNotesMessages.NO_TEXT_TO_EXECUTE);
- } else {
- ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true, true);
- }
- }
- };
-
- evalMenuItem.addActionListener(actionListenerExecuteIntoScilab);
- if (!ScilabConsole.isExistingConsole()) { /* Only available in STD mode */
- evalMenuItem.setEnabled(false);
+ private static Object getButton(String action, String tooltip, String icon, SciNotes editor) {
+ ClassLoader loader = ClassLoader.getSystemClassLoader();
+ String className = "";
+ try {
+ if (action.lastIndexOf(DOT) != -1) {
+ className = action;
+ } else {
+ className = DEFAULTACTIONPATH + DOT + action;
+ }
+ Class clazz = loader.loadClass(className);
+ Method method = clazz.getMethod("createButton", new Class[]{String.class, String.class, SciNotes.class});
+ return method.invoke(null, new Object[]{Messages.gettext(tooltip), icon, editor});
+ } catch (ClassNotFoundException e) {
+ System.err.println("No action: " + className);
+ } catch (NoSuchMethodException e) {
+ System.err.println("No valid method createButton in action: " + className);
+ } catch (IllegalAccessException e) {
+ System.err.println("The method createButton must be public: " + className);
+ } catch (InvocationTargetException e) {
+ System.err.println("The method createButton in " + className + " threw an exception :");
+ e.printStackTrace();
}
- PropertyChangeListener listenerEvalItem = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- String select = c.getSelectedText();
- if (select == null) {
- evalMenuItem.setText(SciNotesMessages.EVALUATE_FROM_BEGINNING);
- } else {
- evalMenuItem.setText(SciNotesMessages.EVALUATE_SELECTION);
- }
- }
- };
- evalMenuItem.addPropertyChangeListener(listenerEvalItem);
- popup.add(evalMenuItem);
-
- /* Edit in the Scilab Text Editor */
- ActionListener actionListenerLoadIntoTextEditor = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- String selection = c.getSelectedText();
- if (selection == null) {
- infoBar.setText(SciNotesMessages.NO_TEXT_SELECTED);
- } else {
- SciNotes.scinotesWithText(selection);
- }
- }
- };
-
- menuItem = new JMenuItem(SciNotesMessages.EDIT_SELECTION);
- menuItem.addActionListener(actionListenerLoadIntoTextEditor);
- popup.add(menuItem);
- popup.addSeparator();
-
- /* Copy */
- menuItem = new JMenuItem(new DefaultEditorKit.CopyAction());
- menuItem.setText(SciNotesMessages.COPY);
- popup.add(menuItem);
-
- /* Cut */
- menuItem = new JMenuItem(new DefaultEditorKit.CutAction());
- menuItem.setText(SciNotesMessages.CUT);
- popup.add(menuItem);
-
- /* Paste */
- menuItem = new JMenuItem(new DefaultEditorKit.PasteAction());
- menuItem.setText(SciNotesMessages.PASTE);
-
- /* Completion */
- menuItem = new JMenuItem();
- menuItem.addActionListener(new ActionListener() {
- private SciNotesCompletionAction action;
- public void actionPerformed(ActionEvent actionEvent) {
- if (action == null) {
- action = new SciNotesCompletionAction(c, editor);
- }
- action.actionPerformed(actionEvent);
- }
- });
- menuItem.setAccelerator(map.get("SciNotesCompletionAction"));
- menuItem.setText(SciNotesMessages.COMPLETE);
- popup.add(menuItem);
- popup.addSeparator();
-
- /* Select all */
- ActionListener actionListenerSelectAll = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- c.selectAll();
- }
- };
- menuItem = new JMenuItem(SciNotesMessages.SELECT_ALL);
- menuItem.addActionListener(actionListenerSelectAll);
- popup.add(menuItem);
-
- /* Edit in the Scilab Text Editor */
- final JMenuItem helpMenuItem = new JMenuItem(SciNotesMessages.HELP_ON_SELECTED);
-
- ActionListener actionListenerHelpOnKeyword = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- String selection = c.getSelectedText();
- if (selection == null) {
- KeywordEvent kwe = ((ScilabEditorPane) c).getKeywordEvent();
- if (ScilabLexerConstants.isHelpable(kwe.getType())) {
- try {
- selection = c.getDocument().getText(kwe.getStart(), kwe.getLength());
- } catch (BadLocationException e) { }
- } else {
- infoBar.setText(SciNotesMessages.NO_TEXT_SELECTED);
- return;
- }
- }
- /* Double the quote/double quote in order to avoid
- * and error with the call of help()
- */
- selection = selection.replaceAll("'", "''");
- selection = selection.replaceAll("\"", "\"\"");
-
- InterpreterManagement.requestScilabExec("help('" + selection + "')");
- }
- };
-
- /* Not sure it is the best listener */
- PropertyChangeListener listenerTextItem = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- String keyword = c.getSelectedText();
- if (keyword == null) {
- KeywordEvent kwe = ((ScilabEditorPane) c).getKeywordEvent();
- if (ScilabLexerConstants.isHelpable(kwe.getType())) {
- try {
- keyword = c.getDocument().getText(kwe.getStart(), kwe.getLength());
- } catch (BadLocationException e) { }
- } else {
- helpMenuItem.setText(SciNotesMessages.HELP_ON_FOO);
- helpMenuItem.setEnabled(false);
- return;
- }
- }
- int nbOfDisplayedOnlyXChar = 10;
- if (keyword.length() > nbOfDisplayedOnlyXChar) {
- keyword = keyword.substring(0, nbOfDisplayedOnlyXChar) + SciNotesMessages.DOTS;
- }
- helpMenuItem.setText(SciNotesMessages.HELP_ABOUT + keyword + "'");
- helpMenuItem.setEnabled(true);
- }
- };
- helpMenuItem.addPropertyChangeListener(listenerTextItem);
- helpMenuItem.addActionListener(actionListenerHelpOnKeyword);
- popup.add(helpMenuItem);
-
- /* Open source file in the Scilab Text Editor */
- final JMenuItem sourceMenuItem = new JMenuItem(SciNotesMessages.OPEN_SOURCE_FILE_ON_KEYWORD);
-
- ActionListener actionListenerOpenSource = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- KeywordEvent kwe = ((ScilabEditorPane) c).getKeywordEvent(c.getSelectionEnd());
- if (ScilabLexerConstants.isOpenable(kwe.getType())) {
- try {
- ScilabDocument doc = (ScilabDocument) ((ScilabEditorPane) c).getDocument();
- String keyword = doc.getText(kwe.getStart(), kwe.getLength());
- int pos = doc.searchFunctionByName(keyword);
- if (pos != -1) {
- ((ScilabEditorPane) c).scrollTextToPos(pos);
- } else {
- String path = "get_function_path('" + keyword + "')";
- InterpreterManagement.requestScilabExec("if " + path + " ~=[] then editor(" + path + ");end");
- }
- } catch (BadLocationException e) { }
- }
- }
- };
-
- /* Not sure it is the best listener */
- PropertyChangeListener listenerSourceItem = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- KeywordEvent kwe = ((ScilabEditorPane) c).getKeywordEvent(c.getSelectionEnd());
- if (ScilabLexerConstants.isOpenable(kwe.getType())) {
- try {
- String keyword = c.getDocument().getText(kwe.getStart(), kwe.getLength());
- int nbOfDisplayedOnlyXChar = 10;
- if (keyword.length() > nbOfDisplayedOnlyXChar) {
- keyword = keyword.substring(0, nbOfDisplayedOnlyXChar) + SciNotesMessages.DOTS;
- }
- sourceMenuItem.setText(SciNotesMessages.SOURCE_OF + keyword + "'");
- sourceMenuItem.setEnabled(true);
- } catch (BadLocationException e) { }
- } else {
- sourceMenuItem.setText(SciNotesMessages.OPEN_SOURCE_FILE_ON_KEYWORD);
- sourceMenuItem.setEnabled(false);
- }
- }
- };
- sourceMenuItem.addPropertyChangeListener(listenerSourceItem);
- sourceMenuItem.addActionListener(actionListenerOpenSource);
-
- popup.add(sourceMenuItem);
-
- /* Open URL default web browser */
- final JMenuItem urlMenuItem = new JMenuItem(SciNotesMessages.OPEN_URL);
-
- ActionListener actionListenerOpenURL = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- KeywordEvent kwe = ((ScilabEditorPane) c).getKeywordEvent(c.getSelectionEnd());
- if (ScilabLexerConstants.URL == kwe.getType() || ScilabLexerConstants.MAIL == kwe.getType()) {
- try {
- ScilabDocument doc = (ScilabDocument) ((ScilabEditorPane) c).getDocument();
- String url = doc.getText(kwe.getStart(), kwe.getLength());
- OpenURLAction.openURL(url);
- } catch (BadLocationException e) { }
- }
- }
- };
-
- /* Not sure it is the best listener */
- PropertyChangeListener listenerURLItem = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent arg0) {
- KeywordEvent kwe = ((ScilabEditorPane) c).getKeywordEvent(c.getSelectionEnd());
- if (ScilabLexerConstants.URL == kwe.getType() || ScilabLexerConstants.MAIL == kwe.getType()) {
- urlMenuItem.setEnabled(true);
- } else {
- urlMenuItem.setEnabled(false);
- }
- }
- };
- urlMenuItem.addPropertyChangeListener(listenerURLItem);
- urlMenuItem.addActionListener(actionListenerOpenURL);
-
- popup.add(urlMenuItem);
- /* Creates the Popupmenu on the component */
- c.setComponentPopupMenu(popup);
+ return null;
}
}
private boolean contentModified;
// Editor's default encoding is UTF-8
- private String encoding = "UTF-8";
+ private String encoding = "utf-8";
private boolean updater = true;
private boolean binary;
private boolean autoIndent;
package org.scilab.modules.scinotes.actions;
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-
import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
*/
public final class AboutAction extends DefaultAction {
- private static final long serialVersionUID = -8172282717877209957L;
+ private static final long serialVersionUID = -8172282717877209957L;
- /**
- * Constructor
- * @param editor associated editor
- */
- public AboutAction(SciNotes editor) {
- super(SciNotesMessages.ABOUT, editor);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor associated editor
+ */
+ public AboutAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Menu created for "Help menu"
- * @param editor associated editor
- * @return the menu
- */
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.ABOUT, null, new AboutAction(editor), KeyStroke.getKeyStroke(KeyEvent.VK_F1, ActionEvent.SHIFT_MASK));
- }
+ /**
+ * Menu created for "Help menu"
+ * @param label label of the menu
+ * @param editor associated editor
+ * @param key KeyStroke
+ * @return the menu
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new AboutAction(label, editor), key);
+ }
- /**
- * Action !!
- * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
- */
- public void doAction() {
- String[] contents = {SciNotesMessages.VERSION,
- "",
- SciNotesMessages.DIGITEO,
- SciNotesMessages.COPYRIGHT};
+ /**
+ * Action !!
+ * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
+ */
+ public void doAction() {
+ String[] contents = {SciNotesMessages.VERSION,
+ "",
+ SciNotesMessages.DIGITEO,
+ SciNotesMessages.COPYRIGHT};
- ScilabAboutBox.createAboutBox(SciNotesMessages.ABOUT, contents, null, null);
- }
+ ScilabAboutBox.createAboutBox(SciNotesMessages.ABOUT, contents, null, null);
+ }
}
import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
/**
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private ActivateHelpOnTypingAction(SciNotes editor) {
- super(SciNotesMessages.HELP_ON_TYPING, editor);
+ public ActivateHelpOnTypingAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* createCheckBoxMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return CheckBoxMenuItem
*/
- public static CheckBoxMenuItem createCheckBoxMenu(SciNotes editor, KeyStroke key) {
- CheckBoxMenuItem cb = createCheckBoxMenu(SciNotesMessages.HELP_ON_TYPING, null, new ActivateHelpOnTypingAction(editor), key);
+ public static CheckBoxMenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ CheckBoxMenuItem cb = createCheckBoxMenu(label, null, new ActivateHelpOnTypingAction(label, editor), key);
boolean b = ConfigSciNotesManager.getHelpOnTypingState();
cb.setChecked(b);
return cb;
package org.scilab.modules.scinotes.actions;
+import javax.swing.KeyStroke;
+
import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* AutoIndentAction Class
*/
public final class AutoIndentAction extends DefaultCheckAction {
-
/**
* serialVersionUID
*/
private static final long serialVersionUID = -1937347660350539353L;
-
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private AutoIndentAction(SciNotes editor) {
- super(SciNotesMessages.AUTO_INDENT, editor);
+ public AutoIndentAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
ConfigSciNotesManager.saveAutoIndent(this.getState());
}
-
/**
* createCheckBoxMenu
+ * @param label label of the menu
* @param editor SciNotes
+ * @param key KeyStroke
* @return CheckBoxMenuItem
*/
- public static CheckBoxMenuItem createCheckBoxMenu(SciNotes editor) {
- CheckBoxMenuItem autoIndent = createCheckBoxMenu(SciNotesMessages.AUTO_INDENT, null, new AutoIndentAction(editor), null);
+ public static CheckBoxMenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ CheckBoxMenuItem autoIndent = createCheckBoxMenu(label, null, new AutoIndentAction(label, editor), key);
autoIndent.setChecked(ConfigSciNotesManager.getAutoIndent());
return autoIndent;
}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Display about box for the text editor
/**
* Constructor
+ * @param name the name of the action
* @param editor associated editor
*/
- public CCloseTabInNewWindowAction(SciNotes editor) {
- super(SciNotesMessages.CCLOSE_TAB_IN_NEW_WINDOW, editor);
+ public CCloseTabInNewWindowAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key Keystroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.CCLOSE_TAB_IN_NEW_WINDOW, null, new CCloseTabInNewWindowAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new CCloseTabInNewWindowAction(label, editor), key);
}
/**
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* CloseAction Class
*
*/
public final class CloseAction extends DefaultAction {
-
+
/**
* serialVersionUID
*/
private static final long serialVersionUID = 3575152401442746355L;
-
+
/**
- * Constructor
+ * Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private CloseAction(SciNotes editor) {
- super(SciNotesMessages.CLOSE, editor);
+ public CloseAction(String name, SciNotes editor) {
+ super(name, editor);
}
-
+
/**
- * DoAction
+ * doAction
*/
public void doAction() {
- getEditor().closeTabAt(getEditor().getTabPane().getSelectedIndex());
-
- // Close the last opened file create a new file named "Untitled 1"
- if (getEditor().getTabPane().getTabCount() == 0) {
- getEditor().addEmptyTab();
- }
+ getEditor().closeTabAt(getEditor().getTabPane().getSelectedIndex());
+
+ // Close the last opened file create a new file named "Untitled 1"
+ if (getEditor().getTabPane().getTabCount() == 0) {
+ getEditor().addEmptyTab();
+ }
}
-
+
/**
* CreateMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.CLOSE, null, new CloseAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new CloseAction(label, editor), key);
}
}
package org.scilab.modules.scinotes.actions;
+import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* CloseAllAction Class
*
*/
public final class CloseAllAction extends DefaultAction {
-
+
/**
- * serialVersionUID
- */
- private static final long serialVersionUID = 7134703185408271944L;
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 7134703185408271944L;
- /**
- * Constructor
- * @param editor SciNotes
- */
- private CloseAllAction(SciNotes editor) {
- super(SciNotesMessages.CLOSEALL, editor);
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public CloseAllAction(String name, SciNotes editor) {
+ super(name, editor);
}
-
- /**
- * doAction
- */
+
+ /**
+ * doAction
+ */
public void doAction() {
- while (getEditor().getTabPane().getTabCount() != 0) {
- if (!getEditor().closeTabAt(getEditor().getTabPane().getSelectedIndex())) {
- return;
- }
- }
-
- // Close the last opened file create a new file named "Untitled 1"
- if (getEditor().getTabPane().getTabCount() == 0) {
- getEditor().addEmptyTab();
- }
+ while (getEditor().getTabPane().getTabCount() != 0) {
+ if (!getEditor().closeTabAt(getEditor().getTabPane().getSelectedIndex())) {
+ return;
+ }
+ }
+
+ // Close the last opened file create a new file named "Untitled 1"
+ if (getEditor().getTabPane().getTabCount() == 0) {
+ getEditor().addEmptyTab();
+ }
}
-
+
/**
* Create menu
+ * @param label label of the menu
* @param editor SciNotes
- * @return MenuItem
+ * @param key KeyStroke
+ * @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.CLOSEALL, null, new CloseAllAction(editor), null);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new CloseAllAction(label, editor), key);
}
}
-
package org.scilab.modules.scinotes.actions;
+import javax.swing.KeyStroke;
+
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* CloseAllButThisAction Class
* @author Allan CORNET
*
*/
-public final class CloseAllButThisAction extends DefaultAction {
+public final class CloseAllButThisAction extends DefaultAction {
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = -9052217229357472945L;
+
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public CloseAllButThisAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ int nbTabCount = getEditor().getTabPane().getTabCount();
+ boolean bContinue = true;
+ if (nbTabCount > 1) {
+ while ((getEditor().getTabPane().getTabCount() != 1) & (bContinue)) {
+ int currentIndex = getEditor().getTabPane().getSelectedIndex();
+ if (currentIndex != 0) {
+ bContinue = getEditor().closeTabAt(0);
+ } else {
+ bContinue = getEditor().closeTabAt(1);
+ }
+ }
+ }
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = -9052217229357472945L;
+ // Close the last opened file create a new file named "Untitled 1"
+ if (getEditor().getTabPane().getTabCount() == 0) {
+ getEditor().addEmptyTab();
+ }
+ }
- /**
- * Constructor
- * @param editor SciNotes
- */
- private CloseAllButThisAction(SciNotes editor) {
- super(SciNotesMessages.CLOSEALLBUTTHIS, editor);
- }
-
- /**
- * doAction
- */
- public void doAction() {
- int nbTabCount = getEditor().getTabPane().getTabCount();
- boolean bContinue = true;
- if (nbTabCount > 1) {
- while ((getEditor().getTabPane().getTabCount() != 1) & (bContinue)) {
- int currentIndex = getEditor().getTabPane().getSelectedIndex();
- if (currentIndex != 0) {
- bContinue = getEditor().closeTabAt(0);
- } else {
- bContinue = getEditor().closeTabAt(1);
- }
- }
- }
-
- // Close the last opened file create a new file named "Untitled 1"
- if (getEditor().getTabPane().getTabCount() == 0) {
- getEditor().addEmptyTab();
- }
- }
-
- /**
- * createMenu
- * @param editor SciNotes
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.CLOSEALLBUTTHIS, null, new CloseAllButThisAction(editor), null);
- }
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new CloseAllButThisAction(label, editor), key);
+ }
}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.scinotes.utils.NavigatorWindow;
/**
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private CodeNavigatorAction(SciNotes editor) {
- super(SciNotesMessages.CODE_NAVIGATOR, editor);
+ public CodeNavigatorAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return createMenu
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.CODE_NAVIGATOR, null, new CodeNavigatorAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new CodeNavigatorAction(label, editor), key);
}
/**
import org.scilab.modules.scinotes.CommentManager;
import org.scilab.modules.scinotes.ScilabDocument;
import org.scilab.modules.scinotes.ScilabEditorPane;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* CommentAction Class
*/
public final class CommentAction extends DefaultAction {
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = -7258307088402814986L;
-
- /**
- * Constructor
- * @param editor SciNotes
- */
- private CommentAction(SciNotes editor) {
- super(SciNotesMessages.COMMENT_SELECTION, editor);
- }
-
- /**
- * doAction
- */
- public void doAction() {
- ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
- int start = sep.getSelectionStart();
- int end = sep.getSelectionEnd();
- CommentManager com = sep.getCommentManager();
- ScilabDocument doc = (ScilabDocument) sep.getDocument();
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = -7258307088402814986L;
- doc.mergeEditsBegin();
- if (start == end) {
- com.commentText(start);
- } else {
- int[] ret = com.commentLines(start, end - 1);
- if (ret != null) {
- sep.setSelectionStart(ret[0]);
- sep.setSelectionEnd(ret[1]);
- }
- }
- doc.mergeEditsEnd();
- }
-
- /**
- * createMenu
- * @param editor SciNotes
- * @param key Keystroke
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.COMMENT_SELECTION, null, new CommentAction(editor), key);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public CommentAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
+ int start = sep.getSelectionStart();
+ int end = sep.getSelectionEnd();
+ CommentManager com = sep.getCommentManager();
+ ScilabDocument doc = (ScilabDocument) sep.getDocument();
+
+ doc.mergeEditsBegin();
+ if (start == end) {
+ com.commentText(start);
+ } else {
+ int[] ret = com.commentLines(start, end - 1);
+ if (ret != null) {
+ sep.setSelectionStart(ret[0]);
+ sep.setSelectionEnd(ret[1]);
+ }
+ }
+ doc.mergeEditsEnd();
+ }
+
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key Keystroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new CommentAction(label, editor), key);
+ }
}
package org.scilab.modules.scinotes.actions;
-import javax.swing.JComponent;
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.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* CopyAction Class
* serialVersionUID
*/
private static final long serialVersionUID = -8858655782952121924L;
-
+
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private CopyAction(SciNotes editor) {
- super(SciNotesMessages.COPY, editor);
+ public CopyAction(String name, SciNotes editor) {
+ super(name, editor);
}
-
+
/**
* doAction
*/
public void doAction() {
- getEditor().getTextPane().getActionMap().get(DefaultEditorKit.copyAction).actionPerformed(null);
+ getEditor().getTextPane().getActionMap().get(DefaultEditorKit.copyAction).actionPerformed(null);
}
-
+
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return createMenu
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.COPY, null, new CopyAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new CopyAction(label, editor), key);
}
-
+
/**
* createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
* @param editor SciNotes
* @return PushButton
*/
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.COPY, "edit-copy.png", new CopyAction(editor));
- }
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param key KeyStroke
- * @param editor Editor
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new CopyAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new CopyAction(tooltip, editor));
}
}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.scinotes.actions;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import javax.swing.JMenuItem;
+import javax.swing.KeyStroke;
+
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.scinotes.SciNotes;
+
+/**
+ * CopySelectionInNewTabAction class
+ * @author Calixte DENIZET
+ */
+public final class CopySelectionInNewTabAction extends DefaultAction {
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 320938663765236236L;
+
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public CopySelectionInNewTabAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ String selection = getEditor().getTextPane().getSelectedText();
+ SciNotes.scinotesWithText(selection);
+ }
+
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor scinotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
+ final MenuItem menuitem = createMenu(label, null, new CopySelectionInNewTabAction(label, editor), key);
+ ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent e) {
+ String selection = editor.getTextPane().getSelectedText();
+ menuitem.setEnabled(selection != null);
+ }
+ });
+
+ return menuitem;
+ }
+}
package org.scilab.modules.scinotes.actions;
import javax.swing.KeyStroke;
-import javax.swing.JComponent;
import javax.swing.text.DefaultEditorKit;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabDocument;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* CutAction Class
* serialVersionUID
*/
private static final long serialVersionUID = -4831313579986185630L;
-
+
/**
- * Constructor
+ * Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private CutAction(SciNotes editor) {
- super(SciNotesMessages.CUT, editor);
+ public CutAction(String name, SciNotes editor) {
+ super(name, editor);
}
-
+
/**
* doAction
*/
public void doAction() {
- ScilabDocument doc = (ScilabDocument) getEditor().getTextPane().getDocument();
- doc.mergeEditsBegin();
- getEditor().getTextPane().getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null);
- doc.mergeEditsEnd();
+ ScilabDocument doc = (ScilabDocument) getEditor().getTextPane().getDocument();
+ doc.mergeEditsBegin();
+ getEditor().getTextPane().getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null);
+ doc.mergeEditsEnd();
}
/**
* createMenu
- * @param editor SciNotes
+ * @param label label of the menu
+ * @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.CUT, null, new CutAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new CutAction(label, editor), key);
}
-
+
/**
* createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
* @param editor SciNotes
* @return PushButton
*/
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.CUT, "edit-cut.png", new CutAction(editor));
- }
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param editor Editor
- * @param key KeyStroke
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new CutAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new CutAction(tooltip, editor));
}
}
*
*/
public class DefaultCheckAction extends SwingScilabCheckBoxMenuItem implements CheckBoxMenuItem, ActionListener {
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 5618123082228356437L;
- private SciNotes editorBackup;
-
- /**
- * Constructor
- * @param editor SciNotes
- */
- @SuppressWarnings("serial")
- public DefaultCheckAction(SciNotes editor) {
- super();
- setText(SciNotesMessages.DEFAULT + SciNotesMessages.DOTS);
- setState(true);
- editorBackup = editor;
-
- setCallback(new CallBack(SciNotesMessages.DEFAULT + SciNotesMessages.DOTS) {
- public void callBack() {
- doAction();
- }
-
- public void actionPerformed(ActionEvent e) {
- callBack();
- }
- });
- }
-
- /**
- *
- * @param label label (string)
- * @param editor SciNotes
- */
- @SuppressWarnings("serial")
- protected DefaultCheckAction(String label, SciNotes editor) {
- super();
- setText(label);
- setState(true);
- editorBackup = editor;
- setCallback(new CallBack(SciNotesMessages.DEFAULT + SciNotesMessages.DOTS) {
- public void callBack() {
- doAction();
- }
-
- public void actionPerformed(ActionEvent e) {
- callBack();
- }
- });
- }
-
- /**
- * get Editor
- * @return SciNotes
- */
- public SciNotes getEditor() {
- return editorBackup;
- }
-
- /**
- * doAction
- */
- public void doAction() {
- JOptionPane.showMessageDialog(getEditor(), "Not Implemented Now !!! (state = " + getState() + ")", null, JOptionPane.ERROR_MESSAGE);
- }
-
- /**
- * actionPerformed
- * @param arg0 ActionEvent
- */
- public void actionPerformed(ActionEvent arg0) {
- doAction();
- }
-
- /**
- * createCheckBoxMenu
- * @param title String
- * @param icon String
- * @param defaultCheckAction DefaultCheckAction
- * @param keyStroke KeyStroke
- * @return CheckBoxMenuItem
- */
- 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;
- }
-
- /**
- * getAsSimpleCheckBoxMenuItem
- * @return SimpleCheckBoxMenuItem
- */
- public SimpleCheckBoxMenuItem getAsSimpleCheckBoxMenuItem() {
- return this;
- }
-
- /**
- * getAsSimpleMenuItem
- * @return SimpleMenuItem
- */
- public SimpleMenuItem getAsSimpleMenuItem() {
- return null;
- }
-
- /**
- * getAsSimpleMenu
- * @return SimpleMenu
- */
- public SimpleMenu getAsSimpleMenu() {
- return null;
- }
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 5618123082228356437L;
+ private SciNotes editorBackup;
+
+ /**
+ * Constructor
+ * @param editor SciNotes
+ */
+ @SuppressWarnings("serial")
+ public DefaultCheckAction(SciNotes editor) {
+ super();
+ setText(SciNotesMessages.DEFAULT + SciNotesMessages.DOTS);
+ setState(true);
+ editorBackup = editor;
+
+ setCallback(new CallBack(SciNotesMessages.DEFAULT + SciNotesMessages.DOTS) {
+ public void callBack() {
+ doAction();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ callBack();
+ }
+ });
+ }
+
+ /**
+ *
+ * @param label label (string)
+ * @param editor SciNotes
+ */
+ @SuppressWarnings("serial")
+ protected DefaultCheckAction(String label, SciNotes editor) {
+ super();
+ setText(label);
+ setState(true);
+ editorBackup = editor;
+ setCallback(new CallBack(SciNotesMessages.DEFAULT + SciNotesMessages.DOTS) {
+ public void callBack() {
+ doAction();
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ callBack();
+ }
+ });
+ }
+
+ /**
+ * get Editor
+ * @return SciNotes
+ */
+ public SciNotes getEditor() {
+ return editorBackup;
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ JOptionPane.showMessageDialog(getEditor(), "Not Implemented Now !!! (state = " + getState() + ")", null, JOptionPane.ERROR_MESSAGE);
+ }
+
+ /**
+ * actionPerformed
+ * @param arg0 ActionEvent
+ */
+ public void actionPerformed(ActionEvent arg0) {
+ doAction();
+ }
+
+ /**
+ * createCheckBoxMenu
+ * @param title String
+ * @param icon String
+ * @param defaultCheckAction DefaultCheckAction
+ * @param keyStroke KeyStroke
+ * @return CheckBoxMenuItem
+ */
+ 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;
+ }
+
+ /**
+ * getAsSimpleCheckBoxMenuItem
+ * @return SimpleCheckBoxMenuItem
+ */
+ public SimpleCheckBoxMenuItem getAsSimpleCheckBoxMenuItem() {
+ return this;
+ }
+
+ /**
+ * getAsSimpleMenuItem
+ * @return SimpleMenuItem
+ */
+ public SimpleMenuItem getAsSimpleMenuItem() {
+ return null;
+ }
+
+ /**
+ * getAsSimpleMenu
+ * @return SimpleMenu
+ */
+ public SimpleMenu getAsSimpleMenu() {
+ return null;
+ }
}
package org.scilab.modules.scinotes.actions;
+import javax.swing.KeyStroke;
import javax.swing.text.DefaultEditorKit;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
- *
+ * Delete action
* @author Bruno JOFRET
*
*/
public final class DeleteAction extends DefaultAction {
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = -1818764947112443369L;
-
- /**
- * Constructor
- * @param editor SciNotes
- */
- private DeleteAction(SciNotes editor) {
- super(SciNotesMessages.DELETE, editor);
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = -1818764947112443369L;
+
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public DeleteAction(String name, SciNotes editor) {
+ super(name, editor);
}
-
- /**
- * DoAction
- */
+
+ /**
+ * DoAction
+ */
public void doAction() {
- getEditor().getTextPane().getActionMap().get(DefaultEditorKit.deleteNextCharAction).actionPerformed(null);
+ getEditor().getTextPane().getActionMap().get(DefaultEditorKit.deleteNextCharAction).actionPerformed(null);
}
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
+ * @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.DELETE, null, new DeleteAction(editor), null);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new DeleteAction(label, editor), key);
}
-
+
}
import java.util.List;
import java.util.Iterator;
import java.util.Set;
-import java.util.SortedMap;
import java.util.Map;
import java.util.HashMap;
+import java.util.TreeMap;
+import javax.swing.ButtonGroup;
+import javax.swing.ImageIcon;
+import javax.swing.JMenu;
import javax.swing.JRadioButtonMenuItem;
+import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import javax.swing.text.EditorKit;
+import org.scilab.modules.gui.menu.Menu;
+import org.scilab.modules.gui.menu.ScilabMenu;
import org.scilab.modules.gui.messagebox.ScilabModalDialog;
import org.scilab.modules.gui.messagebox.ScilabModalDialog.ButtonType;
import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
import org.scilab.modules.scinotes.utils.SciNotesMessages;
-
/**
* EncodingAction Class
* @author Bruno JOFRET
*/
private static final long serialVersionUID = -5421313717126859924L;
+ private static final String CHECKICON = System.getenv("SCI") + "/modules/gui/images/icons/check-icon.png";
+
private static Map<String, String> encodings = new HashMap();
private static Map<String, List<String>> language = new HashMap();
+ private static JRadioButtonMenuItem[] radioTypes;
+ private static Menu[] menuLang;
static {
encodings.put("ASMO-708", "Arabic");
encodings.put("iso-8859-15", "Latin");
encodings.put("iso-2022-jp", "Japanese");
encodings.put("csISO2022JP", "Japanese");
- encodings.put("iso-2022-jp", "Japanese");
encodings.put("iso-2022-kr", "Korean");
encodings.put("euc-jp", "Japanese");
encodings.put("EUC-CN", "Chinese Simplified");
}
/**
+ * createEncodingSubMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return a Menu
+ */
+ public static Menu createMenu(String label, SciNotes editor, KeyStroke key) {
+ Menu encodingTypeMenu = ScilabMenu.createMenu();
+ encodingTypeMenu.setText(label);
+
+ Map<String, List<String>> languages = getEncodings();
+ Iterator<String> iter = languages.keySet().iterator();
+ int size = 0;
+ while (iter.hasNext()) {
+ size += languages.get(iter.next()).size();
+ }
+
+ if (radioTypes == null) {
+ radioTypes = new JRadioButtonMenuItem[size];
+ menuLang = new Menu[languages.size()];
+ }
+
+ ButtonGroup group = new ButtonGroup();
+
+ iter = languages.keySet().iterator();
+ int psize = 0;
+ int k = 0;
+ while (iter.hasNext()) {
+ String lang = iter.next();
+ List<String> encodingList = languages.get(lang);
+ menuLang[k] = ScilabMenu.createMenu();
+ menuLang[k].setText(lang);
+ encodingTypeMenu.add(menuLang[k]);
+ for (int i = 0; i < encodingList.size(); i++) {
+ radioTypes[psize + i] = (new EncodingAction(encodingList.get(i), editor)).createRadioButtonMenuItem(editor);
+ group.add(radioTypes[psize + i]);
+ ((JMenu) menuLang[k].getAsSimpleMenu()).add(radioTypes[psize + i]);
+
+ if (encodingList.get(i).toUpperCase().equals(Charset.defaultCharset().toString().toUpperCase())) {
+ radioTypes[psize + i].setSelected(true);
+ }
+ }
+ psize += encodingList.size();
+ k++;
+ }
+
+ return encodingTypeMenu;
+ }
+
+ /**
+ * Update the selected item in the encoding pull down menu of the document.
+ * @param scilabDocument the document for which the encoding menu should
+ * be updated
+ */
+ public static void updateEncodingMenu(ScilabDocument scilabDocument) {
+ if (radioTypes != null) {
+ for (int i = 0; i < radioTypes.length; i++) {
+ if (scilabDocument.getEncoding().equals(radioTypes[i].getText())) {
+ radioTypes[i].setSelected(true);
+ updateIcon(scilabDocument.getEncoding());
+ return;
+ }
+ }
+ }
+ }
+
+ /**
* getEncodings
* @return Map : Language -> {enc1, enc2, ...}
*/
}
}
+ language = new TreeMap(language);
return language;
}
break;
case NO_OPTION ://No, exit
//Back to previous menu checked
- getEditor().getSciNotesGUI().updateEncodingMenu(styleDocument);
+ updateEncodingMenu(styleDocument);
return;
default:
break;
styleDocument.setEncoding(encoding);
ConfigSciNotesManager.saveDefaultEncoding(encoding);
+ //Update the menu
+ updateIcon(encoding);
+
// If file associated then reload
EditorKit editorKit = getEditor().getEditorKit();
String fileName = getEditor().getTextPane().getName();
SciNotesMessages.SCINOTES_ERROR, IconType.ERROR_ICON);
}
}
+
+ /**
+ * Add a check-icon near the current used language
+ * @param enc the actual encoding
+ */
+ private static void updateIcon(String enc) {
+ String lang = encodings.get(enc);
+ for (int i = 0; i < menuLang.length; i++) {
+ if (((JMenu) menuLang[i].getAsSimpleMenu()).getIcon() != null) {
+ ((JMenu) menuLang[i].getAsSimpleMenu()).setIcon(null);
+ }
+ if (menuLang[i].getText().equals(lang)) {
+ ((JMenu) menuLang[i].getAsSimpleMenu()).setIcon(new ImageIcon(CHECKICON));
+ }
+ }
+ }
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import javax.swing.ButtonGroup;
+import javax.swing.JMenu;
import javax.swing.JRadioButtonMenuItem;
+import javax.swing.KeyStroke;
+import org.scilab.modules.gui.menu.Menu;
+import org.scilab.modules.gui.menu.ScilabMenu;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabDocument;
import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
- * Class EndOfLineAction
+ * Class EndOfLineAction
* @author Allan CORNET
*
*/
-public class EndOfLineAction extends DefaultCheckAction {
-
- private static final String EOL_LINUX = "\n";
- private static final String EOL_MACOS = "\r";
- private static final String EOL_WINDOWS = "\r\n";
- private static final String LINE_SEPARATOR = "line.separator";
-
- /**
- * generated serialVersionUID
- */
- private static final long serialVersionUID = 7147038540238271944L;
-
- /* default */
- private String eolMenuLabel = SciNotesMessages.EOL_AUT0;
-
- /**
- * Constructor
- * @param eolName String
- * @param editor SciNotes
- */
- public EndOfLineAction(String eolName, SciNotes editor) {
- super(eolName, editor);
- eolMenuLabel = eolName;
+public class EndOfLineAction extends DefaultCheckAction {
+
+ private static final String EOL_LINUX = "\n";
+ private static final String EOL_MACOS = "\r";
+ private static final String EOL_WINDOWS = "\r\n";
+ private static final String LINE_SEPARATOR = "line.separator";
+
+ private static JRadioButtonMenuItem[] radioEolTypes;
+
+ /**
+ * generated serialVersionUID
+ */
+ private static final long serialVersionUID = 7147038540238271944L;
+
+ /* default */
+ private String eolMenuLabel = SciNotesMessages.EOL_AUT0;
+
+ /**
+ * Constructor
+ * @param eolName String
+ * @param editor SciNotes
+ */
+ public EndOfLineAction(String eolName, SciNotes editor) {
+ super(eolName, editor);
+ eolMenuLabel = eolName;
+ }
+
+ /**
+ * createRadioButtonMenuItem
+ * @param editor SciNotes
+ * @return JRadioButtonMenuItem
+ */
+ public JRadioButtonMenuItem createRadioButtonMenuItem(SciNotes editor) {
+ JRadioButtonMenuItem radio = new JRadioButtonMenuItem(eolMenuLabel);
+ radio.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ doAction();
+ }
+ });
+ return radio;
}
-
- /**
- * createRadioButtonMenuItem
- * @param editor SciNotes
- * @return JRadioButtonMenuItem
- */
- public JRadioButtonMenuItem createRadioButtonMenuItem(SciNotes editor) {
- JRadioButtonMenuItem radio = new JRadioButtonMenuItem(eolMenuLabel);
- radio.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- doAction();
- }
- });
- return radio;
- }
-
- /**
- * doAction
- */
+
+ /**
+ * doAction
+ */
public void doAction() {
- ScilabDocument styleDocument = ((ScilabDocument) getEditor().getTextPane().getDocument());
-
- // default
- String newOel = System.getProperty(LINE_SEPARATOR);
-
- if (eolMenuLabel.compareToIgnoreCase(SciNotesMessages.EOL_AUT0) == 0) {
- newOel = System.getProperty(LINE_SEPARATOR);
- } else if (eolMenuLabel.compareToIgnoreCase(SciNotesMessages.EOL_LINUX) == 0) {
- newOel = EOL_LINUX;
- } else if (eolMenuLabel.compareToIgnoreCase(SciNotesMessages.EOL_MACOS) == 0) {
- newOel = EOL_MACOS;
- } else if (eolMenuLabel.compareToIgnoreCase(SciNotesMessages.EOL_WINDOWS) == 0) {
- newOel = EOL_WINDOWS;
- }
-
- if (styleDocument.getEOL().compareTo(newOel) != 0) {
- styleDocument.setEOL(newOel);
- styleDocument.setContentModified(true);
- // changing such a property dicards undo
- styleDocument.getUndoManager().discardAllEdits();
- getEditor().updateTabTitle();
- }
-
+ ScilabDocument styleDocument = ((ScilabDocument) getEditor().getTextPane().getDocument());
+
+ // default
+ String newOel = System.getProperty(LINE_SEPARATOR);
+
+ if (eolMenuLabel.compareToIgnoreCase(SciNotesMessages.EOL_AUT0) == 0) {
+ newOel = System.getProperty(LINE_SEPARATOR);
+ } else if (eolMenuLabel.compareToIgnoreCase(SciNotesMessages.EOL_LINUX) == 0) {
+ newOel = EOL_LINUX;
+ } else if (eolMenuLabel.compareToIgnoreCase(SciNotesMessages.EOL_MACOS) == 0) {
+ newOel = EOL_MACOS;
+ } else if (eolMenuLabel.compareToIgnoreCase(SciNotesMessages.EOL_WINDOWS) == 0) {
+ newOel = EOL_WINDOWS;
+ }
+
+ if (styleDocument.getEOL().compareTo(newOel) != 0) {
+ styleDocument.setEOL(newOel);
+ styleDocument.setContentModified(true);
+ // changing such a property dicards undo
+ styleDocument.getUndoManager().discardAllEdits();
+ getEditor().updateTabTitle();
+ }
+ }
+
+ /**
+ * create End Of Line sub Menu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return a Menu
+ */
+ public static Menu createMenu(String label, SciNotes editor, KeyStroke key) {
+ String eolLinux = ScilabDocument.EOLUNIX;
+ String eolMacOs = ScilabDocument.EOLMAC;
+ String eolWindows = ScilabDocument.EOLWIN;
+ String defaultEolLabel = SciNotesMessages.EOL_LINUX;
+
+ // selected by default O.S
+ String systemEolValue = System.getProperty(LINE_SEPARATOR);
+
+ if (systemEolValue.compareTo(eolLinux) == 0) {
+ defaultEolLabel = SciNotesMessages.EOL_LINUX;
+ }
+
+ if (systemEolValue.compareTo(eolWindows) == 0) {
+ defaultEolLabel = SciNotesMessages.EOL_WINDOWS;
+ }
+
+ if (systemEolValue.compareTo(eolMacOs) == 0) {
+ defaultEolLabel = SciNotesMessages.EOL_MACOS;
+ }
+
+ Menu eolTypeMenu = ScilabMenu.createMenu();
+ eolTypeMenu.setText(label);
+
+ radioEolTypes = new JRadioButtonMenuItem[3];
+ ButtonGroup groupEol = new ButtonGroup();
+
+ radioEolTypes[0] = (new EndOfLineAction(SciNotesMessages.EOL_LINUX, editor)).createRadioButtonMenuItem(editor);
+ groupEol.add(radioEolTypes[0]);
+ ((JMenu) eolTypeMenu.getAsSimpleMenu()).add(radioEolTypes[0]);
+
+ radioEolTypes[1] = (new EndOfLineAction(SciNotesMessages.EOL_WINDOWS, editor)).createRadioButtonMenuItem(editor);
+ groupEol.add(radioEolTypes[1]);
+ ((JMenu) eolTypeMenu.getAsSimpleMenu()).add(radioEolTypes[1]);
+
+ radioEolTypes[2] = (new EndOfLineAction(SciNotesMessages.EOL_MACOS, editor)).createRadioButtonMenuItem(editor);
+ groupEol.add(radioEolTypes[2]);
+ ((JMenu) eolTypeMenu.getAsSimpleMenu()).add(radioEolTypes[2]);
+
+ // selected menu
+ for (int k = 0; k < radioEolTypes.length; k++) {
+ if (radioEolTypes[k].getText().compareTo(defaultEolLabel) == 0) {
+ radioEolTypes[k].setSelected(true);
+ }
+ }
+
+ return eolTypeMenu;
+ }
+
+
+ /**
+ * Update the selected item in the EOL pull down menu of the document.
+ * @param scilabDocument the document for which the End Of Line menu should
+ * be updated
+ */
+ public static void updateEolMenu(ScilabDocument scilabDocument) {
+ String eolLinux = ScilabDocument.EOLUNIX;
+ String eolMacOs = ScilabDocument.EOLMAC;
+ String eolWindows = ScilabDocument.EOLWIN;
+
+ String eolUsedLabel = SciNotesMessages.EOL_LINUX;
+ String eolUsed = scilabDocument.getEOL();
+
+ if (eolUsed.compareTo(eolLinux) == 0) {
+ eolUsedLabel = SciNotesMessages.EOL_LINUX;
+ }
+
+ if (eolUsed.compareTo(eolMacOs) == 0) {
+ eolUsedLabel = SciNotesMessages.EOL_MACOS;
+ }
+
+ if (eolUsed.compareTo(eolWindows) == 0) {
+ eolUsedLabel = SciNotesMessages.EOL_WINDOWS;
+ }
+
+ for (int k = 0; k < radioEolTypes.length; k++) {
+ if (radioEolTypes[k].getText().compareTo(eolUsedLabel) == 0) {
+ radioEolTypes[k].setSelected(true);
+ }
+ }
}
}
package org.scilab.modules.scinotes.actions;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.StringTokenizer;
+import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import org.scilab.modules.gui.console.ScilabConsole;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.scinotes.ScilabEditorPane;
/**
*
*/
public final class EvaluateSelectionAction extends DefaultAction {
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 320938663765236236L;
- /**
- * Constructor
- * @param editor SciNotes
- */
- private EvaluateSelectionAction(SciNotes editor) {
- super(SciNotesMessages.EVALUATE_SELECTION, editor);
- }
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 320938663765236236L;
- /**
- * doAction
- */
- public void doAction() {
- /* Will do the job as if it was copy / paste in scilab Console */
- ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
- String selection = sep.getCodeToExecute();
- if (selection.compareTo("") != 0) {
- ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true, false);
- }
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public EvaluateSelectionAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * createMenu
- * @param editor scinotes
- * @param key KeyStroke
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.EVALUATE_SELECTION, null, new EvaluateSelectionAction(editor), key);
- }
+ /**
+ * doAction
+ */
+ public void doAction() {
+ /* Will do the job as if it was copy / paste in scilab Console */
+ ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
+ String selection = sep.getCodeToExecute();
+ if (selection.compareTo("") != 0) {
+ ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true, false);
+ }
+ }
+
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor scinotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
+ StringTokenizer token = new StringTokenizer(label, ";");
+ final String label1 = token.nextToken();
+ final String label2 = token.nextToken();
+ final MenuItem menuitem = createMenu(label1, null, new EvaluateSelectionAction(label1, editor), key);
+ if (!ScilabConsole.isExistingConsole()) { // Only available in STD mode
+ ((JMenuItem) menuitem.getAsSimpleMenuItem()).setEnabled(false);
+ }
+ ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent e) {
+ String select = editor.getTextPane().getSelectedText();
+ if (select == null) {
+ menuitem.setText(label1);
+ } else {
+ menuitem.setText(label2);
+ }
+ }
+ });
+
+ return menuitem;
+ }
}
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private ExecuteFileIntoScilabAction(SciNotes editor) {
- super(SciNotesMessages.EXECUTE_FILE_INTO_SCILAB, editor);
+ public ExecuteFileIntoScilabAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* @param editor the Scilab editor
*/
private void executeFile(SciNotes editor) {
-
String filePath = editor.getTextPane().getName();
- /*TODO : check if that fixes 7032 */
+ if (filePath == null) {
+ return;
+ }
+
filePath = filePath.replaceAll("\"", "\"\"");
filePath = filePath.replaceAll("'", "''");
- /* end */
if (filePath.compareTo("") != 0) {
String cmdToExec = "exec('" + filePath + "', -1)";
try {
* doAction
*/
public void doAction() {
- /* Will execute the document file (file sould be saved)*/
-
SciNotes editor = getEditor();
if (((ScilabDocument) getEditor().getTextPane().getDocument()).isContentModified()) {
}
/**
- * createMenu
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
* @param editor SciNotes
- * @param key KeyStroke
- * @return MenuItem
+ * @return PushButton
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.EXECUTE_FILE_INTO_SCILAB, null, new ExecuteFileIntoScilabAction(editor), key);
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new ExecuteFileIntoScilabAction(tooltip, editor));
}
/**
- * createButton
+ * createMenu
+ * @param label label of the menu
* @param editor SciNotes
- * @return PushButton
+ * @param key KeyStroke
+ * @return MenuItem
*/
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.EXECUTE_FILE_INTO_SCILAB, "media-playback-start.png", new ExecuteFileIntoScilabAction(editor));
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new ExecuteFileIntoScilabAction(label, editor), key);
}
}
import org.scilab.modules.gui.utils.UIElementMapper;
import org.scilab.modules.gui.window.ScilabWindow;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* ExitAction class
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private ExitAction(SciNotes editor) {
- super(SciNotesMessages.EXIT, editor);
+ public ExitAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.EXIT, null, new ExitAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new ExitAction(label, editor), key);
}
}
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private FindAction(SciNotes editor) {
- super(SciNotesMessages.FIND_REPLACE + SciNotesMessages.DOTS, editor);
+ public FindAction(String name, SciNotes editor) {
+ super(name, editor);
editor.addFindActionWindow(this);
}
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key Keystroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.FIND_REPLACE + SciNotesMessages.DOTS, null, new FindAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new FindAction(label, editor), key);
}
/**
* createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
* @param editor SciNotes
* @return PushButton
*/
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.FIND_REPLACE + "...", "edit-find-replace.png", new FindAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new FindAction(tooltip, editor));
}
/**
import java.util.List;
-import javax.swing.JComponent;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabDocument;
-import javax.swing.JEditorPane;
import org.scilab.modules.scinotes.SearchManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
*
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- protected FindNextAction(SciNotes editor) {
- super(SciNotesMessages.FIND_NEXT, editor);
+ public FindNextAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
exp = getEditor().getTextPane().getDocument().getText(startPos, endPos - startPos);
}
- JEditorPane scinotesTextPane = getEditor().getTextPane();
- ScilabDocument scilabStyle = ((ScilabDocument) scinotesTextPane.getDocument());
+ ScilabDocument scilabStyle = (ScilabDocument) getEditor().getTextPane().getDocument();
//search from current position to end document
List<Integer[]> offsets = SearchManager.findWord(scilabStyle, exp, 0, scilabStyle.getLength(), false, false, false);
getEditor().getTextPane().select(offsets.get(index)[0], offsets.get(index)[1]);
}
} catch (BadLocationException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.FIND_NEXT, null, new FindNextAction(editor), key);
- }
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param editor Editor
- * @param key KeyStroke
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new FindNextAction(editor));
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new FindNextAction(label, editor), key);
}
}
import java.util.List;
-import javax.swing.JComponent;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabDocument;
-import javax.swing.JEditorPane;
import org.scilab.modules.scinotes.SearchManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
*
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- protected FindPreviousAction(SciNotes editor) {
- super(SciNotesMessages.FIND_NEXT, editor);
+ public FindPreviousAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
exp = getEditor().getTextPane().getDocument().getText(startPos, endPos - startPos);
}
- JEditorPane scinotesTextPane = getEditor().getTextPane();
- ScilabDocument scilabStyle = ((ScilabDocument) scinotesTextPane.getDocument());
+ ScilabDocument scilabStyle = (ScilabDocument) getEditor().getTextPane().getDocument();
//search from current position to end document
List<Integer[]> offsets = SearchManager.findWord(scilabStyle, exp, 0, scilabStyle.getLength(), false, false, false);
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.FIND_PREVIOUS, null, new FindPreviousAction(editor), key);
- }
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param editor Editor
- * @param key KeyStroke
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new FindPreviousAction(editor));
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new FindPreviousAction(label, editor), key);
}
}
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.ScilabDocument;
import org.scilab.modules.scinotes.FunctionScanner;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Generate help from a function definition
/**
* The help template
*/
- public static final String template = "//\n"
+ public static final String TEMPLATE = "//\n"
+ "//\n"
+ "// Calling Sequence\n"
+ "// [returnValues] = functionName(argsValues) // \n"
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private GenerateHelpFromFunctionAction(SciNotes editor) {
- super(SciNotesMessages.GENERATE_HELP, editor);
+ public GenerateHelpFromFunctionAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
ScilabDocument.ScilabLeafElement se = (ScilabDocument.ScilabLeafElement) e;
if (se.isFunction()) {
FunctionScanner.FunctionInfo info = se.getFunctionInfo();
- String help = template.replaceFirst("functionName", info.functionName);
+ String help = TEMPLATE.replaceFirst("functionName", info.functionName);
help = help.replaceFirst("returnValues", generateList(info.returnValues, ", ", ""));
help = help.replaceFirst("argsValues", generateList(info.argsValues, ", ", ""));
help = help.replaceFirst("returnValuesOnColumn", generateList(info.returnValues, ": \n// ", ": "));
*/
private String generateList(List<String> list, String sep, String end) {
String str = "";
- for(int i = 0; i < list.size() - 1; i++) {
+ for (int i = 0; i < list.size() - 1; i++) {
str += list.get(i) + sep;
}
if (list.size() >= 1) {
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key Keystroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.GENERATE_HELP, null, new GenerateHelpFromFunctionAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new GenerateHelpFromFunctionAction(label, editor), key);
}
}
package org.scilab.modules.scinotes.actions;
-import java.awt.event.KeyEvent;
-
import javax.swing.KeyStroke;
import org.scilab.modules.action_binding.InterpreterManagement;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* HelpAction Class
*/
public final class HelpAction extends DefaultAction {
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = -3024180292998640447L;
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = -3024180292998640447L;
- /**
- * Constructor
- * @param editor SciNotes
- */
- private HelpAction(SciNotes editor) {
- super(SciNotesMessages.HELP, editor);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public HelpAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * doAction
- */
- public void doAction() {
- String selection = getEditor().getTextPane().getSelectedText();
- if (selection == null || selection.equals("")) {
- InterpreterManagement.requestScilabExec("help('editor')");
- } else {
- InterpreterManagement.requestScilabExec("help('" + selection + "')");
- }
- }
+ /**
+ * doAction
+ */
+ public void doAction() {
+ String selection = getEditor().getTextPane().getSelectedText();
+ if (selection == null || selection.equals("")) {
+ InterpreterManagement.requestScilabExec("help('editor')");
+ } else {
+ InterpreterManagement.requestScilabExec("help('" + selection + "')");
+ }
+ }
- /**
- * createMenu
- * @param editor SciNotes
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.HELP, null, new HelpAction(editor),
- KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
- }
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new HelpAction(label, editor), key);
+ }
}
package org.scilab.modules.scinotes.actions;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import org.scilab.modules.scinotes.ScilabLexerConstants;
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.KeywordEvent;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.action_binding.InterpreterManagement;
/**
* @author Calixte DENIZET
*/
public class HelpOnKeywordAction extends DefaultAction {
-
+
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private HelpOnKeywordAction(SciNotes editor) {
- super(SciNotesMessages.HELP_ON_KEYWORD, editor);
+ public HelpOnKeywordAction(String name, SciNotes editor) {
+ super(name, editor);
}
-
+
/**
* doAction
*/
public void doAction() {
- KeywordEvent kwe = ((ScilabEditorPane) getEditor().getTextPane()).getKeywordEvent();
- if (ScilabLexerConstants.isHelpable(kwe.getType())) {
- try {
- String kw = getEditor().getTextPane().getDocument().getText(kwe.getStart(), kwe.getLength());
- InterpreterManagement.requestScilabExec("help('" + kw + "')");
- } catch (BadLocationException e) { }
- }
+ KeywordEvent kwe = ((ScilabEditorPane) getEditor().getTextPane()).getKeywordEvent();
+ if (ScilabLexerConstants.isHelpable(kwe.getType())) {
+ try {
+ String kw = getEditor().getTextPane().getDocument().getText(kwe.getStart(), kwe.getLength());
+ InterpreterManagement.requestScilabExec("help('" + kw + "')");
+ } catch (BadLocationException e) { }
+ }
}
-
+
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key Keystroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.HELP_ON_KEYWORD, null, new HelpOnKeywordAction(editor), key);
+ public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
+ final MenuItem menuitem = createMenu(label, null, new HelpOnKeywordAction(label, editor), key);
+ ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent e) {
+ KeywordEvent kwe = ((ScilabEditorPane) editor.getTextPane()).getKeywordEvent();
+ menuitem.setEnabled(ScilabLexerConstants.isHelpable(kwe.getType()));
+ }
+ });
+
+ return menuitem;
}
}
*/
package org.scilab.modules.scinotes.actions;
-import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
/**
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private HighlightCurrentLineAction(SciNotes editor) {
- super(SciNotesMessages.HIGHLIGHT_CURRENT_LINE, editor);
- setState(false);
+ public HighlightCurrentLineAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* createCheckBoxMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return CheckBoxMenuItem
*/
- public static CheckBoxMenuItem createCheckBoxMenu(SciNotes editor, KeyStroke key) {
- CheckBoxMenuItem cb = createCheckBoxMenu(SciNotesMessages.HIGHLIGHT_CURRENT_LINE, null, new HighlightCurrentLineAction(editor), key);
+ public static CheckBoxMenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ CheckBoxMenuItem cb = createCheckBoxMenu(label, null, new HighlightCurrentLineAction(label, editor), key);
cb.setChecked(ConfigSciNotesManager.getHighlightState());
return cb;
}
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param editor Editor
- * @param key KeyStroke
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new HighlightCurrentLineAction(editor));
- }
}
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.ScilabDocument;
import org.scilab.modules.scinotes.IndentManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
-
/**
* IndentAction Class
@SuppressWarnings("serial")
public final class IndentAction extends DefaultAction {
- /**
- * Constructor
- * @param editor SciNotes
- */
- private IndentAction(SciNotes editor) {
- super(SciNotesMessages.INDENT, editor);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public IndentAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * doAction
- */
- public void doAction() {
- ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
- int start = sep.getSelectionStart();
- int end = sep.getSelectionEnd();
- IndentManager indent = sep.getIndentManager();
- ScilabDocument doc = (ScilabDocument) sep.getDocument();
- int[] ret = new int[2];
+ /**
+ * doAction
+ */
+ public void doAction() {
+ ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
+ int start = sep.getSelectionStart();
+ int end = sep.getSelectionEnd();
+ IndentManager indent = sep.getIndentManager();
+ ScilabDocument doc = (ScilabDocument) sep.getDocument();
+ int[] ret = new int[2];
- doc.mergeEditsBegin();
- if (start == end) {
- ret = indent.indentDoc(start, end);
- if (ret != null) {
- sep.setCaretPosition(ret[0]);
- }
- } else {
- ret = indent.indentDoc(start, end - 1);
- if (ret != null) {
- sep.setSelectionStart(ret[0]);
- sep.setSelectionEnd(ret[1]);
- }
+ doc.mergeEditsBegin();
+ if (start == end) {
+ ret = indent.indentDoc(start, end);
+ if (ret != null) {
+ sep.setCaretPosition(ret[0]);
+ }
+ } else {
+ ret = indent.indentDoc(start, end - 1);
+ if (ret != null) {
+ sep.setSelectionStart(ret[0]);
+ sep.setSelectionEnd(ret[1]);
}
- doc.mergeEditsEnd();
}
+ doc.mergeEditsEnd();
+ }
- /**
- * createMenu
- * @param editor SciNotes
- * @param key KeyStroke
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.INDENT, null, new IndentAction(editor), key);
- }
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new IndentAction(label, editor), key);
+ }
}
*
*/
public final class LineBeautifierAction extends ScilabEditorKit.InsertBreakAction {
-
+
/**
* The key associated with tthis action
*/
- public static String key = "ENTER";
-
+ private static String key = "ENTER";
+
/**
* serialVersionUID
*/
private static final long serialVersionUID = -8313095922543576108L;
-
+
/**
* Constructor
*/
- private LineBeautifierAction() {
- }
-
+ public LineBeautifierAction() { }
+
/**
* actionPerformed
* @param ev ActionEvent
*/
public void actionPerformed(ActionEvent ev) {
- super.actionPerformed(ev);
- ScilabEditorPane sep = (ScilabEditorPane) ev.getSource();
- sep.getIndentManager().indentDoc(sep.getCaretPosition() - 1);
+ super.actionPerformed(ev);
+ ScilabEditorPane sep = (ScilabEditorPane) ev.getSource();
+ sep.getIndentManager().indentDoc(sep.getCaretPosition() - 1);
}
-
+
/**
* putInInputMap
* @param textPane JComponent
*/
package org.scilab.modules.scinotes.actions;
+import java.util.StringTokenizer;
import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
/**
*/
private static final long serialVersionUID = -2778300710964013775L;
+ private static String labelWhereami = "";
+ private static String labelNormal = "";
+ private static String labelNoLine = "";
+
private MenuItem menu;
private int state = 1;
/**
* Construtor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private LineNumbersAction(SciNotes editor) {
- super(SciNotesMessages.LINE_NUMBERS_WHEREAMI, editor);
+ public LineNumbersAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return createMenu
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- LineNumbersAction ln = new LineNumbersAction(editor);
- MenuItem mi = createMenu(SciNotesMessages.LINE_NUMBERS_WHEREAMI, null, ln, key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ StringTokenizer tokens = new StringTokenizer(label, ";");
+ labelWhereami = tokens.nextToken();
+ labelNormal = tokens.nextToken();
+ labelNoLine = tokens.nextToken();
+ LineNumbersAction ln = new LineNumbersAction(labelWhereami, editor);
+ MenuItem mi = createMenu(label, null, ln, key);
ln.state = ConfigSciNotesManager.getLineNumberingState();
ln.menu = mi;
ln.setMenu();
state = (state + 1) % 3;
switch (state) {
case 0 :
- menu.setText(SciNotesMessages.LINE_NUMBERS_NOWHEREAMI);
+ menu.setText(labelNormal);
break;
case 1 :
- menu.setText(SciNotesMessages.LINE_NUMBERS_WHEREAMI);
+ menu.setText(labelWhereami);
break;
default :
- menu.setText(SciNotesMessages.NO_LINE_NUMBERS);
+ menu.setText(labelNoLine);
}
}
}
*/
public final class LoadIntoScilabAction extends DefaultAction {
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = -5659317486404897280L;
-
- private static final int MAX_LINES_RECOMMANDED = 100;
- private static final int NB_STANDARD_COLUMNS = 80;
- private static final int MAX_CHARACTERS_RECOMMANDED = MAX_LINES_RECOMMANDED * NB_STANDARD_COLUMNS;
-
- /**
- * Constructor
- * @param editor SciNotes
- */
- private LoadIntoScilabAction(SciNotes editor) {
- super(SciNotesMessages.LOAD_INTO_SCILAB, editor);
- }
-
- /**
- * doAction
- */
- public void doAction() {
- String text = getEditor().getTextPane().getText();
-
- if (text.compareTo("") != 0) {
- boolean bContinue = false;
-
- if (maxLinesRecommandedDetected(text)) {
- if (ScilabModalDialog.show(getEditor(), SciNotesMessages.BIG_FILE_WARNING, SciNotesMessages.LOAD_INTO_SCILAB,
- IconType.QUESTION_ICON, ButtonType.YES_NO) == AnswerOption.YES_OPTION) {
- bContinue = true;
- } else {
- bContinue = false;
- }
- } else {
- bContinue = true;
- }
-
- if (bContinue) {
- String tmpFilename = "LOAD_INTO_SCILAB-";
-
- // save file as UTF-8
- try {
- File f = File.createTempFile(tmpFilename, ".sce");
- String tmpFullFilename = f.getAbsolutePath();
- OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(f) , "UTF-8");
- out.write(text);
- out.flush();
- out.close();
- String cmdToExec = "exec('" + tmpFullFilename + "', 1)";
- InterpreterManagement.requestScilabExec(cmdToExec);
- } catch (IOException e) {
- ScilabModalDialog.show(getEditor(), SciNotesMessages.COULD_NOT_FIND_TMPFILE);
- }
- }
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = -5659317486404897280L;
+
+ private static final int MAX_LINES_RECOMMANDED = 100;
+ private static final int NB_STANDARD_COLUMNS = 80;
+ private static final int MAX_CHARACTERS_RECOMMANDED = MAX_LINES_RECOMMANDED * NB_STANDARD_COLUMNS;
+
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public LoadIntoScilabAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ String text = getEditor().getTextPane().getText();
+
+ if (text.compareTo("") != 0) {
+ boolean bContinue = false;
+
+ if (maxLinesRecommandedDetected(text)) {
+ if (ScilabModalDialog.show(getEditor(), SciNotesMessages.BIG_FILE_WARNING, SciNotesMessages.LOAD_INTO_SCILAB,
+ IconType.QUESTION_ICON, ButtonType.YES_NO) == AnswerOption.YES_OPTION) {
+ bContinue = true;
+ } else {
+ bContinue = false;
}
- }
-
- /**
- * createMenu
- * @param editor SciNotes
- * @param key KeyStroke
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.LOAD_INTO_SCILAB, null, new LoadIntoScilabAction(editor), key);
- }
-
- /**
- * check if string is not too big
- * @param text to scan
- * @return true or false
- */
- private static boolean maxLinesRecommandedDetected(String text) {
- if (text.length() > MAX_CHARACTERS_RECOMMANDED) {
- return true;
- }
-
- String[] splitedStringOnLineSeparator = text.split(System.getProperty("line.separator"));
- if (splitedStringOnLineSeparator.length > MAX_LINES_RECOMMANDED) {
- return true;
+ } else {
+ bContinue = true;
+ }
+
+ if (bContinue) {
+ String tmpFilename = "LOAD_INTO_SCILAB-";
+
+ // save file as UTF-8
+ try {
+ File f = File.createTempFile(tmpFilename, ".sce");
+ String tmpFullFilename = f.getAbsolutePath();
+ OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(f) , "UTF-8");
+ out.write(text);
+ out.flush();
+ out.close();
+ String cmdToExec = "exec('" + tmpFullFilename + "', 1)";
+ InterpreterManagement.requestScilabExec(cmdToExec);
+ } catch (IOException e) {
+ ScilabModalDialog.show(getEditor(), SciNotesMessages.COULD_NOT_FIND_TMPFILE);
}
+ }
+ }
+ }
+
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new LoadIntoScilabAction(label, editor), key);
+ }
+
+ /**
+ * check if string is not too big
+ * @param text to scan
+ * @return true or false
+ */
+ private static boolean maxLinesRecommandedDetected(String text) {
+ if (text.length() > MAX_CHARACTERS_RECOMMANDED) {
+ return true;
+ }
- return false;
+ String[] splitedStringOnLineSeparator = text.split(System.getProperty("line.separator"));
+ if (splitedStringOnLineSeparator.length > MAX_LINES_RECOMMANDED) {
+ return true;
}
+
+ return false;
+ }
}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* File creation management
*/
public final class NewAction extends DefaultAction {
- private static final long serialVersionUID = -6865132453503118587L;
+ private static final long serialVersionUID = -6865132453503118587L;
- /**
- * Constructor
- * @param editor associated SciNotes instance
- */
- private NewAction(SciNotes editor) {
- super(SciNotesMessages.NEW, editor);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor associated SciNotes instance
+ */
+ public NewAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Create file action
- * @see org.scilab.modules.scinotes.actions.DefaultAction#doAction()
- */
- public void doAction() {
- getEditor().addEmptyTab();
- }
+ /**
+ * Create file action
+ * @see org.scilab.modules.scinotes.actions.DefaultAction#doAction()
+ */
+ public void doAction() {
+ getEditor().addEmptyTab();
+ }
- /**
- * Create a menu to add to SciNotes menu bar
- * @param editor associated SciNotes instance
- * @param key KeyStroke
- * @return the menu
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.NEW, null, new NewAction(editor), key);
- }
+ /**
+ * Create a menu to add to SciNotes menu bar
+ * @param label label of the menu
+ * @param editor associated SciNotes instance
+ * @param key KeyStroke
+ * @return the menu
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new NewAction(label, editor), key);
+ }
- /**
- * Create a button to add to SciNotes tool bar
- * @param editor associated SciNotes instance
- * @return the button
- */
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.NEW, "document-new.png", new NewAction(editor));
- }
+ /**
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
+ * @param editor SciNotes
+ * @return PushButton
+ */
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new NewAction(tooltip, editor));
+ }
}
package org.scilab.modules.scinotes.actions;
-import java.awt.Toolkit;
-import java.awt.event.KeyEvent;
-
import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* NextTabAction Class
*/
public final class NextTabAction extends DefaultAction {
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 3283491475309953312L;
-
- /**
- * Constructor
- * @param editor SciNotes
- */
- private NextTabAction(SciNotes editor) {
- super(SciNotesMessages.NEXT_TAB, editor);
- }
-
- /**
- * doAction
- */
- public void doAction() {
- int index = this.getEditor().getTabPane().getSelectedIndex();
- }
-
- /**
- * createMenu
- * @param editor SciNotes
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.NEXT_TAB, null, new NextTabAction(editor),
- KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
- }
-
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 3283491475309953312L;
+
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public NextTabAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ int index = getEditor().getTabPane().getSelectedIndex();
+ int count = getEditor().getTabPane().getTabCount();
+ getEditor().getTabPane().setSelectedIndex((index + 1) % count);
+ }
+
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new NextTabAction(label, editor), key);
+ }
}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* No Split
*/
public final class NoSplitAction extends DefaultAction {
- /**
- * Constructor
- * @param editor associated editor
- */
- public NoSplitAction(SciNotes editor) {
- super(SciNotesMessages.NO_SPLIT, editor);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor associated editor
+ */
+ public NoSplitAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Create the MenuItem
- * @param editor Editor
- * @param key KeyStroke
- * @return a MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.NO_SPLIT, null, new NoSplitAction(editor), key);
- }
+ /**
+ * Create the MenuItem
+ * @param label label of the menu
+ * @param editor Editor
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new NoSplitAction(label, editor), key);
+ }
- /**
- * Action !!
- * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
- */
- public void doAction() {
- getEditor().removeSplit();
- }
+ /**
+ * Action !!
+ * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
+ */
+ public void doAction() {
+ getEditor().removeSplit();
+ }
}
/**
* Constructor
+ * @param name the name of the action
* @param editor associated SciNotes instance
*/
- private OpenAction(SciNotes editor) {
- super(SciNotesMessages.OPEN, editor);
+ public OpenAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
String initialDirectoryPath = getEditor().getTextPane().getName();
if (initialDirectoryPath == null) {
- initialDirectoryPath = ConfigManager.getLastOpenedDirectory() ;
+ initialDirectoryPath = ConfigManager.getLastOpenedDirectory();
}
String[] mask = new String[]{"*.cos*", "*.sci", "*.sce", "*.tst", "*.start", "*.quit", "*.sc*", "all"};
ConfigSciNotesManager.saveToRecentOpenedFiles(f.getPath());
getEditor().setTitle(f.getPath() + " - " + SciNotesMessages.SCILAB_EDITOR);
- getEditor().updateRecentOpenedFilesMenu();
+ RecentFileAction.updateRecentOpenedFilesMenu(getEditor());
getEditor().readFile(f);
}
}
/**
* Create a menu to add to SciNotes menu bar
+ * @param label label of the menu
* @param editor associated SciNotes instance
* @param key KeyStroke
* @return the menu
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.OPEN, null, new OpenAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new OpenAction(label, editor), key);
}
/**
- * Create a button to add to SciNotes tool bar
- * @param editor associated SciNotes instance
- * @return the button
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
+ * @param editor SciNotes
+ * @return PushButton
*/
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.OPEN, "document-open.png", new OpenAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new OpenAction(tooltip, editor));
}
}
package org.scilab.modules.scinotes.actions;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import org.scilab.modules.scinotes.ScilabLexerConstants;
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.KeywordEvent;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.action_binding.InterpreterManagement;
/**
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private OpenSourceFileOnKeywordAction(SciNotes editor) {
- super(SciNotesMessages.OPEN_SOURCE_FILE_ON_KEYWORD, editor);
+ public OpenSourceFileOnKeywordAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
sep.scrollTextToPos(pos);
} else {
String path = "get_function_path('" + kw + "')";
- InterpreterManagement.requestScilabExec("if " + path +" ~=[] then editor(" + path + ");end");
+ InterpreterManagement.requestScilabExec("if " + path + " ~=[] then editor(" + path + ");end");
}
} catch (BadLocationException e) { }
}
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key Keystroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.OPEN_SOURCE_FILE_ON_KEYWORD, null, new OpenSourceFileOnKeywordAction(editor), key);
+ public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
+ final MenuItem menuitem = createMenu(label, null, new OpenSourceFileOnKeywordAction(label, editor), key);
+ ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent e) {
+ String keyword = editor.getTextPane().getSelectedText();
+ if (keyword == null) {
+ KeywordEvent kwe = editor.getTextPane().getKeywordEvent();
+ menuitem.setEnabled(ScilabLexerConstants.isOpenable(kwe.getType()));
+ }
+ }
+ });
+
+ return menuitem;
}
}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
- * Display about box for the text editor
+ * Open a tab in a new window
* @author Calixte DENIZET
*/
public final class OpenTabInNewWindowAction extends DefaultAction {
/**
* Constructor
+ * @param name the name of the action
* @param editor associated editor
*/
- public OpenTabInNewWindowAction(SciNotes editor) {
- super(SciNotesMessages.OPEN_TAB_IN_NEW_WINDOW, editor);
+ public OpenTabInNewWindowAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key Keystroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.OPEN_TAB_IN_NEW_WINDOW, null, new OpenTabInNewWindowAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new OpenTabInNewWindowAction(label, editor), key);
}
/**
package org.scilab.modules.scinotes.actions;
import java.awt.Desktop;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
-
+import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import org.scilab.modules.scinotes.ScilabLexerConstants;
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.KeywordEvent;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
-import org.scilab.modules.action_binding.InterpreterManagement;
/**
* OpenURLAction Class
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private OpenURLAction(SciNotes editor) {
- super(SciNotesMessages.OPEN_URL, editor);
+ public OpenURLAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key Keystroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.OPEN_URL, null, new OpenURLAction(editor), key);
+ public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
+ final MenuItem menuitem = createMenu(label, null, new OpenURLAction(label, editor), key);
+ ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent arg0) {
+ String keyword = editor.getTextPane().getSelectedText();
+ if (keyword == null) {
+ KeywordEvent kwe = editor.getTextPane().getKeywordEvent();
+ menuitem.setEnabled(ScilabLexerConstants.URL == kwe.getType());
+ }
+ }
+ });
+
+ return menuitem;
}
+ /**
+ * @param url the url to open
+ */
public static void openURL(String url) {
if (url == null || url.length() == 0) {
return;
}
} catch (IOException e) {
System.err.println(e.toString());
- }
- catch (URISyntaxException e) {
+ } catch (URISyntaxException e) {
System.err.println(e.toString());
}
}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* OverwriteAction class
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private OverwriteAction(SciNotes editor) {
- super(SciNotesMessages.OVERWRITE, editor);
+ public OverwriteAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* Create Menu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.OVERWRITE, null, new OverwriteAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new OverwriteAction(label, editor), key);
}
/**
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
-
import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Class Page setup action for SciNotes
*/
public class PageSetupAction extends DefaultAction {
- private static PageFormat pageFormat;
+ private static PageFormat pageFormat;
- /**
- * Default constructor
- * @param editor Editor
- */
- private PageSetupAction(SciNotes editor) {
- super(SciNotesMessages.PAGE_SETUP, editor);
- }
+ /**
+ * Default constructor
+ * @param name the name of the action
+ * @param editor Editor
+ */
+ public PageSetupAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Function Run
- */
- public void doAction() {
- PrinterJob printTask = PrinterJob.getPrinterJob();
- if (pageFormat == null) {
- pageFormat = printTask.pageDialog(new HashPrintRequestAttributeSet());
- } else {
- pageFormat = printTask.pageDialog(pageFormat);
- }
- }
+ /**
+ * Function Run
+ */
+ public void doAction() {
+ PrinterJob printTask = PrinterJob.getPrinterJob();
+ if (pageFormat == null) {
+ pageFormat = printTask.pageDialog(new HashPrintRequestAttributeSet());
+ } else {
+ pageFormat = printTask.pageDialog(pageFormat);
+ }
+ }
- /**
- * Create the MenuItem for page setup action
- * @param editor Editor
- * @return a MenuItem
- */
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.PAGE_SETUP, null, new PageSetupAction(editor), null);
- }
+ /**
+ * Create the MenuItem for page setup action
+ * @param label label of the menu
+ * @param editor Editor
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new PageSetupAction(label, editor), key);
+ }
- /**
- * Get the page format
- * @return PageFormat
- */
- public static PageFormat getPageFormat() {
- return pageFormat;
- }
+ /**
+ * Get the page format
+ * @return PageFormat
+ */
+ public static PageFormat getPageFormat() {
+ return pageFormat;
+ }
}
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2009 - DIGITEO - Bruno JOFRET
+ * Copyright (C) 2010 - Calixte DENIZET
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
package org.scilab.modules.scinotes.actions;
-import javax.swing.JComponent;
import javax.swing.KeyStroke;
import javax.swing.text.DefaultEditorKit;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabDocument;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
+/**
+ * Class for paste action
+ * @author Bruno JOFRET
+ * @author Calixte DENIZET
+ */
public class PasteAction extends DefaultAction {
- private PasteAction(SciNotes editor) {
- super(SciNotesMessages.PASTE, editor);
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor to associate
+ */
+ public PasteAction(String name, SciNotes editor) {
+ super(name, editor);
}
-
+
+ /**
+ * Action !
+ */
public void doAction() {
- ScilabDocument doc = (ScilabDocument) getEditor().getTextPane().getDocument();
- doc.mergeEditsBegin();
- getEditor().getTextPane().getActionMap().get(DefaultEditorKit.pasteAction).actionPerformed(null);
- doc.mergeEditsEnd();
+ ScilabDocument doc = (ScilabDocument) getEditor().getTextPane().getDocument();
+ doc.mergeEditsBegin();
+ getEditor().getTextPane().getActionMap().get(DefaultEditorKit.pasteAction).actionPerformed(null);
+ doc.mergeEditsEnd();
}
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.PASTE, null, new PasteAction(editor), key);
- }
-
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.PASTE, "edit-paste.png", new PasteAction(editor));
- }
-
/**
- * Put input map
- * @param textPane JTextpane
- * @param key KeyStroke
+ * Create the MenuItem for print action
+ * @param label label of the menu
* @param editor Editor
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new PasteAction(label, editor), key);
+ }
+
+ /**
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
+ * @param editor SciNotes
+ * @return PushButton
*/
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new PasteAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new PasteAction(tooltip, editor));
}
}
package org.scilab.modules.scinotes.actions;
-import java.awt.Toolkit;
-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.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Class Previous tab action for SciNotes
*/
public class PreviousTabAction extends DefaultAction {
- /**
- * Default constructor
- * @param editor Editor
- */
- private PreviousTabAction(SciNotes editor) {
- super(SciNotesMessages.PREVIOUS_TAB, editor);
- }
-
- /**
- * Function Run
- */
- public void doAction() {
- this.getEditor().getTabPane().getSelectedIndex();
- }
+ /**
+ * Default constructor
+ * @param name the name of the action
+ * @param editor Editor
+ */
+ public PreviousTabAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ int index = getEditor().getTabPane().getSelectedIndex();
+ int count = getEditor().getTabPane().getTabCount();
+ getEditor().getTabPane().setSelectedIndex((count + index - 1) % count);
+ }
- /**
- * Create the MenuItem for previous tab action
- * @param editor Editor
- * @return a MenuItem
- */
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.PREVIOUS_TAB, null, new PreviousTabAction(editor),
- KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
- + ActionEvent.SHIFT_MASK));
- }
+ /**
+ * Create the MenuItem for previous tab action
+ * @param label label of the menu
+ * @param editor Editor
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new PreviousTabAction(label, editor), key);
+ }
}
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.gui.utils.PrinterWriter;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Class Print action for SciNotes
*/
public class PrintAction extends DefaultAction {
- /**
- * Default constructor
- * @param editor the editor
- */
- private PrintAction(SciNotes editor) {
- super(SciNotesMessages.PRINT, editor);
- }
+ /**
+ * Default constructor
+ * @param name the name of the action
+ * @param editor the editor
+ */
+ public PrintAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Function doAction
- */
- public void doAction() {
- printSciNotesDocument(getEditor());
- }
+ /**
+ * Function doAction
+ */
+ public void doAction() {
+ printSciNotesDocument(getEditor());
+ }
- /**
- * Create the MenuItem for print action
- * @param editor Editor
- * @param key KeyStroke
- * @return a MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.PRINT, null, new PrintAction(editor), key);
- }
+ /**
+ * Create the MenuItem for print action
+ * @param label label of the menu
+ * @param editor Editor
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new PrintAction(label, editor), key);
+ }
- /**
- * Create print button
- * @param editor Editor
- * @return a pushbutton
- */
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.PRINT, "document-print.png", new PrintAction(editor));
- }
+ /**
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
+ * @param editor SciNotes
+ * @return PushButton
+ */
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new PrintAction(tooltip, editor));
+ }
- /**
- * This function allow to print a document
- * by calling a printer job
- * @param editor Editor
- * @return a boolean
- */
- public static boolean printSciNotesDocument(SciNotes editor) {
+ /**
+ * This function allow to print a document
+ * by calling a printer job
+ * @param editor Editor
+ * @return a boolean
+ */
+ public static boolean printSciNotesDocument(SciNotes editor) {
- PrinterJob printTask = PrinterJob.getPrinterJob();
+ PrinterJob printTask = PrinterJob.getPrinterJob();
- PageFormat pageFormat = PageSetupAction.getPageFormat();
- if (pageFormat != null) {
- printTask.setPrintable(new PrinterWriter(editor.getTextPane()), pageFormat);
- } else {
- printTask.setPrintable(new PrinterWriter(editor.getTextPane()));
- }
+ PageFormat pageFormat = PageSetupAction.getPageFormat();
+ if (pageFormat != null) {
+ printTask.setPrintable(new PrinterWriter(editor.getTextPane()), pageFormat);
+ } else {
+ printTask.setPrintable(new PrinterWriter(editor.getTextPane()));
+ }
- if (printTask.printDialog()) {
- try {
- printTask.print();
- } catch (PrinterException e) {
- e.printStackTrace();
- return false;
- }
- }
- return true;
- }
+ if (printTask.printDialog()) {
+ try {
+ printTask.print();
+ } catch (PrinterException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ return true;
+ }
}
import org.scilab.modules.gui.utils.PrinterWriter;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.SciNotesPrintPreviewWindow;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* PrintPreviewAction class
*/
public final class PrintPreviewAction extends DefaultAction {
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = -3222532237364937814L;
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = -3222532237364937814L;
- /**
- * Constructor
- * @param editor SciNotes
- */
- private PrintPreviewAction(SciNotes editor) {
- super(SciNotesMessages.PRINT_PREVIEW, editor);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public PrintPreviewAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * doAction
- */
- public void doAction() {
- PrinterWriter printerWriter = new PrinterWriter(getEditor().getTextPane());
- new SciNotesPrintPreviewWindow(printerWriter, getEditor());
- }
+ /**
+ * doAction
+ */
+ public void doAction() {
+ PrinterWriter printerWriter = new PrinterWriter(getEditor().getTextPane());
+ new SciNotesPrintPreviewWindow(printerWriter, getEditor());
+ }
- /**
- * createMenu
- * @param editor SciNotes
- * @param key KeyStroke
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.PRINT_PREVIEW, null, new PrintPreviewAction(editor), key);
- }
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new PrintPreviewAction(label, editor), key);
+ }
- /**
- * createButton
- * @param editor SciNotes
- * @return PushButton
- */
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.PRINT_PREVIEW, "document-print-preview.png", new PrintPreviewAction(editor));
- }
+ /**
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
+ * @param editor SciNotes
+ * @return PushButton
+ */
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new PrintPreviewAction(tooltip, editor));
+ }
}
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2009 - INRIA - Allan SIMON
- *
+ *
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at
+ * are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
*/
package org.scilab.modules.scinotes.actions;
+
import java.io.File;
+import java.util.List;
+import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menu.Menu;
+import org.scilab.modules.gui.menu.ScilabMenu;
+import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
*
*/
public class RecentFileAction extends DefaultAction {
-
- private File recentFile ;
-
- /**
- * Constructor
- * @param editor SciNotes
- * @param f File
- */
- private RecentFileAction(SciNotes editor , File f) {
- super(f.getName(), editor);
- recentFile = f ;
- }
-
- /**
- * doAction
- */
- public void doAction() {
- ConfigSciNotesManager.saveToRecentOpenedFiles(recentFile.getPath());
- getEditor().readFile(recentFile);
- getEditor().setTitle(recentFile.getPath() + " - SciNotes");
- }
-
- /**
- * createMenu
- * @param editorSciNotes
- * @param f File
- */
- public static MenuItem createMenu(SciNotes editor, File f) {
- return createMenu(f.getName(), null, new RecentFileAction(editor, f), null);
- }
+
+ private static Menu recentsMenu = ScilabMenu.createMenu();
+ private static String label;
+
+ private File recentFile;
+
+ /**
+ * Constructor
+ * @param editor SciNotes
+ * @param f File
+ */
+ public RecentFileAction(SciNotes editor , File f) {
+ super(f.getName(), editor);
+ recentFile = f;
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ ConfigSciNotesManager.saveToRecentOpenedFiles(recentFile.getPath());
+ getEditor().readFile(recentFile);
+ getEditor().setTitle(recentFile.getPath() + " - SciNotes");
+ }
+
+ /**
+ * createMenu
+ * @param editor SciNotes
+ * @param f File
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(SciNotes editor, File f) {
+ return createMenu(f.getName(), null, new RecentFileAction(editor, f), null);
+ }
+
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor associated editor
+ * @param key KeyStroke
+ * @return the menu
+ */
+ public static Menu createMenu(String label, SciNotes editor, KeyStroke key) {
+ RecentFileAction.label = label;
+ updateRecentOpenedFilesMenu(editor);
+ return recentsMenu;
+ }
+
+ /**
+ * Update menu displaying recent opened files.
+ * @param editor SciNotes
+ */
+ public static void updateRecentOpenedFilesMenu(SciNotes editor) {
+ List<File> recentFiles = ConfigSciNotesManager.getAllRecentOpenedFiles();
+
+ ((SwingScilabMenu) recentsMenu.getAsSimpleMenu()).removeAll();
+ for (int i = recentFiles.size() - 1; i >= 0; i--) {
+ recentsMenu.add(RecentFileAction.createMenu(editor, recentFiles.get(i)));
+ }
+ recentsMenu.setText(label);
+ }
}
package org.scilab.modules.scinotes.actions;
-import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* CommentAction Class
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private RedoAction(SciNotes editor) {
- super(SciNotesMessages.REDO, editor);
+ public RedoAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
+ * @return a MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.REDO, null, new RedoAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new RedoAction(label, editor), key);
}
/**
* createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
* @param editor SciNotes
+ * @return PushButton
*/
- public static PushButton createButton(SciNotes editor) {
- PushButton button = createButton(SciNotesMessages.REDO, "edit-redo.png", new RedoAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ PushButton button = createButton(tooltip, icon, new RedoAction(tooltip, editor));
editor.setRedoButton(button);
return button;
}
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param editor Editor
- * @param key KeyStroke
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new RedoAction(editor));
- }
}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* ReloadAction class
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private ReloadAction(SciNotes editor) {
- super(SciNotesMessages.RELOAD, editor);
+ public ReloadAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* Create Menu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.RELOAD, null, new ReloadAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new ReloadAction(label, editor), key);
}
/**
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.ScilabDocument;
import org.scilab.modules.scinotes.TrailingWhiteManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* RemoveTrailingWhiteAction Class
/**
* Construtor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private RemoveTrailingWhiteAction(SciNotes editor) {
- super(SciNotesMessages.REMOVE_TRAILING_WHITE, editor);
+ public RemoveTrailingWhiteAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* doAction
*/
public void doAction() {
- ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
- int start = sep.getSelectionStart();
- int end = sep.getSelectionEnd();
- TrailingWhiteManager trailing = sep.getTrailingWhiteManager();
- ScilabDocument doc = (ScilabDocument) sep.getDocument();
+ ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
+ int start = sep.getSelectionStart();
+ int end = sep.getSelectionEnd();
+ TrailingWhiteManager trailing = sep.getTrailingWhiteManager();
+ ScilabDocument doc = (ScilabDocument) sep.getDocument();
- doc.mergeEditsBegin();
- if (start == end) {
- int ret = trailing.removeTrailingWhite(start);
- if (ret != -1) {
- sep.setCaretPosition(ret);
- }
- } else {
- int[] ret = new int[2];
- ret = trailing.removeTrailingWhite(start, end - 1);
- if (ret != null) {
- sep.setSelectionStart(ret[0]);
- sep.setSelectionEnd(ret[1]);
- }
+ doc.mergeEditsBegin();
+ if (start == end) {
+ int ret = trailing.removeTrailingWhite(start);
+ if (ret != -1) {
+ sep.setCaretPosition(ret);
}
- doc.mergeEditsEnd();
+ } else {
+ int[] ret = new int[2];
+ ret = trailing.removeTrailingWhite(start, end - 1);
+ if (ret != null) {
+ sep.setSelectionStart(ret[0]);
+ sep.setSelectionEnd(ret[1]);
+ }
+ }
+ doc.mergeEditsEnd();
}
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
- * @return createMenu
+ * @return a MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.REMOVE_TRAILING_WHITE, null, new RemoveTrailingWhiteAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new RemoveTrailingWhiteAction(label, editor), key);
}
}
import java.awt.Font;
import java.util.List;
+import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
+/**
+ * ResetFontAction Class
+ * @author Calixte DENIZET
+ */
public class ResetFontAction extends DefaultAction {
- private ResetFontAction(SciNotes editor) {
- super(SciNotesMessages.RESET_DEFAULT_FONT, editor);
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public ResetFontAction(String name, SciNotes editor) {
+ super(name, editor);
}
+ /**
+ * doAction
+ */
public void doAction() {
Font oldFont = ConfigSciNotesManager.getDefaultFont();
List<String> listStylesName = ConfigSciNotesManager.getAllStyleName();
ConfigSciNotesManager.saveFont(oldFont);
}
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.RESET_DEFAULT_FONT, null, new ResetFontAction(editor), null);
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new ResetFontAction(label, editor), key);
}
}
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private SaveAction(SciNotes editor) {
- super(SciNotesMessages.SAVE, editor);
+ public SaveAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* Create Menu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.SAVE, null, new SaveAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new SaveAction(label, editor), key);
}
/**
- * Create Button
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
* @param editor SciNotes
* @return PushButton
*/
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.SAVE, "media-floppy.png", new SaveAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new SaveAction(tooltip, editor));
}
/**
*/
public final class SaveAllAction extends DefaultAction {
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 7134703185408281234L;
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 7134703185408281234L;
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public SaveAllAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Constructor
- * @param editor SciNotes
- */
- private SaveAllAction(SciNotes editor) {
- super(SciNotesMessages.SAVE_ALL, editor);
- }
-
- /**
- * doAction
- */
- public void doAction() {
- int currentIndex = getEditor().getTabPane().getSelectedIndex();
-
- for (int i = 0; i < getEditor().getTabPane().getTabCount(); i++) {
- getEditor().getTabPane().setSelectedIndex(i);
- if (!getEditor().save(getEditor().getTabPane().getSelectedIndex(), true)) {
- ScilabModalDialog.show(getEditor(), SciNotesMessages.COULD_NOT_SAVE_FILE,
- SciNotesMessages.SCINOTES_ERROR, IconType.ERROR_ICON);
- }
- }
- getEditor().getTabPane().setSelectedIndex(currentIndex);
+ /**
+ * doAction
+ */
+ public void doAction() {
+ int currentIndex = getEditor().getTabPane().getSelectedIndex();
+ for (int i = 0; i < getEditor().getTabPane().getTabCount(); i++) {
+ getEditor().getTabPane().setSelectedIndex(i);
+ if (!getEditor().save(getEditor().getTabPane().getSelectedIndex(), true)) {
+ ScilabModalDialog.show(getEditor(), SciNotesMessages.COULD_NOT_SAVE_FILE,
+ SciNotesMessages.SCINOTES_ERROR, IconType.ERROR_ICON);
+ }
}
+ getEditor().getTabPane().setSelectedIndex(currentIndex);
- /**
- * CreateMenu
- * @param editor SciNotes
- * @param key KeyStroke
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.SAVE_ALL, null, new SaveAllAction(editor), key);
- }
+ }
+
+ /**
+ * CreateMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new SaveAllAction(label, editor), key);
+ }
}
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private SaveAsAction(SciNotes editor) {
- super(SciNotesMessages.SAVE_AS, editor);
+ public SaveAsAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* CreateMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.SAVE_AS, null, new SaveAsAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new SaveAsAction(label, editor), key);
}
/**
- * Create Button
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
* @param editor SciNotes
* @return PushButton
*/
- public static PushButton createButton(SciNotes editor) {
- return createButton(SciNotesMessages.SAVE_AS, "document-save-as.png", new SaveAsAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ return createButton(tooltip, icon, new SaveAsAction(tooltip, editor));
}
}
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.scilab.modules.console.SciCompletionManager;
import org.scilab.modules.console.SciInputParsingManager;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabDocument;
import org.scilab.modules.scinotes.utils.SciNotesCompletionWindow;
/**
* Constructor
+ * @param textPane the pane associated
* @param editor SciNotes
*/
public SciNotesCompletionAction(JComponent textPane, SciNotes editor) {
}
/**
- * Put input map
- * @param textPane JTextpane
+ * Constructor
+ * @param editor SciNotes
+ */
+ public SciNotesCompletionAction(SciNotes editor) {
+ this.editor = editor;
+ }
+
+ /**
+ * Constructor
+ * @param name unused parameter
+ * @param editor SciNotes
+ */
+ public SciNotesCompletionAction(String name, SciNotes editor) {
+ this.editor = editor;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (configuration == null) {
+ configuration = new SciNotesCompletionConfiguration(editor.getTextPane());
+ }
+ super.actionPerformed(actionEvent);
+ }
+
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
* @param key KeyStroke
- * @param editor Editor
+ * @return MenuItem
*/
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new SciNotesCompletionAction(textPane, editor));
+ public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
+ MenuItem menu = ScilabMenuItem.createMenuItem();
+ menu.setText(label);
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).addActionListener(new ActionListener() {
+ private SciNotesCompletionAction action;
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (action == null) {
+ action = new SciNotesCompletionAction(editor);
+ }
+ action.actionPerformed(actionEvent);
+ }
+ });
+
+ if (key != null) {
+ ((SwingScilabMenuItem) menu.getAsSimpleMenuItem()).setAccelerator(key);
+ }
+
+ return menu;
}
/**
* Return an empty string to be sure that word won't be completed
* into filename.
* @param level an unused int
+ * @return a String
*/
public String getFilePartLevel(int level) {
return "";
/**
* Constructor
+ * @param textPane where to complete
*/
public SciNotesCompletionConfiguration(JComponent textPane) {
scm.setInputParsingManager(xipm);
package org.scilab.modules.scinotes.actions;
import javax.swing.KeyStroke;
-import javax.swing.JComponent;
import javax.swing.text.DefaultEditorKit;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabDocument;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Class to handle "select all"
/**
* Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
*/
- private SelectAllAction(SciNotes editor) {
- super(SciNotesMessages.SELECT_ALL, editor);
+ public SelectAllAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* createMenu
+ * @param label label of the menu
* @param editor SciNotes
* @param key KeyStroke
* @return MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.SELECT_ALL, null, new SelectAllAction(editor), key);
- }
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param editor Editor
- * @param key KeyStroke
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new SelectAllAction(editor));
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new SelectAllAction(label, editor), key);
}
}
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
+import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.text.DefaultCaret;
import javax.swing.event.ListSelectionEvent;
/**
* Constructor
+ * @param name the name of the action
* @param editor Scilab editor instance
*/
- private SetColorsAction(SciNotes editor) {
- super(SciNotesMessages.SET_COLORS, editor);
+ public SetColorsAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* Create the associated menu
+ * @param label label of the menu
* @param editor Scilab editor instance
+ * @param key KeyStroke
* @return the menu
*/
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.SET_COLORS, null, new SetColorsAction(editor), null);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new SetColorsAction(label, editor), key);
}
/**
import java.awt.Font;
import java.util.List;
+import javax.swing.KeyStroke;
import org.scilab.modules.gui.bridge.fontchooser.SwingScilabFontChooser;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.utils.ConfigSciNotesManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Class to set the font
/**
* Constructor
+ * @param name the name of the action
* @param editor associated with this action
*/
- private SetFontAction(SciNotes editor) {
- super(SciNotesMessages.SET_FONT, editor);
+ public SetFontAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
* DoAction
*/
public void doAction() {
- SwingScilabFontChooser _fontChooser = new SwingScilabFontChooser(ConfigSciNotesManager.getFont(), false);
- _fontChooser.displayAndWait();
+ SwingScilabFontChooser fontChooser = new SwingScilabFontChooser(ConfigSciNotesManager.getFont(), false);
+ fontChooser.displayAndWait();
- Font newFont = _fontChooser.getSelectedFont();
+ Font newFont = fontChooser.getSelectedFont();
if (newFont != null) {
}
/**
- * Create Menu
- * @param editor SciNotes
+ * Create the MenuItem
+ * @param label label of the menu
+ * @param editor Editor
* @param key KeyStroke
- * @return MenuItem
+ * @return a MenuItem
*/
- public static MenuItem createMenu(SciNotes editor) {
- return createMenu(SciNotesMessages.SET_FONT, null, new SetFontAction(editor), null);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new SetFontAction(label, editor), key);
}
}
+++ /dev/null
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
- *
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at
- * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
- *
- */
-
-package org.scilab.modules.scinotes.actions;
-
-import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
-import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
-
-public class ShowToolBarAction extends DefaultCheckAction {
-
- private ShowToolBarAction(SciNotes editor) {
- super(SciNotesMessages.SHOW_HIDE_TOOLBAR, editor);
- }
-
- public static CheckBoxMenuItem createCheckBoxMenu(SciNotes editor) {
- return createCheckBoxMenu(SciNotesMessages.SHOW_HIDE_TOOLBAR, null, new ShowToolBarAction(editor), null);
- }
-
-}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Split horizontally
*/
public final class SplitHorizontallyAction extends DefaultAction {
- /**
- * Constructor
- * @param editor associated editor
- */
- public SplitHorizontallyAction(SciNotes editor) {
- super(SciNotesMessages.SPLIT_HORIZONTALLY, editor);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor associated editor
+ */
+ public SplitHorizontallyAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Create the MenuItem
- * @param editor Editor
- * @param key KeyStroke
- * @return a MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.SPLIT_HORIZONTALLY, null, new SplitHorizontallyAction(editor), key);
- }
+ /**
+ * Create the MenuItem
+ * @param label label of the menu
+ * @param editor Editor
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new SplitHorizontallyAction(label, editor), key);
+ }
- /**
- * Action !!
- * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
- */
- public void doAction() {
- getEditor().splitTab(false);
- }
+ /**
+ * Action !!
+ * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
+ */
+ public void doAction() {
+ getEditor().splitTab(false);
+ }
}
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* Split vertically
*/
public final class SplitVerticallyAction extends DefaultAction {
- /**
- * Constructor
- * @param editor associated editor
- */
- public SplitVerticallyAction(SciNotes editor) {
- super(SciNotesMessages.SPLIT_VERTICALLY, editor);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor associated editor
+ */
+ public SplitVerticallyAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Create the MenuItem
- * @param editor Editor
- * @param key KeyStroke
- * @return a MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.SPLIT_VERTICALLY, null, new SplitVerticallyAction(editor), key);
- }
+ /**
+ * Create the MenuItem
+ * @param label label of the menu
+ * @param editor Editor
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new SplitVerticallyAction(label, editor), key);
+ }
- /**
- * Action !!
- * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
- */
- public void doAction() {
- getEditor().splitTab(true);
- }
+ /**
+ * Action !!
+ * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
+ */
+ public void doAction() {
+ getEditor().splitTab(true);
+ }
}
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2009 - DIGITEO - Bruno JOFRET
+ * Copyright (C) 2010 - Calixte DENIZET
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
package org.scilab.modules.scinotes.actions;
-import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.TabManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.scinotes.ScilabDocument;
/**
* Class Tabify action for SciNotes
* @author Sylvestre Koumar
+ * @author Calixte DENIZET
*
*/
public final class TabifyAction extends DefaultAction {
- /**
- * Default constructor
- * @param editor the editor
- */
- private TabifyAction(SciNotes editor) {
- super(SciNotesMessages.TABIFY_SELECTION, editor);
- }
-
- /**
- * Function doAction
- */
- public synchronized void doAction() {
- ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
- int start = sep.getSelectionStart();
- int end = sep.getSelectionEnd();
- TabManager tab = sep.getTabManager();
- ScilabDocument doc = (ScilabDocument) sep.getDocument();
-
- doc.mergeEditsBegin();
- if (start == end) {
- tab.insertTab(start);
- } else {
- int[] ret = tab.tabifyLines(start, end - 1);
- if (ret != null) {
- sep.setSelectionStart(ret[0]);
- sep.setSelectionEnd(ret[1]);
- }
- }
- doc.mergeEditsEnd();
- }
-
- /**
- * Create the MenuItem for tabify action
- * @param editor Editor
- * @param key KeyStroke
- * @return a MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.TABIFY_SELECTION , null, new TabifyAction(editor), key);
- }
+ /**
+ * Default constructor
+ * @param name the name of the action
+ * @param editor the editor
+ */
+ public TabifyAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
- /**
- * Put input map
- * @param textPane JTextpane
- * @param editor Editor
- * @param key KeyStroke
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new TabifyAction(editor));
- }
+ /**
+ * Function doAction
+ */
+ public synchronized void doAction() {
+ ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
+ int start = sep.getSelectionStart();
+ int end = sep.getSelectionEnd();
+ TabManager tab = sep.getTabManager();
+ ScilabDocument doc = (ScilabDocument) sep.getDocument();
+
+ doc.mergeEditsBegin();
+ if (start == end) {
+ tab.insertTab(start);
+ } else {
+ int[] ret = tab.tabifyLines(start, end - 1);
+ if (ret != null) {
+ sep.setSelectionStart(ret[0]);
+ sep.setSelectionEnd(ret[1]);
+ }
+ }
+ doc.mergeEditsEnd();
+ }
+
+ /**
+ * Create the MenuItem for tabify action
+ * @param label label of the menu
+ * @param editor Editor
+ * @param key KeyStroke
+ * @return a MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new TabifyAction(label, editor), key);
+ }
}
import org.scilab.modules.scinotes.CommentManager;
import org.scilab.modules.scinotes.ScilabDocument;
import org.scilab.modules.scinotes.ScilabEditorPane;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* UnCommentAction Class
*/
public final class UnCommentAction extends DefaultAction {
- /**
- * Constructor
- * @param editor SciNotes
- */
- public UnCommentAction(SciNotes editor) {
- super(SciNotesMessages.UNCOMMENT_SELECTION, editor);
- }
-
- /**
- * doAction
- */
- public void doAction() {
- ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
- int start = sep.getSelectionStart();
- int end = sep.getSelectionEnd();
- CommentManager com = sep.getCommentManager();
- ScilabDocument doc = (ScilabDocument) sep.getDocument();
-
- doc.mergeEditsBegin();
- if (start == end) {
- com.uncommentText(start);
- } else {
- int[] ret = com.uncommentLines(start, end - 1);
- if (ret != null) {
- sep.setSelectionStart(ret[0]);
- sep.setSelectionEnd(ret[1]);
- }
- }
- doc.mergeEditsEnd();
- }
-
- /**
- * createMenu
- * @param editor SciNotes
- * @param key KeyStroke
- * @return MenuItem
- */
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.UNCOMMENT_SELECTION, null, new UnCommentAction(editor), key);
- }
+ /**
+ * Constructor
+ * @param name the name of the action
+ * @param editor SciNotes
+ */
+ public UnCommentAction(String name, SciNotes editor) {
+ super(name, editor);
+ }
+
+ /**
+ * doAction
+ */
+ public void doAction() {
+ ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
+ int start = sep.getSelectionStart();
+ int end = sep.getSelectionEnd();
+ CommentManager com = sep.getCommentManager();
+ ScilabDocument doc = (ScilabDocument) sep.getDocument();
+
+ doc.mergeEditsBegin();
+ if (start == end) {
+ com.uncommentText(start);
+ } else {
+ int[] ret = com.uncommentLines(start, end - 1);
+ if (ret != null) {
+ sep.setSelectionStart(ret[0]);
+ sep.setSelectionEnd(ret[1]);
+ }
+ }
+ doc.mergeEditsEnd();
+ }
+
+ /**
+ * createMenu
+ * @param label label of the menu
+ * @param editor SciNotes
+ * @param key KeyStroke
+ * @return MenuItem
+ */
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new UnCommentAction(label, editor), key);
+ }
}
package org.scilab.modules.scinotes.actions;
-import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.scinotes.SciNotes;
import org.scilab.modules.scinotes.ScilabEditorPane;
import org.scilab.modules.scinotes.TabManager;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
import org.scilab.modules.scinotes.ScilabDocument;
/**
*
*/
public class UnTabifyAction extends DefaultAction {
-
+
/**
* Default constructor
+ * @param name the name of the action
* @param editor the editor
*/
- public UnTabifyAction(SciNotes editor) {
- super(SciNotesMessages.UNTABIFY_SELECTION, editor);
+ public UnTabifyAction(String name, SciNotes editor) {
+ super(name, editor);
}
-
+
/**
* Function doAction
*/
public void doAction() {
- ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
- int start = sep.getSelectionStart();
- int end = sep.getSelectionEnd();
- TabManager tab = sep.getTabManager();
- ScilabDocument doc = (ScilabDocument) sep.getDocument();
-
- doc.mergeEditsBegin();
- if (start == end) {
- tab.untabifyLine(start);
- } else {
- int[] ret = tab.untabifyLines(start, end - 1);
- if (ret != null) {
- sep.setSelectionStart(ret[0]);
- sep.setSelectionEnd(ret[1]);
- }
- }
- doc.mergeEditsEnd();
+ ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
+ int start = sep.getSelectionStart();
+ int end = sep.getSelectionEnd();
+ TabManager tab = sep.getTabManager();
+ ScilabDocument doc = (ScilabDocument) sep.getDocument();
+
+ doc.mergeEditsBegin();
+ if (start == end) {
+ tab.untabifyLine(start);
+ } else {
+ int[] ret = tab.untabifyLines(start, end - 1);
+ if (ret != null) {
+ sep.setSelectionStart(ret[0]);
+ sep.setSelectionEnd(ret[1]);
+ }
+ }
+ doc.mergeEditsEnd();
}
-
+
/**
* Create the MenuItem for untabify action
+ * @param label label of the menu
* @param editor Editor
* @param key KeyStroke
* @return a MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.UNTABIFY_SELECTION , null, new UnTabifyAction(editor), key);
- }
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param key KeyStroke
- * @param editor Editor
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new UnTabifyAction(editor));
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new UnTabifyAction(label, editor), key);
}
}
package org.scilab.modules.scinotes.actions;
-import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.gui.pushbutton.PushButton;
import org.scilab.modules.scinotes.SciNotes;
-import org.scilab.modules.scinotes.utils.SciNotesMessages;
/**
* CommentAction Class
/**
* Constructor
+ * @param name the name of the action
* @param editor SciNotes
*/
- private UndoAction(SciNotes editor) {
- super(SciNotesMessages.UNDO, editor);
+ public UndoAction(String name, SciNotes editor) {
+ super(name, editor);
}
/**
/**
* Create the MenuItem for undo action
+ * @param label label of the menu
* @param editor Editor
* @param key KeyStroke
* @return a MenuItem
*/
- public static MenuItem createMenu(SciNotes editor, KeyStroke key) {
- return createMenu(SciNotesMessages.UNDO, null, new UndoAction(editor), key);
+ public static MenuItem createMenu(String label, SciNotes editor, KeyStroke key) {
+ return createMenu(label, null, new UndoAction(label, editor), key);
}
-
/**
- * Create the menu for undo action
- * @param editor Editor
- * @return a PushButton
+ * createButton
+ * @param tooltip the tooltip
+ * @param icon an icon name searched in SCI/modules/gui/images/icons/
+ * @param editor SciNotes
+ * @return PushButton
*/
- public static PushButton createButton(SciNotes editor) {
- PushButton button = createButton(SciNotesMessages.UNDO, "edit-undo.png", new UndoAction(editor));
+ public static PushButton createButton(String tooltip, String icon, SciNotes editor) {
+ PushButton button = createButton(tooltip, icon, new UndoAction(tooltip, editor));
editor.setUndoButton(button);
return button;
}
-
- /**
- * Put input map
- * @param textPane JTextpane
- * @param editor Editor
- * @param key KeyStroke
- */
- public static void putInInputMap(JComponent textPane, SciNotes editor, KeyStroke key) {
- textPane.getInputMap().put(key, new UndoAction(editor));
- }
}
public static final String NEW = Messages.gettext("New") + DOTS;
public static final String OPEN = Messages.gettext("Open") + DOTS;
public static final String OPEN_SOURCE_FILE_ON_KEYWORD = Messages.gettext("Open function source file") + DOTS;
- public static final String OPEN_URL = Messages.gettext("Open URL in web browser") + DOTS;
+ public static final String OPEN_URL = Messages.gettext("Open URL") + DOTS;
public static final String SOURCE_OF = Messages.gettext("Source of '");
public static final String RECENT_FILES = Messages.gettext("Recent Files");
public static final String SAVE = Messages.gettext("Save");