001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo;
021:
022: import com.nwoods.jgo.JGoBrush;
023: import java.awt.Point;
024:
025: import com.nwoods.jgo.JGoLink;
026: import com.nwoods.jgo.JGoListPosition;
027: import com.nwoods.jgo.JGoObject;
028: import com.nwoods.jgo.JGoPen;
029: import com.nwoods.jgo.JGoPort;
030: import com.nwoods.jgo.JGoView;
031: import java.awt.Color;
032: import java.awt.Dimension;
033: import org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo.util.DrawPort;
034: import org.netbeans.modules.soa.mapper.common.basicmapper.IBasicViewManager;
035: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasMapperLink;
036:
037: /**
038: * @author radval
039: *
040: * Port which supports link highlighting.
041: */
042: public class BasicCanvasPort extends JGoPort {
043:
044: private static Dimension NO_SIZE = new Dimension(0, 0);
045: private static final JGoBrush BRUSH = JGoBrush
046: .makeStockBrush(new Color(255, 255, 255, 0)); // transparent
047:
048: private boolean toggleLinkHighliting = false;
049: private DrawPort mDrawPort;
050: private JGoPen pen;
051:
052: public BasicCanvasPort() {
053: setBrush(BRUSH);
054: }
055:
056: public DrawPort getDrawPort() {
057: return mDrawPort;
058: }
059:
060: public void setPortObject(JGoObject obj) {
061: super .setPortObject(obj);
062: if (obj instanceof DrawPort) {
063: mDrawPort = (DrawPort) obj;
064: }
065: }
066:
067: public int getLinkPosition() {
068: if (mDrawPort != null) {
069: if (mDrawPort.getFieldNode().getFieldNode().isInput()) {
070: return JGoObject.LeftCenter;
071: } else if (mDrawPort.getFieldNode().getFieldNode()
072: .isOutput()) {
073: return JGoObject.RightCenter;
074: }
075: }
076: return JGoObject.Center;
077: }
078:
079: public Dimension getDrawSize() {
080: if (mDrawPort != null) {
081: return mDrawPort.getDrawSize();
082: }
083: return NO_SIZE;
084: }
085:
086: public boolean doMouseEntered(int modifiers, Point dc, Point vc,
087: JGoView view) {
088:
089: if (this .getNumLinks() == 0) {
090: return false;
091: }
092:
093: JGoListPosition pos = this .getFirstLinkPos();
094: while (pos != null) {
095: JGoLink link = this .getLinkAtPos(pos);
096: if (link instanceof AbstractCanvasLink) {
097: AbstractCanvasLink cLink = (AbstractCanvasLink) link;
098: IBasicViewManager viewManager = cLink.getMapperCanvas()
099: .getParentView().getViewManager();
100: //need to check if highlighting is enabled
101: if (!viewManager.isHighlightLink()
102: || !viewManager.isToggleHighlighting()) {
103: break;
104: }
105:
106: cLink.startHighlighting();
107:
108: } else {
109: if (pen == null) {
110: pen = link.getPen();
111: }
112: link.setPen(JGoPen.make(JGoPen.SOLID, 1,
113: ICanvasMapperLink.DEFAULT_LINK_SELECTED_COLOR));
114: }
115: pos = this .getNextLinkPos(pos);
116: }
117: return true;
118: }
119:
120: public boolean doMouseExited(int modifiers, Point dc, Point vc,
121: JGoView view) {
122:
123: if (this .getNumLinks() == 0) {
124: return false;
125: }
126:
127: JGoListPosition pos = this .getFirstLinkPos();
128: while (pos != null) {
129: JGoLink link = this .getLinkAtPos(pos);
130: if (link instanceof AbstractCanvasLink) {
131: AbstractCanvasLink cLink = (AbstractCanvasLink) link;
132: cLink.stopHighlighting();
133: } else {
134: link.setPen(pen);
135: }
136: pos = this .getNextLinkPos(pos);
137: }
138:
139: return true;
140: }
141: }
|