Ticket #19257: 19257.2.patch

File 19257.2.patch, 6.8 KB (added by GerdP, 6 years ago)

AbstractShowHistoryAction with common texts "History" and "Download and show the history of the selected objects." to reduce number of I18N strings. To be used with popup menus and side buttons where selected objects are known.

  • src/org/openstreetmap/josm/actions/AbstractShowHistoryAction.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.actions;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import javax.swing.AbstractAction;
     7
     8import org.openstreetmap.josm.tools.ImageProvider;
     9
     10/**
     11 * Superclass of "History" actions in various parts of JOSM.
     12 * @since xxx
     13 */
     14public abstract class AbstractShowHistoryAction extends AbstractAction {
     15    /**
     16     * Constructs a new {@code AbstractShowHistoryAction}.
     17     */
     18    public AbstractShowHistoryAction() {
     19        putValue(NAME, tr("History"));
     20        putValue(SHORT_DESCRIPTION, tr("Download and show the history of the selected objects."));
     21        new ImageProvider("dialogs", "history").getResource().attachImageIcon(this, true);
     22    }
     23}
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

     
    3737import javax.swing.event.ListSelectionListener;
    3838import javax.swing.event.PopupMenuEvent;
    3939
     40import org.openstreetmap.josm.actions.AbstractShowHistoryAction;
    4041import org.openstreetmap.josm.actions.AbstractSelectAction;
    4142import org.openstreetmap.josm.actions.AutoScaleAction;
    4243import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode;
     
    347348    /**
    348349     * The action for showing history information of the current history item.
    349350     */
    350     class ShowHistoryAction extends AbstractAction implements ListSelectionListener, DataSelectionListener {
     351    class ShowHistoryAction extends AbstractShowHistoryAction implements ListSelectionListener, DataSelectionListener {
    351352        /**
    352353         * Constructs a new {@code ShowHistoryAction}.
    353354         */
    354355        ShowHistoryAction() {
    355             putValue(NAME, tr("History"));
    356             putValue(SHORT_DESCRIPTION, tr("Display the history of the selected objects."));
    357             new ImageProvider("dialogs", "history").getResource().attachImageIcon(this, true);
     356            super();
    358357            updateEnabledState(model.getSize());
    359358        }
    360359
     
    370369        }
    371370
    372371        protected void updateEnabledState(int osmSelectionSize) {
    373             // See #10830 - allow to click on history button is a single object is selected, even if not selected again in the list
     372            // See #10830 - allow to click on history button if a single object is selected, even if not selected again in the list
    374373            setEnabled(!model.isSelectionEmpty() || osmSelectionSize == 1);
    375374        }
    376375
  • src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java

     
    3434import javax.swing.event.ListSelectionEvent;
    3535import javax.swing.event.ListSelectionListener;
    3636
     37import org.openstreetmap.josm.actions.AbstractShowHistoryAction;
    3738import org.openstreetmap.josm.actions.AutoScaleAction;
    3839import org.openstreetmap.josm.actions.HistoryInfoAction;
    3940import org.openstreetmap.josm.actions.downloadtasks.ChangesetContentDownloadTask;
     
    222223        }
    223224    }
    224225
    225     class ShowHistoryAction extends AbstractAction implements ListSelectionListener {
     226    class ShowHistoryAction extends AbstractShowHistoryAction implements ListSelectionListener {
    226227
    227228        ShowHistoryAction() {
    228             putValue(NAME, tr("Show history"));
    229             new ImageProvider("dialogs", "history").getResource().attachImageIcon(this);
    230             putValue(SHORT_DESCRIPTION, tr("Download and show the history of the selected objects"));
     229            super();
    231230            updateEnabledState();
    232231        }
    233232
  • src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

     
    2121import javax.swing.event.ListSelectionEvent;
    2222import javax.swing.event.ListSelectionListener;
    2323
     24import org.openstreetmap.josm.actions.AbstractShowHistoryAction;
    2425import org.openstreetmap.josm.actions.AutoScaleAction;
    2526import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode;
    2627import org.openstreetmap.josm.actions.HistoryInfoAction;
     
    105106        menu.addSeparator();
    106107        menu.add(new SelectPreviousGapAction());
    107108        menu.add(new SelectNextGapAction());
    108         menu.add(new HistoryInfoAction() {
     109        menu.add(new AbstractShowHistoryAction() {
    109110            @Override
    110111            public void actionPerformed(ActionEvent ae) {
    111112                Collection<OsmPrimitive> sel = getMemberTableModel().getSelectedChildPrimitives();
  • src/org/openstreetmap/josm/gui/history/ShowHistoryAction.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.history;
    33
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    5 
    64import java.awt.event.ActionEvent;
    75import java.awt.event.MouseAdapter;
    86import java.awt.event.MouseEvent;
     
    97import java.util.Collections;
    108import java.util.function.Function;
    119
    12 import javax.swing.AbstractAction;
    13 
     10import org.openstreetmap.josm.actions.AbstractShowHistoryAction;
    1411import org.openstreetmap.josm.data.osm.PrimitiveId;
    15 import org.openstreetmap.josm.tools.ImageProvider;
    1612
    1713/**
    1814 * Open a history browser with the history of an object.
    1915 */
    20 class ShowHistoryAction extends AbstractAction {
     16class ShowHistoryAction extends AbstractShowHistoryAction {
    2117    private transient PrimitiveId primitiveId;
    2218
    23     /**
    24      * Constructs a new {@code ShowHistoryAction}.
    25      */
    26     ShowHistoryAction() {
    27         putValue(NAME, tr("Show history"));
    28         putValue(SHORT_DESCRIPTION, tr("Display the history of the selected object."));
    29         new ImageProvider("dialogs", "history").getResource().attachImageIcon(this, true);
    30     }
    31 
    3219    @Override
    3320    public void actionPerformed(ActionEvent e) {
    3421        if (isEnabled()) {