1 | package josmrestartplugin;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.event.ActionEvent;
|
---|
6 | import java.awt.event.KeyEvent;
|
---|
7 | import java.io.File;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.Main;
|
---|
10 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
11 | import org.openstreetmap.josm.tools.PlatformHookWindows;
|
---|
12 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
13 |
|
---|
14 | public class RestartJosmAction extends JosmAction {
|
---|
15 |
|
---|
16 | public RestartJosmAction() {
|
---|
17 | super(tr("Restart JOSM"), null, tr("Restart JOSM"),
|
---|
18 | Shortcut.registerShortcut("file:restart",
|
---|
19 | tr("File: {0}", tr("Restart JOSM")),
|
---|
20 | KeyEvent.VK_J, Shortcut.ALT_CTRL_SHIFT),
|
---|
21 | false);
|
---|
22 | putValue("toolbar", "action/restart");
|
---|
23 | Main.toolbar.register(this);
|
---|
24 | }
|
---|
25 |
|
---|
26 | public void actionPerformed(ActionEvent arg0) {
|
---|
27 | if (!Main.exitJosm(false)) return;
|
---|
28 | try {
|
---|
29 | File jarfile = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
---|
30 | long memmax = Runtime.getRuntime().maxMemory();
|
---|
31 | String javacmd = "java";
|
---|
32 | if (Main.platform instanceof PlatformHookWindows) javacmd = "javaw";
|
---|
33 | String[] cmds = new String[] {
|
---|
34 | javacmd,
|
---|
35 | "-Xmx" + memmax,
|
---|
36 | "-jar",
|
---|
37 | jarfile.getAbsolutePath()
|
---|
38 | };
|
---|
39 | for (String s : cmds)
|
---|
40 | System.out.print(s + " ");
|
---|
41 | System.out.println();
|
---|
42 |
|
---|
43 | Runtime.getRuntime().exec(cmds);
|
---|
44 | } catch (Exception e) {
|
---|
45 | e.printStackTrace();
|
---|
46 | }
|
---|
47 | System.exit(0);
|
---|
48 | }
|
---|
49 | }
|
---|