2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007-2008 - INRIA - Vincent COUVERT
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.console;
15 import java.awt.datatransfer.StringSelection;
16 import java.awt.event.ActionEvent;
17 import java.awt.Toolkit;
18 import javax.swing.JPanel;
19 import javax.swing.JTextPane;
20 import javax.swing.text.BadLocationException;
21 import javax.swing.text.StyledDocument;
23 import org.scilab.modules.action_binding.InterpreterManagement;
25 import com.artenum.rosetta.core.action.AbstractConsoleAction;
26 import com.artenum.rosetta.util.StringConstants;
29 * Stops Scilab current work to enter pause mode
30 * Or cut selected text (if there is)
31 * This event is configured in configuration.xml file
32 * @author Vincent COUVERT
34 public class InterruptScilabWorkOrCut extends AbstractConsoleAction {
36 private static final long serialVersionUID = 1L;
41 public InterruptScilabWorkOrCut() {
48 * @param e the action event that occured
49 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
51 public void actionPerformed(ActionEvent e) {
53 if (((JTextPane) configuration.getInputCommandView()).getSelectedText() != null) {
54 /* Text selected in the input --> Copy */
55 StringSelection strSelected = new StringSelection(((JTextPane) configuration.getInputCommandView()).getSelectedText());
56 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(strSelected, null);
57 JTextPane input = (JTextPane) configuration.getInputCommandView();
58 StyledDocument doc = input.getStyledDocument();
60 doc.remove(input.getSelectionStart(), input.getSelectionEnd() - input.getSelectionStart());
61 } catch (BadLocationException e1) {
65 /* Interrupt Scilab */
66 InterpreterManagement.interruptScilab();
68 // If Scilab is on prompt, then emulate a user entry
69 if (((JPanel) configuration.getPromptView()).isVisible()) {
70 configuration.getOutputView().append(StringConstants.NEW_LINE);
71 configuration.getOutputView().append(configuration.getPromptView().getDefaultPrompt());
72 configuration.getOutputView().append(configuration.getInputParsingManager().getCommandLine());
73 configuration.getOutputView().append(StringConstants.NEW_LINE);
74 ((SciOutputView) configuration.getOutputView()).getConsole().sendCommandsToScilab("", false, false);
75 configuration.getInputParsingManager().reset();