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.view.conditionbuilder;
042:
043: import java.awt.Color;
044: import java.util.ArrayList;
045: import java.util.List;
046:
047: import org.netbeans.modules.sql.framework.model.ColumnRef;
048: import org.netbeans.modules.sql.framework.model.SQLDBColumn;
049: import org.netbeans.modules.sql.framework.model.SQLObject;
050: import org.netbeans.modules.sql.framework.ui.graph.IGraphPort;
051: import org.netbeans.modules.sql.framework.ui.graph.impl.BasicCanvasArea;
052: import org.netbeans.modules.sql.framework.ui.graph.impl.BasicCellArea;
053:
054: import com.nwoods.jgo.JGoBrush;
055: import com.nwoods.jgo.JGoPen;
056: import com.nwoods.jgo.JGoRectangle;
057:
058: /**
059: * @author Ritesh Adval
060: * @version $Revision$
061: */
062: public class ColumnGraphNode extends BasicCanvasArea {
063: protected JGoRectangle columnRect;
064: private BasicCellArea cellArea;
065:
066: /** Creates a new instance of ColumnGraphNode */
067: public ColumnGraphNode() {
068: super ();
069:
070: columnRect = new JGoRectangle();
071: columnRect.setSelectable(true);
072: columnRect.setPen(JGoPen.lightGray);
073: columnRect.setBrush(JGoBrush.makeStockBrush(new Color(254, 253,
074: 235)));
075:
076: this .setResizable(false);
077: this .setSelectable(true);
078: this .setPickableBackground(true);
079:
080: }
081:
082: public ColumnGraphNode(ColumnRef column) {
083: this ();
084: this .setDataObject(column);
085: SQLObject col = column.getColumn();
086: if (col != null) {
087: SQLDBColumn origColumn = (SQLDBColumn) col;
088: String toolTip = origColumn.getQualifiedName();
089: this .setToolTipText(toolTip);
090: }
091:
092: cellArea = new BasicCellArea(BasicCellArea.RIGHT_PORT_AREA,
093: column.toString());
094: cellArea.drawBoundingRect(true);
095: this .addObjectAtTail(cellArea);
096:
097: // This is a hack to add 1 in width to forec this to repaint and all its children
098: // so that BasicCellArea can draw a bounding rect around it
099: this .setSize(this .getMinimumWidth() + 2, this
100: .getMinimumHeight());
101: }
102:
103: /**
104: * Gets a list of all input and output links
105: *
106: * @return list of input links
107: */
108: public List getAllLinks() {
109: ArrayList list = new ArrayList();
110: if (cellArea != null) {
111: IGraphPort port = cellArea.getRightGraphPort();
112: addLinks(port, list);
113: }
114:
115: return list;
116: }
117:
118: /**
119: * Gets field name associated with the given port
120: *
121: * @param graphPort graph port
122: * @return field name
123: */
124: public String getFieldName(IGraphPort graphPort) {
125: ColumnRef columnRef = (ColumnRef) this .getDataObject();
126: SQLDBColumn column = (SQLDBColumn) columnRef.getColumn();
127: if (column != null) {
128: return column.toString();
129: }
130:
131: return null;
132: }
133:
134: /**
135: * get the minimum height
136: *
137: * @return min height
138: */
139: public int getMinimumHeight() {
140: return cellArea.getMinimumHeight();
141: }
142:
143: /**
144: * get the minimum width
145: *
146: * @return min width
147: */
148: public int getMinimumWidth() {
149: return cellArea.getMinimumWidth();
150: }
151:
152: /**
153: * get output graph port , given a field name
154: *
155: * @param fieldName field name
156: * @return graph port
157: */
158: public IGraphPort getOutputGraphPort(String fieldName) {
159: if (cellArea != null) {
160: return cellArea.getRightGraphPort();
161: }
162: return null;
163: }
164:
165: /**
166: * Lays out this area's child objects.
167: */
168: public void layoutChildren() {
169: cellArea.setBoundingRect(this.getBoundingRect());
170: }
171: }
|