Source Code Cross Referenced for SynchronizerNode.java in  » Groupware » LibreSource » com » artenum » so6 » dataflow » graph » 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 » Groupware » LibreSource » com.artenum.so6.dataflow.graph 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * LibreSource
003:         * Copyright (C) 2004-2008 Artenum SARL / INRIA
004:         * http://www.libresource.org - contact@artenum.com
005:         *
006:         * This file is part of the LibreSource software, 
007:         * which can be used and distributed under license conditions.
008:         * The license conditions are provided in the LICENSE.TXT file 
009:         * at the root path of the packaging that enclose this file. 
010:         * More information can be found at 
011:         * - http://dev.libresource.org/home/license
012:         *
013:         * Initial authors :
014:         *
015:         * Guillaume Bort / INRIA
016:         * Francois Charoy / Universite Nancy 2
017:         * Julien Forest / Artenum
018:         * Claude Godart / Universite Henry Poincare
019:         * Florent Jouille / INRIA
020:         * Sebastien Jourdain / INRIA / Artenum
021:         * Yves Lerumeur / Artenum
022:         * Pascal Molli / Universite Henry Poincare
023:         * Gerald Oster / INRIA
024:         * Mariarosa Penzi / Artenum
025:         * Gerard Sookahet / Artenum
026:         * Raphael Tani / INRIA
027:         *
028:         * Contributors :
029:         *
030:         * Stephane Bagnier / Artenum
031:         * Amadou Dia / Artenum-IUP Blois
032:         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033:         */package com.artenum.so6.dataflow.graph;
034:
035:        import com.artenum.graph.interfaces.Cell;
036:        import com.artenum.graph.interfaces.Connection;
037:
038:        import com.artenum.so6.dataflow.ActionManager;
039:        import com.artenum.so6.dataflow.StyleManager;
040:        import com.artenum.so6.dataflow.graph.ui.SynchronizerUI;
041:        import com.artenum.so6.dataflow.util.So6PopupMenu;
042:
043:        import java.awt.Point;
044:        import java.awt.Rectangle;
045:        import java.awt.event.ActionEvent;
046:        import java.awt.event.ActionListener;
047:
048:        import java.util.ArrayList;
049:        import java.util.Hashtable;
050:        import java.util.Iterator;
051:        import java.util.Properties;
052:
053:        import javax.swing.JMenuItem;
054:
055:        /**
056:         * @author seb
057:         */
058:        public class SynchronizerNode extends So6Node implements  ActionListener {
059:            private Hashtable connectionPoint;
060:            private ArrayList availablePoints;
061:            private ArrayList unavailablePoints;
062:            public boolean ONE_CONNECTOR_BY_CONNECTION = false;
063:            public So6PopupMenu popupMenu;
064:
065:            public SynchronizerNode(Properties externalProps) {
066:                super (externalProps);
067:                connectionPoint = new Hashtable();
068:                availablePoints = new ArrayList();
069:                unavailablePoints = new ArrayList();
070:                ui = new SynchronizerUI(this );
071:                ui.setBounds(new Rectangle(ui.getPreferredSize()));
072:
073:                So6PopupMenu popupMenu = new So6PopupMenu(new So6DragListener(
074:                        this , false));
075:                ui.addMouseListener(popupMenu);
076:                ui.addMouseMotionListener(popupMenu);
077:
078:                JMenuItem cwc = new JMenuItem("Create workspace");
079:                cwc.addActionListener(this );
080:                popupMenu.add(cwc);
081:                setSelectedBorderColor(StyleManager.getInstance()
082:                        .getWsUpToDateColor());
083:                setSelectedBorderSize(1);
084:            }
085:
086:            public String getName() {
087:                return getExternalProperties().getProperty("uri");
088:            }
089:
090:            public void buildSimpleConnectionAssignation() {
091:                availablePoints.clear();
092:                unavailablePoints.clear();
093:
094:                Point[] pointList = ((SynchronizerUI) ui)
095:                        .getConnectionPointArray();
096:
097:                for (int i = 0; i < pointList.length; i++) {
098:                    Point p = (Point) pointList[i].clone();
099:                    p.translate(ui.getBounds().getLocation().x, ui.getBounds()
100:                            .getLocation().y);
101:                    availablePoints.add(p);
102:                }
103:
104:                for (Iterator i = getConnections().iterator(); i.hasNext();) {
105:                    Point p = (Point) availablePoints.remove(0);
106:                    unavailablePoints.add(p);
107:                    connectionPoint.put(i.next(), p);
108:                }
109:            }
110:
111:            public void computeConnectionAssignation() {
112:                //buildSimpleConnectionAssignation();
113:                availablePoints.clear();
114:                unavailablePoints.clear();
115:
116:                Point[] pointList = ((SynchronizerUI) ui)
117:                        .getConnectionPointArray();
118:
119:                for (int i = 0; i < pointList.length; i++) {
120:                    Point p = (Point) pointList[i].clone();
121:
122:                    //p.translate(ui.getBounds().getLocation().x, ui.getBounds().getLocation().y);
123:                    availablePoints.add(p);
124:                }
125:
126:                double dist = -1;
127:
128:                for (Iterator connections = getConnections().iterator(); connections
129:                        .hasNext();) {
130:                    Connection connection = (Connection) connections.next();
131:                    Point p1 = connection.getOtherCell(this )
132:                            .getConnectionPoint(connection);
133:                    Point selectedPoint = (Point) availablePoints.get(0);
134:                    Point p2 = selectedPoint;
135:                    dist = p1.distance(p2);
136:
137:                    for (Iterator pointIterator = availablePoints.iterator(); pointIterator
138:                            .hasNext();) {
139:                        p2 = (Point) pointIterator.next();
140:
141:                        if (dist > p1.distance(p2)) {
142:                            selectedPoint = p2;
143:                            dist = p1.distance(p2);
144:                        }
145:                    }
146:
147:                    connectionPoint.put(connection, selectedPoint);
148:                    availablePoints.remove(selectedPoint);
149:                    unavailablePoints.add(selectedPoint);
150:                }
151:            }
152:
153:            public long getTicket() {
154:                return Long.parseLong(getExternalProperties().getProperty(
155:                        "LastTicket"));
156:            }
157:
158:            public Point getConnectionPoint(Connection connection) {
159:                if (!ONE_CONNECTOR_BY_CONNECTION) {
160:                    Cell connectionCell = connection.getOtherCell(this );
161:                    Point remoteCellPoint = ((ConnectionNode) connectionCell)
162:                            .getConnectionPoint(connection);
163:                    Point p = null;
164:                    Point currentPoint = null;
165:                    double dist = -1;
166:                    Point[] pointList = ((SynchronizerUI) ui)
167:                            .getConnectionPointArray();
168:
169:                    return checkDistance(remoteCellPoint, pointList);
170:                } else {
171:                    Point p = (Point) connectionPoint.get(connection);
172:
173:                    if (p == null) {
174:                        return new Point(10, 10);
175:                    }
176:
177:                    return p;
178:                }
179:            }
180:
181:            private Point checkDistance(Point remoteCell, Point[] pointList) {
182:                double newDist;
183:                double smallestDist = -1;
184:                Point selectedPoint = null;
185:
186:                for (int i = 0; i < pointList.length; i++) {
187:                    newDist = remoteCell.distance(pointList[i]);
188:
189:                    if (selectedPoint == null) {
190:                        selectedPoint = pointList[i];
191:                        smallestDist = newDist;
192:                    } else if (smallestDist > newDist) {
193:                        smallestDist = newDist;
194:                        selectedPoint = pointList[i];
195:                    }
196:                }
197:
198:                return selectedPoint;
199:            }
200:
201:            public void updateNode() {
202:                if (ONE_CONNECTOR_BY_CONNECTION) {
203:                    computeConnectionAssignation();
204:
205:                    //buildSimpleConnectionAssignation();
206:                }
207:            }
208:
209:            public void actionPerformed(ActionEvent e) {
210:                ActionManager.getInstance().connectWorkspace(
211:                        getExternalProperties().getProperty("uri"));
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.