Changeset 2274 in josm for trunk/src/org
- Timestamp:
- 2009-10-11T21:15:33+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r2272 r2274 47 47 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 48 48 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 49 import org.openstreetmap.josm.gui.help.HelpBrowserProxy; 49 50 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 50 51 import org.openstreetmap.josm.gui.layer.Layer; … … 374 375 } 375 376 377 /** 378 * Run any cleanup operation before exit 379 * 380 */ 381 public static void cleanupBeforeExit() { 382 // try to close and exit the help browser running in another process 383 // 384 HelpBrowserProxy.getInstance().exit(); 385 } 386 376 387 public static boolean saveUnsavedModifications() { 377 388 if (map == null) return true; … … 393 404 } 394 405 } 406 395 407 return true; 396 408 } -
trunk/src/org/openstreetmap/josm/actions/ExitAction.java
r2025 r2274 27 27 if (Main.saveUnsavedModifications()) { 28 28 Main.saveGuiGeometry(); 29 Main.cleanupBeforeExit(); 29 30 System.exit(0); 30 31 } -
trunk/src/org/openstreetmap/josm/actions/HelpAction.java
r2252 r2274 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.gui.help.HelpBrowser; 18 import org.openstreetmap.josm.gui.help.HelpBrowserProxy; 19 19 import org.openstreetmap.josm.gui.help.Helpful; 20 20 import org.openstreetmap.josm.tools.ImageProvider; … … 27 27 public class HelpAction extends AbstractAction { 28 28 29 private HelpBrowser helpBrowser;30 29 31 30 private String pathhelp = Main.pref.get("help.pathhelp", "Help/"); … … 34 33 public HelpAction() { 35 34 super(tr("Help"), ImageProvider.get("help")); 36 this.helpBrowser = new HelpBrowser();37 35 } 38 36 … … 43 41 Component c = SwingUtilities.getRoot((Component)e.getSource()); 44 42 Point mouse = c.getMousePosition(); 45 c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y); 46 topic = contextSensitiveHelp(c); 43 if (mouse != null) { 44 c = SwingUtilities.getDeepestComponentAt(c, mouse.x, mouse.y); 45 topic = contextSensitiveHelp(c); 46 } else { 47 topic = null; 48 } 47 49 } else { 48 50 Point mouse = Main.parent.getMousePosition(); … … 50 52 } 51 53 if (topic == null) { 52 helpBrowser.setVisible(false); 53 helpBrowser.setUrlForHelpTopic("Help"); 54 HelpBrowserProxy.getInstance().setUrlForHelpTopic("Help"); 54 55 } else { 55 56 help(topic); 56 57 } 57 58 } else { 58 helpBrowser.setVisible(false); 59 helpBrowser.setUrlForHelpTopic("Help"); 59 HelpBrowserProxy.getInstance().setUrlForHelpTopic("Help"); 60 60 } 61 61 } … … 95 95 */ 96 96 public void help(String topic) { 97 helpBrowser.setVisible(false); 98 helpBrowser.setUrlForHelpTopic(pathhelp + topic); 97 HelpBrowserProxy.getInstance().setUrlForHelpTopic(pathhelp + topic); 99 98 } 100 99 } -
trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java
r2034 r2274 13 13 14 14 public HistoryInfoAction() { 15 super(tr(" History of Element"), "about",15 super(tr("Object history"), "about", 16 16 tr("Display history information about OSM ways, nodes, or relations."), 17 17 Shortcut.registerShortcut("core:history", 18 tr(" History of Element"), KeyEvent.VK_H, Shortcut.GROUP_HOTKEY), true);18 tr("Object history"), KeyEvent.VK_H, Shortcut.GROUP_HOTKEY), true); 19 19 } 20 20 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r2085 r2274 50 50 return; 51 51 Main.saveGuiGeometry(); 52 Main.cleanupBeforeExit(); 52 53 System.exit(0); 53 54 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
r2252 r2274 28 28 import org.openstreetmap.josm.gui.conflict.pair.ConflictResolver; 29 29 import org.openstreetmap.josm.gui.conflict.pair.properties.OperationCancelledException; 30 import org.openstreetmap.josm.gui.help.HelpBrowser; 31 import org.openstreetmap.josm.gui.help.HelpBrowserProxy; 30 32 import org.openstreetmap.josm.gui.help.HelpBuilder; 31 33 import org.openstreetmap.josm.tools.ImageProvider; … … 127 129 pnl.add(btn); 128 130 131 btn = new JButton(new HelpAction()); 132 btn.setName("button.help"); 133 pnl.add(btn); 134 129 135 pnl.setBorder(BorderFactory.createLoweredBevelBorder()); 130 136 return pnl; … … 171 177 public void actionPerformed(ActionEvent arg0) { 172 178 setVisible(false); 179 } 180 } 181 182 /** 183 * Action for canceling conflict resolution 184 */ 185 class HelpAction extends AbstractAction { 186 public HelpAction() { 187 putValue(Action.SHORT_DESCRIPTION, tr("Show help information")); 188 putValue(Action.NAME, tr("Help")); 189 putValue(Action.SMALL_ICON, ImageProvider.get("help")); 190 setEnabled(true); 191 } 192 193 public void actionPerformed(ActionEvent arg0) { 194 HelpBrowserProxy.getInstance().setUrlForHelpTopic("/Help/Dialog/ConflictDialog"); 173 195 } 174 196 } -
trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java
r2252 r2274 10 10 import java.awt.event.WindowAdapter; 11 11 import java.awt.event.WindowEvent; 12 import java.io.BufferedReader; 12 13 import java.io.IOException; 14 import java.io.InputStreamReader; 15 import java.util.Observable; 16 import java.util.Observer; 13 17 14 18 import javax.swing.AbstractAction; 19 import javax.swing.JButton; 15 20 import javax.swing.JComponent; 16 21 import javax.swing.JEditorPane; … … 19 24 import javax.swing.JPanel; 20 25 import javax.swing.JScrollPane; 26 import javax.swing.JSeparator; 27 import javax.swing.JToolBar; 21 28 import javax.swing.KeyStroke; 22 29 import javax.swing.event.HyperlinkEvent; 23 30 import javax.swing.event.HyperlinkListener; 31 import javax.swing.text.html.HTMLEditorKit; 32 import javax.swing.text.html.StyleSheet; 24 33 25 34 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.gui.SideButton;27 35 import org.openstreetmap.josm.tools.ImageProvider; 28 36 import org.openstreetmap.josm.tools.LanguageInfo; … … 33 41 public class HelpBrowser extends JFrame { 34 42 43 private static HelpBrowser instance; 44 45 /** 46 * Replies the unique instance of the help browser 47 * 48 * @return the unique instance of the help browser 49 */ 50 static public HelpBrowser getInstance() { 51 if (instance == null) { 52 instance = new HelpBrowser(); 53 } 54 return instance; 55 } 56 57 /** 58 * Launches the internal help browser and directs it to the help page for 59 * <code>helpTopic</code>. 60 * 61 * @param helpTopic the help topic 62 */ 63 static public void launchBrowser(String helpTopic) { 64 HelpBrowser browser = getInstance(); 65 browser.setUrlForHelpTopic(helpTopic); 66 browser.setVisible(true); 67 browser.toFront(); 68 } 69 70 /** the help browser */ 35 71 private JEditorPane help; 72 /** the help browser history */ 73 private HelpBrowserHistory history; 36 74 37 75 /** the currently displayed URL */ … … 43 81 private WikiReader reader = new WikiReader(baseurl); 44 82 83 /** 84 * Builds the style sheet used in the internal help browser 85 * 86 * @return the style sheet 87 */ 88 protected StyleSheet buildStyleSheet() { 89 StyleSheet ss = new StyleSheet(); 90 BufferedReader reader = new BufferedReader( 91 new InputStreamReader( 92 getClass().getResourceAsStream("help-browser.css") 93 ) 94 ); 95 StringBuffer css = new StringBuffer(); 96 try { 97 String line = null; 98 while ((line = reader.readLine()) != null) { 99 css.append(line); 100 css.append("\n"); 101 } 102 reader.close(); 103 } catch(Exception e) { 104 System.err.println(tr("Failed to read CSS file ''help-browser.css''. Exception is: {0}", e.toString())); 105 e.printStackTrace(); 106 return ss; 107 } 108 ss.addRule(css.toString()); 109 return ss; 110 } 111 112 protected JToolBar buildToolBar() { 113 JToolBar tb = new JToolBar(); 114 tb.add(new JButton(new HomeAction())); 115 tb.add(new JButton(new BackAction(history))); 116 tb.add(new JButton(new ForwardAction(history))); 117 tb.add(new JButton(new ReloadAction())); 118 tb.add(new JSeparator()); 119 tb.add(new JButton(new OpenInBrowserAction())); 120 tb.add(new JButton(new EditAction())); 121 return tb; 122 } 45 123 46 124 protected void build() { 47 125 help = new JEditorPane(); 126 HTMLEditorKit kit = new HTMLEditorKit(); 127 kit.setStyleSheet(buildStyleSheet()); 128 help.setEditorKit(kit); 48 129 help.setEditable(false); 49 130 help.addHyperlinkListener(new HyperlinkListener(){ … … 56 137 OpenBrowser.displayUrl(e.getURL().toString()); 57 138 } else { 139 url = e.getURL().toString(); 58 140 setUrl(e.getURL().toString()); 59 141 } … … 62 144 help.setContentType("text/html"); 63 145 146 147 history = new HelpBrowserHistory(this); 148 64 149 JPanel p = new JPanel(new BorderLayout()); 65 150 setContentPane(p); 66 151 67 152 p.add(new JScrollPane(help), BorderLayout.CENTER); 68 69 JPanel buttons = new JPanel();70 p.add(buttons, BorderLayout.SOUTH);71 72 buttons.add(new SideButton(new OpenInBrowserAction()));73 buttons.add(new SideButton(new EditAction()));74 buttons.add(new SideButton(new ReloadAction()));75 153 76 154 addWindowListener(new WindowAdapter(){ … … 80 158 }); 81 159 160 p.add(buildToolBar(), BorderLayout.NORTH); 82 161 help.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Close"); 83 162 help.getActionMap().put("Close", new AbstractAction(){ … … 94 173 } 95 174 96 @Override97 public void setVisible(boolean visible) {98 if (visible) {99 new WindowGeometry(100 getClass().getName() + ".geometry",101 WindowGeometry.centerInWindow(102 Main.parent,103 new Dimension(800,600)104 )105 ).applySafe(this);106 } else if (!visible && isShowing()){107 new WindowGeometry(this).remember(getClass().getName() + ".geometry");108 }109 super.setVisible(visible);110 }111 112 175 public String getUrl() { 113 176 return url; 114 177 } 115 178 116 p ublic void setUrl(String url) {179 protected void loadUrl(String url) { 117 180 String langurl = url; 118 181 if(url.startsWith(baseurl+pathbase)){ … … 134 197 help.setText(tr("Error while loading page {0}",url)); 135 198 } 199 } 200 201 public void setUrl(String url) { 202 loadUrl(url); 136 203 if (!isVisible()) { 137 204 setVisible(true); … … 140 207 toFront(); 141 208 } 209 history.setCurrentUrl(url); 142 210 } 143 211 … … 172 240 class OpenInBrowserAction extends AbstractAction { 173 241 public OpenInBrowserAction() { 174 putValue(NAME, tr("Open in Browser")); 242 //putValue(NAME, tr("Open in Browser")); 175 243 putValue(SHORT_DESCRIPTION, tr("Open the current help page in an external browser")); 176 // provide icon244 putValue(SMALL_ICON, ImageProvider.get("help", "internet")); 177 245 } 178 246 … … 184 252 class EditAction extends AbstractAction { 185 253 public EditAction() { 186 putValue(NAME, tr("Edit")); 254 // putValue(NAME, tr("Edit")); 187 255 putValue(SHORT_DESCRIPTION, tr("Edit the current help page")); 188 256 putValue(SMALL_ICON,ImageProvider.get("dialogs", "edit")); … … 205 273 class ReloadAction extends AbstractAction { 206 274 public ReloadAction() { 207 putValue(NAME, tr("Reload")); 275 //putValue(NAME, tr("Reload")); 208 276 putValue(SHORT_DESCRIPTION, tr("Reload the current help page")); 209 277 putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh")); … … 214 282 } 215 283 } 284 285 class BackAction extends AbstractAction implements Observer { 286 private HelpBrowserHistory history; 287 public BackAction(HelpBrowserHistory history) { 288 this.history = history; 289 history.addObserver(this); 290 //putValue(NAME, tr("Back")); 291 putValue(SHORT_DESCRIPTION, tr("Go to the previous page")); 292 putValue(SMALL_ICON, ImageProvider.get("help", "previous")); 293 setEnabled(history.canGoBack()); 294 } 295 296 public void actionPerformed(ActionEvent e) { 297 history.back(); 298 } 299 public void update(Observable o, Object arg) { 300 System.out.println("BackAction: canGoBoack=" + history.canGoBack() ); 301 setEnabled(history.canGoBack()); 302 } 303 } 304 305 class ForwardAction extends AbstractAction implements Observer { 306 private HelpBrowserHistory history; 307 public ForwardAction(HelpBrowserHistory history) { 308 this.history = history; 309 history.addObserver(this); 310 //putValue(NAME, tr("Forward")); 311 putValue(SHORT_DESCRIPTION, tr("Go to the next page")); 312 putValue(SMALL_ICON, ImageProvider.get("help", "next")); 313 setEnabled(history.canGoForward()); 314 } 315 316 public void actionPerformed(ActionEvent e) { 317 history.forward(); 318 } 319 public void update(Observable o, Object arg) { 320 setEnabled(history.canGoForward()); 321 } 322 } 323 324 class HomeAction extends AbstractAction { 325 public HomeAction() { 326 //putValue(NAME, tr("Home")); 327 putValue(SHORT_DESCRIPTION, tr("Go to the JOSM help home page")); 328 putValue(SMALL_ICON, ImageProvider.get("help", "home")); 329 } 330 331 public void actionPerformed(ActionEvent e) { 332 setUrlForHelpTopic("Help"); 333 } 334 } 216 335 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r2253 r2274 21 21 import java.awt.geom.Area; 22 22 import java.awt.image.BufferedImage; 23 import java.beans.PropertyChangeEvent;24 import java.beans.PropertyChangeListener;25 23 import java.io.File; 26 24 import java.util.ArrayList; -
trunk/src/org/openstreetmap/josm/tools/WikiReader.java
r2257 r2274 127 127 } 128 128 if (inside && !transl) { 129 b += line.replaceAll("<img src=\"/", "<img src=\"" + baseurl + "/").replaceAll("href=\"/", 129 // add a border="0" attribute to images, otherwise the internal help browser 130 // will render a thick border around images inside an <a> element 131 // 132 b += line.replaceAll("<img src=\"/", "<img border=\"0\" src=\"" + baseurl + "/").replaceAll("href=\"/", 130 133 "href=\"" + baseurl + "/").replaceAll(" />", ">") 131 134 + "\n";
Note:
See TracChangeset
for help on using the changeset viewer.