source: josm/trunk/src/org/openstreetmap/josm/gui/help/HelpBrowserCommandProcessor.java@ 2317

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

applied #3663: patch by singularita: Function to automatically download all missing relations members in all relations
Slightly updated and completed with context sensitive help, see also help

File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.help;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.BufferedReader;
7import java.io.IOException;
8import java.io.InputStreamReader;
9import java.util.logging.Logger;
10
11import javax.swing.SwingUtilities;
12
13/**
14 * Listens to commands on an input stream and delegates them to the help browser.
15 *
16 *
17 */
18public class HelpBrowserCommandProcessor implements Runnable {
19 private static final Logger logger = Logger.getLogger(HelpBrowserCommandProcessor.class.getName());
20
21 /** the controlled help browser*/
22 private HelpBrowser browser;
23
24 /**
25 *
26 * @param browser the controlled help browser
27 */
28 public HelpBrowserCommandProcessor(HelpBrowser browser) {
29 this.browser = browser;
30 }
31
32 /**
33 * Show the help page for help topic <code>helpTopic</code>.
34 *
35 * @param helpTopic the help topic
36 */
37 protected void setUrlForHelpTopic(final String helpTopic) {
38 Runnable r = new Runnable() {
39 public void run() {
40 browser.openHelpTopic(helpTopic);
41 browser.setVisible(true);
42 browser.toFront();
43 }
44 };
45 SwingUtilities.invokeLater(r);
46 }
47
48 /**
49 * Exit the help browser
50 */
51 protected void exit() {
52 Runnable r = new Runnable() {
53 public void run() {
54 browser.setVisible(false);
55 System.exit(0);
56 }
57 };
58 SwingUtilities.invokeLater(r);
59 }
60
61 public void run() {
62 BufferedReader reader = new BufferedReader(
63 new InputStreamReader(
64 System.in
65 )
66 );
67 while(true) {
68 String cmd = null;
69
70 try {
71 cmd = reader.readLine();
72 } catch(IOException e) {
73 System.out.println(tr("Failed to read command. Exiting help browser. Exception was:" + e.toString()));
74 System.exit(1);
75 }
76 if (cmd.startsWith("exit")) {
77 exit();
78 } else if (cmd.startsWith("setUrlForHelpTopic ")) {
79 String helpTopic = cmd.substring("setUrlForHelpTopic ".length());
80 setUrlForHelpTopic(helpTopic);
81 }
82 }
83 }
84}
85
Note: See TracBrowser for help on using the repository browser.