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.swing.drawingarea.diagramtools;
043:
044: import java.awt.event.MouseEvent;
045: import java.io.IOException;
046: import java.util.ArrayList;
047: import java.util.List;
048:
049: import org.netbeans.modules.uml.core.support.umlsupport.IETPoint;
050: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ETPointEx;
051: import org.netbeans.modules.uml.ui.swing.drawingarea.ADDrawingAreaControl;
052: import org.netbeans.modules.uml.ui.swing.drawingarea.ADGraphWindow;
053: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
054: import com.tomsawyer.diagramming.TSCutCopyPasteControl;
055: import com.tomsawyer.drawing.TSDGraph; //import com.tomsawyer.editor.state.TSEPasteState;
056: import com.tomsawyer.editor.tool.TSEPasteTool;
057: import com.tomsawyer.graph.TSGraphObject;
058: import com.tomsawyer.util.TSOptionData;
059: import org.netbeans.modules.uml.core.support.Debug;
060:
061: /**
062: * @author Embarcadero Technologies Inc.
063: *
064: */
065:
066: //public class ADPasteState extends TSEPasteState
067: public class ADPasteState extends TSEPasteTool {
068: private List m_pastedNodeList = new ArrayList();
069: private List m_pastedEdgeList = new ArrayList();
070: private List m_pastedNodeLabelList = new ArrayList();
071: private List m_pastedEdgeLabelList = new ArrayList();
072: private List m_pastedConnectorLabelList = new ArrayList();
073: private TSGraphObject m_targetGraphObj = null;
074: private TSOptionData m_optionData = null;
075:
076: public void resetState() {
077: //super.resetState();
078: super .resetTool();
079: getDrawingArea().setModelElement(null);
080: }
081:
082: protected IDrawingAreaControl getDrawingArea() {
083: ADGraphWindow graphWindow = getGraphWindow() instanceof ADGraphWindow ? (ADGraphWindow) getGraphWindow()
084: : null;
085: return graphWindow != null ? graphWindow.getDrawingArea()
086: : null;
087: }
088:
089: public void onMouseReleased(MouseEvent event) {
090: TSCutCopyPasteControl clipboardControl = getCutCopyPasteControl();
091:
092: if (clipboardControl == null) {
093: this .cancelAction();
094: return;
095: }
096:
097: if (clipboardControl != null && clipboardControl.canPaste()) {
098: IETPoint location = new ETPointEx(
099: getNonalignedWorldPoint(event));
100: TSDGraph pClipboardGraph = clipboardControl
101: .getClipboardGraph();
102:
103: if (pClipboardGraph != null) {
104: m_pastedNodeList = new ArrayList();
105: m_pastedEdgeList = new ArrayList();
106: m_pastedNodeLabelList = new ArrayList();
107: m_pastedEdgeLabelList = new ArrayList();
108:
109: m_targetGraphObj = getTargetObject();
110: // m_optionData = *** get option data here - jyothi
111:
112: try {
113: //clipboardControl.paste(m_targetGraphObj, location.getX(), location.getY(), m_pastedNodeList, m_pastedEdgeList, m_pastedNodeLabelList, m_pastedEdgeLabelList);
114: clipboardControl.paste(m_targetGraphObj,
115: m_optionData, location.getX(), location
116: .getY(), m_pastedNodeList,
117: m_pastedEdgeList, m_pastedNodeLabelList,
118: m_pastedConnectorLabelList,
119: m_pastedEdgeLabelList);
120:
121: ((ADDrawingAreaControl) getDrawingArea())
122: .onPostPaste(m_targetGraphObj,
123: m_pastedNodeList, m_pastedEdgeList,
124: m_pastedNodeLabelList,
125: m_pastedEdgeLabelList, true);
126: } catch (IOException e) {
127: e.printStackTrace();
128: }
129: }
130: }
131: this .cancelAction();
132: }
133:
134: // public void onMouseReleased(MouseEvent event)
135: // {
136: //
137: // m_pastedNodeList = new ArrayList();
138: // m_pastedEdgeList = new ArrayList();
139: // m_pastedNodeLabelList = new ArrayList();
140: // m_pastedEdgeLabelList = new ArrayList();
141: //
142: // IDrawingAreaControl drawingArea = getDrawingArea();
143: //
144: // TSCutCopyPasteControl control = this.getCutCopyPasteControl();
145: // m_targetGraphObj = this.getTargetObject();
146: // TSDGraph clipGraph = control.getClipboardGraph();
147: //
148: // ETList < IETGraphObject > affectedObjects = new ETArrayList < IETGraphObject > ();
149: //
150: // affectedObjects.addAll(clipGraph.nodes());
151: // //affectedObjects.addAll(clipGraph.edges());
152: //
153: // IteratorT < IETGraphObject > objIter = new IteratorT < IETGraphObject > (affectedObjects);
154: //
155: // try
156: // {
157: // while (objIter.hasNext())
158: // {
159: // IETGraphObject obj = objIter.next();
160: //
161: // IETGraphObjectUI objUI = obj.getETUI();
162: //
163: // if (objUI != null)
164: // {
165: // String initString = objUI.getInitStringValue();
166: // String drawEngineClass = objUI.getDrawEngineClass();
167: //
168: // objUI.setDrawEngine(null);
169: //
170: // if (obj.isNode())
171: // {
172: // //TODO This should not be necessary. Just trying to see if I can reset the UI/drawengine here
173: // //ETGenericNodeUI nodeUI = ETUIFactory.createNodeUI("org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericNodeUI", initString, drawEngineClass, drawingArea);
174: // ((ETGenericNodeUI)objUI).setOwner((TSENode)obj);
175: // ((ETNode)obj).setUI((TSEObjectUI)objUI);
176: // ((GraphPresentation)((ETNode)obj).getPresentationElement()).setUI(objUI);
177: //
178: // m_pastedNodeList.add(obj);
179: // }
180: // else if (obj.isEdge())
181: // {
182: // //ETGenericEdgeUI edgeUI = ETUIFactory.createEdgeUI("org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericEdgeUI", initString, drawEngineClass, drawingArea);
183: // //obj.setObjectView(edgeUI);
184: // m_pastedEdgeList.add(obj);
185: // }
186: // }
187: //
188: // }
189: // }
190: // catch (Exception e)
191: // {
192: // e.printStackTrace();
193: // }
194: //
195: // super.onMouseReleased(event);
196: //
197: // ((ADDrawingAreaControl)getDrawingArea()).onPostPaste(m_targetGraphObj, m_pastedNodeList, m_pastedEdgeList, m_pastedNodeLabelList, m_pastedEdgeLabelList, true);
198: //
199: // }
200:
201: //
202: // public void onMousePressed(MouseEvent event)
203: // {
204: // // TODO Auto-generated method stub
205: // //super.onMousePressed(arg0);
206: //
207: // TSCutCopyPasteControl clipboardControl = getCutCopyPasteControl();
208: //
209: // if (clipboardControl == null)
210: // {
211: // Debug.out.println("ADPasteState - Something is wrong... the CutCopypastControl is null");
212: // this.cancelAction();
213: // return;
214: // }
215: //
216: // boolean allowPaste = clipboardControl.canPaste();
217: //
218: // if (!allowPaste)
219: // {
220: // this.cancelAction();
221: // }
222: //
223: // if (clipboardControl != null && allowPaste)
224: // {
225: // Point location = event.getPoint();
226: // TSDGraph pClipboardGraph = clipboardControl.getClipboardGraph();
227: //
228: // if (pClipboardGraph != null)
229: // {
230: // m_pastedNodeList = new ArrayList();
231: // m_pastedEdgeList = new ArrayList();
232: // m_pastedNodeLabelList = new ArrayList();
233: // m_pastedEdgeLabelList = new ArrayList();
234: //
235: // m_targetGraphObj = getTargetObject();
236: //
237: // try
238: // {
239: // clipboardControl.paste(m_targetGraphObj, location.x, location.y, m_pastedNodeList, m_pastedEdgeList, m_pastedNodeLabelList, m_pastedEdgeLabelList);
240: // }
241: // catch (IOException e)
242: // {
243: // e.printStackTrace();
244: // }
245: // }
246: // }
247: // }
248:
249: // public void onMouseReleased(MouseEvent event)
250: // {
251: // //super.onMouseReleased(event);
252: //
253: // TSCutCopyPasteControl clipboardControl = getCutCopyPasteControl();
254: //
255: // if (clipboardControl == null)
256: // {
257: // Debug.out.println("ADPasteState - Something is wrong... the CutCopypastControl is null");
258: // this.cancelAction();
259: // return;
260: // }
261: //
262: // boolean allowPaste = clipboardControl.canPaste();
263: //
264: // if (!allowPaste)
265: // {
266: // this.cancelAction();
267: // }
268: //
269: // if (clipboardControl != null && allowPaste)
270: // {
271: // Point location = event.getPoint();
272: // TSDGraph pClipboardGraph = clipboardControl.getClipboardGraph();
273: //
274: // if (pClipboardGraph != null)
275: // {
276: // m_pastedNodeList = new ArrayList();
277: // m_pastedEdgeList = new ArrayList();
278: // m_pastedNodeLabelList = new ArrayList();
279: // m_pastedEdgeLabelList = new ArrayList();
280: //
281: // m_targetGraphObj = getTargetObject();
282: //
283: // try
284: // {
285: // clipboardControl.paste(m_targetGraphObj, location.x, location.y, m_pastedNodeList, m_pastedEdgeList, m_pastedNodeLabelList, m_pastedEdgeLabelList);
286: // ((ADDrawingAreaControl)getDrawingArea()).onPostPaste(m_targetGraphObj, m_pastedNodeList, m_pastedEdgeList, m_pastedNodeLabelList, m_pastedEdgeLabelList, true);
287: // this.commitPasteOperation();
288: // }
289: // catch (IOException e)
290: // {
291: // e.printStackTrace();
292: // }
293: // }
294: // }
295: // this.cancelAction();
296: // }
297:
298: // public void onMouseReleased(MouseEvent event)
299: // {
300: // super.onMouseReleased(event);
301: //
302: // IDrawingAreaControl drawingArea = getDrawingArea();
303: //
304: // TSCutCopyPasteControl control = this.getCutCopyPasteControl();
305: // TSGraphObject targetGraphObj = this.getTargetObject();
306: // TSDGraph clipGraph = control.getClipboardGraph();
307: //
308: // List nodeList = clipGraph.nodes();
309: // List edgeList = new ArrayList();
310: // List nodeLabelList = new ArrayList();
311: // List edgeLabelList = new ArrayList();
312: //
313: // ETList < IETGraphObject > affectedObjects = new ETArrayList < IETGraphObject > ()
314: // {
315: // public boolean addAll(List c)
316: // {
317: // return c != null ? super.addAll(c) : false;
318: // }
319: // };
320: //
321: // affectedObjects.addAll(clipGraph.nodes());
322: // affectedObjects.addAll(clipGraph.edges());
323: //
324: // IteratorT < IETGraphObject > objIter = new IteratorT < IETGraphObject > (affectedObjects);
325: //
326: // try
327: // {
328: // while (objIter.hasNext())
329: // {
330: // IETGraphObject obj = objIter.next();
331: //
332: // IETGraphObjectUI objUI = obj.getETUI();
333: //
334: // if (objUI != null)
335: // {
336: // String initString = objUI.getInitStringValue();
337: // String drawEngineClass = objUI.getDrawEngineClass();
338: //
339: // //objUI.setDrawEngine(null);
340: //
341: // if (obj.isNode())
342: // {
343: // //TODO This should not be necessary. Just trying to see if I can reset the UI/drawengine here
344: // //ETGenericNodeUI nodeUI = ETUIFactory.createNodeUI("org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericNodeUI", initString, drawEngineClass, drawingArea);
345: // //obj.setObjectView(nodeUI);
346: // nodeList.add(obj);
347: // }
348: // else if (obj.isEdge())
349: // {
350: // //ETGenericEdgeUI edgeUI = ETUIFactory.createEdgeUI("org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericEdgeUI", initString, drawEngineClass, drawingArea);
351: // //obj.setObjectView(edgeUI);
352: // edgeList.add(obj);
353: // }
354: // }
355: //
356: // }
357: // }
358: // catch (Exception e)
359: // {
360: // e.printStackTrace();
361: // }
362: //
363: // ((ADDrawingAreaControl)getDrawingArea()).onPostPaste(targetGraphObj, nodeList, edgeList, nodeLabelList, edgeLabelList, true);
364: //
365: // }
366:
367: }
|