0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.modules.sql.framework.ui.graph.impl;
0042:
0043: import java.awt.Color;
0044: import java.awt.Insets;
0045: import java.awt.Rectangle;
0046: import java.beans.PropertyChangeEvent;
0047: import java.beans.PropertyChangeListener;
0048:
0049: import javax.swing.Icon;
0050: import javax.swing.ImageIcon;
0051:
0052: import org.netbeans.modules.sql.framework.ui.graph.IDataNode;
0053: import org.netbeans.modules.sql.framework.ui.graph.IGraphPort;
0054: import org.netbeans.modules.sql.framework.ui.graph.IHighlightConfigurator;
0055: import org.netbeans.modules.sql.framework.ui.graph.IHighlightable;
0056:
0057: import com.nwoods.jgo.JGoBrush;
0058: import com.nwoods.jgo.JGoObject;
0059: import com.nwoods.jgo.JGoPen;
0060: import com.nwoods.jgo.JGoRectangle;
0061:
0062: /**
0063: * @author Ritesh Adval
0064: * @version $Revision$
0065: */
0066: public class BasicCellArea extends CanvasArea implements
0067: PropertyChangeListener, IDataNode {
0068:
0069: /**
0070: * TEXT Property
0071: */
0072: public static final String TEXT = "text";
0073:
0074: /**
0075: * constant that describe that this cell has ports on both side of it
0076: */
0077: public static final int LEFT_RIGHT_PORT_AREA = 0;
0078:
0079: /**
0080: * constant that describe that this cell has ports on left side of it
0081: */
0082: public static final int LEFT_PORT_AREA = 1;
0083:
0084: /**
0085: * constant that describe that this cell has ports on right side of it
0086: */
0087: public static final int RIGHT_PORT_AREA = 2;
0088:
0089: /**
0090: * constants
0091: */
0092: public static final int LEFT = 0;
0093: public static final int RIGHT = 1;
0094:
0095: public static final int IMAGE_EXTRACTION = 0;
0096: public static final int IMAGE_VALIDATION = 1;
0097:
0098: public static final int[] IMAGES = new int[] { IMAGE_EXTRACTION,
0099: IMAGE_VALIDATION };
0100:
0101: public static final Color DEFAULT_TEXT_COLOR = new Color(30, 70,
0102: 230); // navy;
0103:
0104: private static final JGoPen DEFAULT_PEN = JGoPen
0105: .makeStockPen(new Color(201, 230, 247));
0106:
0107: protected boolean drawBoundingRect = false;
0108:
0109: // this area has one cell area
0110: protected CellArea cellArea;
0111:
0112: protected JGoRectangle rect;
0113:
0114: // gap between text and icon
0115: protected int iconTextGap = 2;
0116:
0117: protected int leftGap = 5;
0118:
0119: private ColumnPortArea leftPortArea;
0120: private ColumnPortArea rightPortArea;
0121:
0122: // this area has zero or more images also
0123: private BasicImageArea[] imgs = new BasicImageArea[] {
0124: new BasicImageArea() // extraction
0125: , new BasicImageArea() // validation
0126: };
0127:
0128: // default this area will have port at both ends
0129: private int portType = 0;
0130:
0131: // gap between icons
0132: private int iconIconGap = 2;
0133:
0134: private JGoPen linePen = null;
0135:
0136: private boolean arrowPort = true;
0137:
0138: private Object dataObject;
0139:
0140: /** Creates a new instance of BasicCellArea */
0141: public BasicCellArea() {
0142: super ();
0143: this .setSelectable(false);
0144: this .setResizable(false);
0145: this .setDraggable(true);
0146:
0147: rect = new JGoRectangle();
0148: rect.setPen(DEFAULT_PEN);
0149: rect.setBrush(JGoBrush.makeStockBrush(Color.WHITE));
0150: rect.setSelectable(false);
0151: rect.setResizable(false);
0152: addObjectAtHead(rect);
0153:
0154: this .insets = new Insets(2, 1, 2, 1);
0155:
0156: initImageAreas();
0157: }
0158:
0159: /**
0160: * Creates a new instance of BasicCellArea
0161: *
0162: * @param text text
0163: */
0164: public BasicCellArea(String text) {
0165: this ();
0166:
0167: // add cell area
0168: cellArea = new CellArea(text);
0169: cellArea.addPropertyChangeListener(this );
0170: this .addObjectAtTail(cellArea);
0171:
0172: this .setSize(this .getMinimumWidth(), this .getMinimumHeight());
0173: }
0174:
0175: /**
0176: * Creates a new instance of BasicCellArea Assumes image/Icon is for DataExtraction.
0177: *
0178: * @param text text
0179: * @param icon icon
0180: */
0181: public BasicCellArea(String text, Icon icon) {
0182: this (text);
0183:
0184: setImageIcon(IMAGE_EXTRACTION, icon);
0185: this .setSize(this .getMinimumWidth(), this .getMinimumHeight());
0186: }
0187:
0188: /**
0189: * Creates a cell area and specify its port. Assumes image/Icon is for DataExtraction.
0190: *
0191: * @param portType type of port
0192: * @param text text
0193: * @param icon icon
0194: */
0195: public BasicCellArea(int portType, String text, Icon icon) {
0196: this (portType, text);
0197:
0198: setImageIcon(IMAGE_EXTRACTION, icon);
0199:
0200: // Prepare to handle variable number of Icons
0201: BasicImageArea bImg = null;
0202:
0203: for (int i = 0; i < imgs.length; i++) {
0204: if (i != IMAGE_EXTRACTION) {
0205: bImg = imgs[i];
0206: bImg.setSelectable(false);
0207: bImg.setResizable(false);
0208: this .addObjectAtTail(bImg);
0209: }
0210: }
0211:
0212: this .setSize(this .getMinimumWidth(), this .getMinimumHeight());
0213: }
0214:
0215: /**
0216: * create a new instance of BasicCellArea
0217: *
0218: * @param portType port type
0219: * @param text text
0220: */
0221: public BasicCellArea(int aPortType, String text) {
0222: this (text);
0223: portType = aPortType;
0224:
0225: // add port areas
0226: if (portType == LEFT_PORT_AREA
0227: || portType == LEFT_RIGHT_PORT_AREA) {
0228: leftPortArea = new ColumnPortArea(
0229: ColumnPortArea.LEFT_PORT_AREA, 1);
0230: leftPortArea.setInsets(new Insets(0, 0, 0, 0));
0231: this .addObjectAtTail(leftPortArea);
0232: }
0233: if (portType == RIGHT_PORT_AREA
0234: || portType == LEFT_RIGHT_PORT_AREA) {
0235: rightPortArea = new ColumnPortArea(
0236: ColumnPortArea.RIGHT_PORT_AREA, 1);
0237: rightPortArea.setInsets(new Insets(0, 0, 0, 0));
0238: this .addObjectAtTail(rightPortArea);
0239: }
0240:
0241: this .setSize(this .getMinimumWidth(), this .getMinimumHeight());
0242: }
0243:
0244: /**
0245: * set whether text in this area is editable
0246: *
0247: * @param editable text is editable
0248: */
0249: public void setTextEditable(boolean editable) {
0250: cellArea.setTextEditable(editable);
0251: }
0252:
0253: /**
0254: * Is the text editable
0255: *
0256: * @return whether the text is editable
0257: */
0258: public boolean isTextEditable() {
0259: return cellArea.isTextEditable();
0260: }
0261:
0262: /**
0263: * Sets whether a bounding rectangle needs to be drawn
0264: *
0265: * @param drawRect boolean
0266: */
0267: public void drawBoundingRect(boolean drawRect) {
0268: this .drawBoundingRect = drawRect;
0269: }
0270:
0271: /**
0272: * Sets the bounding rectangle's border color
0273: *
0274: * @param color color
0275: */
0276: public void setBoundingRectBorderColor(Color color) {
0277: rect.setPen(JGoPen.makeStockPen(color));
0278: }
0279:
0280: /**
0281: * get the maximum width
0282: *
0283: * @return max width
0284: */
0285: public int getMaximumWidth() {
0286: int minWidth = getInsets().left + getInsets().right;
0287: minWidth += leftGap;
0288:
0289: if (leftPortArea != null) {
0290: minWidth += leftPortArea.getWidth();
0291: }
0292: if (rightPortArea != null) {
0293: minWidth += rightPortArea.getWidth();
0294: }
0295: if (cellArea != null) {
0296: minWidth += cellArea.getMaximumWidth();
0297: minWidth += iconTextGap;
0298: }
0299:
0300: if (imgs != null) {
0301: BasicImageArea bia = null;
0302: for (int i = 0; i < imgs.length; i++) {
0303: bia = imgs[i];
0304: if (bia != null) {
0305: minWidth += bia.getWidth() + iconIconGap;
0306: }
0307: }
0308:
0309: }
0310: return minWidth;
0311: }
0312:
0313: /**
0314: * get the minimum width of this cell area
0315: *
0316: * @return min width
0317: */
0318: public int getMinimumWidth() {
0319: int minWidth = getInsets().left + getInsets().right;
0320: minWidth += leftGap;
0321:
0322: if (leftPortArea != null) {
0323: minWidth += leftPortArea.getWidth();
0324: }
0325: if (rightPortArea != null) {
0326: minWidth += rightPortArea.getWidth();
0327: }
0328: if (cellArea != null) {
0329: minWidth += cellArea.getMinimumWidth();
0330: minWidth += iconTextGap;
0331: }
0332:
0333: if (imgs != null) {
0334: BasicImageArea bia = null;
0335: for (int i = 0; i < imgs.length; i++) {
0336: bia = imgs[i];
0337: if (bia != null) {
0338: minWidth += bia.getWidth() + iconIconGap;
0339: }
0340: }
0341: }
0342:
0343: return minWidth;
0344: }
0345:
0346: /**
0347: * get the minimum height of this cell area
0348: *
0349: * @return minimum height of this cell area
0350: */
0351: public int getMinimumHeight() {
0352: int minHeight = getInsets().top + getInsets().bottom;
0353:
0354: int height = 0;
0355: if (cellArea != null) {
0356: height = cellArea.getHeight();
0357: }
0358:
0359: if (imgs != null) {
0360: BasicImageArea bia = null;
0361: for (int i = 0; i < imgs.length; i++) {
0362: bia = imgs[i];
0363: if ((bia != null) && (height < bia.getHeight())) {
0364: height = bia.getHeight();
0365: }
0366: }
0367: }
0368:
0369: minHeight += height;
0370: return minHeight;
0371: }
0372:
0373: /**
0374: * Sets a ImageIcon for the icon Type specified.
0375: *
0376: * @param iconType can be IMAGE_EXTRACTION, IMAGE_VALIDATION etc
0377: * @param icon
0378: * @param toolTip
0379: */
0380: public void setImageIcon(int iconType, Icon icon, String toolTip) {
0381:
0382: if (iconType >= IMAGES.length) {
0383: return;
0384: }
0385:
0386: if (icon != null) {
0387: if (imgs != null) {
0388: BasicImageArea imageArea = imgs[iconType];
0389: if (imageArea != null) {
0390: imageArea.setVisible(true);
0391: ImageIcon imgIcon = (ImageIcon) icon;
0392: imageArea.loadImage(imgIcon.getImage(), false);
0393: imageArea.setSize(
0394: imgIcon.getImage().getWidth(null), imgIcon
0395: .getImage().getHeight(null));
0396: if (toolTip != null) {
0397: imageArea.setToolTipText(toolTip);
0398: }
0399: }
0400: }
0401: } else {
0402: if (imgs != null) {
0403: BasicImageArea imageArea = imgs[iconType];
0404: if (imageArea != null) {
0405: imageArea.setVisible(false);
0406: }
0407: }
0408: }
0409:
0410: layoutChildren();
0411: }
0412:
0413: /**
0414: * Sets a ImageIcon for the icon Type specified.
0415: *
0416: * @param iconType can be IMAGE_EXTRACTION, IMAGE_VALIDATION etc
0417: * @param icon
0418: */
0419: public void setImageIcon(int iconType, Icon icon) {
0420: setImageIcon(iconType, icon, null);
0421: }
0422:
0423: /**
0424: * Sets image for DataExtraction icon.
0425: *
0426: * @param icon
0427: */
0428: public void setDataExtractionImageIcon(Icon icon) {
0429: setImageIcon(IMAGE_EXTRACTION, icon);
0430: }
0431:
0432: /**
0433: * Sets image for DataExtraction icon.
0434: *
0435: * @param icon
0436: */
0437: public void setDataExtractionImageIcon(Icon icon, String toolTip) {
0438: setImageIcon(IMAGE_EXTRACTION, icon, toolTip);
0439: }
0440:
0441: /**
0442: * set the image in this cell area
0443: *
0444: * @param icon icon
0445: * @deprecated 12/28/2004 Use setImage(int iconType, Icon icon) or
0446: * setDataExtractionImage(Icon icon).
0447: */
0448: public void setImage(Icon icon) {
0449: setImageIcon(IMAGE_EXTRACTION, icon);
0450: }
0451:
0452: /**
0453: * @param icon
0454: * @param toolTip
0455: * @deprecated 12/28/2004 Use setImage(int iconType, Icon icon, String toolTip) or
0456: * setDataExtractionImage(Icon icon, String toolTip).
0457: */
0458: public void setImage(Icon icon, String toolTip) {
0459: if (icon != null) {
0460: this .setImageIcon(IMAGE_EXTRACTION, icon, toolTip);
0461: }
0462: }
0463:
0464: /**
0465: * set the text in this cell area
0466: *
0467: * @param text text
0468: */
0469: public void setText(String text) {
0470: cellArea.setText(text);
0471: }
0472:
0473: /**
0474: * set the text alignment
0475: *
0476: * @param align text alignment
0477: */
0478: public void setTextAlignment(int align) {
0479: if (cellArea != null) {
0480: cellArea.setTextAlignment(align);
0481: }
0482: }
0483:
0484: /**
0485: * set the gap between icon and text
0486: *
0487: * @param iconTextGap gap between icon and text
0488: */
0489: public void setIconTextGap(int iconTextGap) {
0490: this .iconTextGap = iconTextGap;
0491: }
0492:
0493: /**
0494: * set the gap between icons
0495: *
0496: * @param iconTextGap gap between icons
0497: */
0498: public void setIconIconGap(int iconIconGap) {
0499: this .iconIconGap = iconIconGap;
0500: }
0501:
0502: /**
0503: * get gap between icon and text
0504: *
0505: * @return gap between icon and text
0506: */
0507: public int getIconTextGap() {
0508: return iconTextGap;
0509: }
0510:
0511: /**
0512: * get gap between the icons
0513: *
0514: * @return gap between icons
0515: */
0516: public int getIconIconGap() {
0517: return iconIconGap;
0518: }
0519:
0520: /**
0521: * set the gap from the left where this area should start rendering cell area it
0522: * contains
0523: *
0524: * @param leftGap left gap
0525: */
0526: public void setLeftGap(int leftGap) {
0527: this .leftGap = leftGap;
0528: }
0529:
0530: /**
0531: * get the left gap of this cell area
0532: *
0533: * @return left gap
0534: */
0535: public int getLeftGap() {
0536: return leftGap;
0537: }
0538:
0539: /**
0540: * get the port width of this cell area
0541: *
0542: * @return port width
0543: */
0544: public int getPortAreaWidth() {
0545: if (leftPortArea != null) {
0546: return leftPortArea.getWidth();
0547: } else if (rightPortArea != null) {
0548: return rightPortArea.getWidth();
0549: }
0550: return 0;
0551: }
0552:
0553: /**
0554: * get the left side graph port this area
0555: *
0556: * @return left port
0557: */
0558: public IGraphPort getLeftGraphPort() {
0559: if (leftPortArea != null) {
0560: PortArea pArea = leftPortArea.getPortAreaAt(0);
0561: return pArea.getGraphPort();
0562: }
0563: return null;
0564: }
0565:
0566: /**
0567: * get the right graph port of this cell
0568: *
0569: * @return right side graph port
0570: */
0571: public IGraphPort getRightGraphPort() {
0572: if (rightPortArea != null) {
0573: PortArea pArea = rightPortArea.getPortAreaAt(0);
0574: return pArea.getGraphPort();
0575: }
0576: return null;
0577: }
0578:
0579: /**
0580: * get the text of cell area
0581: *
0582: * @return text
0583: */
0584: public String getText() {
0585: if (cellArea != null) {
0586: return cellArea.getText();
0587: }
0588:
0589: return null;
0590: }
0591:
0592: public String getOriginalText() {
0593: if (cellArea != null) {
0594: return cellArea.getOriginalText();
0595: }
0596:
0597: return null;
0598: }
0599:
0600: /**
0601: * get the line pen
0602: *
0603: * @return line pen
0604: */
0605: public JGoPen getLinePen() {
0606: return (linePen != null) ? linePen : DEFAULT_PEN;
0607: }
0608:
0609: /**
0610: * set the line pen
0611: *
0612: * @param pen line pen
0613: */
0614: public void setLinePen(JGoPen pen) {
0615: JGoPen oldPen = linePen;
0616: if (oldPen != pen) {
0617: linePen = pen;
0618:
0619: layoutChildren();
0620: }
0621: }
0622:
0623: /**
0624: * layout the children of list area
0625: */
0626: public void layoutChildren() {
0627: if (rect != null) {
0628: rect.setPen(getLinePen());
0629: }
0630:
0631: if (leftPortArea != null) {
0632: leftPortArea.setLinePen(getLinePen());
0633: }
0634:
0635: if (rightPortArea != null) {
0636: rightPortArea.setLinePen(getLinePen());
0637: }
0638:
0639: if (arrowPort) {
0640: layoutChildrenForArrowPort();
0641: } else {
0642: layoutChildrenWithoutArrowPort();
0643: }
0644:
0645: }
0646:
0647: private void layoutChildrenForArrowPort() {
0648: if (drawBoundingRect) {
0649: rect.setBoundingRect(this .getBoundingRect());
0650: }
0651: int rectleft = getLeft();
0652: int recttop = getTop();
0653: int rectwidth = getWidth();
0654: int rectheight = getHeight();
0655:
0656: int width = rectwidth - insets.left - insets.right;
0657: int height = rectheight - insets.top - insets.bottom;
0658:
0659: int leftPortAreaW = 0;
0660: int righPortAreaW = 0;
0661:
0662: if (leftPortArea != null) {
0663: leftPortArea.setBoundingRect(rectleft, recttop,
0664: leftPortArea.getWidth(), rectheight);
0665: leftPortAreaW = leftPortArea.getWidth();
0666: }
0667:
0668: if (rightPortArea != null) {
0669: rightPortArea.setBoundingRect(rectleft + rectwidth
0670: - rightPortArea.getWidth(), recttop, rightPortArea
0671: .getWidth(), rectheight);
0672: righPortAreaW = rightPortArea.getWidth();
0673: }
0674:
0675: if (cellArea != null) {
0676: if (leftPortArea != null) {
0677: cellArea.setSpotLocation(JGoObject.Left, leftPortArea,
0678: JGoObject.Right);
0679: } else {
0680: cellArea.setSpotLocation(JGoObject.Left, this ,
0681: JGoObject.Left);
0682: }
0683: cellArea.setLeft(cellArea.getLeft() + leftGap);
0684:
0685: int w = width - leftPortAreaW - righPortAreaW - leftGap
0686: - iconTextGap;
0687:
0688: BasicImageArea bia = null;
0689:
0690: if (imgs != null) {
0691: for (int i = 0; i < imgs.length; i++) {
0692: bia = imgs[i];
0693: if ((bia != null) && (bia.isVisible())) {
0694: w = w - bia.getWidth() - iconIconGap;
0695: }
0696: }
0697: }
0698: cellArea.setSize(w, height);
0699: }
0700:
0701: BasicImageArea bia = null;
0702: BasicImageArea prevImage = null;
0703: boolean firstImage = true;
0704:
0705: if (imgs != null) {
0706: for (int i = 0; i < imgs.length; i++) {
0707: bia = imgs[i];
0708: if ((bia != null) && (bia.isVisible())) {
0709: if (cellArea != null) {
0710:
0711: if (prevImage == null) {
0712: bia.setSpotLocation(JGoObject.Left,
0713: cellArea, JGoObject.Right);
0714: } else {
0715: bia.setSpotLocation(JGoObject.Left,
0716: prevImage, JGoObject.Right);
0717: }
0718:
0719: if (firstImage) {
0720: bia.setLeft(bia.getLeft() + iconTextGap);
0721: firstImage = false;
0722: } else {
0723: bia.setLeft(bia.getLeft() + iconIconGap);
0724: }
0725:
0726: prevImage = bia;
0727:
0728: } else if (leftPortArea != null) {
0729: bia.setSpotLocation(JGoObject.Left,
0730: leftPortArea, JGoObject.Right);
0731: } else {
0732: bia.setSpotLocation(JGoObject.Left, this ,
0733: JGoObject.Left);
0734: }
0735: }
0736: }// for loop
0737: } // if imgs != null
0738: }
0739:
0740: protected boolean geometryChangeChild(JGoObject child,
0741: Rectangle prevRect) {
0742: // do nothing as we do not want to listen to changes in children
0743: return true;
0744: }
0745:
0746: private void layoutChildrenWithoutArrowPort() {
0747: if (drawBoundingRect) {
0748: rect.setBoundingRect(this .getBoundingRect());
0749: }
0750: int rectleft = getLeft();
0751: int recttop = getTop();
0752: int rectwidth = getWidth();
0753: int rectheight = getHeight();
0754:
0755: int width = rectwidth - insets.left - insets.right;
0756: int height = rectheight - insets.top - insets.bottom;
0757:
0758: if (leftPortArea != null) {
0759: leftPortArea.setBoundingRect(rectleft, recttop, width,
0760: rectheight);
0761: }
0762:
0763: if (rightPortArea != null) {
0764: rightPortArea.setBoundingRect(rectleft + rectwidth,
0765: recttop, width, rectheight);
0766: }
0767:
0768: if (cellArea != null) {
0769:
0770: cellArea.setSpotLocation(JGoObject.Left, this ,
0771: JGoObject.Left);
0772: cellArea.setLeft(cellArea.getLeft() + leftGap);
0773:
0774: int w = width - leftGap - iconTextGap;
0775:
0776: BasicImageArea bia = null;
0777:
0778: if (imgs != null) {
0779: for (int i = 0; i < imgs.length; i++) {
0780: bia = imgs[i];
0781: if (bia != null) {
0782: w = w - bia.getWidth() - iconIconGap;
0783: }
0784: }
0785: }
0786:
0787: cellArea.setSize(w, height);
0788: }
0789:
0790: BasicImageArea bia = null;
0791: BasicImageArea prevImage = null;
0792: boolean firstImage = true;
0793:
0794: if (imgs != null) {
0795: for (int i = 0; i < imgs.length; i++) {
0796: bia = imgs[i];
0797: if ((bia != null) && (bia.isVisible())) {
0798: if (cellArea != null) {
0799: bia.setSpotLocation(JGoObject.Left, cellArea,
0800: JGoObject.Right);
0801:
0802: if (prevImage == null) {
0803: bia.setSpotLocation(JGoObject.Left,
0804: cellArea, JGoObject.Right);
0805: } else {
0806: bia.setSpotLocation(JGoObject.Left,
0807: prevImage, JGoObject.Right);
0808: }
0809: int topGap = this .getHeight() - bia.getHeight();
0810: if (topGap > 0) {
0811: bia.setTop(this .getTop() + topGap / 2);
0812: }
0813:
0814: if (firstImage) {
0815: bia.setLeft(bia.getLeft() + iconTextGap);
0816: firstImage = false;
0817: } else {
0818: bia.setLeft(bia.getLeft() + iconIconGap);
0819: }
0820: } else if (leftPortArea != null) {
0821: bia.setSpotLocation(JGoObject.Left,
0822: leftPortArea, JGoObject.Right);
0823: } else {
0824: bia.setSpotLocation(JGoObject.Left, this ,
0825: JGoObject.Left);
0826: }
0827: }
0828: }
0829: }
0830:
0831: }
0832:
0833: /**
0834: * This method gets called when a bound property is changed.
0835: *
0836: * @param evt A PropertyChangeEvent object describing the event source and the
0837: * property that has changed.
0838: */
0839: public void propertyChange(PropertyChangeEvent evt) {
0840: if (evt.getPropertyName().equals(CellArea.TEXT)) {
0841: this .firePropertyChangeEvent(TEXT, evt.getOldValue(), evt
0842: .getNewValue());
0843: }
0844: }
0845:
0846: public void setBackGroundColor(Color bkColor) {
0847: rect.setBrush(JGoBrush.makeStockBrush(bkColor));
0848: this .cellArea.setBackGroundColor(bkColor);
0849: this .layoutChildren();
0850: }
0851:
0852: public void setBorder(JGoPen borderPen) {
0853: rect.setPen(borderPen);
0854: }
0855:
0856: public Object getDataObject() {
0857: return dataObject;
0858: }
0859:
0860: public void setDataObject(Object obj) {
0861: this .dataObject = obj;
0862: }
0863:
0864: protected void initImageAreas() {
0865: // Prepare to handle variable number of Icons
0866: BasicImageArea bImg = null;
0867:
0868: for (int i = 0; i < imgs.length; i++) {
0869: bImg = imgs[i];
0870: if (bImg != null) {
0871: bImg.setSelectable(false);
0872: bImg.setResizable(false);
0873: this .addObjectAtTail(bImg);
0874: }
0875: }
0876: }
0877:
0878: /**
0879: * Sets text color to the given value.
0880: *
0881: * @param textColor new text color
0882: */
0883: public void setTextColor(Color textColor) {
0884: if (cellArea != null) {
0885: cellArea.setTextColor(textColor != null ? textColor
0886: : DEFAULT_TEXT_COLOR);
0887: }
0888: }
0889:
0890: /**
0891: * Gets current text color.
0892: *
0893: * @return current text color
0894: */
0895: public Color getTextColor() {
0896: return (cellArea != null) ? cellArea.getTextColor()
0897: : DEFAULT_TEXT_COLOR;
0898: }
0899:
0900: /**
0901: * Sets background brush to the given value.
0902: *
0903: * @param newBrush new JGoBrush to use in painting background
0904: */
0905: public void setBrush(JGoBrush newBrush) {
0906: repaintBackground(newBrush);
0907: }
0908:
0909: protected void repaintBackground(JGoBrush aBrush) {
0910: if (aBrush != null) {
0911: Color c = aBrush.getColor();
0912: if (cellArea != null) {
0913: cellArea.setBackGroundColor(c);
0914: }
0915:
0916: if (leftPortArea != null) {
0917: leftPortArea.setBackgroundColor(c);
0918: }
0919:
0920: if (rightPortArea != null) {
0921: rightPortArea.setBackgroundColor(c);
0922: }
0923:
0924: if (rect != null) {
0925: rect.setBrush(aBrush);
0926: }
0927: }
0928: }
0929:
0930: /**
0931: * Extends BasicCellArea to implement IHighlightable interface, to allow for a change
0932: * in presentation/appearance whenever a mouse cursor hovers over an instance.
0933: *
0934: * @author Jonathan Giron
0935: * @version $Revision$
0936: */
0937: public static class Highlightable extends BasicCellArea implements
0938: IHighlightable {
0939: private boolean highlightEnabled = true;
0940:
0941: private IHighlightConfigurator highlightConfigurator = new HighlightConfiguratorImpl();
0942:
0943: /**
0944: * Constructs a default instance of BasicCellArea.Highlightable.
0945: */
0946: public Highlightable() {
0947: super ();
0948: }
0949:
0950: /**
0951: * Constructs an instance of BasicCellArea.Highlightable with the given text.
0952: *
0953: * @param text text label for the new instance
0954: */
0955: public Highlightable(String text) {
0956: super (text);
0957: }
0958:
0959: /**
0960: * Constructs an instance of BasicCellArea.Highlightable with the given port type
0961: * and text.
0962: *
0963: * @param portType indicates what kind of port to display with the new instance
0964: * @param text text label for the new instance
0965: */
0966: public Highlightable(int portType, String text) {
0967: super (portType, text);
0968: }
0969:
0970: /**
0971: * Constructs an instance of BasicCellArea.Highlightable with the given port type,
0972: * text, and icon.
0973: *
0974: * @param portType indicates what kind of port to display with the new instance
0975: * @param text text label for the new instance
0976: * @param icon icon for the new instance
0977: */
0978: public Highlightable(int portType, String text, Icon icon) {
0979: super (portType, text, icon);
0980: // TODO Auto-generated constructor stub
0981: }
0982:
0983: /**
0984: * Gets current JGoBrush for this instance
0985: *
0986: * @return current JGoBrush
0987: */
0988: public JGoBrush getBrush() {
0989: return (highlightConfigurator != null) ? highlightConfigurator
0990: .getNormalBrush()
0991: : JGoBrush
0992: .makeStockBrush(IHighlightConfigurator.DEFAULT_BASIC_COLOR);
0993: }
0994:
0995: /**
0996: * @see org.netbeans.modules.sql.framework.ui.graph.IHighlightable#setHighlighted(boolean)
0997: */
0998: public void setHighlighted(boolean shouldHighlight) {
0999: if (highlightConfigurator == null) {
1000: return;
1001: }
1002:
1003: if (shouldHighlight && highlightEnabled) {
1004: repaintBackground(highlightConfigurator.getHoverBrush());
1005: } else {
1006: repaintBackground(highlightConfigurator
1007: .getNormalBrush());
1008: }
1009: }
1010:
1011: /**
1012: * @see org.netbeans.modules.sql.framework.ui.graph.IHighlightable#setHighlightEnabled(boolean)
1013: */
1014: public void setHighlightEnabled(boolean enableHighlighting) {
1015: highlightEnabled = enableHighlighting;
1016: }
1017:
1018: /**
1019: * @see org.netbeans.modules.sql.framework.ui.graph.IHighlightable#isHighlightEnabled()
1020: */
1021: public boolean isHighlightEnabled() {
1022: return highlightEnabled;
1023: }
1024:
1025: /**
1026: * @see org.netbeans.modules.sql.framework.ui.graph.IHighlightable#getHighlightConfigurator()
1027: */
1028: public IHighlightConfigurator getHighlightConfigurator() {
1029: return highlightConfigurator;
1030: }
1031:
1032: /**
1033: * @see org.netbeans.modules.sql.framework.ui.graph.IHighlightable#setHighlightConfigurator(org.netbeans.modules.sql.framework.ui.graph.IHighlightConfigurator)
1034: */
1035: public void setHighlightConfigurator(IHighlightConfigurator hc) {
1036: highlightConfigurator = hc;
1037: if (hc != null) {
1038: repaintBackground(hc.getNormalBrush());
1039: } else {
1040: repaintBackground(JGoBrush
1041: .makeStockBrush(IHighlightConfigurator.DEFAULT_BASIC_COLOR));
1042: }
1043: }
1044:
1045: /**
1046: * @see org.netbeans.modules.sql.framework.ui.graph.impl.BasicCellArea#setBrush(com.nwoods.jgo.JGoBrush)
1047: */
1048: public void setBrush(JGoBrush newBrush) {
1049: if (highlightConfigurator != null) {
1050: highlightConfigurator.setNormalBrush(newBrush);
1051: }
1052: super.setBrush(newBrush);
1053: }
1054: }
1055: }
|