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.StyleManager;
039: import com.artenum.so6.dataflow.graph.ui.ConnectionUI;
040:
041: import java.awt.Point;
042: import java.awt.Rectangle;
043:
044: import java.io.File;
045:
046: import java.util.Properties;
047:
048: /**
049: * @author seb
050: */
051: public class ConnectionNode extends So6Node {
052: public boolean WS_ALIGN = true;
053: private File so6PropertyFile;
054:
055: public ConnectionNode(Properties externalProps) {
056: super (externalProps);
057: so6PropertyFile = new File(getExternalProperties().getProperty(
058: "WscPath"));
059:
060: ui = new ConnectionUI(this );
061: ui.setBounds(new Rectangle(ui.getPreferredSize()));
062: setSelectedBorderColor(StyleManager.getInstance().getBGColor());
063: setSelectedBorderSize(0);
064: }
065:
066: public long getTicket() {
067: return Long.parseLong(getExternalProperties().getProperty(
068: "label"));
069: }
070:
071: public long getSynchronizerTicket() {
072: SynchronizerNode sNode = null;
073:
074: if (((Connection) getConnections().get(0)).getOtherCell(this ) instanceof SynchronizerNode) {
075: sNode = (SynchronizerNode) ((Connection) getConnections()
076: .get(0)).getOtherCell(this );
077: } else {
078: sNode = (SynchronizerNode) ((Connection) getConnections()
079: .get(1)).getOtherCell(this );
080: }
081:
082: return sNode.getTicket();
083: }
084:
085: public boolean isUpToDate() {
086: return getSynchronizerTicket() == getTicket();
087: }
088:
089: public String getName() {
090: return "<html><center>"
091: + (getExternalProperties()
092: .getProperty("ConnectionName"))
093: + "<br>"
094: + (getExternalProperties().getProperty("WscPath")
095: .replaceAll("\\\\", "/")) + "</center></html>";
096: }
097:
098: public boolean canMakeAction() {
099: return so6PropertyFile.exists();
100: }
101:
102: public void updateConnectionPosition() {
103: Point a = (((Connection) getConnections().get(0))
104: .getOtherCell(this ))
105: .getConnectionPoint((Connection) getConnections()
106: .get(0));
107: Point b = ((Connection) getConnections().get(1)).getOtherCell(
108: this ).getConnectionPoint(
109: (Connection) getConnections().get(1));
110: Point center = new Point(a.x + ((b.x - a.x) / 2), a.y
111: + ((b.y - a.y) / 2));
112:
113: // set Ws x
114: if ((((Connection) getConnections().get(0)).getOtherCell(this )) instanceof SynchronizerNode) {
115: ((ConnectionUI) ui)
116: .updateCompomentPosition((a.y - b.y) < 0);
117:
118: if (WS_ALIGN) {
119: center.x = b.x;
120: }
121: } else {
122: ((ConnectionUI) ui)
123: .updateCompomentPosition((a.y - b.y) > 0);
124:
125: if (WS_ALIGN) {
126: center.x = a.x;
127: }
128: }
129:
130: int widthHalf = (int) (getUI().getBounds().getWidth() / 2);
131: int heightHalf = (int) (getUI().getBounds().getHeight() / 2);
132: getUI().setBounds(center.x - widthHalf, center.y - heightHalf,
133: getUI().getPreferredSize().width,
134: getUI().getPreferredSize().height);
135: }
136:
137: public void updateNode() {
138: updateConnectionPosition();
139: ((ConnectionUI) ui).initActions();
140: }
141:
142: public Cell getOtherCell(Cell cell) {
143: if (((Connection) connectionList.get(0)).isInConnection(cell)) {
144: return ((Connection) connectionList.get(1))
145: .getOtherCell(this );
146: } else {
147: return ((Connection) connectionList.get(0))
148: .getOtherCell(this );
149: }
150: }
151:
152: public Point getConnectionPoint(Connection connection) {
153: if (connection.getOtherCell(this ) instanceof SynchronizerNode) {
154: // Commit side
155: return ((ConnectionUI) ui).getCommitPoint();
156: } else {
157: // Update side
158: return ((ConnectionUI) ui).getUpdatePoint();
159: }
160: }
161: }
|