001 /*
002 * This file is part of the Echo Point Project. This project is a
003 * collection of Components that have extended the Echo Web Application
004 * Framework Version 3.
005 *
006 * Version: MPL 1.1
007 *
008 * The contents of this file are subject to the Mozilla Public License Version
009 * 1.1 (the "License"); you may not use this file except in compliance with
010 * the License. You may obtain a copy of the License at
011 * http://www.mozilla.org/MPL/
012 *
013 * Software distributed under the License is distributed on an "AS IS" basis,
014 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015 * for the specific language governing rights and limitations under the
016 * License.
017 */
018 package echopoint.model;
019
020 import com.thoughtworks.xstream.annotations.XStreamAlias;
021
022 /**
023 * A model object that represents a rectangular clickable section on an {@link
024 * echopoint.ImageMap}.
025 *
026 * <p><b>Note:</b> Development of this component was sponsored by
027 * <a href='http://tcnbroadcasting.com/index.jsp' target='_top'>TCN
028 * Broadcasting</a>. We are grateful for their support and sponsorship.</p>
029 *
030 * @author Rakesh 2008-10-19
031 * @version $Id: RectangleSection.java 86 2008-11-09 14:44:29Z sptrakesh $
032 */
033 @XStreamAlias( "rectangleSection" )
034 public class RectangleSection extends MapSection
035 {
036 private static final long serialVersionUID = 1l;
037
038 /** The bottom-left corner (origin) of the rectangle. */
039 private Point bottom;
040
041 /** The top-right (end) of the rectangle. */
042 private Point top;
043
044 /** Default constructor. */
045 public RectangleSection() {}
046
047 /**
048 * Create a new instance using the specified values.
049 *
050 * @param bottomx The x-coordinate of the origin of the rectangle.
051 * @param bottomy The y-coordinate of the origin of the rectangle.
052 * @param topx The x-coordinate of the end of the rectangle.
053 * @param topy The y-coordinate of the end of the rectangle.
054 * @param values Optionally the {@link #actionCommand} and {@link
055 * #altText} values. Note that unless {@link #actionCommand} is
056 * specified the section will not be saved in the image map.
057 */
058 public RectangleSection( final int bottomx, final int bottomy,
059 final int topx, final int topy, final String... values )
060 {
061 this( new Point( bottomx, bottomy ), new Point( topx, topy ), values );
062 }
063
064 /**
065 * Designated constructor. Create a new instance with the specified values.
066 *
067 * @param bottom The bottom corner of the rectangle.
068 * @param top The top corner of the rectangle.
069 * @param values Optionally the {@link #actionCommand} and {@link
070 * #altText} values. Note that unless {@link #actionCommand} is
071 * specified the section will not be saved in the image map.
072 */
073 public RectangleSection( final Point bottom, final Point top,
074 final String... values )
075 {
076 setBottom( bottom );
077 setTop( top );
078
079 if ( values.length > 0 ) setActionCommand( values[0] );
080 if ( values.length > 1 ) setAltText( values[1] );
081 }
082
083 /** {@inheritDoc} */
084 @Override
085 public boolean equals( final Object o )
086 {
087 if ( this == o ) return true;
088 if ( o == null || getClass() != o.getClass() ) return false;
089 if ( !super.equals( o ) ) return false;
090
091 RectangleSection that = (RectangleSection) o;
092
093 return super.equals( o ) &&
094 !( bottom != null ? !bottom.equals( that.bottom ) : that.bottom != null ) &&
095 !( top != null ? !top.equals( that.top ) : that.top != null );
096 }
097
098 public int hashCode()
099 {
100 int result = super.hashCode();
101 result = 31 * result + ( bottom != null ? bottom.hashCode() : 0 );
102 result = 31 * result + ( top != null ? top.hashCode() : 0 );
103 return result;
104 }
105
106 /**
107 * Accessor for property 'bottom'.
108 *
109 * @return Value for property 'bottom'.
110 */
111 public Point getBottom()
112 {
113 return bottom;
114 }
115
116 /**
117 * Mutator for property 'bottom'.
118 *
119 * @param bottom Value to set for property 'bottom'.
120 */
121 public void setBottom( final Point bottom )
122 {
123 this.bottom = bottom;
124 }
125
126 /**
127 * Accessor for property 'top'.
128 *
129 * @return Value for property 'top'.
130 */
131 public Point getTop()
132 {
133 return top;
134 }
135
136 /**
137 * Mutator for property 'top'.
138 *
139 * @param top Value to set for property 'top'.
140 */
141 public void setTop( final Point top )
142 {
143 this.top = top;
144 }
145 }