gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.main / src / main / java / org / gvsig / scripting / main / Main.java @ 320
History | View | Annotate | Download (5.83 KB)
1 |
package org.gvsig.scripting.main; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.io.File; |
7 |
import java.net.URL; |
8 |
import java.util.Calendar; |
9 |
import java.util.Date; |
10 |
import java.util.HashMap; |
11 |
import java.util.Map; |
12 |
|
13 |
import javax.swing.JFrame; |
14 |
import javax.swing.JMenu; |
15 |
import javax.swing.JMenuBar; |
16 |
import javax.swing.JMenuItem; |
17 |
import javax.swing.JPanel; |
18 |
import javax.swing.WindowConstants; |
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; |
25 |
import org.gvsig.about.AboutLocator; |
26 |
import org.gvsig.about.AboutManager; |
27 |
import org.gvsig.scripting.ScriptingDialog; |
28 |
import org.gvsig.scripting.ScriptingManager; |
29 |
import org.gvsig.scripting.swing.api.ScriptingSwingLocator; |
30 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
31 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
32 |
|
33 |
public class Main { |
34 |
|
35 |
/**
|
36 |
*
|
37 |
*/
|
38 |
private static final long serialVersionUID = -6853523688803006280L; |
39 |
ScriptingUIManager uimanager; |
40 |
AboutManager aboutManager; |
41 |
ScriptingManager manager; |
42 |
|
43 |
public static void main(String args[]) { |
44 |
Main main = new Main();
|
45 |
main.doMain(args); |
46 |
} |
47 |
|
48 |
private void initializeAbout() { |
49 |
aboutManager = AboutLocator.getManager(); |
50 |
|
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"); |
57 |
|
58 |
aboutManager.addSponsor("Generalitat Valenciana",
|
59 |
getResource("gva.html"), 1); |
60 |
|
61 |
aboutManager.addDeveloper("gvSIG Asocicion",
|
62 |
getResource("gvSIG-asociacion.html"), 2); |
63 |
|
64 |
} |
65 |
|
66 |
public void doMain(String args[]) { |
67 |
|
68 |
new DefaultLibrariesInitializer().fullInitialize();
|
69 |
|
70 |
initializeAbout(); |
71 |
|
72 |
uimanager = ScriptingSwingLocator.getUIManager(); |
73 |
manager = uimanager.getManager(); |
74 |
|
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 |
} |
116 |
|
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 |
} |
126 |
|
127 |
private void showLauncher() { |
128 |
JFrame frame = new JFrame("gvSIG's Script Framework"); |
129 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
130 |
|
131 |
// Create the menu bar.
|
132 |
JMenuBar menuBar = new JMenuBar(); |
133 |
|
134 |
// Build the menu.
|
135 |
JMenu menu_file = new JMenu("File"); |
136 |
|
137 |
JMenuItem menuItem_composer = new JMenuItem("Composer"); |
138 |
menuItem_composer.addActionListener(new ActionListener() { |
139 |
|
140 |
public void actionPerformed(ActionEvent e) { |
141 |
showComposer(); |
142 |
} |
143 |
}); |
144 |
menu_file.add(menuItem_composer); |
145 |
|
146 |
JMenuItem menuItem_installer = new JMenuItem("Install package"); |
147 |
menuItem_installer.addActionListener(new ActionListener() { |
148 |
|
149 |
public void actionPerformed(ActionEvent e) { |
150 |
showPackageInstaller(manager); |
151 |
} |
152 |
}); |
153 |
menu_file.add(menuItem_installer); |
154 |
|
155 |
JMenuItem menuItem_installPackage = new JMenuItem("Build package"); |
156 |
menuItem_installer.addActionListener(new ActionListener() { |
157 |
|
158 |
public void actionPerformed(ActionEvent e) { |
159 |
showPackageBuilder(manager); |
160 |
} |
161 |
}); |
162 |
menu_file.add(menuItem_installPackage); |
163 |
|
164 |
menu_file.addSeparator(); |
165 |
|
166 |
JMenuItem menuItem_exit = new JMenuItem("Exit"); |
167 |
menuItem_exit.addActionListener(new ActionListener() { |
168 |
|
169 |
public void actionPerformed(ActionEvent e) { |
170 |
System.exit(0); |
171 |
} |
172 |
}); |
173 |
menu_file.add(menuItem_exit); |
174 |
|
175 |
menuBar.add(menu_file); |
176 |
|
177 |
frame.add(menuBar, BorderLayout.NORTH);
|
178 |
frame.add(uimanager.createLauncher(), BorderLayout.CENTER);
|
179 |
|
180 |
// Display the window.
|
181 |
frame.pack(); |
182 |
frame.setVisible(true);
|
183 |
|
184 |
} |
185 |
|
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 |
} |
192 |
|
193 |
private URL getResource(String name) { |
194 |
URL resource = this.getClass().getResource(name); |
195 |
return resource;
|
196 |
} |
197 |
|
198 |
private void showComposer() { |
199 |
showWindow(uimanager.createComposer(), "Scripting Composer");
|
200 |
} |
201 |
|
202 |
private void showPackageInstaller(ScriptingManager manager) { |
203 |
// not implemented
|
204 |
} |
205 |
|
206 |
private void showPackageBuilder(ScriptingManager manager) { |
207 |
// not implemented
|
208 |
} |
209 |
|
210 |
private void showWindow(JPanel panel, String title) { |
211 |
JFrame frame = new JFrame(title); |
212 |
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
213 |
|
214 |
frame.setContentPane(panel); |
215 |
|
216 |
// Display the window.
|
217 |
frame.pack(); |
218 |
frame.setVisible(true);
|
219 |
} |
220 |
} |