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.join;
042:
043: import com.nwoods.jgo.JGoLink;
044: import java.awt.Color;
045: import java.awt.Insets;
046: import java.awt.Rectangle;
047: import java.util.ArrayList;
048: import java.util.List;
049: import org.netbeans.modules.sql.framework.model.SQLJoinTable;
050: import org.netbeans.modules.sql.framework.model.SourceTable;
051: import org.netbeans.modules.sql.framework.ui.graph.IGraphPort;
052: import org.netbeans.modules.sql.framework.ui.graph.impl.BasicCanvasArea;
053: import org.netbeans.modules.sql.framework.ui.graph.impl.BasicCellArea;
054: import com.nwoods.jgo.JGoPen;
055: import com.nwoods.jgo.JGoRectangle;
056: import com.nwoods.jgo.JGoText;
057:
058: /**
059: * This class represents a one cell level representation of a table
060: *
061: * @author radval
062: */
063: public class TableGraphNode extends BasicCanvasArea {
064:
065: protected JGoRectangle columnRect;
066: private BasicCellArea numberArea;
067: private BasicCellArea cellArea;
068:
069: /** Creates a new instance of ColumnGraphNode */
070: public TableGraphNode() {
071: super ();
072: this .setResizable(false);
073: this .setSelectable(false);
074: this .setUpdateGuiInfo(false);
075: }
076:
077: public TableGraphNode(SQLJoinTable table) {
078: this ();
079: this .setDataObject(table);
080: SourceTable sTable = table.getSourceTable();
081:
082: this .setToolTipText(sTable.getQualifiedName());
083:
084: //set up the number area
085: numberArea = new BasicCellArea("?");
086: numberArea.setSelectable(false);
087: numberArea.setResizable(false);
088:
089: numberArea.drawBoundingRect(true);
090: numberArea.setTextAlignment(JGoText.ALIGN_CENTER);
091: numberArea.setLeftGap(3);
092: numberArea.setIconTextGap(0);
093: numberArea.setInsets(new Insets(1, 0, 1, 1));
094: numberArea.setSize(numberArea.getMinimumWidth(), numberArea
095: .getMinimumHeight());
096: numberArea.setBorder(JGoPen.black);
097: numberArea.setBackGroundColor(new Color(241, 240, 227));
098: this .addObjectAtTail(numberArea);
099:
100: cellArea = new BasicCellArea(BasicCellArea.RIGHT_PORT_AREA,
101: sTable.getQualifiedName());
102: cellArea.setSelectable(false);
103: cellArea.setResizable(false);
104:
105: cellArea.drawBoundingRect(true);
106: this .addObjectAtHead(cellArea);
107: //this is a hack to add 1 in width to forec this to repaint and all its children
108: //so that BasicCellArea can draw a bounding rect around it
109: this .setSize(this .getMinimumWidth(), this .getMinimumHeight());
110: }
111:
112: public TableGraphNode(String tableName) {
113: this ();
114: this .setDataObject(null);
115:
116: this .setToolTipText(tableName);
117:
118: //set up the number area
119: numberArea = new BasicCellArea("100");
120: numberArea.setSelectable(true);
121: numberArea.setResizable(true);
122:
123: numberArea.drawBoundingRect(true);
124: numberArea.setTextAlignment(JGoText.ALIGN_CENTER);
125: numberArea.setLeftGap(3);
126: numberArea.setIconTextGap(0);
127: numberArea.setInsets(new Insets(1, 0, 1, 1));
128: numberArea.setSize(numberArea.getMinimumWidth(), numberArea
129: .getMinimumHeight());
130: numberArea.setBorder(JGoPen.black);
131: numberArea.setBackGroundColor(new Color(241, 240, 227));
132: this .addObjectAtTail(numberArea);
133:
134: cellArea = new BasicCellArea(BasicCellArea.RIGHT_PORT_AREA,
135: tableName);
136: cellArea.setSelectable(true);
137: cellArea.setResizable(true);
138:
139: cellArea.drawBoundingRect(true);
140: this .addObjectAtHead(cellArea);
141: //this is a hack to add 1 in width to forec this to repaint and all its children
142: //so that BasicCellArea can draw a bounding rect around it
143: this .setSize(this .getMinimumWidth(), this .getMinimumHeight());
144: }
145:
146: /**
147: * get the minimum height
148: *
149: * @return min height
150: */
151: @Override
152: public int getMinimumHeight() {
153: return cellArea.getMinimumHeight();
154: }
155:
156: /**
157: * get the minimum width
158: *
159: * @return min width
160: */
161: @Override
162: public int getMinimumWidth() {
163: return cellArea.getMinimumWidth()
164: + numberArea.getMinimumWidth();
165: }
166:
167: /**
168: * Lays out this area's child objects.
169: */
170: @Override
171: public void layoutChildren() {
172: Rectangle rect = this .getBoundingRect();
173: numberArea.setBoundingRect(rect.x, rect.y, numberArea
174: .getMinimumWidth(), rect.height);
175: cellArea.setBoundingRect(rect.x + numberArea.getWidth(),
176: rect.y, cellArea.getMinimumWidth() + 1, rect.height);
177: }
178:
179: /**
180: * get output graph port , given a field name
181: *
182: * @param fieldName field name
183: * @return graph port
184: */
185: @Override
186: public IGraphPort getOutputGraphPort(String fieldName) {
187: if (cellArea != null) {
188: return cellArea.getRightGraphPort();
189: }
190: return null;
191: }
192:
193: /**
194: * Gets field name associated with the given port
195: *
196: * @param graphPort graph port
197: * @return field name
198: */
199: @Override
200: public String getFieldName(IGraphPort graphPort) {
201: SQLJoinTable joinTable = (SQLJoinTable) this .getDataObject();
202: SourceTable sourceTable = joinTable.getSourceTable();
203:
204: if (sourceTable != null) {
205: return sourceTable.toString();
206: }
207:
208: return null;
209: }
210:
211: /**
212: * Gets a list of all input and output links
213: *
214: * @return list of input links
215: */
216: @Override
217: public List<JGoLink> getAllLinks() {
218: ArrayList<JGoLink> list = new ArrayList<JGoLink>();
219: if (cellArea != null) {
220: IGraphPort port = cellArea.getRightGraphPort();
221: addLinks(port, list);
222: }
223:
224: return list;
225: }
226:
227: public void setNumber(String num) {
228: this.numberArea.setText(num);
229: this.setSize(this.getMinimumWidth(), this.getMinimumHeight());
230: }
231: }
|