| 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 | import java.lang.management.ManagementFactory;
|
|---|
| 9 | import java.util.LinkedList;
|
|---|
| 10 |
|
|---|
| 11 | import org.openstreetmap.josm.Main;
|
|---|
| 12 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| 13 | import org.openstreetmap.josm.tools.PlatformHookWindows;
|
|---|
| 14 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 15 |
|
|---|
| 16 | public class RestartJosmAction extends JosmAction {
|
|---|
| 17 |
|
|---|
| 18 | public RestartJosmAction() {
|
|---|
| 19 | super(tr("Restart JOSM"), null, tr("Restart JOSM"),
|
|---|
| 20 | Shortcut.registerShortcut("file:restart",
|
|---|
| 21 | tr("File: {0}", tr("Restart JOSM")),
|
|---|
| 22 | KeyEvent.VK_J, Shortcut.ALT_CTRL_SHIFT),
|
|---|
| 23 | false);
|
|---|
| 24 | putValue("toolbar", "action/restart");
|
|---|
| 25 | Main.toolbar.register(this);
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | public void actionPerformed(ActionEvent arg0) {
|
|---|
| 29 | if (!Main.exitJosm(false)) return;
|
|---|
| 30 | try {
|
|---|
| 31 | File jarfile = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
|---|
| 32 | String javacmd = "java";
|
|---|
| 33 | if (Main.platform instanceof PlatformHookWindows) javacmd = "javaw";
|
|---|
| 34 | LinkedList<String> cmds = new LinkedList<String>();
|
|---|
| 35 | cmds.add(javacmd);
|
|---|
| 36 | cmds.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments());
|
|---|
| 37 | cmds.add("-jar");
|
|---|
| 38 | cmds.add(jarfile.getAbsolutePath());
|
|---|
| 39 | for (String s : cmds)
|
|---|
| 40 | System.out.print(s + " ");
|
|---|
| 41 | System.out.println();
|
|---|
| 42 |
|
|---|
| 43 | Runtime.getRuntime().exec(cmds.toArray(new String[0]));
|
|---|
| 44 | } catch (Exception e) {
|
|---|
| 45 | e.printStackTrace();
|
|---|
| 46 | }
|
|---|
| 47 | System.exit(0);
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|