001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.tagging.presets; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005import static org.openstreetmap.josm.tools.I18n.trc; 006import static org.openstreetmap.josm.tools.I18n.trn; 007 008import java.awt.Component; 009import java.awt.Dimension; 010import java.awt.GridBagLayout; 011import java.awt.Insets; 012import java.awt.event.ActionEvent; 013import java.io.File; 014import java.util.ArrayList; 015import java.util.Collection; 016import java.util.Collections; 017import java.util.EnumSet; 018import java.util.HashSet; 019import java.util.LinkedList; 020import java.util.List; 021import java.util.Map; 022import java.util.Set; 023import java.util.concurrent.CompletableFuture; 024import java.util.function.Predicate; 025 026import javax.swing.AbstractAction; 027import javax.swing.Action; 028import javax.swing.ImageIcon; 029import javax.swing.JLabel; 030import javax.swing.JOptionPane; 031import javax.swing.JPanel; 032import javax.swing.JToggleButton; 033import javax.swing.SwingUtilities; 034 035import org.openstreetmap.josm.actions.AdaptableAction; 036import org.openstreetmap.josm.command.ChangePropertyCommand; 037import org.openstreetmap.josm.command.Command; 038import org.openstreetmap.josm.command.SequenceCommand; 039import org.openstreetmap.josm.data.UndoRedoHandler; 040import org.openstreetmap.josm.data.osm.DataSet; 041import org.openstreetmap.josm.data.osm.IPrimitive; 042import org.openstreetmap.josm.data.osm.OsmData; 043import org.openstreetmap.josm.data.osm.OsmDataManager; 044import org.openstreetmap.josm.data.osm.OsmPrimitive; 045import org.openstreetmap.josm.data.osm.Relation; 046import org.openstreetmap.josm.data.osm.RelationMember; 047import org.openstreetmap.josm.data.osm.Tag; 048import org.openstreetmap.josm.data.osm.search.SearchCompiler; 049import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 050import org.openstreetmap.josm.data.osm.search.SearchParseError; 051import org.openstreetmap.josm.gui.ExtendedDialog; 052import org.openstreetmap.josm.gui.MainApplication; 053import org.openstreetmap.josm.gui.Notification; 054import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 055import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 056import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 057import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 058import org.openstreetmap.josm.gui.tagging.presets.items.Key; 059import org.openstreetmap.josm.gui.tagging.presets.items.Link; 060import org.openstreetmap.josm.gui.tagging.presets.items.Optional; 061import org.openstreetmap.josm.gui.tagging.presets.items.PresetLink; 062import org.openstreetmap.josm.gui.tagging.presets.items.Roles; 063import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role; 064import org.openstreetmap.josm.gui.tagging.presets.items.Space; 065import org.openstreetmap.josm.gui.util.GuiHelper; 066import org.openstreetmap.josm.spi.preferences.Config; 067import org.openstreetmap.josm.tools.GBC; 068import org.openstreetmap.josm.tools.ImageProvider; 069import org.openstreetmap.josm.tools.Logging; 070import org.openstreetmap.josm.tools.Utils; 071import org.openstreetmap.josm.tools.template_engine.ParseError; 072import org.openstreetmap.josm.tools.template_engine.TemplateEntry; 073import org.openstreetmap.josm.tools.template_engine.TemplateParser; 074import org.xml.sax.SAXException; 075 076/** 077 * This class read encapsulate one tagging preset. A class method can 078 * read in all predefined presets, either shipped with JOSM or that are 079 * in the config directory. 080 * 081 * It is also able to construct dialogs out of preset definitions. 082 * @since 294 083 */ 084public class TaggingPreset extends AbstractAction implements ActiveLayerChangeListener, AdaptableAction, Predicate<IPrimitive> { 085 086 public static final int DIALOG_ANSWER_APPLY = 1; 087 public static final int DIALOG_ANSWER_NEW_RELATION = 2; 088 public static final int DIALOG_ANSWER_CANCEL = 3; 089 090 public static final String OPTIONAL_TOOLTIP_TEXT = "Optional tooltip text"; 091 092 /** Prefix of preset icon loading failure error message */ 093 public static final String PRESET_ICON_ERROR_MSG_PREFIX = "Could not get presets icon "; 094 095 /** 096 * The preset group this preset belongs to. 097 */ 098 public TaggingPresetMenu group; 099 100 /** 101 * The name of the tagging preset. 102 * @see #getRawName() 103 */ 104 public String name; 105 /** 106 * The icon name assigned to this preset. 107 */ 108 public String iconName; 109 public String name_context; 110 /** 111 * A cache for the local name. Should never be accessed directly. 112 * @see #getLocaleName() 113 */ 114 public String locale_name; 115 public boolean preset_name_label; 116 117 /** 118 * The types as preparsed collection. 119 */ 120 public transient Set<TaggingPresetType> types; 121 public final transient List<TaggingPresetItem> data = new LinkedList<>(); 122 public transient Roles roles; 123 public transient TemplateEntry nameTemplate; 124 public transient Match nameTemplateFilter; 125 126 /** 127 * True whenever the original selection given into createSelection was empty 128 */ 129 private boolean originalSelectionEmpty; 130 131 /** The completable future task of asynchronous icon loading */ 132 private CompletableFuture<Void> iconFuture; 133 134 /** 135 * Create an empty tagging preset. This will not have any items and 136 * will be an empty string as text. createPanel will return null. 137 * Use this as default item for "do not select anything". 138 */ 139 public TaggingPreset() { 140 MainApplication.getLayerManager().addActiveLayerChangeListener(this); 141 updateEnabledState(); 142 } 143 144 /** 145 * Change the display name without changing the toolbar value. 146 */ 147 public void setDisplayName() { 148 putValue(Action.NAME, getName()); 149 putValue("toolbar", "tagging_" + getRawName()); 150 putValue(OPTIONAL_TOOLTIP_TEXT, group != null ? 151 tr("Use preset ''{0}'' of group ''{1}''", getLocaleName(), group.getName()) : 152 tr("Use preset ''{0}''", getLocaleName())); 153 } 154 155 /** 156 * Gets the localized version of the name 157 * @return The name that should be displayed to the user. 158 */ 159 public String getLocaleName() { 160 if (locale_name == null) { 161 if (name_context != null) { 162 locale_name = trc(name_context, TaggingPresetItem.fixPresetString(name)); 163 } else { 164 locale_name = tr(TaggingPresetItem.fixPresetString(name)); 165 } 166 } 167 return locale_name; 168 } 169 170 /** 171 * Returns the translated name of this preset, prefixed with the group names it belongs to. 172 * @return the translated name of this preset, prefixed with the group names it belongs to 173 */ 174 public String getName() { 175 return group != null ? group.getName() + '/' + getLocaleName() : getLocaleName(); 176 } 177 178 /** 179 * Returns the non translated name of this preset, prefixed with the (non translated) group names it belongs to. 180 * @return the non translated name of this preset, prefixed with the (non translated) group names it belongs to 181 */ 182 public String getRawName() { 183 return group != null ? group.getRawName() + '/' + name : name; 184 } 185 186 /** 187 * Returns the preset icon (16px). 188 * @return The preset icon, or {@code null} if none defined 189 * @since 6403 190 */ 191 public final ImageIcon getIcon() { 192 return getIcon(Action.SMALL_ICON); 193 } 194 195 /** 196 * Returns the preset icon (16 or 24px). 197 * @param key Key determining icon size: {@code Action.SMALL_ICON} for 16x, {@code Action.LARGE_ICON_KEY} for 24px 198 * @return The preset icon, or {@code null} if none defined 199 * @since 10849 200 */ 201 public final ImageIcon getIcon(String key) { 202 Object icon = getValue(key); 203 if (icon instanceof ImageIcon) { 204 return (ImageIcon) icon; 205 } 206 return null; 207 } 208 209 /** 210 * Called from the XML parser to set the icon. 211 * The loading task is performed in the background in order to speedup startup. 212 * @param iconName icon name 213 */ 214 public void setIcon(final String iconName) { 215 this.iconName = iconName; 216 if (iconName == null || !TaggingPresetReader.isLoadIcons()) { 217 return; 218 } 219 File arch = TaggingPresetReader.getZipIcons(); 220 final Collection<String> s = Config.getPref().getList("taggingpreset.icon.sources", null); 221 this.iconFuture = new ImageProvider(iconName) 222 .setDirs(s) 223 .setId("presets") 224 .setArchive(arch) 225 .setOptional(true) 226 .getResourceAsync(result -> { 227 if (result != null) { 228 GuiHelper.runInEDT(() -> result.attachImageIcon(this)); 229 } else { 230 Logging.warn(toString() + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName); 231 } 232 }); 233 } 234 235 /** 236 * Called from the XML parser to set the types this preset affects. 237 * @param types comma-separated primitive types ("node", "way", "relation" or "closedway") 238 * @throws SAXException if any SAX error occurs 239 * @see TaggingPresetType#fromString 240 */ 241 public void setType(String types) throws SAXException { 242 this.types = TaggingPresetItem.getType(types); 243 } 244 245 public void setName_template(String pattern) throws SAXException { 246 try { 247 this.nameTemplate = new TemplateParser(pattern).parse(); 248 } catch (ParseError e) { 249 Logging.error("Error while parsing " + pattern + ": " + e.getMessage()); 250 throw new SAXException(e); 251 } 252 } 253 254 public void setName_template_filter(String filter) throws SAXException { 255 try { 256 this.nameTemplateFilter = SearchCompiler.compile(filter); 257 } catch (SearchParseError e) { 258 Logging.error("Error while parsing" + filter + ": " + e.getMessage()); 259 throw new SAXException(e); 260 } 261 } 262 263 private static class PresetPanel extends JPanel { 264 private boolean hasElements; 265 266 PresetPanel() { 267 super(new GridBagLayout()); 268 } 269 } 270 271 /** 272 * Returns the tags being directly applied (without UI element) by {@link Key} items 273 * 274 * @return a list of tags 275 */ 276 private List<Tag> getDirectlyAppliedTags() { 277 List<Tag> tags = new ArrayList<>(); 278 for (TaggingPresetItem item : data) { 279 if (item instanceof Key) { 280 tags.add(((Key) item).asTag()); 281 } 282 } 283 return tags; 284 } 285 286 /** 287 * Creates a panel for this preset. This includes general information such as name and supported {@link TaggingPresetType types}. 288 * This includes the elements from the individual {@link TaggingPresetItem items}. 289 * 290 * @param selected the selected primitives 291 * @return the newly created panel 292 */ 293 public PresetPanel createPanel(Collection<OsmPrimitive> selected) { 294 PresetPanel p = new PresetPanel(); 295 List<Link> l = new LinkedList<>(); 296 List<PresetLink> presetLink = new LinkedList<>(); 297 298 final JPanel pp = new JPanel(); 299 if (types != null) { 300 for (TaggingPresetType t : types) { 301 JLabel la = new JLabel(ImageProvider.get(t.getIconName())); 302 la.setToolTipText(tr("Elements of type {0} are supported.", tr(t.getName()))); 303 pp.add(la); 304 } 305 } 306 final List<Tag> directlyAppliedTags = getDirectlyAppliedTags(); 307 if (!directlyAppliedTags.isEmpty()) { 308 final JLabel label = new JLabel(ImageProvider.get("pastetags")); 309 label.setToolTipText("<html>" + tr("This preset also sets: {0}", Utils.joinAsHtmlUnorderedList(directlyAppliedTags))); 310 pp.add(label); 311 } 312 final int count = pp.getComponentCount(); 313 if (preset_name_label) { 314 p.add(new JLabel(getIcon(Action.LARGE_ICON_KEY)), GBC.std(0, 0).span(1, count > 0 ? 2 : 1).insets(0, 0, 5, 0)); 315 } 316 if (count > 0) { 317 p.add(pp, GBC.std(1, 0).span(GBC.REMAINDER)); 318 } 319 if (preset_name_label) { 320 p.add(new JLabel(getName()), GBC.std(1, count > 0 ? 1 : 0).insets(5, 0, 0, 0).span(GBC.REMAINDER).fill(GBC.HORIZONTAL)); 321 } 322 323 boolean presetInitiallyMatches = !selected.isEmpty() && selected.stream().allMatch(this); 324 JPanel items = new JPanel(new GridBagLayout()); 325 for (TaggingPresetItem i : data) { 326 if (i instanceof Link) { 327 l.add((Link) i); 328 p.hasElements = true; 329 } else if (i instanceof PresetLink) { 330 presetLink.add((PresetLink) i); 331 } else { 332 if (i.addToPanel(items, selected, presetInitiallyMatches)) { 333 p.hasElements = true; 334 } 335 } 336 } 337 p.add(items, GBC.eol().fill()); 338 if (selected.isEmpty() && !supportsRelation()) { 339 GuiHelper.setEnabledRec(items, false); 340 } 341 342 // add PresetLink 343 if (!presetLink.isEmpty()) { 344 p.add(new JLabel(tr("Edit also …")), GBC.eol().insets(0, 8, 0, 0)); 345 for (PresetLink link : presetLink) { 346 link.addToPanel(p, selected, presetInitiallyMatches); 347 } 348 } 349 350 // add Link 351 for (Link link : l) { 352 link.addToPanel(p, selected, presetInitiallyMatches); 353 } 354 355 // "Add toolbar button" 356 JToggleButton tb = new JToggleButton(new ToolbarButtonAction()); 357 tb.setFocusable(false); 358 p.add(tb, GBC.std(1, 0).anchor(GBC.LINE_END)); 359 return p; 360 } 361 362 /** 363 * Determines whether a dialog can be shown for this preset, i.e., at least one tag can/must be set by the user. 364 * 365 * @return {@code true} if a dialog can be shown for this preset 366 */ 367 public boolean isShowable() { 368 for (TaggingPresetItem i : data) { 369 if (!(i instanceof Optional || i instanceof Space || i instanceof Key)) 370 return true; 371 } 372 return false; 373 } 374 375 public String suggestRoleForOsmPrimitive(OsmPrimitive osm) { 376 if (roles != null && osm != null) { 377 for (Role i : roles.roles) { 378 if (i.memberExpression != null && i.memberExpression.match(osm) 379 && (i.types == null || i.types.isEmpty() || i.types.contains(TaggingPresetType.forPrimitive(osm)))) { 380 return i.key; 381 } 382 } 383 } 384 return null; 385 } 386 387 @Override 388 public void actionPerformed(ActionEvent e) { 389 DataSet ds = OsmDataManager.getInstance().getEditDataSet(); 390 Collection<OsmPrimitive> participants = Collections.emptyList(); 391 if (ds != null) { 392 participants = ds.getSelected(); 393 } 394 395 // Display dialog even if no data layer (used by preset-tagging-tester plugin) 396 Collection<OsmPrimitive> sel = createSelection(participants); 397 int answer = showDialog(sel, supportsRelation()); 398 399 if (ds == null) { 400 return; 401 } 402 403 if (!sel.isEmpty() && answer == DIALOG_ANSWER_APPLY) { 404 Command cmd = createCommand(sel, getChangedTags()); 405 if (cmd != null) { 406 UndoRedoHandler.getInstance().add(cmd); 407 } 408 } else if (answer == DIALOG_ANSWER_NEW_RELATION) { 409 final Relation r = new Relation(); 410 final Collection<RelationMember> members = new HashSet<>(); 411 for (Tag t : getChangedTags()) { 412 r.put(t.getKey(), t.getValue()); 413 } 414 for (OsmPrimitive osm : ds.getSelected()) { 415 String role = suggestRoleForOsmPrimitive(osm); 416 RelationMember rm = new RelationMember(role == null ? "" : role, osm); 417 r.addMember(rm); 418 members.add(rm); 419 } 420 SwingUtilities.invokeLater(() -> RelationEditor.getEditor( 421 MainApplication.getLayerManager().getEditLayer(), r, members).setVisible(true)); 422 } 423 ds.setSelected(ds.getSelected()); // force update 424 } 425 426 private static class PresetDialog extends ExtendedDialog { 427 428 /** 429 * Constructs a new {@code PresetDialog}. 430 * @param content the content that will be displayed in this dialog 431 * @param title the text that will be shown in the window titlebar 432 * @param icon the image to be displayed as the icon for this window 433 * @param disableApply whether to disable "Apply" button 434 * @param showNewRelation whether to display "New relation" button 435 */ 436 PresetDialog(Component content, String title, ImageIcon icon, boolean disableApply, boolean showNewRelation) { 437 super(MainApplication.getMainFrame(), title, 438 showNewRelation ? 439 (new String[] {tr("Apply Preset"), tr("New relation"), tr("Cancel")}) : 440 (new String[] {tr("Apply Preset"), tr("Cancel")}), 441 true); 442 if (icon != null) 443 setIconImage(icon.getImage()); 444 contentInsets = new Insets(10, 5, 0, 5); 445 if (showNewRelation) { 446 setButtonIcons("ok", "dialogs/addrelation", "cancel"); 447 } else { 448 setButtonIcons("ok", "cancel"); 449 } 450 setContent(content); 451 setDefaultButton(1); 452 setupDialog(); 453 buttons.get(0).setEnabled(!disableApply); 454 buttons.get(0).setToolTipText(title); 455 // Prevent dialogs of being too narrow (fix #6261) 456 Dimension d = getSize(); 457 if (d.width < 350) { 458 d.width = 350; 459 setSize(d); 460 } 461 super.showDialog(); 462 } 463 } 464 465 /** 466 * Shows the preset dialog. 467 * @param sel selection 468 * @param showNewRelation whether to display "New relation" button 469 * @return the user choice after the dialog has been closed 470 */ 471 public int showDialog(Collection<OsmPrimitive> sel, boolean showNewRelation) { 472 PresetPanel p = createPanel(sel); 473 474 int answer = 1; 475 boolean canCreateRelation = types == null || types.contains(TaggingPresetType.RELATION); 476 if (originalSelectionEmpty && !canCreateRelation) { 477 new Notification( 478 tr("The preset <i>{0}</i> cannot be applied since nothing has been selected!", getLocaleName())) 479 .setIcon(JOptionPane.WARNING_MESSAGE) 480 .show(); 481 return DIALOG_ANSWER_CANCEL; 482 } else if (sel.isEmpty() && !canCreateRelation) { 483 new Notification( 484 tr("The preset <i>{0}</i> cannot be applied since the selection is unsuitable!", getLocaleName())) 485 .setIcon(JOptionPane.WARNING_MESSAGE) 486 .show(); 487 return DIALOG_ANSWER_CANCEL; 488 } else if (p.getComponentCount() != 0 && (sel.isEmpty() || p.hasElements)) { 489 int size = sel.size(); 490 String title = trn("Change {0} object", "Change {0} objects", size, size); 491 if (!showNewRelation && size == 0) { 492 if (originalSelectionEmpty) { 493 title = tr("Nothing selected!"); 494 } else { 495 title = tr("Selection unsuitable!"); 496 } 497 } 498 499 boolean disableApply = size == 0; 500 if (!disableApply) { 501 OsmData<?, ?, ?, ?> ds = sel.iterator().next().getDataSet(); 502 disableApply = ds != null && ds.isLocked(); 503 } 504 answer = new PresetDialog(p, title, preset_name_label ? null : (ImageIcon) getValue(Action.SMALL_ICON), 505 disableApply, showNewRelation).getValue(); 506 } 507 if (!showNewRelation && answer == 2) 508 return DIALOG_ANSWER_CANCEL; 509 else 510 return answer; 511 } 512 513 /** 514 * Removes all unsuitable OsmPrimitives from the given list 515 * @param participants List of possible OsmPrimitives to tag 516 * @return Cleaned list with suitable OsmPrimitives only 517 */ 518 public Collection<OsmPrimitive> createSelection(Collection<OsmPrimitive> participants) { 519 originalSelectionEmpty = participants.isEmpty(); 520 Collection<OsmPrimitive> sel = new LinkedList<>(); 521 for (OsmPrimitive osm : participants) { 522 if (typeMatches(EnumSet.of(TaggingPresetType.forPrimitive(osm)))) { 523 sel.add(osm); 524 } 525 } 526 return sel; 527 } 528 529 /** 530 * Gets a list of tags that are set by this preset. 531 * @return The list of tags. 532 */ 533 public List<Tag> getChangedTags() { 534 List<Tag> result = new ArrayList<>(); 535 for (TaggingPresetItem i: data) { 536 i.addCommands(result); 537 } 538 return result; 539 } 540 541 /** 542 * Create a command to change the given list of tags. 543 * @param sel The primitives to change the tags for 544 * @param changedTags The tags to change 545 * @return A command that changes the tags. 546 */ 547 public static Command createCommand(Collection<OsmPrimitive> sel, List<Tag> changedTags) { 548 List<Command> cmds = new ArrayList<>(); 549 for (Tag tag: changedTags) { 550 ChangePropertyCommand cmd = new ChangePropertyCommand(sel, tag.getKey(), tag.getValue()); 551 if (cmd.getObjectsNumber() > 0) { 552 cmds.add(cmd); 553 } 554 } 555 556 if (cmds.isEmpty()) 557 return null; 558 else if (cmds.size() == 1) 559 return cmds.get(0); 560 else 561 return new SequenceCommand(tr("Change Tags"), cmds); 562 } 563 564 private boolean supportsRelation() { 565 return types == null || types.contains(TaggingPresetType.RELATION); 566 } 567 568 protected final void updateEnabledState() { 569 setEnabled(OsmDataManager.getInstance().getEditDataSet() != null); 570 } 571 572 @Override 573 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 574 updateEnabledState(); 575 } 576 577 @Override 578 public String toString() { 579 return (types == null ? "" : types.toString()) + ' ' + name; 580 } 581 582 /** 583 * Determines whether this preset matches the types. 584 * @param t The types that must match 585 * @return <code>true</code> if all types match. 586 */ 587 public boolean typeMatches(Collection<TaggingPresetType> t) { 588 return t == null || types == null || types.containsAll(t); 589 } 590 591 /** 592 * Determines whether this preset matches the given primitive, i.e., 593 * whether the {@link #typeMatches(Collection) type matches} and the {@link TaggingPresetItem#matches(Map) tags match}. 594 * 595 * @param p the primitive 596 * @return {@code true} if this preset matches the primitive 597 * @since 13623 (signature) 598 */ 599 @Override 600 public boolean test(IPrimitive p) { 601 return matches(EnumSet.of(TaggingPresetType.forPrimitive(p)), p.getKeys(), false); 602 } 603 604 /** 605 * Determines whether this preset matches the parameters. 606 * 607 * @param t the preset types to include, see {@link #typeMatches(Collection)} 608 * @param tags the tags to perform matching on, see {@link TaggingPresetItem#matches(Map)} 609 * @param onlyShowable whether the preset must be {@link #isShowable() showable} 610 * @return {@code true} if this preset matches the parameters. 611 */ 612 public boolean matches(Collection<TaggingPresetType> t, Map<String, String> tags, boolean onlyShowable) { 613 if ((onlyShowable && !isShowable()) || !typeMatches(t)) { 614 return false; 615 } else { 616 return TaggingPresetItem.matches(data, tags); 617 } 618 } 619 620 /** 621 * Action that adds or removes the button on main toolbar 622 */ 623 public class ToolbarButtonAction extends AbstractAction { 624 private final int toolbarIndex; 625 626 /** 627 * Constructs a new {@code ToolbarButtonAction}. 628 */ 629 public ToolbarButtonAction() { 630 super(""); 631 new ImageProvider("dialogs", "pin").getResource().attachImageIcon(this, true); 632 putValue(SHORT_DESCRIPTION, tr("Add or remove toolbar button")); 633 List<String> t = new LinkedList<>(ToolbarPreferences.getToolString()); 634 toolbarIndex = t.indexOf(getToolbarString()); 635 putValue(SELECTED_KEY, toolbarIndex >= 0); 636 } 637 638 @Override 639 public void actionPerformed(ActionEvent ae) { 640 String res = getToolbarString(); 641 MainApplication.getToolbar().addCustomButton(res, toolbarIndex, true); 642 } 643 } 644 645 /** 646 * Gets a string describing this preset that can be used for the toolbar 647 * @return A String that can be passed on to the toolbar 648 * @see ToolbarPreferences#addCustomButton(String, int, boolean) 649 */ 650 public String getToolbarString() { 651 ToolbarPreferences.ActionParser actionParser = new ToolbarPreferences.ActionParser(null); 652 return actionParser.saveAction(new ToolbarPreferences.ActionDefinition(this)); 653 } 654 655 /** 656 * Returns the completable future task that performs icon loading, if any. 657 * @return the completable future task that performs icon loading, or null 658 * @since 14449 659 */ 660 public CompletableFuture<Void> getIconLoadingTask() { 661 return iconFuture; 662 } 663}