gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.app / org.gvsig.geoprocess.app.mainplugin / src / main / java / org / gvsig / geoprocess / sextante / gui / cmd / BSHWindow.java @ 245
History | View | Annotate | Download (3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.geoprocess.sextante.gui.cmd; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.io.FileReader; |
29 |
|
30 |
import javax.swing.JComponent; |
31 |
import javax.swing.JPanel; |
32 |
|
33 |
import bsh.Interpreter; |
34 |
import bsh.util.JConsole; |
35 |
import es.unex.sextante.core.Sextante; |
36 |
import es.unex.sextante.gui.cmd.ScriptsIO; |
37 |
import es.unex.sextante.gui.core.SextanteGUI; |
38 |
import es.unex.sextante.gui.toolbox.ToolboxPanel; |
39 |
|
40 |
import org.gvsig.geoprocess.sextante.gui.GeoprocessWindow; |
41 |
|
42 |
|
43 |
/**
|
44 |
* Window with a BeanShell shell to execute geoprocess.
|
45 |
*
|
46 |
* @author gvSIG Team
|
47 |
* @version $Id$
|
48 |
*/
|
49 |
public class BSHWindow extends GeoprocessWindow { |
50 |
|
51 |
private static final long serialVersionUID = 3805562395822654358L; |
52 |
|
53 |
/**
|
54 |
* Creates a new {@link BSHWindow}.
|
55 |
*
|
56 |
* @param toolbox
|
57 |
* the main geoprocess selector panel
|
58 |
*/
|
59 |
public BSHWindow(ToolboxPanel toolbox) {
|
60 |
super(toolbox);
|
61 |
SextanteGUI.setLastCommandOrigin(SextanteGUI.COMMANDLINE); |
62 |
// SextanteGUI.setLastCommandOriginParentDialog(this);
|
63 |
} |
64 |
|
65 |
@Override
|
66 |
protected String getTitle() { |
67 |
return Sextante.getText("Command_line"); |
68 |
} |
69 |
|
70 |
@Override
|
71 |
protected JComponent getMainComponent() { |
72 |
JPanel panel = new JPanel(); |
73 |
panel.setSize(new Dimension(400, 300)); |
74 |
panel.setPreferredSize(new Dimension(400, 300)); |
75 |
panel.setLayout(new BorderLayout()); |
76 |
JConsole console = new JConsole();
|
77 |
panel.add("Center", console);
|
78 |
Interpreter interpreter = new Interpreter(console);
|
79 |
interpreter.getNameSpace().importCommands( |
80 |
"es.unex.sextante.gui.cmd.bshcommands");
|
81 |
String[] files = ScriptsIO.getScriptFiles(); |
82 |
if (files != null) { |
83 |
for (int i = 0; i < files.length; i++) { |
84 |
try {
|
85 |
FileReader reader = new FileReader(files[i]); |
86 |
interpreter.eval(reader); |
87 |
} catch (Exception e) { |
88 |
// Nothing to do
|
89 |
} |
90 |
} |
91 |
} |
92 |
new Thread(interpreter).start(); |
93 |
|
94 |
return panel;
|
95 |
} |
96 |
|
97 |
} |