source: josm/trunk/src/org/openstreetmap/josm/gui/help/HelpBrowserProxy.java@ 2308

Last change on this file since 2308 was 2308, checked in by Gubaer, 15 years ago

fixed #3762: Deleted relation still referenced when deleting former member
Clean up of Delete command. New: only one confirmation dialog for all parent relations of deleted objects, see help.
Improved infrastructure for context-sensitive help, improved internal help browser.

File size: 3.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.help;
3
4import java.io.File;
5import static org.openstreetmap.josm.tools.I18n.tr;
6import java.io.IOException;
7import java.io.OutputStreamWriter;
8import java.io.PrintWriter;
9import java.util.ArrayList;
10
11import javax.swing.JOptionPane;
12
13import org.openstreetmap.josm.Main;
14
15/**
16 * This is the proxy class for the help browser running in its own process.
17 *
18 *
19 */
20public class HelpBrowserProxy {
21
22 /** the unique instance of the proxy */
23 private static HelpBrowserProxy instance;
24
25 /**
26 * replies the unique instance of the proxy
27 *
28 * @return the unique instance of the proxy
29 */
30 static public HelpBrowserProxy getInstance() {
31 if (instance == null) {
32 instance = new HelpBrowserProxy();
33 }
34 return instance;
35 }
36
37 /** the process running the help browser */
38 private Process helpBrowserProcess;
39 /** the print writer to the input stream of the help browser process */
40 private PrintWriter pw;
41
42 /**
43 * launches the help browser in its own process
44 *
45 */
46 protected void launch() {
47 ArrayList<String> cmdLine = new ArrayList<String>();
48 String javaBin = null;
49 if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
50 javaBin = "javaw.exe";
51 } else {
52 javaBin = "java";
53 }
54 cmdLine.add(new File(new File(System.getProperty("java.home"), "bin"), javaBin).toString());
55 cmdLine.add("-classpath");
56 cmdLine.add(System.getProperty("java.class.path"));
57 cmdLine.add("org.openstreetmap.josm.gui.help.HelpApplication");
58 if (System.getProperty("josm.home") != null) {
59 cmdLine.add("-Djosm.home="+System.getProperty("josm.home"));
60 }
61 String[] cmds = new String[cmdLine.size()];
62 cmdLine.toArray(cmds);
63 try {
64 helpBrowserProcess = Runtime.getRuntime().exec(cmds);
65 } catch(IOException e) {
66 e.printStackTrace();
67 }
68 if (helpBrowserProcess != null) {
69 pw = new PrintWriter(
70 new OutputStreamWriter(
71 helpBrowserProcess.getOutputStream()
72 )
73 );
74 }
75 }
76
77 /**
78 * Direct the help browser to the help page for help topic
79 * <code>relativeHelpTopic</code>
80 *
81 * @param relativeHelpTopic the help topic
82 */
83 public void setUrlForHelpTopic(String relativeHelpTopic) {
84 if (helpBrowserProcess == null) {
85 launch();
86 }
87 if (helpBrowserProcess == null) {
88 JOptionPane.showMessageDialog(
89 Main.parent,
90 tr("Failed to launch the external help browser"),
91 tr("Error"),
92 JOptionPane.ERROR_MESSAGE
93 );
94 System.err.println("Failed to launch browser");
95 return;
96 }
97 pw.println("setUrlForHelpTopic " + relativeHelpTopic);
98 pw.flush();
99 }
100
101 /**
102 * Exit the help browser
103 */
104 public void exit() {
105 if (helpBrowserProcess == null)
106 return;
107 pw.println("exit");
108 pw.flush();
109 pw.close();
110 helpBrowserProcess.destroy();
111 }
112}
Note: See TracBrowser for help on using the repository browser.