001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sql.framework.ui.graph.impl;
042:
043: import java.awt.Color;
044: import java.awt.Cursor;
045: import java.awt.Point;
046:
047: import org.netbeans.modules.sql.framework.ui.graph.IGraphLink;
048: import org.netbeans.modules.sql.framework.ui.graph.IGraphNode;
049: import org.netbeans.modules.sql.framework.ui.graph.IGraphPort;
050:
051: import com.nwoods.jgo.JGoLink;
052: import com.nwoods.jgo.JGoListPosition;
053: import com.nwoods.jgo.JGoObject;
054: import com.nwoods.jgo.JGoPen;
055: import com.nwoods.jgo.JGoPort;
056: import com.nwoods.jgo.JGoView;
057:
058: /**
059: * @author Ritesh Adval
060: * @version $Revision$
061: */
062: public class GraphPort extends JGoPort implements IGraphPort {
063:
064: private boolean toggleLinkHighliting = false;
065: JGoPen pen;
066:
067: /** Creates a new instance of GraphPort */
068: public GraphPort() {
069: super ();
070: this .setSelectable(false);
071: this .setResizable(false);
072: }
073:
074: public boolean doMouseEntered(int modifiers, Point dc, Point vc,
075: JGoView view) {
076: if (this .getNumLinks() == 0) {
077: return false;
078: }
079:
080: JGoListPosition pos = this .getFirstLinkPos();
081: while (pos != null) {
082: JGoLink link = this .getLinkAtPos(pos);
083: if (link instanceof IGraphLink) {
084: ((IGraphLink) link).startHighlighting();
085: } else {
086: if (pen == null) {
087: pen = link.getPen();
088: }
089: link.setPen(JGoPen.make(JGoPen.SOLID, 2, Color.ORANGE));
090: }
091: pos = this .getNextLinkPos(pos);
092: }
093: return true;
094: }
095:
096: public boolean doMouseExited(int modifiers, Point dc, Point vc,
097: JGoView view) {
098: if (this .getNumLinks() == 0) {
099: return false;
100: }
101:
102: JGoListPosition pos = this .getFirstLinkPos();
103: while (pos != null) {
104: JGoLink link = this .getLinkAtPos(pos);
105: if (link instanceof IGraphLink) {
106: ((IGraphLink) link).stopHighlighting();
107: } else {
108: link.setPen(pen);
109: }
110: pos = this .getNextLinkPos(pos);
111: }
112:
113: return true;
114: }
115:
116: /**
117: * @param modifiers which keys are depressed (see Event documentation)
118: * @param dc the point of the click in document coordinates
119: * @param vc the point of the click in view coordinates
120: * @param view the view in which this event occured
121: * @return true if handled here and the view doesn't need to try this object's parent
122: * to see if it's interested
123: */
124: public boolean doMouseDblClick(int modifiers, Point dc, Point vc,
125: JGoView view) {
126: if (toggleLinkHighliting) {
127: doMouseExited(modifiers, dc, vc, view);
128: toggleLinkHighliting = false;
129: return true;
130: }
131: doMouseEntered(modifiers, dc, vc, view);
132: toggleLinkHighliting = true;
133: return true;
134: }
135:
136: /**
137: * Change the cursor at the port
138: *
139: * @param flags
140: */
141: public boolean doUncapturedMouseMove(int flags, Point dc, Point vc,
142: JGoView view) {
143: if ((isValidSource() || isValidDestination())
144: && getLayer() != null && getLayer().isModifiable()) {
145: view.setCursor(Cursor
146: .getPredefinedCursor(Cursor.HAND_CURSOR));
147: return true;
148: }
149: return false;
150: }
151:
152: /**
153: * get the data node for this graph port This is usually its parent
154: *
155: * @return data node
156: */
157: public IGraphNode getDataNode() {
158: JGoObject obj = this .getParent();
159:
160: while (obj != null && !(obj instanceof IGraphNode)) {
161: obj = obj.getParent();
162: }
163:
164: return (IGraphNode) obj;
165: }
166:
167: }
|