Revision 639 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
DefaultJScriptingComposer.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.BorderLayout; |
4 | 4 |
import java.awt.Color; |
5 |
import java.awt.Component; |
|
6 | 5 |
import java.awt.Cursor; |
7 | 6 |
import java.awt.Dialog; |
8 | 7 |
import java.awt.Dimension; |
9 |
import java.awt.FlowLayout; |
|
10 | 8 |
import java.awt.Font; |
11 | 9 |
import java.awt.event.ActionEvent; |
12 | 10 |
import java.awt.event.ActionListener; |
... | ... | |
14 | 12 |
import java.beans.PropertyChangeEvent; |
15 | 13 |
import java.beans.PropertyChangeListener; |
16 | 14 |
import java.io.File; |
17 |
import java.io.OutputStream;
|
|
18 |
import java.io.PrintStream;
|
|
15 |
import java.util.ArrayList;
|
|
16 |
import java.util.Date;
|
|
19 | 17 |
import java.util.HashMap; |
20 | 18 |
import java.util.HashSet; |
21 | 19 |
import java.util.Iterator; |
... | ... | |
30 | 28 |
import javax.swing.JButton; |
31 | 29 |
import javax.swing.JComponent; |
32 | 30 |
import javax.swing.JLabel; |
33 |
import javax.swing.JMenu; |
|
34 | 31 |
import javax.swing.JMenuBar; |
35 | 32 |
import javax.swing.JMenuItem; |
36 | 33 |
import javax.swing.JOptionPane; |
... | ... | |
39 | 36 |
import javax.swing.JSplitPane; |
40 | 37 |
import javax.swing.JTabbedPane; |
41 | 38 |
import javax.swing.JTable; |
42 |
import javax.swing.JTextArea; |
|
43 | 39 |
import javax.swing.JToolBar; |
44 | 40 |
import javax.swing.KeyStroke; |
45 | 41 |
import javax.swing.ListSelectionModel; |
46 | 42 |
import javax.swing.SwingConstants; |
47 | 43 |
import javax.swing.SwingUtilities; |
48 | 44 |
import javax.swing.UIManager; |
45 |
import javax.swing.event.AncestorEvent; |
|
46 |
import javax.swing.event.AncestorListener; |
|
49 | 47 |
import javax.swing.event.ChangeEvent; |
50 | 48 |
import javax.swing.event.ChangeListener; |
51 | 49 |
import javax.swing.event.ListSelectionEvent; |
52 | 50 |
import javax.swing.event.ListSelectionListener; |
53 | 51 |
import javax.swing.table.DefaultTableModel; |
54 |
import javax.swing.text.BadLocationException;
|
|
52 |
import javax.swing.table.TableModel;
|
|
55 | 53 |
import javax.swing.text.JTextComponent; |
56 | 54 |
import org.fife.rsta.ui.GoToDialog; |
57 | 55 |
import org.fife.rsta.ui.search.FindDialog; |
... | ... | |
68 | 66 |
import org.gvsig.scripting.CompileErrorException; |
69 | 67 |
import org.gvsig.scripting.ExecuteErrorException; |
70 | 68 |
import org.gvsig.scripting.ScriptingBaseScript; |
71 |
import org.gvsig.scripting.ScriptingDialog; |
|
72 | 69 |
import org.gvsig.scripting.ScriptingFolder; |
73 | 70 |
import org.gvsig.scripting.ScriptingManager; |
74 | 71 |
import org.gvsig.scripting.ScriptingNotification; |
... | ... | |
77 | 74 |
import org.gvsig.scripting.swing.api.JCodeEditor; |
78 | 75 |
import org.gvsig.scripting.swing.api.JEditor; |
79 | 76 |
import org.gvsig.scripting.swing.api.JScriptingBrowser; |
77 |
import org.gvsig.scripting.swing.api.JScriptingBrowser.BrowserActionEvent; |
|
80 | 78 |
import org.gvsig.scripting.swing.api.JScriptingComposer; |
79 |
import org.gvsig.scripting.swing.api.JScriptingComposer.Dock.DockedPanel; |
|
80 |
import org.gvsig.scripting.swing.api.JScriptingComposer.Problems; |
|
81 |
import org.gvsig.scripting.swing.api.JScriptingComposer.Problems.Problem; |
|
81 | 82 |
import org.gvsig.scripting.swing.api.JScriptingConsole; |
83 |
import org.gvsig.scripting.swing.api.JScriptingLauncher; |
|
82 | 84 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
83 | 85 |
import org.gvsig.scripting.swing.api.ScriptingUIManager.MenuEntry; |
84 | 86 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent.UpdateCaretPositionActionEvent; |
85 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingBrowser; |
|
86 | 87 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingConsole; |
87 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher; |
|
88 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher.LauncherActionEvent; |
|
89 | 88 |
import org.gvsig.scripting.swing.impl.DefaultScriptingUIManager; |
90 | 89 |
import org.gvsig.scripting.swing.impl.JDialogContent; |
91 | 90 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
96 | 95 |
import org.gvsig.tools.packageutils.PackageManager; |
97 | 96 |
import org.gvsig.tools.packageutils.Version; |
98 | 97 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
98 |
import org.gvsig.tools.swing.api.Component; |
|
99 | 99 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
100 | 100 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
101 | 101 |
import org.slf4j.Logger; |
102 | 102 |
import org.slf4j.LoggerFactory; |
103 | 103 |
|
104 |
public class DefaultJScriptingComposer extends JScriptingComposer implements Observer, ActionListener, SearchListener { |
|
105 |
private JToolBar tools; |
|
104 |
public class DefaultJScriptingComposer extends JPanel implements JScriptingComposer, Observer, ActionListener { |
|
106 | 105 |
|
106 |
/** |
|
107 |
* |
|
108 |
*/ |
|
109 |
private static final long serialVersionUID = 1L; |
|
110 |
|
|
111 |
private static final Logger logger = LoggerFactory.getLogger(DefaultJScriptingComposer.class); |
|
112 |
|
|
113 |
public static final int CLOSE_ACTION = 1; |
|
114 |
|
|
115 |
private final ScriptingUIManager uimanager; |
|
116 |
private final ScriptingManager manager; |
|
117 |
private final ClassLoader loader; |
|
118 |
|
|
119 |
private JSplitPane mainPanel; |
|
120 |
private Dock dock; |
|
121 |
|
|
122 |
private Map<String, ToolEntry> menus; |
|
123 |
private JMenuBar menuBar; |
|
124 |
|
|
125 |
private Map<String, ToolEntry> tools; |
|
126 |
private JToolBar toolBar; |
|
127 |
|
|
128 |
private StatusBar statusBar; |
|
129 |
|
|
130 |
private FindDialog findDialog; |
|
131 |
private ReplaceDialog replaceDialog; |
|
132 |
private GoToDialog gotoDialog; |
|
133 |
|
|
134 |
private ActionListener defaultActionlistener = null; |
|
135 |
|
|
136 |
private Set<ChangeListener> changeEditorListeners = null; |
|
137 |
|
|
107 | 138 |
private class GoToLineAction extends AbstractAction { |
108 | 139 |
|
140 |
private static final long serialVersionUID = -7353913671104893812L; |
|
141 |
|
|
109 | 142 |
public GoToLineAction() { |
110 | 143 |
super(uimanager.getTranslation("go_to_line_Xhorizontal_ellipsisX")); |
111 | 144 |
int c = getToolkit().getMenuShortcutKeyMask(); |
112 | 145 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L, c)); |
146 |
putValue(ACTION_COMMAND_KEY, "GotoLine"); |
|
113 | 147 |
} |
114 | 148 |
|
115 | 149 |
@Override |
116 | 150 |
public void actionPerformed(ActionEvent e) { |
117 |
|
|
118 |
RSyntaxTextArea textArea = getCurrentRSyntaxTextArea(); |
|
119 |
if (textArea == null) { |
|
151 |
JEditor editor = getCurrentEditor(); |
|
152 |
if (!(editor instanceof JCodeEditor)) { |
|
120 | 153 |
return; |
121 | 154 |
} |
122 |
|
|
155 |
JCodeEditor codeEditor = (JCodeEditor) editor; |
|
123 | 156 |
if (findDialog.isVisible()) { |
124 | 157 |
findDialog.setVisible(false); |
125 | 158 |
} |
126 | 159 |
if (replaceDialog.isVisible()) { |
127 | 160 |
replaceDialog.setVisible(false); |
128 | 161 |
} |
129 |
gotoDialog.setMaxLineNumberAllowed(textArea.getLineCount());
|
|
162 |
gotoDialog.setMaxLineNumberAllowed(codeEditor.getLineCount());
|
|
130 | 163 |
gotoDialog.setVisible(true); |
131 | 164 |
int line = gotoDialog.getLineNumber(); |
165 |
|
|
132 | 166 |
if (line > 0) { |
133 |
try { |
|
134 |
textArea.setCaretPosition(textArea.getLineStartOffset(line - 1)); |
|
135 |
} catch (BadLocationException ble) { // Never happens |
|
136 |
UIManager.getLookAndFeel().provideErrorFeedback(textArea); |
|
137 |
ble.printStackTrace(); |
|
138 |
} |
|
167 |
codeEditor.selectLine(line); |
|
139 | 168 |
} |
140 | 169 |
} |
170 |
|
|
171 |
@Override |
|
172 |
public boolean isEnabled() { |
|
173 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
174 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
|
175 |
} |
|
141 | 176 |
} |
142 | 177 |
|
143 | 178 |
private class ShowFindDialogAction extends AbstractAction { |
144 | 179 |
|
180 |
private static final long serialVersionUID = -7840632153011361661L; |
|
181 |
|
|
145 | 182 |
public ShowFindDialogAction() { |
146 | 183 |
super(uimanager.getTranslation("find_Xhorizontal_ellipsisX")); |
147 | 184 |
int c = getToolkit().getMenuShortcutKeyMask(); |
148 | 185 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, c)); |
186 |
putValue(ACTION_COMMAND_KEY, "ShowFindDialog"); |
|
149 | 187 |
} |
150 | 188 |
|
189 |
@Override |
|
151 | 190 |
public void actionPerformed(ActionEvent e) { |
152 | 191 |
if (replaceDialog.isVisible()) { |
153 | 192 |
replaceDialog.setVisible(false); |
154 | 193 |
} |
155 | 194 |
findDialog.setVisible(true); |
156 | 195 |
} |
196 |
|
|
197 |
@Override |
|
198 |
public boolean isEnabled() { |
|
199 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
200 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
|
201 |
} |
|
157 | 202 |
} |
158 | 203 |
|
159 | 204 |
private class ShowReplaceDialogAction extends AbstractAction { |
160 | 205 |
|
206 |
private static final long serialVersionUID = 7209167803487996060L; |
|
207 |
|
|
161 | 208 |
public ShowReplaceDialogAction() { |
162 | 209 |
super(uimanager.getTranslation("replace_Xhorizontal_ellipsisX")); |
163 | 210 |
int c = getToolkit().getMenuShortcutKeyMask(); |
164 | 211 |
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, c)); |
212 |
putValue(ACTION_COMMAND_KEY, "ShowReplaceDialog"); |
|
165 | 213 |
} |
166 | 214 |
|
167 | 215 |
@Override |
... | ... | |
171 | 219 |
} |
172 | 220 |
replaceDialog.setVisible(true); |
173 | 221 |
} |
222 |
|
|
223 |
@Override |
|
224 |
public boolean isEnabled() { |
|
225 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
226 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
|
227 |
} |
|
174 | 228 |
} |
175 | 229 |
|
176 | 230 |
private class LauncherAction extends AbstractAction { |
177 | 231 |
|
232 |
private static final long serialVersionUID = 6257776255757689286L; |
|
233 |
|
|
178 | 234 |
public LauncherAction() { |
179 | 235 |
super(uimanager.getTranslation("Launcher")); |
236 |
putValue(ACTION_COMMAND_KEY, "ShowLauncher"); |
|
180 | 237 |
} |
181 | 238 |
|
182 | 239 |
@Override |
183 | 240 |
public void actionPerformed(ActionEvent e) { |
184 | 241 |
getWindowManager().showWindow( |
185 |
uimanager.createLauncher(), |
|
242 |
uimanager.createLauncher().asJComponent(),
|
|
186 | 243 |
uimanager.getTranslation("Scripting_Launcher"), |
187 | 244 |
WindowManager.MODE.TOOL |
188 | 245 |
); |
... | ... | |
192 | 249 |
|
193 | 250 |
private class SelectAllAction extends AbstractAction { |
194 | 251 |
|
252 |
private static final long serialVersionUID = 2725549699989067383L; |
|
253 |
|
|
195 | 254 |
public SelectAllAction() { |
196 | 255 |
super(uimanager.getTranslation("Select_all")); |
197 | 256 |
putValue(Action.SMALL_ICON, uimanager.getIcon("edit-select-all")); |
198 | 257 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Select_all")); |
258 |
putValue(ACTION_COMMAND_KEY, "DocumentSelectAll"); |
|
199 | 259 |
} |
200 | 260 |
|
201 | 261 |
@Override |
... | ... | |
203 | 263 |
currentScriptSelectAll(); |
204 | 264 |
} |
205 | 265 |
|
266 |
@Override |
|
267 |
public boolean isEnabled() { |
|
268 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
269 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
|
270 |
} |
|
271 |
|
|
206 | 272 |
} |
207 | 273 |
|
208 | 274 |
private class PackageScriptAction extends AbstractAction { |
209 | 275 |
|
276 |
private static final long serialVersionUID = 8020393562984016720L; |
|
277 |
|
|
210 | 278 |
public PackageScriptAction() { |
211 | 279 |
super(uimanager.getTranslation("_Package_script")); |
212 | 280 |
putValue(Action.SMALL_ICON, uimanager.getIcon("package")); |
281 |
putValue(ACTION_COMMAND_KEY, "PackageScript"); |
|
213 | 282 |
} |
214 | 283 |
|
215 | 284 |
@Override |
... | ... | |
219 | 288 |
|
220 | 289 |
} |
221 | 290 |
|
222 |
private class ImportJavadocAction extends AbstractAction {
|
|
291 |
private class AboutAction extends AbstractAction {
|
|
223 | 292 |
|
224 |
public ImportJavadocAction() { |
|
225 |
super(uimanager.getTranslation("Import_JavaDoc")); |
|
226 |
putValue(Action.SMALL_ICON, uimanager.getIcon("list-add")); |
|
227 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Import_JavaDoc")); |
|
228 |
} |
|
293 |
private static final long serialVersionUID = -4928359535828269502L; |
|
229 | 294 |
|
230 |
@Override |
|
231 |
public void actionPerformed(ActionEvent e) { |
|
232 |
getWindowManager().showWindow( |
|
233 |
getImportHelpDialog(), |
|
234 |
uimanager.getTranslation("JavaDoc"), |
|
235 |
WindowManager.MODE.WINDOW |
|
236 |
); |
|
237 |
} |
|
238 |
|
|
239 |
} |
|
240 |
|
|
241 |
private class RemoveHelpAction extends AbstractAction { |
|
242 |
|
|
243 |
public RemoveHelpAction() { |
|
244 |
super(uimanager.getTranslation("Remove_help")); |
|
245 |
putValue(Action.SMALL_ICON, uimanager.getIcon("list-remove")); |
|
246 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Remove_JavaDoc")); |
|
247 |
} |
|
248 |
|
|
249 |
@Override |
|
250 |
public void actionPerformed(ActionEvent e) { |
|
251 |
try { |
|
252 |
//getRemoveHelpDialog(); |
|
253 |
JOptionPane.showMessageDialog( |
|
254 |
DefaultJScriptingComposer.this, |
|
255 |
"Falta por implementar", |
|
256 |
"Warning", |
|
257 |
JOptionPane.INFORMATION_MESSAGE |
|
258 |
); |
|
259 |
} catch (Exception e1) { |
|
260 |
logger.warn("Can't remove help",e1); |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
} |
|
265 |
|
|
266 |
private class HelpAction extends AbstractAction { |
|
267 |
|
|
268 |
public HelpAction() { |
|
269 |
super(uimanager.getTranslation("Help_contents")); |
|
270 |
int c = getToolkit().getMenuShortcutKeyMask(); |
|
271 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F1, c)); |
|
272 |
putValue(Action.SMALL_ICON, uimanager.getIcon("help-browser")); |
|
273 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Help_contents")); |
|
274 |
|
|
275 |
} |
|
276 |
|
|
277 |
@Override |
|
278 |
public void actionPerformed(ActionEvent e) { |
|
279 |
try { |
|
280 |
uimanager.showWindow( |
|
281 |
uimanager.getHelp(), |
|
282 |
uimanager.getTranslation("Help_contents") |
|
283 |
); |
|
284 |
} catch(Exception ex) { |
|
285 |
logger.warn("Can't show help dialog.",ex); |
|
286 |
JOptionPane.showMessageDialog( |
|
287 |
DefaultJScriptingComposer.this, |
|
288 |
uimanager.getTranslation("_Cant_show_help_dialog") |
|
289 |
+ "\n\n" |
|
290 |
+ uimanager.getTranslation("_See_the_error_log_for_more_information"), |
|
291 |
"_Warning", |
|
292 |
JOptionPane.WARNING_MESSAGE |
|
293 |
); |
|
294 |
} |
|
295 |
} |
|
296 |
|
|
297 |
} |
|
298 |
|
|
299 |
private class AboutAction extends AbstractAction { |
|
300 |
|
|
301 | 295 |
public AboutAction() { |
302 | 296 |
super(uimanager.getTranslation("About_scripts_editor")); |
303 | 297 |
putValue(Action.SMALL_ICON, uimanager.getIcon("about")); |
304 | 298 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("About_scripts_editor")); |
299 |
putValue(ACTION_COMMAND_KEY, "About"); |
|
305 | 300 |
} |
306 | 301 |
|
307 | 302 |
@Override |
... | ... | |
317 | 312 |
|
318 | 313 |
private class CutAction extends AbstractAction { |
319 | 314 |
|
315 |
private static final long serialVersionUID = -8549655706085425411L; |
|
316 |
|
|
320 | 317 |
public CutAction() { |
321 | 318 |
super(uimanager.getTranslation("Cut")); |
322 | 319 |
putValue(Action.SMALL_ICON, uimanager.getIcon("edit-cut")); |
323 | 320 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Cut")); |
321 |
putValue(ACTION_COMMAND_KEY, "DocumentCut"); |
|
324 | 322 |
} |
325 | 323 |
|
326 | 324 |
@Override |
... | ... | |
328 | 326 |
currentScriptCut(); |
329 | 327 |
} |
330 | 328 |
|
329 |
@Override |
|
330 |
public boolean isEnabled() { |
|
331 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
332 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
|
333 |
} |
|
334 |
|
|
331 | 335 |
} |
332 | 336 |
|
333 | 337 |
private class CopyAction extends AbstractAction { |
334 | 338 |
|
339 |
private static final long serialVersionUID = -6870773810752024874L; |
|
340 |
|
|
335 | 341 |
public CopyAction() { |
336 | 342 |
super(uimanager.getTranslation("Copy")); |
337 | 343 |
putValue(Action.SMALL_ICON, uimanager.getIcon("edit-copy")); |
338 | 344 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Copy")); |
345 |
putValue(ACTION_COMMAND_KEY, "DocumentCopy"); |
|
339 | 346 |
} |
340 | 347 |
|
341 | 348 |
@Override |
... | ... | |
343 | 350 |
currentScriptCopy(); |
344 | 351 |
} |
345 | 352 |
|
353 |
@Override |
|
354 |
public boolean isEnabled() { |
|
355 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
356 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
|
357 |
} |
|
358 |
|
|
346 | 359 |
} |
347 | 360 |
|
348 | 361 |
private class PasteAction extends AbstractAction { |
349 | 362 |
|
363 |
private static final long serialVersionUID = -5829551248494873061L; |
|
364 |
|
|
350 | 365 |
public PasteAction() { |
351 | 366 |
super(uimanager.getTranslation("Paste")); |
352 | 367 |
putValue(Action.SMALL_ICON, uimanager.getIcon("edit-paste")); |
353 | 368 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Paste")); |
369 |
putValue(ACTION_COMMAND_KEY, "DocumentPaste"); |
|
354 | 370 |
} |
355 | 371 |
|
356 | 372 |
@Override |
... | ... | |
358 | 374 |
currentScriptPaste(); |
359 | 375 |
} |
360 | 376 |
|
377 |
@Override |
|
378 |
public boolean isEnabled() { |
|
379 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
380 |
return panel != null && panel.getComponent() instanceof JCodeEditor; |
|
381 |
} |
|
382 |
|
|
361 | 383 |
} |
362 | 384 |
|
363 | 385 |
private class ExitAction extends AbstractAction { |
364 | 386 |
|
387 |
private static final long serialVersionUID = 9165363564675325925L; |
|
388 |
|
|
365 | 389 |
public ExitAction() { |
366 | 390 |
super(uimanager.getTranslation("Close")); |
367 | 391 |
putValue(Action.SMALL_ICON, uimanager.getIcon("exit")); |
368 | 392 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close")); |
393 |
putValue(ACTION_COMMAND_KEY, "CloseComposer"); |
|
369 | 394 |
} |
370 | 395 |
|
371 | 396 |
@Override |
... | ... | |
382 | 407 |
|
383 | 408 |
private class SaveAction extends AbstractAction { |
384 | 409 |
|
410 |
private static final long serialVersionUID = -870379961486387727L; |
|
411 |
|
|
385 | 412 |
public SaveAction() { |
386 | 413 |
super(uimanager.getTranslation("Save")); |
387 | 414 |
int c = getToolkit().getMenuShortcutKeyMask(); |
388 | 415 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, c)); |
389 | 416 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-save")); |
390 | 417 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Save")); |
418 |
putValue(ACTION_COMMAND_KEY, "DocumentSave"); |
|
391 | 419 |
} |
392 | 420 |
|
393 | 421 |
@Override |
394 | 422 |
public void actionPerformed(ActionEvent e) { |
395 | 423 |
currentScriptSave(); |
396 | 424 |
} |
425 |
|
|
426 |
@Override |
|
427 |
public boolean isEnabled() { |
|
428 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
429 |
return panel != null; |
|
430 |
} |
|
397 | 431 |
} |
398 | 432 |
|
399 | 433 |
private class RunAction extends AbstractAction { |
400 | 434 |
|
435 |
private static final long serialVersionUID = 4851968883766990149L; |
|
436 |
|
|
401 | 437 |
public RunAction() { |
402 | 438 |
super(uimanager.getTranslation("Run")); |
403 | 439 |
int c = getToolkit().getMenuShortcutKeyMask(); |
404 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F5,0)); |
|
440 |
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
|
|
405 | 441 |
putValue(Action.SMALL_ICON, uimanager.getIcon("run")); |
406 | 442 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Run")); |
443 |
putValue(ACTION_COMMAND_KEY, "DocumentRun"); |
|
407 | 444 |
} |
408 | 445 |
|
409 | 446 |
@Override |
... | ... | |
411 | 448 |
currentScriptExecute(); |
412 | 449 |
} |
413 | 450 |
|
451 |
@Override |
|
452 |
public boolean isEnabled() { |
|
453 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
454 |
return panel != null; |
|
455 |
} |
|
414 | 456 |
} |
415 | 457 |
|
416 | 458 |
private class CloseAllAction extends AbstractAction { |
417 | 459 |
|
460 |
private static final long serialVersionUID = 3385142920283598457L; |
|
461 |
|
|
418 | 462 |
public CloseAllAction() { |
419 | 463 |
super(uimanager.getTranslation("Close_all_documents")); |
420 | 464 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-closeall")); |
421 | 465 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close_all_documents")); |
466 |
putValue(ACTION_COMMAND_KEY, "CloseAll"); |
|
422 | 467 |
} |
423 | 468 |
|
424 | 469 |
@Override |
425 | 470 |
public void actionPerformed(ActionEvent e) { |
426 |
closeAllScripts(); |
|
471 |
closeAllScripts();
|
|
427 | 472 |
} |
428 | 473 |
|
474 |
@Override |
|
475 |
public boolean isEnabled() { |
|
476 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
477 |
return panel != null; |
|
478 |
} |
|
479 |
|
|
429 | 480 |
} |
430 | 481 |
|
431 |
private class CloseTabAction extends AbstractAction {
|
|
482 |
private class CloseDocumentAction extends AbstractAction {
|
|
432 | 483 |
|
433 |
private final Component component;
|
|
434 |
|
|
435 |
public CloseTabAction(Component component) {
|
|
436 |
super(uimanager.getTranslation("Close_tab"));
|
|
484 |
private static final long serialVersionUID = 4152188500446249755L;
|
|
485 |
|
|
486 |
public CloseDocumentAction() {
|
|
487 |
super(uimanager.getTranslation("Close_document"));
|
|
437 | 488 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-close")); |
438 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close_tab")); |
|
439 |
this.component = component;
|
|
489 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close_current_tab"));
|
|
490 |
putValue(ACTION_COMMAND_KEY, "DocumentClose");
|
|
440 | 491 |
} |
441 | 492 |
|
442 | 493 |
@Override |
443 | 494 |
public void actionPerformed(ActionEvent e) { |
444 |
int index = scriptEditors.indexOfComponent(component); |
|
445 |
if( index == -1 ) { |
|
446 |
return; |
|
447 |
} |
|
448 |
scriptClose(index); |
|
495 |
currentScriptClose(); |
|
449 | 496 |
} |
450 | 497 |
|
498 |
@Override |
|
499 |
public boolean isEnabled() { |
|
500 |
DockedPanel panel = dock.getSelected(Dock.DOCK_CENTER); |
|
501 |
return panel != null; |
|
502 |
} |
|
503 |
|
|
451 | 504 |
} |
452 |
|
|
453 |
private class CloseDocumentAction extends AbstractAction { |
|
454 | 505 |
|
455 |
public CloseDocumentAction() { |
|
456 |
super(uimanager.getTranslation("Close_document")); |
|
457 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-close")); |
|
458 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Close_current_tab")); |
|
506 |
private class ShowConsoleAction extends AbstractAction { |
|
507 |
|
|
508 |
private static final long serialVersionUID = -7545333555439711068L; |
|
509 |
|
|
510 |
public ShowConsoleAction() { |
|
511 |
super(uimanager.getTranslation("Console")); |
|
512 |
putValue(Action.SMALL_ICON, uimanager.getIcon("show-console")); |
|
513 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Show_console_panel")); |
|
514 |
putValue(ACTION_COMMAND_KEY, "ShowConsole"); |
|
459 | 515 |
} |
460 | 516 |
|
461 | 517 |
@Override |
462 | 518 |
public void actionPerformed(ActionEvent e) { |
463 |
currentScriptClose();
|
|
519 |
addConsolePanel();
|
|
464 | 520 |
} |
521 |
} |
|
465 | 522 |
|
523 |
private class ShowProblemsAction extends AbstractAction { |
|
524 |
|
|
525 |
private static final long serialVersionUID = 5276964996914550830L; |
|
526 |
|
|
527 |
public ShowProblemsAction() { |
|
528 |
super(uimanager.getTranslation("Problems")); |
|
529 |
putValue(Action.SMALL_ICON, uimanager.getIcon("show-problems")); |
|
530 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Show_problems_panel")); |
|
531 |
putValue(ACTION_COMMAND_KEY, "ShowProblems"); |
|
532 |
} |
|
533 |
|
|
534 |
@Override |
|
535 |
public void actionPerformed(ActionEvent e) { |
|
536 |
addProblemsPanel(); |
|
537 |
} |
|
466 | 538 |
} |
467 | 539 |
|
540 |
private class ShowProjectsAction extends AbstractAction { |
|
541 |
|
|
542 |
private static final long serialVersionUID = 5873598740133693862L; |
|
543 |
|
|
544 |
public ShowProjectsAction() { |
|
545 |
super(uimanager.getTranslation("Projects")); |
|
546 |
putValue(Action.SMALL_ICON, uimanager.getIcon("show-projects")); |
|
547 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Show_projects_panel")); |
|
548 |
putValue(ACTION_COMMAND_KEY, "ShowProjects"); |
|
549 |
} |
|
550 |
|
|
551 |
@Override |
|
552 |
public void actionPerformed(ActionEvent e) { |
|
553 |
addProjectsPanel(); |
|
554 |
} |
|
555 |
} |
|
556 |
|
|
468 | 557 |
private class NewDocumentAction extends AbstractAction { |
469 | 558 |
|
559 |
private static final long serialVersionUID = 7889613706183211620L; |
|
560 |
|
|
470 | 561 |
public NewDocumentAction() { |
471 | 562 |
super(uimanager.getTranslation("New")); |
472 | 563 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-add")); |
473 | 564 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("New")); |
565 |
putValue(ACTION_COMMAND_KEY, "DocumentNew"); |
|
474 | 566 |
} |
475 | 567 |
|
476 | 568 |
@Override |
... | ... | |
478 | 570 |
try { |
479 | 571 |
scriptNew(); |
480 | 572 |
} catch (Exception e1) { |
481 |
logger.warn("Can't create a new document",e1); |
|
573 |
logger.warn("Can't create a new document", e1);
|
|
482 | 574 |
} |
483 | 575 |
} |
484 | 576 |
|
485 | 577 |
} |
486 | 578 |
|
487 |
private class EditAction extends AbstractAction { |
|
579 |
private class ProjectEditAction extends AbstractAction {
|
|
488 | 580 |
|
489 |
public EditAction() { |
|
581 |
private static final long serialVersionUID = -3393464285985649074L; |
|
582 |
|
|
583 |
public ProjectEditAction() { |
|
490 | 584 |
super(uimanager.getTranslation("Edit")); |
491 | 585 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-edit")); |
492 | 586 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Open_edition_mode")); |
587 |
putValue(ACTION_COMMAND_KEY, "DocumentEdit"); |
|
493 | 588 |
} |
494 | 589 |
|
495 | 590 |
@Override |
496 | 591 |
public void actionPerformed(ActionEvent e) { |
497 | 592 |
try { |
498 | 593 |
ScriptingUnit selectedItem = getLauncherSelectedScript(); |
499 |
if( selectedItem instanceof ScriptingBaseScript ) {
|
|
500 |
scriptEdit((ScriptingBaseScript)selectedItem); |
|
594 |
if (selectedItem instanceof ScriptingBaseScript) {
|
|
595 |
scriptEdit((ScriptingBaseScript) selectedItem);
|
|
501 | 596 |
} |
502 | 597 |
} catch (Exception e1) { |
503 |
logger.warn("Can't edit document",e1); |
|
598 |
logger.warn("Can't edit document", e1);
|
|
504 | 599 |
} |
505 | 600 |
} |
506 | 601 |
} |
507 | 602 |
|
508 |
private class RefreshTreeAction extends AbstractAction {
|
|
603 |
private class ProjectRefreshAction extends AbstractAction {
|
|
509 | 604 |
|
510 |
public RefreshTreeAction() { |
|
605 |
private static final long serialVersionUID = 1944121660002532563L; |
|
606 |
|
|
607 |
public ProjectRefreshAction() { |
|
511 | 608 |
super(uimanager.getTranslation("Refresh")); |
512 | 609 |
putValue(Action.SMALL_ICON, uimanager.getIcon("refresh")); |
513 | 610 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Refresh_directories")); |
611 |
putValue(ACTION_COMMAND_KEY, "ProjectsRefresh"); |
|
514 | 612 |
} |
515 | 613 |
|
516 | 614 |
@Override |
517 | 615 |
public void actionPerformed(ActionEvent e) { |
518 |
launcherRefresh();
|
|
616 |
refreshProjects();
|
|
519 | 617 |
} |
520 | 618 |
|
521 | 619 |
} |
522 | 620 |
|
523 |
private class RenameAction extends AbstractAction { |
|
621 |
private class ProjectRenameAction extends AbstractAction {
|
|
524 | 622 |
|
525 |
public RenameAction() { |
|
623 |
private static final long serialVersionUID = 7469858242486966790L; |
|
624 |
|
|
625 |
public ProjectRenameAction() { |
|
526 | 626 |
super(uimanager.getTranslation("Rename")); |
527 | 627 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-rename")); |
528 | 628 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Set_file_properties")); |
629 |
putValue(ACTION_COMMAND_KEY, "Rename"); |
|
529 | 630 |
} |
530 | 631 |
|
531 | 632 |
@Override |
... | ... | |
533 | 634 |
try { |
534 | 635 |
scriptRename(getLauncherSelectedScript()); |
535 | 636 |
} catch (Exception e1) { |
536 |
logger.warn("Can't rename document",e1); |
|
637 |
logger.warn("Can't rename document", e1);
|
|
537 | 638 |
} |
538 | 639 |
} |
539 | 640 |
} |
540 | 641 |
|
541 |
private class MoveAction extends AbstractAction { |
|
642 |
private class ProjectMoveAction extends AbstractAction {
|
|
542 | 643 |
|
543 |
public MoveAction() { |
|
644 |
private static final long serialVersionUID = -8857101021126773295L; |
|
645 |
|
|
646 |
public ProjectMoveAction() { |
|
544 | 647 |
super(uimanager.getTranslation("Move")); |
545 | 648 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-move")); |
546 | 649 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Move_files")); |
650 |
putValue(ACTION_COMMAND_KEY, "Move"); |
|
547 | 651 |
} |
548 | 652 |
|
549 | 653 |
@Override |
... | ... | |
551 | 655 |
try { |
552 | 656 |
scriptMove(getLauncherSelectedScript()); |
553 | 657 |
} catch (Exception e1) { |
554 |
logger.warn("Can't move document",e1); |
|
658 |
logger.warn("Can't move document", e1);
|
|
555 | 659 |
} |
556 | 660 |
} |
557 | 661 |
} |
558 | 662 |
|
559 |
private class DeleteAction extends AbstractAction { |
|
663 |
private class ProjectDeleteAction extends AbstractAction {
|
|
560 | 664 |
|
561 |
public DeleteAction() { |
|
665 |
private static final long serialVersionUID = 9039455504757742743L; |
|
666 |
|
|
667 |
public ProjectDeleteAction() { |
|
562 | 668 |
super(uimanager.getTranslation("Delete")); |
563 | 669 |
putValue(Action.SMALL_ICON, uimanager.getIcon("doc-remove")); |
564 | 670 |
putValue(Action.SHORT_DESCRIPTION, uimanager.getTranslation("Delete_selected_script")); |
671 |
putValue(ACTION_COMMAND_KEY, "Delete"); |
|
565 | 672 |
} |
566 | 673 |
|
567 | 674 |
@Override |
... | ... | |
569 | 676 |
try { |
570 | 677 |
scriptDelete(getLauncherSelectedScript(), false); |
571 | 678 |
} catch (Exception e1) { |
572 |
logger.warn("Can't delete document",e1); |
|
679 |
logger.warn("Can't delete document", e1);
|
|
573 | 680 |
} |
574 | 681 |
} |
575 | 682 |
} |
576 | 683 |
|
577 |
private class IndexHelpAction extends AbstractAction { |
|
578 |
|
|
579 |
public IndexHelpAction() { |
|
580 |
super(uimanager.getTranslation("Index_help")); |
|
581 |
} |
|
582 |
|
|
583 |
@Override |
|
584 |
public void actionPerformed(ActionEvent e) { |
|
585 |
JOptionPane.showMessageDialog( |
|
586 |
DefaultJScriptingComposer.this, |
|
587 |
"Falta por implementar", |
|
588 |
"Warning", |
|
589 |
JOptionPane.INFORMATION_MESSAGE |
|
590 |
); |
|
591 |
} |
|
592 |
} |
|
593 |
|
|
594 |
private class PackageHelpAction extends AbstractAction { |
|
595 |
|
|
596 |
public PackageHelpAction() { |
|
597 |
super(uimanager.getTranslation("_Package_help")); |
|
598 |
} |
|
599 |
|
|
600 |
@Override |
|
601 |
public void actionPerformed(ActionEvent e) { |
|
602 |
createHelpPackage(); |
|
603 |
} |
|
604 |
} |
|
605 |
|
|
606 | 684 |
/** |
607 |
* |
|
608 |
*/ |
|
609 |
private static final long serialVersionUID = 1L; |
|
610 |
|
|
611 |
private static final Logger logger = LoggerFactory.getLogger(DefaultJScriptingComposer.class); |
|
612 |
|
|
613 |
public static final int CLOSE_ACTION = 1; |
|
614 |
private final Map<String, JEditor> unitsEditor; |
|
615 |
private final Map<JEditor,Boolean> editorTabModified; // Cachea si el tab del editor esta marcado como modificado |
|
616 |
|
|
617 |
/* Generales */ |
|
618 |
ScriptingUIManager uimanager; |
|
619 |
ScriptingManager manager; |
|
620 |
ClassLoader loader; |
|
621 |
|
|
622 |
/* Ventana inicial y componentes*/ |
|
623 |
JSplitPane mainPane; |
|
624 |
JSplitPane editionPane; |
|
625 |
private JMyTabbedPane bottomTab; |
|
626 |
private JMyTabbedPane leftTab; |
|
627 |
|
|
628 |
JMyTabbedPane scriptEditors; |
|
629 |
JMenuBar menuBar; |
|
630 |
JToolBar file; |
|
631 |
JToolBar edit; |
|
632 |
JToolBar script; |
|
633 |
JToolBar help; |
|
634 |
JPanel statusBar; |
|
635 |
JLabel currentLine; |
|
636 |
JLabel statusBarMessage; |
|
637 |
JTextArea problems; |
|
638 |
JScriptingConsole console; |
|
639 |
DefaultJScriptingLauncher launcher; |
|
640 |
JToolBar launcherButtons; |
|
641 |
PrintStream consolePrintStream = null; |
|
642 |
|
|
643 |
private FindDialog findDialog; |
|
644 |
private ReplaceDialog replaceDialog; |
|
645 |
private GoToDialog gotoDialog; |
|
646 |
|
|
647 |
JTable table; |
|
648 |
DefaultTableModel tableModel; |
|
649 |
protected ActionListener defaultActionlistener = null; |
|
650 |
|
|
651 |
private Set<ChangeListener> changeEditorListeners = null; |
|
652 |
|
|
653 |
/** |
|
654 | 685 |
* Instanciacion de un JComposer con todos sus elementos y acciones |
655 | 686 |
* |
656 | 687 |
* @param uimanager |
... | ... | |
659 | 690 |
loader = this.getClass().getClassLoader(); |
660 | 691 |
this.uimanager = uimanager; |
661 | 692 |
this.manager = uimanager.getManager(); |
662 |
|
|
663 |
this.unitsEditor = new LinkedHashMap<>(); |
|
664 |
this.editorTabModified = new HashMap<>(); |
|
665 | 693 |
initComponents(); |
666 | 694 |
} |
667 | 695 |
|
668 | 696 |
@Override |
697 |
public JComponent asJComponent() { |
|
698 |
return this; |
|
699 |
} |
|
700 |
|
|
701 |
@Override |
|
669 | 702 |
public WindowManager getWindowManager() { |
670 |
return ((DefaultScriptingUIManager)(this.uimanager)).getWindowManager(); |
|
703 |
return ((DefaultScriptingUIManager) (this.uimanager)).getWindowManager();
|
|
671 | 704 |
} |
672 | 705 |
|
673 | 706 |
@Override |
674 | 707 |
public void setWindowManager(WindowManager windowsManager) { |
675 |
((DefaultScriptingUIManager)(this.uimanager)).setWindowManager(windowsManager); |
|
708 |
((DefaultScriptingUIManager) (this.uimanager)).setWindowManager(windowsManager);
|
|
676 | 709 |
} |
677 | 710 |
|
678 | 711 |
private void initComponents() { |
679 | 712 |
|
680 |
findDialog = new FindDialog((Dialog)null, this); |
|
681 |
replaceDialog = new ReplaceDialog((Dialog)null, this); |
|
713 |
this.addAncestorListener(new AncestorListener() { |
|
714 |
|
|
715 |
@Override |
|
716 |
public void ancestorAdded(AncestorEvent event) { |
|
717 |
((DefaultScriptingUIManager) uimanager).setActiveComposer(DefaultJScriptingComposer.this); |
|
718 |
} |
|
719 |
|
|
720 |
@Override |
|
721 |
public void ancestorRemoved(AncestorEvent event) { |
|
722 |
((DefaultScriptingUIManager) uimanager).setActiveComposer(null); |
|
723 |
} |
|
724 |
|
|
725 |
@Override |
|
726 |
public void ancestorMoved(AncestorEvent event) { |
|
727 |
} |
|
728 |
}); |
|
729 |
SearchListener findReplaceSearchListener = new FindReplaceSearchListener(); |
|
730 |
|
|
731 |
findDialog = new FindDialog((Dialog) null, findReplaceSearchListener); |
|
732 |
replaceDialog = new ReplaceDialog((Dialog) null, findReplaceSearchListener); |
|
682 | 733 |
gotoDialog = new GoToDialog((Dialog) null); |
683 | 734 |
|
684 | 735 |
SearchContext searchContext = findDialog.getSearchContext(); |
685 | 736 |
replaceDialog.setSearchContext(searchContext); |
686 | 737 |
|
687 |
// Barra de menu
|
|
688 |
menuBar = new JMenuBar();
|
|
738 |
this.menuBar = new JMenuBar();
|
|
739 |
this.toolBar = new JToolBar();
|
|
689 | 740 |
|
690 |
// Construimos los componentes del menu |
|
691 |
JMenu menu_file = new JMenu(this.uimanager.getTranslation("File")); |
|
692 |
menu_file.add(new JMenuItem(new NewDocumentAction())); |
|
693 |
menu_file.addSeparator(); |
|
694 |
menu_file.add(new JMenuItem(new CloseDocumentAction())); |
|
695 |
menu_file.add(new JMenuItem(new CloseAllAction())); |
|
696 |
menu_file.addSeparator(); |
|
697 |
menu_file.add(new JMenuItem(new RunAction())); |
|
698 |
menu_file.addSeparator(); |
|
699 |
menu_file.add(new JMenuItem(new SaveAction())); |
|
700 |
menu_file.addSeparator(); |
|
701 |
menu_file.add(new JMenuItem(new ExitAction())); |
|
741 |
this.menus = new LinkedHashMap<>(); |
|
742 |
this.tools = new LinkedHashMap<>(); |
|
702 | 743 |
|
703 |
JMenu menu_edit = new JMenu(this.uimanager.getTranslation("Edit")); |
|
704 |
menu_edit.add(new JMenuItem(new CutAction())); |
|
705 |
menu_edit.add(new JMenuItem(new CopyAction())); |
|
706 |
menu_edit.add(new JMenuItem(new PasteAction())); |
|
707 |
menu_edit.addSeparator(); |
|
708 |
menu_edit.add(new JMenuItem(new SelectAllAction())); |
|
709 |
menu_edit.addSeparator(); |
|
710 |
menu_edit.add(new JMenuItem(new ShowFindDialogAction())); |
|
711 |
menu_edit.add(new JMenuItem(new ShowReplaceDialogAction())); |
|
712 |
menu_edit.add(new JMenuItem(new GoToLineAction())); |
|
744 |
String _File = this.uimanager.getTranslation("File"); |
|
745 |
String _Edit = this.uimanager.getTranslation("Edit"); |
|
746 |
String _Projects = this.uimanager.getTranslation("Projects"); |
|
747 |
String _Tools = this.uimanager.getTranslation("Tools"); |
|
748 |
String _Help = this.uimanager.getTranslation("Help"); |
|
749 |
String _View = this.uimanager.getTranslation("Show"); |
|
713 | 750 |
|
714 |
JMenu menu_tools = new JMenu(this.uimanager.getTranslation("Tools")); |
|
715 |
menu_tools.add(new JMenuItem(new LauncherAction())); |
|
716 |
menu_tools.addSeparator(); |
|
717 |
menu_tools.add(new JMenuItem(new PackageScriptAction())); |
|
751 |
this.addMenu(_File, null); |
|
752 |
this.addMenu(_File, new NewDocumentAction()); |
|
753 |
this.addMenuSeparator(_File); |
|
754 |
this.addMenu(_File, new CloseDocumentAction()); |
|
755 |
this.addMenu(_File, new CloseAllAction()); |
|
756 |
this.addMenuSeparator(_File); |
|
757 |
this.addMenu(_File, new RunAction()); |
|
758 |
this.addMenuSeparator(_File); |
|
759 |
this.addMenu(_File, new SaveAction()); |
|
760 |
this.addMenuSeparator(_File); |
|
761 |
this.addMenu(_File, new ExitAction()); |
|
718 | 762 |
|
719 |
JMenu menu_help = new JMenu("Help"); |
|
720 |
menu_help.add(new JMenuItem(new AboutAction())); |
|
763 |
this.addMenu(_Edit, null); |
|
764 |
this.addMenu(_Edit, new CutAction()); |
|
765 |
this.addMenu(_Edit, new CopyAction()); |
|
766 |
this.addMenu(_Edit, new PasteAction()); |
|
767 |
this.addMenuSeparator(_Edit); |
|
768 |
this.addMenu(_Edit, new SelectAllAction()); |
|
769 |
this.addMenuSeparator(_Edit); |
|
770 |
this.addMenu(_Edit, new ShowFindDialogAction()); |
|
771 |
this.addMenu(_Edit, new ShowReplaceDialogAction()); |
|
772 |
this.addMenu(_Edit, new GoToLineAction()); |
|
721 | 773 |
|
722 |
menuBar.add(menu_file);
|
|
723 |
menuBar.add(menu_edit);
|
|
724 |
menuBar.add(menu_tools);
|
|
725 |
menuBar.add(menu_help);
|
|
774 |
this.addMenu(_View, null);
|
|
775 |
this.addMenu(_View, new ShowProjectsAction());
|
|
776 |
this.addMenu(_View, new ShowProblemsAction());
|
|
777 |
this.addMenu(_View, new ShowConsoleAction());
|
|
726 | 778 |
|
727 |
// Botones |
|
728 |
file = new JToolBar(); |
|
729 |
help = new JToolBar(); |
|
730 |
edit = new JToolBar(); |
|
731 |
script = new JToolBar(); |
|
732 |
this.tools = new JToolBar(); |
|
733 |
setButtonsDefault(); |
|
734 |
JPanel scriptButtonsPane = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0)); |
|
735 |
scriptButtonsPane.add(file); |
|
736 |
scriptButtonsPane.add(edit); |
|
737 |
scriptButtonsPane.add(this.tools); |
|
779 |
this.addMenu(_Projects, null); |
|
780 |
this.addMenu(_Projects, new ProjectEditAction()); |
|
781 |
this.addMenuSeparator(_Projects); |
|
782 |
this.addMenu(_Projects, new ProjectRefreshAction()); |
|
783 |
this.addMenuSeparator(_Projects); |
|
784 |
this.addMenu(_Projects, new ProjectRenameAction()); |
|
785 |
this.addMenu(_Projects, new ProjectMoveAction()); |
|
738 | 786 |
|
739 |
scriptButtonsPane.add(script, BorderLayout.CENTER);
|
|
740 |
JPanel buttonsPane = new JPanel(new BorderLayout());
|
|
741 |
buttonsPane.add(scriptButtonsPane, BorderLayout.LINE_START);
|
|
742 |
buttonsPane.add(help, BorderLayout.LINE_END);
|
|
787 |
this.addMenu(_Tools, null);
|
|
788 |
this.addMenu(_Tools, new LauncherAction());
|
|
789 |
this.addMenuSeparator(_Tools);
|
|
790 |
this.addMenu(_Tools, new PackageScriptAction());
|
|
743 | 791 |
|
744 |
JPanel launcherPane = new JPanel(new BorderLayout()); |
|
745 |
launcher = (DefaultJScriptingLauncher) uimanager.createLauncher(); |
|
746 |
launcher.addDefaultActionListener(this); |
|
747 |
launcher.setPreferredSize(new Dimension(200, 450)); |
|
748 |
launcherButtons = new JToolBar(SwingConstants.VERTICAL); |
|
749 |
setButtonsLauncherPanel(); |
|
792 |
this.addMenu(_Help, null); |
|
793 |
this.addMenu(_Help, new AboutAction()); |
|
750 | 794 |
|
751 |
launcherPane.add(launcher, BorderLayout.CENTER); |
|
752 |
launcherPane.add(launcherButtons, BorderLayout.WEST); |
|
795 |
this.addTool(new NewDocumentAction()); |
|
796 |
this.addTool(new SaveAction()); |
|
797 |
this.addTool(new CutAction()); |
|
798 |
this.addTool(new CopyAction()); |
|
799 |
this.addTool(new PasteAction()); |
|
800 |
this.addTool(new RunAction()); |
|
753 | 801 |
|
754 |
// Panel de Edicion
|
|
755 |
scriptEditors = new JMyTabbedPane();
|
|
756 |
scriptEditors.addCloseTabListener(new ActionListener() {
|
|
802 |
JTabbedPaneClosable tabbedPanelLeft = new JTabbedPaneClosable(uimanager);
|
|
803 |
JTabbedPaneClosable tabbedPanelBottom = new JTabbedPaneClosable(uimanager);
|
|
804 |
JTabbedPaneClosable tabbedPanelCenter = new JTabbedPaneClosable(uimanager);
|
|
757 | 805 |
|
806 |
tabbedPanelLeft.setTabPlacement(JTabbedPane.BOTTOM); |
|
807 |
tabbedPanelCenter.setPreferredSize(new Dimension(500, 300)); |
|
808 |
tabbedPanelCenter.addChangeListener(new ChangeListener() { |
|
809 |
|
|
758 | 810 |
@Override |
759 |
public void actionPerformed(ActionEvent ae) {
|
|
760 |
currentScriptClose();
|
|
811 |
public void stateChanged(ChangeEvent e) {
|
|
812 |
updateMenusAndTools();
|
|
761 | 813 |
} |
762 | 814 |
}); |
763 |
|
|
764 |
scriptEditors.addChangeListener(new ChangeListener() { |
|
815 |
|
|
816 |
this.dock = new DefaultDock( |
|
817 |
tabbedPanelLeft, |
|
818 |
tabbedPanelBottom, |
|
819 |
tabbedPanelCenter |
|
820 |
); |
|
821 |
this.dock.addCloseListener(new ActionListener() { |
|
822 |
|
|
765 | 823 |
@Override |
766 |
public void stateChanged(ChangeEvent arg0) { |
|
767 |
JPanel editor = (JPanel) scriptEditors.getSelectedComponent(); |
|
768 |
if (scriptEditors.getSelectedIndex() == -1) { |
|
769 |
setButtonsDefault(); |
|
770 |
} else if (editor instanceof DefaultJDialogEditor) { |
|
771 |
setButtonsDialog(); |
|
772 |
} else if (editor instanceof DefaultJCodeEditor) { |
|
773 |
setButtonsScript(); |
|
774 |
} |
|
775 |
fireChangeEditor(new ChangeEvent(DefaultJScriptingComposer.this)); |
|
824 |
public void actionPerformed(ActionEvent e) { |
|
825 |
DockedPanel panel = (DockedPanel) e.getSource(); |
|
826 |
scriptClose(panel); |
|
776 | 827 |
} |
777 | 828 |
}); |
778 |
scriptEditors.setPreferredSize(new Dimension(500, 350)); |
|
779 |
bottomTab = new JMyTabbedPane(); |
|
829 |
tabbedPanelBottom.setPreferredSize(new Dimension(450, 100)); |
|
780 | 830 |
|
781 |
tableModel = new AbstractTableModel(); |
|
782 |
tableModel.addColumn(this.uimanager.getTranslation("Description")); |
|
783 |
tableModel.addColumn(this.uimanager.getTranslation("Resource")); |
|
784 |
tableModel.addColumn(this.uimanager.getTranslation("Location")); |
|
785 |
table = new JTable(tableModel); |
|
786 |
table.getColumnModel().getColumn(0).setPreferredWidth(300); |
|
831 |
this.addProjectsPanel(); |
|
832 |
this.addConsolePanel(); |
|
833 |
this.addProblemsPanel(); |
|
787 | 834 |
|
788 |
table.getSelectionModel().addListSelectionListener(new RowListener()); |
|
789 |
table.setRowSelectionAllowed(true); |
|
790 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
835 |
this.dock.select(DOCKED_CONSOLE); |
|
836 |
this.dock.select(DOCKED_PROJECTS); |
|
791 | 837 |
|
792 |
JScrollPane scrollProblems = new JScrollPane(table); |
|
793 |
scrollProblems.setAutoscrolls(true); |
|
838 |
JSplitPane centerPanel = new JSplitPane( |
|
839 |
JSplitPane.VERTICAL_SPLIT, |
|
840 |
tabbedPanelCenter, |
|
841 |
tabbedPanelBottom |
|
842 |
); |
|
843 |
centerPanel.setOneTouchExpandable(true); |
|
794 | 844 |
|
795 |
console = new DefaultJScriptingConsole(); |
|
845 |
mainPanel = new JSplitPane( |
|
846 |
JSplitPane.HORIZONTAL_SPLIT, |
|
847 |
tabbedPanelLeft, |
|
848 |
centerPanel |
|
849 |
); |
|
850 |
mainPanel.setOneTouchExpandable(true); |
|
796 | 851 |
|
797 |
bottomTab.add(this.uimanager.getTranslation("Problems"), scrollProblems); |
|
798 |
bottomTab.add(this.uimanager.getTranslation("Console"), console.asJComponent()); |
|
799 |
bottomTab.setPreferredSize(new Dimension(450, 100)); |
|
800 |
bottomTab.setSelectedIndex(1); |
|
852 |
statusBar = new DefaultStatusBar(uimanager); |
|
801 | 853 |
|
802 |
/* Si no se desea cargar datos para que arranque con ellos, |
|
803 |
* este if nunca ser? cierto */ |
|
804 |
if (!unitsEditor.isEmpty()) { |
|
805 |
Iterator<JEditor> it = unitsEditor.values().iterator(); |
|
806 |
while (it.hasNext()) { |
|
807 |
JEditor editor = it.next(); |
|
808 |
editor.addDefaultActionListener(this); |
|
809 |
scriptEditors.addTab(editor.getScript().getName(), editor); |
|
810 |
} |
|
811 |
} |
|
812 |
editionPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptEditors, bottomTab); |
|
813 |
editionPane.setOneTouchExpandable(true); |
|
854 |
updateMenusAndTools(); |
|
814 | 855 |
|
815 |
this.leftTab = new JMyTabbedPane(); |
|
816 |
this.leftTab.setTabPlacement(JTabbedPane.BOTTOM); |
|
817 |
this.leftTab.add(this.uimanager.getTranslation("Projects"), launcherPane); |
|
818 |
|
|
819 |
mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.leftTab, editionPane); |
|
820 |
mainPane.setOneTouchExpandable(true); |
|
821 |
|
|
822 |
// Barra de estado |
|
823 |
statusBar = new JPanel(new BorderLayout()); |
|
824 |
statusBarMessage = new JLabel(); |
|
825 |
statusBarMessage.setText(this.uimanager.getTranslation("Welcome_message")); |
|
826 |
currentLine = new JLabel(); |
|
827 |
currentLine.setText("Line 0:0"); |
|
828 |
|
|
829 |
statusBar.add(statusBarMessage, BorderLayout.WEST); |
|
830 |
statusBar.add(currentLine, BorderLayout.EAST); |
|
831 |
|
|
832 |
// Integrac??n en el frame principal de todos los componentes |
|
833 | 856 |
JPanel buttons = new JPanel(); |
834 | 857 |
buttons.setLayout(new BorderLayout()); |
835 |
buttons.add(BorderLayout.NORTH, menuBar); |
|
836 |
buttons.add(BorderLayout.SOUTH, buttonsPane);
|
|
858 |
buttons.add(BorderLayout.NORTH, this.menuBar);
|
|
859 |
buttons.add(BorderLayout.SOUTH, this.toolBar);
|
|
837 | 860 |
|
838 | 861 |
this.setLayout(new BorderLayout()); |
839 | 862 |
this.add(BorderLayout.NORTH, buttons); |
840 |
this.add(BorderLayout.CENTER, mainPane); |
|
841 |
this.add(BorderLayout.SOUTH, statusBar); |
|
863 |
this.add(BorderLayout.CENTER, mainPanel);
|
|
864 |
this.add(BorderLayout.SOUTH, statusBar.asJComponent());
|
|
842 | 865 |
this.setPreferredSize(new Dimension(800, 600)); |
843 | 866 |
} |
844 | 867 |
|
845 |
@Override |
|
846 |
public void addLeftPanel(String title,final JComponent panel) { |
|
847 |
this.leftTab.add(title,panel); |
|
848 |
this.leftTab.addCloseTabListener(new ActionListener() { |
|
868 |
public void addMenu(String text, Action action) { |
|
869 |
String name; |
|
870 |
if (action == null) { |
|
871 |
name = String.format("Menu%x", new Date().getTime()); |
|
872 |
} else { |
|
873 |
name = (String) action.getValue(Action.ACTION_COMMAND_KEY); |
|
874 |
} |
|
875 |
this.menus.put(name, new ToolEntry(name, action, text)); |
|
876 |
} |
|
849 | 877 |
|
878 |
public void addMenuSeparator(String text) { |
|
879 |
String name = String.format("Sep%x", new Date().getTime()); |
|
880 |
this.menus.put(name, new ToolEntry(name, null, text + "/-")); |
|
881 |
} |
|
882 |
|
|
883 |
public void addTool(Action action) { |
|
884 |
String name = (String) action.getValue(Action.ACTION_COMMAND_KEY); |
|
885 |
this.tools.put(name, new ToolEntry(name, action)); |
|
886 |
} |
|
887 |
|
|
888 |
public void updateMenusAndTools() { |
|
889 |
|
|
890 |
this.menuBar.removeAll(); |
|
891 |
this.toolBar.removeAll(); |
|
892 |
for (MenuEntry entry : this.uimanager.getComposerMenus()) { |
|
893 |
this.addMenu(entry.getText(), entry.getAction()); |
|
894 |
} |
|
895 |
for (Action action : this.uimanager.getComposerTools()) { |
|
896 |
this.addTool(action); |
|
897 |
} |
|
898 |
|
|
899 |
MenuBarHelper menuBarHelper = new MenuBarHelper(menuBar); |
|
900 |
for (ToolEntry entry : menus.values()) { |
|
901 |
try { |
|
902 |
JMenuItem menu = menuBarHelper.add(entry.getText(), entry.getAction(), this); |
|
903 |
entry.setComponent(menu); |
|
904 |
} catch(Throwable th) { |
|
905 |
logger.warn("Can't add entry '"+entry.getName()+"' to the toolbar.", th); |
|
906 |
} |
|
907 |
} |
|
908 |
|
|
909 |
for (ToolEntry entry : tools.values()) { |
|
910 |
try { |
|
911 |
JButton button = new ButtonWithContext(entry.getAction()); |
|
912 |
this.toolBar.add(button); |
|
913 |
entry.setComponent(button); |
|
914 |
} catch(Throwable th) { |
|
915 |
logger.warn("Can't add entry '"+entry.getName()+"' to the toolbar.", th); |
|
916 |
} |
|
917 |
|
|
918 |
} |
|
919 |
this.menuBar.repaint(); |
|
920 |
this.toolBar.repaint(); |
|
921 |
} |
|
922 |
|
|
923 |
public void addProblemsPanel() { |
|
924 |
DockedPanel panel = this.dock.get(DOCKED_PROBLEMS); |
|
925 |
if (panel != null) { |
|
926 |
panel.select(); |
|
927 |
return; |
|
928 |
} |
|
929 |
final Problems problems = new DefaultProblems(this.uimanager); |
|
930 |
problems.addListSelectionListener(new ListSelectionListener() { |
|
931 |
|
|
850 | 932 |
@Override |
851 |
public void actionPerformed(ActionEvent e) { |
|
852 |
int n = leftTab.getSelectedIndex(); |
|
853 |
leftTab.remove(n); |
|
933 |
public void valueChanged(ListSelectionEvent e) { |
|
934 |
if (e.getValueIsAdjusting()) { |
|
935 |
return; |
|
936 |
} |
|
937 |
Problem row = problems.getSelect(); |
|
938 |
if (row != null) { |
|
939 |
int lineno = row.getLineNumber(); |
|
940 |
JEditor editor = getCurrentEditor(); |
|
941 |
if (editor instanceof JCodeEditor) { |
|
942 |
((JCodeEditor) editor).selectLine(lineno); |
|
943 |
} |
|
944 |
} |
|
854 | 945 |
} |
855 | 946 |
}); |
947 |
this.dock.add( |
|
948 |
DOCKED_PROBLEMS, |
|
949 |
this.uimanager.getTranslation("Problems"), |
|
950 |
problems, |
|
951 |
Dock.DOCK_BOTTOM |
|
952 |
); |
|
953 |
this.dock.select(DOCKED_PROBLEMS); |
|
856 | 954 |
} |
857 |
|
|
858 |
@Override |
|
859 |
public void addBottomPanel(String title,final JComponent panel) { |
|
860 |
this.bottomTab.add(title,panel); |
|
861 |
this.bottomTab.addCloseTabListener(new ActionListener() { |
|
862 | 955 |
|
956 |
public void addConsolePanel() { |
|
957 |
DockedPanel panel = this.dock.get(DOCKED_CONSOLE); |
|
958 |
if (panel != null) { |
|
959 |
panel.select(); |
|
960 |
return; |
|
961 |
} |
|
962 |
DefaultJScriptingConsole console = new DefaultJScriptingConsole(); |
|
963 |
this.dock.add( |
|
964 |
DOCKED_CONSOLE, |
|
965 |
this.uimanager.getTranslation("Console"), |
|
966 |
console, |
|
967 |
Dock.DOCK_BOTTOM |
|
968 |
); |
|
969 |
this.dock.select(DOCKED_CONSOLE); |
|
970 |
} |
|
971 |
|
|
972 |
public void addProjectsPanel() { |
|
973 |
DockedPanel panel = this.dock.get(DOCKED_PROJECTS); |
|
974 |
if (panel != null) { |
|
975 |
panel.select(); |
|
976 |
return; |
|
977 |
} |
|
978 |
JScriptingLauncher launcher = uimanager.createLauncher(); |
|
979 |
launcher.addDefaultActionListener(new ActionListener() { |
|
980 |
|
|
863 | 981 |
@Override |
864 | 982 |
public void actionPerformed(ActionEvent e) { |
865 |
int n = bottomTab.getSelectedIndex(); |
|
866 |
bottomTab.remove(n); |
|
983 |
BrowserActionEvent e2 = (BrowserActionEvent) e; |
|
984 |
switch (e.getID()) { |
|
985 |
case JScriptingBrowser.DEFAULT_ACTION: |
|
986 |
scriptEdit(e2.getScript()); |
|
987 |
break; |
|
988 |
case JScriptingBrowser.DROPDOWN_ACTION: |
|
989 |
case JScriptingBrowser.SELECTION_ACTION: |
|
990 |
break; |
|
991 |
} |
|
867 | 992 |
} |
868 | 993 |
}); |
994 |
launcher.asJComponent().setPreferredSize(new Dimension(200, 450)); |
|
995 |
|
|
996 |
this.dock.add( |
|
997 |
DOCKED_PROJECTS, |
|
998 |
this.uimanager.getTranslation("Projects"), |
|
999 |
launcher, |
|
1000 |
Dock.DOCK_LEFT |
|
1001 |
); |
|
1002 |
this.dock.select(DOCKED_PROJECTS); |
|
869 | 1003 |
} |
870 |
|
|
1004 |
|
|
871 | 1005 |
@Override |
1006 |
public Problems getProblems() { |
|
1007 |
DockedPanel panel = this.dock.get(DOCKED_PROBLEMS); |
|
1008 |
if (panel == null) { |
|
1009 |
return null; |
|
1010 |
} |
|
1011 |
return (Problems) panel.getComponent(); |
|
1012 |
} |
|
1013 |
|
|
1014 |
@Override |
|
1015 |
public JScriptingLauncher getProjects() { |
|
1016 |
DockedPanel panel = this.dock.get(DOCKED_PROJECTS); |
|
1017 |
if (panel == null) { |
|
1018 |
return null; |
|
1019 |
} |
|
1020 |
return (JScriptingLauncher) panel.getComponent(); |
|
1021 |
} |
|
1022 |
|
|
1023 |
@Override |
|
1024 |
public Dock getDock() { |
|
1025 |
return dock; |
|
1026 |
} |
|
1027 |
|
|
1028 |
@Override |
|
1029 |
public JScriptingConsole getConsole() { |
|
1030 |
DockedPanel panel = this.dock.get(DOCKED_CONSOLE); |
|
1031 |
if (panel == null) { |
|
1032 |
return null; |
|
1033 |
} |
|
1034 |
return (JScriptingConsole) panel.getComponent(); |
|
1035 |
} |
|
1036 |
|
|
1037 |
@Override |
|
872 | 1038 |
public void addChangeEditorListener(ChangeListener listener) { |
873 |
if( this.changeEditorListeners==null ) {
|
|
1039 |
if (this.changeEditorListeners == null) {
|
|
874 | 1040 |
this.changeEditorListeners = new HashSet<>(); |
875 | 1041 |
} |
876 | 1042 |
this.changeEditorListeners.add(listener); |
877 | 1043 |
} |
878 |
|
|
1044 |
|
|
879 | 1045 |
public void fireChangeEditor(ChangeEvent e) { |
880 |
if( this.changeEditorListeners==null ) {
|
|
1046 |
if (this.changeEditorListeners == null) {
|
|
881 | 1047 |
return; |
882 | 1048 |
} |
883 |
for( ChangeListener listener : this.changeEditorListeners ) {
|
|
1049 |
for (ChangeListener listener : this.changeEditorListeners) {
|
|
884 | 1050 |
try { |
885 | 1051 |
listener.stateChanged(e); |
886 |
} catch(Throwable th) { |
|
887 |
|
|
1052 |
} catch (Throwable th) {
|
|
1053 |
|
|
888 | 1054 |
} |
889 | 1055 |
} |
890 | 1056 |
} |
891 |
|
|
1057 |
|
|
892 | 1058 |
private void createScriptPackage() { |
893 | 1059 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
894 | 1060 |
SwingInstallerManager installerManager = SwingInstallerLocator.getSwingInstallerManager(); |
... | ... | |
913 | 1079 |
); |
914 | 1080 |
} |
915 | 1081 |
|
916 |
private void createHelpPackage() { |
|
917 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
918 |
SwingInstallerManager installerManager = SwingInstallerLocator.getSwingInstallerManager(); |
|
919 |
|
|
920 |
PackageBuildder packager = installerManager.createPackagerPanel( |
|
921 |
ScriptingManager.HELP_INSTALLER_PROVIDER_NAME, |
|
922 |
manager.getHelpManager().getHelpRoots().get(0), |
|
923 |
manager.getPackagesFolder() |
|
924 |
); |
|
925 |
PackageInfo packageInfo = packager.getPackageInfo(); |
|
926 |
packageInfo.setArchitecture(PackageManager.ARCH.ALL); |
|
927 |
packageInfo.setJavaVM(PackageManager.JVM.J1_7); |
|
928 |
packageInfo.setOperatingSystem(PackageManager.OS.ALL); |
|
929 |
packageInfo.setOfficial(false); |
|
930 |
packageInfo.setState(PackageManager.STATE.TESTING); |
|
931 |
packageInfo.setType(ScriptingManager.INSTALLER_PROVIDER_NAME); |
|
932 |
Version version = ToolsLocator.getPackageManager().createVersion(); |
|
933 |
version.parse("1.0.0"); |
|
934 |
packageInfo.setVersion(version); |
|
935 |
this.uimanager.showWindow( |
|
936 |
(JPanel) packager.asJComponent(), |
|
937 |
i18nManager.getTranslation("_Help_scripting_packager") |
|
938 |
); |
|
939 |
} |
|
940 |
|
|
941 |
private class AbstractTableModel extends DefaultTableModel { |
|
942 |
|
|
943 |
/** |
|
944 |
* |
|
945 |
*/ |
|
946 |
private static final long serialVersionUID = -5314938428821653641L; |
|
947 |
|
|
948 |
@Override |
|
949 |
public boolean isCellEditable(int row, int col) { |
|
950 |
return false; |
|
951 |
} |
|
952 |
} |
|
953 |
|
|
954 |
private class RowListener implements ListSelectionListener { |
|
955 |
|
|
956 |
@Override |
|
957 |
public void valueChanged(ListSelectionEvent event) { |
|
958 |
if (event.getValueIsAdjusting()) { |
|
959 |
return; |
|
960 |
} |
|
961 |
if (!table.getSelectionModel().isSelectionEmpty()) { |
|
962 |
int index = table.getSelectionModel().getLeadSelectionIndex(); |
|
963 |
String[] lineAndColumn = ((String) table.getValueAt(index, 2)).split(":"); |
|
964 |
int line = -1; |
|
965 |
if (lineAndColumn.length > 0) { |
|
966 |
try { |
|
967 |
line = Integer.parseInt(lineAndColumn[0].trim()); |
|
968 |
} catch (Exception e) { |
|
969 |
// Do nothing |
|
970 |
} |
|
971 |
} |
|
972 |
if (line >= 0) { |
|
973 |
setEditorSelection(((String) table.getValueAt(index, 1)), line); |
|
974 |
} |
|
975 |
} |
|
976 |
} |
|
977 |
} |
|
978 |
|
|
979 |
private void setEditorSelection(String name, int line) { |
|
980 |
for (int i = 0; i < scriptEditors.getTabCount(); i++) { |
|
981 |
|
|
982 |
if (((JEditor) scriptEditors.getComponent(i)).getScript().getId().equals(name)) { |
|
983 |
scriptEditors.setSelectedIndex(i); |
|
984 |
|
|
985 |
JTextComponent editor = ((JCodeEditor) scriptEditors.getComponent(i)).getJTextComponent(); |
|
986 |
editor.requestFocusInWindow(); |
|
987 |
|
|
988 |
String code = editor.getText(); |
|
989 |
int lineCounter = 0; |
|
990 |
int initialSelection = 0; |
|
991 |
int finalSelection = 0; |
|
992 |
for (int j = 0; j < code.length(); j++) { |
|
993 |
if (code.charAt(j) == '\n') { |
|
994 |
lineCounter++; |
|
995 |
if (lineCounter == line - 1) { |
|
996 |
initialSelection = j; |
|
997 |
} |
|
998 |
if (lineCounter == line || (finalSelection == 0 && j == code.length() - 1)) { |
|
999 |
finalSelection = j; |
|
1000 |
} |
|
1001 |
} |
|
1002 |
} |
|
1003 |
|
|
1004 |
editor.select(initialSelection, finalSelection); |
|
1005 |
} |
|
1006 |
} |
|
1007 |
} |
|
1008 |
|
|
1082 |
// private void setEditorSelection(String name, int line) { |
|
1083 |
// for (int i = 0; i < scriptEditors.getTabCount(); i++) { |
|
1084 |
// |
|
1085 |
// if (((JEditor) scriptEditors.getComponent(i)).getScript().getId().equals(name)) { |
|
1086 |
// scriptEditors.setSelectedIndex(i); |
|
1087 |
// |
|
1088 |
// JCodeEditor editor = ((JCodeEditor) scriptEditors.getComponent(i)); |
|
1089 |
// editor.selectLine(line); |
|
1090 |
// } |
|
1091 |
// }xxxxxxxxxxxxxxxxxxxxxxxx |
|
1092 |
// } |
|
1009 | 1093 |
public void addDefaultActionListener(ActionListener actionlistener) { |
1010 | 1094 |
this.defaultActionlistener = actionlistener; |
Also available in: Unified diff