Changeset 2274 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-10-11T21:15:33+02:00 (15 years ago)
Author:
Gubaer
Message:

Improved help browser layout (now uses custom CSS shipped with JOSM)
Help browser now in separate process, not blocked any more when invoked from modal dialogs in JOSM
Added standard browser actions (home, prev, next) etc.
Added help support for conflict resolution

Location:
trunk/src/org/openstreetmap/josm
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r2272 r2274  
    4747import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    4848import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
     49import org.openstreetmap.josm.gui.help.HelpBrowserProxy;
    4950import org.openstreetmap.josm.gui.io.SaveLayersDialog;
    5051import org.openstreetmap.josm.gui.layer.Layer;
     
    374375    }
    375376
     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
    376387    public static boolean saveUnsavedModifications() {
    377388        if (map == null) return true;
     
    393404            }
    394405        }
     406
    395407        return true;
    396408    }
  • trunk/src/org/openstreetmap/josm/actions/ExitAction.java

    r2025 r2274  
    2727        if (Main.saveUnsavedModifications()) {
    2828            Main.saveGuiGeometry();
     29            Main.cleanupBeforeExit();
    2930            System.exit(0);
    3031        }
  • trunk/src/org/openstreetmap/josm/actions/HelpAction.java

    r2252 r2274  
    1616
    1717import org.openstreetmap.josm.Main;
    18 import org.openstreetmap.josm.gui.help.HelpBrowser;
     18import org.openstreetmap.josm.gui.help.HelpBrowserProxy;
    1919import org.openstreetmap.josm.gui.help.Helpful;
    2020import org.openstreetmap.josm.tools.ImageProvider;
     
    2727public class HelpAction extends AbstractAction {
    2828
    29     private HelpBrowser helpBrowser;
    3029
    3130    private String pathhelp = Main.pref.get("help.pathhelp", "Help/");
     
    3433    public HelpAction() {
    3534        super(tr("Help"), ImageProvider.get("help"));
    36         this.helpBrowser = new HelpBrowser();
    3735    }
    3836
     
    4341                Component c = SwingUtilities.getRoot((Component)e.getSource());
    4442                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                }
    4749            } else {
    4850                Point mouse = Main.parent.getMousePosition();
     
    5052            }
    5153            if (topic == null) {
    52                 helpBrowser.setVisible(false);
    53                 helpBrowser.setUrlForHelpTopic("Help");
     54                HelpBrowserProxy.getInstance().setUrlForHelpTopic("Help");
    5455            } else {
    5556                help(topic);
    5657            }
    5758        } else {
    58             helpBrowser.setVisible(false);
    59             helpBrowser.setUrlForHelpTopic("Help");
     59            HelpBrowserProxy.getInstance().setUrlForHelpTopic("Help");
    6060        }
    6161    }
     
    9595     */
    9696    public void help(String topic) {
    97         helpBrowser.setVisible(false);
    98         helpBrowser.setUrlForHelpTopic(pathhelp + topic);
     97        HelpBrowserProxy.getInstance().setUrlForHelpTopic(pathhelp + topic);
    9998    }
    10099}
  • trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java

    r2034 r2274  
    1313
    1414    public HistoryInfoAction() {
    15         super(tr("History of Element"), "about",
     15        super(tr("Object history"), "about",
    1616                tr("Display history information about OSM ways, nodes, or relations."),
    1717                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);
    1919    }
    2020
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r2085 r2274  
    5050                    return;
    5151                Main.saveGuiGeometry();
     52                Main.cleanupBeforeExit();
    5253                System.exit(0);
    5354            }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java

    r2252 r2274  
    2828import org.openstreetmap.josm.gui.conflict.pair.ConflictResolver;
    2929import org.openstreetmap.josm.gui.conflict.pair.properties.OperationCancelledException;
     30import org.openstreetmap.josm.gui.help.HelpBrowser;
     31import org.openstreetmap.josm.gui.help.HelpBrowserProxy;
    3032import org.openstreetmap.josm.gui.help.HelpBuilder;
    3133import org.openstreetmap.josm.tools.ImageProvider;
     
    127129        pnl.add(btn);
    128130
     131        btn = new JButton(new HelpAction());
     132        btn.setName("button.help");
     133        pnl.add(btn);
     134
    129135        pnl.setBorder(BorderFactory.createLoweredBevelBorder());
    130136        return pnl;
     
    171177        public void actionPerformed(ActionEvent arg0) {
    172178            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");
    173195        }
    174196    }
  • trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java

    r2252 r2274  
    1010import java.awt.event.WindowAdapter;
    1111import java.awt.event.WindowEvent;
     12import java.io.BufferedReader;
    1213import java.io.IOException;
     14import java.io.InputStreamReader;
     15import java.util.Observable;
     16import java.util.Observer;
    1317
    1418import javax.swing.AbstractAction;
     19import javax.swing.JButton;
    1520import javax.swing.JComponent;
    1621import javax.swing.JEditorPane;
     
    1924import javax.swing.JPanel;
    2025import javax.swing.JScrollPane;
     26import javax.swing.JSeparator;
     27import javax.swing.JToolBar;
    2128import javax.swing.KeyStroke;
    2229import javax.swing.event.HyperlinkEvent;
    2330import javax.swing.event.HyperlinkListener;
     31import javax.swing.text.html.HTMLEditorKit;
     32import javax.swing.text.html.StyleSheet;
    2433
    2534import org.openstreetmap.josm.Main;
    26 import org.openstreetmap.josm.gui.SideButton;
    2735import org.openstreetmap.josm.tools.ImageProvider;
    2836import org.openstreetmap.josm.tools.LanguageInfo;
     
    3341public class HelpBrowser extends JFrame {
    3442
     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 */
    3571    private JEditorPane help;
     72    /** the help browser history */
     73    private HelpBrowserHistory history;
    3674
    3775    /** the currently displayed URL */
     
    4381    private WikiReader reader = new WikiReader(baseurl);
    4482
     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    }
    45123
    46124    protected void build() {
    47125        help = new JEditorPane();
     126        HTMLEditorKit kit = new HTMLEditorKit();
     127        kit.setStyleSheet(buildStyleSheet());
     128        help.setEditorKit(kit);
    48129        help.setEditable(false);
    49130        help.addHyperlinkListener(new HyperlinkListener(){
     
    56137                    OpenBrowser.displayUrl(e.getURL().toString());
    57138                } else {
     139                    url = e.getURL().toString();
    58140                    setUrl(e.getURL().toString());
    59141                }
     
    62144        help.setContentType("text/html");
    63145
     146
     147        history = new HelpBrowserHistory(this);
     148
    64149        JPanel p = new JPanel(new BorderLayout());
    65150        setContentPane(p);
    66151
    67152        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()));
    75153
    76154        addWindowListener(new WindowAdapter(){
     
    80158        });
    81159
     160        p.add(buildToolBar(), BorderLayout.NORTH);
    82161        help.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Close");
    83162        help.getActionMap().put("Close", new AbstractAction(){
     
    94173    }
    95174
    96     @Override
    97     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 
    112175    public String getUrl() {
    113176        return url;
    114177    }
    115178
    116     public void setUrl(String url) {
     179    protected void loadUrl(String url) {
    117180        String langurl = url;
    118181        if(url.startsWith(baseurl+pathbase)){
     
    134197            help.setText(tr("Error while loading page {0}",url));
    135198        }
     199    }
     200
     201    public void setUrl(String url) {
     202        loadUrl(url);
    136203        if (!isVisible()) {
    137204            setVisible(true);
     
    140207            toFront();
    141208        }
     209        history.setCurrentUrl(url);
    142210    }
    143211
     
    172240    class OpenInBrowserAction extends AbstractAction {
    173241        public OpenInBrowserAction() {
    174             putValue(NAME, tr("Open in Browser"));
     242            //putValue(NAME, tr("Open in Browser"));
    175243            putValue(SHORT_DESCRIPTION, tr("Open the current help page in an external browser"));
    176             // provide icon
     244            putValue(SMALL_ICON, ImageProvider.get("help", "internet"));
    177245        }
    178246
     
    184252    class EditAction extends AbstractAction {
    185253        public EditAction() {
    186             putValue(NAME, tr("Edit"));
     254            // putValue(NAME, tr("Edit"));
    187255            putValue(SHORT_DESCRIPTION, tr("Edit the current help page"));
    188256            putValue(SMALL_ICON,ImageProvider.get("dialogs", "edit"));
     
    205273    class ReloadAction extends AbstractAction {
    206274        public ReloadAction() {
    207             putValue(NAME, tr("Reload"));
     275            //putValue(NAME, tr("Reload"));
    208276            putValue(SHORT_DESCRIPTION, tr("Reload the current help page"));
    209277            putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh"));
     
    214282        }
    215283    }
     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    }
    216335}
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r2253 r2274  
    2121import java.awt.geom.Area;
    2222import java.awt.image.BufferedImage;
    23 import java.beans.PropertyChangeEvent;
    24 import java.beans.PropertyChangeListener;
    2523import java.io.File;
    2624import java.util.ArrayList;
  • trunk/src/org/openstreetmap/josm/tools/WikiReader.java

    r2257 r2274  
    127127            }
    128128            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=\"/",
    130133                        "href=\"" + baseurl + "/").replaceAll(" />", ">")
    131134                        + "\n";
Note: See TracChangeset for help on using the changeset viewer.