source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java@ 15029

Last change on this file since 15029 was 15029, checked in by Don-vip, 5 years ago

fix #17645 - robustness to invalid preset icons

  • Property svn:eol-style set to native
File size: 25.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.presets;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trc;
6import static org.openstreetmap.josm.tools.I18n.trn;
7
8import java.awt.Component;
9import java.awt.Dimension;
10import java.awt.GridBagLayout;
11import java.awt.Insets;
12import java.awt.event.ActionEvent;
13import java.io.File;
14import java.util.ArrayList;
15import java.util.Collection;
16import java.util.Collections;
17import java.util.EnumSet;
18import java.util.HashSet;
19import java.util.LinkedList;
20import java.util.List;
21import java.util.Map;
22import java.util.Set;
23import java.util.concurrent.CompletableFuture;
24import java.util.function.Predicate;
25
26import javax.swing.AbstractAction;
27import javax.swing.Action;
28import javax.swing.ImageIcon;
29import javax.swing.JLabel;
30import javax.swing.JOptionPane;
31import javax.swing.JPanel;
32import javax.swing.JToggleButton;
33import javax.swing.SwingUtilities;
34
35import org.openstreetmap.josm.actions.AdaptableAction;
36import org.openstreetmap.josm.command.ChangePropertyCommand;
37import org.openstreetmap.josm.command.Command;
38import org.openstreetmap.josm.command.SequenceCommand;
39import org.openstreetmap.josm.data.UndoRedoHandler;
40import org.openstreetmap.josm.data.osm.DataSet;
41import org.openstreetmap.josm.data.osm.IPrimitive;
42import org.openstreetmap.josm.data.osm.OsmData;
43import org.openstreetmap.josm.data.osm.OsmDataManager;
44import org.openstreetmap.josm.data.osm.OsmPrimitive;
45import org.openstreetmap.josm.data.osm.Relation;
46import org.openstreetmap.josm.data.osm.RelationMember;
47import org.openstreetmap.josm.data.osm.Tag;
48import org.openstreetmap.josm.data.osm.search.SearchCompiler;
49import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
50import org.openstreetmap.josm.data.osm.search.SearchParseError;
51import org.openstreetmap.josm.gui.ExtendedDialog;
52import org.openstreetmap.josm.gui.MainApplication;
53import org.openstreetmap.josm.gui.Notification;
54import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
55import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
56import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
57import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
58import org.openstreetmap.josm.gui.tagging.presets.items.Key;
59import org.openstreetmap.josm.gui.tagging.presets.items.Link;
60import org.openstreetmap.josm.gui.tagging.presets.items.Optional;
61import org.openstreetmap.josm.gui.tagging.presets.items.PresetLink;
62import org.openstreetmap.josm.gui.tagging.presets.items.Roles;
63import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role;
64import org.openstreetmap.josm.gui.tagging.presets.items.Space;
65import org.openstreetmap.josm.gui.util.GuiHelper;
66import org.openstreetmap.josm.spi.preferences.Config;
67import org.openstreetmap.josm.tools.GBC;
68import org.openstreetmap.josm.tools.ImageProvider;
69import org.openstreetmap.josm.tools.Logging;
70import org.openstreetmap.josm.tools.Utils;
71import org.openstreetmap.josm.tools.template_engine.ParseError;
72import org.openstreetmap.josm.tools.template_engine.TemplateEntry;
73import org.openstreetmap.josm.tools.template_engine.TemplateParser;
74import org.xml.sax.SAXException;
75
76/**
77 * This class read encapsulate one tagging preset. A class method can
78 * read in all predefined presets, either shipped with JOSM or that are
79 * in the config directory.
80 *
81 * It is also able to construct dialogs out of preset definitions.
82 * @since 294
83 */
84public class TaggingPreset extends AbstractAction implements ActiveLayerChangeListener, AdaptableAction, Predicate<IPrimitive> {
85
86 public static final int DIALOG_ANSWER_APPLY = 1;
87 public static final int DIALOG_ANSWER_NEW_RELATION = 2;
88 public static final int DIALOG_ANSWER_CANCEL = 3;
89
90 public static final String OPTIONAL_TOOLTIP_TEXT = "Optional tooltip text";
91
92 /** Prefix of preset icon loading failure error message */
93 public static final String PRESET_ICON_ERROR_MSG_PREFIX = "Could not get presets icon ";
94
95 /**
96 * The preset group this preset belongs to.
97 */
98 public TaggingPresetMenu group;
99
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(() -> {
229 try {
230 result.attachImageIcon(this);
231 } catch (IllegalArgumentException e) {
232 Logging.warn(toString() + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName);
233 Logging.warn(e);
234 }
235 });
236 } else {
237 Logging.warn(toString() + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName);
238 }
239 });
240 }
241
242 /**
243 * Called from the XML parser to set the types this preset affects.
244 * @param types comma-separated primitive types ("node", "way", "relation" or "closedway")
245 * @throws SAXException if any SAX error occurs
246 * @see TaggingPresetType#fromString
247 */
248 public void setType(String types) throws SAXException {
249 this.types = TaggingPresetItem.getType(types);
250 }
251
252 public void setName_template(String pattern) throws SAXException {
253 try {
254 this.nameTemplate = new TemplateParser(pattern).parse();
255 } catch (ParseError e) {
256 Logging.error("Error while parsing " + pattern + ": " + e.getMessage());
257 throw new SAXException(e);
258 }
259 }
260
261 public void setName_template_filter(String filter) throws SAXException {
262 try {
263 this.nameTemplateFilter = SearchCompiler.compile(filter);
264 } catch (SearchParseError e) {
265 Logging.error("Error while parsing" + filter + ": " + e.getMessage());
266 throw new SAXException(e);
267 }
268 }
269
270 private static class PresetPanel extends JPanel {
271 private boolean hasElements;
272
273 PresetPanel() {
274 super(new GridBagLayout());
275 }
276 }
277
278 /**
279 * Returns the tags being directly applied (without UI element) by {@link Key} items
280 *
281 * @return a list of tags
282 */
283 private List<Tag> getDirectlyAppliedTags() {
284 List<Tag> tags = new ArrayList<>();
285 for (TaggingPresetItem item : data) {
286 if (item instanceof Key) {
287 tags.add(((Key) item).asTag());
288 }
289 }
290 return tags;
291 }
292
293 /**
294 * Creates a panel for this preset. This includes general information such as name and supported {@link TaggingPresetType types}.
295 * This includes the elements from the individual {@link TaggingPresetItem items}.
296 *
297 * @param selected the selected primitives
298 * @return the newly created panel
299 */
300 public PresetPanel createPanel(Collection<OsmPrimitive> selected) {
301 PresetPanel p = new PresetPanel();
302 List<Link> l = new LinkedList<>();
303 List<PresetLink> presetLink = new LinkedList<>();
304
305 final JPanel pp = new JPanel();
306 if (types != null) {
307 for (TaggingPresetType t : types) {
308 JLabel la = new JLabel(ImageProvider.get(t.getIconName()));
309 la.setToolTipText(tr("Elements of type {0} are supported.", tr(t.getName())));
310 pp.add(la);
311 }
312 }
313 final List<Tag> directlyAppliedTags = getDirectlyAppliedTags();
314 if (!directlyAppliedTags.isEmpty()) {
315 final JLabel label = new JLabel(ImageProvider.get("pastetags"));
316 label.setToolTipText("<html>" + tr("This preset also sets: {0}", Utils.joinAsHtmlUnorderedList(directlyAppliedTags)));
317 pp.add(label);
318 }
319 final int count = pp.getComponentCount();
320 if (preset_name_label) {
321 p.add(new JLabel(getIcon(Action.LARGE_ICON_KEY)), GBC.std(0, 0).span(1, count > 0 ? 2 : 1).insets(0, 0, 5, 0));
322 }
323 if (count > 0) {
324 p.add(pp, GBC.std(1, 0).span(GBC.REMAINDER));
325 }
326 if (preset_name_label) {
327 p.add(new JLabel(getName()), GBC.std(1, count > 0 ? 1 : 0).insets(5, 0, 0, 0).span(GBC.REMAINDER).fill(GBC.HORIZONTAL));
328 }
329
330 boolean presetInitiallyMatches = !selected.isEmpty() && selected.stream().allMatch(this);
331 JPanel items = new JPanel(new GridBagLayout());
332 for (TaggingPresetItem i : data) {
333 if (i instanceof Link) {
334 l.add((Link) i);
335 p.hasElements = true;
336 } else if (i instanceof PresetLink) {
337 presetLink.add((PresetLink) i);
338 } else {
339 if (i.addToPanel(items, selected, presetInitiallyMatches)) {
340 p.hasElements = true;
341 }
342 }
343 }
344 p.add(items, GBC.eol().fill());
345 if (selected.isEmpty() && !supportsRelation()) {
346 GuiHelper.setEnabledRec(items, false);
347 }
348
349 // add PresetLink
350 if (!presetLink.isEmpty()) {
351 p.add(new JLabel(tr("Edit also …")), GBC.eol().insets(0, 8, 0, 0));
352 for (PresetLink link : presetLink) {
353 link.addToPanel(p, selected, presetInitiallyMatches);
354 }
355 }
356
357 // add Link
358 for (Link link : l) {
359 link.addToPanel(p, selected, presetInitiallyMatches);
360 }
361
362 // "Add toolbar button"
363 JToggleButton tb = new JToggleButton(new ToolbarButtonAction());
364 tb.setFocusable(false);
365 p.add(tb, GBC.std(1, 0).anchor(GBC.LINE_END));
366 return p;
367 }
368
369 /**
370 * Determines whether a dialog can be shown for this preset, i.e., at least one tag can/must be set by the user.
371 *
372 * @return {@code true} if a dialog can be shown for this preset
373 */
374 public boolean isShowable() {
375 for (TaggingPresetItem i : data) {
376 if (!(i instanceof Optional || i instanceof Space || i instanceof Key))
377 return true;
378 }
379 return false;
380 }
381
382 public String suggestRoleForOsmPrimitive(OsmPrimitive osm) {
383 if (roles != null && osm != null) {
384 for (Role i : roles.roles) {
385 if (i.memberExpression != null && i.memberExpression.match(osm)
386 && (i.types == null || i.types.isEmpty() || i.types.contains(TaggingPresetType.forPrimitive(osm)))) {
387 return i.key;
388 }
389 }
390 }
391 return null;
392 }
393
394 @Override
395 public void actionPerformed(ActionEvent e) {
396 DataSet ds = OsmDataManager.getInstance().getEditDataSet();
397 Collection<OsmPrimitive> participants = Collections.emptyList();
398 if (ds != null) {
399 participants = ds.getSelected();
400 }
401
402 // Display dialog even if no data layer (used by preset-tagging-tester plugin)
403 Collection<OsmPrimitive> sel = createSelection(participants);
404 int answer = showDialog(sel, supportsRelation());
405
406 if (ds == null) {
407 return;
408 }
409
410 if (!sel.isEmpty() && answer == DIALOG_ANSWER_APPLY) {
411 Command cmd = createCommand(sel, getChangedTags());
412 if (cmd != null) {
413 UndoRedoHandler.getInstance().add(cmd);
414 }
415 } else if (answer == DIALOG_ANSWER_NEW_RELATION) {
416 final Relation r = new Relation();
417 final Collection<RelationMember> members = new HashSet<>();
418 for (Tag t : getChangedTags()) {
419 r.put(t.getKey(), t.getValue());
420 }
421 for (OsmPrimitive osm : ds.getSelected()) {
422 String role = suggestRoleForOsmPrimitive(osm);
423 RelationMember rm = new RelationMember(role == null ? "" : role, osm);
424 r.addMember(rm);
425 members.add(rm);
426 }
427 SwingUtilities.invokeLater(() -> RelationEditor.getEditor(
428 MainApplication.getLayerManager().getEditLayer(), r, members).setVisible(true));
429 }
430 ds.setSelected(ds.getSelected()); // force update
431 }
432
433 private static class PresetDialog extends ExtendedDialog {
434
435 /**
436 * Constructs a new {@code PresetDialog}.
437 * @param content the content that will be displayed in this dialog
438 * @param title the text that will be shown in the window titlebar
439 * @param icon the image to be displayed as the icon for this window
440 * @param disableApply whether to disable "Apply" button
441 * @param showNewRelation whether to display "New relation" button
442 */
443 PresetDialog(Component content, String title, ImageIcon icon, boolean disableApply, boolean showNewRelation) {
444 super(MainApplication.getMainFrame(), title,
445 showNewRelation ?
446 (new String[] {tr("Apply Preset"), tr("New relation"), tr("Cancel")}) :
447 (new String[] {tr("Apply Preset"), tr("Cancel")}),
448 true);
449 if (icon != null)
450 setIconImage(icon.getImage());
451 contentInsets = new Insets(10, 5, 0, 5);
452 if (showNewRelation) {
453 setButtonIcons("ok", "dialogs/addrelation", "cancel");
454 } else {
455 setButtonIcons("ok", "cancel");
456 }
457 setContent(content);
458 setDefaultButton(1);
459 setupDialog();
460 buttons.get(0).setEnabled(!disableApply);
461 buttons.get(0).setToolTipText(title);
462 // Prevent dialogs of being too narrow (fix #6261)
463 Dimension d = getSize();
464 if (d.width < 350) {
465 d.width = 350;
466 setSize(d);
467 }
468 super.showDialog();
469 }
470 }
471
472 /**
473 * Shows the preset dialog.
474 * @param sel selection
475 * @param showNewRelation whether to display "New relation" button
476 * @return the user choice after the dialog has been closed
477 */
478 public int showDialog(Collection<OsmPrimitive> sel, boolean showNewRelation) {
479 PresetPanel p = createPanel(sel);
480
481 int answer = 1;
482 boolean canCreateRelation = types == null || types.contains(TaggingPresetType.RELATION);
483 if (originalSelectionEmpty && !canCreateRelation) {
484 new Notification(
485 tr("The preset <i>{0}</i> cannot be applied since nothing has been selected!", getLocaleName()))
486 .setIcon(JOptionPane.WARNING_MESSAGE)
487 .show();
488 return DIALOG_ANSWER_CANCEL;
489 } else if (sel.isEmpty() && !canCreateRelation) {
490 new Notification(
491 tr("The preset <i>{0}</i> cannot be applied since the selection is unsuitable!", getLocaleName()))
492 .setIcon(JOptionPane.WARNING_MESSAGE)
493 .show();
494 return DIALOG_ANSWER_CANCEL;
495 } else if (p.getComponentCount() != 0 && (sel.isEmpty() || p.hasElements)) {
496 int size = sel.size();
497 String title = trn("Change {0} object", "Change {0} objects", size, size);
498 if (!showNewRelation && size == 0) {
499 if (originalSelectionEmpty) {
500 title = tr("Nothing selected!");
501 } else {
502 title = tr("Selection unsuitable!");
503 }
504 }
505
506 boolean disableApply = size == 0;
507 if (!disableApply) {
508 OsmData<?, ?, ?, ?> ds = sel.iterator().next().getDataSet();
509 disableApply = ds != null && ds.isLocked();
510 }
511 answer = new PresetDialog(p, title, preset_name_label ? null : (ImageIcon) getValue(Action.SMALL_ICON),
512 disableApply, showNewRelation).getValue();
513 }
514 if (!showNewRelation && answer == 2)
515 return DIALOG_ANSWER_CANCEL;
516 else
517 return answer;
518 }
519
520 /**
521 * Removes all unsuitable OsmPrimitives from the given list
522 * @param participants List of possible OsmPrimitives to tag
523 * @return Cleaned list with suitable OsmPrimitives only
524 */
525 public Collection<OsmPrimitive> createSelection(Collection<OsmPrimitive> participants) {
526 originalSelectionEmpty = participants.isEmpty();
527 Collection<OsmPrimitive> sel = new LinkedList<>();
528 for (OsmPrimitive osm : participants) {
529 if (typeMatches(EnumSet.of(TaggingPresetType.forPrimitive(osm)))) {
530 sel.add(osm);
531 }
532 }
533 return sel;
534 }
535
536 /**
537 * Gets a list of tags that are set by this preset.
538 * @return The list of tags.
539 */
540 public List<Tag> getChangedTags() {
541 List<Tag> result = new ArrayList<>();
542 for (TaggingPresetItem i: data) {
543 i.addCommands(result);
544 }
545 return result;
546 }
547
548 /**
549 * Create a command to change the given list of tags.
550 * @param sel The primitives to change the tags for
551 * @param changedTags The tags to change
552 * @return A command that changes the tags.
553 */
554 public static Command createCommand(Collection<OsmPrimitive> sel, List<Tag> changedTags) {
555 List<Command> cmds = new ArrayList<>();
556 for (Tag tag: changedTags) {
557 ChangePropertyCommand cmd = new ChangePropertyCommand(sel, tag.getKey(), tag.getValue());
558 if (cmd.getObjectsNumber() > 0) {
559 cmds.add(cmd);
560 }
561 }
562
563 if (cmds.isEmpty())
564 return null;
565 else if (cmds.size() == 1)
566 return cmds.get(0);
567 else
568 return new SequenceCommand(tr("Change Tags"), cmds);
569 }
570
571 private boolean supportsRelation() {
572 return types == null || types.contains(TaggingPresetType.RELATION);
573 }
574
575 protected final void updateEnabledState() {
576 setEnabled(OsmDataManager.getInstance().getEditDataSet() != null);
577 }
578
579 @Override
580 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
581 updateEnabledState();
582 }
583
584 @Override
585 public String toString() {
586 return (types == null ? "" : types.toString()) + ' ' + name;
587 }
588
589 /**
590 * Determines whether this preset matches the types.
591 * @param t The types that must match
592 * @return <code>true</code> if all types match.
593 */
594 public boolean typeMatches(Collection<TaggingPresetType> t) {
595 return t == null || types == null || types.containsAll(t);
596 }
597
598 /**
599 * Determines whether this preset matches the given primitive, i.e.,
600 * whether the {@link #typeMatches(Collection) type matches} and the {@link TaggingPresetItem#matches(Map) tags match}.
601 *
602 * @param p the primitive
603 * @return {@code true} if this preset matches the primitive
604 * @since 13623 (signature)
605 */
606 @Override
607 public boolean test(IPrimitive p) {
608 return matches(EnumSet.of(TaggingPresetType.forPrimitive(p)), p.getKeys(), false);
609 }
610
611 /**
612 * Determines whether this preset matches the parameters.
613 *
614 * @param t the preset types to include, see {@link #typeMatches(Collection)}
615 * @param tags the tags to perform matching on, see {@link TaggingPresetItem#matches(Map)}
616 * @param onlyShowable whether the preset must be {@link #isShowable() showable}
617 * @return {@code true} if this preset matches the parameters.
618 */
619 public boolean matches(Collection<TaggingPresetType> t, Map<String, String> tags, boolean onlyShowable) {
620 if ((onlyShowable && !isShowable()) || !typeMatches(t)) {
621 return false;
622 } else {
623 return TaggingPresetItem.matches(data, tags);
624 }
625 }
626
627 /**
628 * Action that adds or removes the button on main toolbar
629 */
630 public class ToolbarButtonAction extends AbstractAction {
631 private final int toolbarIndex;
632
633 /**
634 * Constructs a new {@code ToolbarButtonAction}.
635 */
636 public ToolbarButtonAction() {
637 super("");
638 new ImageProvider("dialogs", "pin").getResource().attachImageIcon(this, true);
639 putValue(SHORT_DESCRIPTION, tr("Add or remove toolbar button"));
640 List<String> t = new LinkedList<>(ToolbarPreferences.getToolString());
641 toolbarIndex = t.indexOf(getToolbarString());
642 putValue(SELECTED_KEY, toolbarIndex >= 0);
643 }
644
645 @Override
646 public void actionPerformed(ActionEvent ae) {
647 String res = getToolbarString();
648 MainApplication.getToolbar().addCustomButton(res, toolbarIndex, true);
649 }
650 }
651
652 /**
653 * Gets a string describing this preset that can be used for the toolbar
654 * @return A String that can be passed on to the toolbar
655 * @see ToolbarPreferences#addCustomButton(String, int, boolean)
656 */
657 public String getToolbarString() {
658 ToolbarPreferences.ActionParser actionParser = new ToolbarPreferences.ActionParser(null);
659 return actionParser.saveAction(new ToolbarPreferences.ActionDefinition(this));
660 }
661
662 /**
663 * Returns the completable future task that performs icon loading, if any.
664 * @return the completable future task that performs icon loading, or null
665 * @since 14449
666 */
667 public CompletableFuture<Void> getIconLoadingTask() {
668 return iconFuture;
669 }
670}
Note: See TracBrowser for help on using the repository browser.