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