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_R, Shortcut.GROUP_MENU),
|
---|
21 | true);
|
---|
22 | }
|
---|
23 |
|
---|
24 | public void actionPerformed(ActionEvent arg0) {
|
---|
25 | if (!Main.exitJosm(false)) return;
|
---|
26 | try {
|
---|
27 | File jarfile = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
---|
28 | long memmax = Runtime.getRuntime().maxMemory();
|
---|
29 | String javacmd = "java";
|
---|
30 | if (Main.platform instanceof PlatformHookWindows) javacmd = "javaw";
|
---|
31 | String[] cmds = new String[] {
|
---|
32 | javacmd,
|
---|
33 | "-Xmx" + memmax,
|
---|
34 | "-jar",
|
---|
35 | jarfile.getAbsolutePath()
|
---|
36 | };
|
---|
37 | for (String s : cmds)
|
---|
38 | System.out.print(s + " ");
|
---|
39 | System.out.println();
|
---|
40 |
|
---|
41 | Runtime.getRuntime().exec(cmds);
|
---|
42 | } catch (Exception e) {
|
---|
43 | e.printStackTrace();
|
---|
44 | }
|
---|
45 | System.exit(0);
|
---|
46 | }
|
---|
47 | }
|
---|