2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 package org.scilab.modules.scinotes.actions;
15 import java.beans.PropertyChangeEvent;
16 import java.beans.PropertyChangeListener;
17 import java.util.StringTokenizer;
18 import javax.swing.JMenuItem;
19 import javax.swing.KeyStroke;
21 import org.scilab.modules.gui.console.ScilabConsole;
22 import org.scilab.modules.gui.menuitem.MenuItem;
23 import org.scilab.modules.scinotes.SciNotes;
24 import org.scilab.modules.scinotes.ScilabEditorPane;
27 * EvaluateSelectionAction class
28 * @author Bruno JOFRET
31 public final class EvaluateSelectionAction extends DefaultAction {
36 private static final long serialVersionUID = 320938663765236236L;
40 * @param name the name of the action
41 * @param editor SciNotes
43 public EvaluateSelectionAction(String name, SciNotes editor) {
50 public void doAction() {
51 /* Will do the job as if it was copy / paste in scilab Console */
52 ScilabEditorPane sep = (ScilabEditorPane) getEditor().getTextPane();
53 String selection = sep.getCodeToExecute();
54 if (selection.compareTo("") != 0) {
55 ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true, false);
61 * @param label label of the menu
62 * @param editor scinotes
63 * @param key KeyStroke
66 public static MenuItem createMenu(String label, final SciNotes editor, KeyStroke key) {
67 StringTokenizer token = new StringTokenizer(label, ";");
68 final String label1 = token.nextToken();
69 final String label2 = token.nextToken();
70 final MenuItem menuitem = createMenu(label1, null, new EvaluateSelectionAction(label1, editor), key);
71 if (!ScilabConsole.isExistingConsole()) { // Only available in STD mode
72 ((JMenuItem) menuitem.getAsSimpleMenuItem()).setEnabled(false);
74 ((JMenuItem) menuitem.getAsSimpleMenuItem()).addPropertyChangeListener(new PropertyChangeListener() {
75 public void propertyChange(PropertyChangeEvent e) {
76 String select = editor.getTextPane().getSelectedText();
78 menuitem.setText(label2);
80 menuitem.setText(label1);