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 @ 1128
History | View | Annotate | Download (92 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Cursor; |
6 |
import java.awt.Dialog; |
7 |
import java.awt.Dimension; |
8 |
import java.awt.Font; |
9 |
import java.awt.event.ActionEvent; |
10 |
import java.awt.event.ActionListener; |
11 |
import java.awt.event.KeyEvent; |
12 |
import java.awt.event.MouseAdapter; |
13 |
import java.awt.event.MouseEvent; |
14 |
import java.beans.PropertyChangeEvent; |
15 |
import java.beans.PropertyChangeListener; |
16 |
import java.io.File; |
17 |
import java.util.ArrayList; |
18 |
import java.util.Collection; |
19 |
import java.util.Date; |
20 |
import java.util.HashMap; |
21 |
import java.util.HashSet; |
22 |
import java.util.Iterator; |
23 |
import java.util.LinkedHashMap; |
24 |
import java.util.List; |
25 |
import java.util.Map; |
26 |
import java.util.Set; |
27 |
import javax.swing.AbstractAction; |
28 |
import javax.swing.Action; |
29 |
import static javax.swing.Action.ACCELERATOR_KEY; |
30 |
import static javax.swing.Action.ACTION_COMMAND_KEY; |
31 |
import javax.swing.BorderFactory; |
32 |
import javax.swing.JButton; |
33 |
import javax.swing.JComponent; |
34 |
import javax.swing.JLabel; |
35 |
import javax.swing.JMenuBar; |
36 |
import javax.swing.JMenuItem; |
37 |
import javax.swing.JOptionPane; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JScrollPane; |
40 |
import javax.swing.JSplitPane; |
41 |
import javax.swing.JTabbedPane; |
42 |
import javax.swing.JTable; |
43 |
import javax.swing.JToolBar; |
44 |
import javax.swing.KeyStroke; |
45 |
import javax.swing.ListSelectionModel; |
46 |
import javax.swing.SwingConstants; |
47 |
import javax.swing.SwingUtilities; |
48 |
import javax.swing.UIManager; |
49 |
import javax.swing.event.AncestorEvent; |
50 |
import javax.swing.event.AncestorListener; |
51 |
import javax.swing.event.ChangeEvent; |
52 |
import javax.swing.event.ChangeListener; |
53 |
import javax.swing.event.ListSelectionEvent; |
54 |
import javax.swing.event.ListSelectionListener; |
55 |
import javax.swing.table.DefaultTableModel; |
56 |
import javax.swing.table.TableModel; |
57 |
import javax.swing.text.JTextComponent; |
58 |
import org.apache.commons.io.FileUtils; |
59 |
import org.apache.commons.io.IOCase; |
60 |
import org.apache.commons.io.filefilter.FileFilterUtils; |
61 |
import org.fife.rsta.ui.GoToDialog; |
62 |
import org.fife.rsta.ui.search.FindDialog; |
63 |
import org.fife.rsta.ui.search.ReplaceDialog; |
64 |
import org.fife.rsta.ui.search.SearchEvent; |
65 |
import org.fife.rsta.ui.search.SearchListener; |
66 |
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; |
67 |
import org.fife.ui.rtextarea.SearchContext; |
68 |
import org.fife.ui.rtextarea.SearchEngine; |
69 |
import org.fife.ui.rtextarea.SearchResult; |
70 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
71 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
72 |
import org.gvsig.installer.swing.api.packagebuilder.PackageBuildder; |
73 |
import org.gvsig.scripting.CompileErrorException; |
74 |
import org.gvsig.scripting.ExecuteErrorException; |
75 |
import org.gvsig.scripting.ScriptingBaseScript; |
76 |
import org.gvsig.scripting.ScriptingErrorException; |
77 |
import org.gvsig.scripting.ScriptingFolder; |
78 |
import org.gvsig.scripting.ScriptingManager; |
79 |
import org.gvsig.scripting.ScriptingNotification; |
80 |
import org.gvsig.scripting.ScriptingScript; |
81 |
import org.gvsig.scripting.ScriptingUnit; |
82 |
import org.gvsig.scripting.swing.api.JCodeEditor; |
83 |
import org.gvsig.scripting.swing.api.JEditor; |
84 |
import org.gvsig.scripting.swing.api.JScriptingBrowser; |
85 |
import org.gvsig.scripting.swing.api.JScriptingBrowser.BrowserActionEvent; |
86 |
import org.gvsig.scripting.swing.api.JScriptingComposer; |
87 |
import static org.gvsig.scripting.swing.api.JScriptingComposer.DOCKED_PROBLEMS; |
88 |
import org.gvsig.scripting.swing.api.JScriptingComposer.Dock.DockedPanel; |
89 |
import org.gvsig.scripting.swing.api.JScriptingComposer.Problems; |
90 |
import org.gvsig.scripting.swing.api.JScriptingComposer.Problems.Problem; |
91 |
import org.gvsig.scripting.swing.api.JScriptingConsole; |
92 |
import org.gvsig.scripting.swing.api.JScriptingLauncher; |
93 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
94 |
import org.gvsig.scripting.swing.api.ScriptingUIManager.MenuEntry; |
95 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent.UpdateCaretPositionActionEvent; |
96 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingConsole; |
97 |
import org.gvsig.scripting.swing.impl.DefaultScriptingUIManager; |
98 |
import org.gvsig.scripting.swing.impl.JDialogContent; |
99 |
import org.gvsig.scripting.swing.impl.composer.DefaultJScriptingComposer.DefaultProblems.ProblemsTableMode.DefaultProblem; |
100 |
import org.gvsig.scripting.swing.impl.composer.editors.ScriptUnitEditor; |
101 |
import org.gvsig.tools.ToolsLocator; |
102 |
import org.gvsig.tools.i18n.I18nManager; |
103 |
import org.gvsig.tools.observer.Observable; |
104 |
import org.gvsig.tools.observer.Observer; |
105 |
import org.gvsig.tools.packageutils.PackageInfo; |
106 |
import org.gvsig.tools.packageutils.PackageManager; |
107 |
import org.gvsig.tools.packageutils.Version; |
108 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
109 |
import org.gvsig.tools.swing.api.Component; |
110 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
111 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
112 |
import org.slf4j.Logger; |
113 |
import org.slf4j.LoggerFactory; |
114 |
|
115 |
public class DefaultJScriptingComposer extends JPanel implements JScriptingComposer, Observer, ActionListener { |
116 |
|
117 |
/**
|
118 |
*
|
119 |
*/
|
120 |
private static final long serialVersionUID = 1L; |
121 |
|
122 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJScriptingComposer.class); |
123 |
|
124 |
public static final int CLOSE_ACTION = 1; |
125 |
|
126 |
private final ScriptingUIManager uimanager; |
127 |
private final ScriptingManager manager; |
128 |
private final ClassLoader loader; |
129 |
|
130 |
private JSplitPane mainPanel; |
131 |
private Dock dock;
|
132 |
|
133 |
private Map<String, ToolEntry> menus; |
134 |
private JMenuBar menuBar; |
135 |
|
136 |
private Map<String, ToolEntry> tools; |
137 |
private JToolBar toolBar; |
138 |
|
139 |
private StatusBar statusBar;
|
140 |
|
141 |
private FindDialog findDialog;
|
142 |
private ReplaceDialog replaceDialog;
|
143 |
private GoToDialog gotoDialog;
|
144 |
|
145 |
private ActionListener defaultActionlistener = null; |
146 |
|
147 |
private Set<ChangeListener> changeEditorListeners = null; |
148 |
|
149 |
private class GoToLineAction extends AbstractAction { |
150 |
|
151 |
private static final long serialVersionUID = -7353913671104893812L; |
152 |
|
153 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
154 |
public GoToLineAction() {
|
155 |
super(uimanager.getTranslation("go_to_line_Xhorizontal_ellipsisX")); |
156 |
int c = getToolkit().getMenuShortcutKeyMask();
|
157 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L, c)); |
158 |
putValue(ACTION_COMMAND_KEY, "GotoLine");
|
159 |
} |
160 |
|
161 |
@Override
|
162 |
public void actionPerformed(ActionEvent e) { |
163 |
JEditor editor = getCurrentEditor(); |
164 |
if (!(editor instanceof JCodeEditor)) { |
165 |
return;
|
166 |
} |
167 |
JCodeEditor codeEditor = (JCodeEditor) editor; |
168 |
if (findDialog.isVisible()) {
|
169 |
findDialog.setVisible(false);
|
170 |
} |
171 |
if (replaceDialog.isVisible()) {
|
172 |
replaceDialog.setVisible(false);
|
173 |
} |
174 |
gotoDialog.setMaxLineNumberAllowed(codeEditor.getLineCount()); |
175 |
gotoDialog.setVisible(true);
|
176 |
int line = gotoDialog.getLineNumber();
|
177 |
|
178 |
if (line > 0) { |
179 |
codeEditor.selectLine(line); |
180 |
} |
181 |
} |
182 |
|
183 |
@Override
|
184 |
public boolean isEnabled() { |
185 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
186 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
187 |
} |
188 |
} |
189 |
|
190 |
private class ShowFindDialogAction extends AbstractAction { |
191 |
|
192 |
private static final long serialVersionUID = -7840632153011361661L; |
193 |
|
194 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
195 |
public ShowFindDialogAction() {
|
196 |
super(uimanager.getTranslation("find_Xhorizontal_ellipsisX")); |
197 |
int c = getToolkit().getMenuShortcutKeyMask();
|
198 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, c)); |
199 |
putValue(ACTION_COMMAND_KEY, "ShowFindDialog");
|
200 |
} |
201 |
|
202 |
@Override
|
203 |
public void actionPerformed(ActionEvent e) { |
204 |
if (replaceDialog.isVisible()) {
|
205 |
replaceDialog.setVisible(false);
|
206 |
} |
207 |
findDialog.setVisible(true);
|
208 |
} |
209 |
|
210 |
@Override
|
211 |
public boolean isEnabled() { |
212 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
213 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
214 |
} |
215 |
} |
216 |
|
217 |
private class ShowReplaceDialogAction extends AbstractAction { |
218 |
|
219 |
private static final long serialVersionUID = 7209167803487996060L; |
220 |
|
221 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
222 |
public ShowReplaceDialogAction() {
|
223 |
super(uimanager.getTranslation("replace_Xhorizontal_ellipsisX")); |
224 |
int c = getToolkit().getMenuShortcutKeyMask();
|
225 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, c)); |
226 |
putValue(ACTION_COMMAND_KEY, "ShowReplaceDialog");
|
227 |
} |
228 |
|
229 |
@Override
|
230 |
public void actionPerformed(ActionEvent e) { |
231 |
if (findDialog.isVisible()) {
|
232 |
findDialog.setVisible(false);
|
233 |
} |
234 |
replaceDialog.setVisible(true);
|
235 |
} |
236 |
|
237 |
@Override
|
238 |
public boolean isEnabled() { |
239 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
240 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
241 |
} |
242 |
} |
243 |
|
244 |
private class LauncherAction extends AbstractAction { |
245 |
|
246 |
private static final long serialVersionUID = 6257776255757689286L; |
247 |
|
248 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
249 |
public LauncherAction() {
|
250 |
super(uimanager.getTranslation("Launcher")); |
251 |
putValue(ACTION_COMMAND_KEY, "ShowLauncher");
|
252 |
} |
253 |
|
254 |
@Override
|
255 |
public void actionPerformed(ActionEvent e) { |
256 |
getWindowManager().showWindow( |
257 |
uimanager.createLauncher().asJComponent(), |
258 |
uimanager.getTranslation("Scripting_Launcher"),
|
259 |
WindowManager.MODE.TOOL |
260 |
); |
261 |
} |
262 |
|
263 |
} |
264 |
|
265 |
private class SelectAllAction extends AbstractAction { |
266 |
|
267 |
private static final long serialVersionUID = 2725549699989067383L; |
268 |
|
269 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
270 |
public SelectAllAction() {
|
271 |
super(uimanager.getTranslation("Select_all")); |
272 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-edit-select-all")); |
273 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Select_all")); |
274 |
putValue(ACTION_COMMAND_KEY, "DocumentSelectAll");
|
275 |
} |
276 |
|
277 |
@Override
|
278 |
public void actionPerformed(ActionEvent e) { |
279 |
currentScriptSelectAll(); |
280 |
} |
281 |
|
282 |
@Override
|
283 |
public boolean isEnabled() { |
284 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
285 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
286 |
} |
287 |
|
288 |
} |
289 |
|
290 |
private class PackageScriptAction extends AbstractAction { |
291 |
|
292 |
private static final long serialVersionUID = 8020393562984016720L; |
293 |
|
294 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
295 |
public PackageScriptAction() {
|
296 |
super(uimanager.getTranslation("_Package_script")); |
297 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-package")); |
298 |
putValue(ACTION_COMMAND_KEY, "PackageScript");
|
299 |
} |
300 |
|
301 |
@Override
|
302 |
public void actionPerformed(ActionEvent e) { |
303 |
createScriptPackage(); |
304 |
} |
305 |
|
306 |
} |
307 |
|
308 |
private class AboutAction extends AbstractAction { |
309 |
|
310 |
private static final long serialVersionUID = -4928359535828269502L; |
311 |
|
312 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
313 |
public AboutAction() {
|
314 |
super(uimanager.getTranslation("About_scripts_editor")); |
315 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-about")); |
316 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("About_scripts_editor")); |
317 |
putValue(ACTION_COMMAND_KEY, "About");
|
318 |
} |
319 |
|
320 |
@Override
|
321 |
public void actionPerformed(ActionEvent e) { |
322 |
getWindowManager().showWindow( |
323 |
getAboutUsDialog(), |
324 |
uimanager.getTranslation("About_scripts_editor"),
|
325 |
WindowManager.MODE.WINDOW |
326 |
); |
327 |
} |
328 |
|
329 |
} |
330 |
|
331 |
private class CutAction extends AbstractAction { |
332 |
|
333 |
private static final long serialVersionUID = -8549655706085425411L; |
334 |
|
335 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
336 |
public CutAction() {
|
337 |
super(uimanager.getTranslation("Cut")); |
338 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-edit-cut")); |
339 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Cut")); |
340 |
putValue(ACTION_COMMAND_KEY, "DocumentCut");
|
341 |
} |
342 |
|
343 |
@Override
|
344 |
public void actionPerformed(ActionEvent e) { |
345 |
currentScriptCut(); |
346 |
} |
347 |
|
348 |
@Override
|
349 |
public boolean isEnabled() { |
350 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
351 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
352 |
} |
353 |
|
354 |
} |
355 |
|
356 |
private class CopyAction extends AbstractAction { |
357 |
|
358 |
private static final long serialVersionUID = -6870773810752024874L; |
359 |
|
360 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
361 |
public CopyAction() {
|
362 |
super(uimanager.getTranslation("Copy")); |
363 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-edit-copy")); |
364 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Copy")); |
365 |
putValue(ACTION_COMMAND_KEY, "DocumentCopy");
|
366 |
} |
367 |
|
368 |
@Override
|
369 |
public void actionPerformed(ActionEvent e) { |
370 |
currentScriptCopy(); |
371 |
} |
372 |
|
373 |
@Override
|
374 |
public boolean isEnabled() { |
375 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
376 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
377 |
} |
378 |
|
379 |
} |
380 |
|
381 |
private class PasteAction extends AbstractAction { |
382 |
|
383 |
private static final long serialVersionUID = -5829551248494873061L; |
384 |
|
385 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
386 |
public PasteAction() {
|
387 |
super(uimanager.getTranslation("Paste")); |
388 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-edit-paste")); |
389 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Paste")); |
390 |
putValue(ACTION_COMMAND_KEY, "DocumentPaste");
|
391 |
} |
392 |
|
393 |
@Override
|
394 |
public void actionPerformed(ActionEvent e) { |
395 |
currentScriptPaste(); |
396 |
} |
397 |
|
398 |
@Override
|
399 |
public boolean isEnabled() { |
400 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
401 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
402 |
} |
403 |
|
404 |
} |
405 |
|
406 |
private class ExitAction extends AbstractAction { |
407 |
|
408 |
private static final long serialVersionUID = 9165363564675325925L; |
409 |
|
410 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
411 |
public ExitAction() {
|
412 |
super(uimanager.getTranslation("Close")); |
413 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-exit")); |
414 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close")); |
415 |
putValue(ACTION_COMMAND_KEY, "CloseComposer");
|
416 |
} |
417 |
|
418 |
@Override
|
419 |
public void actionPerformed(ActionEvent e) { |
420 |
closeAllScripts(); |
421 |
closeWindow(); |
422 |
if (defaultActionlistener != null) { |
423 |
ActionEvent event = new ActionEvent(this, CLOSE_ACTION, "close"); |
424 |
defaultActionlistener.actionPerformed(event); |
425 |
} |
426 |
} |
427 |
|
428 |
} |
429 |
|
430 |
private class SaveAction extends AbstractAction { |
431 |
|
432 |
private static final long serialVersionUID = -870379961486387727L; |
433 |
|
434 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
435 |
public SaveAction() {
|
436 |
super(uimanager.getTranslation("Save")); |
437 |
int c = getToolkit().getMenuShortcutKeyMask();
|
438 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, c)); |
439 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-doc-save")); |
440 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Save")); |
441 |
putValue(ACTION_COMMAND_KEY, "DocumentSave");
|
442 |
} |
443 |
|
444 |
@Override
|
445 |
public void actionPerformed(ActionEvent e) { |
446 |
currentScriptSave(); |
447 |
} |
448 |
|
449 |
@Override
|
450 |
public boolean isEnabled() { |
451 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
452 |
return panel != null; |
453 |
} |
454 |
} |
455 |
|
456 |
private class RunAction extends AbstractAction { |
457 |
|
458 |
private static final long serialVersionUID = 4851968883766990149L; |
459 |
|
460 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
461 |
public RunAction() {
|
462 |
super(uimanager.getTranslation("Run")); |
463 |
int c = getToolkit().getMenuShortcutKeyMask();
|
464 |
// putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
|
465 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-run")); |
466 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Run")); |
467 |
putValue(ACTION_COMMAND_KEY, "DocumentRun");
|
468 |
} |
469 |
|
470 |
@Override
|
471 |
public void actionPerformed(ActionEvent e) { |
472 |
currentScriptExecute(); |
473 |
} |
474 |
|
475 |
@Override
|
476 |
public boolean isEnabled() { |
477 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
478 |
return panel != null; |
479 |
} |
480 |
} |
481 |
|
482 |
private class SaveAndRunAction extends AbstractAction { |
483 |
|
484 |
private static final long serialVersionUID = 4851968883766990149L; |
485 |
|
486 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
487 |
public SaveAndRunAction() {
|
488 |
super(uimanager.getTranslation("Save and run")); |
489 |
int c = getToolkit().getMenuShortcutKeyMask();
|
490 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
491 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-save-and-run")); |
492 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Save and run")); |
493 |
putValue(ACTION_COMMAND_KEY, "DocumentSaveAndRun");
|
494 |
} |
495 |
|
496 |
@Override
|
497 |
public void actionPerformed(ActionEvent e) { |
498 |
currentScriptSave(); |
499 |
currentScriptExecute(); |
500 |
} |
501 |
|
502 |
@Override
|
503 |
public boolean isEnabled() { |
504 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
505 |
return panel != null; |
506 |
} |
507 |
} |
508 |
|
509 |
private class CloseAllAction extends AbstractAction { |
510 |
|
511 |
private static final long serialVersionUID = 3385142920283598457L; |
512 |
|
513 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
514 |
public CloseAllAction() {
|
515 |
super(uimanager.getTranslation("Close_all_documents")); |
516 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-doc-closeall")); |
517 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close_all_documents")); |
518 |
putValue(ACTION_COMMAND_KEY, "CloseAll");
|
519 |
} |
520 |
|
521 |
@Override
|
522 |
public void actionPerformed(ActionEvent e) { |
523 |
closeAllScripts(); |
524 |
} |
525 |
|
526 |
@Override
|
527 |
public boolean isEnabled() { |
528 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
529 |
return panel != null; |
530 |
} |
531 |
|
532 |
} |
533 |
|
534 |
private class CloseDocumentAction extends AbstractAction { |
535 |
|
536 |
private static final long serialVersionUID = 4152188500446249755L; |
537 |
|
538 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
539 |
public CloseDocumentAction() {
|
540 |
super(uimanager.getTranslation("Close_document")); |
541 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-doc-close")); |
542 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close_current_tab")); |
543 |
putValue(ACTION_COMMAND_KEY, "DocumentClose");
|
544 |
} |
545 |
|
546 |
@Override
|
547 |
public void actionPerformed(ActionEvent e) { |
548 |
currentScriptClose(); |
549 |
} |
550 |
|
551 |
@Override
|
552 |
public boolean isEnabled() { |
553 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
554 |
return panel != null; |
555 |
} |
556 |
|
557 |
} |
558 |
|
559 |
private class ShowConsoleAction extends AbstractAction { |
560 |
|
561 |
private static final long serialVersionUID = -7545333555439711068L; |
562 |
|
563 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
564 |
public ShowConsoleAction() {
|
565 |
super(uimanager.getTranslation("Console")); |
566 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-show-console")); |
567 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Show_console_panel")); |
568 |
putValue(ACTION_COMMAND_KEY, "ShowConsole");
|
569 |
} |
570 |
|
571 |
@Override
|
572 |
public void actionPerformed(ActionEvent e) { |
573 |
addConsolePanel(); |
574 |
} |
575 |
} |
576 |
|
577 |
private class ShowProblemsAction extends AbstractAction { |
578 |
|
579 |
private static final long serialVersionUID = 5276964996914550830L; |
580 |
|
581 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
582 |
public ShowProblemsAction() {
|
583 |
super(uimanager.getTranslation("Problems")); |
584 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-show-problems")); |
585 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Show_problems_panel")); |
586 |
putValue(ACTION_COMMAND_KEY, "ShowProblems");
|
587 |
} |
588 |
|
589 |
@Override
|
590 |
public void actionPerformed(ActionEvent e) { |
591 |
addProblemsPanel(); |
592 |
} |
593 |
} |
594 |
|
595 |
private class ShowProjectsAction extends AbstractAction { |
596 |
|
597 |
private static final long serialVersionUID = 5873598740133693862L; |
598 |
|
599 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
600 |
public ShowProjectsAction() {
|
601 |
super(uimanager.getTranslation("Projects")); |
602 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-show-projects")); |
603 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Show_projects_panel")); |
604 |
putValue(ACTION_COMMAND_KEY, "ShowProjects");
|
605 |
} |
606 |
|
607 |
@Override
|
608 |
public void actionPerformed(ActionEvent e) { |
609 |
addProjectsPanel(); |
610 |
} |
611 |
} |
612 |
|
613 |
private class NewDocumentAction extends AbstractAction { |
614 |
|
615 |
private static final long serialVersionUID = 7889613706183211620L; |
616 |
|
617 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
618 |
public NewDocumentAction() {
|
619 |
super(uimanager.getTranslation("New")); |
620 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-doc-add")); |
621 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("New")); |
622 |
putValue(ACTION_COMMAND_KEY, "DocumentNew");
|
623 |
} |
624 |
|
625 |
@Override
|
626 |
public void actionPerformed(ActionEvent e) { |
627 |
try {
|
628 |
scriptNew(); |
629 |
} catch (Exception e1) { |
630 |
LOGGER.warn("Can't create a new document", e1);
|
631 |
} |
632 |
} |
633 |
|
634 |
} |
635 |
|
636 |
private class NewFolderAction extends AbstractAction { |
637 |
|
638 |
private static final long serialVersionUID = 7889613706183211620L; |
639 |
|
640 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
641 |
public NewFolderAction() {
|
642 |
super(uimanager.getTranslation("New folder")); |
643 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-folder-add")); |
644 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("New folder")); |
645 |
putValue(ACTION_COMMAND_KEY, "FolderNew");
|
646 |
} |
647 |
|
648 |
@Override
|
649 |
public void actionPerformed(ActionEvent e) { |
650 |
try {
|
651 |
FolderNew(); |
652 |
} catch (Exception e1) { |
653 |
LOGGER.warn("Can't create a new folder", e1);
|
654 |
} |
655 |
} |
656 |
|
657 |
} |
658 |
|
659 |
private class ProjectEditAction extends AbstractAction { |
660 |
|
661 |
private static final long serialVersionUID = -3393464285985649074L; |
662 |
|
663 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
664 |
public ProjectEditAction() {
|
665 |
super(uimanager.getTranslation("Edit")); |
666 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-doc-edit")); |
667 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Open_edition_mode")); |
668 |
putValue(ACTION_COMMAND_KEY, "DocumentEdit");
|
669 |
} |
670 |
|
671 |
@Override
|
672 |
public void actionPerformed(ActionEvent e) { |
673 |
try {
|
674 |
ScriptingUnit selectedItem = getLauncherSelectedScript(); |
675 |
if( uimanager.hasEditor(selectedItem) ) {
|
676 |
scriptEdit(selectedItem); |
677 |
} |
678 |
} catch (Exception e1) { |
679 |
LOGGER.warn("Can't edit document", e1);
|
680 |
} |
681 |
} |
682 |
} |
683 |
|
684 |
private class ProjectRefreshAction extends AbstractAction { |
685 |
|
686 |
private static final long serialVersionUID = 1944121660002532563L; |
687 |
|
688 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
689 |
public ProjectRefreshAction() {
|
690 |
super(uimanager.getTranslation("Refresh")); |
691 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-refresh")); |
692 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Refresh_directories")); |
693 |
putValue(ACTION_COMMAND_KEY, "ProjectsRefresh");
|
694 |
} |
695 |
|
696 |
@Override
|
697 |
public void actionPerformed(ActionEvent e) { |
698 |
refreshProjects(); |
699 |
} |
700 |
|
701 |
} |
702 |
|
703 |
private class ProjectRenameAction extends AbstractAction { |
704 |
|
705 |
private static final long serialVersionUID = 7469858242486966790L; |
706 |
|
707 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
708 |
public ProjectRenameAction() {
|
709 |
super(uimanager.getTranslation("Rename")); |
710 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-doc-rename")); |
711 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Set_file_properties")); |
712 |
putValue(ACTION_COMMAND_KEY, "Rename");
|
713 |
} |
714 |
|
715 |
@Override
|
716 |
public void actionPerformed(ActionEvent e) { |
717 |
try {
|
718 |
scriptRename(getLauncherSelectedScript()); |
719 |
} catch (Exception e1) { |
720 |
LOGGER.warn("Can't rename document", e1);
|
721 |
} |
722 |
} |
723 |
} |
724 |
|
725 |
private class ProjectMoveAction extends AbstractAction { |
726 |
|
727 |
private static final long serialVersionUID = -8857101021126773295L; |
728 |
|
729 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
730 |
public ProjectMoveAction() {
|
731 |
super(uimanager.getTranslation("Move")); |
732 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-doc-move")); |
733 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Move_files")); |
734 |
putValue(ACTION_COMMAND_KEY, "Move");
|
735 |
} |
736 |
|
737 |
@Override
|
738 |
public void actionPerformed(ActionEvent e) { |
739 |
try {
|
740 |
scriptMove(getLauncherSelectedScript()); |
741 |
} catch (Exception e1) { |
742 |
LOGGER.warn("Can't move document", e1);
|
743 |
} |
744 |
} |
745 |
} |
746 |
|
747 |
private class ProjectDeleteAction extends AbstractAction { |
748 |
|
749 |
private static final long serialVersionUID = 9039455504757742743L; |
750 |
|
751 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
752 |
public ProjectDeleteAction() {
|
753 |
super(uimanager.getTranslation("Delete")); |
754 |
putValue(Action.SMALL_ICON, uimanager.getIcon("scripting-doc-remove")); |
755 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Delete_selected_script")); |
756 |
putValue(ACTION_COMMAND_KEY, "Delete");
|
757 |
} |
758 |
|
759 |
@Override
|
760 |
public void actionPerformed(ActionEvent e) { |
761 |
try {
|
762 |
scriptDelete(getLauncherSelectedScript(), false);
|
763 |
} catch (Exception e1) { |
764 |
LOGGER.warn("Can't delete document", e1);
|
765 |
} |
766 |
} |
767 |
} |
768 |
|
769 |
/**
|
770 |
* Instanciacion de un JComposer con todos sus elementos y acciones
|
771 |
*
|
772 |
* @param uimanager
|
773 |
*/
|
774 |
public DefaultJScriptingComposer(final ScriptingUIManager uimanager) { |
775 |
loader = this.getClass().getClassLoader();
|
776 |
this.uimanager = uimanager;
|
777 |
this.manager = uimanager.getManager();
|
778 |
synchronized(this.manager) { |
779 |
initComponents(); |
780 |
} |
781 |
} |
782 |
|
783 |
@Override
|
784 |
public JComponent asJComponent() { |
785 |
return this; |
786 |
} |
787 |
|
788 |
@Override
|
789 |
public WindowManager getWindowManager() {
|
790 |
return ((DefaultScriptingUIManager) (this.uimanager)).getWindowManager(); |
791 |
} |
792 |
|
793 |
@Override
|
794 |
public void setWindowManager(WindowManager windowsManager) { |
795 |
((DefaultScriptingUIManager) (this.uimanager)).setWindowManager(windowsManager);
|
796 |
} |
797 |
|
798 |
private void initComponents() { |
799 |
|
800 |
this.addAncestorListener(new AncestorListener() { |
801 |
|
802 |
@Override
|
803 |
public void ancestorAdded(AncestorEvent event) { |
804 |
((DefaultScriptingUIManager) uimanager).setActiveComposer(DefaultJScriptingComposer.this); |
805 |
} |
806 |
|
807 |
@Override
|
808 |
public void ancestorRemoved(AncestorEvent event) { |
809 |
((DefaultScriptingUIManager) uimanager).setActiveComposer(null);
|
810 |
} |
811 |
|
812 |
@Override
|
813 |
public void ancestorMoved(AncestorEvent event) { |
814 |
} |
815 |
}); |
816 |
SearchListener findReplaceSearchListener = new FindReplaceSearchListener();
|
817 |
|
818 |
findDialog = new FindDialog((Dialog) null, findReplaceSearchListener); |
819 |
replaceDialog = new ReplaceDialog((Dialog) null, findReplaceSearchListener); |
820 |
gotoDialog = new GoToDialog((Dialog) null); |
821 |
|
822 |
SearchContext searchContext = findDialog.getSearchContext(); |
823 |
replaceDialog.setSearchContext(searchContext); |
824 |
|
825 |
this.menuBar = new JMenuBar(); |
826 |
this.toolBar = new JToolBar(); |
827 |
|
828 |
this.menus = new LinkedHashMap<>(); |
829 |
this.tools = new LinkedHashMap<>(); |
830 |
|
831 |
String _File = this.uimanager.getTranslation("File"); |
832 |
String _Edit = this.uimanager.getTranslation("Edit"); |
833 |
String _Projects = this.uimanager.getTranslation("Projects"); |
834 |
String _Tools = this.uimanager.getTranslation("Tools"); |
835 |
String _Help = this.uimanager.getTranslation("Help"); |
836 |
String _View = this.uimanager.getTranslation("Show"); |
837 |
|
838 |
this.addMenu(_File, null); |
839 |
this.addMenu(_File, new NewDocumentAction()); |
840 |
this.addMenu(_File, new NewFolderAction()); |
841 |
this.addMenuSeparator(_File);
|
842 |
this.addMenu(_File, new CloseDocumentAction()); |
843 |
this.addMenu(_File, new CloseAllAction()); |
844 |
this.addMenuSeparator(_File);
|
845 |
this.addMenu(_File, new RunAction()); |
846 |
this.addMenu(_File, new SaveAndRunAction()); |
847 |
this.addMenuSeparator(_File);
|
848 |
this.addMenu(_File, new SaveAction()); |
849 |
this.addMenuSeparator(_File);
|
850 |
this.addMenu(_File, new ExitAction()); |
851 |
|
852 |
this.addMenu(_Edit, null); |
853 |
this.addMenu(_Edit, new CutAction()); |
854 |
this.addMenu(_Edit, new CopyAction()); |
855 |
this.addMenu(_Edit, new PasteAction()); |
856 |
this.addMenuSeparator(_Edit);
|
857 |
this.addMenu(_Edit, new SelectAllAction()); |
858 |
this.addMenuSeparator(_Edit);
|
859 |
this.addMenu(_Edit, new ShowFindDialogAction()); |
860 |
this.addMenu(_Edit, new ShowReplaceDialogAction()); |
861 |
this.addMenu(_Edit, new GoToLineAction()); |
862 |
|
863 |
this.addMenu(_View, null); |
864 |
this.addMenu(_View, new ShowProjectsAction()); |
865 |
this.addMenu(_View, new ShowProblemsAction()); |
866 |
this.addMenu(_View, new ShowConsoleAction()); |
867 |
|
868 |
this.addMenu(_Projects, null); |
869 |
this.addMenu(_Projects, new ProjectEditAction()); |
870 |
this.addMenuSeparator(_Projects);
|
871 |
this.addMenu(_Projects, new ProjectRefreshAction()); |
872 |
this.addMenuSeparator(_Projects);
|
873 |
this.addMenu(_Projects, new ProjectRenameAction()); |
874 |
this.addMenu(_Projects, new ProjectMoveAction()); |
875 |
this.addMenu(_Projects, new ProjectDeleteAction()); |
876 |
|
877 |
this.addMenu(_Tools, null); |
878 |
this.addMenu(_Tools, new LauncherAction()); |
879 |
this.addMenuSeparator(_Tools);
|
880 |
this.addMenu(_Tools, new PackageScriptAction()); |
881 |
|
882 |
this.addMenu(_Help, null); |
883 |
this.addMenu(_Help, new AboutAction()); |
884 |
|
885 |
this.addTool(new NewDocumentAction()); |
886 |
this.addTool(new SaveAction()); |
887 |
this.addTool(new CutAction()); |
888 |
this.addTool(new CopyAction()); |
889 |
this.addTool(new PasteAction()); |
890 |
this.addTool(new RunAction()); |
891 |
this.addTool(new SaveAndRunAction()); |
892 |
|
893 |
JTabbedPaneClosable tabbedPanelLeft = new JTabbedPaneClosable(uimanager);
|
894 |
JTabbedPaneClosable tabbedPanelBottom = new JTabbedPaneClosable(uimanager);
|
895 |
JTabbedPaneClosable tabbedPanelCenter = new JTabbedPaneClosable(uimanager);
|
896 |
|
897 |
tabbedPanelLeft.setTabPlacement(JTabbedPane.BOTTOM);
|
898 |
tabbedPanelCenter.setPreferredSize(new Dimension(500, 300)); |
899 |
tabbedPanelCenter.addChangeListener(new ChangeListener() { |
900 |
|
901 |
@Override
|
902 |
public void stateChanged(ChangeEvent e) { |
903 |
updateMenusAndTools(); |
904 |
try {
|
905 |
((ScriptUnitEditor)((JTabbedPane)e.getSource()).getSelectedComponent()).getJTextComponent().requestFocusInWindow();
|
906 |
} catch(Throwable th) { |
907 |
LOGGER.debug("Can't set focus in the editor", th);
|
908 |
} |
909 |
} |
910 |
}); |
911 |
|
912 |
this.dock = new DefaultDock( |
913 |
tabbedPanelLeft, |
914 |
tabbedPanelBottom, |
915 |
tabbedPanelCenter |
916 |
); |
917 |
this.dock.addCloseListener(new ActionListener() { |
918 |
|
919 |
@Override
|
920 |
public void actionPerformed(ActionEvent e) { |
921 |
DockedPanel panel = (DockedPanel) e.getSource(); |
922 |
scriptClose(panel); |
923 |
} |
924 |
}); |
925 |
//tabbedPanelBottom.setPreferredSize(new Dimension(450, 100));
|
926 |
|
927 |
this.addProjectsPanel();
|
928 |
this.addConsolePanel();
|
929 |
this.addProblemsPanel();
|
930 |
|
931 |
this.dock.select(DOCKED_CONSOLE);
|
932 |
this.dock.select(DOCKED_PROJECTS);
|
933 |
|
934 |
JSplitPane centerPanel = new JSplitPane( |
935 |
JSplitPane.VERTICAL_SPLIT,
|
936 |
tabbedPanelCenter, |
937 |
tabbedPanelBottom |
938 |
); |
939 |
centerPanel.setResizeWeight(0.8);
|
940 |
centerPanel.setOneTouchExpandable(true);
|
941 |
|
942 |
mainPanel = new JSplitPane( |
943 |
JSplitPane.HORIZONTAL_SPLIT,
|
944 |
tabbedPanelLeft, |
945 |
centerPanel |
946 |
); |
947 |
mainPanel.setOneTouchExpandable(true);
|
948 |
|
949 |
statusBar = new DefaultStatusBar(uimanager);
|
950 |
|
951 |
updateMenusAndTools(); |
952 |
|
953 |
JPanel buttons = new JPanel(); |
954 |
buttons.setLayout(new BorderLayout()); |
955 |
buttons.add(BorderLayout.NORTH, this.menuBar); |
956 |
buttons.add(BorderLayout.SOUTH, this.toolBar); |
957 |
|
958 |
this.setLayout(new BorderLayout()); |
959 |
this.add(BorderLayout.NORTH, buttons); |
960 |
this.add(BorderLayout.CENTER, mainPanel); |
961 |
this.add(BorderLayout.SOUTH, statusBar.asJComponent()); |
962 |
this.setPreferredSize(new Dimension(800, 600)); |
963 |
} |
964 |
|
965 |
public void addMenu(String text, Action action) { |
966 |
String name;
|
967 |
if (action == null) { |
968 |
name = String.format("Menu%x", new Date().getTime()); |
969 |
} else {
|
970 |
name = (String) action.getValue(Action.ACTION_COMMAND_KEY); |
971 |
} |
972 |
this.menus.put(name, new ToolEntry(name, action, text)); |
973 |
} |
974 |
|
975 |
public void addMenuSeparator(String text) { |
976 |
String name = String.format("Sep%x", new Date().getTime()); |
977 |
this.menus.put(name, new ToolEntry(name, null, text + "/-")); |
978 |
} |
979 |
|
980 |
public void addTool(Action action) { |
981 |
String name = (String) action.getValue(Action.ACTION_COMMAND_KEY); |
982 |
this.tools.put(name, new ToolEntry(name, action)); |
983 |
} |
984 |
|
985 |
public void updateMenusAndTools() { |
986 |
|
987 |
this.menuBar.removeAll();
|
988 |
this.toolBar.removeAll();
|
989 |
for (MenuEntry entry : this.uimanager.getComposerMenus()) { |
990 |
this.addMenu(entry.getText(), entry.getAction());
|
991 |
} |
992 |
for (Action action : this.uimanager.getComposerTools()) { |
993 |
this.addTool(action);
|
994 |
} |
995 |
|
996 |
MenuBarHelper menuBarHelper = new MenuBarHelper(menuBar);
|
997 |
for (ToolEntry entry : menus.values()) {
|
998 |
try {
|
999 |
JMenuItem menu = menuBarHelper.add(entry.getText(), entry.getAction(), this); |
1000 |
entry.setComponent(menu); |
1001 |
} catch(Throwable th) { |
1002 |
LOGGER.warn("Can't add entry '"+entry.getName()+"' to the toolbar.", th); |
1003 |
} |
1004 |
} |
1005 |
|
1006 |
for (ToolEntry entry : tools.values()) {
|
1007 |
try {
|
1008 |
JButton button = new ButtonWithContext(entry.getAction()); |
1009 |
this.toolBar.add(button);
|
1010 |
entry.setComponent(button); |
1011 |
} catch(Throwable th) { |
1012 |
LOGGER.warn("Can't add entry '"+entry.getName()+"' to the toolbar.", th); |
1013 |
} |
1014 |
|
1015 |
} |
1016 |
this.menuBar.repaint();
|
1017 |
this.toolBar.repaint();
|
1018 |
} |
1019 |
|
1020 |
public void addProblemsPanel() { |
1021 |
DockedPanel panel = this.dock.get(DOCKED_PROBLEMS);
|
1022 |
if (panel != null) { |
1023 |
panel.select(); |
1024 |
return;
|
1025 |
} |
1026 |
final Problems problems = new DefaultProblems(this.uimanager); |
1027 |
problems.addListSelectionListener(new ListSelectionListener() { |
1028 |
|
1029 |
@Override
|
1030 |
public void valueChanged(ListSelectionEvent e) { |
1031 |
if (e.getValueIsAdjusting()) {
|
1032 |
return;
|
1033 |
} |
1034 |
Problem row = problems.getSelect(); |
1035 |
if (row != null) { |
1036 |
JEditor editor; |
1037 |
int lineno = row.getLineNumber();
|
1038 |
if( row.getResource() == null ) { |
1039 |
editor = getCurrentEditor(); |
1040 |
} else {
|
1041 |
String id = row.getResource().getAbsolutePath();
|
1042 |
DockedPanel panel = getDock().get(id); |
1043 |
if( panel == null ) { |
1044 |
ScriptingBaseScript script = manager.getScript(row.getResource()); |
1045 |
scriptEdit(script); |
1046 |
panel = getDock().get(id); |
1047 |
if( panel == null ) { |
1048 |
LOGGER.warn("Can't load script '"+id+"'."); |
1049 |
return;
|
1050 |
} |
1051 |
} |
1052 |
panel.select(); |
1053 |
editor = (JEditor) panel.getComponent(); |
1054 |
} |
1055 |
if ( editor instanceof JCodeEditor) { |
1056 |
((JCodeEditor) editor).gotoline(lineno); |
1057 |
} |
1058 |
} |
1059 |
} |
1060 |
}); |
1061 |
this.dock.add(
|
1062 |
DOCKED_PROBLEMS, |
1063 |
this.uimanager.getTranslation("Problems"), |
1064 |
problems, |
1065 |
Dock.DOCK_BOTTOM |
1066 |
); |
1067 |
this.dock.select(DOCKED_PROBLEMS);
|
1068 |
} |
1069 |
|
1070 |
public void addConsolePanel() { |
1071 |
DockedPanel panel = this.dock.get(DOCKED_CONSOLE);
|
1072 |
if (panel != null) { |
1073 |
panel.select(); |
1074 |
return;
|
1075 |
} |
1076 |
DefaultJScriptingConsole console = new DefaultJScriptingConsole(true); |
1077 |
this.dock.add(
|
1078 |
DOCKED_CONSOLE, |
1079 |
this.uimanager.getTranslation("Console"), |
1080 |
console, |
1081 |
Dock.DOCK_BOTTOM |
1082 |
); |
1083 |
this.dock.select(DOCKED_CONSOLE);
|
1084 |
} |
1085 |
|
1086 |
public void addProjectsPanel() { |
1087 |
DockedPanel panel = this.dock.get(DOCKED_PROJECTS);
|
1088 |
if (panel != null) { |
1089 |
panel.select(); |
1090 |
return;
|
1091 |
} |
1092 |
JScriptingLauncher launcher = uimanager.createLauncher(); |
1093 |
launcher.addDefaultActionListener(new ActionListener() { |
1094 |
|
1095 |
@Override
|
1096 |
public void actionPerformed(ActionEvent e) { |
1097 |
BrowserActionEvent e2 = (BrowserActionEvent) e; |
1098 |
switch (e.getID()) {
|
1099 |
case JScriptingBrowser.DEFAULT_ACTION:
|
1100 |
ScriptingUnit unit = e2.getUnit(); |
1101 |
if( unit instanceof ScriptingFolder ) { |
1102 |
return;
|
1103 |
} |
1104 |
if( uimanager.hasEditor(unit) ) {
|
1105 |
scriptEdit(unit); |
1106 |
} |
1107 |
break;
|
1108 |
case JScriptingBrowser.DROPDOWN_ACTION:
|
1109 |
case JScriptingBrowser.SELECTION_ACTION:
|
1110 |
break;
|
1111 |
} |
1112 |
} |
1113 |
}); |
1114 |
launcher.asJComponent().setPreferredSize(new Dimension(200, 450)); |
1115 |
|
1116 |
this.dock.add(
|
1117 |
DOCKED_PROJECTS, |
1118 |
this.uimanager.getTranslation("Projects"), |
1119 |
launcher, |
1120 |
Dock.DOCK_LEFT |
1121 |
); |
1122 |
this.dock.select(DOCKED_PROJECTS);
|
1123 |
} |
1124 |
|
1125 |
@Override
|
1126 |
public Problems getProblems() {
|
1127 |
DockedPanel panel = this.dock.get(DOCKED_PROBLEMS);
|
1128 |
if (panel == null) { |
1129 |
return null; |
1130 |
} |
1131 |
return (Problems) panel.getComponent();
|
1132 |
} |
1133 |
|
1134 |
@Override
|
1135 |
public JScriptingLauncher getProjects() {
|
1136 |
DockedPanel panel = this.dock.get(DOCKED_PROJECTS);
|
1137 |
if (panel == null) { |
1138 |
return null; |
1139 |
} |
1140 |
return (JScriptingLauncher) panel.getComponent();
|
1141 |
} |
1142 |
|
1143 |
@Override
|
1144 |
public Dock getDock() {
|
1145 |
return dock;
|
1146 |
} |
1147 |
|
1148 |
@Override
|
1149 |
public JScriptingConsole getConsole() {
|
1150 |
DockedPanel panel = this.dock.get(DOCKED_CONSOLE);
|
1151 |
if (panel == null) { |
1152 |
return null; |
1153 |
} |
1154 |
return (JScriptingConsole) panel.getComponent();
|
1155 |
} |
1156 |
|
1157 |
@Override
|
1158 |
public void addChangeEditorListener(ChangeListener listener) { |
1159 |
if (this.changeEditorListeners == null) { |
1160 |
this.changeEditorListeners = new HashSet<>(); |
1161 |
} |
1162 |
this.changeEditorListeners.add(listener);
|
1163 |
} |
1164 |
|
1165 |
@Override
|
1166 |
public void removeChangeEditorListener(ChangeListener listener) { |
1167 |
if (this.changeEditorListeners == null) { |
1168 |
return;
|
1169 |
} |
1170 |
this.changeEditorListeners.remove(listener);
|
1171 |
} |
1172 |
|
1173 |
public void fireChangeEditor(ChangeEvent e) { |
1174 |
if (this.changeEditorListeners == null) { |
1175 |
return;
|
1176 |
} |
1177 |
for (ChangeListener listener : this.changeEditorListeners) { |
1178 |
try {
|
1179 |
listener.stateChanged(e); |
1180 |
} catch (Throwable th) { |
1181 |
|
1182 |
} |
1183 |
} |
1184 |
} |
1185 |
|
1186 |
private void createScriptPackage() { |
1187 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
1188 |
SwingInstallerManager installerManager = SwingInstallerLocator.getSwingInstallerManager(); |
1189 |
PackageBuildder packager = installerManager.createPackagerPanel( |
1190 |
ScriptingManager.INSTALLER_PROVIDER_NAME, |
1191 |
manager.getRootUserFolder(), |
1192 |
manager.getPackagesFolder() |
1193 |
); |
1194 |
packager.addBeforePackingListener(new PackageBuildder.BeforePackingListener() {
|
1195 |
@Override
|
1196 |
public void perfrom(PackageBuildder builder) { |
1197 |
// Clean $py.class files before packing
|
1198 |
Collection<File> files = FileUtils.listFiles( |
1199 |
builder.getFolderToPackaging(), |
1200 |
FileFilterUtils.suffixFileFilter("$py.class", IOCase.INSENSITIVE),
|
1201 |
FileFilterUtils.trueFileFilter() |
1202 |
); |
1203 |
if( files!=null ) { |
1204 |
for (File file : files) { |
1205 |
FileUtils.deleteQuietly(file); |
1206 |
} |
1207 |
} |
1208 |
} |
1209 |
}); |
1210 |
|
1211 |
PackageInfo packageInfo = packager.getPackageInfo(); |
1212 |
packageInfo.setArchitecture(PackageManager.ARCH.ALL); |
1213 |
packageInfo.setJavaVM(PackageManager.JVM.J1_7); |
1214 |
packageInfo.setOperatingSystem(PackageManager.OS.ALL); |
1215 |
packageInfo.setOfficial(false);
|
1216 |
packageInfo.setState(PackageManager.STATE.TESTING); |
1217 |
packageInfo.setType(ScriptingManager.INSTALLER_PROVIDER_NAME); |
1218 |
Version version = ToolsLocator.getPackageManager().createVersion(); |
1219 |
version.parse("1.0.0");
|
1220 |
packageInfo.setVersion(version); |
1221 |
this.uimanager.showWindow(
|
1222 |
(JPanel) packager.asJComponent(),
|
1223 |
i18nManager.getTranslation("_Scripting_packager")
|
1224 |
); |
1225 |
} |
1226 |
|
1227 |
// private void setEditorSelection(String name, int line) {
|
1228 |
// for (int i = 0; i < scriptEditors.getTabCount(); i++) {
|
1229 |
//
|
1230 |
// if (((JEditor) scriptEditors.getComponent(i)).getScript().getId().equals(name)) {
|
1231 |
// scriptEditors.setSelectedIndex(i);
|
1232 |
//
|
1233 |
// JCodeEditor editor = ((JCodeEditor) scriptEditors.getComponent(i));
|
1234 |
// editor.selectLine(line);
|
1235 |
// }
|
1236 |
// }xxxxxxxxxxxxxxxxxxxxxxxx
|
1237 |
// }
|
1238 |
public void addDefaultActionListener(ActionListener actionlistener) { |
1239 |
this.defaultActionlistener = actionlistener;
|
1240 |
} |
1241 |
|
1242 |
/**
|
1243 |
* Funci?n para obtener el elemento seleccionado del Launcher
|
1244 |
*
|
1245 |
* @return Selected ScriptingUnit on the tree
|
1246 |
*/
|
1247 |
private ScriptingUnit getLauncherSelectedScript() {
|
1248 |
JScriptingBrowser browser = this.getCurrentBrowser();
|
1249 |
ScriptingUnit unit = browser.getSelectedNode(); |
1250 |
return unit;
|
1251 |
} |
1252 |
|
1253 |
private JScriptingBrowser getCurrentBrowser() {
|
1254 |
JScriptingLauncher launcher = this.getProjects();
|
1255 |
JScriptingBrowser browser = launcher.getSelectedBrowser(); |
1256 |
return browser;
|
1257 |
} |
1258 |
|
1259 |
// /**
|
1260 |
// * Lanza la ejecuci?n de un ScriptingBaseScript
|
1261 |
// *
|
1262 |
// * @param unit
|
1263 |
// */
|
1264 |
// private void scriptExecute(ScriptingUnit unit) {
|
1265 |
// if (unit instanceof ScriptingBaseScript) {
|
1266 |
// ((ScriptingBaseScript) unit).run();
|
1267 |
// }
|
1268 |
// }
|
1269 |
|
1270 |
public void scriptEdit(ScriptingUnit unit) { |
1271 |
String id = unit.getFile().getAbsolutePath();
|
1272 |
DockedPanel x = this.dock.get(id);
|
1273 |
if (x != null) { |
1274 |
x.select(); |
1275 |
return;
|
1276 |
} |
1277 |
final JEditor editor = this.uimanager.createEditor(unit); |
1278 |
if (editor == null) { |
1279 |
JOptionPane.showMessageDialog(null, this.uimanager.getTranslation("Error_opening_in_edition_mode"), this.uimanager.getTranslation("Error_opening_in_edition_mode_title"), JOptionPane.INFORMATION_MESSAGE); |
1280 |
return;
|
1281 |
} |
1282 |
final DockedPanel panel = this.dock.add(id, unit.getName(), editor, Dock.DOCK_CENTER); |
1283 |
panel.select(); |
1284 |
editor.addChangeListener(new PropertyChangeListener() { |
1285 |
|
1286 |
@Override
|
1287 |
public void propertyChange(PropertyChangeEvent evt) { |
1288 |
panel.setModified(true);
|
1289 |
fireChangeEditor(new ChangeEvent(editor)); |
1290 |
} |
1291 |
}); |
1292 |
if (editor instanceof JCodeEditor) { |
1293 |
((JCodeEditor) editor).addUpdateCaretPositionActionListener(new ActionListener() { |
1294 |
|
1295 |
@Override
|
1296 |
public void actionPerformed(ActionEvent e) { |
1297 |
UpdateCaretPositionActionEvent event = (UpdateCaretPositionActionEvent) e; |
1298 |
getStatusbar().setPosition( |
1299 |
event.getLine(), |
1300 |
event.getColumn() |
1301 |
); |
1302 |
} |
1303 |
}); |
1304 |
} |
1305 |
ScriptingUnit xx = editor.getUnit(); |
1306 |
if (xx instanceof ScriptingScript ) { |
1307 |
((ScriptingScript)xx).addObserver(this);
|
1308 |
} |
1309 |
} |
1310 |
|
1311 |
/**
|
1312 |
* Ventana para creaci?n de nuevos ScriptingBaseScripts
|
1313 |
*
|
1314 |
* @throws Exception
|
1315 |
*
|
1316 |
*/
|
1317 |
public void scriptNew() throws Exception { |
1318 |
this.unitNew(false); |
1319 |
} |
1320 |
|
1321 |
public void FolderNew() throws Exception { |
1322 |
this.unitNew(true); |
1323 |
} |
1324 |
|
1325 |
public void unitNew(boolean folder) throws Exception { |
1326 |
JNewScriptModel model = new JNewScriptModel(manager);
|
1327 |
model.setSelectionPath(this.getCurrentBrowser().getSelectionPath());
|
1328 |
JDialogContent dialog = new JDialogContent(
|
1329 |
uimanager, |
1330 |
"document-new",
|
1331 |
this.uimanager.getTranslation("New_Script"), |
1332 |
this.uimanager.getTranslation("New_Script_Description"), |
1333 |
new JNewScriptPanel(uimanager, model,folder)
|
1334 |
); |
1335 |
dialog.showDialog(); |
1336 |
if (model.getAction() == JNewScriptModel.ACTION_ACCEPT) {
|
1337 |
model.validate(); |
1338 |
ScriptingUnit unit = this.manager.createUnit(
|
1339 |
model.getType(), |
1340 |
manager.getFolder(model.getPath()), |
1341 |
model.getName(), |
1342 |
model.getLanguage() |
1343 |
); |
1344 |
if (unit instanceof ScriptingBaseScript) { |
1345 |
this.scriptEdit((ScriptingBaseScript) unit);
|
1346 |
} |
1347 |
|
1348 |
this.refreshProjects();
|
1349 |
} |
1350 |
} |
1351 |
|
1352 |
|
1353 |
public void scriptClose(DockedPanel panel) { |
1354 |
if (!panel.isModified()) {
|
1355 |
panel.remove(); |
1356 |
return;
|
1357 |
} |
1358 |
panel.select(); |
1359 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
1360 |
int respuesta = JOptionPane.showConfirmDialog( |
1361 |
this,
|
1362 |
i18nManager.getTranslation("_The_script_XscriptnameX_is_modified",
|
1363 |
new String[]{panel.getTitle()}) |
1364 |
+ "\n\n"
|
1365 |
+ i18nManager.getTranslation("_Do_you_want_to_save_changes_XquestionX"),
|
1366 |
i18nManager.getTranslation("_Save_changes_XquestionX"),
|
1367 |
JOptionPane.YES_NO_CANCEL_OPTION
|
1368 |
); |
1369 |
switch (respuesta) {
|
1370 |
case JOptionPane.YES_OPTION: |
1371 |
currentScriptSave(); |
1372 |
panel.remove(); |
1373 |
break;
|
1374 |
case JOptionPane.NO_OPTION: |
1375 |
panel.remove(); |
1376 |
break;
|
1377 |
default:
|
1378 |
case JOptionPane.CANCEL_OPTION: |
1379 |
break;
|
1380 |
} |
1381 |
} |
1382 |
|
1383 |
public void scriptMove(final ScriptingUnit theUnit) throws Exception { |
1384 |
if (theUnit.getParent() == null) { |
1385 |
JOptionPane.showMessageDialog(null, "Please, select first the file to move on the tree directory", "Error", JOptionPane.ERROR_MESSAGE); |
1386 |
} else {
|
1387 |
JMoveScriptModel model = new JMoveScriptModel(manager, theUnit);
|
1388 |
JDialogContent dialog = new JDialogContent(
|
1389 |
uimanager, |
1390 |
"format-indent-more",
|
1391 |
this.uimanager.getTranslation("Move") + " '" + theUnit.getName() + "' " + this.uimanager.getTranslation("script_filesystem"), |
1392 |
this.uimanager.getTranslation("move_desc"), |
1393 |
new JMoveScriptPanel(uimanager, model)
|
1394 |
); |
1395 |
dialog.showDialog(); |
1396 |
if (model.getAction() == JMoveScriptModel.ACTION_ACCEPT) {
|
1397 |
model.validate(); |
1398 |
ScriptingFolder folderDest = manager.getFolder(model.getMoveTo()); |
1399 |
if (model.getUnit().move(folderDest)) {
|
1400 |
JOptionPane.showMessageDialog(null, |
1401 |
this.uimanager.getTranslation("Moving_succesfully"), |
1402 |
this.uimanager.getTranslation("Success"), JOptionPane.INFORMATION_MESSAGE); |
1403 |
this.refreshProjects();
|
1404 |
} else {
|
1405 |
JOptionPane.showMessageDialog(null, |
1406 |
this.uimanager.getTranslation("Error_moving"), |
1407 |
this.uimanager.getTranslation("Error"), JOptionPane.ERROR_MESSAGE); |
1408 |
} |
1409 |
} |
1410 |
} |
1411 |
|
1412 |
} |
1413 |
|
1414 |
public void scriptRename(ScriptingUnit theUnit) throws Exception { |
1415 |
if (theUnit.getParent() == null) { |
1416 |
JOptionPane.showMessageDialog(null, |
1417 |
this.uimanager.getTranslation("Select_first"), |
1418 |
this.uimanager.getTranslation("Error"), JOptionPane.ERROR_MESSAGE); |
1419 |
} else {
|
1420 |
JRenameModel model = new JRenameModel(manager, theUnit);
|
1421 |
JDialogContent dialog = new JDialogContent(
|
1422 |
uimanager, |
1423 |
"preferences-system",
|
1424 |
this.uimanager.getTranslation("Rename") + " '" + theUnit.getName() + "' " + this.uimanager.getTranslation("script_filesystem"), |
1425 |
this.uimanager.getTranslation("rename_desc"), |
1426 |
new JRenamePanel(uimanager, model)
|
1427 |
); |
1428 |
dialog.showDialog(); |
1429 |
if (model.getAction() == JRenameModel.ACTION_ACCEPT) {
|
1430 |
model.validate(); |
1431 |
ScriptingUnit unit = model.getUnit(); |
1432 |
if (!model.getNewName().equals(unit.getId())) {
|
1433 |
if (unit.rename(model.getNewName())) {
|
1434 |
JOptionPane.showMessageDialog(null, |
1435 |
this.uimanager.getTranslation("Rename_succesfully"), |
1436 |
this.uimanager.getTranslation("Success"), JOptionPane.INFORMATION_MESSAGE); |
1437 |
this.refreshProjects();
|
1438 |
} else {
|
1439 |
JOptionPane.showMessageDialog(null, |
1440 |
this.uimanager.getTranslation(this.uimanager.getTranslation("Error_renaming")), |
1441 |
this.uimanager.getTranslation("Error"), JOptionPane.ERROR_MESSAGE); |
1442 |
} |
1443 |
if (unit instanceof ScriptingScript) { |
1444 |
((ScriptingScript) unit).save(); |
1445 |
} |
1446 |
} |
1447 |
} |
1448 |
} |
1449 |
} |
1450 |
|
1451 |
@Override
|
1452 |
public JPanel getAboutUsDialog() { |
1453 |
return new JDialogContent(uimanager, |
1454 |
"system-users",
|
1455 |
this.uimanager.getTranslation("About_us"), |
1456 |
this.uimanager.getTranslation("About_us_title"), |
1457 |
new JDefaultDialog(uimanager, this, uimanager.getAboutManager().getAboutPanel())); |
1458 |
} |
1459 |
|
1460 |
public void scriptDelete(final ScriptingUnit unit, boolean isRecursive) { |
1461 |
int n = 0; |
1462 |
if (!isRecursive) {
|
1463 |
n = JOptionPane.showConfirmDialog(
|
1464 |
this.getRootPane(),
|
1465 |
this.uimanager.getTranslation("Delete_all_message"), |
1466 |
this.uimanager.getTranslation("Delete_all_title"), |
1467 |
JOptionPane.YES_NO_OPTION);
|
1468 |
} |
1469 |
if (n == 0) { |
1470 |
//Si es un folder borramos recursivamente sus subdirectorios
|
1471 |
if (unit instanceof ScriptingFolder) { |
1472 |
List<ScriptingUnit> subunits
|
1473 |
= ((ScriptingFolder) unit).getUnits(); |
1474 |
Iterator<ScriptingUnit> it = subunits.iterator();
|
1475 |
while (it.hasNext()) {
|
1476 |
ScriptingUnit subunit = it.next(); |
1477 |
scriptDelete(subunit, true);
|
1478 |
} |
1479 |
} |
1480 |
// Por ?ltimo borramos el nodo seleccionado
|
1481 |
unit.getParent().remove(unit); |
1482 |
this.refreshProjects();
|
1483 |
|
1484 |
} |
1485 |
} |
1486 |
|
1487 |
/**
|
1488 |
* Funci?n que cierra la pesta?a de edici?n actual
|
1489 |
*
|
1490 |
*/
|
1491 |
public void currentScriptClose() { |
1492 |
DockedPanel panel = this.dock.getSelected(Dock.DOCK_CENTER);
|
1493 |
if (panel == null) { |
1494 |
return;
|
1495 |
} |
1496 |
scriptClose(panel); |
1497 |
} |
1498 |
|
1499 |
/**
|
1500 |
* Close all editor tabs of the composer
|
1501 |
*/
|
1502 |
public void closeAllScripts() { |
1503 |
List<DockedPanel> modifiedPanels = new ArrayList<>(); |
1504 |
List<DockedPanel> toRemove = new ArrayList<>(); |
1505 |
|
1506 |
for (DockedPanel panel : this.dock) { |
1507 |
if (Dock.DOCK_CENTER.equals(panel.getAlign())) {
|
1508 |
if (panel.isModified()) {
|
1509 |
modifiedPanels.add(panel); |
1510 |
} else {
|
1511 |
toRemove.add(panel); |
1512 |
} |
1513 |
} |
1514 |
} |
1515 |
if (modifiedPanels.isEmpty() && toRemove.isEmpty()) {
|
1516 |
return;
|
1517 |
} |
1518 |
int action = JOptionPane.showConfirmDialog( |
1519 |
this,
|
1520 |
this.uimanager.getTranslation("projects_modified"), |
1521 |
this.uimanager.getTranslation("projects_modified_title"), |
1522 |
JOptionPane.YES_NO_CANCEL_OPTION
|
1523 |
); |
1524 |
switch (action) {
|
1525 |
case JOptionPane.CANCEL_OPTION: |
1526 |
return;
|
1527 |
case JOptionPane.YES_OPTION: |
1528 |
for (DockedPanel panel : modifiedPanels) {
|
1529 |
JEditor editor = (JEditor) panel.getComponent(); |
1530 |
if (editor.getUnit()!= null) { |
1531 |
editor.getUnit().setSaved(true);
|
1532 |
} |
1533 |
editor.save(); |
1534 |
toRemove.add(panel); |
1535 |
} |
1536 |
break;
|
1537 |
case JOptionPane.NO_OPTION: |
1538 |
for (DockedPanel panel : modifiedPanels) {
|
1539 |
JEditor editor = (JEditor) panel.getComponent(); |
1540 |
if (editor.getUnit() != null) { |
1541 |
editor.getUnit().setSaved(true);
|
1542 |
} |
1543 |
toRemove.add(panel); |
1544 |
} |
1545 |
} |
1546 |
if( toRemove.isEmpty() ) {
|
1547 |
return;
|
1548 |
} |
1549 |
for (DockedPanel panel : toRemove) {
|
1550 |
panel.remove(); |
1551 |
} |
1552 |
} |
1553 |
|
1554 |
/**
|
1555 |
* Funci?n que ejecuta el ScriptingBaseScript de la pesta?a actual
|
1556 |
*
|
1557 |
*/
|
1558 |
@SuppressWarnings("UseSpecificCatch") |
1559 |
public void currentScriptExecute() { |
1560 |
ScriptingScript script = this.getCurrentScript();
|
1561 |
if (script != null) { |
1562 |
Problems problems = this.getProblems();
|
1563 |
if (problems != null) { |
1564 |
problems.removeAll(); |
1565 |
} |
1566 |
JScriptingConsole console = this.getConsole();
|
1567 |
if (console == null) { |
1568 |
addConsolePanel(); |
1569 |
} else {
|
1570 |
console.clear(); |
1571 |
} |
1572 |
script.addObserver(this);
|
1573 |
script.addStdoutWriter(this.getConsole().getOutputWriter());
|
1574 |
script.addStderrWriter(this.getConsole().getErrorsWriter());
|
1575 |
try {
|
1576 |
script.compile(); |
1577 |
script.runAsTask(null);
|
1578 |
} catch (Throwable e) { |
1579 |
LOGGER.info("Can't execute script", e);
|
1580 |
} |
1581 |
} |
1582 |
} |
1583 |
|
1584 |
/**
|
1585 |
* Funciones de 'cortar', 'copiar', 'pegar' y 'seleccionar todo' para los
|
1586 |
* JEditors
|
1587 |
*
|
1588 |
*/
|
1589 |
public void currentScriptCopy() { |
1590 |
DockedPanel panel = this.dock.getSelected(Dock.DOCK_CENTER);
|
1591 |
if (panel.getComponent().asJComponent() instanceof JCodeEditor) { |
1592 |
JCodeEditor editor = (JCodeEditor) panel.getComponent().asJComponent(); |
1593 |
editor.getJTextComponent().copy(); |
1594 |
} |
1595 |
} |
1596 |
|
1597 |
public void currentScriptCut() { |
1598 |
DockedPanel panel = this.dock.getSelected(Dock.DOCK_CENTER);
|
1599 |
if (panel.getComponent().asJComponent() instanceof JCodeEditor) { |
1600 |
JCodeEditor editor = (JCodeEditor) panel.getComponent().asJComponent(); |
1601 |
editor.getJTextComponent().cut(); |
1602 |
panel.setModified(true);
|
1603 |
} |
1604 |
} |
1605 |
|
1606 |
public void currentScriptPaste() { |
1607 |
DockedPanel panel = this.dock.getSelected(Dock.DOCK_CENTER);
|
1608 |
if (panel.getComponent().asJComponent() instanceof JCodeEditor) { |
1609 |
JCodeEditor editor = (JCodeEditor) panel.getComponent().asJComponent(); |
1610 |
editor.getJTextComponent().paste(); |
1611 |
panel.setModified(true);
|
1612 |
} |
1613 |
} |
1614 |
|
1615 |
public void currentScriptSelectAll() { |
1616 |
DockedPanel panel = this.dock.getSelected(Dock.DOCK_CENTER);
|
1617 |
if (panel.getComponent().asJComponent() instanceof JCodeEditor) { |
1618 |
JCodeEditor editor = (JCodeEditor) panel.getComponent().asJComponent(); |
1619 |
editor.getJTextComponent().selectAll(); |
1620 |
} |
1621 |
} |
1622 |
|
1623 |
/**
|
1624 |
* Funci?n para el guardado del ScriptingBaseScript de la pesta?a actual
|
1625 |
*
|
1626 |
*/
|
1627 |
public void currentScriptSave() { |
1628 |
DockedPanel panel = this.dock.getSelected(Dock.DOCK_CENTER);
|
1629 |
if (panel.getComponent().asJComponent() instanceof JEditor) { |
1630 |
JEditor editor = (JEditor) panel.getComponent().asJComponent(); |
1631 |
editor.save(); |
1632 |
panel.setModified(false);
|
1633 |
} |
1634 |
} |
1635 |
|
1636 |
@Override
|
1637 |
public JEditor getCurrentEditor() {
|
1638 |
DockedPanel panel = this.dock.getSelected(Dock.DOCK_CENTER);
|
1639 |
if (panel == null) { |
1640 |
return null; |
1641 |
} |
1642 |
if (panel.getComponent().asJComponent() instanceof JEditor) { |
1643 |
return (JEditor) panel.getComponent().asJComponent();
|
1644 |
} |
1645 |
return null; |
1646 |
} |
1647 |
|
1648 |
@Override
|
1649 |
public ScriptingScript getCurrentScript() {
|
1650 |
JEditor editor = this.getCurrentEditor();
|
1651 |
if (editor == null) { |
1652 |
return null; |
1653 |
} |
1654 |
ScriptingUnit unit = editor.getUnit(); |
1655 |
if( unit instanceof ScriptingScript ) { |
1656 |
return (ScriptingScript) unit;
|
1657 |
} |
1658 |
return null; |
1659 |
} |
1660 |
|
1661 |
private RSyntaxTextArea getCurrentRSyntaxTextArea() {
|
1662 |
JEditor editor = getCurrentEditor(); |
1663 |
if (editor instanceof JCodeEditor) { |
1664 |
JTextComponent textComponent = ((JCodeEditor) editor).getJTextComponent();
|
1665 |
if (textComponent instanceof RSyntaxTextArea) { |
1666 |
return (RSyntaxTextArea) textComponent;
|
1667 |
} |
1668 |
} |
1669 |
return null; |
1670 |
} |
1671 |
|
1672 |
@Override
|
1673 |
public void refreshProjects() { |
1674 |
try {
|
1675 |
this.getProjects().refresh();
|
1676 |
} catch (Exception ex) { |
1677 |
// Ignore
|
1678 |
} |
1679 |
} |
1680 |
|
1681 |
@Override
|
1682 |
public StatusBar getStatusbar() {
|
1683 |
return this.statusBar; |
1684 |
} |
1685 |
|
1686 |
/**
|
1687 |
*
|
1688 |
* @param e
|
1689 |
*/
|
1690 |
@Override
|
1691 |
public void actionPerformed(ActionEvent e) { |
1692 |
|
1693 |
if (e instanceof UpdateCaretPositionActionEvent) { |
1694 |
UpdateCaretPositionActionEvent e2 = (UpdateCaretPositionActionEvent) e; |
1695 |
|
1696 |
if (e2.hasLineAndColumn()) {
|
1697 |
this.getStatusbar().setPosition(e2.getLine(), e2.getColumn());
|
1698 |
} else {
|
1699 |
this.getStatusbar().setPosition(0, 0); |
1700 |
} |
1701 |
} |
1702 |
} |
1703 |
|
1704 |
@Override
|
1705 |
public void update(final Observable observable, final Object notification) { |
1706 |
if (!SwingUtilities.isEventDispatchThread()) { |
1707 |
SwingUtilities.invokeLater(new Runnable() { |
1708 |
@Override
|
1709 |
public void run() { |
1710 |
update(observable, notification); |
1711 |
} |
1712 |
}); |
1713 |
return;
|
1714 |
} |
1715 |
if (notification instanceof ScriptingNotification) { |
1716 |
ScriptingNotification e = (ScriptingNotification) notification; |
1717 |
|
1718 |
if (e.getException() instanceof CompileErrorException) { |
1719 |
CompileErrorException ce = (CompileErrorException) e.getException(); |
1720 |
Problems problems = this.getProblems();
|
1721 |
if (problems != null) { |
1722 |
problems.add("Error", ce);
|
1723 |
this.dock.select(DOCKED_PROBLEMS);
|
1724 |
} |
1725 |
|
1726 |
} else if (e.getException() instanceof ExecuteErrorException) { |
1727 |
ExecuteErrorException ee = (ExecuteErrorException) e.getException(); |
1728 |
Problems problems = this.getProblems();
|
1729 |
if (problems != null) { |
1730 |
problems.add("Error",ee);
|
1731 |
this.dock.select(DOCKED_PROBLEMS);
|
1732 |
} |
1733 |
JScriptingConsole console = this.getConsole();
|
1734 |
if (console != null) { |
1735 |
console.append(ee.getMessage(), Color.RED.darker());
|
1736 |
ee.printStackTrace(console.errors()); |
1737 |
} |
1738 |
|
1739 |
} else {
|
1740 |
Exception ex = e.getException();
|
1741 |
Problems problems = this.getProblems();
|
1742 |
if (problems != null) { |
1743 |
problems.add("Error",ex);
|
1744 |
this.dock.select(DOCKED_PROBLEMS);
|
1745 |
} |
1746 |
JScriptingConsole console = this.getConsole();
|
1747 |
if (console != null) { |
1748 |
console.append(ex.getMessage(), Color.RED.darker());
|
1749 |
ex.printStackTrace(console.errors()); |
1750 |
} |
1751 |
} |
1752 |
} |
1753 |
} |
1754 |
|
1755 |
public void closeWindow() { |
1756 |
this.setVisible(false); |
1757 |
} |
1758 |
|
1759 |
private static class DefaultStatusBar extends JPanel implements StatusBar { |
1760 |
|
1761 |
private static final long serialVersionUID = -6135634992327170084L; |
1762 |
|
1763 |
private JLabel message; |
1764 |
private JLabel position; |
1765 |
private final ScriptingUIManager uimanager; |
1766 |
|
1767 |
public DefaultStatusBar(ScriptingUIManager uimanager) {
|
1768 |
this.uimanager = uimanager;
|
1769 |
this.initComponents();
|
1770 |
} |
1771 |
|
1772 |
private void initComponents() { |
1773 |
this.message = new JLabel(this.uimanager.getTranslation("Welcome_message")); |
1774 |
this.position = new JLabel("Line 0:0"); |
1775 |
|
1776 |
this.setLayout(new BorderLayout()); |
1777 |
|
1778 |
this.add(this.message, BorderLayout.WEST); |
1779 |
this.add(this.position, BorderLayout.EAST); |
1780 |
} |
1781 |
|
1782 |
@Override
|
1783 |
public void clear() { |
1784 |
this.message.setText(""); |
1785 |
} |
1786 |
|
1787 |
@Override
|
1788 |
public void message(String message) { |
1789 |
this.message.setText(message);
|
1790 |
} |
1791 |
|
1792 |
@Override
|
1793 |
public void setPosition(int line) { |
1794 |
this.setPosition(line, -1); |
1795 |
} |
1796 |
|
1797 |
@Override
|
1798 |
public void setPosition(int line, int column) { |
1799 |
if (line < 0) { |
1800 |
this.position.setText(""); |
1801 |
return;
|
1802 |
} |
1803 |
if (column < 0) { |
1804 |
this.position.setText(this.uimanager.getTranslation("Line") + " " + line + ":0"); |
1805 |
} else {
|
1806 |
this.position.setText(this.uimanager.getTranslation("Line") + " " + line + ":" + column); |
1807 |
} |
1808 |
} |
1809 |
|
1810 |
@Override
|
1811 |
public JComponent asJComponent() { |
1812 |
return this; |
1813 |
} |
1814 |
} |
1815 |
|
1816 |
public static class JTabbedPaneClosable extends JTabbedPane { |
1817 |
|
1818 |
private static final long serialVersionUID = -3995298424891579555L; |
1819 |
|
1820 |
private final ActionListenerSupport closeTabListeners; |
1821 |
private ScriptingUIManager uimanager;
|
1822 |
|
1823 |
private class TabTitleComponent extends JPanel { |
1824 |
|
1825 |
private static final long serialVersionUID = -1061417669527944341L; |
1826 |
private final JLabel label; |
1827 |
private final JButton button; |
1828 |
private boolean changed = false; |
1829 |
private final Font fontNormal; |
1830 |
private final Font fontBold; |
1831 |
|
1832 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
1833 |
public TabTitleComponent(String title, final ActionListener onclose) { |
1834 |
this.setOpaque(true); |
1835 |
this.label = new JLabel(title + " "); |
1836 |
this.label.setOpaque(true); |
1837 |
this.label.setBackground(UIManager.getColor("TabbedPane.tabAreaBackground")); |
1838 |
this.label.setVerticalTextPosition(SwingConstants.CENTER); |
1839 |
this.fontNormal = this.label.getFont(); |
1840 |
this.fontBold = new Font(this.fontNormal.getFontName(), Font.BOLD, this.fontNormal.getSize()); |
1841 |
|
1842 |
this.button = new JButton(); |
1843 |
this.button.setText(""); |
1844 |
this.button.setToolTipText(uimanager.getTranslation("Close_tab")); |
1845 |
this.button.setBackground(UIManager.getColor("TabbedPane.tabAreaBackground")); |
1846 |
this.button.setBorder(BorderFactory.createEmptyBorder()); |
1847 |
this.button.setBorderPainted(false); |
1848 |
this.button.setFocusPainted(false); |
1849 |
this.button.setContentAreaFilled(false); |
1850 |
this.button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
1851 |
this.button.setRolloverEnabled(true); |
1852 |
this.button.setIcon(uimanager.getIcon("scripting-tabclose-inactive")); |
1853 |
this.button.setRolloverIcon(uimanager.getIcon("scripting-tabclose-active")); |
1854 |
this.button.addActionListener(new ActionListener() { |
1855 |
@Override
|
1856 |
public void actionPerformed(ActionEvent ae) { |
1857 |
ae.setSource(TabTitleComponent.this); |
1858 |
onclose.actionPerformed(ae); |
1859 |
} |
1860 |
}); |
1861 |
this.setLayout(new BorderLayout()); |
1862 |
this.add(this.label, BorderLayout.CENTER); |
1863 |
this.add(this.button, BorderLayout.EAST); |
1864 |
} |
1865 |
|
1866 |
public void setTitle(String title) { |
1867 |
this.label.setText(title);
|
1868 |
} |
1869 |
|
1870 |
public String getTitle() { |
1871 |
return this.label.getText(); |
1872 |
} |
1873 |
|
1874 |
public void setChanged(boolean changed) { |
1875 |
if (changed) {
|
1876 |
this.label.setFont(this.fontBold); |
1877 |
} else {
|
1878 |
this.label.setFont(this.fontNormal); |
1879 |
} |
1880 |
this.changed = changed;
|
1881 |
} |
1882 |
|
1883 |
public boolean isChanged() { |
1884 |
return this.changed; |
1885 |
} |
1886 |
} |
1887 |
|
1888 |
public JTabbedPaneClosable(ScriptingUIManager uimanager) {
|
1889 |
super();
|
1890 |
this.uimanager = uimanager;
|
1891 |
this.closeTabListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
1892 |
} |
1893 |
|
1894 |
@Override
|
1895 |
public String getTitleAt(int index) { |
1896 |
TabTitleComponent title = (TabTitleComponent) this.getTabComponentAt(index);
|
1897 |
if (title == null) { |
1898 |
return null; |
1899 |
} |
1900 |
return title.getTitle();
|
1901 |
} |
1902 |
|
1903 |
@Override
|
1904 |
public void setTitleAt(int index, String title) { |
1905 |
TabTitleComponent titleComponent = (TabTitleComponent) this.getTabComponentAt(index);
|
1906 |
titleComponent.setTitle(title); |
1907 |
} |
1908 |
|
1909 |
@Override
|
1910 |
public void addTab(String title, java.awt.Component component) { |
1911 |
super.addTab(null, component); |
1912 |
int index = getTabCount() - 1; |
1913 |
TabTitleComponent tabcomponent = new TabTitleComponent(title, new ActionListener() { |
1914 |
|
1915 |
@Override
|
1916 |
public void actionPerformed(ActionEvent ae) { |
1917 |
TabTitleComponent tabTitleComponent = (TabTitleComponent) ae.getSource(); |
1918 |
int index = indexOfTabComponent(tabTitleComponent);
|
1919 |
setSelectedIndex(index); |
1920 |
ae.setSource(JTabbedPaneClosable.this); |
1921 |
closeTabListeners.fireActionEvent(ae); |
1922 |
} |
1923 |
}); |
1924 |
super.setTabComponentAt(index, tabcomponent);
|
1925 |
} |
1926 |
|
1927 |
public void addCloseTabListener(ActionListener remove) { |
1928 |
this.closeTabListeners.addActionListener(remove);
|
1929 |
} |
1930 |
|
1931 |
public void removeCloseTabListener(ActionListener remove) { |
1932 |
this.closeTabListeners.removeActionListener(remove);
|
1933 |
} |
1934 |
|
1935 |
public ActionListener[] getCloseTabListeners() { |
1936 |
return this.closeTabListeners.getActionListeners(); |
1937 |
} |
1938 |
|
1939 |
public boolean isTabModified(int index) { |
1940 |
TabTitleComponent comp = (TabTitleComponent) this.getTabComponentAt(index);
|
1941 |
if (comp == null) { |
1942 |
return false; |
1943 |
} |
1944 |
return comp.isChanged();
|
1945 |
} |
1946 |
|
1947 |
public void setTabModified(int index, boolean changed) { |
1948 |
TabTitleComponent comp = (TabTitleComponent) this.getTabComponentAt(index);
|
1949 |
if (comp != null) { |
1950 |
comp.setChanged(changed); |
1951 |
} |
1952 |
} |
1953 |
} |
1954 |
|
1955 |
public static class DefaultProblems extends JPanel implements Problems { |
1956 |
|
1957 |
private static final long serialVersionUID = 7728033081188167969L; |
1958 |
|
1959 |
private static final int COLUMN_TYPE = 0; |
1960 |
private static final int COLUMN_MESSAGE = 1; |
1961 |
private static final int COLUMN_RESOURCE = 2; |
1962 |
private static final int COLUMN_LOCATION = 3; |
1963 |
private static final int NUM_COLUMNS = 4; |
1964 |
|
1965 |
private JTable table; |
1966 |
private ProblemsTableMode tableModel;
|
1967 |
private final ScriptingUIManager uimanager; |
1968 |
private Set<ListSelectionListener> selectionListeners; |
1969 |
|
1970 |
public static class ProblemsTableMode extends DefaultTableModel implements TableModel { |
1971 |
private static final long serialVersionUID = -3294067602561419422L; |
1972 |
|
1973 |
public static class DefaultProblem implements Problem { |
1974 |
|
1975 |
String[] row; |
1976 |
private File resource; |
1977 |
|
1978 |
public DefaultProblem() {
|
1979 |
this.row = new String[NUM_COLUMNS]; |
1980 |
} |
1981 |
|
1982 |
public DefaultProblem(String[] row) { |
1983 |
this.row = row;
|
1984 |
} |
1985 |
|
1986 |
public DefaultProblem(String type, String message, String resourceName, String location, File resource) { |
1987 |
String[] theRow = new String[NUM_COLUMNS]; |
1988 |
theRow[COLUMN_TYPE] = type; |
1989 |
theRow[COLUMN_MESSAGE] = message; |
1990 |
theRow[COLUMN_RESOURCE] = resourceName; |
1991 |
theRow[COLUMN_LOCATION] = location; |
1992 |
this.resource = resource;
|
1993 |
this.row = theRow;
|
1994 |
} |
1995 |
|
1996 |
public String get(int index) { |
1997 |
return row[index];
|
1998 |
} |
1999 |
|
2000 |
public String getValue(int index) { |
2001 |
return row[index];
|
2002 |
} |
2003 |
|
2004 |
public void setValue(int index, String value) { |
2005 |
row[index] = value; |
2006 |
} |
2007 |
|
2008 |
@Override
|
2009 |
public String getType() { |
2010 |
return this.row[COLUMN_TYPE]; |
2011 |
} |
2012 |
|
2013 |
@Override
|
2014 |
public String getMessage() { |
2015 |
return this.row[COLUMN_MESSAGE]; |
2016 |
} |
2017 |
|
2018 |
@Override
|
2019 |
public String getResourceName() { |
2020 |
return this.row[COLUMN_RESOURCE]; |
2021 |
} |
2022 |
|
2023 |
@Override
|
2024 |
public File getResource() { |
2025 |
return this.resource; |
2026 |
} |
2027 |
|
2028 |
@Override
|
2029 |
@SuppressWarnings("UseSpecificCatch") |
2030 |
public int getLineNumber() { |
2031 |
try {
|
2032 |
String[] lineAndColumn = this.row[COLUMN_LOCATION].split(":"); |
2033 |
if (lineAndColumn.length > 0) { |
2034 |
int lineno = Integer.parseInt(lineAndColumn[0].trim()); |
2035 |
return lineno;
|
2036 |
} |
2037 |
} catch (Exception e) { |
2038 |
// Do nothing
|
2039 |
} |
2040 |
return -1; |
2041 |
} |
2042 |
|
2043 |
} |
2044 |
private final ScriptingUIManager uimanager; |
2045 |
private List<DefaultProblem> data; |
2046 |
private String[] columnNames; |
2047 |
|
2048 |
public ProblemsTableMode(ScriptingUIManager uimanager) {
|
2049 |
this.uimanager = uimanager;
|
2050 |
this.columnNames = new String[]{ |
2051 |
this.uimanager.getTranslation("Category"), |
2052 |
this.uimanager.getTranslation("Description"), |
2053 |
this.uimanager.getTranslation("Resource"), |
2054 |
this.uimanager.getTranslation("Location") |
2055 |
}; |
2056 |
|
2057 |
} |
2058 |
|
2059 |
private List<DefaultProblem> getData() { |
2060 |
if( this.data == null ) { |
2061 |
this.data = new ArrayList<>(); |
2062 |
} |
2063 |
return this.data; |
2064 |
} |
2065 |
|
2066 |
public void add(DefaultProblem row) { |
2067 |
this.getData().add(row);
|
2068 |
this.fireTableDataChanged();
|
2069 |
} |
2070 |
|
2071 |
private void add(String type, String message, String resourceName, String location, File resource) { |
2072 |
DefaultProblem problem = new DefaultProblem(type, message, resourceName, location, resource);
|
2073 |
this.add(problem);
|
2074 |
} |
2075 |
|
2076 |
@Override
|
2077 |
public int getRowCount() { |
2078 |
return this.getData().size(); |
2079 |
} |
2080 |
|
2081 |
@Override
|
2082 |
public int getColumnCount() { |
2083 |
return NUM_COLUMNS;
|
2084 |
} |
2085 |
|
2086 |
@Override
|
2087 |
public String getColumnName(int columnIndex) { |
2088 |
return columnNames[columnIndex];
|
2089 |
} |
2090 |
|
2091 |
@Override
|
2092 |
public Class<?> getColumnClass(int columnIndex) { |
2093 |
return String.class; |
2094 |
} |
2095 |
|
2096 |
@Override
|
2097 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
2098 |
return false; |
2099 |
} |
2100 |
|
2101 |
@Override
|
2102 |
public Object getValueAt(int rowIndex, int columnIndex) { |
2103 |
return this.getData().get(rowIndex).get(columnIndex); |
2104 |
} |
2105 |
|
2106 |
public Problem getProblem(int rowIndex) { |
2107 |
return this.getData().get(rowIndex); |
2108 |
} |
2109 |
|
2110 |
@Override
|
2111 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
2112 |
this.getData().get(rowIndex).setValue(columnIndex, (String) aValue); |
2113 |
} |
2114 |
|
2115 |
public void removeAll() { |
2116 |
this.getData().clear();
|
2117 |
} |
2118 |
} |
2119 |
|
2120 |
public DefaultProblems(ScriptingUIManager uimanager) {
|
2121 |
this.uimanager = uimanager;
|
2122 |
this.initComponents();
|
2123 |
} |
2124 |
|
2125 |
private void initComponents() { |
2126 |
this.selectionListeners = new HashSet<>(); |
2127 |
tableModel = new ProblemsTableMode(this.uimanager); |
2128 |
table = new JTable(tableModel); |
2129 |
table.getColumnModel().getColumn(1).setPreferredWidth(300); |
2130 |
|
2131 |
table.setRowSelectionAllowed(true);
|
2132 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
2133 |
|
2134 |
JScrollPane scrollProblems = new JScrollPane(table); |
2135 |
scrollProblems.setAutoscrolls(true);
|
2136 |
|
2137 |
this.setLayout(new BorderLayout()); |
2138 |
this.add(scrollProblems, BorderLayout.CENTER); |
2139 |
|
2140 |
// Si ya hay seleccionada una linea y vuelvo a clickar sobre ella
|
2141 |
// para que me lleve a la linea del editor que toque, con el
|
2142 |
// addSelectionListener no me vuelve a lanzar el evento, asi que
|
2143 |
// me apalanco en el mouseClicked tambien.
|
2144 |
table.addMouseListener(new MouseAdapter(){ |
2145 |
@Override
|
2146 |
public void mouseClicked(MouseEvent evnt) { |
2147 |
if (evnt.getClickCount() == 1) { |
2148 |
fireSelectionListeners(); |
2149 |
} |
2150 |
} |
2151 |
}); |
2152 |
} |
2153 |
|
2154 |
@Override
|
2155 |
public void addListSelectionListener(ListSelectionListener listener) { |
2156 |
this.table.getSelectionModel().addListSelectionListener(listener);
|
2157 |
this.selectionListeners.add(listener);
|
2158 |
} |
2159 |
|
2160 |
private void fireSelectionListeners() { |
2161 |
int row = this.table.getSelectedRow(); |
2162 |
for( ListSelectionListener listener : this.selectionListeners ) { |
2163 |
try {
|
2164 |
listener.valueChanged(new ListSelectionEvent(this, row, row, false)); |
2165 |
} catch(Exception th) { |
2166 |
|
2167 |
} |
2168 |
} |
2169 |
} |
2170 |
|
2171 |
@Override
|
2172 |
public void removeAll() { |
2173 |
this.tableModel.removeAll();
|
2174 |
this.table.updateUI();
|
2175 |
} |
2176 |
|
2177 |
@Override
|
2178 |
public void add(String type, String message, String resource, String location) { |
2179 |
this.tableModel.add(type, message, resource, location, null); |
2180 |
} |
2181 |
|
2182 |
@Override
|
2183 |
public void add(String type, String message, String resource, int line, int column) { |
2184 |
this.add(type, message, resource, line + ":" + column); |
2185 |
} |
2186 |
|
2187 |
public void add(String type, String message, String resourceName, int line, int column, File resource) { |
2188 |
this.tableModel.add(type, message, resourceName, line + ":" + column, resource); |
2189 |
} |
2190 |
|
2191 |
@Override
|
2192 |
public void add(String type, Exception e) { |
2193 |
if (e instanceof ScriptingErrorException) { |
2194 |
ScriptingErrorException se = (ScriptingErrorException) e; |
2195 |
this.add(
|
2196 |
"Error",
|
2197 |
se.getMessage(), |
2198 |
se.getScriptName(), |
2199 |
se.getLineNumber(), |
2200 |
se.getColumnNumber(), |
2201 |
se.getScriptFile() |
2202 |
); |
2203 |
|
2204 |
} else {
|
2205 |
this.add("Error", |
2206 |
"Error",
|
2207 |
e.getMessage(), |
2208 |
null
|
2209 |
); |
2210 |
} |
2211 |
} |
2212 |
|
2213 |
@Override
|
2214 |
public Problem getSelect() {
|
2215 |
int row = this.table.getSelectedRow(); |
2216 |
if (row < 0) { |
2217 |
return null; |
2218 |
} |
2219 |
return this.get(row); |
2220 |
} |
2221 |
|
2222 |
@Override
|
2223 |
public int getCount() { |
2224 |
return this.tableModel.getRowCount(); |
2225 |
} |
2226 |
|
2227 |
@Override
|
2228 |
public Problem get(int row) { |
2229 |
return this.tableModel.getProblem(row); |
2230 |
} |
2231 |
|
2232 |
@Override
|
2233 |
public JComponent asJComponent() { |
2234 |
return this; |
2235 |
} |
2236 |
|
2237 |
} |
2238 |
|
2239 |
public static class DefaultDock extends JPanel implements Dock { |
2240 |
|
2241 |
private static final long serialVersionUID = 4899734277977456625L; |
2242 |
|
2243 |
public class DefaultDockedPanel implements DockedPanel { |
2244 |
|
2245 |
String id;
|
2246 |
String title;
|
2247 |
Component component;
|
2248 |
private final String align; |
2249 |
|
2250 |
public DefaultDockedPanel(String id, String title, Component component, String align) { |
2251 |
this.id = id;
|
2252 |
this.title = title;
|
2253 |
this.component = component;
|
2254 |
this.align = align;
|
2255 |
} |
2256 |
|
2257 |
@Override
|
2258 |
public String getId() { |
2259 |
return this.id; |
2260 |
} |
2261 |
|
2262 |
@Override
|
2263 |
public String getAlign() { |
2264 |
return this.align; |
2265 |
} |
2266 |
|
2267 |
@Override
|
2268 |
public Component getComponent() { |
2269 |
return this.component; |
2270 |
} |
2271 |
|
2272 |
@Override
|
2273 |
public String getTitle() { |
2274 |
return this.title; |
2275 |
} |
2276 |
|
2277 |
@Override
|
2278 |
public boolean isModified() { |
2279 |
return getModified(this); |
2280 |
} |
2281 |
|
2282 |
@Override
|
2283 |
public void setModified(boolean modified) { |
2284 |
DefaultDock.this.setModified(this, modified);
|
2285 |
} |
2286 |
|
2287 |
@Override
|
2288 |
public void remove() { |
2289 |
DefaultDock.this.remove(this.getId());
|
2290 |
} |
2291 |
|
2292 |
@Override
|
2293 |
public void select() { |
2294 |
DefaultDock.this.select(this.getId());
|
2295 |
} |
2296 |
} |
2297 |
|
2298 |
private final Map<String, Dock.DockedPanel> panels; |
2299 |
private final JTabbedPaneClosable tabbedPanelLeft; |
2300 |
private final JTabbedPaneClosable tabbedPanelBottom; |
2301 |
private final JTabbedPaneClosable tabbedPanelCenter; |
2302 |
private Set<ActionListener> closeListeners; |
2303 |
private Set<ActionListener> activePanelListeners; |
2304 |
|
2305 |
public DefaultDock(JTabbedPaneClosable tabbedPanelLeft, JTabbedPaneClosable tabbedPanelBottom, JTabbedPaneClosable tabbedPanelCenter) {
|
2306 |
this.panels = new HashMap<>(); |
2307 |
this.tabbedPanelBottom = tabbedPanelBottom;
|
2308 |
this.tabbedPanelLeft = tabbedPanelLeft;
|
2309 |
this.tabbedPanelCenter = tabbedPanelCenter;
|
2310 |
|
2311 |
ActionListener onCloseTab = new ActionListener() { |
2312 |
|
2313 |
@Override
|
2314 |
public void actionPerformed(ActionEvent e) { |
2315 |
JTabbedPaneClosable tabbedPanel = (JTabbedPaneClosable) e.getSource(); |
2316 |
java.awt.Component component = tabbedPanel.getSelectedComponent(); |
2317 |
if (component != null) { |
2318 |
DockedPanel panel = getDockedPanel(component); |
2319 |
if (panel != null) { |
2320 |
fireCloseListener(new ActionEvent(panel, 0, ACTION_CLOSE_PANEL)); |
2321 |
} |
2322 |
// panels.remove(panel.getId());
|
2323 |
// tabbedPanel.remove(panel.getComponent().asJComponent());
|
2324 |
} |
2325 |
} |
2326 |
}; |
2327 |
ChangeListener onChangeTab = new ChangeListener() { |
2328 |
|
2329 |
@Override
|
2330 |
public void stateChanged(ChangeEvent e) { |
2331 |
|
2332 |
fireChangeListener(new ActionEvent(DefaultDock.this, 0, ACTION_ACTIVATE_PANEL)); |
2333 |
} |
2334 |
}; |
2335 |
this.tabbedPanelCenter.addChangeListener(onChangeTab);
|
2336 |
this.tabbedPanelBottom.addChangeListener(onChangeTab);
|
2337 |
this.tabbedPanelLeft.addChangeListener(onChangeTab);
|
2338 |
|
2339 |
this.tabbedPanelBottom.addCloseTabListener(onCloseTab);
|
2340 |
this.tabbedPanelLeft.addCloseTabListener(onCloseTab);
|
2341 |
this.tabbedPanelCenter.addCloseTabListener(onCloseTab);
|
2342 |
|
2343 |
} |
2344 |
|
2345 |
/**
|
2346 |
*
|
2347 |
* @param listener
|
2348 |
*/
|
2349 |
@Override
|
2350 |
public void addCloseListener(ActionListener listener) { |
2351 |
if (this.closeListeners == null) { |
2352 |
this.closeListeners = new HashSet<>(); |
2353 |
} |
2354 |
this.closeListeners.add(listener);
|
2355 |
} |
2356 |
|
2357 |
@Override
|
2358 |
public void removeCloseListener(ActionListener listener) { |
2359 |
if (this.closeListeners == null) { |
2360 |
return;
|
2361 |
} |
2362 |
this.closeListeners.remove(listener);
|
2363 |
} |
2364 |
|
2365 |
@Override
|
2366 |
public void addActivateListener(ActionListener listener) { |
2367 |
if (this.activePanelListeners == null) { |
2368 |
this.activePanelListeners = new HashSet<>(); |
2369 |
} |
2370 |
this.activePanelListeners.add(listener);
|
2371 |
} |
2372 |
|
2373 |
@Override
|
2374 |
public void removeActivateListener(ActionListener listener) { |
2375 |
if (this.activePanelListeners == null) { |
2376 |
return;
|
2377 |
} |
2378 |
this.activePanelListeners.remove(listener);
|
2379 |
} |
2380 |
|
2381 |
|
2382 |
public void fireCloseListener(ActionEvent e) { |
2383 |
if (this.closeListeners == null) { |
2384 |
return;
|
2385 |
} |
2386 |
for (ActionListener listener : this.closeListeners) { |
2387 |
try {
|
2388 |
listener.actionPerformed(e); |
2389 |
} catch (Exception ex) { |
2390 |
|
2391 |
} |
2392 |
} |
2393 |
} |
2394 |
|
2395 |
public void fireChangeListener(ActionEvent e) { |
2396 |
if (this.activePanelListeners == null) { |
2397 |
return;
|
2398 |
} |
2399 |
for (ActionListener listener : this.activePanelListeners) { |
2400 |
try {
|
2401 |
listener.actionPerformed(e); |
2402 |
} catch (Exception ex) { |
2403 |
|
2404 |
} |
2405 |
} |
2406 |
} |
2407 |
|
2408 |
private JTabbedPaneClosable getTabbedPanel(String align) { |
2409 |
switch (align) {
|
2410 |
case Dock.DOCK_LEFT:
|
2411 |
return this.tabbedPanelLeft; |
2412 |
case Dock.DOCK_CENTER:
|
2413 |
return this.tabbedPanelCenter; |
2414 |
default:
|
2415 |
case Dock.DOCK_BOTTOM:
|
2416 |
return this.tabbedPanelBottom; |
2417 |
} |
2418 |
} |
2419 |
|
2420 |
private DockedPanel getDockedPanel(java.awt.Component component) {
|
2421 |
for (DockedPanel panel : this.panels.values()) { |
2422 |
if (panel.getComponent().asJComponent() == component) {
|
2423 |
return panel;
|
2424 |
} |
2425 |
} |
2426 |
return null; |
2427 |
} |
2428 |
|
2429 |
private int getIndex(DockedPanel panel) { |
2430 |
final JTabbedPaneClosable tabbedPanel = getTabbedPanel(panel.getAlign());
|
2431 |
for (int i = 0; i < tabbedPanel.getTabCount(); i++) { |
2432 |
java.awt.Component component = tabbedPanel.getComponentAt(i); |
2433 |
if (component == panel.getComponent().asJComponent()) {
|
2434 |
return i;
|
2435 |
} |
2436 |
} |
2437 |
return -1; |
2438 |
} |
2439 |
|
2440 |
@Override
|
2441 |
public void setModified(DockedPanel panel, boolean modified) { |
2442 |
final int index = this.getIndex(panel); |
2443 |
if (index < 0) { |
2444 |
return;
|
2445 |
} |
2446 |
final JTabbedPaneClosable tabbedPanel = getTabbedPanel(panel.getAlign());
|
2447 |
tabbedPanel.setTabModified(index, modified); |
2448 |
} |
2449 |
|
2450 |
@Override
|
2451 |
public boolean getModified(DockedPanel panel) { |
2452 |
final int index = this.getIndex(panel); |
2453 |
if (index < 0) { |
2454 |
return false; |
2455 |
} |
2456 |
final JTabbedPaneClosable tabbedPanel = getTabbedPanel(panel.getAlign());
|
2457 |
return tabbedPanel.isTabModified(index);
|
2458 |
} |
2459 |
|
2460 |
@Override
|
2461 |
public DockedPanel getSelected(String align) { |
2462 |
final JTabbedPaneClosable tabbedPanel = getTabbedPanel(align);
|
2463 |
java.awt.Component selected = tabbedPanel.getSelectedComponent(); |
2464 |
return this.getDockedPanel(selected); |
2465 |
} |
2466 |
|
2467 |
@Override
|
2468 |
public DockedPanel add(String id, String title, final Component component, String align) { |
2469 |
final JTabbedPaneClosable tabbedPanel = getTabbedPanel(align);
|
2470 |
DockedPanel panel = this.panels.get(id);
|
2471 |
if (panel != null) { |
2472 |
tabbedPanel.remove(panel.getComponent().asJComponent()); |
2473 |
} |
2474 |
panel = new DefaultDockedPanel(id, title, component, align);
|
2475 |
this.panels.put(id, panel);
|
2476 |
tabbedPanel.add(panel.getTitle(), panel.getComponent().asJComponent()); |
2477 |
return panel;
|
2478 |
} |
2479 |
|
2480 |
@Override
|
2481 |
public void remove(String id) { |
2482 |
DockedPanel panel = this.panels.get(id);
|
2483 |
if (panel != null) { |
2484 |
final JTabbedPaneClosable tabbedPanel = getTabbedPanel(panel.getAlign());
|
2485 |
tabbedPanel.remove(panel.getComponent().asJComponent()); |
2486 |
this.panels.remove(id);
|
2487 |
} |
2488 |
} |
2489 |
|
2490 |
@Override
|
2491 |
public DockedPanel get(String id) { |
2492 |
DockedPanel panel = this.panels.get(id);
|
2493 |
return panel;
|
2494 |
} |
2495 |
|
2496 |
@Override
|
2497 |
public void select(String id) { |
2498 |
DockedPanel panel = this.panels.get(id);
|
2499 |
if (panel != null) { |
2500 |
final JTabbedPaneClosable tabbedPanel = getTabbedPanel(panel.getAlign());
|
2501 |
tabbedPanel.setSelectedComponent(panel.getComponent().asJComponent()); |
2502 |
} |
2503 |
} |
2504 |
|
2505 |
@Override
|
2506 |
public Iterator<DockedPanel> iterator() { |
2507 |
return this.panels.values().iterator(); |
2508 |
} |
2509 |
|
2510 |
} |
2511 |
|
2512 |
private static class ToolEntry { |
2513 |
|
2514 |
private String name; |
2515 |
private String text; |
2516 |
private Action action; |
2517 |
private JComponent component; |
2518 |
|
2519 |
public ToolEntry(String name, Action action, String text) { |
2520 |
this.name = name;
|
2521 |
this.action = action;
|
2522 |
this.text = text;
|
2523 |
} |
2524 |
|
2525 |
public ToolEntry(String name, Action action) { |
2526 |
this(name, action, null); |
2527 |
} |
2528 |
|
2529 |
public String getName() { |
2530 |
return this.name; |
2531 |
} |
2532 |
|
2533 |
public String getText() { |
2534 |
return this.text; |
2535 |
} |
2536 |
|
2537 |
public Action getAction() { |
2538 |
return this.action; |
2539 |
} |
2540 |
|
2541 |
public JComponent getComponent() { |
2542 |
return this.component; |
2543 |
} |
2544 |
|
2545 |
public void setComponent(JComponent component) { |
2546 |
this.component = component;
|
2547 |
} |
2548 |
} |
2549 |
|
2550 |
public class ButtonWithContext extends JButton { |
2551 |
|
2552 |
private static final long serialVersionUID = -7434255417630073101L; |
2553 |
|
2554 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
2555 |
public ButtonWithContext(Action action) { |
2556 |
super(action);
|
2557 |
this.setBorderPainted(false); |
2558 |
this.setText(""); |
2559 |
} |
2560 |
|
2561 |
public Object getContext() { |
2562 |
return DefaultJScriptingComposer.this;
|
2563 |
} |
2564 |
} |
2565 |
|
2566 |
private class FindReplaceSearchListener implements SearchListener { |
2567 |
|
2568 |
@Override
|
2569 |
public void searchEvent(SearchEvent e) { |
2570 |
|
2571 |
RSyntaxTextArea textArea = getCurrentRSyntaxTextArea(); |
2572 |
if (textArea == null) { |
2573 |
return;
|
2574 |
} |
2575 |
|
2576 |
SearchEvent.Type type = e.getType(); |
2577 |
SearchContext context = e.getSearchContext(); |
2578 |
SearchResult result;
|
2579 |
|
2580 |
switch (type) {
|
2581 |
default: // Prevent FindBugs warning later |
2582 |
case MARK_ALL:
|
2583 |
result = SearchEngine.markAll(textArea, context); |
2584 |
break;
|
2585 |
case FIND:
|
2586 |
result = SearchEngine.find(textArea, context); |
2587 |
if (!result.wasFound()) {
|
2588 |
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
|
2589 |
} |
2590 |
break;
|
2591 |
case REPLACE:
|
2592 |
result = SearchEngine.replace(textArea, context); |
2593 |
if (!result.wasFound()) {
|
2594 |
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
|
2595 |
} |
2596 |
break;
|
2597 |
case REPLACE_ALL:
|
2598 |
result = SearchEngine.replaceAll(textArea, context); |
2599 |
JOptionPane.showMessageDialog(null, result.getCount() |
2600 |
+ " occurrences replaced.");
|
2601 |
break;
|
2602 |
} |
2603 |
String text;
|
2604 |
if (result.wasFound()) {
|
2605 |
text = "Text found; occurrences marked: " + result.getMarkedCount();
|
2606 |
} else if (type == SearchEvent.Type.MARK_ALL) { |
2607 |
if (result.getMarkedCount() > 0) { |
2608 |
text = "Occurrences marked: " + result.getMarkedCount();
|
2609 |
} else {
|
2610 |
text = "";
|
2611 |
} |
2612 |
} else {
|
2613 |
text = "Text not found";
|
2614 |
} |
2615 |
getStatusbar().message(text); |
2616 |
} |
2617 |
|
2618 |
@Override
|
2619 |
public String getSelectedText() { |
2620 |
RSyntaxTextArea textArea = getCurrentRSyntaxTextArea(); |
2621 |
if (textArea == null) { |
2622 |
return ""; |
2623 |
} |
2624 |
return textArea.getSelectedText();
|
2625 |
} |
2626 |
|
2627 |
} |
2628 |
} |