/** * Loads a help topic given by a relative help topic name (i.e. "/Action/New") * * <p>First tries to load the language specific help topic. If it is missing, tries to load the * topic in english. * * @param relativeHelpTopic the relative help topic */ protected void loadRelativeHelpTopic(String relativeHelpTopic) { String url = HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic)); String content = null; try { content = reader.fetchHelpTopicContent(url, true); } catch (MissingHelpContentException e) { url = HelpUtil.getHelpTopicUrl( HelpUtil.buildAbsoluteHelpTopic(relativeHelpTopic, Locale.ENGLISH)); try { logger.info("fetching url: " + url); content = reader.fetchHelpTopicContent(url, true); } catch (MissingHelpContentException e1) { this.url = url; handleMissingHelpContent(relativeHelpTopic); return; } catch (HelpContentReaderException e1) { e1.printStackTrace(); handleHelpContentReaderException(relativeHelpTopic, e1); return; } } catch (HelpContentReaderException e) { e.printStackTrace(); handleHelpContentReaderException(relativeHelpTopic, e); return; } help.setText(content); history.setCurrentUrl(url); this.url = url; scrollToTop(); }
protected void updateSummary() { StringBuffer sb = new StringBuffer(); sb.append("<html>"); sb.append(buildStrategySummary()); sb.append("<br><br>"); sb.append(buildChangesetSummary()); sb.append("</html>"); jepMessage.setText(sb.toString()); }
/** * Displays a error page if a help topic couldn't be loaded because of network or IO error. * * @param relativeHelpTopic the help topic * @param e the exception */ protected void handleHelpContentReaderException( String relativeHelpTopic, HelpContentReaderException e) { String message = tr( "<html><p class=\"error-header\">Error when retrieving help information</p>" + "<p class=\"error-body\">The content for the help topic <strong>{0}</strong> could " + "not be loaded. The error message is (untranslated):<br>" + "<tt>{1}</tt>" + "</p></html>", relativeHelpTopic, e.toString()); help.setText(message); }
protected void build() { jepMessage = new JEditorPane("text/html", ""); jepMessage.setOpaque(false); jepMessage.setEditable(false); jepMessage.addHyperlinkListener(this); Font f = UIManager.getFont("Label.font"); StyleSheet ss = new StyleSheet(); String rule = MessageFormat.format( "font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; font-style: {3}", f.getName(), f.getSize(), f.isBold() ? "bold" : "normal", f.isItalic() ? "italic" : "normal"); rule = "body {" + rule + "}"; rule = MessageFormat.format( "font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; font-style: {3}", f.getName(), f.getSize(), "bold", f.isItalic() ? "italic" : "normal"); rule = "strong {" + rule + "}"; ss.addRule(rule); ss.addRule("a {text-decoration: underline; color: blue}"); HTMLEditorKit kit = new HTMLEditorKit(); kit.setStyleSheet(ss); jepMessage.setEditorKit(kit); setLayout(new BorderLayout()); add(jepMessage, BorderLayout.CENTER); lblWarning = new JLabel(""); lblWarning.setVisible(false); lblWarning.setIcon(ImageProvider.get("warning-small.png")); lblWarning.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel pnl = new JPanel(new BorderLayout()); pnl.add(lblWarning, BorderLayout.NORTH); add(pnl, BorderLayout.WEST); }
/** * Displays a warning page when a help topic doesn't exist yet. * * @param relativeHelpTopic the help topic */ protected void handleMissingHelpContent(String relativeHelpTopic) { String message = tr( "<html><p class=\"warning-header\">Help content for help topic missing</p>" + "<p class=\"warning-body\">Help content for the help topic <strong>{0}</strong> is " + "not available yet. It is missing both in your local language ({1}) and in english.<br><br>" + "Please help to improve the JOSM help system and fill in the missing information. " + "You can both edit the <a href=\"{2}\">help topic in your local language ({1})</a> and " + "the <a href=\"{3}\">help topic in english</a>." + "</p></html>", relativeHelpTopic, Locale.getDefault().getDisplayName(), getHelpTopicEditUrl(buildAbsoluteHelpTopic(relativeHelpTopic)), getHelpTopicEditUrl(buildAbsoluteHelpTopic(relativeHelpTopic, Locale.ENGLISH))); help.setText(message); }
/** * Loads a help topic given by an absolute help topic name, i.e. "/De:Help/Action/New" * * @param absoluteHelpTopic the absolute help topic name */ protected void loadAbsoluteHelpTopic(String absoluteHelpTopic) { String url = HelpUtil.getHelpTopicUrl(absoluteHelpTopic); String content = null; try { content = reader.fetchHelpTopicContent(url, true); } catch (MissingHelpContentException e) { this.url = url; handleMissingHelpContent(absoluteHelpTopic); return; } catch (HelpContentReaderException e) { e.printStackTrace(); handleHelpContentReaderException(absoluteHelpTopic, e); return; } help.setText(content); history.setCurrentUrl(url); this.url = url; scrollToTop(); }
/** * Opens an URL and displays the content. * * <p>If the URL is the locator of an absolute help topic, help content is loaded from the JOSM * wiki. Otherwise, the help browser loads the page from the given URL * * @param url the url */ public void openUrl(String url) { if (!isVisible()) { setVisible(true); toFront(); } else { toFront(); } String helpTopic = HelpUtil.extractAbsoluteHelpTopic(url); if (helpTopic == null) { try { this.url = url; String content = reader.fetchHelpTopicContent(url, false); help.setText(content); history.setCurrentUrl(url); this.url = url; scrollToTop(); } catch (Exception e) { HelpAwareOptionPane.showOptionDialog( Main.parent, tr( "<html>Failed to open help page for url {0}.<br>" + "This is most likely due to a network problem, please check<br>" + "your internet connection</html>", url.toString()), tr("Failed to open URL"), JOptionPane.ERROR_MESSAGE, null, /* no icon */ null, /* standard options, just OK button */ null, /* default is standard */ null /* no help context */); } history.setCurrentUrl(url); } else { loadAbsoluteHelpTopic(helpTopic); } }
protected void build() { help = new JEditorPane(); HTMLEditorKit kit = new HTMLEditorKit(); kit.setStyleSheet(buildStyleSheet()); help.setEditorKit(kit); help.setEditable(false); help.addHyperlinkListener(new HyperlinkHandler()); help.setContentType("text/html"); history = new HelpBrowserHistory(this); JPanel p = new JPanel(new BorderLayout()); setContentPane(p); p.add(spHelp = new JScrollPane(help), BorderLayout.CENTER); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { setVisible(false); } }); p.add(buildToolBar(), BorderLayout.NORTH); help.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Close"); help.getActionMap() .put( "Close", new AbstractAction() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); setMinimumSize(new Dimension(400, 200)); setTitle(tr("JOSM Help Browser")); }