001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.components;
016:
017: import java.awt.Point;
018: import java.awt.event.MouseEvent;
019: import java.awt.geom.Point2D;
020:
021: import org.jgraph.JGraph;
022: import org.jgraph.graph.CellHandle;
023: import org.jgraph.graph.CellMapper;
024: import org.jgraph.graph.CellView;
025: import org.jgraph.graph.CellViewRenderer;
026: import org.jgraph.graph.DefaultGraphCell;
027: import org.jgraph.graph.EdgeView;
028: import org.jgraph.graph.GraphCell;
029: import org.jgraph.graph.GraphConstants;
030: import org.jgraph.graph.GraphContext;
031:
032: public class DesignEdgeView extends EdgeView {
033: public DesignEdgeRenderer renderer = new DesignEdgeRenderer();
034:
035: public DesignEdgeView(Object cell, JGraph graph, CellMapper mapper) {
036: super (cell, graph, mapper);
037: }
038:
039: public CellViewRenderer getRenderer() {
040: //return super.getRenderer();
041: return renderer;
042: }
043:
044: public CellHandle getHandle(GraphContext context) {
045: return new EdgeHandle(this , context) {
046: protected void reloadPoints(EdgeView edge) {
047: if (edge != null)
048: super .reloadPoints(edge);
049: }
050:
051: public void mousePressed(MouseEvent event) {
052: super .mousePressed(event);
053:
054: if (!event.isControlDown()) {
055: if (currentPoint != null) {
056: CellView lSourceView = edge.getSource();
057: CellView lTargetView = edge.getTarget();
058:
059: boolean lSourceInvalid = !isCellValid(lSourceView);
060: boolean lTargetInvalid = !isCellValid(lTargetView);
061:
062: if ((lSourceInvalid || lTargetInvalid)
063: && !(lSourceInvalid && lTargetInvalid)) {
064: int lCount = edge.getPointCount();
065: if (currentPoint.equals(edge
066: .getPoint(lCount - 2))) {
067: Point2D lPoint = edge
068: .getPoint(lCount - 1);
069: if (lPoint.equals(currentPoint)) {
070: currentPoint = lPoint;
071: boolean disconnectable = graph
072: .isDisconnectable()
073: && GraphConstants
074: .isDisconnectable(orig
075: .getAllAttributes());
076: target = (edge.getTarget() == null || (disconnectable && GraphConstants
077: .isDisconnectable(edge
078: .getTarget()
079: .getParentView()
080: .getAllAttributes())));
081: }
082: }
083: }
084: }
085: }
086: }
087:
088: public void mouseReleased(MouseEvent event) {
089: if (!event.isControlDown()) {
090: CellView lSourceView = edge.getSource();
091: CellView lTargetView = edge.getTarget();
092:
093: if ((lSourceView == null || lTargetView == null)
094: && !(lSourceView == null && lTargetView == null)) {
095: Point2D point = graph.fromScreen(graph
096: .snap(new Point(event.getPoint())));
097:
098: int index = (lSourceView == null) ? 0
099: : r.length - 1;
100:
101: edge.addPoint(index, point);
102: reloadPoints(edge);
103: paint(graph.getGraphics());
104: }
105: }
106: super .mouseReleased(event);
107: }
108:
109: // check cell
110: public boolean isCellValid(CellView pCellView) {
111: if (pCellView == null)
112: return false;
113:
114: GraphCell lCell = (GraphCell) pCellView.getCell();
115: if (lCell instanceof DefaultGraphCell) {
116: DefaultGraphCell lGraphCell = (DefaultGraphCell) lCell;
117: if (lGraphCell.getUserObject() != null
118: && lGraphCell.getUserObject()
119: .equals("test"))
120: return false;
121: }
122:
123: return true;
124: }
125:
126: protected boolean snap(boolean source, Point2D point) {
127: return super .snap(source, point);
128: //return true;
129: }
130: };
131: }
132: }
|