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.Insets;
045: import java.awt.Point;
046: import java.awt.Rectangle;
047: import java.util.ArrayList;
048: import java.util.Iterator;
049:
050: import com.nwoods.jgo.JGoBrush;
051: import com.nwoods.jgo.JGoPen;
052: import com.nwoods.jgo.JGoRectangle;
053:
054: /**
055: * @author Ritesh Adval
056: * @version $Revision$
057: */
058: public class ToolBarArea extends CanvasArea {
059:
060: private JGoRectangle rect;
061: private ArrayList items;
062:
063: private int hGap = 2;
064:
065: /** Creates a new instance of TableToolBarArea */
066: public ToolBarArea() {
067: items = new ArrayList();
068:
069: rect = new JGoRectangle();
070: rect = new JGoRectangle();
071: rect.setSelectable(false);
072: rect.setPen(JGoPen.lightGray);
073: rect
074: .setBrush(JGoBrush.makeStockBrush(new Color(254, 253,
075: 235)));
076: addObjectAtHead(rect);
077:
078: this .insets = new Insets(4, 2, 2, 4);
079:
080: this .setResizable(false);
081: this .setSelectable(false);
082: }
083:
084: /**
085: * add a toolbar item
086: *
087: * @param item toolbar item
088: */
089: public void addToolBarItem(ToolBarItemArea item) {
090: this .addObjectAtTail(item);
091: items.add(item);
092: }
093:
094: /**
095: * remove a tool bar item
096: *
097: * @param item toolbar item
098: */
099: public void removeToolBarItem(ToolBarItemArea item) {
100: this .removeObject(item);
101: items.remove(item);
102: }
103:
104: /**
105: * initialize the tool bar area
106: *
107: * @param loc the location of toolbar
108: */
109: public void initialize(Point loc) {
110:
111: this .setBoundingRect(loc.x, loc.y, getMaximumWidth(),
112: getMaximumHeight());
113:
114: }
115:
116: /**
117: * get the maximum width
118: *
119: * @return maximum width
120: */
121: public int getMaximumWidth() {
122: int maxWidth = insets.left + insets.right;
123:
124: Iterator it = items.iterator();
125: while (it.hasNext()) {
126: ToolBarItemArea item = (ToolBarItemArea) it.next();
127: maxWidth += item.getWidth();
128: }
129:
130: return maxWidth;
131: }
132:
133: /**
134: * get the maximum height
135: *
136: * @return maximum height
137: */
138: public int getMaximumHeight() {
139: int maxHeight = insets.top + insets.bottom;
140:
141: Iterator it = items.iterator();
142: while (it.hasNext()) {
143: ToolBarItemArea item = (ToolBarItemArea) it.next();
144: maxHeight += item.getHeight();
145: break;
146: }
147:
148: return maxHeight;
149: }
150:
151: /**
152: * override this method to handle the changes in the geometry of this area we will lay
153: * out all toolbar items
154: *
155: * @param prevRect previous bounds rectangle
156: */
157: protected void geometryChange(Rectangle prevRect) {
158: // handle any size changes by repositioning all the items
159: if (prevRect.width != getWidth()
160: || prevRect.height != getHeight()) {
161: layoutChildren();
162: } else {
163: super .geometryChange(prevRect);
164: }
165: }
166:
167: /**
168: * layout all the children of this toolbar area
169: */
170: public void layoutChildren() {
171:
172: rect.setBoundingRect(this .getBoundingRect());
173: Insets insets1 = getInsets();
174:
175: //get the bounding rectangle of this table area
176: int x = getLeft() + insets1.left;
177: int y = getTop() + insets1.top;
178: int nextLeft = x;
179:
180: Iterator it = items.iterator();
181: while (it.hasNext()) {
182: ToolBarItemArea item = (ToolBarItemArea) it.next();
183: item.setBoundingRect(nextLeft, y, item.getWidth(), item
184: .getHeight());
185:
186: nextLeft += item.getWidth() + hGap;
187: }
188: }
189:
190: }
|