gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / main / java / org / gvsig / scripting / swing / impl / composer / DefaultJScriptingComposer.java @ 368
History | View | Annotate | Download (41 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.Font; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ActionListener; |
8 |
import java.io.File; |
9 |
import java.io.OutputStream; |
10 |
import java.io.PrintStream; |
11 |
import java.util.ArrayList; |
12 |
import java.util.Iterator; |
13 |
import java.util.List; |
14 |
|
15 |
import javax.swing.JButton; |
16 |
import javax.swing.JLabel; |
17 |
import javax.swing.JMenu; |
18 |
import javax.swing.JMenuBar; |
19 |
import javax.swing.JMenuItem; |
20 |
import javax.swing.JOptionPane; |
21 |
import javax.swing.JPanel; |
22 |
import javax.swing.JScrollPane; |
23 |
import javax.swing.JSplitPane; |
24 |
import javax.swing.JTabbedPane; |
25 |
import javax.swing.JTable; |
26 |
import javax.swing.JTextArea; |
27 |
import javax.swing.JToolBar; |
28 |
import javax.swing.ListSelectionModel; |
29 |
import javax.swing.SwingConstants; |
30 |
import javax.swing.SwingUtilities; |
31 |
import javax.swing.event.ChangeEvent; |
32 |
import javax.swing.event.ChangeListener; |
33 |
import javax.swing.event.ListSelectionEvent; |
34 |
import javax.swing.event.ListSelectionListener; |
35 |
import javax.swing.table.DefaultTableModel; |
36 |
import javax.swing.text.JTextComponent; |
37 |
|
38 |
import org.gvsig.scripting.CompileErrorException; |
39 |
import org.gvsig.scripting.ExecuteErrorException; |
40 |
import org.gvsig.scripting.ScriptingBaseScript; |
41 |
import org.gvsig.scripting.ScriptingDialog; |
42 |
import org.gvsig.scripting.ScriptingFolder; |
43 |
import org.gvsig.scripting.ScriptingManager; |
44 |
import org.gvsig.scripting.ScriptingNotification; |
45 |
import org.gvsig.scripting.ScriptingScript; |
46 |
import org.gvsig.scripting.ScriptingUnit; |
47 |
import org.gvsig.scripting.swing.api.JCodeEditor; |
48 |
import org.gvsig.scripting.swing.api.JEditor; |
49 |
import org.gvsig.scripting.swing.api.JScriptingBrowser; |
50 |
import org.gvsig.scripting.swing.api.JScriptingComposer; |
51 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
52 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent.UpdateCaretPositionActionEvent; |
53 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingBrowser; |
54 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher; |
55 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher.LauncherActionEvent; |
56 |
import org.gvsig.scripting.swing.impl.JDialogContent; |
57 |
import org.gvsig.tools.observer.Observable; |
58 |
import org.gvsig.tools.observer.Observer; |
59 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
60 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
61 |
import org.gvsig.tools.task.AbstractMonitorableTask; |
62 |
import org.gvsig.tools.task.SimpleTaskStatus; |
63 |
import org.slf4j.Logger; |
64 |
import org.slf4j.LoggerFactory; |
65 |
|
66 |
|
67 |
public class DefaultJScriptingComposer extends JScriptingComposer implements Observer, ActionListener{ |
68 |
|
69 |
/**
|
70 |
*
|
71 |
*/
|
72 |
private static final long serialVersionUID = 1L; |
73 |
|
74 |
private static final Logger logger = LoggerFactory.getLogger(DefaultJScriptingComposer.class); |
75 |
|
76 |
public static final int CLOSE_ACTION = 1; |
77 |
public List<JEditor> unitsEditor; |
78 |
|
79 |
/* Generales */
|
80 |
ScriptingUIManager uimanager; |
81 |
ScriptingManager manager; |
82 |
ClassLoader loader;
|
83 |
|
84 |
/* Ventana inicial y componentes*/
|
85 |
JSplitPane mainPane;
|
86 |
JSplitPane editionPane;
|
87 |
JTabbedPane problemsPane;
|
88 |
JTabbedPane scriptEditors;
|
89 |
JMenuBar menuBar;
|
90 |
JToolBar file;
|
91 |
JToolBar edit;
|
92 |
JToolBar script;
|
93 |
JToolBar help;
|
94 |
JPanel statusBar;
|
95 |
JLabel currentLine;
|
96 |
JLabel statusBarMessage;
|
97 |
JTextArea problems;
|
98 |
JTextArea console;
|
99 |
DefaultJScriptingLauncher launcher; |
100 |
JToolBar launcherButtons;
|
101 |
PrintStream consolePrintStream = null; |
102 |
WindowManager windowsManager = null;
|
103 |
|
104 |
/* JFrame para la creación de nuevos ScriptingBaseScripts o modificación de atributos */
|
105 |
//JFrame NewUnitFrame;
|
106 |
|
107 |
/* Para el mantenimiento de la tabla de problemas en el código*/
|
108 |
Object[][] tableData; |
109 |
JTable table;
|
110 |
DefaultTableModel tableModel;
|
111 |
protected ActionListener defaultActionlistener = null; |
112 |
|
113 |
/**
|
114 |
* Instanciación de un JComposer con todos sus elementos y acciones
|
115 |
* @param manager
|
116 |
*/
|
117 |
public DefaultJScriptingComposer(final ScriptingUIManager uimanager) { |
118 |
loader = this.getClass().getClassLoader();
|
119 |
this.uimanager = uimanager;
|
120 |
this.manager = uimanager.getManager();
|
121 |
this.setWindowManager( ToolsSwingLocator.getWindowManager());
|
122 |
|
123 |
unitsEditor = new ArrayList<JEditor>(); |
124 |
|
125 |
initUI(); |
126 |
|
127 |
System.setOut(this.getConsolePrintStream()); |
128 |
System.setErr(this.getConsolePrintStream()); |
129 |
|
130 |
} |
131 |
|
132 |
public WindowManager getWindowManager() {
|
133 |
return this.windowsManager; |
134 |
} |
135 |
|
136 |
public void setWindowManager(WindowManager windowsManager) { |
137 |
this.windowsManager = windowsManager;
|
138 |
} |
139 |
|
140 |
private void initUI() { |
141 |
// Barra de menu
|
142 |
menuBar = new JMenuBar(); |
143 |
|
144 |
// Construimos los componentes del menu
|
145 |
JMenu menu_file = new JMenu("File"); |
146 |
JMenuItem menuItem_new = new JMenuItem("New",uimanager.getIcon("document-new")); |
147 |
menuItem_new.addActionListener(new ActionListener(){ |
148 |
public void actionPerformed(ActionEvent e) { |
149 |
try {
|
150 |
newScriptingBaseScript(); |
151 |
} catch (Exception e1) { |
152 |
// TODO Auto-generated catch block
|
153 |
e1.printStackTrace(); |
154 |
} |
155 |
} |
156 |
}); |
157 |
menu_file.add(menuItem_new); |
158 |
menu_file.addSeparator(); |
159 |
JMenuItem menuItem_close = new JMenuItem("Close document",uimanager.getIcon("emblem-unreadable")); |
160 |
menuItem_close.addActionListener(new ActionListener(){ |
161 |
public void actionPerformed(ActionEvent e) { |
162 |
closeScriptingBaseScript(); |
163 |
} |
164 |
}); |
165 |
menu_file.add(menuItem_close); |
166 |
JMenuItem menuItem_closeAll = new JMenuItem("Close all documents",uimanager.getIcon("emblem-unreadable")); |
167 |
menuItem_closeAll.addActionListener(new ActionListener(){ |
168 |
public void actionPerformed(ActionEvent e) { |
169 |
closeAllScriptingBaseScript(); |
170 |
} |
171 |
}); |
172 |
menu_file.add(menuItem_closeAll); |
173 |
menu_file.addSeparator(); |
174 |
JMenuItem menuItem_run = new JMenuItem("Run",uimanager.getIcon("applications-system")); |
175 |
menuItem_run.addActionListener(new ActionListener(){ |
176 |
public void actionPerformed(ActionEvent e) { |
177 |
runScriptingBaseScript(); |
178 |
} |
179 |
}); |
180 |
menu_file.add(menuItem_run); |
181 |
menu_file.addSeparator(); |
182 |
JMenuItem menuItem_save = new JMenuItem("Save",uimanager.getIcon("media-floppy")); |
183 |
menuItem_save.addActionListener(new ActionListener(){ |
184 |
public void actionPerformed(ActionEvent e) { |
185 |
saveScriptingBaseScript(); |
186 |
} |
187 |
}); |
188 |
menu_file.add(menuItem_save); |
189 |
menu_file.addSeparator(); |
190 |
JMenuItem menuItem_exit = new JMenuItem("Close",uimanager.getIcon("system-log-out")); |
191 |
menuItem_exit.addActionListener(new ActionListener(){ |
192 |
public void actionPerformed(ActionEvent e) { |
193 |
closeAllScriptingBaseScript(); |
194 |
if(defaultActionlistener!=null){ |
195 |
ActionEvent event = new ActionEvent(this,CLOSE_ACTION,"close"); |
196 |
defaultActionlistener.actionPerformed(event); |
197 |
} |
198 |
|
199 |
} |
200 |
}); |
201 |
menu_file.add(menuItem_exit); |
202 |
|
203 |
JMenu menu_edit = new JMenu("Edit"); |
204 |
JMenuItem menuItem_cut = new JMenuItem("cut",uimanager.getIcon("edit-cut")); |
205 |
menuItem_cut.addActionListener(new ActionListener(){ |
206 |
public void actionPerformed(ActionEvent e) { |
207 |
cutScriptingBaseScript(); |
208 |
} |
209 |
}); |
210 |
menu_edit.add(menuItem_cut); |
211 |
JMenuItem menuItem_copy = new JMenuItem("copy",uimanager.getIcon("edit-copy")); |
212 |
menuItem_copy.addActionListener(new ActionListener(){ |
213 |
public void actionPerformed(ActionEvent e) { |
214 |
copyScriptingBaseScript(); |
215 |
} |
216 |
}); |
217 |
menu_edit.add(menuItem_copy); |
218 |
JMenuItem menuItem_paste = new JMenuItem("paste",uimanager.getIcon("edit-paste")); |
219 |
menuItem_paste.addActionListener(new ActionListener(){ |
220 |
public void actionPerformed(ActionEvent e) { |
221 |
pasteScriptingBaseScript(); |
222 |
} |
223 |
}); |
224 |
menu_edit.add(menuItem_paste); |
225 |
menu_edit.addSeparator(); |
226 |
JMenuItem menuItem_selectAll = new JMenuItem("select all",uimanager.getIcon("edit-select-all")); |
227 |
menuItem_selectAll.addActionListener(new ActionListener(){ |
228 |
public void actionPerformed(ActionEvent e) { |
229 |
selectAllScriptingBaseScript(); |
230 |
} |
231 |
}); |
232 |
menu_edit.add(menuItem_selectAll); |
233 |
|
234 |
JMenu menu_tools = new JMenu("Tools"); |
235 |
JMenuItem menuItem_launcher = new JMenuItem("Launcher"); |
236 |
menuItem_launcher.addActionListener(new ActionListener(){ |
237 |
public void actionPerformed(ActionEvent e) { |
238 |
getWindowManager().showWindow(uimanager.createLauncher(), "Scripting Launcher", WindowManager.MODE.TOOL);
|
239 |
} |
240 |
}); |
241 |
menu_tools.add(menuItem_launcher); |
242 |
|
243 |
|
244 |
JMenu menu_help = new JMenu("Help"); |
245 |
JMenuItem menuItem_import = new JMenuItem("Import JavaDoc",uimanager.getIcon("list-add")); |
246 |
menuItem_import.addActionListener(new ActionListener(){ |
247 |
public void actionPerformed(ActionEvent e) { |
248 |
getWindowManager().showWindow(getImportHelpDialog(), "JavaDoc", WindowManager.MODE.WINDOW);
|
249 |
} |
250 |
}); |
251 |
menu_help.add(menuItem_import); |
252 |
JMenuItem menuItem_remove = new JMenuItem("Remove JavaDoc",uimanager.getIcon("list-remove")); |
253 |
menuItem_remove.addActionListener(new ActionListener(){ |
254 |
public void actionPerformed(ActionEvent e) { |
255 |
try {
|
256 |
getRemoveHelpDialog(); |
257 |
} catch (Exception e1) { |
258 |
// TODO Auto-generated catch block
|
259 |
e1.printStackTrace(); |
260 |
} |
261 |
} |
262 |
}); |
263 |
menu_help.add(menuItem_remove); |
264 |
JMenuItem menuItem_show = new JMenuItem("Show JavaDoc",uimanager.getIcon("help-browser")); |
265 |
menuItem_show.addActionListener(new ActionListener(){ |
266 |
public void actionPerformed(ActionEvent e) { |
267 |
getWindowManager().showWindow(uimanager.getAPIHelp(), "JavaDoc", WindowManager.MODE.WINDOW);
|
268 |
} |
269 |
}); |
270 |
menu_help.add(menuItem_show); |
271 |
menu_help.addSeparator(); |
272 |
JMenuItem menuItem_about = new JMenuItem("About us",uimanager.getIcon("system-users")); |
273 |
menuItem_about.addActionListener(new ActionListener(){ |
274 |
public void actionPerformed(ActionEvent e) { |
275 |
getWindowManager().showWindow(getAboutUsDialog(), "About", WindowManager.MODE.WINDOW);
|
276 |
|
277 |
} |
278 |
}); |
279 |
menu_help.add(menuItem_about); |
280 |
JMenuItem menuItem_help = new JMenuItem("Get help",uimanager.getIcon("help-browser")); |
281 |
menuItem_help.addActionListener(new ActionListener(){ |
282 |
public void actionPerformed(ActionEvent e) { |
283 |
getWindowManager().showWindow(uimanager.getUserHelp(), "Scripting Framework Help", WindowManager.MODE.WINDOW);
|
284 |
} |
285 |
}); |
286 |
menu_help.add(menuItem_help); |
287 |
|
288 |
menuBar.add(menu_file); |
289 |
menuBar.add(menu_edit); |
290 |
menuBar.add(menu_tools); |
291 |
menuBar.add(menu_help); |
292 |
|
293 |
// Botones de acción
|
294 |
file = new JToolBar(); |
295 |
help = new JToolBar(); |
296 |
edit = new JToolBar(); |
297 |
script = new JToolBar(); |
298 |
setDefaultButtons(); |
299 |
JPanel scriptButtonsPane = new JPanel(new BorderLayout()); |
300 |
scriptButtonsPane.add(edit,BorderLayout.WEST);
|
301 |
scriptButtonsPane.add(script,BorderLayout.CENTER);
|
302 |
JPanel buttonsPane = new JPanel(new BorderLayout()); |
303 |
buttonsPane.add(file, BorderLayout.WEST);
|
304 |
buttonsPane.add(help, BorderLayout.EAST);
|
305 |
buttonsPane.add(scriptButtonsPane, BorderLayout.CENTER);
|
306 |
|
307 |
// Panel de selección de proyecto
|
308 |
JPanel launcherPane = new JPanel(new BorderLayout()); |
309 |
launcher = (DefaultJScriptingLauncher)uimanager.createLauncher(); |
310 |
launcher.addDefaultActionListener(this);
|
311 |
launcher.setPreferredSize(new Dimension(200, 450)); |
312 |
launcherButtons = new JToolBar(SwingConstants.VERTICAL); |
313 |
setLauncherPaneButtons(); |
314 |
|
315 |
launcherPane.add(launcher,BorderLayout.CENTER);
|
316 |
launcherPane.add(launcherButtons,BorderLayout.WEST);
|
317 |
|
318 |
|
319 |
// Panel de Edición
|
320 |
scriptEditors = new JTabbedPane(); |
321 |
scriptEditors.addChangeListener(new ChangeListener(){ |
322 |
public void stateChanged(ChangeEvent arg0) { |
323 |
JPanel editor = (JPanel)scriptEditors.getSelectedComponent(); |
324 |
if(scriptEditors.getSelectedIndex()==-1) |
325 |
setDefaultButtons(); |
326 |
else if(editor instanceof DefaultJDialogEditor) |
327 |
setDialogButtons(); |
328 |
else if(editor instanceof DefaultJCodeEditor) |
329 |
setScriptButtons(); |
330 |
} |
331 |
}); |
332 |
scriptEditors.setPreferredSize(new Dimension(500, 350)); |
333 |
problemsPane = new JTabbedPane(); |
334 |
|
335 |
tableData = null;
|
336 |
tableModel = new AbstractTableModel(); |
337 |
tableModel.addColumn("Description");
|
338 |
tableModel.addColumn("Resource");
|
339 |
tableModel.addColumn("Location");
|
340 |
table = new JTable(tableModel); |
341 |
table.getColumnModel().getColumn(0).setPreferredWidth(300); |
342 |
//table.setFont(new Font("Serif",Font.PLAIN,13));
|
343 |
|
344 |
table.getSelectionModel().addListSelectionListener(new RowListener());
|
345 |
table.setRowSelectionAllowed(true);
|
346 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
347 |
|
348 |
JScrollPane scrollProblems = new JScrollPane(table); |
349 |
scrollProblems.setAutoscrolls(true);
|
350 |
|
351 |
console = new JTextArea(); |
352 |
console.setFont(new Font("monospaced",Font.PLAIN,13)); |
353 |
|
354 |
JScrollPane scrollConsole = new JScrollPane(console); |
355 |
problemsPane.add("Problems", scrollProblems);
|
356 |
problemsPane.add("Console", scrollConsole);
|
357 |
problemsPane.setPreferredSize(new Dimension(450, 100)); |
358 |
problemsPane.setSelectedIndex(1);
|
359 |
|
360 |
/* Si no se desea cargar datos para que arranque con ellos,
|
361 |
* este if nunca será cierto */
|
362 |
if(!unitsEditor.isEmpty()){;
|
363 |
Iterator<JEditor> it = unitsEditor.iterator();
|
364 |
while(it.hasNext()){
|
365 |
JEditor editor = it.next(); |
366 |
editor.addDefaultActionListener(this);
|
367 |
scriptEditors.addTab(editor.getScript().getName(), editor); |
368 |
} |
369 |
} |
370 |
editionPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,scriptEditors,problemsPane); |
371 |
editionPane.setOneTouchExpandable(true);
|
372 |
|
373 |
mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,launcherPane, editionPane); |
374 |
mainPane.setOneTouchExpandable(true);
|
375 |
|
376 |
// Barra de estado
|
377 |
statusBar = new JPanel(new BorderLayout()); |
378 |
statusBarMessage = new JLabel(); |
379 |
statusBarMessage.setText("Welcome to ScriptingFramework v1.0");
|
380 |
currentLine = new JLabel(); |
381 |
currentLine.setText("Line 0:0");
|
382 |
|
383 |
statusBar.add(statusBarMessage,BorderLayout.WEST);
|
384 |
statusBar.add(currentLine,BorderLayout.EAST);
|
385 |
|
386 |
// Integracíón en el frame principal de todos los componentes
|
387 |
JPanel buttons = new JPanel(); |
388 |
buttons.setLayout( new BorderLayout() ); |
389 |
buttons.add(BorderLayout.NORTH, menuBar);
|
390 |
buttons.add(BorderLayout.SOUTH, buttonsPane);
|
391 |
|
392 |
this.setLayout(new BorderLayout()); |
393 |
this.add(BorderLayout.NORTH, buttons); |
394 |
this.add(BorderLayout.CENTER, mainPane); |
395 |
this.add(BorderLayout.SOUTH, statusBar); |
396 |
this.setPreferredSize(new Dimension(800,600)); |
397 |
} |
398 |
|
399 |
private PrintStream getConsolePrintStream() { |
400 |
if( this.consolePrintStream == null ) { |
401 |
JTextAreaOutputStream outputConsole = new JTextAreaOutputStream(console);
|
402 |
this.consolePrintStream = new PrintStream(outputConsole); |
403 |
} |
404 |
return this.consolePrintStream; |
405 |
} |
406 |
|
407 |
private class AbstractTableModel extends DefaultTableModel { |
408 |
|
409 |
/**
|
410 |
*
|
411 |
*/
|
412 |
private static final long serialVersionUID = -5314938428821653641L; |
413 |
|
414 |
@Override
|
415 |
public boolean isCellEditable(int row, int col){ |
416 |
return false; |
417 |
} |
418 |
} |
419 |
|
420 |
|
421 |
private class RowListener implements ListSelectionListener { |
422 |
public void valueChanged(ListSelectionEvent event) { |
423 |
if (event.getValueIsAdjusting()) {
|
424 |
return;
|
425 |
} |
426 |
if(!table.getSelectionModel().isSelectionEmpty()){
|
427 |
int index = table.getSelectionModel().getLeadSelectionIndex();
|
428 |
String[] lineAndColumn = ((String)table.getValueAt(index, 2)).split(":"); |
429 |
int line = -1; |
430 |
if(lineAndColumn.length>0) { |
431 |
try {
|
432 |
line = Integer.parseInt(lineAndColumn[0].trim()); |
433 |
} catch (Exception e) { |
434 |
// Do nothing
|
435 |
} |
436 |
} |
437 |
if( line >= 0 ) { |
438 |
setEditorSelection(((String)table.getValueAt(index, 1)), line); |
439 |
} |
440 |
} |
441 |
} |
442 |
} |
443 |
|
444 |
private void setEditorSelection(String name, int line){ |
445 |
for (int i=0; i<scriptEditors.getTabCount(); i++){ |
446 |
|
447 |
if(((JEditor)scriptEditors.getComponent(i)).getScript().getId().equals(name)){
|
448 |
scriptEditors.setSelectedIndex(i); |
449 |
|
450 |
JTextComponent editor = ((JCodeEditor)scriptEditors.getComponent(i)).getJTextComponent();
|
451 |
editor.requestFocusInWindow(); |
452 |
|
453 |
String code = editor.getText();
|
454 |
int lineCounter = 0; |
455 |
int initialSelection = 0; |
456 |
int finalSelection = 0; |
457 |
for(int j=0; j<code.length(); j++){ |
458 |
if (code.charAt(j) == '\n'){ |
459 |
lineCounter++; |
460 |
if(lineCounter == line-1){ |
461 |
initialSelection = j; |
462 |
} |
463 |
if(lineCounter == line || (finalSelection==0 && j==code.length()-1)){ |
464 |
finalSelection = j; |
465 |
} |
466 |
} |
467 |
} |
468 |
|
469 |
editor.select(initialSelection,finalSelection); |
470 |
} |
471 |
} |
472 |
} |
473 |
|
474 |
public void addDefaultActionListener(ActionListener actionlistener) { |
475 |
this.defaultActionlistener = actionlistener;
|
476 |
} |
477 |
|
478 |
/**
|
479 |
* Función para obtener el elemento seleccionado del Launcher
|
480 |
* @return Selected ScriptingUnit on the tree
|
481 |
*/
|
482 |
private ScriptingUnit getLauncherSelectedNode(){
|
483 |
JTabbedPane tabbed = launcher.getTabbedPane();
|
484 |
DefaultJScriptingBrowser browser = (DefaultJScriptingBrowser)tabbed.getSelectedComponent(); |
485 |
ScriptingUnit unit = browser.getSelectedNode(); |
486 |
return unit;
|
487 |
} |
488 |
|
489 |
/**
|
490 |
* Lanza el modo edición de un ScriptingBaseScript
|
491 |
* @param unit
|
492 |
*/
|
493 |
private void editSelectedNode(ScriptingUnit unit){ |
494 |
if(unit instanceof ScriptingBaseScript){ |
495 |
editUnit((ScriptingBaseScript)unit); |
496 |
} |
497 |
} |
498 |
|
499 |
/**
|
500 |
* Lanza la ejecución de un ScriptingBaseScript
|
501 |
* @param unit
|
502 |
*/
|
503 |
private void runSelectedNode(ScriptingUnit unit){ |
504 |
if(unit instanceof ScriptingBaseScript){ |
505 |
((ScriptingBaseScript)unit).run(); |
506 |
} |
507 |
} |
508 |
|
509 |
/**
|
510 |
* Funciones para obtener las botoneras en función del tipo de ScriptingBaseScript
|
511 |
* que se esté mostrando en ese momento. Está la estándar 'getDefaultButtons()' para
|
512 |
* cuando no hay ninguno, 'getScriptButtons()' con los botones característicos para
|
513 |
* el manejo de ScriptingScripts y 'getDialogButtons()' para los ScriptingDialogs.
|
514 |
* También se incluye 'getEditButtons()' con las funciones sobre la edición de texto
|
515 |
* como copiar, cortar y pegar.
|
516 |
*
|
517 |
*/
|
518 |
private void setDefaultButtons(){ |
519 |
file.removeAll(); |
520 |
edit.removeAll(); |
521 |
script.removeAll(); |
522 |
help.removeAll(); |
523 |
JButton newb = new JButton(uimanager.getIcon("document-new")); |
524 |
newb.setToolTipText("New");
|
525 |
newb.setBorderPainted(false);
|
526 |
newb.addActionListener(new ActionListener(){ |
527 |
public void actionPerformed(ActionEvent e) { |
528 |
try {
|
529 |
newScriptingBaseScript(); |
530 |
} catch (Exception e1) { |
531 |
// TODO Auto-generated catch block
|
532 |
e1.printStackTrace(); |
533 |
} |
534 |
} |
535 |
}); |
536 |
file.add(newb); |
537 |
file.repaint(); |
538 |
|
539 |
help.removeAll(); |
540 |
JButton helpb = new JButton(uimanager.getIcon("help-browser")); |
541 |
helpb.setBorderPainted(false);
|
542 |
helpb.setToolTipText("Help");
|
543 |
helpb.addActionListener(new ActionListener(){ |
544 |
public void actionPerformed(ActionEvent e) { |
545 |
uimanager.showWindow(uimanager.getAPIHelp(),"JavaDoc");
|
546 |
} |
547 |
}); |
548 |
help.add(helpb); |
549 |
help.repaint(); |
550 |
edit.setVisible(false);
|
551 |
script.setVisible(false);
|
552 |
} |
553 |
|
554 |
private void setScriptButtons(){ |
555 |
file.removeAll(); |
556 |
edit.removeAll(); |
557 |
script.removeAll(); |
558 |
setDefaultButtons(); |
559 |
|
560 |
edit.setVisible(true);
|
561 |
script.setVisible(true);
|
562 |
setEditButtons(); |
563 |
JButton close = new JButton(uimanager.getIcon("emblem-unreadable")); |
564 |
close.setBorderPainted(false);
|
565 |
close.setToolTipText("Close current tab");
|
566 |
close.addActionListener(new ActionListener(){ |
567 |
public void actionPerformed(ActionEvent e) { |
568 |
closeScriptingBaseScript(); |
569 |
} |
570 |
}); |
571 |
file.add(close); |
572 |
JButton save = new JButton(uimanager.getIcon("media-floppy")); |
573 |
save.setBorderPainted(false);
|
574 |
save.setToolTipText("Save");
|
575 |
save.addActionListener(new ActionListener(){ |
576 |
public void actionPerformed(ActionEvent e) { |
577 |
saveScriptingBaseScript(); |
578 |
} |
579 |
}); |
580 |
file.add(save); |
581 |
file.repaint(); |
582 |
|
583 |
JButton run = new JButton(uimanager.getIcon("applications-system")); |
584 |
run.setBorderPainted(false);
|
585 |
run.setToolTipText("Run");
|
586 |
run.addActionListener(new ActionListener(){ |
587 |
public void actionPerformed(ActionEvent e) { |
588 |
runScriptingBaseScript(); |
589 |
} |
590 |
}); |
591 |
script.add(run); |
592 |
script.repaint(); |
593 |
} |
594 |
|
595 |
private void setDialogButtons(){ |
596 |
script.removeAll(); |
597 |
setScriptButtons(); |
598 |
script.addSeparator(); |
599 |
JButton help = new JButton(uimanager.getIcon("help-browser")); |
600 |
help.setBorderPainted(false);
|
601 |
help.setToolTipText("Help");
|
602 |
script.add(help); |
603 |
script.repaint(); |
604 |
} |
605 |
|
606 |
private void setEditButtons(){ |
607 |
JButton cut = new JButton(uimanager.getIcon("edit-cut")); |
608 |
cut.setBorderPainted(false);
|
609 |
cut.setToolTipText("Cut");
|
610 |
cut.addActionListener(new ActionListener(){ |
611 |
public void actionPerformed(ActionEvent e) { |
612 |
cutScriptingBaseScript(); |
613 |
} |
614 |
}); |
615 |
edit.add(cut); |
616 |
JButton copy = new JButton(uimanager.getIcon("edit-copy")); |
617 |
copy.setBorderPainted(false);
|
618 |
copy.setToolTipText("Copy");
|
619 |
copy.addActionListener(new ActionListener(){ |
620 |
public void actionPerformed(ActionEvent e) { |
621 |
copyScriptingBaseScript(); |
622 |
} |
623 |
}); |
624 |
edit.add(copy); |
625 |
JButton paste = new JButton(uimanager.getIcon("edit-paste")); |
626 |
paste.setBorderPainted(false);
|
627 |
paste.setToolTipText("Paste");
|
628 |
paste.addActionListener(new ActionListener(){ |
629 |
public void actionPerformed(ActionEvent e) { |
630 |
pasteScriptingBaseScript(); |
631 |
} |
632 |
}); |
633 |
edit.add(paste); |
634 |
edit.repaint(); |
635 |
} |
636 |
|
637 |
/**
|
638 |
* Botonera con posibles acciones a realizar con el Panel Launcher
|
639 |
*
|
640 |
*/
|
641 |
private void setLauncherPaneButtons(){ |
642 |
|
643 |
JButton newb = new JButton(uimanager.getIcon("document-new")); |
644 |
newb.setBorderPainted(false);
|
645 |
newb.setToolTipText("New");
|
646 |
newb.addActionListener(new ActionListener(){ |
647 |
public void actionPerformed(ActionEvent e) { |
648 |
try {
|
649 |
newScriptingBaseScript(); |
650 |
} catch (Exception e1) { |
651 |
// TODO Auto-generated catch block
|
652 |
e1.printStackTrace(); |
653 |
} |
654 |
} |
655 |
}); |
656 |
launcherButtons.add(newb); |
657 |
JButton edit = new JButton(uimanager.getIcon("applications-accessories")); |
658 |
edit.setBorderPainted(false);
|
659 |
edit.setToolTipText("Open edition mode");
|
660 |
edit.addActionListener(new ActionListener(){ |
661 |
public void actionPerformed(ActionEvent e) { |
662 |
editSelectedNode(getLauncherSelectedNode()); |
663 |
} |
664 |
}); |
665 |
launcherButtons.add(edit); |
666 |
JButton run = new JButton(uimanager.getIcon("applications-system")); |
667 |
run.setBorderPainted(false);
|
668 |
run.setToolTipText("Run selected script");
|
669 |
run.addActionListener(new ActionListener(){ |
670 |
public void actionPerformed(ActionEvent e) { |
671 |
runSelectedNode(getLauncherSelectedNode()); |
672 |
} |
673 |
}); |
674 |
launcherButtons.add(run); |
675 |
launcherButtons.addSeparator(); |
676 |
JButton refresh = new JButton(uimanager.getIcon("view-refresh")); |
677 |
refresh.setBorderPainted(false);
|
678 |
refresh.setToolTipText("Refresh directories");
|
679 |
refresh.addActionListener(new ActionListener(){ |
680 |
public void actionPerformed(ActionEvent e) { |
681 |
launcherRefresh(); |
682 |
} |
683 |
}); |
684 |
launcherButtons.add(refresh); |
685 |
launcherButtons.addSeparator(); |
686 |
JButton rename = new JButton(uimanager.getIcon("preferences-system")); |
687 |
rename.setBorderPainted(false);
|
688 |
rename.setToolTipText("Set file properties");
|
689 |
rename.addActionListener(new ActionListener(){ |
690 |
public void actionPerformed(ActionEvent e) { |
691 |
try {
|
692 |
renameSelectedNode(getLauncherSelectedNode()); |
693 |
} catch (Exception e1) { |
694 |
// TODO Auto-generated catch block
|
695 |
e1.printStackTrace(); |
696 |
} |
697 |
} |
698 |
}); |
699 |
launcherButtons.add(rename); |
700 |
JButton move = new JButton(uimanager.getIcon("format-indent-more")); |
701 |
move.setBorderPainted(false);
|
702 |
move.setToolTipText("Move files");
|
703 |
move.addActionListener(new ActionListener(){ |
704 |
public void actionPerformed(ActionEvent e){ |
705 |
try {
|
706 |
moveSelectedNode(getLauncherSelectedNode()); |
707 |
} catch (Exception e1) { |
708 |
// TODO Auto-generated catch block
|
709 |
e1.printStackTrace(); |
710 |
} |
711 |
} |
712 |
}); |
713 |
launcherButtons.add(move); |
714 |
launcherButtons.addSeparator(); |
715 |
JButton delete = new JButton(uimanager.getIcon("user-trash")); |
716 |
delete.setBorderPainted(false);
|
717 |
delete.setToolTipText("Delete selected script");
|
718 |
delete.addActionListener(new ActionListener(){ |
719 |
public void actionPerformed(ActionEvent e) { |
720 |
deleteSelectedNode(getLauncherSelectedNode(),false);
|
721 |
} |
722 |
}); |
723 |
launcherButtons.add(delete); |
724 |
} |
725 |
|
726 |
/**
|
727 |
* Función que abre en modo edición un ScriptingBaseScript
|
728 |
* @param unit
|
729 |
*/
|
730 |
public void editUnit(ScriptingBaseScript unit){ |
731 |
JEditor panel = null;
|
732 |
if( unit instanceof ScriptingDialog ) { |
733 |
panel = new DefaultJDialogEditor(uimanager, (ScriptingDialog) unit);
|
734 |
if(panel instanceof DefaultJDialogEditor){ |
735 |
((DefaultJDialogEditor)panel).addDefaultActionListener(this);
|
736 |
} |
737 |
}else if( unit instanceof ScriptingScript ) { |
738 |
panel = new DefaultJCodeEditor(uimanager, (ScriptingScript) unit);
|
739 |
if(panel instanceof DefaultJCodeEditor){ |
740 |
((DefaultJCodeEditor)panel).addDefaultActionListener(this);
|
741 |
} |
742 |
}else{
|
743 |
JOptionPane.showMessageDialog(null, "Can't open editon view from this script type", "Info", JOptionPane.INFORMATION_MESSAGE); |
744 |
return ;
|
745 |
} |
746 |
unitsEditor.add(panel); |
747 |
|
748 |
Iterator<JEditor> it = unitsEditor.iterator();
|
749 |
while(it.hasNext()){
|
750 |
JEditor editor = it.next(); |
751 |
String title;
|
752 |
if (editor.getScript().isSaved()){
|
753 |
title = editor.getScript().getName(); |
754 |
}else{
|
755 |
title = "*"+editor.getScript().getName();
|
756 |
} |
757 |
|
758 |
scriptEditors.addTab(title, editor); |
759 |
} |
760 |
scriptEditors.setSelectedIndex(unitsEditor.size()-1);
|
761 |
editionPane.repaint(); |
762 |
file.repaint(); |
763 |
} |
764 |
|
765 |
|
766 |
/**
|
767 |
* Ventana para creación de nuevos ScriptingBaseScripts
|
768 |
* @throws Exception
|
769 |
*
|
770 |
*/
|
771 |
public void newScriptingBaseScript() throws Exception{ |
772 |
JNewScriptModel model = new JNewScriptModel(manager);
|
773 |
JDialogContent dialog = new JDialogContent(
|
774 |
uimanager, |
775 |
"document-new",
|
776 |
"New Script",
|
777 |
"Create a new Script, Dialog, Project or Folder",
|
778 |
new JNewScriptPanel(uimanager,model)
|
779 |
); |
780 |
dialog.showDialog(); |
781 |
if(model.getAction()==JNewScriptModel.ACTION_ACCEPT){
|
782 |
this.createNewScriptingBaseScript(model);
|
783 |
} |
784 |
} |
785 |
|
786 |
public void createNewScriptingBaseScript(JNewScriptModel model) throws Exception { |
787 |
model.validate(); |
788 |
ScriptingUnit unit= this.manager.createUnit(
|
789 |
model.getType(), |
790 |
manager.getFolder(new File(model.getPath())), |
791 |
model.getName()+model.getExtension() |
792 |
); |
793 |
if(unit instanceof ScriptingBaseScript){ |
794 |
this.editUnit((ScriptingBaseScript) unit);
|
795 |
} |
796 |
|
797 |
this.launcherRefresh();
|
798 |
} |
799 |
|
800 |
public JPanel getImportHelpDialog(){ |
801 |
return new JDialogContent(uimanager, "list-add","Import JavaDoc","Insert JavaDocs from system directories to the ScriptingFramework JavaDoc",new JImportHelp(uimanager,this)); |
802 |
} |
803 |
|
804 |
public void getRemoveHelpDialog() throws Exception{ |
805 |
JRemoveHelpModel model = new JRemoveHelpModel(manager);
|
806 |
JDialogContent dialog = new JDialogContent(
|
807 |
uimanager, |
808 |
"list-remove",
|
809 |
"Remove JavaDoc",
|
810 |
"Remove JavaDocs from the ScriptingFramework JavaDoc",
|
811 |
new JRemoveHelpPanel(uimanager,model));
|
812 |
dialog.showDialog(); |
813 |
if(model.getAction()==JNewScriptModel.ACTION_ACCEPT){
|
814 |
this.removeHelps(model);
|
815 |
} |
816 |
} |
817 |
|
818 |
public void removeHelps(JRemoveHelpModel model) throws Exception { |
819 |
model.validate(); |
820 |
Object[] helps = model.getHelps(); |
821 |
for (int i=0;i<helps.length;i++){ |
822 |
this.manager.getHelpManager().removeHelp(helps[i].toString());
|
823 |
} |
824 |
//Recargar JavaHelp
|
825 |
this.manager.getHelpManager().reloadHelp();
|
826 |
JOptionPane.showMessageDialog(null, "Deleting JavaDocs successfully", "Info", JOptionPane.INFORMATION_MESSAGE); |
827 |
uimanager.showWindow(uimanager.getAPIHelp(),"JavaDoc");
|
828 |
} |
829 |
|
830 |
public void moveSelectedNode(final ScriptingUnit unit) throws Exception{ |
831 |
if (unit.getParent()==null){ |
832 |
JOptionPane.showMessageDialog(null, "Please, select first the file to move on the tree directory", "Error", JOptionPane.ERROR_MESSAGE); |
833 |
}else{
|
834 |
JMoveScriptModel model = new JMoveScriptModel(manager,unit);
|
835 |
JDialogContent dialog = new JDialogContent(
|
836 |
uimanager, |
837 |
"format-indent-more",
|
838 |
"Move '"+unit.getName()+ "' script", |
839 |
"Change the location of the selected script",
|
840 |
new JMoveScriptPanel(uimanager,model)
|
841 |
); |
842 |
dialog.showDialog(); |
843 |
if(model.getAction()==JMoveScriptModel.ACTION_ACCEPT){
|
844 |
this.moveScriptingUnitScript(model);
|
845 |
} |
846 |
} |
847 |
|
848 |
} |
849 |
|
850 |
public void moveScriptingUnitScript(JMoveScriptModel model) throws Exception { |
851 |
model.validate(); |
852 |
ScriptingFolder folderDest = manager.getFolder(new File(model.getMoveTo())); |
853 |
if(model.getUnit().move(folderDest)){
|
854 |
JOptionPane.showMessageDialog(null, "File moved succesfully.", "Info", JOptionPane.INFORMATION_MESSAGE); |
855 |
this.launcherRefresh();
|
856 |
}else{
|
857 |
JOptionPane.showMessageDialog(null, "Unexpected error moving the file", "Error", JOptionPane.ERROR_MESSAGE); |
858 |
} |
859 |
} |
860 |
|
861 |
public void renameSelectedNode(final ScriptingUnit unit) throws Exception{ |
862 |
if (unit.getParent()==null){ |
863 |
JOptionPane.showMessageDialog(null, "Please, select first the file to move on the tree directory", "Error", JOptionPane.ERROR_MESSAGE); |
864 |
}else{
|
865 |
JRenameModel model = new JRenameModel(manager,unit);
|
866 |
JDialogContent dialog = new JDialogContent(
|
867 |
uimanager, |
868 |
"preferences-system",
|
869 |
"Rename files of '"+unit.getName()+ "' script on the filesystem", |
870 |
"Change the filenames of the selected script and other properties",
|
871 |
new JRenamePanel(uimanager,model)
|
872 |
); |
873 |
dialog.showDialog(); |
874 |
if(model.getAction()==JRenameModel.ACTION_ACCEPT){
|
875 |
this.renameScriptingUnitScript(model);
|
876 |
} |
877 |
} |
878 |
} |
879 |
|
880 |
public void renameScriptingUnitScript(JRenameModel model) throws Exception { |
881 |
model.validate(); |
882 |
ScriptingUnit unit = model.getUnit(); |
883 |
if (!model.getNewName().equals(unit.getId())){
|
884 |
if(unit.rename(model.getNewName())){
|
885 |
JOptionPane.showMessageDialog(null, "Rename succesfully", "Info", JOptionPane.INFORMATION_MESSAGE); |
886 |
this.launcherRefresh();
|
887 |
}else{
|
888 |
JOptionPane.showMessageDialog(null, "Unexpected error renaming the file", "Error", JOptionPane.ERROR_MESSAGE); |
889 |
} |
890 |
if(unit instanceof ScriptingScript){ |
891 |
((ScriptingScript)unit).save(); |
892 |
} |
893 |
} |
894 |
} |
895 |
|
896 |
@Override
|
897 |
public JPanel getAboutUsDialog(){ |
898 |
return new JDialogContent(uimanager, "system-users","About us","Information about the contributors to gvSIG project",new JDefaultDialog(uimanager,this,uimanager.getAboutManager().getAboutPanel())); |
899 |
} |
900 |
|
901 |
|
902 |
public void deleteSelectedNode(final ScriptingUnit unit, boolean isRecursive){ |
903 |
int n = 0; |
904 |
if(!isRecursive){
|
905 |
n=JOptionPane.showConfirmDialog(
|
906 |
this.getRootPane(),
|
907 |
"Are you sure?\nAll the contents will be deleted too.",
|
908 |
"Delete this Unit and all the contents",
|
909 |
JOptionPane.YES_NO_OPTION);
|
910 |
} |
911 |
if (n==0){ |
912 |
//Si es un folder borramos recursivamente sus subdirectorios
|
913 |
if(unit instanceof ScriptingFolder){ |
914 |
List<ScriptingUnit> subunits =
|
915 |
((ScriptingFolder) unit).getUnits(); |
916 |
Iterator<ScriptingUnit> it = subunits.iterator();
|
917 |
while(it.hasNext()){
|
918 |
ScriptingUnit subunit = it.next(); |
919 |
deleteSelectedNode(subunit, true);
|
920 |
} |
921 |
} |
922 |
// Por último borramos el nodo seleccionado
|
923 |
unit.getParent().remove(unit); |
924 |
launcherRefresh(); |
925 |
|
926 |
} |
927 |
} |
928 |
|
929 |
/**
|
930 |
* Función que cierra la pestaña de edición actual
|
931 |
*
|
932 |
*/
|
933 |
public void closeScriptingBaseScript(){ |
934 |
if (!unitsEditor.isEmpty()){
|
935 |
int position = scriptEditors.getSelectedIndex();
|
936 |
String title = scriptEditors.getTitleAt(position);
|
937 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(position); |
938 |
int respuesta=1; |
939 |
if(!pestanaEditor.getScript().isSaved()){
|
940 |
respuesta = JOptionPane.showConfirmDialog(
|
941 |
scriptEditors, |
942 |
"'" + title.substring(1)+"' has been modified. Save changes?", |
943 |
"An Inane Question",
|
944 |
JOptionPane.YES_NO_CANCEL_OPTION);
|
945 |
if(respuesta == 0) |
946 |
saveScriptingBaseScript(); |
947 |
} |
948 |
|
949 |
if(respuesta<2){ |
950 |
pestanaEditor.getScript().setSaved(true);
|
951 |
scriptEditors.remove(position); |
952 |
unitsEditor.remove(position); |
953 |
scriptEditors.repaint(); |
954 |
} |
955 |
} |
956 |
} |
957 |
|
958 |
/**
|
959 |
* Función que cierra todas las pestañas de edición abiertas
|
960 |
*
|
961 |
*/
|
962 |
public void closeAllScriptingBaseScript(){ |
963 |
boolean exit=false; |
964 |
while (!unitsEditor.isEmpty() && !exit){
|
965 |
int action=1; |
966 |
int i=0; |
967 |
boolean answered=false; |
968 |
while(i<scriptEditors.getComponentCount() && !answered){
|
969 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(i); |
970 |
if(!pestanaEditor.getScript().isSaved()){
|
971 |
action = JOptionPane.showConfirmDialog(
|
972 |
scriptEditors, |
973 |
"Some projects has been modified. Save changes?",
|
974 |
"An Inane Question",
|
975 |
JOptionPane.YES_NO_CANCEL_OPTION);
|
976 |
answered=true;
|
977 |
} |
978 |
i++; |
979 |
} |
980 |
if(action == 0){ |
981 |
for(i=0;i<scriptEditors.getComponentCount();i++){ |
982 |
scriptEditors.setSelectedIndex(i); |
983 |
saveScriptingBaseScript(); |
984 |
} |
985 |
} |
986 |
if(action < 2){ |
987 |
for(i=scriptEditors.getComponentCount()-1;i>=0;i--){ |
988 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(i); |
989 |
pestanaEditor.getScript().setSaved(true);
|
990 |
scriptEditors.setSelectedIndex(i); |
991 |
closeScriptingBaseScript(); |
992 |
} |
993 |
} else{
|
994 |
exit=true;
|
995 |
} |
996 |
|
997 |
} |
998 |
} |
999 |
|
1000 |
/**
|
1001 |
* Función que ejecuta el ScriptingBaseScript de la pestaña actual
|
1002 |
*
|
1003 |
*/
|
1004 |
public void runScriptingBaseScript(){ |
1005 |
if (!unitsEditor.isEmpty()){
|
1006 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1007 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1008 |
consoleClear(); |
1009 |
errorsClear(); |
1010 |
pestanaEditor.getScript().addObserver(this);
|
1011 |
try {
|
1012 |
ScriptingScript script = pestanaEditor.getScript(); |
1013 |
script.compile(); |
1014 |
if( script instanceof ScriptingDialog ) { |
1015 |
script.run(); |
1016 |
} else {
|
1017 |
ScriptTask task = new ScriptTask(this, script); |
1018 |
task.start(); |
1019 |
} |
1020 |
} catch (Throwable e) { |
1021 |
// Ignore it, compile and run handle errors correctlty
|
1022 |
logger.info("Can't execute dialog-", e);
|
1023 |
} |
1024 |
} |
1025 |
} |
1026 |
|
1027 |
class ScriptTask extends AbstractMonitorableTask { |
1028 |
|
1029 |
ScriptingScript script; |
1030 |
DefaultJScriptingComposer composer; |
1031 |
|
1032 |
protected ScriptTask(DefaultJScriptingComposer composer, ScriptingScript script) {
|
1033 |
super(script.getName());
|
1034 |
this.composer = composer;
|
1035 |
this.script = script;
|
1036 |
this.script.put("task",this); |
1037 |
this.script.put("taskStatus",this.getTaskStatus()); |
1038 |
} |
1039 |
|
1040 |
public void run() { |
1041 |
try {
|
1042 |
composer.consolePrintln("Running '"+ script.getName() +"'..."); |
1043 |
script.run(); |
1044 |
composer.consolePrintln("Quit '"+ script.getName() +"'"); |
1045 |
} catch (Throwable e) { |
1046 |
((SimpleTaskStatus)this.getTaskStatus()).abort();
|
1047 |
composer.consolePrintln("Aborted '"+ script.getName() +"'"); |
1048 |
} |
1049 |
} |
1050 |
} |
1051 |
|
1052 |
|
1053 |
/**
|
1054 |
* Funciones de 'cortar', 'copiar', 'pegar' y 'seleccionar todo' para los JEditors
|
1055 |
*
|
1056 |
*/
|
1057 |
public void copyScriptingBaseScript(){ |
1058 |
if (!unitsEditor.isEmpty()){
|
1059 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1060 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1061 |
pestanaEditor.getJTextComponent().copy(); |
1062 |
} |
1063 |
} |
1064 |
|
1065 |
public void cutScriptingBaseScript(){ |
1066 |
if (!unitsEditor.isEmpty()){
|
1067 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1068 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1069 |
pestanaEditor.getJTextComponent().cut(); |
1070 |
JTabbedPane tabs = (JTabbedPane)pestanaEditor.getParent(); |
1071 |
|
1072 |
String title = tabs.getTitleAt(pestanaIndex);
|
1073 |
if(title.length()>0 && !title.substring(0,1).equals("*")){ |
1074 |
tabs.setTitleAt(tabs.getSelectedIndex(), "*"+title);
|
1075 |
pestanaEditor.getScript().setSaved(false);
|
1076 |
} |
1077 |
} |
1078 |
} |
1079 |
|
1080 |
public void pasteScriptingBaseScript(){ |
1081 |
if (!unitsEditor.isEmpty()){
|
1082 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1083 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1084 |
pestanaEditor.getJTextComponent().paste(); |
1085 |
JTabbedPane tabs = (JTabbedPane)pestanaEditor.getParent(); |
1086 |
|
1087 |
String title = tabs.getTitleAt(pestanaIndex);
|
1088 |
if(title.length()>0 && !title.substring(0,1).equals("*")){ |
1089 |
tabs.setTitleAt(tabs.getSelectedIndex(), "*"+title);
|
1090 |
pestanaEditor.getScript().setSaved(false);
|
1091 |
} |
1092 |
} |
1093 |
} |
1094 |
|
1095 |
public void selectAllScriptingBaseScript(){ |
1096 |
if (!unitsEditor.isEmpty()){
|
1097 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1098 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1099 |
pestanaEditor.getJTextComponent().selectAll(); |
1100 |
} |
1101 |
} |
1102 |
|
1103 |
/**
|
1104 |
* Función para el guardado del ScriptingBaseScript de la pestaña actual
|
1105 |
*
|
1106 |
*/
|
1107 |
public void saveScriptingBaseScript(){ |
1108 |
if (!unitsEditor.isEmpty()){
|
1109 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1110 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1111 |
pestanaEditor.save(); |
1112 |
String title = scriptEditors.getTitleAt(pestanaIndex);
|
1113 |
if (title.substring(0, 1).equals("*")){ |
1114 |
scriptEditors.setTitleAt(pestanaIndex, title.substring(1));
|
1115 |
} |
1116 |
} |
1117 |
} |
1118 |
|
1119 |
/**
|
1120 |
* Actualización del Launcher
|
1121 |
*
|
1122 |
*/
|
1123 |
public void launcherRefresh(){ |
1124 |
launcher.refresh(); |
1125 |
launcher.addDefaultActionListener(this);
|
1126 |
launcher.setPreferredSize(new Dimension(200, 450)); |
1127 |
} |
1128 |
|
1129 |
/**
|
1130 |
* Función para indicar la posición del cursor en un JEditor
|
1131 |
* @param line
|
1132 |
* @param column
|
1133 |
*/
|
1134 |
public void setEditorCursorPosition(int line, int column){ |
1135 |
if (line==0 && column ==0) |
1136 |
currentLine.setText("");
|
1137 |
else
|
1138 |
currentLine.setText("Line "+line+":"+column); |
1139 |
statusBar.repaint(); |
1140 |
} |
1141 |
|
1142 |
/**
|
1143 |
* Función para la actualización del mensaje de la barra de estado
|
1144 |
* @param message
|
1145 |
*/
|
1146 |
public void setMessage(String message){ |
1147 |
statusBarMessage.setText(message); |
1148 |
statusBar.repaint(); |
1149 |
} |
1150 |
|
1151 |
/**
|
1152 |
* Función para la actualización del mensaje de la barra de estado un tiempo limitado
|
1153 |
* @param message
|
1154 |
* @param seconds
|
1155 |
*/
|
1156 |
public void setMessage(String message, int seconds){ |
1157 |
setMessage(message); |
1158 |
} |
1159 |
|
1160 |
/**
|
1161 |
*
|
1162 |
*/
|
1163 |
public void actionPerformed(ActionEvent e) { |
1164 |
|
1165 |
if(e instanceof UpdateCaretPositionActionEvent){ |
1166 |
UpdateCaretPositionActionEvent e2 = (UpdateCaretPositionActionEvent) e; |
1167 |
|
1168 |
if( e2.hasLineAndColumn() ) {
|
1169 |
setEditorCursorPosition(e2.getLine(),e2.getColumn()); |
1170 |
}else{
|
1171 |
setEditorCursorPosition(0,0); |
1172 |
} |
1173 |
}else if (e instanceof LauncherActionEvent){ |
1174 |
LauncherActionEvent e2 = (LauncherActionEvent) e; |
1175 |
|
1176 |
switch(e.getID()){
|
1177 |
case JScriptingBrowser.DEFAULT_ACTION:
|
1178 |
editUnit(e2.getScript()); |
1179 |
break;
|
1180 |
case JScriptingBrowser.DROPDOWN_ACTION:
|
1181 |
case JScriptingBrowser.SELECTION_ACTION:
|
1182 |
|
1183 |
break;
|
1184 |
} |
1185 |
} |
1186 |
} |
1187 |
|
1188 |
/**
|
1189 |
* Clase empleada para crear un objeto JTextArea que hereda
|
1190 |
* de OutputStream en el que volcar las salidas estándar.
|
1191 |
*/
|
1192 |
|
1193 |
public class JTextAreaOutputStream extends OutputStream { |
1194 |
JTextArea ta;
|
1195 |
|
1196 |
public JTextAreaOutputStream(JTextArea t) { |
1197 |
super();
|
1198 |
ta = t; |
1199 |
} |
1200 |
|
1201 |
@Override
|
1202 |
public void write(int i) { |
1203 |
ta.append(Character.toString((char)i)); |
1204 |
} |
1205 |
|
1206 |
public void write(char[] buf, int off, int len) { |
1207 |
String s = new String(buf, off, len); |
1208 |
ta.append(s); |
1209 |
} |
1210 |
} |
1211 |
|
1212 |
public void update(final Observable observable, final Object notification) { |
1213 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1214 |
SwingUtilities.invokeLater(new Runnable() { |
1215 |
public void run() { |
1216 |
update(observable,notification); |
1217 |
} |
1218 |
}); |
1219 |
return;
|
1220 |
} |
1221 |
if(notification instanceof ScriptingNotification){ |
1222 |
ScriptingNotification e= (ScriptingNotification) notification; |
1223 |
|
1224 |
if(e.getException() instanceof CompileErrorException){ |
1225 |
CompileErrorException ce = (CompileErrorException) e.getException(); |
1226 |
errorsAdd(ce.getMessage(), ce.getScriptName(), ce.getLineNumber(), ce.getColumnNumber()) ; |
1227 |
|
1228 |
} else if(e.getException() instanceof ExecuteErrorException){ |
1229 |
ExecuteErrorException ee = (ExecuteErrorException) e.getException(); |
1230 |
errorsAdd(ee.getMessage(), ee.getScriptName(), ee.getLineNumber(), ee.getColumnNumber()) ; |
1231 |
consolePrintln(ee.getMessage()); |
1232 |
ee.printStackTrace(this.getConsolePrintStream());
|
1233 |
|
1234 |
} else {
|
1235 |
Throwable ex = e.getException();
|
1236 |
errorsAdd(ex.getMessage()) ; |
1237 |
consolePrintln(ex.getMessage()); |
1238 |
ex.printStackTrace(this.getConsolePrintStream());
|
1239 |
} |
1240 |
} |
1241 |
} |
1242 |
|
1243 |
public void errorsAdd(final String description, final String resource, final int line, final int column) { |
1244 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1245 |
SwingUtilities.invokeLater(new Runnable() { |
1246 |
public void run() { |
1247 |
errorsAdd(description, resource, line, column); |
1248 |
} |
1249 |
}); |
1250 |
return;
|
1251 |
} |
1252 |
String location1;
|
1253 |
if( line < 0 ) { |
1254 |
location1 = "(no line)";
|
1255 |
} else if( column < 0) { |
1256 |
location1 = String.valueOf(line);
|
1257 |
} else {
|
1258 |
location1 = String.valueOf(line)+":"+String.valueOf(column); |
1259 |
} |
1260 |
Object[] rowData = {description, resource,location1}; |
1261 |
tableModel.addRow(rowData); |
1262 |
problemsPane.setSelectedIndex(0);
|
1263 |
} |
1264 |
|
1265 |
public void errorsAdd(String description, String resource) { |
1266 |
errorsAdd(description, resource, -1, -1); |
1267 |
} |
1268 |
|
1269 |
public void errorsAdd(String description) { |
1270 |
errorsAdd(description, null, -1, -1); |
1271 |
} |
1272 |
|
1273 |
public void errorsClear() { |
1274 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1275 |
SwingUtilities.invokeLater(new Runnable() { |
1276 |
public void run() { |
1277 |
errorsClear(); |
1278 |
} |
1279 |
}); |
1280 |
return;
|
1281 |
} |
1282 |
while( tableModel.getRowCount()>0) { |
1283 |
tableModel.removeRow(0);
|
1284 |
} |
1285 |
} |
1286 |
|
1287 |
public void consoleClear() { |
1288 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1289 |
SwingUtilities.invokeLater(new Runnable() { |
1290 |
public void run() { |
1291 |
consoleClear(); |
1292 |
} |
1293 |
}); |
1294 |
return;
|
1295 |
} |
1296 |
console.setText("");
|
1297 |
problemsPane.setSelectedIndex(1);
|
1298 |
} |
1299 |
|
1300 |
public void consolePrintln(final String str) { |
1301 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1302 |
SwingUtilities.invokeLater(new Runnable() { |
1303 |
public void run() { |
1304 |
consolePrintln(str); |
1305 |
} |
1306 |
}); |
1307 |
return;
|
1308 |
} |
1309 |
console.append(str); |
1310 |
console.append("\n");
|
1311 |
problemsPane.setSelectedIndex(1);
|
1312 |
} |
1313 |
|
1314 |
public void consolePrint(final String str) { |
1315 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1316 |
SwingUtilities.invokeLater(new Runnable() { |
1317 |
public void run() { |
1318 |
consolePrint(str); |
1319 |
} |
1320 |
}); |
1321 |
return;
|
1322 |
} |
1323 |
console.append(str); |
1324 |
problemsPane.setSelectedIndex(1);
|
1325 |
} |
1326 |
|
1327 |
} |