001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.uml;
053:
054: import java.awt.Color;
055: import org.acm.seguin.summary.Summary;
056: import org.acm.seguin.summary.FieldSummary;
057: import org.acm.seguin.summary.TypeSummary;
058: import org.acm.seguin.summary.TypeDeclSummary;
059: import org.acm.seguin.uml.line.DragPanelAdapter;
060: import org.acm.seguin.summary.query.GetTypeSummary;
061: import net.sourceforge.jrefactory.ast.ModifierHolder;
062:
063: /**
064: * Displays a single UML field in a line
065: *
066: *@author Chris Seguin
067: *@created July 6, 1999
068: */
069: public class UMLField extends UMLLine implements ISourceful {
070: private FieldSummary summary;
071: private UMLPackage current;
072: private boolean association;
073: private DragPanelAdapter parentDragAdapter;
074: private DragPanelAdapter fieldDragAdapter;
075:
076: /**
077: * Create a new instance of a UMLLine
078: *
079: *@param initCurrent Description of Parameter
080: *@param parent Description of Parameter
081: *@param field Description of Parameter
082: *@param adapter Description of Parameter
083: */
084: public UMLField(UMLPackage initCurrent, UMLType parent,
085: FieldSummary field, DragPanelAdapter adapter) {
086: super (parent, adapter);
087:
088: // Set the instance variables
089: summary = field;
090: current = initCurrent;
091: association = false;
092:
093: // Reset the parent data
094: //ModifierHolder modifiers = summary.getModifiers();
095: //setProtection(UMLLine.getProtectionCode(modifiers));
096: setProtection(UMLLine.getProtectionCode(summary));
097: setLabelText(summary.toString());
098: setLabelFont(UMLLine.getProtectionFont(false, summary));
099:
100: // Reset the size
101: setSize(getPreferredSize());
102:
103: // Create another adapter for draging this
104: parentDragAdapter = adapter;
105: fieldDragAdapter = new DragPanelAdapter(this , initCurrent);
106:
107: // Add a mouse listener
108: addMouseListener(new UMLMouseAdapter(current, parent, this ));
109: }
110:
111: /**
112: * Transform into an association
113: *
114: *@param way Description of Parameter
115: */
116: public void setAssociation(boolean way) {
117: association = way;
118: if (association) {
119: setLabelText(summary.getName());
120: addMouseListener(fieldDragAdapter);
121: addMouseMotionListener(fieldDragAdapter);
122: removeMouseListener(parentDragAdapter);
123: removeMouseMotionListener(parentDragAdapter);
124: label.addMouseListener(fieldDragAdapter);
125: label.addMouseMotionListener(fieldDragAdapter);
126: label.removeMouseListener(parentDragAdapter);
127: label.removeMouseMotionListener(parentDragAdapter);
128: } else {
129: setLabelText(summary.toString());
130: addMouseListener(parentDragAdapter);
131: addMouseMotionListener(parentDragAdapter);
132: removeMouseListener(fieldDragAdapter);
133: removeMouseMotionListener(fieldDragAdapter);
134: label.addMouseListener(parentDragAdapter);
135: label.addMouseMotionListener(parentDragAdapter);
136: label.removeMouseListener(fieldDragAdapter);
137: label.removeMouseMotionListener(fieldDragAdapter);
138: }
139:
140: setSize(getPreferredSize());
141: }
142:
143: /**
144: * Return the summary
145: *
146: *@return Description of the Returned Value
147: */
148: public FieldSummary getSummary() {
149: return summary;
150: }
151:
152: /**
153: * Is this object represented as an association
154: *
155: *@return Description of the Returned Value
156: */
157: public boolean isAssociation() {
158: return association;
159: }
160:
161: /**
162: * Is this object represented as an association
163: *
164: *@return Description of the Returned Value
165: */
166: public boolean isConvertable() {
167: TypeDeclSummary typeDecl = summary.getTypeDecl();
168: if (typeDecl.isPrimitive()) {
169: return false;
170: }
171:
172: TypeSummary typeSummary = GetTypeSummary.query(typeDecl);
173: return (typeSummary != null);
174: }
175:
176: /**
177: * Description of the Method
178: *
179: *@return Description of the Returned Value
180: */
181: public TypeSummary getType() {
182: TypeDeclSummary typeDecl = summary.getTypeDecl();
183: return GetTypeSummary.query(typeDecl);
184: }
185:
186: /**
187: * Return the default background color
188: *
189: *@return the color
190: */
191: protected Color getDefaultBackground() {
192: if (association) {
193: return Color.lightGray;
194: } else {
195: return super .getDefaultBackground();
196: }
197: }
198:
199: /**
200: * Gets the sourceSummary attribute of the UMLField object
201: *
202: *@return The sourceSummary value
203: */
204: public Summary getSourceSummary() {
205: return summary;
206: }
207: }
|