001: /*
002: * Gruntspud
003: *
004: * Copyright (C) 2002 Brett Smith.
005: *
006: * Written by: Brett Smith <t_magicthize@users.sourceforge.net>
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public License
010: * as published by the Free Software Foundation; either version 2 of
011: * the License, or (at your option) any later version.
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Library General Public License for more details.
016: *
017: * You should have received a copy of the GNU Library General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: */
021:
022: package gruntspud;
023:
024: import gruntspud.ui.UIUtil;
025:
026: import java.util.HashMap;
027: import java.util.Iterator;
028:
029: import javax.swing.Icon;
030:
031: import org.netbeans.lib.cvsclient.command.KeywordSubstitutionOptions;
032:
033: /**
034: * Description of the Class
035: *
036: *@author magicthize
037: *@created 26 May 2002
038: */
039: public class CVSSubstType implements Comparable {
040: public final static HashMap ALL_TYPES = new HashMap();
041:
042: /**
043: * Description of the Field
044: */
045: public final static CVSSubstType CVS_SUBST_TYPE_DEFAULT_LOCKER = new CVSSubstType(
046: "Default Locker", UIUtil
047: .getCachedIcon(Constants.ICON_TYPE_DEFAULT_LOCKER),
048: KeywordSubstitutionOptions.DEFAULT_LOCKER);
049:
050: /**
051: * Description of the Field
052: */
053: public final static CVSSubstType CVS_SUBST_TYPE_OLD_VALUES = new CVSSubstType(
054: "Old values", UIUtil
055: .getCachedIcon(Constants.ICON_TYPE_OLD_VALUES),
056: KeywordSubstitutionOptions.OLD_VALUES);
057:
058: /**
059: * Description of the Field
060: */
061: public final static CVSSubstType CVS_SUBST_TYPE_ONLY_KEYWORDS = new CVSSubstType(
062: "Only keywords", UIUtil
063: .getCachedIcon(Constants.ICON_TYPE_ONLY_KEYWORDS),
064: KeywordSubstitutionOptions.ONLY_KEYWORDS);
065:
066: /**
067: * Description of the Field
068: */
069: public final static CVSSubstType CVS_SUBST_TYPE_ONLY_VALUES = new CVSSubstType(
070: "Only values", UIUtil
071: .getCachedIcon(Constants.ICON_TYPE_ONLY_VALUES),
072: KeywordSubstitutionOptions.ONLY_VALUES);
073:
074: /**
075: * Description of the Field
076: */
077: public final static CVSSubstType CVS_SUBST_TYPE_TEXT = new CVSSubstType(
078: "Text", UIUtil.getCachedIcon(Constants.ICON_TYPE_TEXT),
079: KeywordSubstitutionOptions.DEFAULT);
080:
081: /**
082: * Description of the Field
083: */
084: public final static CVSSubstType CVS_SUBST_TYPE_BINARY = new CVSSubstType(
085: "Binary", UIUtil.getCachedIcon(Constants.ICON_TYPE_BINARY),
086: KeywordSubstitutionOptions.BINARY);
087:
088: /**
089: * Description of the Field
090: */
091: public final static CVSSubstType CVS_SUBST_TYPE_UNICODE = new CVSSubstType(
092: "Unicode", UIUtil
093: .getCachedIcon(Constants.ICON_TYPE_UNICODE), null);
094:
095: /**
096: * Description of the Field
097: */
098: public final static CVSSubstType CVS_SUBST_TYPE_IGNORED = new CVSSubstType(
099: "Ignored",
100: UIUtil.getCachedIcon(Constants.ICON_TYPE_IGNORE), null);
101:
102: /**
103: * Description of the Field
104: */
105: public final static CVSSubstType CVS_SUBST_TYPE_COPY = new CVSSubstType(
106: "Copy", UIUtil.getCachedIcon(Constants.ICON_TYPE_COPY),
107: null);
108:
109: /**
110: * Description of the Field
111: */
112: public final static CVSSubstType CVS_SUBST_TYPE_DIRECTORY = new CVSSubstType(
113: "Directory", UIUtil
114: .getCachedIcon(Constants.ICON_TYPE_DIRECTORY), null);
115: private String name;
116: private Icon icon;
117: private KeywordSubstitutionOptions keywordSubstitutionOptions;
118:
119: /**
120: * Constructor for the CVSSubstType object
121: *
122: *@param name Description of the Parameter
123: *@param icon Description of the Parameter
124: */
125: private CVSSubstType(String name, Icon icon,
126: KeywordSubstitutionOptions keywordSubstitutionOptions) {
127: this .name = name;
128: this .icon = icon;
129: this .keywordSubstitutionOptions = keywordSubstitutionOptions;
130:
131: if (keywordSubstitutionOptions != null) {
132: ALL_TYPES.put(keywordSubstitutionOptions, this );
133: }
134: }
135:
136: /**
137: * Gets the name attribute of the CVSFileType object
138: *
139: *@return The name value
140: */
141: public String getName() {
142: return name;
143: }
144:
145: /**
146: * Gets the name attribute of the CVSFileType object
147: *
148: *@return The name value
149: */
150: public KeywordSubstitutionOptions getKeywordSubstitutionOptions() {
151: return keywordSubstitutionOptions;
152: }
153:
154: /**
155: * Gets the icon attribute of the CVSFileType object
156: *
157: *@return The icon value
158: */
159: public Icon getIcon() {
160: return icon;
161: }
162:
163: /**
164: * Description of the Method
165: *
166: *@return Description of the Return Value
167: */
168: public String toString() {
169: return getName();
170: }
171:
172: /**
173: * DOCUMENT ME!
174: *
175: * @param s DOCUMENT ME!
176: *
177: * @return DOCUMENT ME!
178: */
179: public static CVSSubstType getSubstTypeForName(String s) {
180: /** @todo was a bad move making ignored a substitution type - change it */
181: if (s.equals(CVSSubstType.CVS_SUBST_TYPE_IGNORED.getName())) {
182: return CVSSubstType.CVS_SUBST_TYPE_IGNORED;
183: }
184:
185: for (Iterator i = ALL_TYPES.values().iterator(); i.hasNext();) {
186: CVSSubstType c = (CVSSubstType) i.next();
187:
188: if (c.getName().equals(s)) {
189: return c;
190: }
191: }
192:
193: return null;
194: }
195:
196: /**
197: * DOCUMENT ME!
198: *
199: * @param s DOCUMENT ME!
200: *
201: * @return DOCUMENT ME!
202: */
203: public static CVSSubstType getSubstTypeForString(String s) {
204: KeywordSubstitutionOptions k = KeywordSubstitutionOptions
205: .findKeywordSubstOption(s.substring(2));
206:
207: return (CVSSubstType) ALL_TYPES.get(k);
208: }
209:
210: /**
211: * DOCUMENT ME!
212: *
213: * @param o DOCUMENT ME!
214: *
215: * @return DOCUMENT ME!
216: */
217: public int compareTo(Object o) {
218: /** @todo make this better */
219: return name.compareTo(((CVSSubstType) o).getName());
220: }
221: }
|