View Javadoc

1   /*
2    * $Id: ImageButtonBean.java 421119 2006-07-12 04:49:11Z wsmoak $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.util;
19  
20  import java.io.Serializable;
21  
22  /***
23   * A simple JavaBean to encapsulate the request parameters sent for an HTML
24   * input element of type image. Such an element causes two parameters to be
25   * sent, one each for the X and Y coordinates of the button press. An instance
26   * of this bean within an <code>ActionForm</code> can be used to capture these
27   * and provide a simple means of detecting whether or not the corresponding
28   * image was selected.
29   *
30   * @version $Rev: 421119 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
31   *          $
32   */
33  public class ImageButtonBean implements Serializable {
34      // ------------------------------------------------------------- Properties
35  
36      /***
37       * The X coordinate of the button press.
38       */
39      private String x;
40  
41      /***
42       * The Y coordinate of the button press.
43       */
44      private String y;
45  
46      // ----------------------------------------------------------- Constructors
47  
48      /***
49       * Construct an instance with empty property values.
50       */
51      public ImageButtonBean() {
52          ; // do nothing
53      }
54  
55      /***
56       * Construct an instance with the supplied property values.
57       *
58       * @param x The X coordinate of the button press.
59       * @param y The Y coordinate of the button press.
60       */
61      public ImageButtonBean(String x, String y) {
62          this.x = x;
63          this.y = y;
64      }
65  
66      public String getX() {
67          return (this.x);
68      }
69  
70      public void setX(String x) {
71          this.x = x;
72      }
73  
74      public String getY() {
75          return (this.y);
76      }
77  
78      public void setY(String y) {
79          this.y = y;
80      }
81  
82      // --------------------------------------------------------- Public Methods
83  
84      /***
85       * A convenience method to determine whether or not the corresponding
86       * image element was selected.
87       */
88      public boolean isSelected() {
89          return ((x != null) || (y != null));
90      }
91  
92      /***
93       * Return a string representation of this object.
94       */
95      public String toString() {
96          StringBuffer sb = new StringBuffer("ImageButtonBean[");
97  
98          sb.append(this.x);
99          sb.append(", ");
100         sb.append(this.y);
101         sb.append("]");
102 
103         return (sb.toString());
104     }
105 }