Changeset 16355 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-04-19T12:44:40+02:00 (5 years ago)
- 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 39 39 import org.openstreetmap.josm.gui.download.DownloadSourceSizingPolicy.AdjustableDownloadSizePolicy; 40 40 import org.openstreetmap.josm.gui.download.overpass.OverpassWizardRegistration; 41 import org.openstreetmap.josm.gui.download.overpass.OverpassWizardRegistration.OverpassQueryWizard;42 41 import org.openstreetmap.josm.gui.download.overpass.OverpassWizardRegistration.OverpassWizardCallbacks; 43 42 import org.openstreetmap.josm.gui.util.GuiHelper; … … 168 167 leftPanel.add(new JLabel(tr("Overpass query:")), GBC.eol().insets(5, 1, 5, 1).anchor(GBC.NORTHWEST)); 169 168 leftPanel.add(new JLabel(), GBC.eol().fill(GBC.VERTICAL)); 170 OverpassWizardRegistration.getWizards( )169 OverpassWizardRegistration.getWizards(this) 171 170 .stream() 172 .map( this::generateWizardButton)171 .map(JButton::new) 173 172 .forEach(button -> leftPanel.add(button, GBC.eol().anchor(GBC.CENTER))); 174 173 leftPanel.add(new JLabel(), GBC.eol().fill(GBC.VERTICAL)); … … 180 179 181 180 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 @Override189 public void actionPerformed(ActionEvent e) {190 wizard.startWizard(OverpassDownloadSourcePanel.this);191 }192 });193 return openQueryWizard;194 181 } 195 182 -
trunk/src/org/openstreetmap/josm/gui/download/OverpassQueryWizardDialog.java
r16354 r16355 45 45 tr("Build query"), tr("Build query and execute"), tr("Cancel")); 46 46 this.callbacks = callbacks; 47 setButtonIcons(" ok", "download-overpass", "cancel");47 setButtonIcons("dialogs/magic-wand", "download-overpass", "cancel"); 48 48 setCancelButton(CANCEL + 1); 49 49 setDefaultButton(BUILD_AN_EXECUTE_QUERY + 1); -
trunk/src/org/openstreetmap/josm/gui/download/overpass/OverpassWizardRegistration.java
r16353 r16355 5 5 6 6 import java.awt.Component; 7 import java.awt.event.ActionEvent; 7 8 import java.util.ArrayList; 8 9 import java.util.Collections; 9 10 import java.util.List; 10 11 import java.util.Objects; 11 import java.util.Optional; 12 import java.util.function.Function; 13 import java.util.stream.Collectors; 14 15 import javax.swing.AbstractAction; 16 import javax.swing.Action; 12 17 13 18 import org.openstreetmap.josm.gui.download.OverpassQueryWizardDialog; 19 import org.openstreetmap.josm.tools.ImageProvider; 14 20 15 21 /** … … 22 28 * A list of all registered wizards. Needs to be synchronized since plugin registration may happen outside main thread / asynchronously. 23 29 */ 24 private static List<OverpassQueryWizard> wizards = Collections.synchronizedList(new ArrayList<>());30 private static final List<Function<OverpassWizardCallbacks, Action>> wizards = Collections.synchronizedList(new ArrayList<>()); 25 31 26 32 /** … … 29 35 * To be called by plugins during the JOSM boot process or at least before opening the download dialog for the first time. 30 36 * @param wizard The wizard to register 31 * @since 13930 37 * @since 13930, 16355 (signature) 32 38 */ 33 public static void registerWizard( OverpassQueryWizardwizard) {39 public static void registerWizard(Function<OverpassWizardCallbacks, Action> wizard) { 34 40 Objects.requireNonNull(wizard, "wizard"); 35 41 wizards.add(wizard); … … 40 46 * @return The list of wizards. 41 47 */ 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()); 44 52 } 45 53 46 54 static { 47 55 // 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 } 49 61 @Override 50 public void startWizard(OverpassWizardCallbacks callbacks) {62 public void actionPerformed(ActionEvent e) { 51 63 new OverpassQueryWizardDialog(callbacks).showDialog(); 52 }53 54 @Override55 public Optional<String> getWizardTooltip() {56 return Optional.of(tr("Build an Overpass query using the Overpass Turbo Query Wizard tool"));57 }58 59 @Override60 public String getWizardName() {61 return tr("Query Wizard");62 64 } 63 65 }); … … 69 71 70 72 /** 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} 97 74 * @author Michael Zangl 98 75 * @since 13930
Note:
See TracChangeset
for help on using the changeset viewer.