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

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