All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.vectorpublish.desktop.vp.ui.ImageKey Maven / Gradle / Ivy

package net.vectorpublish.desktop.vp.ui;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * The key for an image.
 * 

* The imagekey is detached from the plug-in. That means that multiple plug-ins * can have the same imagekey without the same image. This looks like a * misdesign because you may think that if you change the icon of a imagekey you * change the icon of other plug-ins too, this is not correct. The * {@link ImageKey} only shall give a hint that two plug-ins who have different * icons may share the same icon for a simmilar action. */ public class ImageKey { private final static Set KEYS = new LinkedHashSet<>(); public static final String REGEX_PATTERN = "[a-z0-9\\._]+"; public static ImageKey get(String key) { for (final ImageKey imageKey : KEYS) { if (imageKey.key.equals(key)) { return imageKey; } } synchronized (KEYS) { for (final ImageKey imageKey : KEYS) { if (imageKey.key.equals(key)) { return imageKey; } } return new ImageKey(key); } } private final String key; private ImageKey(String key) { this.key = key; if (!key.matches("^" + REGEX_PATTERN + "$")) { throw new IllegalArgumentException("The Key ('" + key + "') must be any lowcase alphanumeric value without spaces but dot and underscore is allowed."); } KEYS.add(this); } public final String getCanonical() { return key; } /** * Please use == instead. * * @see Object#equals(Object) */ @Override @Deprecated public boolean equals(Object obj) { return super.equals(obj); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy