Changeset 2252 in josm for trunk/src/org
- Timestamp:
- 2009-10-06T00:07:00+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/HelpAction.java
r2250 r2252 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.BorderLayout;7 6 import java.awt.Component; 8 7 import java.awt.Point; 9 8 import java.awt.event.ActionEvent; 10 import java.awt.event.KeyEvent;11 import java.awt.event.WindowAdapter;12 import java.awt.event.WindowEvent;13 import java.io.IOException;14 9 15 10 import javax.swing.AbstractAction; 16 11 import javax.swing.AbstractButton; 17 12 import javax.swing.Action; 18 import javax.swing.JButton;19 13 import javax.swing.JComponent; 20 import javax.swing.JEditorPane;21 import javax.swing.JFrame;22 14 import javax.swing.JMenu; 23 import javax.swing.JOptionPane;24 import javax.swing.JPanel;25 import javax.swing.JScrollPane;26 import javax.swing.KeyStroke;27 15 import javax.swing.SwingUtilities; 28 import javax.swing.event.HyperlinkEvent;29 import javax.swing.event.HyperlinkListener;30 16 31 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.gui.help.HelpBrowser; 19 import org.openstreetmap.josm.gui.help.Helpful; 32 20 import org.openstreetmap.josm.tools.ImageProvider; 33 import org.openstreetmap.josm.tools.LanguageInfo;34 import org.openstreetmap.josm.tools.OpenBrowser;35 import org.openstreetmap.josm.tools.WikiReader;36 21 37 22 /** … … 42 27 public class HelpAction extends AbstractAction { 43 28 44 public interface Helpful { 45 String helpTopic(); 46 } 29 private HelpBrowser helpBrowser; 47 30 48 private String languageCode = LanguageInfo.getLanguageCodeWiki();49 private JFrame helpBrowser = new JFrame(tr("JOSM Online Help"));50 private String baseurl = Main.pref.get("help.baseurl", "http://josm.openstreetmap.de");51 private String pathbase = Main.pref.get("help.pathbase", "/wiki/");52 31 private String pathhelp = Main.pref.get("help.pathhelp", "Help/"); 53 32 private String pathmenu = Main.pref.get("help.pathmenu", "Menu/"); 54 private JEditorPane help = new JEditorPane();55 private WikiReader reader = new WikiReader(baseurl);56 private String url;57 33 58 34 public HelpAction() { 59 35 super(tr("Help"), ImageProvider.get("help")); 60 help.setEditable(false); 61 help.addHyperlinkListener(new HyperlinkListener(){ 62 public void hyperlinkUpdate(HyperlinkEvent e) { 63 if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) 64 return; 65 if (e.getURL() == null) { 66 help.setText("<html>404 not found</html>"); 67 } else if (e.getURL().toString().endsWith("action=edit")) { 68 OpenBrowser.displayUrl(e.getURL().toString()); 69 } else { 70 setHelpUrl(e.getURL().toString()); 71 } 72 } 73 }); 74 help.setContentType("text/html"); 75 76 JPanel p = new JPanel(new BorderLayout()); 77 helpBrowser.setContentPane(p); 78 79 p.add(new JScrollPane(help), BorderLayout.CENTER); 80 String[] bounds = Main.pref.get("help.window.bounds", "0,0,800,600").split(","); 81 helpBrowser.setBounds( 82 Integer.parseInt(bounds[0]), 83 Integer.parseInt(bounds[1]), 84 Integer.parseInt(bounds[2]), 85 Integer.parseInt(bounds[3])); 86 87 JPanel buttons = new JPanel(); 88 p.add(buttons, BorderLayout.SOUTH); 89 createButton(buttons, tr("Open in Browser")); 90 createButton(buttons, tr("Edit")); 91 createButton(buttons, tr("Reload")); 92 93 helpBrowser.addWindowListener(new WindowAdapter(){ 94 @Override public void windowClosing(WindowEvent e) { 95 closeHelp(); 96 } 97 }); 98 99 help.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Close"); 100 help.getActionMap().put("Close", new AbstractAction(){ 101 public void actionPerformed(ActionEvent e) { 102 closeHelp(); 103 } 104 }); 36 this.helpBrowser = new HelpBrowser(); 105 37 } 106 38 107 39 public void actionPerformed(ActionEvent e) { 108 if (tr("Open in Browser").equals(e.getActionCommand())) { 109 OpenBrowser.displayUrl(url); 110 } else if (tr("Edit").equals(e.getActionCommand())) { 111 if (!url.startsWith(baseurl)) { 112 JOptionPane.showMessageDialog( 113 Main.parent, 114 tr("Can only edit help pages from JOSM Online Help"), 115 tr("Warning"), 116 JOptionPane.WARNING_MESSAGE 117 ); 118 return; 119 } 120 OpenBrowser.displayUrl(url+"?action=edit"); 121 } else if (tr("Reload").equals(e.getActionCommand())) { 122 setHelpUrl(url); 123 } else if (e.getActionCommand() == null) { 40 if (e.getActionCommand() == null) { 124 41 String topic = null; 125 42 if (e.getSource() instanceof Component) { … … 134 51 if (topic == null) { 135 52 helpBrowser.setVisible(false); 136 setHelpUrl(baseurl+pathbase+"Help");53 helpBrowser.setUrlForHelpTopic("Help"); 137 54 } else { 138 55 help(topic); … … 140 57 } else { 141 58 helpBrowser.setVisible(false); 142 setHelpUrl(baseurl+pathbase+"Help");59 helpBrowser.setUrlForHelpTopic("Help"); 143 60 } 144 61 } … … 179 96 public void help(String topic) { 180 97 helpBrowser.setVisible(false); 181 setHelpUrl(baseurl+pathbase+pathhelp+topic); 182 } 183 184 /** 185 * Set the content of the help window to a specific text (in html format) 186 * @param url The url this content is the representation of 187 */ 188 public void setHelpUrl(String url) { 189 String langurl = url; 190 if(url.startsWith(baseurl+pathbase)) 191 { 192 int i = pathbase.length()+baseurl.length(); 193 String title = url.substring(i); 194 if(languageCode.length() != 0 && !title.startsWith(languageCode)) { 195 title = languageCode + title; 196 } 197 langurl = url.substring(0, i) + title; 198 } 199 boolean loaded = false; 200 if(!langurl.equals(this.url) && !langurl.equals(url)) 201 { 202 loaded = loadHelpUrl(url, langurl, true); 203 } 204 if(!loaded) { 205 loaded = loadHelpUrl(url, langurl, false); 206 } 207 if(!loaded) { 208 help.setText(tr("Error while loading page {0}",url)); 209 } 210 helpBrowser.setVisible(true); 211 } 212 213 private boolean loadHelpUrl(String url, String langurl, boolean lang) 214 { 215 this.url = lang ? langurl : url; 216 boolean loaded = false; 217 try { 218 String txt = reader.read(this.url); 219 if(txt.length() == 0) 220 { 221 if(lang) 222 throw new IOException(); 223 else 224 { 225 if(url.equals(langurl)) 226 { 227 txt = ("<HTML>"+tr("Help page missing. Create it in <A HREF=\"{0}\">English</A>.", 228 url+"?action=edit")+"</HTML>"); 229 } 230 else 231 { 232 txt = ("<HTML>"+tr("Help page missing. Create it in <A HREF=\"{0}\">English</A> or <A HREF=\"{1}\">your language</A>.", 233 url+"?action=edit", langurl+"?action=edit")+"</HTML>"); 234 } 235 } 236 } 237 help.setText(txt); 238 help.setCaretPosition(0); 239 loaded = true; 240 } catch (IOException ex) { 241 } 242 return loaded; 243 } 244 245 /** 246 * Closes the help window 247 */ 248 public void closeHelp() { 249 String bounds = helpBrowser.getX()+","+helpBrowser.getY()+","+helpBrowser.getWidth()+","+helpBrowser.getHeight(); 250 Main.pref.put("help.window.bounds", bounds); 251 helpBrowser.setVisible(false); 252 } 253 254 private void createButton(JPanel buttons, String name) { 255 JButton b = new JButton(tr(name)); 256 b.setActionCommand(name); 257 b.addActionListener(this); 258 buttons.add(b); 98 helpBrowser.setUrlForHelpTopic(pathhelp + topic); 259 99 } 260 100 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2249 r2252 634 634 incomplete = osm.incomplete; 635 635 flags = osm.flags; 636 user= osm.user; 636 637 clearCached(); 637 638 clearErrors(); -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r2204 r2252 88 88 if (node == null) return false; 89 89 for (int i=0; i<nodes.length; i++) { 90 if (nodes[i].equals(node)) {90 if (nodes[i].equals(node)) 91 91 return true; 92 }93 92 } 94 93 return false; … … 177 176 return false; 178 177 Way w = (Way)other; 179 return nodes.equals(w.nodes);178 return Arrays.equals(nodes, w.nodes); 180 179 } 181 180 -
trunk/src/org/openstreetmap/josm/gui/MapScaler.java
r2017 r2252 12 12 13 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm. actions.HelpAction.Helpful;14 import org.openstreetmap.josm.gui.help.Helpful; 15 15 16 16 public class MapScaler extends JComponent implements Helpful { -
trunk/src/org/openstreetmap/josm/gui/MapSlider.java
r2114 r2252 9 9 import javax.swing.event.ChangeListener; 10 10 11 import org.openstreetmap.josm.actions.HelpAction.Helpful;12 11 import org.openstreetmap.josm.data.ProjectionBounds; 12 import org.openstreetmap.josm.gui.help.Helpful; 13 13 14 14 class MapSlider extends JSlider implements PropertyChangeListener, ChangeListener, Helpful { -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r2229 r2252 40 40 41 41 import org.openstreetmap.josm.Main; 42 import org.openstreetmap.josm.actions.HelpAction.Helpful;43 42 import org.openstreetmap.josm.data.coor.CoordinateFormat; 44 43 import org.openstreetmap.josm.data.coor.LatLon; … … 46 45 import org.openstreetmap.josm.data.osm.OsmPrimitive; 47 46 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 47 import org.openstreetmap.josm.gui.help.Helpful; 48 48 import org.openstreetmap.josm.tools.GBC; 49 49 import org.openstreetmap.josm.tools.ImageProvider; -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r2120 r2252 15 15 16 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.actions.HelpAction.Helpful;18 17 import org.openstreetmap.josm.data.Bounds; 19 18 import org.openstreetmap.josm.data.ProjectionBounds; … … 27 26 import org.openstreetmap.josm.data.osm.WaySegment; 28 27 import org.openstreetmap.josm.data.projection.Projection; 28 import org.openstreetmap.josm.gui.help.Helpful; 29 29 30 30 /** -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r2131 r2252 46 46 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 47 47 import org.openstreetmap.josm.gui.SideButton; 48 import org.openstreetmap.josm.gui.help.HelpBuilder; 48 49 import org.openstreetmap.josm.gui.layer.Layer; 49 50 import org.openstreetmap.josm.gui.layer.OsmDataLayer; -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
r2017 r2252 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.HelpBuilder; 30 31 import org.openstreetmap.josm.tools.ImageProvider; 31 32 … … 143 144 144 145 resolver.addPropertyChangeListener(this); 146 HelpBuilder.setHelpContext(this.getRootPane(), "Dialog/ConflictDialog"); 145 147 } 146 148 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r2232 r2252 33 33 import org.openstreetmap.josm.Main; 34 34 import org.openstreetmap.josm.actions.JosmAction; 35 import org.openstreetmap.josm.actions.HelpAction.Helpful;36 35 import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action; 36 import org.openstreetmap.josm.gui.help.Helpful; 37 37 import org.openstreetmap.josm.tools.GBC; 38 38 import org.openstreetmap.josm.tools.ImageProvider; … … 291 291 @Override 292 292 public void mouseClicked(MouseEvent e) { 293 // toggleExpandedState();293 // toggleExpandedState(); 294 294 if (isCollapsed) { 295 295 expand();
Note:
See TracChangeset
for help on using the changeset viewer.