Revision 468 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 | ||
---|---|---|
1 | 1 |
package org.gvsig.scripting.swing.impl.composer; |
2 | 2 |
|
3 | 3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dialog; |
|
4 | 5 |
import java.awt.Dimension; |
5 | 6 |
import java.awt.Font; |
6 | 7 |
import java.awt.event.ActionEvent; |
7 | 8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.KeyEvent; |
|
8 | 10 |
import java.io.File; |
9 | 11 |
import java.io.OutputStream; |
10 | 12 |
import java.io.PrintStream; |
11 |
import java.util.ArrayList; |
|
12 | 13 |
import java.util.Iterator; |
14 |
import java.util.LinkedHashMap; |
|
13 | 15 |
import java.util.List; |
16 |
import java.util.Map; |
|
17 |
import javax.swing.AbstractAction; |
|
14 | 18 |
|
15 | 19 |
import javax.swing.JButton; |
16 | 20 |
import javax.swing.JLabel; |
... | ... | |
25 | 29 |
import javax.swing.JTable; |
26 | 30 |
import javax.swing.JTextArea; |
27 | 31 |
import javax.swing.JToolBar; |
32 |
import javax.swing.KeyStroke; |
|
28 | 33 |
import javax.swing.ListSelectionModel; |
29 | 34 |
import javax.swing.SwingConstants; |
30 | 35 |
import javax.swing.SwingUtilities; |
36 |
import javax.swing.UIManager; |
|
31 | 37 |
import javax.swing.event.ChangeEvent; |
32 | 38 |
import javax.swing.event.ChangeListener; |
33 | 39 |
import javax.swing.event.ListSelectionEvent; |
34 | 40 |
import javax.swing.event.ListSelectionListener; |
35 | 41 |
import javax.swing.table.DefaultTableModel; |
42 |
import javax.swing.text.BadLocationException; |
|
36 | 43 |
import javax.swing.text.JTextComponent; |
44 |
import org.fife.rsta.ui.GoToDialog; |
|
45 |
import org.fife.rsta.ui.search.FindDialog; |
|
46 |
import org.fife.rsta.ui.search.ReplaceDialog; |
|
47 |
import org.fife.rsta.ui.search.SearchEvent; |
|
48 |
import org.fife.rsta.ui.search.SearchListener; |
|
49 |
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; |
|
50 |
import org.fife.ui.rtextarea.SearchContext; |
|
51 |
import org.fife.ui.rtextarea.SearchEngine; |
|
52 |
import org.fife.ui.rtextarea.SearchResult; |
|
53 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
|
54 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
|
37 | 55 |
|
38 | 56 |
import org.gvsig.scripting.CompileErrorException; |
39 | 57 |
import org.gvsig.scripting.ExecuteErrorException; |
... | ... | |
53 | 71 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingBrowser; |
54 | 72 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher; |
55 | 73 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher.LauncherActionEvent; |
74 |
import org.gvsig.scripting.swing.impl.DefaultScriptingUIManager; |
|
56 | 75 |
import org.gvsig.scripting.swing.impl.JDialogContent; |
76 |
import org.gvsig.tools.ToolsLocator; |
|
77 |
import org.gvsig.tools.i18n.I18nManager; |
|
57 | 78 |
import org.gvsig.tools.observer.Observable; |
58 | 79 |
import org.gvsig.tools.observer.Observer; |
80 |
import org.gvsig.tools.swing.api.Component; |
|
59 | 81 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
60 | 82 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
61 |
import org.gvsig.tools.task.AbstractMonitorableTask; |
|
62 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
63 | 83 |
import org.slf4j.Logger; |
64 | 84 |
import org.slf4j.LoggerFactory; |
65 | 85 |
|
86 |
public class DefaultJScriptingComposer extends JScriptingComposer implements Observer, ActionListener, SearchListener { |
|
66 | 87 |
|
67 |
public class DefaultJScriptingComposer extends JScriptingComposer implements Observer, ActionListener{ |
|
88 |
/** |
|
89 |
* |
|
90 |
*/ |
|
91 |
private static final long serialVersionUID = 1L; |
|
68 | 92 |
|
69 |
/** |
|
70 |
* |
|
71 |
*/ |
|
72 |
private static final long serialVersionUID = 1L; |
|
93 |
private static final Logger logger = LoggerFactory.getLogger(DefaultJScriptingComposer.class); |
|
73 | 94 |
|
74 |
private static final Logger logger = LoggerFactory.getLogger(DefaultJScriptingComposer.class); |
|
75 |
|
|
76 |
public static final int CLOSE_ACTION = 1; |
|
77 |
public List<JEditor> unitsEditor; |
|
95 |
public static final int CLOSE_ACTION = 1; |
|
96 |
public Map<String, JEditor> unitsEditor; |
|
78 | 97 |
|
79 |
/* Generales */
|
|
80 |
ScriptingUIManager uimanager;
|
|
81 |
ScriptingManager manager;
|
|
82 |
ClassLoader loader;
|
|
98 |
/* Generales */
|
|
99 |
ScriptingUIManager uimanager;
|
|
100 |
ScriptingManager manager;
|
|
101 |
ClassLoader loader;
|
|
83 | 102 |
|
84 |
/* Ventana inicial y componentes*/ |
|
85 |
JSplitPane mainPane; |
|
86 |
JSplitPane editionPane; |
|
87 |
JTabbedPane problemsPane; |
|
88 |
JTabbedPane scriptEditors; |
|
89 |
JMenuBar menuBar; |
|
90 |
JToolBar file; |
|
91 |
JToolBar edit; |
|
92 |
JToolBar script; |
|
93 |
JToolBar help; |
|
94 |
JPanel statusBar; |
|
95 |
JLabel currentLine; |
|
96 |
JLabel statusBarMessage; |
|
97 |
JTextArea problems; |
|
98 |
JTextArea console; |
|
99 |
DefaultJScriptingLauncher launcher; |
|
100 |
JToolBar launcherButtons; |
|
101 |
PrintStream consolePrintStream = null; |
|
102 |
WindowManager windowsManager = null; |
|
103 |
|
|
104 |
/* JFrame para la creación de nuevos ScriptingBaseScripts o modificación de atributos */ |
|
105 |
//JFrame NewUnitFrame; |
|
103 |
/* Ventana inicial y componentes*/ |
|
104 |
JSplitPane mainPane; |
|
105 |
JSplitPane editionPane; |
|
106 |
JTabbedPane problemsPane; |
|
107 |
JTabbedPane scriptEditors; |
|
108 |
JMenuBar menuBar; |
|
109 |
JToolBar file; |
|
110 |
JToolBar edit; |
|
111 |
JToolBar script; |
|
112 |
JToolBar help; |
|
113 |
JPanel statusBar; |
|
114 |
JLabel currentLine; |
|
115 |
JLabel statusBarMessage; |
|
116 |
JTextArea problems; |
|
117 |
JTextArea console; |
|
118 |
DefaultJScriptingLauncher launcher; |
|
119 |
JToolBar launcherButtons; |
|
120 |
PrintStream consolePrintStream = null; |
|
106 | 121 |
|
107 |
/* Para el mantenimiento de la tabla de problemas en el código*/ |
|
108 |
Object[][] tableData; |
|
109 |
JTable table; |
|
110 |
DefaultTableModel tableModel; |
|
111 |
protected ActionListener defaultActionlistener = null; |
|
122 |
private FindDialog findDialog; |
|
123 |
private ReplaceDialog replaceDialog; |
|
124 |
private GoToDialog gotoDialog; |
|
125 |
|
|
126 |
JTable table; |
|
127 |
DefaultTableModel tableModel; |
|
128 |
protected ActionListener defaultActionlistener = null; |
|
112 | 129 |
|
113 |
/**
|
|
114 |
* Instanciación de un JComposer con todos sus elementos y acciones
|
|
115 |
* @param manager
|
|
116 |
*/
|
|
117 |
public DefaultJScriptingComposer(final ScriptingUIManager uimanager) {
|
|
118 |
loader = this.getClass().getClassLoader();
|
|
119 |
this.uimanager = uimanager;
|
|
120 |
this.manager = uimanager.getManager();
|
|
121 |
this.setWindowManager( ToolsSwingLocator.getWindowManager());
|
|
130 |
/**
|
|
131 |
* Instanciacion de un JComposer con todos sus elementos y acciones
|
|
132 |
*
|
|
133 |
* @param manager
|
|
134 |
*/
|
|
135 |
public DefaultJScriptingComposer(final ScriptingUIManager uimanager) {
|
|
136 |
loader = this.getClass().getClassLoader();
|
|
137 |
this.uimanager = uimanager;
|
|
138 |
this.manager = uimanager.getManager();
|
|
122 | 139 |
|
123 |
unitsEditor = new ArrayList<JEditor>();
|
|
140 |
unitsEditor = new LinkedHashMap<String, JEditor>();
|
|
124 | 141 |
|
125 |
initUI(); |
|
126 |
|
|
127 |
System.setOut(this.getConsolePrintStream()); |
|
128 |
System.setErr(this.getConsolePrintStream()); |
|
142 |
initComponents(); |
|
129 | 143 |
|
130 |
} |
|
131 |
|
|
132 |
public WindowManager getWindowManager() { |
|
133 |
return this.windowsManager; |
|
134 |
} |
|
135 |
|
|
136 |
public void setWindowManager(WindowManager windowsManager) { |
|
137 |
this.windowsManager = windowsManager; |
|
138 |
} |
|
139 |
|
|
140 |
private void initUI() { |
|
141 |
// Barra de menu |
|
142 |
menuBar = new JMenuBar(); |
|
144 |
System.setOut(this.getConsolePrintStream()); |
|
145 |
System.setErr(this.getConsolePrintStream()); |
|
143 | 146 |
|
144 |
// Construimos los componentes del menu |
|
145 |
JMenu menu_file = new JMenu(this.uimanager.getTranslation("File")); |
|
146 |
JMenuItem menuItem_new = new JMenuItem(this.uimanager.getTranslation("New"),uimanager.getIcon("document-new")); |
|
147 |
menuItem_new.addActionListener(new ActionListener(){ |
|
148 |
public void actionPerformed(ActionEvent e) { |
|
149 |
try { |
|
150 |
newScriptingBaseScript(); |
|
151 |
} catch (Exception e1) { |
|
152 |
// TODO Auto-generated catch block |
|
153 |
e1.printStackTrace(); |
|
154 |
} |
|
155 |
} |
|
156 |
}); |
|
157 |
menu_file.add(menuItem_new); |
|
158 |
menu_file.addSeparator(); |
|
159 |
JMenuItem menuItem_close = new JMenuItem(this.uimanager.getTranslation("Close_document"),uimanager.getIcon("emblem-unreadable")); |
|
160 |
menuItem_close.addActionListener(new ActionListener(){ |
|
161 |
public void actionPerformed(ActionEvent e) { |
|
162 |
closeScriptingBaseScript(); |
|
163 |
} |
|
164 |
}); |
|
165 |
menu_file.add(menuItem_close); |
|
166 |
JMenuItem menuItem_closeAll = new JMenuItem(this.uimanager.getTranslation("Close_all_documents"),uimanager.getIcon("emblem-unreadable")); |
|
167 |
menuItem_closeAll.addActionListener(new ActionListener(){ |
|
168 |
public void actionPerformed(ActionEvent e) { |
|
169 |
closeAllScriptingBaseScript(); |
|
170 |
} |
|
171 |
}); |
|
172 |
menu_file.add(menuItem_closeAll); |
|
173 |
menu_file.addSeparator(); |
|
174 |
JMenuItem menuItem_run = new JMenuItem(this.uimanager.getTranslation("Run"),uimanager.getIcon("applications-system")); |
|
175 |
menuItem_run.addActionListener(new ActionListener(){ |
|
176 |
public void actionPerformed(ActionEvent e) { |
|
177 |
runScriptingBaseScript(); |
|
178 |
} |
|
179 |
}); |
|
180 |
menu_file.add(menuItem_run); |
|
181 |
menu_file.addSeparator(); |
|
182 |
JMenuItem menuItem_save = new JMenuItem(this.uimanager.getTranslation("Save"),uimanager.getIcon("media-floppy")); |
|
183 |
menuItem_save.addActionListener(new ActionListener(){ |
|
184 |
public void actionPerformed(ActionEvent e) { |
|
185 |
saveScriptingBaseScript(); |
|
186 |
} |
|
187 |
}); |
|
188 |
menu_file.add(menuItem_save); |
|
189 |
menu_file.addSeparator(); |
|
190 |
JMenuItem menuItem_exit = new JMenuItem(this.uimanager.getTranslation("Close"),uimanager.getIcon("system-log-out")); |
|
191 |
menuItem_exit.addActionListener(new ActionListener(){ |
|
192 |
public void actionPerformed(ActionEvent e) { |
|
193 |
closeAllScriptingBaseScript(); |
|
194 |
closeWindow(); |
|
195 |
if(defaultActionlistener!=null){ |
|
196 |
ActionEvent event = new ActionEvent(this,CLOSE_ACTION,"close"); |
|
197 |
defaultActionlistener.actionPerformed(event); |
|
198 |
} |
|
199 |
|
|
200 |
} |
|
201 |
}); |
|
202 |
menu_file.add(menuItem_exit); |
|
147 |
} |
|
203 | 148 |
|
204 |
JMenu menu_edit = new JMenu(this.uimanager.getTranslation("Edit")); |
|
205 |
JMenuItem menuItem_cut = new JMenuItem(this.uimanager.getTranslation("Cut"),uimanager.getIcon("edit-cut")); |
|
206 |
menuItem_cut.addActionListener(new ActionListener(){ |
|
207 |
public void actionPerformed(ActionEvent e) { |
|
208 |
cutScriptingBaseScript(); |
|
209 |
} |
|
210 |
}); |
|
211 |
menu_edit.add(menuItem_cut); |
|
212 |
JMenuItem menuItem_copy = new JMenuItem(this.uimanager.getTranslation("Copy"),uimanager.getIcon("edit-copy")); |
|
213 |
menuItem_copy.addActionListener(new ActionListener(){ |
|
214 |
public void actionPerformed(ActionEvent e) { |
|
215 |
copyScriptingBaseScript(); |
|
216 |
} |
|
217 |
}); |
|
218 |
menu_edit.add(menuItem_copy); |
|
219 |
JMenuItem menuItem_paste = new JMenuItem(this.uimanager.getTranslation("Paste"),uimanager.getIcon("edit-paste")); |
|
220 |
menuItem_paste.addActionListener(new ActionListener(){ |
|
221 |
public void actionPerformed(ActionEvent e) { |
|
222 |
pasteScriptingBaseScript(); |
|
223 |
} |
|
224 |
}); |
|
225 |
menu_edit.add(menuItem_paste); |
|
226 |
menu_edit.addSeparator(); |
|
227 |
JMenuItem menuItem_selectAll = new JMenuItem(this.uimanager.getTranslation("Select_all"),uimanager.getIcon("edit-select-all")); |
|
228 |
menuItem_selectAll.addActionListener(new ActionListener(){ |
|
229 |
public void actionPerformed(ActionEvent e) { |
|
230 |
selectAllScriptingBaseScript(); |
|
231 |
} |
|
232 |
}); |
|
233 |
menu_edit.add(menuItem_selectAll); |
|
149 |
@Override |
|
150 |
public WindowManager getWindowManager() { |
|
151 |
return ((DefaultScriptingUIManager)(this.uimanager)).getWindowManager(); |
|
152 |
} |
|
234 | 153 |
|
235 |
JMenu menu_tools = new JMenu(this.uimanager.getTranslation("Tools")); |
|
236 |
JMenuItem menuItem_launcher = new JMenuItem(this.uimanager.getTranslation("Launcher")); |
|
237 |
menuItem_launcher.addActionListener(new ActionListener(){ |
|
238 |
public void actionPerformed(ActionEvent e) { |
|
239 |
getWindowManager().showWindow(uimanager.createLauncher(), uimanager.getTranslation("Scripting_Launcher"), WindowManager.MODE.TOOL); |
|
240 |
} |
|
241 |
}); |
|
242 |
menu_tools.add(menuItem_launcher); |
|
243 |
|
|
154 |
@Override |
|
155 |
public void setWindowManager(WindowManager windowsManager) { |
|
156 |
((DefaultScriptingUIManager)(this.uimanager)).setWindowManager(windowsManager); |
|
157 |
} |
|
244 | 158 |
|
245 |
JMenu menu_help = new JMenu("Help"); |
|
246 |
JMenuItem menuItem_import = new JMenuItem(this.uimanager.getTranslation("Import_JavaDoc"),uimanager.getIcon("list-add")); |
|
247 |
menuItem_import.addActionListener(new ActionListener(){ |
|
248 |
public void actionPerformed(ActionEvent e) { |
|
249 |
getWindowManager().showWindow(getImportHelpDialog(), uimanager.getTranslation("JavaDoc"), WindowManager.MODE.WINDOW); |
|
250 |
} |
|
251 |
}); |
|
252 |
menu_help.add(menuItem_import); |
|
253 |
JMenuItem menuItem_remove = new JMenuItem(this.uimanager.getTranslation("Remove_JavaDoc"), uimanager.getIcon("list-remove")); |
|
254 |
menuItem_remove.addActionListener(new ActionListener(){ |
|
255 |
public void actionPerformed(ActionEvent e) { |
|
256 |
try { |
|
257 |
getRemoveHelpDialog(); |
|
258 |
} catch (Exception e1) { |
|
259 |
// TODO Auto-generated catch block |
|
260 |
e1.printStackTrace(); |
|
261 |
} |
|
262 |
} |
|
263 |
}); |
|
264 |
menu_help.add(menuItem_remove); |
|
265 |
JMenuItem menuItem_show = new JMenuItem(this.uimanager.getTranslation("Show_JavaDoc"),uimanager.getIcon("help-browser")); |
|
266 |
menuItem_show.addActionListener(new ActionListener(){ |
|
267 |
public void actionPerformed(ActionEvent e) { |
|
268 |
getWindowManager().showWindow(uimanager.getAPIHelp(), uimanager.getTranslation("JavaDoc"), WindowManager.MODE.WINDOW); |
|
269 |
} |
|
270 |
}); |
|
271 |
menu_help.add(menuItem_show); |
|
272 |
menu_help.addSeparator(); |
|
273 |
JMenuItem menuItem_about = new JMenuItem(this.uimanager.getTranslation("About_us"),uimanager.getIcon("system-users")); |
|
274 |
menuItem_about.addActionListener(new ActionListener(){ |
|
275 |
public void actionPerformed(ActionEvent e) { |
|
276 |
getWindowManager().showWindow(getAboutUsDialog(), uimanager.getTranslation("About_us"), WindowManager.MODE.WINDOW); |
|
159 |
private void initComponents() { |
|
160 |
|
|
161 |
findDialog = new FindDialog((Dialog)null, this); |
|
162 |
replaceDialog = new ReplaceDialog((Dialog)null, this); |
|
163 |
gotoDialog = new GoToDialog((Dialog) null); |
|
164 |
|
|
165 |
SearchContext searchContext = findDialog.getSearchContext(); |
|
166 |
replaceDialog.setSearchContext(searchContext); |
|
167 |
|
|
168 |
// Barra de menu |
|
169 |
menuBar = new JMenuBar(); |
|
277 | 170 |
|
278 |
} |
|
279 |
}); |
|
280 |
menu_help.add(menuItem_about); |
|
281 |
JMenuItem menuItem_help = new JMenuItem(this.uimanager.getTranslation("Get_help"),uimanager.getIcon("help-browser")); |
|
282 |
menuItem_help.addActionListener(new ActionListener(){ |
|
283 |
public void actionPerformed(ActionEvent e) { |
|
284 |
getWindowManager().showWindow(uimanager.getUserHelp(), uimanager.getTranslation("Get_help"), WindowManager.MODE.WINDOW); |
|
285 |
} |
|
286 |
}); |
|
287 |
menu_help.add(menuItem_help); |
|
171 |
// Construimos los componentes del menu |
|
172 |
JMenu menu_file = new JMenu(this.uimanager.getTranslation("File")); |
|
173 |
JMenuItem menuItem_new = new JMenuItem(this.uimanager.getTranslation("New"), uimanager.getIcon("document-new")); |
|
174 |
menuItem_new.addActionListener(new ActionListener() { |
|
175 |
public void actionPerformed(ActionEvent e) { |
|
176 |
try { |
|
177 |
scriptNew(); |
|
178 |
} catch (Exception e1) { |
|
179 |
// TODO Auto-generated catch block |
|
180 |
e1.printStackTrace(); |
|
181 |
} |
|
182 |
} |
|
183 |
}); |
|
184 |
menu_file.add(menuItem_new); |
|
185 |
menu_file.addSeparator(); |
|
186 |
JMenuItem menuItem_close = new JMenuItem(this.uimanager.getTranslation("Close_document"), uimanager.getIcon("emblem-unreadable")); |
|
187 |
menuItem_close.addActionListener(new ActionListener() { |
|
188 |
public void actionPerformed(ActionEvent e) { |
|
189 |
currentScriptClose(); |
|
190 |
} |
|
191 |
}); |
|
192 |
menu_file.add(menuItem_close); |
|
193 |
JMenuItem menuItem_closeAll = new JMenuItem(this.uimanager.getTranslation("Close_all_documents"), uimanager.getIcon("emblem-unreadable")); |
|
194 |
menuItem_closeAll.addActionListener(new ActionListener() { |
|
195 |
public void actionPerformed(ActionEvent e) { |
|
196 |
closeAllScripts(); |
|
197 |
} |
|
198 |
}); |
|
199 |
menu_file.add(menuItem_closeAll); |
|
200 |
menu_file.addSeparator(); |
|
201 |
JMenuItem menuItem_run = new JMenuItem(this.uimanager.getTranslation("Run"), uimanager.getIcon("applications-system")); |
|
202 |
menuItem_run.addActionListener(new ActionListener() { |
|
203 |
public void actionPerformed(ActionEvent e) { |
|
204 |
currentScriptExecute(); |
|
205 |
} |
|
206 |
}); |
|
207 |
menu_file.add(menuItem_run); |
|
208 |
menu_file.addSeparator(); |
|
209 |
JMenuItem menuItem_save = new JMenuItem(this.uimanager.getTranslation("Save"), uimanager.getIcon("media-floppy")); |
|
210 |
menuItem_save.addActionListener(new ActionListener() { |
|
211 |
public void actionPerformed(ActionEvent e) { |
|
212 |
currentScriptSave(); |
|
213 |
} |
|
214 |
}); |
|
215 |
menu_file.add(menuItem_save); |
|
216 |
menu_file.addSeparator(); |
|
217 |
JMenuItem menuItem_exit = new JMenuItem(this.uimanager.getTranslation("Close"), uimanager.getIcon("system-log-out")); |
|
218 |
menuItem_exit.addActionListener(new ActionListener() { |
|
219 |
public void actionPerformed(ActionEvent e) { |
|
220 |
closeAllScripts(); |
|
221 |
closeWindow(); |
|
222 |
if (defaultActionlistener != null) { |
|
223 |
ActionEvent event = new ActionEvent(this, CLOSE_ACTION, "close"); |
|
224 |
defaultActionlistener.actionPerformed(event); |
|
225 |
} |
|
288 | 226 |
|
289 |
menuBar.add(menu_file); |
|
290 |
menuBar.add(menu_edit); |
|
291 |
menuBar.add(menu_tools); |
|
292 |
menuBar.add(menu_help); |
|
227 |
} |
|
228 |
}); |
|
229 |
menu_file.add(menuItem_exit); |
|
293 | 230 |
|
294 |
// Botones de acción |
|
295 |
file = new JToolBar(); |
|
296 |
help = new JToolBar(); |
|
297 |
edit = new JToolBar(); |
|
298 |
script = new JToolBar(); |
|
299 |
setDefaultButtons(); |
|
300 |
JPanel scriptButtonsPane = new JPanel(new BorderLayout()); |
|
301 |
scriptButtonsPane.add(edit,BorderLayout.WEST); |
|
302 |
scriptButtonsPane.add(script,BorderLayout.CENTER); |
|
303 |
JPanel buttonsPane = new JPanel(new BorderLayout()); |
|
304 |
buttonsPane.add(file, BorderLayout.WEST); |
|
305 |
buttonsPane.add(help, BorderLayout.EAST); |
|
306 |
buttonsPane.add(scriptButtonsPane, BorderLayout.CENTER); |
|
231 |
JMenu menu_edit = new JMenu(this.uimanager.getTranslation("Edit")); |
|
232 |
JMenuItem menuItem_cut = new JMenuItem(this.uimanager.getTranslation("Cut"), uimanager.getIcon("edit-cut")); |
|
233 |
menuItem_cut.addActionListener(new ActionListener() { |
|
234 |
@Override |
|
235 |
public void actionPerformed(ActionEvent e) { |
|
236 |
currentScriptCut(); |
|
237 |
} |
|
238 |
}); |
|
239 |
menu_edit.add(menuItem_cut); |
|
240 |
JMenuItem menuItem_copy = new JMenuItem(this.uimanager.getTranslation("Copy"), uimanager.getIcon("edit-copy")); |
|
241 |
menuItem_copy.addActionListener(new ActionListener() { |
|
242 |
@Override |
|
243 |
public void actionPerformed(ActionEvent e) { |
|
244 |
currentScriptCopy(); |
|
245 |
} |
|
246 |
}); |
|
247 |
menu_edit.add(menuItem_copy); |
|
248 |
JMenuItem menuItem_paste = new JMenuItem(this.uimanager.getTranslation("Paste"), uimanager.getIcon("edit-paste")); |
|
249 |
menuItem_paste.addActionListener(new ActionListener() { |
|
250 |
@Override |
|
251 |
public void actionPerformed(ActionEvent e) { |
|
252 |
currentScriptPaste(); |
|
253 |
} |
|
254 |
}); |
|
255 |
menu_edit.add(menuItem_paste); |
|
256 |
menu_edit.addSeparator(); |
|
257 |
|
|
258 |
JMenuItem menuItem_selectAll = new JMenuItem(this.uimanager.getTranslation("Select_all"), uimanager.getIcon("edit-select-all")); |
|
259 |
menuItem_selectAll.addActionListener(new ActionListener() { |
|
260 |
@Override |
|
261 |
public void actionPerformed(ActionEvent e) { |
|
262 |
currentScriptSelectAll(); |
|
263 |
} |
|
264 |
}); |
|
265 |
menu_edit.add(menuItem_selectAll); |
|
266 |
menu_edit.addSeparator(); |
|
267 |
|
|
268 |
menu_edit.add(new JMenuItem(new ShowFindDialogAction())); |
|
269 |
menu_edit.add(new JMenuItem(new ShowReplaceDialogAction())); |
|
270 |
menu_edit.add(new JMenuItem(new GoToLineAction())); |
|
271 |
|
|
272 |
JMenu menu_tools = new JMenu(this.uimanager.getTranslation("Tools")); |
|
273 |
JMenuItem menuItem_launcher = new JMenuItem(this.uimanager.getTranslation("Launcher")); |
|
274 |
menuItem_launcher.addActionListener(new ActionListener() { |
|
275 |
@Override |
|
276 |
public void actionPerformed(ActionEvent e) { |
|
277 |
getWindowManager().showWindow(uimanager.createLauncher(), uimanager.getTranslation("Scripting_Launcher"), WindowManager.MODE.TOOL); |
|
278 |
} |
|
279 |
}); |
|
280 |
menu_tools.add(menuItem_launcher); |
|
307 | 281 |
|
308 |
// Panel de selección de proyecto |
|
309 |
JPanel launcherPane = new JPanel(new BorderLayout()); |
|
310 |
launcher = (DefaultJScriptingLauncher)uimanager.createLauncher(); |
|
311 |
launcher.addDefaultActionListener(this); |
|
312 |
launcher.setPreferredSize(new Dimension(200, 450)); |
|
313 |
launcherButtons = new JToolBar(SwingConstants.VERTICAL); |
|
314 |
setLauncherPaneButtons(); |
|
282 |
JMenuItem menuItem_packager = new JMenuItem(this.uimanager.getTranslation("_Scripting_packager")); |
|
283 |
menuItem_packager.addActionListener(new ActionListener() { |
|
315 | 284 |
|
316 |
launcherPane.add(launcher,BorderLayout.CENTER); |
|
317 |
launcherPane.add(launcherButtons,BorderLayout.WEST); |
|
285 |
@Override |
|
286 |
public void actionPerformed(ActionEvent ae) { |
|
287 |
createPackage(); |
|
288 |
} |
|
289 |
}); |
|
290 |
menu_tools.add(menuItem_packager); |
|
318 | 291 |
|
292 |
JMenu menu_help = new JMenu("Help"); |
|
293 |
JMenuItem menuItem_import = new JMenuItem(this.uimanager.getTranslation("Import_JavaDoc"), uimanager.getIcon("list-add")); |
|
294 |
menuItem_import.addActionListener(new ActionListener() { |
|
295 |
@Override |
|
296 |
public void actionPerformed(ActionEvent e) { |
|
297 |
getWindowManager().showWindow(getImportHelpDialog(), uimanager.getTranslation("JavaDoc"), WindowManager.MODE.WINDOW); |
|
298 |
} |
|
299 |
}); |
|
300 |
menu_help.add(menuItem_import); |
|
301 |
JMenuItem menuItem_remove = new JMenuItem(this.uimanager.getTranslation("Remove_JavaDoc"), uimanager.getIcon("list-remove")); |
|
302 |
menuItem_remove.addActionListener(new ActionListener() { |
|
303 |
@Override |
|
304 |
public void actionPerformed(ActionEvent e) { |
|
305 |
try { |
|
306 |
getRemoveHelpDialog(); |
|
307 |
} catch (Exception e1) { |
|
308 |
// TODO Auto-generated catch block |
|
309 |
e1.printStackTrace(); |
|
310 |
} |
|
311 |
} |
|
312 |
}); |
|
313 |
menu_help.add(menuItem_remove); |
|
314 |
JMenuItem menuItem_show = new JMenuItem(this.uimanager.getTranslation("Show_JavaDoc"), uimanager.getIcon("help-browser")); |
|
315 |
menuItem_show.addActionListener(new ActionListener() { |
|
316 |
@Override |
|
317 |
public void actionPerformed(ActionEvent e) { |
|
318 |
getWindowManager().showWindow(uimanager.getAPIHelp(), uimanager.getTranslation("JavaDoc"), WindowManager.MODE.WINDOW); |
|
319 |
} |
|
320 |
}); |
|
321 |
menu_help.add(menuItem_show); |
|
322 |
menu_help.addSeparator(); |
|
323 |
JMenuItem menuItem_about = new JMenuItem(this.uimanager.getTranslation("About_us"), uimanager.getIcon("system-users")); |
|
324 |
menuItem_about.addActionListener(new ActionListener() { |
|
325 |
@Override |
|
326 |
public void actionPerformed(ActionEvent e) { |
|
327 |
getWindowManager().showWindow(getAboutUsDialog(), uimanager.getTranslation("About_us"), WindowManager.MODE.WINDOW); |
|
319 | 328 |
|
320 |
// Panel de Edición |
|
321 |
scriptEditors = new JTabbedPane(); |
|
322 |
scriptEditors.addChangeListener(new ChangeListener(){ |
|
323 |
public void stateChanged(ChangeEvent arg0) { |
|
324 |
JPanel editor = (JPanel)scriptEditors.getSelectedComponent(); |
|
325 |
if(scriptEditors.getSelectedIndex()==-1) |
|
326 |
setDefaultButtons(); |
|
327 |
else if(editor instanceof DefaultJDialogEditor) |
|
328 |
setDialogButtons(); |
|
329 |
else if(editor instanceof DefaultJCodeEditor) |
|
330 |
setScriptButtons(); |
|
331 |
} |
|
332 |
}); |
|
333 |
scriptEditors.setPreferredSize(new Dimension(500, 350)); |
|
334 |
problemsPane = new JTabbedPane(); |
|
329 |
} |
|
330 |
}); |
|
331 |
menu_help.add(menuItem_about); |
|
332 |
JMenuItem menuItem_help = new JMenuItem(this.uimanager.getTranslation("Get_help"), uimanager.getIcon("help-browser")); |
|
333 |
menuItem_help.addActionListener(new ActionListener() { |
|
334 |
@Override |
|
335 |
public void actionPerformed(ActionEvent e) { |
|
336 |
getWindowManager().showWindow(uimanager.getUserHelp(), uimanager.getTranslation("Get_help"), WindowManager.MODE.WINDOW); |
|
337 |
} |
|
338 |
}); |
|
339 |
menu_help.add(menuItem_help); |
|
335 | 340 |
|
336 |
tableData = null; |
|
337 |
tableModel = new AbstractTableModel(); |
|
338 |
tableModel.addColumn(this.uimanager.getTranslation("Description")); |
|
339 |
tableModel.addColumn(this.uimanager.getTranslation("Resource")); |
|
340 |
tableModel.addColumn(this.uimanager.getTranslation("Location")); |
|
341 |
table = new JTable(tableModel); |
|
342 |
table.getColumnModel().getColumn(0).setPreferredWidth(300); |
|
341 |
menuBar.add(menu_file); |
|
342 |
menuBar.add(menu_edit); |
|
343 |
menuBar.add(menu_tools); |
|
344 |
menuBar.add(menu_help); |
|
345 |
|
|
346 |
// Botones de acción |
|
347 |
file = new JToolBar(); |
|
348 |
help = new JToolBar(); |
|
349 |
edit = new JToolBar(); |
|
350 |
script = new JToolBar(); |
|
351 |
setButtonsDefault(); |
|
352 |
JPanel scriptButtonsPane = new JPanel(new BorderLayout()); |
|
353 |
scriptButtonsPane.add(edit, BorderLayout.WEST); |
|
354 |
|
|
355 |
scriptButtonsPane.add(script, BorderLayout.CENTER); |
|
356 |
JPanel buttonsPane = new JPanel(new BorderLayout()); |
|
357 |
buttonsPane.add(file, BorderLayout.WEST); |
|
358 |
buttonsPane.add(help, BorderLayout.EAST); |
|
359 |
buttonsPane.add(scriptButtonsPane, BorderLayout.CENTER); |
|
360 |
|
|
361 |
JPanel launcherPane = new JPanel(new BorderLayout()); |
|
362 |
launcher = (DefaultJScriptingLauncher) uimanager.createLauncher(); |
|
363 |
launcher.addDefaultActionListener(this); |
|
364 |
launcher.setPreferredSize(new Dimension(200, 450)); |
|
365 |
launcherButtons = new JToolBar(SwingConstants.VERTICAL); |
|
366 |
setButtonsLauncherPanel(); |
|
367 |
|
|
368 |
launcherPane.add(launcher, BorderLayout.CENTER); |
|
369 |
launcherPane.add(launcherButtons, BorderLayout.WEST); |
|
370 |
|
|
371 |
// Panel de Edición |
|
372 |
scriptEditors = new JTabbedPane(); |
|
373 |
scriptEditors.addChangeListener(new ChangeListener() { |
|
374 |
public void stateChanged(ChangeEvent arg0) { |
|
375 |
JPanel editor = (JPanel) scriptEditors.getSelectedComponent(); |
|
376 |
if (scriptEditors.getSelectedIndex() == -1) { |
|
377 |
setButtonsDefault(); |
|
378 |
} else if (editor instanceof DefaultJDialogEditor) { |
|
379 |
setButtonsDialog(); |
|
380 |
} else if (editor instanceof DefaultJCodeEditor) { |
|
381 |
setButtonsScript(); |
|
382 |
} |
|
383 |
} |
|
384 |
}); |
|
385 |
scriptEditors.setPreferredSize(new Dimension(500, 350)); |
|
386 |
problemsPane = new JTabbedPane(); |
|
387 |
|
|
388 |
tableModel = new AbstractTableModel(); |
|
389 |
tableModel.addColumn(this.uimanager.getTranslation("Description")); |
|
390 |
tableModel.addColumn(this.uimanager.getTranslation("Resource")); |
|
391 |
tableModel.addColumn(this.uimanager.getTranslation("Location")); |
|
392 |
table = new JTable(tableModel); |
|
393 |
table.getColumnModel().getColumn(0).setPreferredWidth(300); |
|
343 | 394 |
//table.setFont(new Font("Serif",Font.PLAIN,13)); |
344 |
|
|
345 |
table.getSelectionModel().addListSelectionListener(new RowListener()); |
|
346 |
table.setRowSelectionAllowed(true); |
|
347 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
348 |
|
|
349 |
JScrollPane scrollProblems = new JScrollPane(table); |
|
350 |
scrollProblems.setAutoscrolls(true); |
|
351 | 395 |
|
352 |
console = new JTextArea(); |
|
353 |
console.setFont(new Font("monospaced",Font.PLAIN,13)); |
|
354 |
|
|
355 |
JScrollPane scrollConsole = new JScrollPane(console); |
|
356 |
problemsPane.add(this.uimanager.getTranslation("Problems"), scrollProblems); |
|
357 |
problemsPane.add(this.uimanager.getTranslation("Console"), scrollConsole); |
|
358 |
problemsPane.setPreferredSize(new Dimension(450, 100)); |
|
359 |
problemsPane.setSelectedIndex(1); |
|
396 |
table.getSelectionModel().addListSelectionListener(new RowListener()); |
|
397 |
table.setRowSelectionAllowed(true); |
|
398 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
360 | 399 |
|
361 |
/* Si no se desea cargar datos para que arranque con ellos, |
|
362 |
* este if nunca será cierto */ |
|
363 |
if(!unitsEditor.isEmpty()){; |
|
364 |
Iterator<JEditor> it = unitsEditor.iterator(); |
|
365 |
while(it.hasNext()){ |
|
366 |
JEditor editor = it.next(); |
|
367 |
editor.addDefaultActionListener(this); |
|
368 |
scriptEditors.addTab(editor.getScript().getName(), editor); |
|
369 |
} |
|
370 |
} |
|
371 |
editionPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,scriptEditors,problemsPane); |
|
372 |
editionPane.setOneTouchExpandable(true); |
|
400 |
JScrollPane scrollProblems = new JScrollPane(table); |
|
401 |
scrollProblems.setAutoscrolls(true); |
|
373 | 402 |
|
374 |
mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,launcherPane, editionPane);
|
|
375 |
mainPane.setOneTouchExpandable(true);
|
|
403 |
console = new JTextArea();
|
|
404 |
console.setFont(new Font("monospaced", Font.PLAIN, 13));
|
|
376 | 405 |
|
377 |
// Barra de estado |
|
378 |
statusBar = new JPanel(new BorderLayout()); |
|
379 |
statusBarMessage = new JLabel(); |
|
380 |
statusBarMessage.setText(this.uimanager.getTranslation("Welcome_message")); |
|
381 |
currentLine = new JLabel(); |
|
382 |
currentLine.setText("Line 0:0"); |
|
406 |
JScrollPane scrollConsole = new JScrollPane(console); |
|
407 |
problemsPane.add(this.uimanager.getTranslation("Problems"), scrollProblems); |
|
408 |
problemsPane.add(this.uimanager.getTranslation("Console"), scrollConsole); |
|
409 |
problemsPane.setPreferredSize(new Dimension(450, 100)); |
|
410 |
problemsPane.setSelectedIndex(1); |
|
383 | 411 |
|
384 |
statusBar.add(statusBarMessage,BorderLayout.WEST); |
|
385 |
statusBar.add(currentLine,BorderLayout.EAST); |
|
386 |
|
|
387 |
// Integracíón en el frame principal de todos los componentes |
|
388 |
JPanel buttons = new JPanel(); |
|
389 |
buttons.setLayout( new BorderLayout() ); |
|
390 |
buttons.add(BorderLayout.NORTH, menuBar); |
|
391 |
buttons.add(BorderLayout.SOUTH, buttonsPane); |
|
392 |
|
|
393 |
this.setLayout(new BorderLayout()); |
|
394 |
this.add(BorderLayout.NORTH, buttons); |
|
395 |
this.add(BorderLayout.CENTER, mainPane); |
|
396 |
this.add(BorderLayout.SOUTH, statusBar); |
|
397 |
this.setPreferredSize(new Dimension(800,600)); |
|
398 |
} |
|
412 |
/* Si no se desea cargar datos para que arranque con ellos, |
|
413 |
* este if nunca será cierto */ |
|
414 |
if (!unitsEditor.isEmpty()) {; |
|
415 |
Iterator<JEditor> it = unitsEditor.values().iterator(); |
|
416 |
while (it.hasNext()) { |
|
417 |
JEditor editor = it.next(); |
|
418 |
editor.addDefaultActionListener(this); |
|
419 |
scriptEditors.addTab(editor.getScript().getName(), editor); |
|
420 |
} |
|
421 |
} |
|
422 |
editionPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptEditors, problemsPane); |
|
423 |
editionPane.setOneTouchExpandable(true); |
|
399 | 424 |
|
400 |
private PrintStream getConsolePrintStream() { |
|
401 |
if( this.consolePrintStream == null ) { |
|
402 |
JTextAreaOutputStream outputConsole = new JTextAreaOutputStream(console); |
|
403 |
this.consolePrintStream = new PrintStream(outputConsole); |
|
404 |
} |
|
405 |
return this.consolePrintStream; |
|
406 |
} |
|
407 |
|
|
408 |
private class AbstractTableModel extends DefaultTableModel { |
|
425 |
mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, launcherPane, editionPane); |
|
426 |
mainPane.setOneTouchExpandable(true); |
|
409 | 427 |
|
410 |
/** |
|
411 |
* |
|
412 |
*/ |
|
413 |
private static final long serialVersionUID = -5314938428821653641L; |
|
428 |
// Barra de estado |
|
429 |
statusBar = new JPanel(new BorderLayout()); |
|
430 |
statusBarMessage = new JLabel(); |
|
431 |
statusBarMessage.setText(this.uimanager.getTranslation("Welcome_message")); |
|
432 |
currentLine = new JLabel(); |
|
433 |
currentLine.setText("Line 0:0"); |
|
414 | 434 |
|
415 |
@Override |
|
416 |
public boolean isCellEditable(int row, int col){ |
|
417 |
return false; |
|
418 |
} |
|
419 |
} |
|
435 |
statusBar.add(statusBarMessage, BorderLayout.WEST); |
|
436 |
statusBar.add(currentLine, BorderLayout.EAST); |
|
420 | 437 |
|
421 |
|
|
438 |
// Integracíón en el frame principal de todos los componentes |
|
439 |
JPanel buttons = new JPanel(); |
|
440 |
buttons.setLayout(new BorderLayout()); |
|
441 |
buttons.add(BorderLayout.NORTH, menuBar); |
|
442 |
buttons.add(BorderLayout.SOUTH, buttonsPane); |
|
443 |
|
|
444 |
this.setLayout(new BorderLayout()); |
|
445 |
this.add(BorderLayout.NORTH, buttons); |
|
446 |
this.add(BorderLayout.CENTER, mainPane); |
|
447 |
this.add(BorderLayout.SOUTH, statusBar); |
|
448 |
this.setPreferredSize(new Dimension(800, 600)); |
|
449 |
} |
|
450 |
|
|
451 |
private void createPackage() { |
|
452 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
453 |
WindowManager windowManager = ToolsSwingLocator.getWindowManager(); |
|
454 |
SwingInstallerManager installerManager = SwingInstallerLocator.getSwingInstallerManager(); |
|
455 |
Component packager = installerManager.createPackagerPanel( |
|
456 |
ScriptingManager.INSTALLER_PROVIDER_NAME, |
|
457 |
manager.getRootUserFolder(), |
|
458 |
manager.getPackagesFolder() |
|
459 |
); |
|
460 |
windowManager.showWindow( |
|
461 |
(JPanel) packager.asJComponent(), |
|
462 |
i18nManager.getTranslation("_Scripting_packager"), |
|
463 |
WindowManager.MODE.WINDOW |
|
464 |
); |
|
465 |
} |
|
466 |
|
|
467 |
private PrintStream getConsolePrintStream() { |
|
468 |
if (this.consolePrintStream == null) { |
|
469 |
JTextAreaOutputStream outputConsole = new JTextAreaOutputStream(console); |
|
470 |
this.consolePrintStream = new PrintStream(outputConsole); |
|
471 |
} |
|
472 |
return this.consolePrintStream; |
|
473 |
} |
|
474 |
|
|
475 |
private class AbstractTableModel extends DefaultTableModel { |
|
476 |
|
|
477 |
/** |
|
478 |
* |
|
479 |
*/ |
|
480 |
private static final long serialVersionUID = -5314938428821653641L; |
|
481 |
|
|
482 |
@Override |
|
483 |
public boolean isCellEditable(int row, int col) { |
|
484 |
return false; |
|
485 |
} |
|
486 |
} |
|
487 |
|
|
422 | 488 |
private class RowListener implements ListSelectionListener { |
489 |
|
|
423 | 490 |
public void valueChanged(ListSelectionEvent event) { |
424 | 491 |
if (event.getValueIsAdjusting()) { |
425 | 492 |
return; |
426 | 493 |
} |
427 |
if(!table.getSelectionModel().isSelectionEmpty()){
|
|
428 |
int index = table.getSelectionModel().getLeadSelectionIndex();
|
|
429 |
String[] lineAndColumn = ((String)table.getValueAt(index, 2)).split(":");
|
|
430 |
int line = -1;
|
|
431 |
if(lineAndColumn.length>0) {
|
|
432 |
try {
|
|
433 |
line = Integer.parseInt(lineAndColumn[0].trim());
|
|
434 |
} catch (Exception e) {
|
|
435 |
// Do nothing
|
|
436 |
}
|
|
437 |
}
|
|
438 |
if( line >= 0 ) {
|
|
439 |
setEditorSelection(((String)table.getValueAt(index, 1)), line);
|
|
440 |
}
|
|
494 |
if (!table.getSelectionModel().isSelectionEmpty()) {
|
|
495 |
int index = table.getSelectionModel().getLeadSelectionIndex();
|
|
496 |
String[] lineAndColumn = ((String) table.getValueAt(index, 2)).split(":");
|
|
497 |
int line = -1;
|
|
498 |
if (lineAndColumn.length > 0) {
|
|
499 |
try {
|
|
500 |
line = Integer.parseInt(lineAndColumn[0].trim());
|
|
501 |
} catch (Exception e) {
|
|
502 |
// Do nothing
|
|
503 |
}
|
|
504 |
}
|
|
505 |
if (line >= 0) {
|
|
506 |
setEditorSelection(((String) table.getValueAt(index, 1)), line);
|
|
507 |
}
|
|
441 | 508 |
} |
442 | 509 |
} |
443 | 510 |
} |
444 |
|
|
445 |
private void setEditorSelection(String name, int line){ |
|
446 |
for (int i=0; i<scriptEditors.getTabCount(); i++){
|
|
447 |
|
|
448 |
if(((JEditor)scriptEditors.getComponent(i)).getScript().getId().equals(name)){
|
|
449 |
scriptEditors.setSelectedIndex(i);
|
|
450 |
|
|
451 |
JTextComponent editor = ((JCodeEditor)scriptEditors.getComponent(i)).getJTextComponent();
|
|
452 |
editor.requestFocusInWindow();
|
|
453 |
|
|
454 |
String code = editor.getText();
|
|
455 |
int lineCounter = 0;
|
|
456 |
int initialSelection = 0;
|
|
457 |
int finalSelection = 0;
|
|
458 |
for(int j=0; j<code.length(); j++){
|
|
459 |
if (code.charAt(j) == '\n'){
|
|
460 |
lineCounter++;
|
|
461 |
if(lineCounter == line-1){
|
|
462 |
initialSelection = j;
|
|
463 |
}
|
|
464 |
if(lineCounter == line || (finalSelection==0 && j==code.length()-1)){
|
|
465 |
finalSelection = j;
|
|
466 |
}
|
|
467 |
}
|
|
468 |
}
|
|
469 |
|
|
470 |
editor.select(initialSelection,finalSelection);
|
|
471 |
}
|
|
472 |
}
|
|
511 |
|
|
512 |
private void setEditorSelection(String name, int line) {
|
|
513 |
for (int i = 0; i < scriptEditors.getTabCount(); i++) {
|
|
514 |
|
|
515 |
if (((JEditor) scriptEditors.getComponent(i)).getScript().getId().equals(name)) {
|
|
516 |
scriptEditors.setSelectedIndex(i);
|
|
517 |
|
|
518 |
JTextComponent editor = ((JCodeEditor) scriptEditors.getComponent(i)).getJTextComponent();
|
|
519 |
editor.requestFocusInWindow();
|
|
520 |
|
|
521 |
String code = editor.getText();
|
|
522 |
int lineCounter = 0;
|
|
523 |
int initialSelection = 0;
|
|
524 |
int finalSelection = 0;
|
|
525 |
for (int j = 0; j < code.length(); j++) {
|
|
526 |
if (code.charAt(j) == '\n') {
|
|
527 |
lineCounter++;
|
|
528 |
if (lineCounter == line - 1) {
|
|
529 |
initialSelection = j;
|
|
530 |
}
|
|
531 |
if (lineCounter == line || (finalSelection == 0 && j == code.length() - 1)) {
|
|
532 |
finalSelection = j;
|
|
533 |
}
|
|
534 |
}
|
|
535 |
}
|
|
536 |
|
|
537 |
editor.select(initialSelection, finalSelection);
|
|
538 |
}
|
|
539 |
}
|
|
473 | 540 |
} |
474 |
|
|
475 |
public void addDefaultActionListener(ActionListener actionlistener) { |
|
476 |
this.defaultActionlistener = actionlistener; |
|
477 |
} |
|
478 |
|
|
479 |
/** |
|
480 |
* Función para obtener el elemento seleccionado del Launcher |
|
481 |
* @return Selected ScriptingUnit on the tree |
|
482 |
*/ |
|
483 |
private ScriptingUnit getLauncherSelectedNode(){ |
|
484 |
JTabbedPane tabbed = launcher.getTabbedPane(); |
|
485 |
DefaultJScriptingBrowser browser = (DefaultJScriptingBrowser)tabbed.getSelectedComponent(); |
|
486 |
ScriptingUnit unit = browser.getSelectedNode(); |
|
487 |
return unit; |
|
488 |
} |
|
489 | 541 |
|
490 |
/** |
|
491 |
* Lanza el modo edición de un ScriptingBaseScript |
|
492 |
* @param unit |
|
493 |
*/ |
|
494 |
private void editSelectedNode(ScriptingUnit unit){ |
|
495 |
if(unit instanceof ScriptingBaseScript){ |
|
496 |
editUnit((ScriptingBaseScript)unit); |
|
497 |
} |
|
498 |
} |
|
542 |
public void addDefaultActionListener(ActionListener actionlistener) { |
|
543 |
this.defaultActionlistener = actionlistener; |
|
544 |
} |
|
499 | 545 |
|
500 |
/** |
|
501 |
* Lanza la ejecución de un ScriptingBaseScript |
|
502 |
* @param unit |
|
503 |
*/ |
|
504 |
private void runSelectedNode(ScriptingUnit unit){ |
|
505 |
if(unit instanceof ScriptingBaseScript){ |
|
506 |
((ScriptingBaseScript)unit).run(); |
|
507 |
} |
|
508 |
} |
|
546 |
/** |
|
547 |
* Función para obtener el elemento seleccionado del Launcher |
|
548 |
* |
|
549 |
* @return Selected ScriptingUnit on the tree |
|
550 |
*/ |
|
551 |
private ScriptingUnit getLauncherSelectedScript() { |
|
552 |
JTabbedPane tabbed = launcher.getTabbedPane(); |
|
553 |
DefaultJScriptingBrowser browser = (DefaultJScriptingBrowser) tabbed.getSelectedComponent(); |
|
554 |
ScriptingUnit unit = browser.getSelectedNode(); |
|
555 |
return unit; |
|
556 |
} |
|
509 | 557 |
|
510 |
/** |
|
511 |
* Funciones para obtener las botoneras en función del tipo de ScriptingBaseScript |
|
512 |
* que se esté mostrando en ese momento. Está la estándar 'getDefaultButtons()' para |
|
513 |
* cuando no hay ninguno, 'getScriptButtons()' con los botones característicos para |
|
514 |
* el manejo de ScriptingScripts y 'getDialogButtons()' para los ScriptingDialogs. |
|
515 |
* También se incluye 'getEditButtons()' con las funciones sobre la edición de texto |
|
516 |
* como copiar, cortar y pegar. |
|
517 |
* |
|
518 |
*/ |
|
519 |
private void setDefaultButtons(){ |
|
520 |
file.removeAll(); |
|
521 |
edit.removeAll(); |
|
522 |
script.removeAll(); |
|
523 |
help.removeAll(); |
|
524 |
JButton newb = new JButton(uimanager.getIcon("document-new")); |
|
525 |
newb.setToolTipText(this.uimanager.getTranslation("New")); |
|
526 |
newb.setBorderPainted(false); |
|
527 |
newb.addActionListener(new ActionListener(){ |
|
528 |
public void actionPerformed(ActionEvent e) { |
|
529 |
try { |
|
530 |
newScriptingBaseScript(); |
|
531 |
} catch (Exception e1) { |
|
532 |
// TODO Auto-generated catch block |
|
533 |
e1.printStackTrace(); |
|
534 |
} |
|
535 |
} |
|
536 |
}); |
|
537 |
file.add(newb); |
|
538 |
file.repaint(); |
|
558 |
/** |
|
559 |
* Lanza la ejecución de un ScriptingBaseScript |
|
560 |
* |
|
561 |
* @param unit |
|
562 |
*/ |
|
563 |
private void scriptExecute(ScriptingUnit unit) { |
|
564 |
if (unit instanceof ScriptingBaseScript) { |
|
565 |
((ScriptingBaseScript) unit).run(); |
|
566 |
} |
|
567 |
} |
|
539 | 568 |
|
540 |
help.removeAll(); |
|
541 |
JButton helpb = new JButton(uimanager.getIcon("help-browser")); |
|
542 |
helpb.setBorderPainted(false); |
|
543 |
helpb.setToolTipText(this.uimanager.getTranslation("Help")); |
|
544 |
helpb.addActionListener(new ActionListener(){ |
|
545 |
public void actionPerformed(ActionEvent e) { |
|
546 |
uimanager.showWindow(uimanager.getAPIHelp(), uimanager.getTranslation("JavaDoc")); |
|
547 |
} |
|
548 |
}); |
|
549 |
help.add(helpb); |
|
550 |
help.repaint(); |
|
551 |
edit.setVisible(false); |
|
552 |
script.setVisible(false); |
|
553 |
} |
|
569 |
/** |
|
570 |
* Funciones para obtener las botoneras en función del tipo de |
|
571 |
* ScriptingBaseScript que se esté mostrando en ese momento. Está la |
|
572 |
* estándar 'getDefaultButtons()' para cuando no hay ninguno, |
|
573 |
* 'getScriptButtons()' con los botones característicos para el manejo de |
|
574 |
* ScriptingScripts y 'getDialogButtons()' para los ScriptingDialogs. |
|
575 |
* También se incluye 'getEditButtons()' con las funciones sobre la |
|
576 |
* edición de texto como copiar, cortar y pegar. |
|
577 |
* |
|
578 |
*/ |
|
579 |
private void setButtonsDefault() { |
|
580 |
file.removeAll(); |
|
581 |
edit.removeAll(); |
|
582 |
script.removeAll(); |
|
583 |
help.removeAll(); |
|
584 |
JButton newb = new JButton(uimanager.getIcon("document-new")); |
|
585 |
newb.setToolTipText(this.uimanager.getTranslation("New")); |
|
586 |
newb.setBorderPainted(false); |
|
587 |
newb.addActionListener(new ActionListener() { |
|
588 |
public void actionPerformed(ActionEvent e) { |
|
589 |
try { |
|
590 |
scriptNew(); |
|
591 |
} catch (Exception e1) { |
|
592 |
// TODO Auto-generated catch block |
|
593 |
e1.printStackTrace(); |
|
594 |
} |
|
595 |
} |
|
596 |
}); |
|
597 |
file.add(newb); |
|
598 |
file.repaint(); |
|
554 | 599 |
|
555 |
private void setScriptButtons(){ |
|
556 |
file.removeAll(); |
|
557 |
edit.removeAll(); |
|
558 |
script.removeAll(); |
|
559 |
setDefaultButtons(); |
|
600 |
help.removeAll(); |
|
601 |
JButton helpb = new JButton(uimanager.getIcon("help-browser")); |
|
602 |
helpb.setBorderPainted(false); |
|
603 |
helpb.setToolTipText(this.uimanager.getTranslation("Help")); |
|
604 |
helpb.addActionListener(new ActionListener() { |
|
605 |
public void actionPerformed(ActionEvent e) { |
|
606 |
uimanager.showWindow(uimanager.getAPIHelp(), uimanager.getTranslation("JavaDoc")); |
|
607 |
} |
|
608 |
}); |
|
609 |
help.add(helpb); |
|
610 |
help.repaint(); |
|
611 |
edit.setVisible(false); |
|
612 |
script.setVisible(false); |
|
613 |
} |
|
560 | 614 |
|
561 |
edit.setVisible(true); |
|
562 |
script.setVisible(true); |
|
563 |
setEditButtons(); |
|
564 |
JButton close = new JButton(uimanager.getIcon("emblem-unreadable")); |
|
565 |
close.setBorderPainted(false); |
|
566 |
close.setToolTipText(this.uimanager.getTranslation("Close_current_tab")); |
|
567 |
close.addActionListener(new ActionListener(){ |
|
568 |
public void actionPerformed(ActionEvent e) { |
|
569 |
closeScriptingBaseScript(); |
|
570 |
} |
|
571 |
}); |
|
572 |
file.add(close); |
|
573 |
JButton save = new JButton(uimanager.getIcon("media-floppy")); |
|
574 |
save.setBorderPainted(false); |
|
575 |
save.setToolTipText(this.uimanager.getTranslation("Save")); |
|
576 |
save.addActionListener(new ActionListener(){ |
|
577 |
public void actionPerformed(ActionEvent e) { |
|
578 |
saveScriptingBaseScript(); |
|
579 |
} |
|
580 |
}); |
|
581 |
file.add(save); |
|
582 |
file.repaint(); |
|
615 |
private void setButtonsScript() { |
|
616 |
file.removeAll(); |
|
617 |
edit.removeAll(); |
|
618 |
script.removeAll(); |
|
619 |
setButtonsDefault(); |
|
583 | 620 |
|
584 |
JButton run = new JButton(uimanager.getIcon("applications-system")); |
|
585 |
run.setBorderPainted(false); |
|
586 |
run.setToolTipText(this.uimanager.getTranslation("Run")); |
|
587 |
run.addActionListener(new ActionListener(){ |
|
588 |
public void actionPerformed(ActionEvent e) { |
|
589 |
runScriptingBaseScript(); |
|
590 |
} |
|
591 |
}); |
|
592 |
script.add(run); |
|
593 |
script.repaint(); |
|
594 |
} |
|
621 |
edit.setVisible(true); |
|
622 |
script.setVisible(true); |
|
623 |
setButtonsEdit(); |
|
624 |
JButton close = new JButton(uimanager.getIcon("emblem-unreadable")); |
|
625 |
close.setBorderPainted(false); |
|
626 |
close.setToolTipText(this.uimanager.getTranslation("Close_current_tab")); |
|
627 |
close.addActionListener(new ActionListener() { |
|
628 |
public void actionPerformed(ActionEvent e) { |
|
629 |
currentScriptClose(); |
|
630 |
} |
|
631 |
}); |
|
632 |
file.add(close); |
|
633 |
JButton save = new JButton(uimanager.getIcon("media-floppy")); |
|
634 |
save.setBorderPainted(false); |
|
635 |
save.setToolTipText(this.uimanager.getTranslation("Save")); |
|
636 |
save.addActionListener(new ActionListener() { |
|
637 |
public void actionPerformed(ActionEvent e) { |
|
638 |
currentScriptSave(); |
|
639 |
} |
|
640 |
}); |
|
641 |
file.add(save); |
|
642 |
file.repaint(); |
|
595 | 643 |
|
596 |
private void setDialogButtons(){ |
|
597 |
script.removeAll(); |
|
598 |
setScriptButtons(); |
|
599 |
script.addSeparator(); |
|
600 |
JButton help = new JButton(uimanager.getIcon("help-browser")); |
|
601 |
help.setBorderPainted(false); |
|
602 |
help.setToolTipText(this.uimanager.getTranslation("Help")); |
|
603 |
script.add(help); |
|
604 |
script.repaint(); |
|
605 |
} |
|
644 |
JButton run = new JButton(uimanager.getIcon("applications-system")); |
|
645 |
run.setBorderPainted(false); |
|
646 |
run.setToolTipText(this.uimanager.getTranslation("Run")); |
|
647 |
run.addActionListener(new ActionListener() { |
|
648 |
public void actionPerformed(ActionEvent e) { |
|
649 |
currentScriptExecute(); |
|
650 |
} |
|
651 |
}); |
|
652 |
script.add(run); |
|
653 |
script.repaint(); |
|
654 |
} |
|
606 | 655 |
|
607 |
private void setEditButtons(){ |
|
608 |
JButton cut = new JButton(uimanager.getIcon("edit-cut")); |
|
609 |
cut.setBorderPainted(false); |
|
610 |
cut.setToolTipText(this.uimanager.getTranslation("Cut")); |
|
611 |
cut.addActionListener(new ActionListener(){ |
|
612 |
public void actionPerformed(ActionEvent e) { |
|
613 |
cutScriptingBaseScript(); |
|
614 |
} |
|
615 |
}); |
|
616 |
edit.add(cut); |
|
617 |
JButton copy = new JButton(uimanager.getIcon("edit-copy")); |
|
618 |
copy.setBorderPainted(false); |
|
619 |
copy.setToolTipText(this.uimanager.getTranslation("Copy")); |
|
620 |
copy.addActionListener(new ActionListener(){ |
|
621 |
public void actionPerformed(ActionEvent e) { |
|
622 |
copyScriptingBaseScript(); |
|
623 |
} |
|
624 |
}); |
|
625 |
edit.add(copy); |
|
626 |
JButton paste = new JButton(uimanager.getIcon("edit-paste")); |
|
627 |
paste.setBorderPainted(false); |
|
628 |
paste.setToolTipText(this.uimanager.getTranslation("Paste")); |
|
629 |
paste.addActionListener(new ActionListener(){ |
|
630 |
public void actionPerformed(ActionEvent e) { |
|
631 |
pasteScriptingBaseScript(); |
|
632 |
} |
|
633 |
}); |
|
634 |
edit.add(paste); |
|
635 |
edit.repaint(); |
|
636 |
} |
|
656 |
private void setButtonsDialog() { |
|
657 |
script.removeAll(); |
|
658 |
setButtonsScript(); |
|
659 |
script.addSeparator(); |
|
660 |
JButton help = new JButton(uimanager.getIcon("help-browser")); |
|
661 |
help.setBorderPainted(false); |
|
662 |
help.setToolTipText(this.uimanager.getTranslation("Help")); |
|
663 |
script.add(help); |
|
664 |
script.repaint(); |
|
665 |
} |
|
637 | 666 |
|
638 |
/** |
|
639 |
* Botonera con posibles acciones a realizar con el Panel Launcher |
|
640 |
* |
|
641 |
*/ |
|
642 |
private void setLauncherPaneButtons(){ |
|
667 |
private void setButtonsEdit() { |
|
668 |
JButton cut = new JButton(uimanager.getIcon("edit-cut")); |
|
669 |
cut.setBorderPainted(false); |
|
670 |
cut.setToolTipText(this.uimanager.getTranslation("Cut")); |
|
671 |
cut.addActionListener(new ActionListener() { |
|
672 |
public void actionPerformed(ActionEvent e) { |
|
673 |
currentScriptCut(); |
|
674 |
} |
|
675 |
}); |
|
676 |
edit.add(cut); |
|
677 |
JButton copy = new JButton(uimanager.getIcon("edit-copy")); |
|
678 |
copy.setBorderPainted(false); |
|
679 |
copy.setToolTipText(this.uimanager.getTranslation("Copy")); |
|
680 |
copy.addActionListener(new ActionListener() { |
|
681 |
public void actionPerformed(ActionEvent e) { |
|
682 |
currentScriptCopy(); |
|
683 |
} |
|
684 |
}); |
|
685 |
edit.add(copy); |
|
686 |
JButton paste = new JButton(uimanager.getIcon("edit-paste")); |
|
687 |
paste.setBorderPainted(false); |
|
688 |
paste.setToolTipText(this.uimanager.getTranslation("Paste")); |
|
689 |
paste.addActionListener(new ActionListener() { |
|
690 |
public void actionPerformed(ActionEvent e) { |
|
691 |
currentScriptPaste(); |
|
692 |
} |
|
693 |
}); |
|
694 |
edit.add(paste); |
|
695 |
edit.repaint(); |
|
696 |
} |
|
643 | 697 |
|
644 |
JButton newb = new JButton(uimanager.getIcon("document-new")); |
|
645 |
newb.setBorderPainted(false); |
|
646 |
newb.setToolTipText(this.uimanager.getTranslation("New")); |
|
647 |
newb.addActionListener(new ActionListener(){ |
|
648 |
public void actionPerformed(ActionEvent e) { |
|
649 |
try { |
|
650 |
newScriptingBaseScript(); |
|
651 |
} catch (Exception e1) { |
|
652 |
// TODO Auto-generated catch block |
|
653 |
e1.printStackTrace(); |
|
654 |
} |
|
655 |
} |
|
656 |
}); |
|
657 |
launcherButtons.add(newb); |
|
658 |
JButton edit = new JButton(uimanager.getIcon("applications-accessories")); |
|
659 |
edit.setBorderPainted(false); |
|
660 |
edit.setToolTipText(this.uimanager.getTranslation("Open_edition_mode")); |
|
661 |
edit.addActionListener(new ActionListener(){ |
|
662 |
public void actionPerformed(ActionEvent e) { |
|
663 |
editSelectedNode(getLauncherSelectedNode()); |
|
664 |
} |
|
665 |
}); |
|
666 |
launcherButtons.add(edit); |
|
667 |
JButton run = new JButton(uimanager.getIcon("applications-system")); |
|
668 |
run.setBorderPainted(false); |
|
669 |
run.setToolTipText(this.uimanager.getTranslation("Run_selected_script")); |
|
670 |
run.addActionListener(new ActionListener(){ |
|
671 |
public void actionPerformed(ActionEvent e) { |
|
672 |
runSelectedNode(getLauncherSelectedNode()); |
|
673 |
} |
|
674 |
}); |
|
675 |
launcherButtons.add(run); |
|
676 |
launcherButtons.addSeparator(); |
|
677 |
JButton refresh = new JButton(uimanager.getIcon("view-refresh")); |
|
678 |
refresh.setBorderPainted(false); |
|
679 |
refresh.setToolTipText(this.uimanager.getTranslation("Refresh_directories")); |
|
680 |
refresh.addActionListener(new ActionListener(){ |
|
681 |
public void actionPerformed(ActionEvent e) { |
|
682 |
launcherRefresh(); |
|
683 |
} |
|
684 |
}); |
|
685 |
launcherButtons.add(refresh); |
|
686 |
launcherButtons.addSeparator(); |
|
687 |
JButton rename = new JButton(uimanager.getIcon("preferences-system")); |
|
688 |
rename.setBorderPainted(false); |
|
689 |
rename.setToolTipText(this.uimanager.getTranslation("Set_file_properties")); |
|
690 |
rename.addActionListener(new ActionListener(){ |
|
691 |
public void actionPerformed(ActionEvent e) { |
|
692 |
try { |
|
693 |
renameSelectedNode(getLauncherSelectedNode()); |
|
694 |
} catch (Exception e1) { |
|
695 |
// TODO Auto-generated catch block |
|
696 |
e1.printStackTrace(); |
|
697 |
} |
|
698 |
} |
|
699 |
}); |
|
700 |
launcherButtons.add(rename); |
|
701 |
JButton move = new JButton(uimanager.getIcon("format-indent-more")); |
|
702 |
move.setBorderPainted(false); |
|
703 |
move.setToolTipText(this.uimanager.getTranslation("Move_files")); |
|
704 |
move.addActionListener(new ActionListener(){ |
|
705 |
public void actionPerformed(ActionEvent e){ |
|
706 |
try { |
|
707 |
moveSelectedNode(getLauncherSelectedNode()); |
|
708 |
} catch (Exception e1) { |
|
709 |
// TODO Auto-generated catch block |
|
710 |
e1.printStackTrace(); |
|
711 |
} |
|
712 |
} |
|
713 |
}); |
|
714 |
launcherButtons.add(move); |
|
715 |
launcherButtons.addSeparator(); |
|
716 |
JButton delete = new JButton(uimanager.getIcon("user-trash")); |
|
717 |
delete.setBorderPainted(false); |
|
718 |
delete.setToolTipText(this.uimanager.getTranslation("Delete_selected_script")); |
|
719 |
delete.addActionListener(new ActionListener(){ |
|
720 |
public void actionPerformed(ActionEvent e) { |
|
721 |
deleteSelectedNode(getLauncherSelectedNode(),false); |
|
722 |
} |
|
723 |
}); |
|
724 |
launcherButtons.add(delete); |
|
725 |
} |
|
698 |
/** |
|
699 |
* Botonera con posibles acciones a realizar con el Panel Launcher |
|
700 |
* |
|
701 |
*/ |
|
702 |
private void setButtonsLauncherPanel() { |
|
726 | 703 |
|
727 |
/** |
|
728 |
* Función que abre en modo edición un ScriptingBaseScript |
|
729 |
* @param unit |
|
730 |
*/ |
|
731 |
public void editUnit(ScriptingBaseScript unit){ |
|
732 |
JEditor panel = null; |
|
733 |
if( unit instanceof ScriptingDialog ) { |
|
734 |
panel = new DefaultJDialogEditor(uimanager, (ScriptingDialog) unit); |
|
735 |
if(panel instanceof DefaultJDialogEditor){ |
|
736 |
((DefaultJDialogEditor)panel).addDefaultActionListener(this); |
|
737 |
} |
|
738 |
}else if( unit instanceof ScriptingScript ) { |
|
739 |
panel = new DefaultJCodeEditor(uimanager, (ScriptingScript) unit); |
|
740 |
if(panel instanceof DefaultJCodeEditor){ |
|
741 |
((DefaultJCodeEditor)panel).addDefaultActionListener(this); |
|
742 |
} |
|
743 |
}else{ |
|
744 |
JOptionPane.showMessageDialog(null, this.uimanager.getTranslation("Error_opening_in_edition_mode"), this.uimanager.getTranslation("Error_opening_in_edition_mode_title"), JOptionPane.INFORMATION_MESSAGE); |
|
745 |
return ; |
|
746 |
} |
|
747 |
unitsEditor.add(panel); |
|
704 |
JButton newb = new JButton(uimanager.getIcon("document-new")); |
|
705 |
newb.setBorderPainted(false); |
|
706 |
newb.setToolTipText(this.uimanager.getTranslation("New")); |
|
707 |
newb.addActionListener(new ActionListener() { |
|
708 |
public void actionPerformed(ActionEvent e) { |
|
709 |
try { |
|
710 |
scriptNew(); |
|
711 |
} catch (Exception e1) { |
|
712 |
// TODO Auto-generated catch block |
|
713 |
e1.printStackTrace(); |
|
714 |
} |
|
715 |
} |
|
716 |
}); |
|
717 |
launcherButtons.add(newb); |
|
718 |
JButton edit = new JButton(uimanager.getIcon("applications-accessories")); |
|
719 |
edit.setBorderPainted(false); |
|
720 |
edit.setToolTipText(this.uimanager.getTranslation("Open_edition_mode")); |
|
721 |
edit.addActionListener(new ActionListener() { |
|
722 |
public void actionPerformed(ActionEvent e) { |
|
723 |
scriptEdit((ScriptingBaseScript)getLauncherSelectedScript()); |
|
724 |
} |
|
725 |
}); |
|
726 |
launcherButtons.add(edit); |
|
727 |
JButton run = new JButton(uimanager.getIcon("applications-system")); |
|
728 |
run.setBorderPainted(false); |
|
729 |
run.setToolTipText(this.uimanager.getTranslation("Run_selected_script")); |
|
730 |
run.addActionListener(new ActionListener() { |
|
731 |
public void actionPerformed(ActionEvent e) { |
|
732 |
scriptExecute(getLauncherSelectedScript()); |
|
733 |
} |
|
734 |
}); |
|
735 |
launcherButtons.add(run); |
|
736 |
launcherButtons.addSeparator(); |
|
737 |
JButton refresh = new JButton(uimanager.getIcon("view-refresh")); |
|
738 |
refresh.setBorderPainted(false); |
|
739 |
refresh.setToolTipText(this.uimanager.getTranslation("Refresh_directories")); |
|
740 |
refresh.addActionListener(new ActionListener() { |
|
741 |
public void actionPerformed(ActionEvent e) { |
|
742 |
launcherRefresh(); |
|
743 |
} |
|
744 |
}); |
|
745 |
launcherButtons.add(refresh); |
|
746 |
launcherButtons.addSeparator(); |
|
747 |
JButton rename = new JButton(uimanager.getIcon("preferences-system")); |
|
748 |
rename.setBorderPainted(false); |
|
749 |
rename.setToolTipText(this.uimanager.getTranslation("Set_file_properties")); |
|
750 |
rename.addActionListener(new ActionListener() { |
|
751 |
public void actionPerformed(ActionEvent e) { |
|
752 |
try { |
|
753 |
scriptRename(getLauncherSelectedScript()); |
|
754 |
} catch (Exception e1) { |
|
755 |
// TODO Auto-generated catch block |
|
756 |
e1.printStackTrace(); |
|
757 |
} |
|
758 |
} |
|
759 |
}); |
|
760 |
launcherButtons.add(rename); |
|
761 |
JButton move = new JButton(uimanager.getIcon("format-indent-more")); |
|
762 |
move.setBorderPainted(false); |
|
763 |
move.setToolTipText(this.uimanager.getTranslation("Move_files")); |
|
764 |
move.addActionListener(new ActionListener() { |
|
765 |
public void actionPerformed(ActionEvent e) { |
|
766 |
try { |
|
767 |
scriptMove(getLauncherSelectedScript()); |
|
768 |
} catch (Exception e1) { |
|
769 |
// TODO Auto-generated catch block |
|
770 |
e1.printStackTrace(); |
|
771 |
} |
|
772 |
} |
|
773 |
}); |
|
774 |
launcherButtons.add(move); |
|
775 |
launcherButtons.addSeparator(); |
|
776 |
JButton delete = new JButton(uimanager.getIcon("user-trash")); |
|
777 |
delete.setBorderPainted(false); |
|
778 |
delete.setToolTipText(this.uimanager.getTranslation("Delete_selected_script")); |
|
779 |
delete.addActionListener(new ActionListener() { |
|
780 |
public void actionPerformed(ActionEvent e) { |
|
781 |
scriptDelete(getLauncherSelectedScript(), false); |
|
782 |
} |
|
783 |
}); |
|
784 |
launcherButtons.add(delete); |
|
785 |
} |
|
748 | 786 |
|
749 |
Iterator<JEditor> it = unitsEditor.iterator(); |
|
750 |
while(it.hasNext()){ |
|
751 |
JEditor editor = it.next(); |
|
752 |
String title; |
|
753 |
if (editor.getScript().isSaved()){ |
|
754 |
title = editor.getScript().getName(); |
|
755 |
}else{ |
|
756 |
title = "*"+editor.getScript().getName(); |
|
757 |
} |
|
758 |
|
|
759 |
scriptEditors.addTab(title, editor); |
|
760 |
} |
|
761 |
scriptEditors.setSelectedIndex(unitsEditor.size()-1); |
|
762 |
editionPane.repaint(); |
|
763 |
file.repaint(); |
|
764 |
} |
|
787 |
/** |
|
788 |
* Función que abre en modo edición un ScriptingBaseScript |
|
789 |
* |
|
790 |
* @param unit |
|
791 |
*/ |
|
792 |
public void scriptEdit(ScriptingBaseScript unit) { |
|
793 |
if( ! unitsEditor.containsKey(unit.getFile().getAbsolutePath()) ) { |
|
794 |
JEditor panel = null; |
|
795 |
if (unit instanceof ScriptingDialog) { |
|
796 |
panel = new DefaultJDialogEditor(uimanager, (ScriptingDialog) unit); |
|
797 |
if (panel instanceof DefaultJDialogEditor) { |
|
798 |
((DefaultJDialogEditor) panel).addDefaultActionListener(this); |
|
799 |
} |
|
800 |
} else if (unit instanceof ScriptingScript) { |
|
801 |
panel = new DefaultJCodeEditor(uimanager, (ScriptingScript) unit); |
|
802 |
if (panel instanceof DefaultJCodeEditor) { |
|
803 |
((DefaultJCodeEditor) panel).addDefaultActionListener(this); |
|
804 |
} |
|
805 |
} else { |
|
806 |
JOptionPane.showMessageDialog(null, this.uimanager.getTranslation("Error_opening_in_edition_mode"), this.uimanager.getTranslation("Error_opening_in_edition_mode_title"), JOptionPane.INFORMATION_MESSAGE); |
|
807 |
return; |
|
808 |
} |
|
809 |
unitsEditor.put(unit.getFile().getAbsolutePath(), panel); |
|
810 |
} |
|
811 |
int n = 0; |
|
812 |
int selected = unitsEditor.size() - 1; |
|
813 |
Iterator<JEditor> it = unitsEditor.values().iterator(); |
|
814 |
while (it.hasNext()) { |
|
815 |
JEditor editor = it.next(); |
|
816 |
String title; |
|
817 |
if (editor.getScript().isSaved()) { |
|
818 |
title = editor.getScript().getName(); |
|
819 |
} else { |
|
820 |
title = "*" + editor.getScript().getName(); |
|
821 |
} |
|
822 |
scriptEditors.addTab(title, editor); |
|
823 |
if( editor.getScript().getFile().getAbsolutePath().equals(unit.getFile().getAbsolutePath()) ) { |
|
824 |
selected = n; |
|
825 |
} |
|
826 |
n++; |
|
827 |
} |
|
828 |
scriptEditors.setSelectedIndex(selected); |
|
829 |
editionPane.repaint(); |
|
830 |
file.repaint(); |
|
831 |
} |
|
765 | 832 |
|
833 |
/** |
|
834 |
* Ventana para creación de nuevos ScriptingBaseScripts |
|
835 |
* |
|
836 |
* @throws Exception |
|
837 |
* |
|
838 |
*/ |
|
839 |
public void scriptNew() throws Exception { |
|
840 |
JNewScriptModel model = new JNewScriptModel(manager); |
|
841 |
JDialogContent dialog = new JDialogContent( |
|
842 |
uimanager, |
|
843 |
"document-new", |
|
844 |
this.uimanager.getTranslation("New_Script"), |
|
845 |
this.uimanager.getTranslation("New_Script_Description"), |
|
846 |
new JNewScriptPanel(uimanager, model) |
|
847 |
); |
|
848 |
dialog.showDialog(); |
|
849 |
if (model.getAction() == JNewScriptModel.ACTION_ACCEPT) { |
|
850 |
model.validate(); |
|
851 |
ScriptingUnit unit = this.manager.createUnit( |
|
852 |
model.getType(), |
|
853 |
manager.getFolder(new File(model.getPath())), |
|
854 |
model.getName(), |
|
855 |
model.getLanguage() |
|
856 |
); |
|
857 |
if (unit instanceof ScriptingBaseScript) { |
|
858 |
this.scriptEdit((ScriptingBaseScript) unit); |
|
859 |
} |
|
766 | 860 |
|
767 |
/** |
|
768 |
* Ventana para creación de nuevos ScriptingBaseScripts |
|
769 |
* @throws Exception |
|
770 |
* |
|
771 |
*/ |
|
772 |
public void newScriptingBaseScript() throws Exception{ |
|
773 |
JNewScriptModel model = new JNewScriptModel(manager); |
Also available in: Unified diff