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