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.graph;
042:
043: import java.awt.Color;
044: import java.awt.Cursor;
045: import java.awt.Insets;
046: import java.awt.Point;
047: import java.awt.Rectangle;
048: import java.awt.event.ItemListener;
049:
050: import org.netbeans.modules.sql.framework.ui.graph.impl.BasicText;
051: import org.netbeans.modules.sql.framework.ui.graph.impl.CanvasArea;
052: import org.netbeans.modules.sql.framework.ui.graph.impl.CheckBoxArea;
053:
054: import com.nwoods.jgo.JGoBrush;
055: import com.nwoods.jgo.JGoPen;
056: import com.nwoods.jgo.JGoRectangle;
057: import com.nwoods.jgo.JGoView;
058: import net.java.hulp.i18n.Logger;
059: import org.netbeans.modules.etl.logger.Localizer;
060: import org.netbeans.modules.etl.logger.LogUtil;
061:
062: /**
063: * Extension of CanvasArea to show toggle control for parentheses surrounding a given operator.
064: *
065: * @author Ritesh Adval
066: * @author Jonathan Giron
067: * @version $Revision$
068: */
069: public class ParenthesisCheckBoxArea extends CanvasArea {
070: private JGoRectangle rect;
071:
072: private CheckBoxArea cbArea;
073:
074: private BasicText title;
075:
076: private int checkboxTextGap = 1;
077:
078: private static transient final Logger mLogger = LogUtil
079: .getLogger(ParenthesisCheckBoxArea.class.getName());
080:
081: private static transient final Localizer mLoc = Localizer.get();
082:
083: /**
084: * Constructs a default instance of ParenthesisCheckBoxArea.
085: */
086: ParenthesisCheckBoxArea() {
087: this .setSelectable(false);
088: this .setResizable(false);
089:
090: //add the bounding display rectangle
091: rect = new JGoRectangle();
092:
093: rect.setPen(JGoPen.makeStockPen(Color.WHITE));
094: rect
095: .setBrush(JGoBrush.makeStockBrush(new Color(241, 249,
096: 253)));
097: rect.setSelectable(false);
098: rect.setResizable(false);
099: addObjectAtHead(rect);
100:
101: // Add check box
102: cbArea = new CheckBoxArea();
103: String nbBundle1 = mLoc
104: .t("PRSR001: Display or hide parentheses in SQL");
105: String toolTipText = Localizer.parse(nbBundle1);
106: cbArea.setToolTipText(toolTipText);
107: cbArea.setBackground(new Color(221, 235, 246));
108: addObjectAtTail(cbArea);
109:
110: //add text of title
111: String nbBundle2 = mLoc.t("PRSR001: Use parentheses ( )");
112: String titleText = Localizer.parse(nbBundle2);
113: title = new BasicText(titleText);
114: title.setEditable(false);
115: title.setSelectable(false);
116: title.setResizable(false);
117: title.setTransparent(true);
118: title.setBold(false);
119:
120: title.setShowDot(false);
121: addObjectAtTail(title);
122:
123: this .insets = new Insets(1, 3, 1, 3);
124: }
125:
126: /**
127: * layout the children of this cell area
128: */
129: public void layoutChildren() {
130: Rectangle rectangle = this .getBoundingRect();
131: rect.setBoundingRect(rectangle);
132:
133: Insets insets1 = getInsets();
134:
135: int x = this .getLeft() + insets1.left;
136: int y = this .getTop() + insets1.top;
137: int width = this .getWidth() - insets1.left - insets1.right;
138: int height = this .getHeight() - insets1.top - insets1.bottom;
139:
140: cbArea.setBoundingRect(x, y, cbArea.getWidth(), height);
141: int yCenteringAdjustment = Math.max(0,
142: (cbArea.getHeight() - title.getHeight()) / 2);
143: title.setBoundingRect(x + cbArea.getWidth() + checkboxTextGap,
144: y + yCenteringAdjustment, width - cbArea.getWidth()
145: - checkboxTextGap, height
146: - (yCenteringAdjustment * 2));
147: }
148:
149: /**
150: * @see org.netbeans.modules.sql.framework.ui.graph.ICanvasInterface#getMinimumWidth()
151: */
152: public int getMinimumWidth() {
153: Insets insets1 = getInsets();
154: int minWidth = insets1.left + insets1.right;
155: minWidth += cbArea.getWidth();
156: minWidth += checkboxTextGap;
157: minWidth += title.getMaximumWidth();
158:
159: return minWidth;
160: }
161:
162: /**
163: * @see org.netbeans.modules.sql.framework.ui.graph.ICanvasInterface#getMinimumHeight()
164: */
165: public int getMinimumHeight() {
166: int minHeight = cbArea.getHeight();
167:
168: if (title.getHeight() > minHeight) {
169: minHeight = title.getHeight();
170: }
171:
172: minHeight += getInsets().top + getInsets().bottom;
173: return minHeight;
174: }
175:
176: /**
177: * @see org.netbeans.modules.sql.framework.ui.graph.ICanvasInterface#getMaximumHeight()
178: */
179: public int getMaximumHeight() {
180: // For now, fix this check box area to be uniform in height regardless of the
181: // whether its parent JGoArea is resized.
182: return getMinimumHeight();
183: }
184:
185: /**
186: * Change the cursor at the port
187: *
188: * @param flags
189: */
190: public boolean doUncapturedMouseMove(int flags, Point dc, Point vc,
191: JGoView view) {
192: if (getLayer() != null && getLayer().isModifiable()) {
193: view.setCursor(Cursor
194: .getPredefinedCursor(Cursor.DEFAULT_CURSOR));
195: return true;
196: }
197: return false;
198: }
199:
200: /**
201: * Adds the given item listener to this control.
202: *
203: * @param l ItemListener to be added
204: */
205: public void addItemListener(ItemListener l) {
206: this .cbArea.addItemListener(l);
207: }
208:
209: /**
210: * Removes the given item listener from this control.
211: *
212: * @param l ItemListener to be removed
213: */
214: public void removeItemListener(ItemListener l) {
215: this .cbArea.removeItemListener(l);
216: }
217:
218: /**
219: * whether to select or deselect check box ui
220: */
221: public void setShowParenthesis(boolean select) {
222: this .cbArea.setSelected(select);
223: }
224:
225: /**
226: * Sets background color.
227: *
228: * @param c new background color
229: */
230: public void setBackgroundColor(Color c) {
231: rect.setBrush(JGoBrush.makeStockBrush(c));
232: cbArea.setBackground(c);
233: title.setTransparent(true);
234: }
235:
236: /**
237: * Sets color of text label associated with the check box.
238: *
239: * @param c new text color
240: */
241: public void setTextColor(Color c) {
242: title.setTextColor(c);
243: }
244: }
|