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: package org.netbeans.modules.uml.ui.products.ad.compartments.sequencediagram;
043:
044: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
045: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
046: import org.netbeans.modules.uml.core.metamodel.core.primitivetypes.IMessageKind;
047: import org.netbeans.modules.uml.core.metamodel.dynamics.ILifeline;
048: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
049: import org.netbeans.modules.uml.core.support.umlsupport.IETPoint;
050: import org.netbeans.modules.uml.core.support.umlsupport.IETRect;
051: import org.netbeans.modules.uml.core.support.umlsupport.IETSize;
052: import org.netbeans.modules.uml.ui.controls.drawingarea.DiagramAreaEnumerations;
053: import org.netbeans.modules.uml.ui.products.ad.compartments.ETClassNameCompartment;
054: import org.netbeans.modules.uml.ui.products.ad.diagramengines.sequencediagram.ILifelineDrawEngine;
055: import org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation;
056: import org.netbeans.modules.uml.ui.support.applicationmanager.MoveToFlags;
057: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine;
058: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo;
059: import org.netbeans.modules.uml.ui.support.viewfactorysupport.INotificationTargets;
060: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ModelElementChangedKind;
061: import org.netbeans.modules.uml.ui.support.viewfactorysupport.PresentationHelper;
062: import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
063: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
064: import org.netbeans.modules.uml.ui.swing.trackbar.JTrackBar;
065: import com.tomsawyer.drawing.TSConnector;
066: import com.tomsawyer.editor.TSEConnector;
067:
068: /**
069: *
070: * @author Trey Spiva
071: */
072: public class ETLifelineNameCompartment extends ETClassNameCompartment
073: implements ILifelineNameCompartment, IConnectorsCompartment {
074: private String m_RepresentingMetaType = "";
075:
076: public ETLifelineNameCompartment() {
077: setName(" : ");
078: }
079:
080: /* (non-Javadoc)
081: * @see org.netbeans.modules.uml.ui.products.ad.compartments.ILifelineNameCompartment#setRepresentsMetaType(java.lang.String)
082: */
083: public void setRepresentsMetaType(String value) {
084: m_RepresentingMetaType = value;
085: }
086:
087: /* (non-Javadoc)
088: * @see org.netbeans.modules.uml.ui.products.ad.compartments.ILifelineNameCompartment#getRepresentsMetaType()
089: */
090: public String getRepresentsMetaType() {
091: return m_RepresentingMetaType;
092: }
093:
094: /* (non-Javadoc)
095: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment#getCompartmentID()
096: */
097: public String getCompartmentID() {
098: return "LifelineNameCompartment";
099: }
100:
101: /**
102: * Calculates the "best" size for this compartment. The calculation sets
103: * the member variable GetCachedOptimumSize(), which represents the "best"
104: * size of the compartment at 100%.
105: *
106: * @param pDrawInfo The draw information.
107: * @param bAt100Pct nX,nY is either in current zoom or 100% based on this
108: * flag. If bAt100Pct then it's at 100%
109: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment#calculateOptimumSize(org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo, boolean)
110: */
111: public IETSize calculateOptimumSize(IDrawInfo pDrawInfo,
112: boolean bAt100Pct) {
113: // Apply the scale at the end.
114: IETSize retVal = super .calculateOptimumSize(pDrawInfo, true);
115:
116: // might be zero if we're hidden or no name set
117: IETSize cachedSize = getCachedOptimumSize();
118: if ((cachedSize != null) && (cachedSize.getWidth() > 0)
119: && (cachedSize.getHeight() > 0)) {
120: // Fix W1841: Increase the size of the lifeline name compartment
121: // Careful, increasing these values may corrupt the sequence diagram
122: // generation process.
123: int w = cachedSize.getWidth() + 4;
124: int h = cachedSize.getHeight() + 4;
125:
126: // Fix W1827: make sure the lifeline head's width is at least twice
127: // the height
128: w = Math.max(w, h * 2);
129:
130: cachedSize.setSize(w, h);
131: internalSetOptimumSize(cachedSize);
132: }
133:
134: return bAt100Pct ? m_cachedOptimumSize : scaleSize(
135: m_cachedOptimumSize, pDrawInfo != null ? pDrawInfo
136: .getTSTransform() : getTransform());
137: }
138:
139: /* (non-Javadoc)
140: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment#modelElementHasChanged(org.netbeans.modules.uml.ui.support.viewfactorysupport.INotificationTargets)
141: */
142: public long modelElementHasChanged(INotificationTargets pTargets) {
143: long retVal = 0;
144:
145: IElement modelElement = null;
146: if (pTargets != null) {
147: int kind = pTargets.getKind();
148: if ((kind == ModelElementChangedKind.MECK_NAMEMODIFIED)
149: || (kind == ModelElementChangedKind.MECK_REPRESENTINGCLASSIFIERCHANGED)
150: || (kind == ModelElementChangedKind.MECK_ALIASNAMEMODIFIED)) {
151: modelElement = pTargets.getChangedModelElement();
152: }
153: }
154:
155: boolean isLifeline = (modelElement instanceof ILifeline);
156: boolean isClassifier = (modelElement instanceof IClassifier);
157:
158: if ((isLifeline == true) || (isClassifier == true)) {
159: reattach();
160:
161: // Update the diagram's trackbar, and the draw engine's size
162: IDrawEngine engine = getEngine();
163: if (engine != null) {
164: engine.sizeToContents();
165: IPresentationElement element = TypeConversions
166: .getPresentationElement(engine);
167:
168: IDrawingAreaControl ctrl = getDrawingArea();
169: if (ctrl != null) {
170: ctrl
171: .postSimplePresentationDelayedAction(
172: element,
173: DiagramAreaEnumerations.SPAK_UPDATE_TRACKBAR);
174: ctrl.postSimplePresentationDelayedAction(element,
175: DiagramAreaEnumerations.SPAK_VALIDATENODE);
176: }
177:
178: }
179: }
180:
181: return retVal;
182: }
183:
184: //**************************************************
185: // IConnectorsCompartment implementation
186: //**************************************************
187:
188: /**
189: * Indicates that a message edge can be started from the current logical location.
190: *
191: * @param ptLogical[in] Logical view coordinates to test
192: * @return TRUE if the location is a place where a message can be started
193: */
194: public boolean canStartMessage(IETPoint ptLogical) {
195: return false;
196: }
197:
198: /**
199: * Indicates that a message edge can be finished from the current logical location.
200: *
201: * @param ptLogical[in] Logical view coordinates to test
202: * @return TRUE if the location is a place where a message can be finished
203: */
204: public boolean canFinishMessage(IETPoint ptLogical) {
205: return true;
206: }
207:
208: /* (non-Javadoc)
209: * @see org.netbeans.modules.uml.ui.products.ad.compartments.IConnectorsCompartment#connectMessage(org.netbeans.modules.uml.core.support.umlsupport.IETPoint, int, int)
210: */
211: public TSEConnector connectMessage(IETPoint pPoint, int kind,
212: int connectMessageKind, TSEConnector connector) {
213: if (IMessageKind.MK_CREATE == kind) {
214: // TODO: handle the create message
215: } else if (m_engine != null) {
216: IADLifelineCompartment cpLifelineCompartment = (IADLifelineCompartment) TypeConversions
217: .getCompartment(m_engine,
218: IADLifelineCompartment.class);
219: if (cpLifelineCompartment instanceof IConnectorsCompartment) {
220: IConnectorsCompartment connectorsCompartment = (IConnectorsCompartment) cpLifelineCompartment;
221:
222: connector = connectorsCompartment.connectMessage(
223: pPoint, kind, connectMessageKind, connector);
224: }
225: }
226:
227: return connector;
228: }
229:
230: /* (non-Javadoc)
231: * @see org.netbeans.modules.uml.ui.products.ad.compartments.IConnectorsCompartment#updateConnectors(org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo)
232: */
233: public void updateConnectors(IDrawInfo pDrawInfo) {
234: if (m_engine instanceof ILifelineDrawEngine) {
235: ILifelineDrawEngine lifelineDE = (ILifelineDrawEngine) m_engine;
236: if (lifelineDE != null) {
237: TSConnector cpDEConnector = lifelineDE
238: .getConnectorForCreateMessage();
239: if (cpDEConnector != null) {
240: // Determine the connector on the other end of the edge
241: TSConnector cpOtherConnector = PresentationHelper
242: .getConnectorOnOtherEndOfEdge(
243: cpDEConnector, false);
244: if (cpOtherConnector != null) {
245: double y = cpOtherConnector.getCenterY();
246: moveConnector(cpDEConnector, y, false, false);
247: }
248: }
249: }
250: }
251: }
252:
253: /* (non-Javadoc)
254: * @see org.netbeans.modules.uml.ui.products.ad.compartments.IConnectorsCompartment#moveConnector(com.tomsawyer.editor.TSEConnector, double, boolean, boolean)
255: */
256: public void moveConnector(TSConnector connector, double nY,
257: boolean bDoItNow, boolean bSetYOfAssociatedPiece) {
258: // The only connector that will be attached to the lifeline name compartment is the create message.
259: // Therefore, just move the lifeline itself.
260:
261: final double lDy = nY - connector.getCenterY();
262: if (Math.abs(lDy) > 0.5) {
263: if (m_engine != null) {
264: IPresentationElement presentationElement = TypeConversions
265: .getPresentationElement(m_engine);
266: if (presentationElement instanceof INodePresentation) {
267: INodePresentation nodePresentation = (INodePresentation) presentationElement;
268:
269: IETRect rectBounding = TypeConversions
270: .getLogicalBoundingRect(nodePresentation);
271:
272: final int lNewY = (int) (rectBounding.getCenterY() + lDy);
273: nodePresentation
274: .moveTo(
275: 0,
276: lNewY,
277: (int) (MoveToFlags.MTF_MOVEY | MoveToFlags.MTF_LOGICALCOORD));
278: }
279: }
280: }
281: }
282:
283: }
|