001/*
002 * Copyright (c) 2003-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.ecoinformatics.seek.querybuilder;
031
032import java.awt.Polygon;
033
034/**
035 * @author Rod Spears
036 * 
037 *         This class represents a single relationship between two fields in
038 *         different tables
039 */
040public class DBTableJoinItem {
041        protected Polygon mPolygons[] = new Polygon[3];
042        protected boolean mIsChanged = true;
043
044        protected boolean mIsSelected = false;
045
046        protected DBTableField mItemLeft;
047        protected DBTableField mItemRight;
048
049        /**
050         * Constructor with DBTableFields
051         * 
052         * @param aItemLeft
053         * @param aItemRight
054         */
055        public DBTableJoinItem(DBTableField aItemLeft, DBTableField aItemRight) {
056                for (int i = 0; i < mPolygons.length; i++)
057                        mPolygons[i] = new Polygon();
058
059                mItemLeft = aItemLeft;
060                mItemRight = aItemRight;
061        }
062
063        /**
064         * Return Left side item of Join
065         * 
066         * @return the object on the left side of the join
067         */
068        public DBTableField getItemLeft() {
069                return mItemLeft;
070        }
071
072        /**
073         * Return Right side item of Join
074         * 
075         * @return the object on the left side of the join
076         */
077        public DBTableField getItemRight() {
078                return mItemRight;
079        }
080
081        /**
082         * Returns the array of X coord locations
083         * 
084         * @return array
085         */
086        public Polygon[] getPolygons() {
087                return mPolygons;
088        }
089
090        /**
091         * 
092         * @param aX1
093         * @param aY1
094         * @param aX2
095         * @param aY2
096         */
097        private void adjustPolygon(Polygon aPoly, int aX1, int aY1, int aX2, int aY2) {
098                boolean firstLeft = aX1 < aX2;
099                boolean firstHigher = aY1 < aY2;
100                boolean xEqual = aX1 == aX2;
101                boolean yEqual = aY1 == aY2;
102
103                aPoly.reset();
104
105                if (aX1 == aX2) {
106                        aPoly.addPoint(aX1 - 2, aY1);
107                        aPoly.addPoint(aX1 + 2, aY1);
108                        aPoly.addPoint(aX1 + 2, aY2);
109                        aPoly.addPoint(aX1 - 2, aY2);
110                        aPoly.addPoint(aX1 - 2, aY1);
111
112                } else if (aY1 == aY2) {
113                        aPoly.addPoint(aX1, aY1 - 2);
114                        aPoly.addPoint(aX2, aY1 - 2);
115                        aPoly.addPoint(aX2, aY1 + 2);
116                        aPoly.addPoint(aX1, aY1 + 2);
117                        aPoly.addPoint(aX1, aY1 - 2);
118
119                } else {
120                        aPoly.addPoint(aX1, aY1 - 3);
121                        aPoly.addPoint(aX2, aY2 - 3);
122                        aPoly.addPoint(aX2, aY2 + 3);
123                        aPoly.addPoint(aX1, aY1 + 3);
124                        aPoly.addPoint(aX1, aY1 - 3);
125                        /*
126                         * if (aX1 < aY1) { if (aY1 < aY2) { aPoly.addPoint(aX1, aY1-2);
127                         * aPoly.addPoint(aX2, aY2-2); aPoly.addPoint(aX2, aY2+2);
128                         * aPoly.addPoint(aX1, aY1+2); aPoly.addPoint(aX1, aY1-2); } else {
129                         * aPoly.addPoint(aX1, aY1-2); aPoly.addPoint(aX2, aY2-2);
130                         * aPoly.addPoint(aX2, aY2+2); aPoly.addPoint(aX1, aY1+2);
131                         * aPoly.addPoint(aX1, aY1-2); } } else { if (aY1 < aY2) {
132                         * 
133                         * } else { aPoly.addPoint(aX1, aY1-2); aPoly.addPoint(aX2, aY2-2);
134                         * aPoly.addPoint(aX2, aY2+2); aPoly.addPoint(aX1, aY1+2);
135                         * aPoly.addPoint(aX1, aY1-2);
136                         * 
137                         * } }
138                         */
139                }
140        }
141
142        /**
143         * Change contents of one of the polygons
144         * 
145         * @param aInx
146         *            the index of the polygon
147         * @param aX1
148         *            X point
149         * @param aY1
150         *            Y point
151         * @param aX2
152         *            X point
153         * @param aY2
154         *            Y point
155         */
156        public void changePolygon(int aInx, int aX1, int aY1, int aX2, int aY2) {
157                adjustPolygon(mPolygons[aInx], aX1, aY1, aX2, aY2);
158                mIsChanged = true;
159        }
160
161        /**
162         * Sets that the polygons have changed
163         * 
164         * @param aIsChanged
165         */
166        public void setChanged(boolean aIsChanged) {
167                mIsChanged = aIsChanged;
168        }
169
170        /**
171         * @return Returns the mIsSelected.
172         */
173        public boolean isSelected() {
174                return mIsSelected;
175        }
176
177        /**
178         * @param isSelected
179         *            The mIsSelected to set.
180         */
181        public void setIsSelected(boolean isSelected) {
182                mIsSelected = isSelected;
183        }
184}