001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * LibProperties.java
044: *
045: */
046:
047: package org.netbeans.test.umllib.util;
048:
049: import java.io.PrintStream;
050: import java.lang.Enum;
051: import java.util.HashMap;
052: import java.util.Iterator;
053: import org.netbeans.test.umllib.DiagramElementOperator;
054: import org.netbeans.test.umllib.ElementTypes;
055: import org.netbeans.test.umllib.ExpandedElementTypes;
056: import org.netbeans.test.umllib.LinkTypes;
057: import org.netbeans.test.umllib.SetName;
058: import org.netbeans.test.umllib.namers.LifelineNamer;
059:
060: /**
061: *
062: * @author Alexei Mokeev
063: */
064: public class LibProperties {
065: private static LibProperties properties = null;;
066: private HashMap<Enum, String> tools = null;
067: private HashMap<Enum, SetName> namers = null;
068: private HashMap<Enum, String> defNames = null;
069: public SetName DEFAULT_NAMER = null;
070: public SetName LABELS_NAMER = null;
071: public SetName LIFELINE_NAMER = null;
072:
073: //
074: public final String COMMON_NEW_ELEMENT_NAME = "Unnamed";
075:
076: /** Creates a new instance of LibProperties */
077: protected LibProperties() {
078: tools = new HashMap<Enum, String>();
079: namers = new HashMap<Enum, SetName>();
080: defNames = new HashMap<Enum, String>();
081: DEFAULT_NAMER = new DiagramElementOperator.DefaultNamer();
082: LABELS_NAMER = new DiagramElementOperator.LabelsNamer();
083: LIFELINE_NAMER = new LifelineNamer();
084:
085: initDefaultToolNames();
086: initDefaultNamers();
087: initDefaultNames();
088: }
089:
090: /**
091: *
092: * @return
093: */
094: public static LibProperties getProperties() {
095: if (properties == null) {
096: properties = new LibProperties();
097: }
098: return properties;
099: }
100:
101: /**
102: *
103: * @param element
104: * @return
105: */
106: public static String getCurrentToolName(Enum element) {
107: return getProperties().getToolName(element);
108: }
109:
110: /**
111: *
112: * @param element
113: * @return
114: */
115: public static SetName getCurrentNamer(Enum element) {
116: return getProperties().getNamer(element);
117: }
118:
119: /**
120: *
121: * @param element
122: * @return
123: */
124: public static String getCurrentDefaultName(Enum element) {
125: return getProperties().getDefaultName(element);
126: }
127:
128: protected void initDefaultToolNames() {
129: setToolName(ElementTypes.CLASS, "Class");
130: setToolName(ElementTypes.INTERFACE, "Interface");
131: setToolName(ElementTypes.ARTIFACT, "Artifact");
132: setToolName(ElementTypes.ALIASED, "Aliased");
133: setToolName(ElementTypes.COMPONENT, "Component");
134: setToolName(ElementTypes.PACKAGE, "Package");
135: setToolName(ElementTypes.DEPLOYMENT_SPECIFICATION,
136: "Deployment Specification");
137: setToolName(ElementTypes.BOUNDARY_CLASS, "Boundary Class");
138: setToolName(ElementTypes.CONTROL_CLASS, "Control Class");
139: setToolName(ElementTypes.ENTITY_CLASS, "Entity Class");
140: setToolName(ElementTypes.ENUMERATION, "Enumeration");
141: setToolName(ElementTypes.ASSEMBLY_CONNECTOR,
142: "Assembly Connector");
143: setToolName(ElementTypes.NODE, "Node");
144: setToolName(ElementTypes.DATATYPE, "Datatype");
145: setToolName(ElementTypes.UTILITY_CLASS, "Utility Class");
146: setToolName(ElementTypes.ACTOR_ROLE, "Actor Role");
147: setToolName(ElementTypes.USE_CASE, "Use Case");
148: setToolName(ElementTypes.ACTOR_LIFELINE, "Actor");
149: setToolName(ElementTypes.LIFELINE, "Lifeline");
150: setToolName(ElementTypes.ACTOR, "Actor");
151: setToolName(ElementTypes.COLLABORATION_LIFELINE,
152: "Collaboration Lifeline");
153: setToolName(ElementTypes.COMMENT, "Comment");
154: setToolName(ElementTypes.LINK_COMMENT, "Link Comment");
155: setToolName(ElementTypes.INVOCATION, "Invocation");
156: setToolName(ElementTypes.DECISION, "Decision");
157: setToolName(ElementTypes.VERTICAL_FORK, "Vertical Fork");
158: setToolName(ElementTypes.HORIZONTAL_FORK, "Horizontal Fork");
159: setToolName(ElementTypes.ACTIVITY_GROUP, "Activity Group");
160: setToolName(ElementTypes.INITIAL_NODE, "Initial Node");
161: setToolName(ElementTypes.ACTIVITY_FINAL_NODE,
162: "Activity Final Node");
163: setToolName(ElementTypes.FLOW_FINAL, "Flow Final");
164: setToolName(ElementTypes.PARAMETER_USAGE, "Parameter Usage");
165: setToolName(ElementTypes.DATA_STORE, "Data Store");
166: setToolName(ElementTypes.SIGNAL, "Signal");
167: setToolName(ElementTypes.PARTITION, "Partition");
168: setToolName(ElementTypes.CREATE_MESSAGE, "Create Message");
169: setToolName(ElementTypes.COMBINED_FRAGMENT, "Combined Fragment");
170: setToolName(ElementTypes.TEMPLATE_CLASS, "Template Class");
171: setToolName(ElementTypes.DERIVATION_CLASSIFIER,
172: "Derivation Classifier");
173: setToolName(ElementTypes.DESIGN_PATTERN, "Design Pattern");
174: setToolName(ElementTypes.ROLE, "Role");
175: setToolName(ElementTypes.INTERFACE_ROLE, "Interface Role");
176: setToolName(ElementTypes.CLASS_ROLE, "Class Role");
177: setToolName(ElementTypes.USE_CASE_ROLE, "Use Case Role");
178: setToolName(ElementTypes.ROLE_BINDING, "Role Binding");
179:
180: setToolName(ElementTypes.SUBMACHINE_STATE, "Submachine State");
181: setToolName(ElementTypes.JUNCTION_POINT_STATE, "Junction State");
182: setToolName(ElementTypes.ENTRY_POINT_STATE, "Entry Point State");
183: setToolName(ElementTypes.DEEP_HISTORY_STATE,
184: "Deep History State");
185: setToolName(ElementTypes.SHALLOW_HISTORY_STATE,
186: "Shallow History State");
187: setToolName(ElementTypes.CHOICE_PSEUDO_STATE,
188: "Choice Pseudo State");
189: setToolName(ElementTypes.COMPOSITE_STATE, "Composite State");
190: setToolName(ElementTypes.HORIZONTAL_JOIN_MERGE,
191: "Horizontal Join/Merge");
192: setToolName(ElementTypes.VERTICAL_JOIN_MERGE,
193: "Vertical Join/Merge");
194: setToolName(ElementTypes.ABORTED_FINAL_STATE,
195: "Aborted Final State");
196: setToolName(ElementTypes.FINAL_STATE, "Final State");
197: setToolName(ElementTypes.INITIAL_STATE, "Initial State");
198: setToolName(ElementTypes.SIMPLE_STATE, "Simple State");
199:
200: //expanded
201: setToolName(ExpandedElementTypes.CLASS, "Class");
202: setToolName(ExpandedElementTypes.INTERFACE, "Interface");
203: setToolName(ExpandedElementTypes.ARTIFACT, "Artifact");
204: setToolName(ExpandedElementTypes.ALIASED, "Aliased");
205: setToolName(ExpandedElementTypes.COMPONENT, "Component");
206: setToolName(ExpandedElementTypes.PACKAGE, "Package");
207: //setToolName(ExpandedElementTypes.DEPLOYMENT_SPECIFICATION, "Deployment Specification");
208: setToolName(ExpandedElementTypes.BOUNDARY_CLASS,
209: "Boundary Class");
210: setToolName(ExpandedElementTypes.CONTROL_CLASS, "Control Class");
211: setToolName(ExpandedElementTypes.ENTITY_CLASS, "Entity Class");
212: setToolName(ExpandedElementTypes.ENUMERATION, "Enumeration");
213: setToolName(ExpandedElementTypes.ASSEMBLY_CONNECTOR,
214: "Assembly Connector");
215: setToolName(ExpandedElementTypes.NODE, "Node");
216: setToolName(ExpandedElementTypes.DATATYPE, "Datatype");
217: setToolName(ExpandedElementTypes.UTILITY_CLASS, "Utility Class");
218: setToolName(ExpandedElementTypes.ACTOR_ROLE, "Actor Role");
219: setToolName(ExpandedElementTypes.USE_CASE, "Use Case");
220: setToolName(ExpandedElementTypes.ACTOR_LIFELINE, "Actor");
221: setToolName(ExpandedElementTypes.LIFELINE, "Lifeline");
222: setToolName(ExpandedElementTypes.ACTOR, "Actor");
223: setToolName(ExpandedElementTypes.COLLABORATION_LIFELINE,
224: "Collaboration Lifeline");
225: setToolName(ExpandedElementTypes.COMMENT, "Comment");
226: setToolName(ExpandedElementTypes.LINK_COMMENT, "Link Comment");
227: //setToolName(ExpandedElementTypes.INVOCATION, "Invocation");
228: //setToolName(ExpandedElementTypes.DECISION, "Decision");
229: //setToolName(ExpandedElementTypes.VERTICAL_FORK, "Vertical Fork");
230: //setToolName(ExpandedElementTypes.HORIZONTAL_FORK, "Horizontal Fork");
231: setToolName(ExpandedElementTypes.ACTIVITY_GROUP,
232: "Activity Group");
233: //setToolName(ExpandedElementTypes.INITIAL_NODE, "Initial Node");
234: //setToolName(ExpandedElementTypes.ACTIVITY_FINAL_NODE, "Activity Final Node");
235: //setToolName(ExpandedElementTypes.FLOW_FINAL, "Flow Final");
236: //setToolName(ExpandedElementTypes.PARAMETER_USAGE, "Parameter Usage");
237: //setToolName(ExpandedElementTypes.DATA_STORE, "Data Store");
238: //setToolName(ExpandedElementTypes.SIGNAL, "Signal");
239: //setToolName(ExpandedElementTypes.PARTITION, "Partition");
240: //setToolName(ExpandedElementTypes.CREATE_MESSAGE, "Create Message");
241: //setToolName(ExpandedElementTypes.COMBINED_FRAGMENT, "Combined Fragment");
242: setToolName(ExpandedElementTypes.TEMPLATE_CLASS,
243: "Template Class");
244: setToolName(ExpandedElementTypes.DERIVATION_CLASSIFIER,
245: "Derivation Classifier");
246: setToolName(ExpandedElementTypes.DESIGN_PATTERN,
247: "Design Pattern");
248: setToolName(ExpandedElementTypes.ROLE, "Role");
249: setToolName(ExpandedElementTypes.INTERFACE_ROLE,
250: "Interface Role");
251: setToolName(ExpandedElementTypes.CLASS_ROLE, "Class Role");
252: setToolName(ExpandedElementTypes.USE_CASE_ROLE, "Use Case Role");
253: setToolName(ExpandedElementTypes.ROLE_BINDING, "Role Binding");
254:
255: //setToolName(ExpandedElementTypes.SUBMACHINE_STATE, "Submachine State");
256: //setToolName(ExpandedElementTypes.JUNCTION_POINT_STATE, "Junction State");
257: //setToolName(ExpandedElementTypes.ENTRY_POINT_STATE, "Entry Point State");
258: //setToolName(ExpandedElementTypes.DEEP_HISTORY_STATE, "Deep History State");
259: //setToolName(ExpandedElementTypes.SHALLOW_HISTORY_STATE, "Shallow History State");
260: //setToolName(ExpandedElementTypes.CHOICE_PSEUDO_STATE, "Choice Pseudo State");
261: //setToolName(ExpandedElementTypes.COMPOSITE_STATE, "Composite State");
262: //setToolName(ExpandedElementTypes.HORIZONTAL_JOIN_MERGE, "Horizontal Join/Merge");
263: //setToolName(ExpandedElementTypes.VERTICAL_JOIN_MERGE, "Vertical Join/Merge");
264: //setToolName(ExpandedElementTypes.ABORTED_FINAL_STATE, "Aborted Final State");
265: //setToolName(ExpandedElementTypes.FINAL_STATE, "Final State");
266: //setToolName(ExpandedElementTypes.INITIAL_STATE, "Initial State");
267: //setToolName(ExpandedElementTypes.SIMPLE_STATE, "Simple State");
268: //
269:
270: setToolName(LinkTypes.DEPENDENCY, "Dependency");
271: setToolName(LinkTypes.PERMISSION, "Permission");
272: setToolName(LinkTypes.ASSOCIATION, "Association");
273: setToolName(LinkTypes.NAVIGABLE_ASSOCIATION,
274: "Navigable Association");
275: setToolName(LinkTypes.COMPOSITION, "Composition");
276: setToolName(LinkTypes.NAVIGABLE_COMPOSITION,
277: "Navigable Composition");
278: setToolName(LinkTypes.AGGREGATION, "Aggregation");
279: setToolName(LinkTypes.NAVIGABLE_AGGREGATION,
280: "Navigable Aggregation");
281: setToolName(LinkTypes.ASSOCIATION_CLASS, "Association Class");
282: setToolName(LinkTypes.GENERALIZATION, "Generalization");
283: setToolName(LinkTypes.IMPLEMENTATION, "Implementation");
284: setToolName(LinkTypes.NESTED_LINK, "Nested Link");
285: setToolName(LinkTypes.REALIZE, "Realize");
286: setToolName(LinkTypes.USAGE, "Usage");
287: setToolName(LinkTypes.ABSTRACTION, "Abstraction");
288: setToolName(LinkTypes.PACKAGE, "Nested Link");
289: setToolName(LinkTypes.DERIVATION_EDGE, "Derivation Edge");
290: setToolName(LinkTypes.DELEGATE, "Delegate");
291: setToolName(LinkTypes.ASSEMBLY, "Assembly Connector");
292: setToolName(LinkTypes.ACTIVITY_EDGE, "Activity Edge");
293: setToolName(LinkTypes.CONNECTOR, "Connector");
294: setToolName(LinkTypes.SYNC_MESSAGE, "Synchronous Message");
295: setToolName(LinkTypes.ASYNC_MESSAGE, "Asynchronous Message");
296: setToolName(LinkTypes.MESSAGE_TO_SELF, "Message To Self");
297: setToolName(LinkTypes.CREATE_MESSAGE, "Create Message");
298: setToolName(LinkTypes.ROLE, "Role Binding");
299: setToolName(LinkTypes.ROLE_BINDING, "Role Binding");
300: setToolName(LinkTypes.INCLUDE, "Include");
301: setToolName(LinkTypes.EXTEND, "Extend");
302: setToolName(LinkTypes.COMMENT, "Link Comment");
303: }
304:
305: protected void initDefaultNamers() {
306: setNamer(ElementTypes.DECISION, LABELS_NAMER);
307: setNamer(ElementTypes.VERTICAL_FORK, LABELS_NAMER);
308: setNamer(ElementTypes.HORIZONTAL_FORK, LABELS_NAMER);
309: setNamer(ElementTypes.INITIAL_NODE, LABELS_NAMER);
310: setNamer(ElementTypes.ACTIVITY_FINAL_NODE, LABELS_NAMER);
311: setNamer(ElementTypes.FLOW_FINAL, LABELS_NAMER);
312: setNamer(ElementTypes.LIFELINE, LIFELINE_NAMER);
313: setNamer(ElementTypes.COLLABORATION_LIFELINE, LIFELINE_NAMER);
314: setNamer(ElementTypes.ACTOR_LIFELINE, LIFELINE_NAMER);
315:
316: }
317:
318: //
319: protected void initDefaultNames() {
320: setDefaultName(ElementTypes.COMMENT, "");
321: setDefaultName(ElementTypes.LINK_COMMENT, "");
322: setDefaultName(ElementTypes.PORT, "");
323:
324: setDefaultName(ExpandedElementTypes.COMMENT, "");
325: setDefaultName(ExpandedElementTypes.LINK_COMMENT, "");
326: setDefaultName(ExpandedElementTypes.PORT, "");
327: }
328:
329: /**
330: *
331: * @param element
332: * @param toolTip
333: * @return
334: */
335: public String setToolName(Enum element, String toolTip) {
336: return (String) tools.put(element, toolTip);
337: }
338:
339: /**
340: *
341: * @param element
342: * @return
343: */
344: public String getToolName(Enum element) {
345: return (String) tools.get(element);
346: }
347:
348: /**
349: *
350: * @param element
351: * @return
352: */
353: public SetName getNamer(Enum element) {
354: SetName namer = null;
355: try {
356: namer = namers.get(element);
357: if (namer == null) {
358: namer = DEFAULT_NAMER;
359: }
360: } catch (Exception e) {
361: }
362: ;
363: return namer;
364: }
365:
366: /**
367: *
368: * @param element
369: * @param obj
370: * @return
371: */
372: public SetName setNamer(Enum element, SetName obj) {
373: return (SetName) namers.put(element, obj);
374: }
375:
376: private void setDefaultName(Enum element, String defName) {
377: defNames.put(element, defName);
378: }
379:
380: /**
381: * get Default or initial name with standart uml options
382: * @param element
383: * @return
384: */
385: public String getDefaultName(Enum element) {
386: String ret = null;
387: try {
388: ret = defNames.get(element);
389: if (ret == null) {
390: if (element instanceof LinkTypes)
391: ret = "";
392: else
393: ret = COMMON_NEW_ELEMENT_NAME;
394: }
395: } catch (Exception e) {
396: }
397: ;
398: return ret;
399:
400: }
401: }
|