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:
042: package org.netbeans.modules.sql.framework.ui.graph.impl;
043:
044: import java.awt.Color;
045: import java.awt.Dimension;
046: import java.awt.Insets;
047: import java.awt.Rectangle;
048:
049: import com.nwoods.jgo.JGoBrush;
050: import com.nwoods.jgo.JGoPen;
051: import com.nwoods.jgo.JGoRectangle;
052: import com.nwoods.jgo.JGoText;
053: import com.nwoods.jgo.JGoView;
054:
055: /**
056: * @author Ritesh Adval
057: * @version $Revision$
058: */
059: public class HeaderCellArea extends CanvasArea {
060:
061: private BasicText text;
062:
063: private JGoRectangle rect;
064:
065: /**
066: * Creates a new instance of HeaderCellArea
067: *
068: * @param columnName name of the column
069: */
070: public HeaderCellArea(String columnName) {
071: super ();
072: this .setSelectable(false);
073: this .setResizable(false);
074:
075: text = new BasicText(columnName);
076: text.setSelectable(false);
077: text.setResizable(false);
078: text.setDraggable(false);
079:
080: //make it transparent so that we can see the effect of JGo3DRect
081: text.setTransparent(true);
082: //align the text to center
083: text.setAlignment(JGoText.ALIGN_CENTER);
084: //make the text bold
085: text.setBold(true);
086: this .addObjectAtTail(text);
087:
088: rect = new JGoRectangle();
089: rect.setSelectable(false);
090: rect.setResizable(false);
091:
092: rect.setPen(JGoPen.makeStockPen(Color.lightGray));
093: rect
094: .setBrush(JGoBrush.makeStockBrush(new Color(254, 253,
095: 235)));
096: addObjectAtHead(rect);
097:
098: //set the insets on header cell
099: layoutChildren();
100: }
101:
102: /**
103: * get the minimum size of the area
104: *
105: * @return minimum size
106: */
107: public Dimension getMinimumSize() {
108:
109: int w = text.getWidth() + insets.left + insets.right;
110: int h = text.getHeight() + insets.top + insets.bottom;
111: return new Dimension(w, h);
112: }
113:
114: /**
115: * paint this area
116: *
117: * @param g Graphics2D
118: * @param view view
119: */
120: public void paint(java.awt.Graphics2D g, JGoView view) {
121: super .paint(g, view);
122:
123: Insets insets1 = getInsets();
124:
125: //get the bounding rectangle of this table area
126: int width = getWidth() - insets1.left - insets1.right;
127:
128: int textWidth = text.getWidth();
129: if (width < textWidth) {
130:
131: }
132: }
133:
134: /**
135: * override this method to handle the changes in the geometry of this area we will lay
136: * out all the cell again
137: *
138: * @param prevRect previous bounds rectangle
139: */
140: protected void geometryChange(Rectangle prevRect) {
141: // handle any size changes by repositioning all the items
142: if (prevRect.width != getWidth()
143: || prevRect.height != getHeight()) {
144: layoutChildren();
145: } else {
146: super .geometryChange(prevRect);
147: }
148: }
149:
150: /**
151: * layout the children of this cell area
152: */
153: public void layoutChildren() {
154: Rectangle rectangle = this.getBoundingRect();
155: text.setBoundingRect(rectangle);
156: rect.setBoundingRect(rectangle);
157:
158: }
159:
160: }
|