Ignore:
Timestamp:
2020-04-19T12:44:40+02:00 (4 years ago)
Author:
simon04
Message:

see #18164 - OverpassQueryWizard: add icon

Icon taken from https://publicdomainvectors.org/en/free-clipart/Wand-with-Stars-Vector-Graphics/8217.html (PD and CC0 licensed)

Location:
trunk/src/org/openstreetmap/josm/gui/download
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java

    r15447 r16355  
    3939import org.openstreetmap.josm.gui.download.DownloadSourceSizingPolicy.AdjustableDownloadSizePolicy;
    4040import org.openstreetmap.josm.gui.download.overpass.OverpassWizardRegistration;
    41 import org.openstreetmap.josm.gui.download.overpass.OverpassWizardRegistration.OverpassQueryWizard;
    4241import org.openstreetmap.josm.gui.download.overpass.OverpassWizardRegistration.OverpassWizardCallbacks;
    4342import org.openstreetmap.josm.gui.util.GuiHelper;
     
    168167            leftPanel.add(new JLabel(tr("Overpass query:")), GBC.eol().insets(5, 1, 5, 1).anchor(GBC.NORTHWEST));
    169168            leftPanel.add(new JLabel(), GBC.eol().fill(GBC.VERTICAL));
    170             OverpassWizardRegistration.getWizards()
     169            OverpassWizardRegistration.getWizards(this)
    171170                .stream()
    172                 .map(this::generateWizardButton)
     171                .map(JButton::new)
    173172                .forEach(button -> leftPanel.add(button, GBC.eol().anchor(GBC.CENTER)));
    174173            leftPanel.add(new JLabel(), GBC.eol().fill(GBC.VERTICAL));
     
    180179
    181180            setMinimumSize(new Dimension(450, 240));
    182         }
    183 
    184         private JButton generateWizardButton(OverpassQueryWizard wizard) {
    185             JButton openQueryWizard = new JButton(wizard.getWizardName());
    186             openQueryWizard.setToolTipText(wizard.getWizardTooltip().orElse(null));
    187             openQueryWizard.addActionListener(new AbstractAction() {
    188                 @Override
    189                 public void actionPerformed(ActionEvent e) {
    190                     wizard.startWizard(OverpassDownloadSourcePanel.this);
    191                 }
    192             });
    193             return openQueryWizard;
    194181        }
    195182
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassQueryWizardDialog.java

    r16354 r16355  
    4545                tr("Build query"), tr("Build query and execute"), tr("Cancel"));
    4646        this.callbacks = callbacks;
    47         setButtonIcons("ok", "download-overpass", "cancel");
     47        setButtonIcons("dialogs/magic-wand", "download-overpass", "cancel");
    4848        setCancelButton(CANCEL + 1);
    4949        setDefaultButton(BUILD_AN_EXECUTE_QUERY + 1);
  • trunk/src/org/openstreetmap/josm/gui/download/overpass/OverpassWizardRegistration.java

    r16353 r16355  
    55
    66import java.awt.Component;
     7import java.awt.event.ActionEvent;
    78import java.util.ArrayList;
    89import java.util.Collections;
    910import java.util.List;
    1011import java.util.Objects;
    11 import java.util.Optional;
     12import java.util.function.Function;
     13import java.util.stream.Collectors;
     14
     15import javax.swing.AbstractAction;
     16import javax.swing.Action;
    1217
    1318import org.openstreetmap.josm.gui.download.OverpassQueryWizardDialog;
     19import org.openstreetmap.josm.tools.ImageProvider;
    1420
    1521/**
     
    2228     * A list of all registered wizards. Needs to be synchronized since plugin registration may happen outside main thread / asynchronously.
    2329     */
    24     private static List<OverpassQueryWizard> wizards = Collections.synchronizedList(new ArrayList<>());
     30    private static final List<Function<OverpassWizardCallbacks, Action>> wizards = Collections.synchronizedList(new ArrayList<>());
    2531
    2632    /**
     
    2935     * To be called by plugins during the JOSM boot process or at least before opening the download dialog for the first time.
    3036     * @param wizard The wizard to register
    31      * @since 13930
     37     * @since 13930, 16355 (signature)
    3238     */
    33     public static void registerWizard(OverpassQueryWizard wizard) {
     39    public static void registerWizard(Function<OverpassWizardCallbacks, Action> wizard) {
    3440        Objects.requireNonNull(wizard, "wizard");
    3541        wizards.add(wizard);
     
    4046     * @return The list of wizards.
    4147     */
    42     public static List<OverpassQueryWizard> getWizards() {
    43         return Collections.unmodifiableList(wizards);
     48    public static List<Action> getWizards(OverpassWizardCallbacks callbacks) {
     49        return wizards.stream()
     50                .map(x -> x.apply(callbacks))
     51                .collect(Collectors.toList());
    4452    }
    4553
    4654    static {
    4755        // Register the default wizard
    48         registerWizard(new OverpassQueryWizard() {
     56        registerWizard(callbacks -> new AbstractAction(tr("Query Wizard")) {
     57            {
     58                putValue(SHORT_DESCRIPTION, tr("Build an Overpass query using the Overpass Turbo Query Wizard tool"));
     59                new ImageProvider("dialogs/magic-wand").getResource().attachImageIcon(this, true);
     60            }
    4961            @Override
    50             public void startWizard(OverpassWizardCallbacks callbacks) {
     62            public void actionPerformed(ActionEvent e) {
    5163                new OverpassQueryWizardDialog(callbacks).showDialog();
    52             }
    53 
    54             @Override
    55             public Optional<String> getWizardTooltip() {
    56                 return Optional.of(tr("Build an Overpass query using the Overpass Turbo Query Wizard tool"));
    57             }
    58 
    59             @Override
    60             public String getWizardName() {
    61                 return tr("Query Wizard");
    6264            }
    6365        });
     
    6971
    7072    /**
    71      * Defines a query wizard that generates overpass queries.
    72      * @author Michael Zangl
    73      * @since 13930
    74      */
    75     public interface OverpassQueryWizard {
    76         /**
    77          * Get the name of the wizard
    78          * @return The name
    79          */
    80         String getWizardName();
    81 
    82         /**
    83          * Get the tooltip text to display when hovering the wizard button.
    84          * @return The tooltip text or an empty optional to display no tooltip.
    85          */
    86         Optional<String> getWizardTooltip();
    87 
    88         /**
    89          * Start the wizard.
    90          * @param callbacks The callbacks to use to send back wizard results.
    91          */
    92         void startWizard(OverpassWizardCallbacks callbacks);
    93     }
    94 
    95     /**
    96      * Wizard callbacks required by {@link OverpassQueryWizard#startWizard}
     73     * Wizard callbacks required by {@link #registerWizard}
    9774     * @author Michael Zangl
    9875     * @since 13930
Note: See TracChangeset for help on using the changeset viewer.