001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.soa.ui.axinodes;
021:
022: import java.awt.Image;
023: import java.util.HashMap;
024: import java.util.Map;
025: import org.openide.util.NbBundle;
026: import org.openide.util.Utilities;
027:
028: /**
029: * @author nk160297
030: */
031: public enum NodeType {
032: UNKNOWN_TYPE, // Special element which means that the value isn't known.
033: ELEMENT, ATTRIBUTE, COMPOSITOR;
034:
035: public static enum BadgeModificator {
036: SINGLE, OPTIONAL, REPEATING, OPTIONAL_REPEATING;
037: }
038:
039: private static final String IMAGE_FOLDER_NAME = "org/netbeans/modules/soa/ui/axinodes/images/"; // NOI18N
040:
041: private String myDisplayName;
042: private String myHelpId;
043: private Map<BadgeModificator, Image> myImageMap;
044:
045: /**
046: * This image is used as the default for types which hasn't icon provided.
047: * It is public to be able to check if the image is provided.
048: */
049: public static final Image UNKNOWN_IMAGE = getImageImpl(
050: UNKNOWN_TYPE, null);
051:
052: public synchronized String getDisplayName() {
053: if (myDisplayName == null) {
054: try {
055: myDisplayName = NbBundle.getMessage(NodeType.class,
056: this .toString());
057: } catch (Exception ex) {
058: myDisplayName = name();
059: }
060: }
061: return myDisplayName;
062: }
063:
064: public String getHelpId() {
065: if (myHelpId == null) {
066: myHelpId = getClass().getName() + "." + this .toString(); // NOI18N
067: }
068: return myHelpId;
069: }
070:
071: public Image getImage(BadgeModificator mult) {
072: if (mult == null) {
073: mult = BadgeModificator.SINGLE;
074: }
075: synchronized (this ) {
076: Image image = getImageMap().get(mult);
077: if (image == null) {
078: image = getImageImpl(this , mult);
079: if (image == null) {
080: image = UNKNOWN_IMAGE;
081: }
082: //
083: getImageMap().put(mult, image);
084: }
085: return image;
086: }
087: }
088:
089: private Map<BadgeModificator, Image> getImageMap() {
090: if (myImageMap == null) {
091: myImageMap = new HashMap<BadgeModificator, Image>();
092: }
093: return myImageMap;
094: }
095:
096: /**
097: * Modificator allows having more then one icon associated with a Node Type
098: */
099: private static Image getImageImpl(Object name, BadgeModificator mult) {
100: String fileName = null;
101: if (mult == null || mult == BadgeModificator.SINGLE) {
102: fileName = IMAGE_FOLDER_NAME + name + ".png"; // NOI18N
103: } else {
104: fileName = IMAGE_FOLDER_NAME + name + "_" + mult + ".png"; // NOI18N
105: }
106: return Utilities.loadImage(fileName);
107: }
108: }
|