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 circular clickable section in a {@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: CircleSection.java 72 2008-10-21 02:51:23Z sptrakesh $
032 */
033 @XStreamAlias( "circleSection" )
034 public class CircleSection extends MapSection
035 {
036 private static final long serialVersionUID = 1l;
037
038 /** The point that represents the centroid of the circle. */
039 private Point centre;
040
041 /** The radius of the circular section. */
042 private int radius;
043
044 /** Default constructor. */
045 public CircleSection() {}
046
047 /**
048 * Create a new instance using the specified values.
049 *
050 * @param x The x-coordinate of the centroid of the circular section.
051 * @param y The y-coordinate of the centroid of the circular section.
052 * @param radius The radius of the circular section.
053 * @param values Optionally the {@link #actionCommand} and {@link
054 * #altText} values. Note that unless {@link #actionCommand} is
055 * specified the section will not be saved in the image map.
056 */
057 public CircleSection( final int x, final int y, final int radius,
058 final String... values )
059 {
060 this( new Point( x, y ), radius, values );
061 }
062
063 /**
064 * Designated constructor. Create a new circular section using the
065 * specified values.
066 *
067 * @param centre The point that represents the centroid of the circle.
068 * @param radius The radius of the circular section.
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 CircleSection( final Point centre, final int radius,
074 final String... values )
075 {
076 setCentre( centre );
077 setRadius( radius );
078
079 if ( values.length > 0 ) setActionCommand( values[0] );
080 if ( values.length > 1 ) setAltText( values[1] );
081 }
082
083 /**
084 * Compare the specified object with this instance for equality.
085 *
086 * @param o The object that is to be compared.
087 * @return Return <code>true</code> if the specified object is equivalent.
088 */
089 @Override
090 public boolean equals( final Object o )
091 {
092 if ( this == o ) return true;
093 if ( o == null || getClass() != o.getClass() ) return false;
094 if ( !super.equals( o ) ) return false;
095
096 CircleSection that = (CircleSection) o;
097
098 return ( super.equals( o ) && radius == that.radius &&
099 !( centre != null ? !centre.equals( that.centre ) : that.centre != null ) );
100 }
101
102 /**
103 * Compute a hash code for this instance.
104 *
105 * @return The hash code value for this instance.
106 */
107 @Override
108 public int hashCode()
109 {
110 int result = super.hashCode();
111 result = 31 * result + ( centre != null ? centre.hashCode() : 0 );
112 result = 31 * result + radius;
113 return result;
114 }
115
116 /**
117 * Accessor for property 'centre'.
118 *
119 * @return Value for property 'centre'.
120 */
121 public Point getCentre()
122 {
123 return centre;
124 }
125
126 /**
127 * Mutator for property 'centre'.
128 *
129 * @param centre Value to set for property 'centre'.
130 */
131 public void setCentre( final Point centre )
132 {
133 this.centre = centre;
134 }
135
136 /**
137 * Accessor for property 'radius'.
138 *
139 * @return Value for property 'radius'.
140 */
141 public int getRadius()
142 {
143 return radius;
144 }
145
146 /**
147 * Mutator for property 'radius'.
148 *
149 * @param radius Value to set for property 'radius'.
150 */
151 public void setRadius( final int radius )
152 {
153 this.radius = radius;
154 }
155 }