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.support.applicationmanager;
043:
044: import org.netbeans.modules.uml.ui.products.ad.viewfactory.IETGraphObjectUI;
045: import java.util.List;
046:
047: import org.dom4j.Document;
048: import org.dom4j.Node;
049:
050: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
051: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
052: import org.netbeans.modules.uml.core.support.umlsupport.IETPoint;
053: import org.netbeans.modules.uml.core.support.umlsupport.ETPoint;
054: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment;
055: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine;
056: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
057: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETLabel;
058: import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
059: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
060: import com.tomsawyer.drawing.TSLabel;
061: import com.tomsawyer.editor.TSENodeLabel;
062: import com.tomsawyer.editor.TSEConnectorLabel;
063: import com.tomsawyer.editor.TSEEdgeLabel;
064: import com.tomsawyer.editor.TSEObjectUI;
065: import com.tomsawyer.editor.TSEGraphWindow;
066: import com.tomsawyer.editor.TSEObject;
067: import com.tomsawyer.editor.ui.TSELabelUI;
068: import com.tomsawyer.graph.TSGraphObject;
069:
070: public class LabelPresentation extends GraphPresentation implements
071: ILabelPresentation {
072:
073: /// flag indicated if the element should be deleted if not edited
074: boolean m_bDeleteIfNotEdited = false;
075:
076: /**
077: *
078: */
079: public LabelPresentation() {
080: super ();
081: }
082:
083: /* (non-Javadoc)
084: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#getETLabel()
085: */
086: public IETLabel getETLabel() {
087: return getETGraphObject() instanceof IETLabel ? (IETLabel) getETGraphObject()
088: : null;
089: }
090:
091: /* (non-Javadoc)
092: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#getLabelView()
093: */
094: public TSELabelUI getLabelView() {
095: return this .getUI() instanceof TSELabelUI ? (TSELabelUI) this
096: .getUI() : null;
097: }
098:
099: private TSLabel mLabel = null;
100:
101: /* (non-Javadoc)
102: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#getTSLabel()
103: */
104: public TSLabel getTSLabel() {
105: return mLabel;
106: }
107:
108: /* (non-Javadoc)
109: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#setTSLabel(com.tomsawyer.drawing.TSLabel)
110: */
111: public void setTSLabel(TSLabel value) {
112: mLabel = value;
113: }
114:
115: public IETGraphObjectUI getUI() {
116: TSLabel label = getTSLabel();
117: IETGraphObjectUI retVal = null;
118:
119: TSEObjectUI ui = null;
120: if (label instanceof TSEEdgeLabel) {
121: TSEEdgeLabel edgeLabel = (TSEEdgeLabel) label;
122: ui = edgeLabel.getUI();
123: } else if (label instanceof TSENodeLabel) {
124: TSENodeLabel edgeLabel = (TSENodeLabel) label;
125: ui = edgeLabel.getUI();
126: } else if (label instanceof TSEConnectorLabel) {
127: TSEConnectorLabel edgeLabel = (TSEConnectorLabel) label;
128: ui = edgeLabel.getUI();
129: }
130:
131: if (ui instanceof IETGraphObjectUI) {
132: retVal = (IETGraphObjectUI) ui;
133: }
134:
135: return retVal;
136: }
137:
138: /* (non-Javadoc)
139: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#invalidate()
140: */
141: public void invalidate() {
142: TSLabel label = getTSLabel();
143: IDrawEngine engine = getDrawEngine();
144: if (label != null && engine != null) {
145:
146: IDrawingAreaControl ctrl = engine.getDrawingArea();
147:
148: TSEGraphWindow window = ctrl.getGraphWindow();
149: if (window != null) {
150: window.addInvalidRegion((TSEObject) label);
151: }
152: }
153:
154: }
155:
156: /* (non-Javadoc)
157: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#beginEdit()
158: */
159: public long beginEdit() {
160:
161: IDrawEngine pDE = this .getDrawEngine();
162:
163: if (pDE != null) {
164:
165: int count = 0;
166:
167: List pCompartments = pDE.getCompartments();
168:
169: if (pCompartments != null) {
170: count = pCompartments.size();
171: }
172: if (count > 0) {
173: ICompartment pFirstCompartment = (ICompartment) pCompartments
174: .get(0);
175:
176: if (pFirstCompartment != null) {
177: int tempShort = 0;
178: setSelected(true);
179: pFirstCompartment.editCompartment(
180: m_bDeleteIfNotEdited, tempShort, 0, -1);
181:
182: // always set deleteIfNotEdited back to false so subsequent edits don't accidently delete
183: m_bDeleteIfNotEdited = false;
184: }
185: }
186: }
187: return 0;
188: }
189:
190: /* (non-Javadoc)
191: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#get_DeleteIfNotEdited()
192: */
193: public boolean getDeleteIfNotEdited() {
194: // TODO Auto-generated method stub
195: return false;
196: }
197:
198: /* (non-Javadoc)
199: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#put_DeleteIfNotEdited(boolean)
200: */
201: public long setDeleteIfNotEdited(boolean bDelete) {
202: // TODO Auto-generated method stub
203: return 0;
204: }
205:
206: /* (non-Javadoc)
207: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#getPresentationOwner()
208: */
209: public IPresentationElement getPresentationOwner() {
210: IPresentationElement retVal = null;
211:
212: IETLabel etlabel = getETLabel();
213: if (etlabel != null) {
214: retVal = etlabel.getParentPresentationElement();
215: }
216:
217: return retVal;
218: }
219:
220: /* (non-Javadoc)
221: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#getLocation(int, int, int, int)
222: */
223: public long getLocation(int pWidth, int pHeight, int pXCenter,
224: int pYCenter) {
225: // TODO Auto-generated method stub
226: return 0;
227: }
228:
229: /* (non-Javadoc)
230: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#moveTo(int, int, int)
231: */
232: public long moveTo(int x, int y, int flags) {
233: // TODO Auto-generated method stub
234: return 0;
235: }
236:
237: /**
238: *
239: * Creates the label presentation element node.
240: *
241: * @param doc[in] the document owner of the new node
242: * @param parent[in] the parent of the new node
243: * @return HRESULTs
244: *
245: */
246: public void establishNodePresence(Document doc, Node parent) {
247: buildNodePresence("UML:LabelPresentation", doc, parent);
248: }
249:
250: /**
251: * Gets the FIRST model element associated with this presentation element. More generically
252: * there is a many to one relationship...but in most cases a many to one relationship
253: * between an IPresentationElement and IElement exists.
254: *
255: * @param pVal[out, retval] The first model element associated with this presentation element
256: *
257: * @return HRESULT
258: */
259: public IElement getModelElement() {
260: return super .getModelElement();
261: // return getFirstSubject();
262: }
263:
264: /**
265: * Sets the model element associated with this presentation element.
266: *
267: * @param newVal[in] The model element associated with this presentation element
268: *
269: * @return HRESULT
270: */
271: public void setModelElement(IElement newVal) {
272:
273: super .setModelElement(newVal);
274: // if (newVal != null) {
275: // // Remove all the subjects
276: // ETList < IElement > pModelElements = getSubjects();
277: // long count = getSubjectCount();
278: // for (long i = 0; i < count; i++) {
279: // IElement pEle = pModelElements.get((int) i);
280: // pEle.removePresentationElement(this);
281: // removeSubject(pEle);
282: // }
283: //
284: // // Add the subject
285: // addSubject(newVal);
286: //
287: // // Now update the draw engine/compartment so that it's pointing to the same model element
288: // IETGraphObject graphObj = getETGraphObject();
289: // if (graphObj != null) {
290: // IDrawEngine drawEng = graphObj.getEngine();
291: // if (drawEng != null) {
292: // drawEng.initCompartments(this);
293: // }
294: // }
295: // }
296: }
297:
298: public IETPoint getCenter() {
299: TSLabel label = getTSLabel();
300: return label != null ? new ETPoint((int) label.getCenter()
301: .getX(), (int) label.getCenter().getY()) : null;
302: }
303:
304: public long getWidth() {
305: TSLabel label = getTSLabel();
306: return label != null ? (long) label.getWidth() : 0;
307: }
308:
309: public long getHeight() {
310: TSLabel label = getTSLabel();
311: return label != null ? (long) label.getHeight() : 0;
312: }
313:
314: }
|