Revision 320 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.main/src/main/java/org/gvsig/scripting/main/Main.java
Main.java | ||
---|---|---|
10 | 10 |
import java.util.HashMap; |
11 | 11 |
import java.util.Map; |
12 | 12 |
|
13 |
import javax.swing.JButton; |
|
14 | 13 |
import javax.swing.JFrame; |
15 | 14 |
import javax.swing.JMenu; |
16 | 15 |
import javax.swing.JMenuBar; |
17 | 16 |
import javax.swing.JMenuItem; |
18 | 17 |
import javax.swing.JPanel; |
19 |
import javax.swing.JToolBar; |
|
20 | 18 |
import javax.swing.WindowConstants; |
21 | 19 |
|
20 |
import org.apache.commons.cli.CommandLine; |
|
21 |
import org.apache.commons.cli.CommandLineParser; |
|
22 |
import org.apache.commons.cli.Options; |
|
23 |
import org.apache.commons.cli.ParseException; |
|
24 |
import org.apache.commons.cli.PosixParser; |
|
22 | 25 |
import org.gvsig.about.AboutLocator; |
23 | 26 |
import org.gvsig.about.AboutManager; |
24 |
import org.gvsig.about.AboutParticipant;
|
|
27 |
import org.gvsig.scripting.ScriptingDialog;
|
|
25 | 28 |
import org.gvsig.scripting.ScriptingManager; |
26 | 29 |
import org.gvsig.scripting.swing.api.ScriptingSwingLocator; |
27 | 30 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
... | ... | |
29 | 32 |
|
30 | 33 |
public class Main { |
31 | 34 |
|
32 |
/**
|
|
35 |
/**
|
|
33 | 36 |
* |
34 | 37 |
*/ |
35 |
private static final long serialVersionUID = -6853523688803006280L; |
|
36 |
static ScriptingUIManager uimanager; |
|
37 |
static AboutManager aboutManager; |
|
38 |
private static final long serialVersionUID = -6853523688803006280L; |
|
39 |
ScriptingUIManager uimanager; |
|
40 |
AboutManager aboutManager; |
|
41 |
ScriptingManager manager; |
|
38 | 42 |
|
39 |
public static void main(String args[]) {
|
|
40 |
Main main = new Main();
|
|
41 |
main.doMain(args);
|
|
42 |
}
|
|
43 |
public static void main(String args[]) {
|
|
44 |
Main main = new Main();
|
|
45 |
main.doMain(args);
|
|
46 |
}
|
|
43 | 47 |
|
44 |
|
|
45 |
private void initializeAbout() { |
|
46 |
aboutManager = AboutLocator.getManager(); |
|
48 |
private void initializeAbout() { |
|
49 |
aboutManager = AboutLocator.getManager(); |
|
47 | 50 |
|
48 |
Map<String, String> gvsig_vars = new HashMap<String, String>();
|
|
49 |
gvsig_vars.put("version", "2.0.0");
|
|
50 |
gvsig_vars.put("build", "2020");
|
|
51 |
aboutManager.setProject("gvSIG Desktop", getResource("gvsig.html"),
|
|
52 |
null, gvsig_vars);
|
|
53 |
aboutManager.getProject().set("build", "2021");
|
|
51 |
Map<String, String> gvsig_vars = new HashMap<String, String>();
|
|
52 |
gvsig_vars.put("version", "2.0.0");
|
|
53 |
gvsig_vars.put("build", "2020");
|
|
54 |
aboutManager.setProject("gvSIG Desktop", getResource("gvsig.html"),
|
|
55 |
null, gvsig_vars);
|
|
56 |
aboutManager.getProject().set("build", "2021");
|
|
54 | 57 |
|
55 |
AboutParticipant participant; |
|
58 |
aboutManager.addSponsor("Generalitat Valenciana", |
|
59 |
getResource("gva.html"), 1); |
|
56 | 60 |
|
57 |
participant = |
|
58 |
aboutManager.addSponsor("Generalitat Valenciana", |
|
59 |
getResource("gva.html"), 1); |
|
61 |
aboutManager.addDeveloper("gvSIG Asocicion", |
|
62 |
getResource("gvSIG-asociacion.html"), 2); |
|
60 | 63 |
|
61 |
participant = |
|
62 |
aboutManager.addDeveloper("IVER", getResource("iver.html"), 2); |
|
64 |
} |
|
63 | 65 |
|
64 |
participant = |
|
65 |
aboutManager.addDeveloper("PRODEVELOP", |
|
66 |
getResource("prodevelop.html"), 2); |
|
66 |
public void doMain(String args[]) { |
|
67 | 67 |
|
68 |
participant = |
|
69 |
aboutManager.addDeveloper("Software Colaborativo", |
|
70 |
getResource("scolab.html"), 3); |
|
68 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
71 | 69 |
|
72 |
participant = |
|
73 |
aboutManager.addDeveloper("DISID", getResource("disid.html"), 4); |
|
70 |
initializeAbout(); |
|
74 | 71 |
|
75 |
participant =
|
|
76 |
aboutManager.addDeveloper("UCLM", getResource("uclm.html"), 5);
|
|
72 |
uimanager = ScriptingSwingLocator.getUIManager();
|
|
73 |
manager = uimanager.getManager();
|
|
77 | 74 |
|
78 |
participant = |
|
79 |
aboutManager.addDeveloper("CSGIS", getResource("csgis.html"), 5); |
|
75 |
Options options = new Options(); |
|
76 |
options.addOption("l", "show-launcher", false, |
|
77 |
"Show the launcher window"); |
|
78 |
options.addOption("c", "show-composer", false, |
|
79 |
"Show the composer window"); |
|
80 |
options.addOption("r", "run", true, "Run the specified script"); |
|
81 |
options.addOption("s", "show", true, "Show the specified dialog"); |
|
82 |
options.addOption("h", "home", true, |
|
83 |
"Specify for the home of the script framework"); |
|
84 |
CommandLineParser parser = new PosixParser(); |
|
85 |
CommandLine line = null; |
|
86 |
try { |
|
87 |
line = parser.parse(options, args); |
|
88 |
if (line.hasOption("home")) { |
|
89 |
manager.setHomeFolder(new File(line.getOptionValue("home"))); |
|
90 |
} |
|
91 |
if (line.hasOption("show-launcher")) { |
|
92 |
showLauncher(); |
|
93 |
} |
|
94 |
if (line.hasOption("show-composer")) { |
|
95 |
showComposer(); |
|
96 |
} |
|
97 |
if (line.hasOption("run")) { |
|
98 |
manager.getScript(new File(line.getOptionValue("run"))).run(); |
|
99 |
} |
|
100 |
if (line.hasOption("show")) { |
|
101 |
showDialog(line.getOptionValue("show")); |
|
102 |
if ( !(line.hasOption("show-launcher") || line.hasOption("show-composer")) ) { |
|
103 |
System.exit(0); |
|
104 |
} |
|
105 |
} |
|
106 |
} catch (ParseException exp) { |
|
107 |
System.out.println("Unexpected exception:" + exp.getMessage()); |
|
108 |
} |
|
109 |
String[] moreArgs = line.getArgs(); |
|
110 |
if( moreArgs.length > 0 ) { |
|
111 |
showDialog(moreArgs[0]); |
|
112 |
System.exit(0); |
|
113 |
} |
|
114 |
showLauncher(); |
|
115 |
} |
|
80 | 116 |
|
81 |
participant = aboutManager.getDeveloper("PRODEVELOP"); |
|
82 |
participant.addContribution("JDBC Oracle Spatial", |
|
83 |
"Prodevelop S.L. ha mejorado y ampliado la extension extJDBC " |
|
84 |
+ "y ha a?adido el driver para el acceso a informacion " |
|
85 |
+ "geografica en bases de datos Oracle.", getDate(2009, 1, 2), |
|
86 |
getDate(2009, 12, 21)); |
|
87 |
participant.addContribution("ArcIMS", "Cliente ArcIMS para gvSIG", |
|
88 |
getDate(2009, 1, 2), getDate(2009, 12, 21)); |
|
117 |
private void showDialog(String name) { |
|
118 |
if (!name.endsWith(".dlg")) { |
|
119 |
name = name + ".dlg"; |
|
120 |
} |
|
121 |
ScriptingDialog dlg = (ScriptingDialog) manager |
|
122 |
.getScript(new File(name)); |
|
123 |
dlg.setShowMode(ScriptingDialog.MODE_DIALOG); |
|
124 |
dlg.run(); |
|
125 |
} |
|
89 | 126 |
|
90 |
participant = aboutManager.getDeveloper("DISID"); |
|
91 |
participant.addContribution("Gesti?n de Internacionalizacion", |
|
92 |
"Extensi?n de Gesti?n de traducciones", getDate(2009, 1, 2), |
|
93 |
getDate(2009, 12, 21)); |
|
127 |
private void showLauncher() { |
|
128 |
JFrame frame = new JFrame("gvSIG's Script Framework"); |
|
129 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
94 | 130 |
|
95 |
participant = aboutManager.getDeveloper("UCLM"); |
|
96 |
participant.addContribution("JCRS", |
|
97 |
"Extensi?n para el manejo de Sistemas de Referencia de " |
|
98 |
+ "Coordenadas", getDate(2009, 1, 2), getDate(2009, 12, 21)); |
|
131 |
// Create the menu bar. |
|
132 |
JMenuBar menuBar = new JMenuBar(); |
|
99 | 133 |
|
100 |
participant = |
|
101 |
aboutManager.addSponsor("Junta Castilla y Le?n", |
|
102 |
getResource("castillaLeon.html"), 2); |
|
103 |
participant.addContribution("Backup del fichero GVP", |
|
104 |
"Backup automatico del gvp antes de guardar", getDate(2009, 6, 1), |
|
105 |
getDate(2009, 12, 1)); |
|
106 |
participant.addContribution("Herramienta de informacion rapida", |
|
107 |
"Herramienta que muestra un tip con la informacion de las " |
|
108 |
+ "geometrias sobre las que pasa el puntero", |
|
109 |
getDate(2009, 6, 1), getDate(2009, 12, 1)); |
|
110 |
participant.addContribution("Herramientas de seleccion", |
|
111 |
"Varias herramientas de seleccion", 2009, 6, 1, 2009, 12, 1); |
|
134 |
// Build the menu. |
|
135 |
JMenu menu_file = new JMenu("File"); |
|
112 | 136 |
|
113 |
participant = |
|
114 |
aboutManager.addSponsor("Region de Murcia", |
|
115 |
getResource("regionDeMurcia.html"), 2); |
|
116 |
participant.addContribution("ArcSDE", |
|
117 |
"Extesi?n de la Aplicaci?n para la conexi?n con una Base de " |
|
118 |
+ "Datos ArcSDE.", getDate(2009, 6, 1), getDate(2009, 12, 1)); |
|
137 |
JMenuItem menuItem_composer = new JMenuItem("Composer"); |
|
138 |
menuItem_composer.addActionListener(new ActionListener() { |
|
119 | 139 |
|
120 |
participant = |
|
121 |
aboutManager.addTranslator("Gustavo P?rez", |
|
122 |
getResource("gustavoPerez.html"), 1); |
|
123 |
participant |
|
124 |
.addContribution("traducci?n multidioma", "traducci?n al franc?s", |
|
125 |
getDate(2009, 1, 2), getDate(2009, 12, 21)); |
|
126 |
} |
|
127 |
|
|
128 |
public void doMain(String args[]) { |
|
140 |
public void actionPerformed(ActionEvent e) { |
|
141 |
showComposer(); |
|
142 |
} |
|
143 |
}); |
|
144 |
menu_file.add(menuItem_composer); |
|
129 | 145 |
|
130 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
146 |
JMenuItem menuItem_installer = new JMenuItem("Install package"); |
|
147 |
menuItem_installer.addActionListener(new ActionListener() { |
|
131 | 148 |
|
132 |
// This step is necessary for extensions to work: |
|
133 |
/* |
|
134 |
* try { |
|
135 |
* PlatformInit.getInstance().init(false, false); |
|
136 |
* } catch (Exception e1) { |
|
137 |
* // TODO Auto-generated catch block |
|
138 |
* e1.printStackTrace(); |
|
139 |
* } |
|
140 |
*/ |
|
141 |
initializeAbout(); |
|
149 |
public void actionPerformed(ActionEvent e) { |
|
150 |
showPackageInstaller(manager); |
|
151 |
} |
|
152 |
}); |
|
153 |
menu_file.add(menuItem_installer); |
|
142 | 154 |
|
143 |
// Asignamos el locator e iniciamos la instancia |
|
144 |
uimanager = ScriptingSwingLocator.getUIManager(); |
|
145 |
final ScriptingManager manager = uimanager.getManager(); |
|
155 |
JMenuItem menuItem_installPackage = new JMenuItem("Build package"); |
|
156 |
menuItem_installer.addActionListener(new ActionListener() { |
|
146 | 157 |
|
147 |
// // Ejemplo de mecanismo de registro de paquetes para la Browser del |
|
148 |
// // Sistema |
|
149 |
// URL u = |
|
150 |
// Main.class.getClassLoader().getResource( |
|
151 |
// "org/gvsig/scripting/impl/scripts/"); |
|
152 |
// File f = new File(u.getPath()); |
|
153 |
// manager.registerSystemFolder("Tests", f); |
|
154 |
// |
|
155 |
// uimanager.addUserHelp("es", Main.class.getResource("/")); |
|
158 |
public void actionPerformed(ActionEvent e) { |
|
159 |
showPackageBuilder(manager); |
|
160 |
} |
|
161 |
}); |
|
162 |
menu_file.add(menuItem_installPackage); |
|
156 | 163 |
|
157 |
JFrame frame = new JFrame("gvSIG's Script Framework"); |
|
158 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
164 |
menu_file.addSeparator(); |
|
159 | 165 |
|
160 |
// Create the menu bar.
|
|
161 |
JMenuBar menuBar = new JMenuBar();
|
|
166 |
JMenuItem menuItem_exit = new JMenuItem("Exit");
|
|
167 |
menuItem_exit.addActionListener(new ActionListener() {
|
|
162 | 168 |
|
163 |
// Build the menu. |
|
164 |
JMenu menu_file = new JMenu("File"); |
|
169 |
public void actionPerformed(ActionEvent e) { |
|
170 |
System.exit(0); |
|
171 |
} |
|
172 |
}); |
|
173 |
menu_file.add(menuItem_exit); |
|
165 | 174 |
|
166 |
JMenuItem menuItem_composer = new JMenuItem("Composer"); |
|
167 |
menuItem_composer.addActionListener(new ActionListener() { |
|
175 |
menuBar.add(menu_file); |
|
168 | 176 |
|
169 |
public void actionPerformed(ActionEvent e) { |
|
170 |
showComposer(manager); |
|
171 |
} |
|
172 |
}); |
|
173 |
menu_file.add(menuItem_composer); |
|
177 |
frame.add(menuBar, BorderLayout.NORTH); |
|
178 |
frame.add(uimanager.createLauncher(), BorderLayout.CENTER); |
|
174 | 179 |
|
175 |
JMenuItem menuItem_installer = new JMenuItem("Install package"); |
|
176 |
menuItem_installer.addActionListener(new ActionListener() { |
|
180 |
// Display the window. |
|
181 |
frame.pack(); |
|
182 |
frame.setVisible(true); |
|
177 | 183 |
|
178 |
public void actionPerformed(ActionEvent e) { |
|
179 |
showPackageInstaller(manager); |
|
180 |
} |
|
181 |
}); |
|
182 |
menu_file.add(menuItem_installer); |
|
184 |
} |
|
183 | 185 |
|
184 |
JMenuItem menuItem_installPackage = new JMenuItem("Build package"); |
|
185 |
menuItem_installer.addActionListener(new ActionListener() { |
|
186 |
@SuppressWarnings("unused") |
|
187 |
private Date getDate(int year, int month, int day) { |
|
188 |
Calendar cal = Calendar.getInstance(); |
|
189 |
cal.set(year, month, day); |
|
190 |
return cal.getTime(); |
|
191 |
} |
|
186 | 192 |
|
187 |
public void actionPerformed(ActionEvent e) { |
|
188 |
showPackageBuilder(manager); |
|
189 |
} |
|
190 |
}); |
|
191 |
menu_file.add(menuItem_installPackage); |
|
193 |
private URL getResource(String name) { |
|
194 |
URL resource = this.getClass().getResource(name); |
|
195 |
return resource; |
|
196 |
} |
|
192 | 197 |
|
193 |
|
|
194 |
menu_file.addSeparator(); |
|
198 |
private void showComposer() { |
|
199 |
showWindow(uimanager.createComposer(), "Scripting Composer"); |
|
200 |
} |
|
195 | 201 |
|
196 |
JMenuItem menuItem_exit = new JMenuItem("Exit"); |
|
197 |
menuItem_exit.addActionListener(new ActionListener() { |
|
202 |
private void showPackageInstaller(ScriptingManager manager) { |
|
203 |
// not implemented |
|
204 |
} |
|
198 | 205 |
|
199 |
public void actionPerformed(ActionEvent e) { |
|
200 |
System.exit(0); |
|
201 |
} |
|
202 |
}); |
|
203 |
menu_file.add(menuItem_exit); |
|
206 |
private void showPackageBuilder(ScriptingManager manager) { |
|
207 |
// not implemented |
|
208 |
} |
|
204 | 209 |
|
205 |
menuBar.add(menu_file); |
|
210 |
private void showWindow(JPanel panel, String title) { |
|
211 |
JFrame frame = new JFrame(title); |
|
212 |
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
|
206 | 213 |
|
207 |
frame.add(menuBar, BorderLayout.NORTH); |
|
208 |
frame.add( uimanager.createBrowser(uimanager, manager.getUserFolder()), BorderLayout.CENTER); |
|
214 |
frame.setContentPane(panel); |
|
209 | 215 |
|
210 |
// Display the window. |
|
211 |
frame.pack(); |
|
212 |
frame.setVisible(true); |
|
213 |
|
|
214 |
} |
|
215 |
|
|
216 |
private Date getDate(int year, int month, int day) { |
|
217 |
Calendar cal = Calendar.getInstance(); |
|
218 |
cal.set(year, month, day); |
|
219 |
return cal.getTime(); |
|
220 |
} |
|
221 |
|
|
222 |
private URL getResource(String name) { |
|
223 |
URL resource = this.getClass().getResource(name); |
|
224 |
return resource; |
|
225 |
} |
|
226 |
|
|
227 |
private void showComposer(ScriptingManager manager) { |
|
228 |
showWindow(uimanager.createComposer(), "Scripting Composer"); |
|
229 |
} |
|
230 |
|
|
231 |
private void showPackageInstaller(ScriptingManager manager) { |
|
232 |
// not implemented |
|
233 |
} |
|
234 |
|
|
235 |
private void showPackageBuilder(ScriptingManager manager) { |
|
236 |
// not implemented |
|
237 |
} |
|
238 |
|
|
239 |
private void showWindow(JPanel panel, String title) { |
|
240 |
JFrame frame = new JFrame(title); |
|
241 |
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
|
242 |
|
|
243 |
frame.setContentPane(panel); |
|
244 |
|
|
245 |
// Display the window. |
|
246 |
frame.pack(); |
|
247 |
frame.setVisible(true); |
|
248 |
} |
|
216 |
// Display the window. |
|
217 |
frame.pack(); |
|
218 |
frame.setVisible(true); |
|
219 |
} |
|
249 | 220 |
} |
Also available in: Unified diff