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 @ 478
History | View | Annotate | Download (60.9 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Dialog; |
6 |
import java.awt.Dimension; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.KeyEvent; |
10 |
import java.io.File; |
11 |
import java.io.OutputStream; |
12 |
import java.io.PrintStream; |
13 |
import java.util.Iterator; |
14 |
import java.util.LinkedHashMap; |
15 |
import java.util.List; |
16 |
import java.util.Map; |
17 |
import javax.swing.AbstractAction; |
18 |
import javax.swing.Action; |
19 |
import static javax.swing.Action.ACCELERATOR_KEY; |
20 |
import javax.swing.JButton; |
21 |
import javax.swing.JLabel; |
22 |
import javax.swing.JMenu; |
23 |
import javax.swing.JMenuBar; |
24 |
import javax.swing.JMenuItem; |
25 |
import javax.swing.JOptionPane; |
26 |
import javax.swing.JPanel; |
27 |
import javax.swing.JScrollPane; |
28 |
import javax.swing.JSplitPane; |
29 |
import javax.swing.JTabbedPane; |
30 |
import javax.swing.JTable; |
31 |
import javax.swing.JTextArea; |
32 |
import javax.swing.JToolBar; |
33 |
import javax.swing.KeyStroke; |
34 |
import javax.swing.ListSelectionModel; |
35 |
import javax.swing.SwingConstants; |
36 |
import javax.swing.SwingUtilities; |
37 |
import javax.swing.UIManager; |
38 |
import javax.swing.event.ChangeEvent; |
39 |
import javax.swing.event.ChangeListener; |
40 |
import javax.swing.event.ListSelectionEvent; |
41 |
import javax.swing.event.ListSelectionListener; |
42 |
import javax.swing.table.DefaultTableModel; |
43 |
import javax.swing.text.BadLocationException; |
44 |
import javax.swing.text.JTextComponent; |
45 |
import org.fife.rsta.ui.GoToDialog; |
46 |
import org.fife.rsta.ui.search.FindDialog; |
47 |
import org.fife.rsta.ui.search.ReplaceDialog; |
48 |
import org.fife.rsta.ui.search.SearchEvent; |
49 |
import org.fife.rsta.ui.search.SearchListener; |
50 |
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; |
51 |
import org.fife.ui.rtextarea.SearchContext; |
52 |
import org.fife.ui.rtextarea.SearchEngine; |
53 |
import org.fife.ui.rtextarea.SearchResult; |
54 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
55 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
56 |
import org.gvsig.installer.swing.api.packagebuilder.PackageBuildder; |
57 |
import org.gvsig.scripting.CompileErrorException; |
58 |
import org.gvsig.scripting.ExecuteErrorException; |
59 |
import org.gvsig.scripting.ScriptingBaseScript; |
60 |
import org.gvsig.scripting.ScriptingDialog; |
61 |
import org.gvsig.scripting.ScriptingFolder; |
62 |
import org.gvsig.scripting.ScriptingManager; |
63 |
import org.gvsig.scripting.ScriptingNotification; |
64 |
import org.gvsig.scripting.ScriptingScript; |
65 |
import org.gvsig.scripting.ScriptingUnit; |
66 |
import org.gvsig.scripting.swing.api.JCodeEditor; |
67 |
import org.gvsig.scripting.swing.api.JEditor; |
68 |
import org.gvsig.scripting.swing.api.JScriptingBrowser; |
69 |
import org.gvsig.scripting.swing.api.JScriptingComposer; |
70 |
import org.gvsig.scripting.swing.api.JScriptingConsole; |
71 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
72 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent.UpdateCaretPositionActionEvent; |
73 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingBrowser; |
74 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingConsole; |
75 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher; |
76 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher.LauncherActionEvent; |
77 |
import org.gvsig.scripting.swing.impl.DefaultScriptingUIManager; |
78 |
import org.gvsig.scripting.swing.impl.JDialogContent; |
79 |
import org.gvsig.tools.ToolsLocator; |
80 |
import org.gvsig.tools.i18n.I18nManager; |
81 |
import org.gvsig.tools.observer.Observable; |
82 |
import org.gvsig.tools.observer.Observer; |
83 |
import org.gvsig.tools.packageutils.PackageInfo; |
84 |
import org.gvsig.tools.packageutils.PackageManager; |
85 |
import org.gvsig.tools.packageutils.Version; |
86 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
87 |
import org.slf4j.Logger; |
88 |
import org.slf4j.LoggerFactory; |
89 |
|
90 |
public class DefaultJScriptingComposer extends JScriptingComposer implements Observer, ActionListener, SearchListener { |
91 |
|
92 |
|
93 |
private class GoToLineAction extends AbstractAction { |
94 |
|
95 |
public GoToLineAction() {
|
96 |
super("Go To Line..."); |
97 |
int c = getToolkit().getMenuShortcutKeyMask();
|
98 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L, c)); |
99 |
} |
100 |
|
101 |
public void actionPerformed(ActionEvent e) { |
102 |
|
103 |
RSyntaxTextArea textArea = getCurrentRSyntaxTextArea(); |
104 |
if (textArea == null) { |
105 |
return;
|
106 |
} |
107 |
|
108 |
if (findDialog.isVisible()) {
|
109 |
findDialog.setVisible(false);
|
110 |
} |
111 |
if (replaceDialog.isVisible()) {
|
112 |
replaceDialog.setVisible(false);
|
113 |
} |
114 |
gotoDialog.setMaxLineNumberAllowed(textArea.getLineCount()); |
115 |
gotoDialog.setVisible(true);
|
116 |
int line = gotoDialog.getLineNumber();
|
117 |
if (line > 0) { |
118 |
try {
|
119 |
textArea.setCaretPosition(textArea.getLineStartOffset(line - 1));
|
120 |
} catch (BadLocationException ble) { // Never happens |
121 |
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
|
122 |
ble.printStackTrace(); |
123 |
} |
124 |
} |
125 |
} |
126 |
} |
127 |
|
128 |
private class ShowFindDialogAction extends AbstractAction { |
129 |
|
130 |
public ShowFindDialogAction() {
|
131 |
super("Find..."); |
132 |
int c = getToolkit().getMenuShortcutKeyMask();
|
133 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, c)); |
134 |
} |
135 |
|
136 |
public void actionPerformed(ActionEvent e) { |
137 |
if (replaceDialog.isVisible()) {
|
138 |
replaceDialog.setVisible(false);
|
139 |
} |
140 |
findDialog.setVisible(true);
|
141 |
} |
142 |
} |
143 |
|
144 |
private class ShowReplaceDialogAction extends AbstractAction { |
145 |
|
146 |
public ShowReplaceDialogAction() {
|
147 |
super("Replace..."); |
148 |
int c = getToolkit().getMenuShortcutKeyMask();
|
149 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, c)); |
150 |
} |
151 |
|
152 |
public void actionPerformed(ActionEvent e) { |
153 |
if (findDialog.isVisible()) {
|
154 |
findDialog.setVisible(false);
|
155 |
} |
156 |
replaceDialog.setVisible(true);
|
157 |
} |
158 |
} |
159 |
|
160 |
private class LauncherAction extends AbstractAction { |
161 |
|
162 |
public LauncherAction() {
|
163 |
super(uimanager.getTranslation("Launcher")); |
164 |
} |
165 |
|
166 |
@Override
|
167 |
public void actionPerformed(ActionEvent e) { |
168 |
getWindowManager().showWindow( |
169 |
uimanager.createLauncher(), |
170 |
uimanager.getTranslation("Scripting_Launcher"),
|
171 |
WindowManager.MODE.TOOL |
172 |
); |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
private class SelectAllAction extends AbstractAction { |
178 |
|
179 |
public SelectAllAction() {
|
180 |
super(uimanager.getTranslation("Select_all")); |
181 |
putValue(Action.SMALL_ICON, uimanager.getIcon("edit-select-all")); |
182 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Select_all")); |
183 |
} |
184 |
|
185 |
@Override
|
186 |
public void actionPerformed(ActionEvent e) { |
187 |
currentScriptSelectAll(); |
188 |
} |
189 |
|
190 |
} |
191 |
|
192 |
private class PackageScriptAction extends AbstractAction { |
193 |
|
194 |
public PackageScriptAction() {
|
195 |
super(uimanager.getTranslation("_Package_script")); |
196 |
} |
197 |
|
198 |
@Override
|
199 |
public void actionPerformed(ActionEvent e) { |
200 |
createScriptPackage(); |
201 |
} |
202 |
|
203 |
} |
204 |
|
205 |
private class ImportJavadocAction extends AbstractAction { |
206 |
|
207 |
public ImportJavadocAction() {
|
208 |
super(uimanager.getTranslation("Import_JavaDoc")); |
209 |
putValue(Action.SMALL_ICON, uimanager.getIcon("list-add")); |
210 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Import_JavaDoc")); |
211 |
} |
212 |
|
213 |
@Override
|
214 |
public void actionPerformed(ActionEvent e) { |
215 |
getWindowManager().showWindow( |
216 |
getImportHelpDialog(), |
217 |
uimanager.getTranslation("JavaDoc"),
|
218 |
WindowManager.MODE.WINDOW |
219 |
); |
220 |
} |
221 |
|
222 |
} |
223 |
|
224 |
private class RemoveHelpAction extends AbstractAction { |
225 |
|
226 |
public RemoveHelpAction() {
|
227 |
super(uimanager.getTranslation("Remove_help")); |
228 |
putValue(Action.SMALL_ICON, uimanager.getIcon("list-remove")); |
229 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Remove_JavaDoc")); |
230 |
} |
231 |
|
232 |
@Override
|
233 |
public void actionPerformed(ActionEvent e) { |
234 |
try {
|
235 |
//getRemoveHelpDialog();
|
236 |
JOptionPane.showMessageDialog(
|
237 |
DefaultJScriptingComposer.this, |
238 |
"Falta por implementar",
|
239 |
"Warning",
|
240 |
JOptionPane.INFORMATION_MESSAGE
|
241 |
); |
242 |
} catch (Exception e1) { |
243 |
logger.warn("Can't remove help",e1);
|
244 |
} |
245 |
} |
246 |
|
247 |
} |
248 |
|
249 |
private class HelpAction extends AbstractAction { |
250 |
|
251 |
public HelpAction() {
|
252 |
super(uimanager.getTranslation("Help_contents")); |
253 |
int c = getToolkit().getMenuShortcutKeyMask();
|
254 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F1, c)); |
255 |
putValue(Action.SMALL_ICON, uimanager.getIcon("help-browser")); |
256 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Help_contents")); |
257 |
|
258 |
} |
259 |
|
260 |
@Override
|
261 |
public void actionPerformed(ActionEvent e) { |
262 |
try {
|
263 |
uimanager.showWindow( |
264 |
uimanager.getHelp(), |
265 |
uimanager.getTranslation("Help_contents")
|
266 |
); |
267 |
} catch(Exception ex) { |
268 |
logger.warn("Can't show help dialog.",ex);
|
269 |
JOptionPane.showMessageDialog(
|
270 |
DefaultJScriptingComposer.this, |
271 |
uimanager.getTranslation("_Cant_show_help_dialog")
|
272 |
+ "\n\n"
|
273 |
+ uimanager.getTranslation("_See_the_error_log_for_more_information"),
|
274 |
"_Warning",
|
275 |
JOptionPane.WARNING_MESSAGE
|
276 |
); |
277 |
} |
278 |
} |
279 |
|
280 |
} |
281 |
|
282 |
private class AboutAction extends AbstractAction { |
283 |
|
284 |
public AboutAction() {
|
285 |
super(uimanager.getTranslation("About_scripts_editor")); |
286 |
putValue(Action.SMALL_ICON, uimanager.getIcon("system-users")); |
287 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("About_scripts_editor")); |
288 |
} |
289 |
|
290 |
@Override
|
291 |
public void actionPerformed(ActionEvent e) { |
292 |
getWindowManager().showWindow( |
293 |
getAboutUsDialog(), |
294 |
uimanager.getTranslation("About_scripts_editor"),
|
295 |
WindowManager.MODE.WINDOW |
296 |
); |
297 |
} |
298 |
|
299 |
} |
300 |
|
301 |
private class CutAction extends AbstractAction { |
302 |
|
303 |
public CutAction() {
|
304 |
super(uimanager.getTranslation("Cut")); |
305 |
putValue(Action.SMALL_ICON, uimanager.getIcon("edit-cut")); |
306 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Cut")); |
307 |
} |
308 |
|
309 |
@Override
|
310 |
public void actionPerformed(ActionEvent e) { |
311 |
currentScriptCut(); |
312 |
} |
313 |
|
314 |
} |
315 |
|
316 |
private class CopyAction extends AbstractAction { |
317 |
|
318 |
public CopyAction() {
|
319 |
super(uimanager.getTranslation("Copy")); |
320 |
putValue(Action.SMALL_ICON, uimanager.getIcon("edit-copy")); |
321 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Copy")); |
322 |
} |
323 |
|
324 |
@Override
|
325 |
public void actionPerformed(ActionEvent e) { |
326 |
currentScriptCopy(); |
327 |
} |
328 |
|
329 |
} |
330 |
|
331 |
private class PasteAction extends AbstractAction { |
332 |
|
333 |
public PasteAction() {
|
334 |
super(uimanager.getTranslation("Paste")); |
335 |
putValue(Action.SMALL_ICON, uimanager.getIcon("edit-paste")); |
336 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Paste")); |
337 |
} |
338 |
|
339 |
@Override
|
340 |
public void actionPerformed(ActionEvent e) { |
341 |
currentScriptPaste(); |
342 |
} |
343 |
|
344 |
} |
345 |
|
346 |
private class ExitAction extends AbstractAction { |
347 |
|
348 |
public ExitAction() {
|
349 |
super(uimanager.getTranslation("Close")); |
350 |
putValue(Action.SMALL_ICON, uimanager.getIcon("system-log-out")); |
351 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close")); |
352 |
} |
353 |
|
354 |
@Override
|
355 |
public void actionPerformed(ActionEvent e) { |
356 |
closeAllScripts(); |
357 |
closeWindow(); |
358 |
if (defaultActionlistener != null) { |
359 |
ActionEvent event = new ActionEvent(this, CLOSE_ACTION, "close"); |
360 |
defaultActionlistener.actionPerformed(event); |
361 |
} |
362 |
} |
363 |
|
364 |
} |
365 |
|
366 |
private class SaveAction extends AbstractAction { |
367 |
|
368 |
public SaveAction() {
|
369 |
super(uimanager.getTranslation("Save")); |
370 |
int c = getToolkit().getMenuShortcutKeyMask();
|
371 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, c)); |
372 |
putValue(Action.SMALL_ICON, uimanager.getIcon("media-floppy")); |
373 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Save")); |
374 |
} |
375 |
|
376 |
@Override
|
377 |
public void actionPerformed(ActionEvent e) { |
378 |
currentScriptSave(); |
379 |
} |
380 |
} |
381 |
|
382 |
private class RunAction extends AbstractAction { |
383 |
|
384 |
public RunAction() {
|
385 |
super(uimanager.getTranslation("Run")); |
386 |
int c = getToolkit().getMenuShortcutKeyMask();
|
387 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F5, c)); |
388 |
putValue(Action.SMALL_ICON, uimanager.getIcon("applications-system")); |
389 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Run")); |
390 |
} |
391 |
|
392 |
@Override
|
393 |
public void actionPerformed(ActionEvent e) { |
394 |
currentScriptExecute(); |
395 |
} |
396 |
|
397 |
} |
398 |
|
399 |
private class CloseAllAction extends AbstractAction { |
400 |
|
401 |
public CloseAllAction() {
|
402 |
super(uimanager.getTranslation("Close_all_documents")); |
403 |
putValue(Action.SMALL_ICON, uimanager.getIcon("emblem-unreadable")); |
404 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close_all_documents")); |
405 |
} |
406 |
|
407 |
@Override
|
408 |
public void actionPerformed(ActionEvent e) { |
409 |
closeAllScripts(); |
410 |
} |
411 |
|
412 |
} |
413 |
|
414 |
private class CloseDocumentAction extends AbstractAction { |
415 |
|
416 |
public CloseDocumentAction() {
|
417 |
super(uimanager.getTranslation("Close_document")); |
418 |
putValue(Action.SMALL_ICON, uimanager.getIcon("emblem-unreadable")); |
419 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close_current_tab")); |
420 |
} |
421 |
|
422 |
@Override
|
423 |
public void actionPerformed(ActionEvent e) { |
424 |
currentScriptClose(); |
425 |
} |
426 |
|
427 |
} |
428 |
|
429 |
private class NewDocumentAction extends AbstractAction { |
430 |
|
431 |
public NewDocumentAction() {
|
432 |
super(uimanager.getTranslation("New")); |
433 |
putValue(Action.SMALL_ICON, uimanager.getIcon("document-new")); |
434 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("New")); |
435 |
} |
436 |
|
437 |
@Override
|
438 |
public void actionPerformed(ActionEvent e) { |
439 |
try {
|
440 |
scriptNew(); |
441 |
} catch (Exception e1) { |
442 |
logger.warn("Can't create a new document",e1);
|
443 |
} |
444 |
} |
445 |
|
446 |
} |
447 |
|
448 |
private class EditAction extends AbstractAction { |
449 |
|
450 |
public EditAction() {
|
451 |
super(uimanager.getTranslation("Edit")); |
452 |
putValue(Action.SMALL_ICON, uimanager.getIcon("applications-accessories")); |
453 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Open_edition_mode")); |
454 |
} |
455 |
|
456 |
@Override
|
457 |
public void actionPerformed(ActionEvent e) { |
458 |
try {
|
459 |
scriptEdit((ScriptingBaseScript)getLauncherSelectedScript()); |
460 |
} catch (Exception e1) { |
461 |
logger.warn("Can't edit document",e1);
|
462 |
} |
463 |
} |
464 |
} |
465 |
|
466 |
private class RefreshTreeAction extends AbstractAction { |
467 |
|
468 |
public RefreshTreeAction() {
|
469 |
super(uimanager.getTranslation("Refresh")); |
470 |
putValue(Action.SMALL_ICON, uimanager.getIcon("view-refresh")); |
471 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Refresh_directories")); |
472 |
} |
473 |
|
474 |
@Override
|
475 |
public void actionPerformed(ActionEvent e) { |
476 |
launcherRefresh(); |
477 |
} |
478 |
|
479 |
} |
480 |
|
481 |
private class RenameAction extends AbstractAction { |
482 |
|
483 |
public RenameAction() {
|
484 |
super(uimanager.getTranslation("Rename")); |
485 |
putValue(Action.SMALL_ICON, uimanager.getIcon("preferences-system")); |
486 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Set_file_properties")); |
487 |
} |
488 |
|
489 |
@Override
|
490 |
public void actionPerformed(ActionEvent e) { |
491 |
try {
|
492 |
scriptRename(getLauncherSelectedScript()); |
493 |
} catch (Exception e1) { |
494 |
logger.warn("Can't rename document",e1);
|
495 |
} |
496 |
} |
497 |
} |
498 |
|
499 |
private class MoveAction extends AbstractAction { |
500 |
|
501 |
public MoveAction() {
|
502 |
super(uimanager.getTranslation("Move")); |
503 |
putValue(Action.SMALL_ICON, uimanager.getIcon("format-indent-more")); |
504 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Move_files")); |
505 |
} |
506 |
|
507 |
@Override
|
508 |
public void actionPerformed(ActionEvent e) { |
509 |
try {
|
510 |
scriptMove(getLauncherSelectedScript()); |
511 |
} catch (Exception e1) { |
512 |
logger.warn("Can't move document",e1);
|
513 |
} |
514 |
} |
515 |
} |
516 |
|
517 |
private class DeleteAction extends AbstractAction { |
518 |
|
519 |
public DeleteAction() {
|
520 |
super(uimanager.getTranslation("Delete")); |
521 |
putValue(Action.SMALL_ICON, uimanager.getIcon("user-trash")); |
522 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Delete_selected_script")); |
523 |
} |
524 |
|
525 |
@Override
|
526 |
public void actionPerformed(ActionEvent e) { |
527 |
try {
|
528 |
scriptDelete(getLauncherSelectedScript(), false);
|
529 |
} catch (Exception e1) { |
530 |
logger.warn("Can't delete document",e1);
|
531 |
} |
532 |
} |
533 |
} |
534 |
|
535 |
private class IndexHelpAction extends AbstractAction { |
536 |
|
537 |
public IndexHelpAction() {
|
538 |
super(uimanager.getTranslation("Index_help")); |
539 |
} |
540 |
|
541 |
@Override
|
542 |
public void actionPerformed(ActionEvent e) { |
543 |
JOptionPane.showMessageDialog(
|
544 |
DefaultJScriptingComposer.this, |
545 |
"Falta por implementar",
|
546 |
"Warning",
|
547 |
JOptionPane.INFORMATION_MESSAGE
|
548 |
); |
549 |
} |
550 |
} |
551 |
|
552 |
private class PackageHelpAction extends AbstractAction { |
553 |
|
554 |
public PackageHelpAction() {
|
555 |
super(uimanager.getTranslation("_Package_help")); |
556 |
} |
557 |
|
558 |
@Override
|
559 |
public void actionPerformed(ActionEvent e) { |
560 |
createHelpPackage(); |
561 |
} |
562 |
} |
563 |
|
564 |
/**
|
565 |
*
|
566 |
*/
|
567 |
private static final long serialVersionUID = 1L; |
568 |
|
569 |
private static final Logger logger = LoggerFactory.getLogger(DefaultJScriptingComposer.class); |
570 |
|
571 |
public static final int CLOSE_ACTION = 1; |
572 |
public Map<String, JEditor> unitsEditor; |
573 |
|
574 |
/* Generales */
|
575 |
ScriptingUIManager uimanager; |
576 |
ScriptingManager manager; |
577 |
ClassLoader loader;
|
578 |
|
579 |
/* Ventana inicial y componentes*/
|
580 |
JSplitPane mainPane;
|
581 |
JSplitPane editionPane;
|
582 |
JTabbedPane problemsPane;
|
583 |
JTabbedPane scriptEditors;
|
584 |
JMenuBar menuBar;
|
585 |
JToolBar file;
|
586 |
JToolBar edit;
|
587 |
JToolBar script;
|
588 |
JToolBar help;
|
589 |
JPanel statusBar;
|
590 |
JLabel currentLine;
|
591 |
JLabel statusBarMessage;
|
592 |
JTextArea problems;
|
593 |
JScriptingConsole console; |
594 |
DefaultJScriptingLauncher launcher; |
595 |
JToolBar launcherButtons;
|
596 |
PrintStream consolePrintStream = null; |
597 |
|
598 |
private FindDialog findDialog;
|
599 |
private ReplaceDialog replaceDialog;
|
600 |
private GoToDialog gotoDialog;
|
601 |
|
602 |
JTable table;
|
603 |
DefaultTableModel tableModel;
|
604 |
protected ActionListener defaultActionlistener = null; |
605 |
|
606 |
/**
|
607 |
* Instanciacion de un JComposer con todos sus elementos y acciones
|
608 |
*
|
609 |
* @param uimanager
|
610 |
*/
|
611 |
public DefaultJScriptingComposer(final ScriptingUIManager uimanager) { |
612 |
loader = this.getClass().getClassLoader();
|
613 |
this.uimanager = uimanager;
|
614 |
this.manager = uimanager.getManager();
|
615 |
|
616 |
unitsEditor = new LinkedHashMap<String, JEditor>(); |
617 |
|
618 |
initComponents(); |
619 |
} |
620 |
|
621 |
@Override
|
622 |
public WindowManager getWindowManager() {
|
623 |
return ((DefaultScriptingUIManager)(this.uimanager)).getWindowManager(); |
624 |
} |
625 |
|
626 |
@Override
|
627 |
public void setWindowManager(WindowManager windowsManager) { |
628 |
((DefaultScriptingUIManager)(this.uimanager)).setWindowManager(windowsManager);
|
629 |
} |
630 |
|
631 |
private void initComponents() { |
632 |
|
633 |
findDialog = new FindDialog((Dialog)null, this); |
634 |
replaceDialog = new ReplaceDialog((Dialog)null, this); |
635 |
gotoDialog = new GoToDialog((Dialog) null); |
636 |
|
637 |
SearchContext searchContext = findDialog.getSearchContext(); |
638 |
replaceDialog.setSearchContext(searchContext); |
639 |
|
640 |
// Barra de menu
|
641 |
menuBar = new JMenuBar(); |
642 |
|
643 |
// Construimos los componentes del menu
|
644 |
JMenu menu_file = new JMenu(this.uimanager.getTranslation("File")); |
645 |
menu_file.add(new JMenuItem(new NewDocumentAction())); |
646 |
menu_file.addSeparator(); |
647 |
menu_file.add(new JMenuItem(new CloseDocumentAction())); |
648 |
menu_file.add(new JMenuItem(new CloseAllAction())); |
649 |
menu_file.addSeparator(); |
650 |
menu_file.add(new JMenuItem(new RunAction())); |
651 |
menu_file.addSeparator(); |
652 |
menu_file.add(new JMenuItem(new SaveAction())); |
653 |
menu_file.addSeparator(); |
654 |
menu_file.add(new JMenuItem(new ExitAction())); |
655 |
|
656 |
JMenu menu_edit = new JMenu(this.uimanager.getTranslation("Edit")); |
657 |
menu_edit.add(new JMenuItem(new CutAction())); |
658 |
menu_edit.add(new JMenuItem(new CopyAction())); |
659 |
menu_edit.add(new JMenuItem(new PasteAction())); |
660 |
menu_edit.addSeparator(); |
661 |
menu_edit.add(new JMenuItem(new SelectAllAction())); |
662 |
menu_edit.addSeparator(); |
663 |
menu_edit.add(new JMenuItem(new ShowFindDialogAction())); |
664 |
menu_edit.add(new JMenuItem(new ShowReplaceDialogAction())); |
665 |
menu_edit.add(new JMenuItem(new GoToLineAction())); |
666 |
|
667 |
JMenu menu_tools = new JMenu(this.uimanager.getTranslation("Tools")); |
668 |
menu_tools.add(new JMenuItem(new LauncherAction())); |
669 |
menu_tools.addSeparator(); |
670 |
menu_tools.add(new JMenuItem(new PackageScriptAction())); |
671 |
menu_tools.add(new JMenuItem(new PackageHelpAction())); |
672 |
menu_tools.addSeparator(); |
673 |
|
674 |
JMenu menu_tools_javadoc = new JMenu(this.uimanager.getTranslation("Help")); |
675 |
menu_tools_javadoc.add(new JMenuItem(new RemoveHelpAction())); |
676 |
menu_tools_javadoc.add(new JMenuItem(new IndexHelpAction())); |
677 |
menu_tools_javadoc.addSeparator(); |
678 |
menu_tools_javadoc.add(new JMenuItem(new ImportJavadocAction())); |
679 |
menu_tools.add(menu_tools_javadoc); |
680 |
|
681 |
|
682 |
JMenu menu_help = new JMenu("Help"); |
683 |
menu_help.add(new JMenuItem(new HelpAction())); |
684 |
menu_help.addSeparator(); |
685 |
menu_help.add(new JMenuItem(new AboutAction())); |
686 |
|
687 |
menuBar.add(menu_file); |
688 |
menuBar.add(menu_edit); |
689 |
menuBar.add(menu_tools); |
690 |
menuBar.add(menu_help); |
691 |
|
692 |
// Botones
|
693 |
file = new JToolBar(); |
694 |
help = new JToolBar(); |
695 |
edit = new JToolBar(); |
696 |
script = new JToolBar(); |
697 |
setButtonsDefault(); |
698 |
JPanel scriptButtonsPane = new JPanel(new BorderLayout()); |
699 |
scriptButtonsPane.add(edit, BorderLayout.WEST);
|
700 |
|
701 |
scriptButtonsPane.add(script, BorderLayout.CENTER);
|
702 |
JPanel buttonsPane = new JPanel(new BorderLayout()); |
703 |
buttonsPane.add(file, BorderLayout.WEST);
|
704 |
buttonsPane.add(help, BorderLayout.EAST);
|
705 |
buttonsPane.add(scriptButtonsPane, BorderLayout.CENTER);
|
706 |
|
707 |
JPanel launcherPane = new JPanel(new BorderLayout()); |
708 |
launcher = (DefaultJScriptingLauncher) uimanager.createLauncher(); |
709 |
launcher.addDefaultActionListener(this);
|
710 |
launcher.setPreferredSize(new Dimension(200, 450)); |
711 |
launcherButtons = new JToolBar(SwingConstants.VERTICAL); |
712 |
setButtonsLauncherPanel(); |
713 |
|
714 |
launcherPane.add(launcher, BorderLayout.CENTER);
|
715 |
launcherPane.add(launcherButtons, BorderLayout.WEST);
|
716 |
|
717 |
// Panel de Edicion
|
718 |
scriptEditors = new JTabbedPane(); |
719 |
scriptEditors.addChangeListener(new ChangeListener() { |
720 |
public void stateChanged(ChangeEvent arg0) { |
721 |
JPanel editor = (JPanel) scriptEditors.getSelectedComponent(); |
722 |
if (scriptEditors.getSelectedIndex() == -1) { |
723 |
setButtonsDefault(); |
724 |
} else if (editor instanceof DefaultJDialogEditor) { |
725 |
setButtonsDialog(); |
726 |
} else if (editor instanceof DefaultJCodeEditor) { |
727 |
setButtonsScript(); |
728 |
} |
729 |
} |
730 |
}); |
731 |
scriptEditors.setPreferredSize(new Dimension(500, 350)); |
732 |
problemsPane = new JTabbedPane(); |
733 |
|
734 |
tableModel = new AbstractTableModel(); |
735 |
tableModel.addColumn(this.uimanager.getTranslation("Description")); |
736 |
tableModel.addColumn(this.uimanager.getTranslation("Resource")); |
737 |
tableModel.addColumn(this.uimanager.getTranslation("Location")); |
738 |
table = new JTable(tableModel); |
739 |
table.getColumnModel().getColumn(0).setPreferredWidth(300); |
740 |
|
741 |
table.getSelectionModel().addListSelectionListener(new RowListener());
|
742 |
table.setRowSelectionAllowed(true);
|
743 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
744 |
|
745 |
JScrollPane scrollProblems = new JScrollPane(table); |
746 |
scrollProblems.setAutoscrolls(true);
|
747 |
|
748 |
console = new DefaultJScriptingConsole();
|
749 |
|
750 |
problemsPane.add(this.uimanager.getTranslation("Problems"), scrollProblems); |
751 |
problemsPane.add(this.uimanager.getTranslation("Console"), console.asJComponent()); |
752 |
problemsPane.setPreferredSize(new Dimension(450, 100)); |
753 |
problemsPane.setSelectedIndex(1);
|
754 |
|
755 |
/* Si no se desea cargar datos para que arranque con ellos,
|
756 |
* este if nunca será cierto */
|
757 |
if (!unitsEditor.isEmpty()) {;
|
758 |
Iterator<JEditor> it = unitsEditor.values().iterator();
|
759 |
while (it.hasNext()) {
|
760 |
JEditor editor = it.next(); |
761 |
editor.addDefaultActionListener(this);
|
762 |
scriptEditors.addTab(editor.getScript().getName(), editor); |
763 |
} |
764 |
} |
765 |
editionPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptEditors, problemsPane); |
766 |
editionPane.setOneTouchExpandable(true);
|
767 |
|
768 |
mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, launcherPane, editionPane); |
769 |
mainPane.setOneTouchExpandable(true);
|
770 |
|
771 |
// Barra de estado
|
772 |
statusBar = new JPanel(new BorderLayout()); |
773 |
statusBarMessage = new JLabel(); |
774 |
statusBarMessage.setText(this.uimanager.getTranslation("Welcome_message")); |
775 |
currentLine = new JLabel(); |
776 |
currentLine.setText("Line 0:0");
|
777 |
|
778 |
statusBar.add(statusBarMessage, BorderLayout.WEST);
|
779 |
statusBar.add(currentLine, BorderLayout.EAST);
|
780 |
|
781 |
// Integracíón en el frame principal de todos los componentes
|
782 |
JPanel buttons = new JPanel(); |
783 |
buttons.setLayout(new BorderLayout()); |
784 |
buttons.add(BorderLayout.NORTH, menuBar);
|
785 |
buttons.add(BorderLayout.SOUTH, buttonsPane);
|
786 |
|
787 |
this.setLayout(new BorderLayout()); |
788 |
this.add(BorderLayout.NORTH, buttons); |
789 |
this.add(BorderLayout.CENTER, mainPane); |
790 |
this.add(BorderLayout.SOUTH, statusBar); |
791 |
this.setPreferredSize(new Dimension(800, 600)); |
792 |
} |
793 |
|
794 |
private void createScriptPackage() { |
795 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
796 |
SwingInstallerManager installerManager = SwingInstallerLocator.getSwingInstallerManager(); |
797 |
PackageBuildder packager = installerManager.createPackagerPanel( |
798 |
ScriptingManager.INSTALLER_PROVIDER_NAME, |
799 |
manager.getRootUserFolder(), |
800 |
manager.getPackagesFolder() |
801 |
); |
802 |
PackageInfo packageInfo = packager.getPackageInfo(); |
803 |
packageInfo.setArchitecture(PackageManager.ARCH.ALL); |
804 |
packageInfo.setJavaVM(PackageManager.JVM.J1_7); |
805 |
packageInfo.setOperatingSystem(PackageManager.OS.ALL); |
806 |
packageInfo.setOfficial(false);
|
807 |
packageInfo.setState(PackageManager.STATE.TESTING); |
808 |
packageInfo.setType(ScriptingManager.INSTALLER_PROVIDER_NAME); |
809 |
Version version = ToolsLocator.getPackageManager().createVersion(); |
810 |
version.parse("1.0.0");
|
811 |
packageInfo.setVersion(version); |
812 |
this.uimanager.showWindow(
|
813 |
(JPanel) packager.asJComponent(),
|
814 |
i18nManager.getTranslation("_Scripting_packager")
|
815 |
); |
816 |
} |
817 |
|
818 |
private void createHelpPackage() { |
819 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
820 |
SwingInstallerManager installerManager = SwingInstallerLocator.getSwingInstallerManager(); |
821 |
|
822 |
PackageBuildder packager = installerManager.createPackagerPanel( |
823 |
ScriptingManager.HELP_INSTALLER_PROVIDER_NAME, |
824 |
manager.getHelpManager().getHelpRoots().get(0),
|
825 |
manager.getPackagesFolder() |
826 |
); |
827 |
PackageInfo packageInfo = packager.getPackageInfo(); |
828 |
packageInfo.setArchitecture(PackageManager.ARCH.ALL); |
829 |
packageInfo.setJavaVM(PackageManager.JVM.J1_7); |
830 |
packageInfo.setOperatingSystem(PackageManager.OS.ALL); |
831 |
packageInfo.setOfficial(false);
|
832 |
packageInfo.setState(PackageManager.STATE.TESTING); |
833 |
packageInfo.setType(ScriptingManager.INSTALLER_PROVIDER_NAME); |
834 |
Version version = ToolsLocator.getPackageManager().createVersion(); |
835 |
version.parse("1.0.0");
|
836 |
packageInfo.setVersion(version); |
837 |
this.uimanager.showWindow(
|
838 |
(JPanel) packager.asJComponent(),
|
839 |
i18nManager.getTranslation("_Help_scripting_packager")
|
840 |
); |
841 |
} |
842 |
|
843 |
private class AbstractTableModel extends DefaultTableModel { |
844 |
|
845 |
/**
|
846 |
*
|
847 |
*/
|
848 |
private static final long serialVersionUID = -5314938428821653641L; |
849 |
|
850 |
@Override
|
851 |
public boolean isCellEditable(int row, int col) { |
852 |
return false; |
853 |
} |
854 |
} |
855 |
|
856 |
private class RowListener implements ListSelectionListener { |
857 |
|
858 |
public void valueChanged(ListSelectionEvent event) { |
859 |
if (event.getValueIsAdjusting()) {
|
860 |
return;
|
861 |
} |
862 |
if (!table.getSelectionModel().isSelectionEmpty()) {
|
863 |
int index = table.getSelectionModel().getLeadSelectionIndex();
|
864 |
String[] lineAndColumn = ((String) table.getValueAt(index, 2)).split(":"); |
865 |
int line = -1; |
866 |
if (lineAndColumn.length > 0) { |
867 |
try {
|
868 |
line = Integer.parseInt(lineAndColumn[0].trim()); |
869 |
} catch (Exception e) { |
870 |
// Do nothing
|
871 |
} |
872 |
} |
873 |
if (line >= 0) { |
874 |
setEditorSelection(((String) table.getValueAt(index, 1)), line); |
875 |
} |
876 |
} |
877 |
} |
878 |
} |
879 |
|
880 |
private void setEditorSelection(String name, int line) { |
881 |
for (int i = 0; i < scriptEditors.getTabCount(); i++) { |
882 |
|
883 |
if (((JEditor) scriptEditors.getComponent(i)).getScript().getId().equals(name)) {
|
884 |
scriptEditors.setSelectedIndex(i); |
885 |
|
886 |
JTextComponent editor = ((JCodeEditor) scriptEditors.getComponent(i)).getJTextComponent();
|
887 |
editor.requestFocusInWindow(); |
888 |
|
889 |
String code = editor.getText();
|
890 |
int lineCounter = 0; |
891 |
int initialSelection = 0; |
892 |
int finalSelection = 0; |
893 |
for (int j = 0; j < code.length(); j++) { |
894 |
if (code.charAt(j) == '\n') { |
895 |
lineCounter++; |
896 |
if (lineCounter == line - 1) { |
897 |
initialSelection = j; |
898 |
} |
899 |
if (lineCounter == line || (finalSelection == 0 && j == code.length() - 1)) { |
900 |
finalSelection = j; |
901 |
} |
902 |
} |
903 |
} |
904 |
|
905 |
editor.select(initialSelection, finalSelection); |
906 |
} |
907 |
} |
908 |
} |
909 |
|
910 |
public void addDefaultActionListener(ActionListener actionlistener) { |
911 |
this.defaultActionlistener = actionlistener;
|
912 |
} |
913 |
|
914 |
/**
|
915 |
* Función para obtener el elemento seleccionado del Launcher
|
916 |
*
|
917 |
* @return Selected ScriptingUnit on the tree
|
918 |
*/
|
919 |
private ScriptingUnit getLauncherSelectedScript() {
|
920 |
JTabbedPane tabbed = launcher.getTabbedPane();
|
921 |
DefaultJScriptingBrowser browser = (DefaultJScriptingBrowser) tabbed.getSelectedComponent(); |
922 |
ScriptingUnit unit = browser.getSelectedNode(); |
923 |
return unit;
|
924 |
} |
925 |
|
926 |
/**
|
927 |
* Lanza la ejecución de un ScriptingBaseScript
|
928 |
*
|
929 |
* @param unit
|
930 |
*/
|
931 |
private void scriptExecute(ScriptingUnit unit) { |
932 |
if (unit instanceof ScriptingBaseScript) { |
933 |
((ScriptingBaseScript) unit).run(); |
934 |
} |
935 |
} |
936 |
|
937 |
private JButton createButton(Action action) { |
938 |
JButton btn = new JButton(action); |
939 |
btn.setBorderPainted(false);
|
940 |
btn.setText("");
|
941 |
return btn;
|
942 |
} |
943 |
/**
|
944 |
* Funciones para obtener las botoneras en función del tipo de
|
945 |
* ScriptingBaseScript que se esté mostrando en ese momento. Está la
|
946 |
* estándar 'getDefaultButtons()' para cuando no hay ninguno,
|
947 |
* 'getScriptButtons()' con los botones característicos para el manejo de
|
948 |
* ScriptingScripts y 'getDialogButtons()' para los ScriptingDialogs.
|
949 |
* También se incluye 'getEditButtons()' con las funciones sobre la
|
950 |
* edición de texto como copiar, cortar y pegar.
|
951 |
*
|
952 |
*/
|
953 |
private void setButtonsDefault() { |
954 |
file.removeAll(); |
955 |
edit.removeAll(); |
956 |
script.removeAll(); |
957 |
help.removeAll(); |
958 |
|
959 |
file.add(createButton(new NewDocumentAction()));
|
960 |
file.repaint(); |
961 |
|
962 |
help.add(createButton(new HelpAction()));
|
963 |
help.repaint(); |
964 |
|
965 |
edit.setVisible(false);
|
966 |
script.setVisible(false);
|
967 |
} |
968 |
|
969 |
private void setButtonsScript() { |
970 |
setButtonsDefault(); |
971 |
|
972 |
edit.setVisible(true);
|
973 |
script.setVisible(true);
|
974 |
|
975 |
setButtonsEdit(); |
976 |
|
977 |
file.add(createButton(new CloseDocumentAction()));
|
978 |
file.add(createButton(new SaveAction()));
|
979 |
file.repaint(); |
980 |
|
981 |
script.add(createButton(new RunAction()));
|
982 |
script.repaint(); |
983 |
} |
984 |
|
985 |
private void setButtonsDialog() { |
986 |
setButtonsScript(); |
987 |
|
988 |
script.addSeparator(); |
989 |
script.add(createButton(new HelpAction()));
|
990 |
script.repaint(); |
991 |
} |
992 |
|
993 |
private void setButtonsEdit() { |
994 |
edit.add(createButton(new CutAction()));
|
995 |
edit.add(createButton(new CopyAction()));
|
996 |
edit.add(createButton(new PasteAction()));
|
997 |
edit.repaint(); |
998 |
} |
999 |
|
1000 |
/**
|
1001 |
* Botonera con posibles acciones a realizar con el Panel Launcher
|
1002 |
*
|
1003 |
*/
|
1004 |
private void setButtonsLauncherPanel() { |
1005 |
launcherButtons.add(createButton(new NewDocumentAction()));
|
1006 |
launcherButtons.add(createButton(new EditAction()));
|
1007 |
launcherButtons.add(createButton(new RunAction()));
|
1008 |
launcherButtons.addSeparator(); |
1009 |
launcherButtons.add(createButton(new RefreshTreeAction()));
|
1010 |
launcherButtons.addSeparator(); |
1011 |
launcherButtons.add(createButton(new RenameAction()));
|
1012 |
launcherButtons.add(createButton(new MoveAction()));
|
1013 |
launcherButtons.addSeparator(); |
1014 |
launcherButtons.add(createButton(new DeleteAction()));
|
1015 |
} |
1016 |
|
1017 |
/**
|
1018 |
* Función que abre en modo edición un ScriptingBaseScript
|
1019 |
*
|
1020 |
* @param unit
|
1021 |
*/
|
1022 |
public void scriptEdit(ScriptingBaseScript unit) { |
1023 |
if( ! unitsEditor.containsKey(unit.getFile().getAbsolutePath()) ) {
|
1024 |
JEditor panel = null;
|
1025 |
if (unit instanceof ScriptingDialog) { |
1026 |
panel = new DefaultJDialogEditor(uimanager, (ScriptingDialog) unit);
|
1027 |
if (panel instanceof DefaultJDialogEditor) { |
1028 |
((DefaultJDialogEditor) panel).addDefaultActionListener(this);
|
1029 |
} |
1030 |
} else if (unit instanceof ScriptingScript) { |
1031 |
panel = new DefaultJCodeEditor(uimanager, (ScriptingScript) unit);
|
1032 |
if (panel instanceof DefaultJCodeEditor) { |
1033 |
((DefaultJCodeEditor) panel).addDefaultActionListener(this);
|
1034 |
} |
1035 |
} else {
|
1036 |
JOptionPane.showMessageDialog(null, this.uimanager.getTranslation("Error_opening_in_edition_mode"), this.uimanager.getTranslation("Error_opening_in_edition_mode_title"), JOptionPane.INFORMATION_MESSAGE); |
1037 |
return;
|
1038 |
} |
1039 |
unitsEditor.put(unit.getFile().getAbsolutePath(), panel); |
1040 |
} |
1041 |
int n = 0; |
1042 |
int selected = unitsEditor.size() - 1; |
1043 |
Iterator<JEditor> it = unitsEditor.values().iterator();
|
1044 |
while (it.hasNext()) {
|
1045 |
JEditor editor = it.next(); |
1046 |
String title;
|
1047 |
if (editor.getScript().isSaved()) {
|
1048 |
title = editor.getScript().getName(); |
1049 |
} else {
|
1050 |
title = "*" + editor.getScript().getName();
|
1051 |
} |
1052 |
scriptEditors.addTab(title, editor); |
1053 |
if( editor.getScript().getFile().getAbsolutePath().equals(unit.getFile().getAbsolutePath()) ) {
|
1054 |
selected = n; |
1055 |
} |
1056 |
n++; |
1057 |
} |
1058 |
scriptEditors.setSelectedIndex(selected); |
1059 |
editionPane.repaint(); |
1060 |
file.repaint(); |
1061 |
} |
1062 |
|
1063 |
/**
|
1064 |
* Ventana para creación de nuevos ScriptingBaseScripts
|
1065 |
*
|
1066 |
* @throws Exception
|
1067 |
*
|
1068 |
*/
|
1069 |
public void scriptNew() throws Exception { |
1070 |
JNewScriptModel model = new JNewScriptModel(manager);
|
1071 |
JDialogContent dialog = new JDialogContent(
|
1072 |
uimanager, |
1073 |
"document-new",
|
1074 |
this.uimanager.getTranslation("New_Script"), |
1075 |
this.uimanager.getTranslation("New_Script_Description"), |
1076 |
new JNewScriptPanel(uimanager, model)
|
1077 |
); |
1078 |
dialog.showDialog(); |
1079 |
if (model.getAction() == JNewScriptModel.ACTION_ACCEPT) {
|
1080 |
model.validate(); |
1081 |
ScriptingUnit unit = this.manager.createUnit(
|
1082 |
model.getType(), |
1083 |
manager.getFolder(new File(model.getPath())), |
1084 |
model.getName(), |
1085 |
model.getLanguage() |
1086 |
); |
1087 |
if (unit instanceof ScriptingBaseScript) { |
1088 |
this.scriptEdit((ScriptingBaseScript) unit);
|
1089 |
} |
1090 |
|
1091 |
this.launcherRefresh();
|
1092 |
} |
1093 |
} |
1094 |
|
1095 |
public JPanel getImportHelpDialog() { |
1096 |
return new JDialogContent( |
1097 |
uimanager, |
1098 |
"list-add",
|
1099 |
this.uimanager.getTranslation("Import_JavaDoc"), |
1100 |
this.uimanager.getTranslation("Import_JavaDoc_title"), |
1101 |
new JImportHelpController(uimanager, this)); |
1102 |
} |
1103 |
|
1104 |
public void getRemoveHelpDialog() throws Exception { |
1105 |
JRemoveHelpModel model = new JRemoveHelpModel(manager);
|
1106 |
JDialogContent dialog = new JDialogContent(
|
1107 |
uimanager, |
1108 |
"list-remove",
|
1109 |
this.uimanager.getTranslation("Remove_JavaDoc"), |
1110 |
this.uimanager.getTranslation("Remove_JavaDoc_title"), |
1111 |
new JRemoveHelpPanel(uimanager, model));
|
1112 |
dialog.showDialog(); |
1113 |
if (model.getAction() == JNewScriptModel.ACTION_ACCEPT) {
|
1114 |
this.removeHelps(model);
|
1115 |
} |
1116 |
} |
1117 |
|
1118 |
public void removeHelps(JRemoveHelpModel model) throws Exception { |
1119 |
model.validate(); |
1120 |
Object[] helps = model.getHelps(); |
1121 |
for (int i = 0; i < helps.length; i++) { |
1122 |
this.manager.getHelpManager().removeHelp(helps[i].toString());
|
1123 |
} |
1124 |
//Recargar JavaHelp
|
1125 |
this.manager.getHelpManager().reloadHelp();
|
1126 |
JOptionPane.showMessageDialog(null, |
1127 |
this.uimanager.getTranslation("Deleting_JavaDocs_successfully"), |
1128 |
this.uimanager.getTranslation("Deleting_JavaDocs_successfully_title"), |
1129 |
JOptionPane.INFORMATION_MESSAGE);
|
1130 |
uimanager.showWindow(uimanager.getHelp(), this.uimanager.getTranslation("JavaDoc")); |
1131 |
} |
1132 |
|
1133 |
public void scriptMove(final ScriptingUnit theUnit) throws Exception { |
1134 |
if (theUnit.getParent() == null) { |
1135 |
JOptionPane.showMessageDialog(null, "Please, select first the file to move on the tree directory", "Error", JOptionPane.ERROR_MESSAGE); |
1136 |
} else {
|
1137 |
JMoveScriptModel model = new JMoveScriptModel(manager, theUnit);
|
1138 |
JDialogContent dialog = new JDialogContent(
|
1139 |
uimanager, |
1140 |
"format-indent-more",
|
1141 |
this.uimanager.getTranslation("Move") + " '" + theUnit.getName() + "' " + this.uimanager.getTranslation("script_filesystem"), |
1142 |
this.uimanager.getTranslation("move_desc"), |
1143 |
new JMoveScriptPanel(uimanager, model)
|
1144 |
); |
1145 |
dialog.showDialog(); |
1146 |
if (model.getAction() == JMoveScriptModel.ACTION_ACCEPT) {
|
1147 |
model.validate(); |
1148 |
ScriptingFolder folderDest = manager.getFolder(model.getMoveTo()); |
1149 |
if (model.getUnit().move(folderDest)) {
|
1150 |
JOptionPane.showMessageDialog(null, |
1151 |
this.uimanager.getTranslation("Moving_succesfully"), |
1152 |
this.uimanager.getTranslation("Success"), JOptionPane.INFORMATION_MESSAGE); |
1153 |
this.launcherRefresh();
|
1154 |
} else {
|
1155 |
JOptionPane.showMessageDialog(null, |
1156 |
this.uimanager.getTranslation("Error_moving"), |
1157 |
this.uimanager.getTranslation("Error"), JOptionPane.ERROR_MESSAGE); |
1158 |
} |
1159 |
} |
1160 |
} |
1161 |
|
1162 |
} |
1163 |
|
1164 |
public void scriptRename(ScriptingUnit theUnit) throws Exception { |
1165 |
if (theUnit.getParent() == null) { |
1166 |
JOptionPane.showMessageDialog(null, |
1167 |
this.uimanager.getTranslation("Select_first"), |
1168 |
this.uimanager.getTranslation("Error"), JOptionPane.ERROR_MESSAGE); |
1169 |
} else {
|
1170 |
JRenameModel model = new JRenameModel(manager, theUnit);
|
1171 |
JDialogContent dialog = new JDialogContent(
|
1172 |
uimanager, |
1173 |
"preferences-system",
|
1174 |
this.uimanager.getTranslation("Rename") + " '" + theUnit.getName() + "' " + this.uimanager.getTranslation("script_filesystem"), |
1175 |
this.uimanager.getTranslation("rename_desc"), |
1176 |
new JRenamePanel(uimanager, model)
|
1177 |
); |
1178 |
dialog.showDialog(); |
1179 |
if (model.getAction() == JRenameModel.ACTION_ACCEPT) {
|
1180 |
model.validate(); |
1181 |
ScriptingUnit unit = model.getUnit(); |
1182 |
if (!model.getNewName().equals(unit.getId())) {
|
1183 |
if (unit.rename(model.getNewName())) {
|
1184 |
JOptionPane.showMessageDialog(null, |
1185 |
this.uimanager.getTranslation("Rename_succesfully"), |
1186 |
this.uimanager.getTranslation("Success"), JOptionPane.INFORMATION_MESSAGE); |
1187 |
this.launcherRefresh();
|
1188 |
} else {
|
1189 |
JOptionPane.showMessageDialog(null, |
1190 |
this.uimanager.getTranslation(this.uimanager.getTranslation("Error_renaming")), |
1191 |
this.uimanager.getTranslation("Error"), JOptionPane.ERROR_MESSAGE); |
1192 |
} |
1193 |
if (unit instanceof ScriptingScript) { |
1194 |
((ScriptingScript) unit).save(); |
1195 |
} |
1196 |
} |
1197 |
} |
1198 |
} |
1199 |
} |
1200 |
|
1201 |
@Override
|
1202 |
public JPanel getAboutUsDialog() { |
1203 |
return new JDialogContent(uimanager, |
1204 |
"system-users",
|
1205 |
this.uimanager.getTranslation("About_us"), |
1206 |
this.uimanager.getTranslation("About_us_title"), |
1207 |
new JDefaultDialog(uimanager, this, uimanager.getAboutManager().getAboutPanel())); |
1208 |
} |
1209 |
|
1210 |
public void scriptDelete(final ScriptingUnit unit, boolean isRecursive) { |
1211 |
int n = 0; |
1212 |
if (!isRecursive) {
|
1213 |
n = JOptionPane.showConfirmDialog(
|
1214 |
this.getRootPane(),
|
1215 |
this.uimanager.getTranslation("Delete_all_message"), |
1216 |
this.uimanager.getTranslation("Delete_all_title"), |
1217 |
JOptionPane.YES_NO_OPTION);
|
1218 |
} |
1219 |
if (n == 0) { |
1220 |
//Si es un folder borramos recursivamente sus subdirectorios
|
1221 |
if (unit instanceof ScriptingFolder) { |
1222 |
List<ScriptingUnit> subunits
|
1223 |
= ((ScriptingFolder) unit).getUnits(); |
1224 |
Iterator<ScriptingUnit> it = subunits.iterator();
|
1225 |
while (it.hasNext()) {
|
1226 |
ScriptingUnit subunit = it.next(); |
1227 |
scriptDelete(subunit, true);
|
1228 |
} |
1229 |
} |
1230 |
// Por último borramos el nodo seleccionado
|
1231 |
unit.getParent().remove(unit); |
1232 |
launcherRefresh(); |
1233 |
|
1234 |
} |
1235 |
} |
1236 |
|
1237 |
/**
|
1238 |
* Función que cierra la pestaña de edición actual
|
1239 |
*
|
1240 |
*/
|
1241 |
public void currentScriptClose() { |
1242 |
if (!unitsEditor.isEmpty()) {
|
1243 |
int position = scriptEditors.getSelectedIndex();
|
1244 |
String title = scriptEditors.getTitleAt(position);
|
1245 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(position); |
1246 |
ScriptingScript script = pestanaEditor.getScript(); |
1247 |
int respuesta = 1; |
1248 |
if (!script.isSaved()) {
|
1249 |
respuesta = JOptionPane.showConfirmDialog(
|
1250 |
scriptEditors, |
1251 |
"'" + title.substring(1) + "' " + this.uimanager.getTranslation("project_modified"), |
1252 |
this.uimanager.getTranslation("projects_modified_title"), |
1253 |
JOptionPane.YES_NO_CANCEL_OPTION);
|
1254 |
if (respuesta == 0) { |
1255 |
currentScriptSave(); |
1256 |
} |
1257 |
} |
1258 |
|
1259 |
if (respuesta < 2) { |
1260 |
pestanaEditor.getScript().setSaved(true);
|
1261 |
scriptEditors.remove(position); |
1262 |
unitsEditor.remove(script.getFile().getAbsolutePath()); |
1263 |
scriptEditors.repaint(); |
1264 |
} |
1265 |
} |
1266 |
} |
1267 |
|
1268 |
/**
|
1269 |
* Función que cierra todas las pestañas de edición abiertas
|
1270 |
*
|
1271 |
*/
|
1272 |
public void closeAllScripts() { |
1273 |
boolean exit = false; |
1274 |
while (!unitsEditor.isEmpty() && !exit) {
|
1275 |
int action = 1; |
1276 |
int i = 0; |
1277 |
boolean answered = false; |
1278 |
while (i < scriptEditors.getComponentCount() && !answered) {
|
1279 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(i); |
1280 |
if (!pestanaEditor.getScript().isSaved()) {
|
1281 |
action = JOptionPane.showConfirmDialog(
|
1282 |
scriptEditors, |
1283 |
this.uimanager.getTranslation("projects_modified"), |
1284 |
this.uimanager.getTranslation("projects_modified_title"), |
1285 |
JOptionPane.YES_NO_CANCEL_OPTION);
|
1286 |
answered = true;
|
1287 |
} |
1288 |
i++; |
1289 |
} |
1290 |
if (action == 0) { |
1291 |
for (i = 0; i < scriptEditors.getComponentCount(); i++) { |
1292 |
scriptEditors.setSelectedIndex(i); |
1293 |
currentScriptSave(); |
1294 |
} |
1295 |
} |
1296 |
if (action < 2) { |
1297 |
for (i = scriptEditors.getComponentCount() - 1; i >= 0; i--) { |
1298 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(i); |
1299 |
pestanaEditor.getScript().setSaved(true);
|
1300 |
scriptEditors.setSelectedIndex(i); |
1301 |
currentScriptClose(); |
1302 |
} |
1303 |
} else {
|
1304 |
exit = true;
|
1305 |
} |
1306 |
|
1307 |
} |
1308 |
} |
1309 |
|
1310 |
/**
|
1311 |
* Función que ejecuta el ScriptingBaseScript de la pestaña actual
|
1312 |
*
|
1313 |
*/
|
1314 |
public void currentScriptExecute() { |
1315 |
if (!unitsEditor.isEmpty()) {
|
1316 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1317 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1318 |
consoleClear(); |
1319 |
errorsClear(); |
1320 |
pestanaEditor.getScript().addObserver(this);
|
1321 |
try {
|
1322 |
ScriptingScript script = pestanaEditor.getScript(); |
1323 |
script.compile(); |
1324 |
script.runAsTask(null);
|
1325 |
|
1326 |
} catch (Throwable e) { |
1327 |
logger.info("Can't execute dialog-", e);
|
1328 |
} |
1329 |
} |
1330 |
} |
1331 |
|
1332 |
/*
|
1333 |
class ScriptTask extends AbstractMonitorableTask {
|
1334 |
|
1335 |
ScriptingScript script;
|
1336 |
DefaultJScriptingComposer composer;
|
1337 |
|
1338 |
protected ScriptTask(DefaultJScriptingComposer composer, ScriptingScript script) {
|
1339 |
super(script.getName());
|
1340 |
this.composer = composer;
|
1341 |
this.script = script;
|
1342 |
this.script.put("task",this);
|
1343 |
this.script.put("taskStatus",this.getTaskStatus());
|
1344 |
}
|
1345 |
|
1346 |
public void run() {
|
1347 |
try {
|
1348 |
composer.consolePrintln("Running '"+ script.getName() +"'...");
|
1349 |
script.run();
|
1350 |
composer.consolePrintln("Quit '"+ script.getName() +"'");
|
1351 |
} catch (Throwable e) {
|
1352 |
((SimpleTaskStatus)this.getTaskStatus()).abort();
|
1353 |
composer.consolePrintln("Aborted '"+ script.getName() +"'");
|
1354 |
}
|
1355 |
}
|
1356 |
}
|
1357 |
*/
|
1358 |
/**
|
1359 |
* Funciones de 'cortar', 'copiar', 'pegar' y 'seleccionar todo' para los
|
1360 |
* JEditors
|
1361 |
*
|
1362 |
*/
|
1363 |
public void currentScriptCopy() { |
1364 |
if (!unitsEditor.isEmpty()) {
|
1365 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1366 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1367 |
pestanaEditor.getJTextComponent().copy(); |
1368 |
} |
1369 |
} |
1370 |
|
1371 |
public void currentScriptCut() { |
1372 |
if (!unitsEditor.isEmpty()) {
|
1373 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1374 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1375 |
pestanaEditor.getJTextComponent().cut(); |
1376 |
JTabbedPane tabs = (JTabbedPane) pestanaEditor.getParent(); |
1377 |
|
1378 |
String title = tabs.getTitleAt(pestanaIndex);
|
1379 |
if (title.length() > 0 && !title.substring(0, 1).equals("*")) { |
1380 |
tabs.setTitleAt(tabs.getSelectedIndex(), "*" + title);
|
1381 |
pestanaEditor.getScript().setSaved(false);
|
1382 |
} |
1383 |
} |
1384 |
} |
1385 |
|
1386 |
public void currentScriptPaste() { |
1387 |
if (!unitsEditor.isEmpty()) {
|
1388 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1389 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1390 |
pestanaEditor.getJTextComponent().paste(); |
1391 |
JTabbedPane tabs = (JTabbedPane) pestanaEditor.getParent(); |
1392 |
|
1393 |
String title = tabs.getTitleAt(pestanaIndex);
|
1394 |
if (title.length() > 0 && !title.substring(0, 1).equals("*")) { |
1395 |
tabs.setTitleAt(tabs.getSelectedIndex(), "*" + title);
|
1396 |
pestanaEditor.getScript().setSaved(false);
|
1397 |
} |
1398 |
} |
1399 |
} |
1400 |
|
1401 |
public void currentScriptSelectAll() { |
1402 |
if (!unitsEditor.isEmpty()) {
|
1403 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1404 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1405 |
pestanaEditor.getJTextComponent().selectAll(); |
1406 |
} |
1407 |
} |
1408 |
|
1409 |
/**
|
1410 |
* Función para el guardado del ScriptingBaseScript de la pestaña actual
|
1411 |
*
|
1412 |
*/
|
1413 |
public void currentScriptSave() { |
1414 |
if (!unitsEditor.isEmpty()) {
|
1415 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1416 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1417 |
pestanaEditor.save(); |
1418 |
String title = scriptEditors.getTitleAt(pestanaIndex);
|
1419 |
if (title.substring(0, 1).equals("*")) { |
1420 |
scriptEditors.setTitleAt(pestanaIndex, title.substring(1));
|
1421 |
} |
1422 |
} |
1423 |
} |
1424 |
|
1425 |
/**
|
1426 |
* Actualización del Launcher
|
1427 |
*
|
1428 |
*/
|
1429 |
public void launcherRefresh() { |
1430 |
launcher.refresh(); |
1431 |
// launcher.addDefaultActionListener(this);
|
1432 |
// launcher.setPreferredSize(new Dimension(200, 450));
|
1433 |
} |
1434 |
|
1435 |
/**
|
1436 |
* Función para indicar la posición del cursor en un JEditor
|
1437 |
*
|
1438 |
* @param line
|
1439 |
* @param column
|
1440 |
*/
|
1441 |
public void setEditorCursorPosition(int line, int column) { |
1442 |
if (line == 0 && column == 0) { |
1443 |
currentLine.setText("");
|
1444 |
} else {
|
1445 |
currentLine.setText( |
1446 |
this.uimanager.getTranslation("Line") + " " + line + ":" + column); |
1447 |
} |
1448 |
statusBar.repaint(); |
1449 |
} |
1450 |
|
1451 |
/**
|
1452 |
* Función para la actualización del mensaje de la barra de estado
|
1453 |
*
|
1454 |
* @param message
|
1455 |
*/
|
1456 |
public void setMessage(String message) { |
1457 |
statusBarMessage.setText(message); |
1458 |
statusBar.repaint(); |
1459 |
} |
1460 |
|
1461 |
/**
|
1462 |
* Función para la actualización del mensaje de la barra de estado un
|
1463 |
* tiempo limitado
|
1464 |
*
|
1465 |
* @param message
|
1466 |
* @param seconds
|
1467 |
*/
|
1468 |
public void setMessage(String message, int seconds) { |
1469 |
setMessage(message); |
1470 |
} |
1471 |
|
1472 |
/**
|
1473 |
*
|
1474 |
* @param e
|
1475 |
*/
|
1476 |
public void actionPerformed(ActionEvent e) { |
1477 |
|
1478 |
if (e instanceof UpdateCaretPositionActionEvent) { |
1479 |
UpdateCaretPositionActionEvent e2 = (UpdateCaretPositionActionEvent) e; |
1480 |
|
1481 |
if (e2.hasLineAndColumn()) {
|
1482 |
setEditorCursorPosition(e2.getLine(), e2.getColumn()); |
1483 |
} else {
|
1484 |
setEditorCursorPosition(0, 0); |
1485 |
} |
1486 |
} else if (e instanceof LauncherActionEvent) { |
1487 |
LauncherActionEvent e2 = (LauncherActionEvent) e; |
1488 |
|
1489 |
switch (e.getID()) {
|
1490 |
case JScriptingBrowser.DEFAULT_ACTION:
|
1491 |
scriptEdit(e2.getScript()); |
1492 |
break;
|
1493 |
case JScriptingBrowser.DROPDOWN_ACTION:
|
1494 |
case JScriptingBrowser.SELECTION_ACTION:
|
1495 |
|
1496 |
break;
|
1497 |
} |
1498 |
} |
1499 |
} |
1500 |
|
1501 |
/**
|
1502 |
* Clase empleada para crear un objeto JTextArea que hereda de OutputStream
|
1503 |
* en el que volcar las salidas estándar.
|
1504 |
*/
|
1505 |
public class JTextAreaOutputStream extends OutputStream { |
1506 |
|
1507 |
JTextArea ta;
|
1508 |
|
1509 |
public JTextAreaOutputStream(JTextArea t) { |
1510 |
super();
|
1511 |
ta = t; |
1512 |
} |
1513 |
|
1514 |
@Override
|
1515 |
public void write(int i) { |
1516 |
ta.append(Character.toString((char) i)); |
1517 |
} |
1518 |
|
1519 |
public void write(char[] buf, int off, int len) { |
1520 |
String s = new String(buf, off, len); |
1521 |
ta.append(s); |
1522 |
} |
1523 |
} |
1524 |
|
1525 |
public void update(final Observable observable, final Object notification) { |
1526 |
if (!SwingUtilities.isEventDispatchThread()) { |
1527 |
SwingUtilities.invokeLater(new Runnable() { |
1528 |
public void run() { |
1529 |
update(observable, notification); |
1530 |
} |
1531 |
}); |
1532 |
return;
|
1533 |
} |
1534 |
if (notification instanceof ScriptingNotification) { |
1535 |
ScriptingNotification e = (ScriptingNotification) notification; |
1536 |
|
1537 |
if (e.getException() instanceof CompileErrorException) { |
1538 |
CompileErrorException ce = (CompileErrorException) e.getException(); |
1539 |
errorsAdd(ce.getMessage(), ce.getScriptName(), ce.getLineNumber(), ce.getColumnNumber()); |
1540 |
|
1541 |
} else if (e.getException() instanceof ExecuteErrorException) { |
1542 |
ExecuteErrorException ee = (ExecuteErrorException) e.getException(); |
1543 |
errorsAdd(ee.getMessage(), ee.getScriptName(), ee.getLineNumber(), ee.getColumnNumber()); |
1544 |
consolePrintln(ee.getMessage(), Color.RED.darker());
|
1545 |
ee.printStackTrace(this.console.getStderr());
|
1546 |
|
1547 |
} else {
|
1548 |
Throwable ex = e.getException();
|
1549 |
errorsAdd(ex.getMessage()); |
1550 |
consolePrintln(ex.getMessage(), Color.RED.darker());
|
1551 |
ex.printStackTrace(this.console.getStderr());
|
1552 |
} |
1553 |
} |
1554 |
} |
1555 |
|
1556 |
public void errorsAdd(final String description, final String resource, final int line, final int column) { |
1557 |
if (!SwingUtilities.isEventDispatchThread()) { |
1558 |
SwingUtilities.invokeLater(new Runnable() { |
1559 |
public void run() { |
1560 |
errorsAdd(description, resource, line, column); |
1561 |
} |
1562 |
}); |
1563 |
return;
|
1564 |
} |
1565 |
String location1;
|
1566 |
if (line < 0) { |
1567 |
location1 = "(" + this.uimanager.getTranslation("no_line") + ")"; |
1568 |
} else if (column < 0) { |
1569 |
location1 = String.valueOf(line);
|
1570 |
} else {
|
1571 |
location1 = String.valueOf(line) + ":" + String.valueOf(column); |
1572 |
} |
1573 |
Object[] rowData = {description, resource, location1}; |
1574 |
tableModel.addRow(rowData); |
1575 |
problemsPane.setSelectedIndex(0);
|
1576 |
} |
1577 |
|
1578 |
public void errorsAdd(String description, String resource) { |
1579 |
errorsAdd(description, resource, -1, -1); |
1580 |
} |
1581 |
|
1582 |
public void errorsAdd(String description) { |
1583 |
errorsAdd(description, null, -1, -1); |
1584 |
} |
1585 |
|
1586 |
public void errorsClear() { |
1587 |
if (!SwingUtilities.isEventDispatchThread()) { |
1588 |
SwingUtilities.invokeLater(new Runnable() { |
1589 |
public void run() { |
1590 |
errorsClear(); |
1591 |
} |
1592 |
}); |
1593 |
return;
|
1594 |
} |
1595 |
while (tableModel.getRowCount() > 0) { |
1596 |
tableModel.removeRow(0);
|
1597 |
} |
1598 |
} |
1599 |
|
1600 |
public void consoleClear() { |
1601 |
if (!SwingUtilities.isEventDispatchThread()) { |
1602 |
SwingUtilities.invokeLater(new Runnable() { |
1603 |
public void run() { |
1604 |
consoleClear(); |
1605 |
} |
1606 |
}); |
1607 |
return;
|
1608 |
} |
1609 |
console.clear(); |
1610 |
problemsPane.setSelectedIndex(1);
|
1611 |
} |
1612 |
|
1613 |
public void consolePrintln(final String str, final Color color) { |
1614 |
if (!SwingUtilities.isEventDispatchThread()) { |
1615 |
SwingUtilities.invokeLater(new Runnable() { |
1616 |
public void run() { |
1617 |
consolePrintln(str, color); |
1618 |
} |
1619 |
}); |
1620 |
return;
|
1621 |
} |
1622 |
console.append(str, color); |
1623 |
console.append("\n");
|
1624 |
problemsPane.setSelectedIndex(1);
|
1625 |
} |
1626 |
|
1627 |
public void consolePrint(final String str) { |
1628 |
if (!SwingUtilities.isEventDispatchThread()) { |
1629 |
SwingUtilities.invokeLater(new Runnable() { |
1630 |
public void run() { |
1631 |
consolePrint(str); |
1632 |
} |
1633 |
}); |
1634 |
return;
|
1635 |
} |
1636 |
console.append(str); |
1637 |
problemsPane.setSelectedIndex(1);
|
1638 |
} |
1639 |
|
1640 |
public void closeWindow() { |
1641 |
this.setVisible(false); |
1642 |
} |
1643 |
|
1644 |
|
1645 |
private RSyntaxTextArea getCurrentRSyntaxTextArea() {
|
1646 |
int pestanaIndex = scriptEditors.getSelectedIndex();
|
1647 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1648 |
JTextComponent textComponent = pestanaEditor.getJTextComponent();
|
1649 |
if( !(textComponent instanceof RSyntaxTextArea) ) { |
1650 |
return null; |
1651 |
} |
1652 |
return (RSyntaxTextArea)textComponent;
|
1653 |
} |
1654 |
|
1655 |
@Override
|
1656 |
public void searchEvent(SearchEvent e) { |
1657 |
|
1658 |
RSyntaxTextArea textArea = getCurrentRSyntaxTextArea(); |
1659 |
if( textArea == null ) { |
1660 |
return;
|
1661 |
} |
1662 |
|
1663 |
SearchEvent.Type type = e.getType(); |
1664 |
SearchContext context = e.getSearchContext(); |
1665 |
SearchResult result = null; |
1666 |
|
1667 |
switch (type) {
|
1668 |
default: // Prevent FindBugs warning later |
1669 |
case MARK_ALL:
|
1670 |
result = SearchEngine.markAll(textArea, context); |
1671 |
break;
|
1672 |
case FIND:
|
1673 |
result = SearchEngine.find(textArea, context); |
1674 |
if (!result.wasFound()) {
|
1675 |
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
|
1676 |
} |
1677 |
break;
|
1678 |
case REPLACE:
|
1679 |
result = SearchEngine.replace(textArea, context); |
1680 |
if (!result.wasFound()) {
|
1681 |
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
|
1682 |
} |
1683 |
break;
|
1684 |
case REPLACE_ALL:
|
1685 |
result = SearchEngine.replaceAll(textArea, context); |
1686 |
JOptionPane.showMessageDialog(null, result.getCount() |
1687 |
+ " occurrences replaced.");
|
1688 |
break;
|
1689 |
} |
1690 |
String text = null; |
1691 |
if (result.wasFound()) {
|
1692 |
text = "Text found; occurrences marked: " + result.getMarkedCount();
|
1693 |
} else if (type == SearchEvent.Type.MARK_ALL) { |
1694 |
if (result.getMarkedCount() > 0) { |
1695 |
text = "Occurrences marked: " + result.getMarkedCount();
|
1696 |
} else {
|
1697 |
text = "";
|
1698 |
} |
1699 |
} else {
|
1700 |
text = "Text not found";
|
1701 |
} |
1702 |
setMessage(text); |
1703 |
} |
1704 |
|
1705 |
@Override
|
1706 |
public String getSelectedText() { |
1707 |
RSyntaxTextArea textArea = getCurrentRSyntaxTextArea(); |
1708 |
if( textArea == null ) { |
1709 |
return ""; |
1710 |
} |
1711 |
return textArea.getSelectedText();
|
1712 |
} |
1713 |
|
1714 |
} |