Source Code Cross Referenced for AbstractCanvasLink.java in  » IDE-Netbeans » soa » org » netbeans » modules » soa » mapper » basicmapper » canvas » jgo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » soa » org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         * 
006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007:         * or http://www.netbeans.org/cddl.txt.
008:         * 
009:         * When distributing Covered Code, include this CDDL Header Notice in each file
010:         * and include the License file at http://www.netbeans.org/cddl.txt.
011:         * If applicable, add the following below the CDDL Header, with the fields
012:         * enclosed by brackets [] replaced by your own identifying information:
013:         * "Portions Copyrighted [year] [name of copyright owner]"
014:         * 
015:         * The Original Software is NetBeans. The Initial Developer of the Original
016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017:         * Microsystems, Inc. All Rights Reserved.
018:         */
019:
020:        package org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo;
021:
022:        import java.awt.Rectangle;
023:        import java.beans.PropertyChangeEvent;
024:        import java.beans.PropertyChangeListener;
025:
026:        import javax.swing.SwingUtilities;
027:
028:        import com.nwoods.jgo.JGoBrush;
029:        import com.nwoods.jgo.JGoLink;
030:        import com.nwoods.jgo.JGoPen;
031:        import com.nwoods.jgo.JGoPort;
032:        import com.nwoods.jgo.JGoSelection;
033:        import com.nwoods.jgo.JGoView;
034:        import org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo.util.DrawPort;
035:        import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasMapperLink;
036:        import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasView;
037:        import org.netbeans.modules.soa.mapper.common.IMapperLink;
038:        import org.netbeans.modules.soa.mapper.common.IMapperNode;
039:        import org.netbeans.modules.soa.mapper.common.basicmapper.tree.IMapperTreeNode;
040:        import org.netbeans.modules.soa.mapper.common.gtk.ICanvasLinkLabel;
041:        import org.netbeans.modules.soa.mapper.common.gtk.ICanvasNode;
042:
043:        /**
044:         * <p>
045:         *
046:         * Title: </p> AbstractCanvasLink <p>
047:         *
048:         * Description: </p> AbstractCanvasLink provides the basic implemenation of a
049:         * canvas link with a JGoLink. <p>
050:         *
051:         * @author    Un Seng Leong
052:         * @created   December 4, 2002
053:         */
054:        public abstract class AbstractCanvasLink extends JGoLink implements 
055:                ICanvasMapperLink {
056:
057:            /**
058:             * the canvas of this link
059:             */
060:            private ICanvasView mCanvas;
061:
062:            /**
063:             * the mapper link of this canvas link.
064:             */
065:            private IMapperLink mMapperLink;
066:
067:            /**
068:             * the pixels of the middle segement indent
069:             */
070:            private static final int MID_SEGEMTNT_IDENT = 5;
071:
072:            /**
073:             * the mid point of this link, this is for debugging purpose.
074:             */
075:            private int mMidPoint = 0;
076:
077:            /**
078:             * the offset pixels that counts to be overlap segement.
079:             */
080:            private static final int OVERLAP_OFFSET_PIXELS = 2;
081:
082:            /**
083:             * The value indicates the mid segement should go left.
084:             */
085:            private static final int INDENT_TO_LEFT = -1;
086:
087:            /**
088:             * The value indicates the mid segement should go right.
089:             */
090:            private static final int INDENT_TO_RIGHT = 1;
091:
092:            protected JGoPort endPort;
093:            protected JGoPort startPort;
094:
095:            private JGoPen pen;
096:            private JGoBrush brush;
097:            private boolean mIsSelected;
098:
099:            /**
100:             * Creates a new AbstractCanvasLink object, with a specified mapper link.
101:             *
102:             * @param link  the mapper link this canvas link repersents.
103:             */
104:            public AbstractCanvasLink(IMapperLink link) {
105:                mMapperLink = link;
106:                this .setRelinkable(false);
107:                this .setOrthogonal(true);
108:                this .setJumpsOver(true);
109:
110:                this .pen = this .getPen();
111:                this .brush = this .getBrush();
112:            }
113:
114:            protected AbstractCanvasLink(JGoPort fromPort, JGoPort toPort) {
115:                super (fromPort, toPort);
116:                this .setJumpsOver(true);
117:            }
118:
119:            /**
120:             * Return the destination node of this link.
121:             *
122:             * @return   the destination node of this link.
123:             */
124:            public ICanvasNode getDestinationNode() {
125:                if (mMapperLink.getEndNode() instanceof  ICanvasNode) {
126:                    return (ICanvasNode) mMapperLink.getEndNode();
127:                }
128:
129:                return null;
130:            }
131:
132:            /**
133:             * Return the label of this link.
134:             *
135:             * @return   always null.
136:             */
137:            public ICanvasLinkLabel getLabel() {
138:                return null;
139:            }
140:
141:            /**
142:             * Return the canvas of this link.
143:             *
144:             * @return   the canvas view of this link.
145:             */
146:            public ICanvasView getMapperCanvas() {
147:                return mCanvas;
148:            }
149:
150:            /**
151:             * Return the mapper link.
152:             *
153:             * @return   the mapper link.
154:             */
155:            public IMapperLink getMapperLink() {
156:                return mMapperLink;
157:            }
158:
159:            /**
160:             * Return the source node fo this link.
161:             *
162:             * @return   the source node fo this link.
163:             */
164:            public ICanvasNode getSourceNode() {
165:                if (mMapperLink.getStartNode() instanceof  ICanvasNode) {
166:                    return (ICanvasNode) mMapperLink.getStartNode();
167:                }
168:
169:                return null;
170:            }
171:
172:            /**
173:             * Set the label of this link
174:             *
175:             * @param label  the label of this link.
176:             */
177:            public void setLabel(ICanvasLinkLabel label) {
178:            }
179:
180:            /**
181:             * Set if the label is visible.
182:             *
183:             * @param val  the label visible value
184:             */
185:            public void setLabelVisible(boolean val) {
186:            }
187:
188:            /**
189:             * Set the canvas of this link.
190:             *
191:             * @param canvas  the canvas of this link.
192:             */
193:            public void setMapperCanvas(ICanvasView canvas) {
194:                mCanvas = canvas;
195:                pen = JGoPen.makeStockPen(DEFAULT_LINK_COLOR);
196:                brush = JGoBrush.makeStockBrush(DEFAULT_LINK_COLOR);
197:                this .setPen(pen);
198:                this .setBrush(brush);
199:            }
200:
201:            /**
202:             * update the label text
203:             *
204:             * @param name  the text of the lable of this link
205:             */
206:            public void updateLabelText(String name) {
207:            }
208:
209:            /**
210:             * Sets the dataObject attribute of the AbstractCanvasLink object
211:             *
212:             * @param obj  The new dataObject value
213:             */
214:            public void setDataObject(Object obj) {
215:            }
216:
217:            /**
218:             * Gets the dataObject attribute of the AbstractCanvasLink object
219:             *
220:             * @return   The dataObject value
221:             */
222:            public Object getDataObject() {
223:                return null;
224:            }
225:
226:            /**
227:             * Return true if this link is not hidding from the screen, such as by
228:             * scroll panel.
229:             *
230:             * @param viewRect  the rectangle of the viewable area
231:             * @return          true if this link is not hidding from the screen, such
232:             *      as by scroll panel.
233:             */
234:            public boolean isDisplaying(Rectangle viewRect) {
235:                return true;// ???
236:            }
237:
238:            public void setPosition(int pos, int collectionSize) {
239:                mPosition = pos;
240:                mCollectionSize = collectionSize;
241:            }
242:
243:            int mPosition = 0;
244:            int mCollectionSize = 0;
245:
246:            /**
247:             * Return the mid point of this orthoal link. Override getMidOrthoPosition in JGoLink.
248:             *
249:             * @param from      the from point related to the mid point
250:             * @param to        the to point related to the mid point
251:             * @param vertical  true if the mid point is related to a vertical segment, false otherwise.
252:             * @return          The mid orthoal position value
253:             */
254:            protected int getMidOrthoPosition(int from, int to, boolean vertical) {
255:                int result = super .getMidOrthoPosition(from, to, vertical);
256:                if (mPosition > 0) {
257:                    int newPos = from + (mPosition * 6);
258:                    if (newPos < result) {
259:                        result = newPos;
260:                    }
261:                }
262:                return result;
263:            }
264:
265:            protected class NodeYChangeListener implements 
266:                    PropertyChangeListener {
267:                // PENDING -- the y axis difference between the tree view and
268:                // the canvas. This need to be calculate dynamically.
269:
270:                /**
271:                 * the difference between tree view and the canvas in y coordination.
272:                 */
273:                protected static final int Y_AXIS_DIFF = 1;
274:
275:                /**
276:                 * the port of the link.
277:                 */
278:                private JGoPort mPort;
279:
280:                /**
281:                 * the view contains this link.
282:                 */
283:                private JGoView mView;
284:
285:                /**
286:                 * Creates a new NodeYChangeListener object.
287:                 *
288:                 * @param view  the view contains this link.
289:                 * @param port  the port of the link.
290:                 */
291:                public NodeYChangeListener(JGoView view, JGoPort port) {
292:                    mPort = port;
293:                    mView = view;
294:                }
295:
296:                /**
297:                 * Change the port of this link to alone with the mapper node y
298:                 * coordination.
299:                 *
300:                 * @param e  the PropertyChangeEvent
301:                 */
302:                public void propertyChange(PropertyChangeEvent e) {
303:                    if (e.getPropertyName().equals(IMapperNode.Y_CHANGE)) {
304:
305:                        final int topLoc = ((IMapperNode) e.getSource()).getY()
306:                                + Y_AXIS_DIFF + mView.getViewPosition().y;
307:                        SwingUtilities.invokeLater(new Runnable() {
308:                            public void run() {
309:                                mPort.setTop(topLoc);
310:                            }
311:                        });
312:                    }
313:                }
314:            }
315:
316:            protected void gainedSelection(JGoSelection jgoselection) {
317:                mIsSelected = true;
318:                super .gainedSelection(jgoselection);
319:                startHighlighting();
320:                if (getMapperCanvas().isPathHighlightingEnabled()) {
321:                    new NetworkHighlightTraverser(true).visit(this );
322:                }
323:            }
324:
325:            protected void lostSelection(JGoSelection jgoselection) {
326:                mIsSelected = false;
327:                super .lostSelection(jgoselection);
328:                stopHighlighting();
329:                if (getMapperCanvas().isPathHighlightingEnabled()) {
330:                    new NetworkHighlightTraverser(false).visit(this );
331:                }
332:            }
333:
334:            /**
335:             * start highlighting this link
336:             */
337:            public void startHighlighting() {
338:                this .setPen(JGoPen.make(JGoPen.SOLID, mIsSelected ? 2 : 1,
339:                        DEFAULT_LINK_SELECTED_COLOR));
340:                this .setBrush(JGoBrush
341:                        .makeStockBrush(DEFAULT_LINK_SELECTED_COLOR));
342:                highlightSingleLink(mMapperLink, getMapperCanvas());
343:            }
344:
345:            /**
346:             * stop highlighting this link
347:             */
348:            public void stopHighlighting() {
349:                if (!mIsSelected) {
350:                    this .setPen(pen);
351:                    this .setBrush(brush);
352:                    unHighlightSingleLink(mMapperLink, getMapperCanvas());
353:                }
354:            }
355:
356:            public JGoPort getStartPort() {
357:                return this .startPort;
358:            }
359:
360:            public JGoPort getEndPort() {
361:                return this .endPort;
362:            }
363:
364:            public static void initializeArrowHeads(JGoLink link) {
365:                link.setArrowLength(7.5);
366:                link.setArrowShaftLength(6.5);
367:                link.setArrowWidth(4);
368:            }
369:
370:            private void highlightSingleLink(IMapperLink link,
371:                    ICanvasView canvasView) {
372:                IMapperNode startNode = link.getStartNode();
373:                if (startNode instanceof  IMapperTreeNode) {
374:                    IMapperTreeNode startTreeNode = (IMapperTreeNode) startNode;
375:                    startTreeNode.setHighlightLink(true);
376:                    startTreeNode.setSelectedLink(mIsSelected);
377:                    canvasView.getParentView().getViewManager().getSourceView()
378:                            .getTree().scrollPathToVisible(
379:                                    startTreeNode.getPath());
380:                    canvasView.getParentView().getViewManager().getSourceView()
381:                            .getTree().repaint();
382:                }
383:
384:                IMapperNode endNode = link.getEndNode();
385:                if (endNode instanceof  IMapperTreeNode) {
386:                    IMapperTreeNode endTreeNode = (IMapperTreeNode) endNode;
387:                    endTreeNode.setHighlightLink(true);
388:                    endTreeNode.setSelectedLink(mIsSelected);
389:                    canvasView.getParentView().getViewManager().getDestView()
390:                            .getTree().scrollPathToVisible(
391:                                    endTreeNode.getPath());
392:                    canvasView.getParentView().getViewManager().getDestView()
393:                            .getTree().repaint();
394:                }
395:
396:                setPortActivated(startPort, true);
397:                setPortActivated(endPort, true);
398:            }
399:
400:            private void unHighlightSingleLink(IMapperLink link,
401:                    ICanvasView canvasView) {
402:                IMapperNode startNode = link.getStartNode();
403:                if (startNode instanceof  IMapperTreeNode) {
404:                    IMapperTreeNode startTreeNode = (IMapperTreeNode) startNode;
405:                    startTreeNode.setHighlightLink(false);
406:                    startTreeNode.setSelectedLink(false);
407:                    canvasView.getParentView().getViewManager().getSourceView()
408:                            .getTree().repaint();
409:
410:                }
411:
412:                IMapperNode endNode = link.getEndNode();
413:                if (endNode instanceof  IMapperTreeNode) {
414:                    IMapperTreeNode endTreeNode = (IMapperTreeNode) endNode;
415:                    endTreeNode.setHighlightLink(false);
416:                    endTreeNode.setSelectedLink(false);
417:                    canvasView.getParentView().getViewManager().getDestView()
418:                            .getTree().repaint();
419:                }
420:
421:                setPortActivated(startPort, false);
422:                setPortActivated(endPort, false);
423:            }
424:
425:            private static void setPortActivated(JGoPort port,
426:                    boolean isActivated) {
427:                if (port instanceof  BasicCanvasPort) {
428:                    DrawPort drawnPort = ((BasicCanvasPort) port).getDrawPort();
429:                    if (drawnPort != null) {
430:                        drawnPort.setIsActivated(isActivated);
431:                    }
432:                }
433:            }
434:        }
w__w_w.j_a___v_a___2s__._c__o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.