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