View Javadoc

1   /*
2    * Copyright 2006-2016 The JGUIraffe Team.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License")
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.jguiraffe.gui.builder.event;
17  
18  import net.sf.jguiraffe.gui.forms.ComponentHandler;
19  
20  import org.apache.commons.lang.ObjectUtils;
21  import org.apache.commons.lang.builder.HashCodeBuilder;
22  
23  /**
24   * <p>
25   * A specific event class for dealing with action events.
26   * </p>
27   * <p>
28   * Action events are triggered by components like buttons. They usually cause
29   * the application to perform a certain action. As an additional property a
30   * command string is provided.
31   * </p>
32   *
33   * @author Oliver Heger
34   * @version $Id: FormActionEvent.java 205 2012-01-29 18:29:57Z oheger $
35   */
36  public class FormActionEvent extends FormEvent
37  {
38      /**
39       * The serial version UID.
40       */
41      private static final long serialVersionUID = 626918826171020465L;
42  
43      /** Stores the command string. */
44      private final String command;
45  
46      /**
47       * Creates a new instance of <code>FormActionEvent</code> and initializes
48       * it.
49       *
50       * @param source the original event
51       * @param handler the component handler
52       * @param name the component's name
53       * @param cmd the action command string
54       */
55      public FormActionEvent(Object source, ComponentHandler<?> handler,
56              String name, String cmd)
57      {
58          super(source, handler, name);
59          command = cmd;
60      }
61  
62      /**
63       * Returns the action command string.
64       *
65       * @return the command
66       */
67      public String getCommand()
68      {
69          return command;
70      }
71  
72      /**
73       * {@inheritDoc} This implementation takes the additional fields into
74       * account declared by this class.
75       *
76       * @since 1.3
77       */
78      @Override
79      public int hashCode()
80      {
81          return new HashCodeBuilder().appendSuper(super.hashCode())
82                  .append(getCommand()).toHashCode();
83      }
84  
85      /**
86       * {@inheritDoc} This implementation also checks the additional fields
87       * declared by this class.
88       *
89       * @since 1.3
90       */
91      @Override
92      public boolean equals(Object obj)
93      {
94          return super.equals(obj)
95                  && ObjectUtils.equals(getCommand(),
96                          ((FormActionEvent) obj).getCommand());
97      }
98  }