001: package net.sourceforge.squirrel_sql.plugins.graph;
002:
003: import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.ConstraintGraphXmlBean;
004: import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.FoldingPointXmlBean;
005:
006: import java.awt.*;
007: import java.util.Vector;
008: import java.util.Arrays;
009:
010: public class ConstraintGraph {
011: private GraphLine[] _fkStubLines;
012: private GraphLine[] _pkStubLines;
013: private Point _fkGatherPoint;
014: private Point _pkGatherPoint;
015:
016: private Vector<FoldingPoint> _foldingPoints = new Vector<FoldingPoint>();
017: private GraphLine _hitConnectLine;
018: private boolean _isHitOnConnectLine;
019: private FoldingPoint _hitFoldingPoint;
020:
021: public ConstraintGraph() {
022: }
023:
024: public ConstraintGraph(
025: ConstraintGraphXmlBean constraintGraphXmlBean, Zoomer zoomer) {
026: for (int i = 0; i < constraintGraphXmlBean
027: .getFoldingPointXmlBeans().length; i++) {
028: Point p = new Point();
029: p.x = constraintGraphXmlBean.getFoldingPointXmlBeans()[i]
030: .getX();
031: p.y = constraintGraphXmlBean.getFoldingPointXmlBeans()[i]
032: .getY();
033: _foldingPoints.add(new FoldingPoint(p, zoomer));
034: }
035: }
036:
037: public ConstraintGraphXmlBean getXmlBean() {
038: ConstraintGraphXmlBean ret = new ConstraintGraphXmlBean();
039: FoldingPointXmlBean[] foldPointXmlBeans = new FoldingPointXmlBean[_foldingPoints
040: .size()];
041: for (int i = 0; i < _foldingPoints.size(); i++) {
042: FoldingPoint point = _foldingPoints.elementAt(i);
043: foldPointXmlBeans[i] = new FoldingPointXmlBean();
044: foldPointXmlBeans[i].setX(point.getUnZoomedPoint().x);
045: foldPointXmlBeans[i].setY(point.getUnZoomedPoint().y);
046: }
047: ret.setFoldingPointXmlBeans(foldPointXmlBeans);
048:
049: return ret;
050:
051: }
052:
053: public void setFkStubLines(GraphLine[] fkStubLines) {
054: _fkStubLines = fkStubLines;
055: }
056:
057: public void setPkStubLines(GraphLine[] pkStubLines) {
058: _pkStubLines = pkStubLines;
059: }
060:
061: public void setFkGatherPoint(Point fkGatherPoint) {
062: _fkGatherPoint = fkGatherPoint;
063: }
064:
065: public void setPkGatherPoint(Point pkGatherPoint) {
066: _pkGatherPoint = pkGatherPoint;
067: }
068:
069: public GraphLine[] getAllLines() {
070: Vector<GraphLine> ret = new Vector<GraphLine>();
071:
072: ret.addAll(Arrays.asList(_fkStubLines));
073: ret.addAll(Arrays.asList(getConnectLines()));
074: ret.addAll(Arrays.asList(_pkStubLines));
075:
076: return ret.toArray(new GraphLine[ret.size()]);
077: }
078:
079: public GraphLine[] getLinesToArrow() {
080: return _pkStubLines;
081: }
082:
083: public GraphLine[] getConnectLines() {
084: if (0 == _foldingPoints.size()) {
085: return new GraphLine[] { new GraphLine(_fkGatherPoint,
086: _pkGatherPoint) };
087: }
088:
089: GraphLine[] ret = new GraphLine[_foldingPoints.size() + 1];
090:
091: ret[0] = new GraphLine(_fkGatherPoint, _foldingPoints.get(0));
092:
093: for (int i = 0; i < _foldingPoints.size() - 1; i++) {
094: ret[i + 1] = new GraphLine(_foldingPoints.get(i),
095: _foldingPoints.get(i + 1));
096: }
097:
098: ret[ret.length - 1] = new GraphLine(_foldingPoints
099: .lastElement(), _pkGatherPoint);
100:
101: return ret;
102:
103: }
104:
105: public void setHitConnectLine(GraphLine line) {
106: _hitConnectLine = line;
107: _isHitOnConnectLine = true;
108: }
109:
110: public void addFoldingPointToHitConnectLine(
111: FoldingPoint lastPopupClickPoint) {
112: if (_fkGatherPoint.equals(_hitConnectLine.getBegin())) {
113: _foldingPoints.insertElementAt(lastPopupClickPoint, 0);
114: return;
115: }
116:
117: for (int i = 0; i < _foldingPoints.size() - 1; i++) {
118: FoldingPoint fp = _foldingPoints.get(i);
119: if (_hitConnectLine.getBegin().equals(fp.getZoomedPoint())) {
120: _foldingPoints.insertElementAt(lastPopupClickPoint,
121: i + 1);
122: return;
123: }
124: }
125:
126: _foldingPoints.add(lastPopupClickPoint);
127:
128: }
129:
130: public Vector<FoldingPoint> getFoldingPoints() {
131: return _foldingPoints;
132: }
133:
134: public void setHitFoldingPoint(FoldingPoint foldingPoint) {
135: _isHitOnConnectLine = false;
136: _hitFoldingPoint = foldingPoint;
137: }
138:
139: public boolean isHitOnConnectLine() {
140: return _isHitOnConnectLine;
141: }
142:
143: public void removeHitFoldingPoint() {
144: _foldingPoints.remove(_hitFoldingPoint);
145: }
146:
147: public void moveLastHitFoldingPointTo(FoldingPoint point) {
148: // if(point.x < 0)
149: // {
150: // point.x = 0;
151: // }
152: // if(point.y < 0)
153: // {
154: // point.y = 0;
155: // }
156:
157: _foldingPoints.indexOf(_hitFoldingPoint);
158: _foldingPoints.set(_foldingPoints.indexOf(_hitFoldingPoint),
159: point);
160: _hitFoldingPoint = point;
161: }
162:
163: public void removeAllFoldingPoints() {
164: _foldingPoints.clear();
165: }
166:
167: public FoldingPoint getFirstFoldingPoint() {
168: if (0 == _foldingPoints.size()) {
169: return null;
170: } else {
171: return _foldingPoints.get(0);
172: }
173: }
174:
175: public FoldingPoint getLastFoldingPoint() {
176: if (0 == _foldingPoints.size()) {
177: return null;
178: } else {
179: return _foldingPoints.get(_foldingPoints.size() - 1);
180: }
181:
182: }
183:
184: public GraphLine getMainLine() {
185: if (0 == _foldingPoints.size()) {
186: return new GraphLine(_pkGatherPoint, _fkGatherPoint);
187: } else {
188: return new GraphLine(_foldingPoints.get(0), _fkGatherPoint);
189: }
190: }
191: }
|