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 dealing with focus events.
26   * </p>
27   * <p>
28   * A focus event is fired when a component gains or loses focus.
29   * </p>
30   *
31   * @author Oliver Heger
32   * @version $Id: FormFocusEvent.java 205 2012-01-29 18:29:57Z oheger $
33   */
34  public class FormFocusEvent extends FormEvent
35  {
36      /**
37       * The serial version UID.
38       */
39      private static final long serialVersionUID = 2244179360483037190L;
40  
41      /** The type of this event. */
42      private final Type type;
43  
44      /**
45       * Creates a new instance of {@code FormFocusEvent} and initializes it.
46       *
47       * @param source the source event
48       * @param handler the component handler
49       * @param name the component's name
50       * @param type the focus type of the event (gained or lost)
51       */
52      public FormFocusEvent(Object source, ComponentHandler<?> handler,
53              String name, Type type)
54      {
55          super(source, handler, name);
56          this.type = type;
57      }
58  
59      /**
60       * Returns the type of this event.
61       *
62       * @return the type of this event
63       */
64      public Type getType()
65      {
66          return type;
67      }
68  
69      /**
70       * {@inheritDoc} This implementation takes the additional fields into
71       * account declared by this class.
72       *
73       * @since 1.3
74       */
75      @Override
76      public int hashCode()
77      {
78          return new HashCodeBuilder().appendSuper(super.hashCode())
79                  .append(getType()).toHashCode();
80      }
81  
82      /**
83       * {@inheritDoc} This implementation also checks the additional fields
84       * declared by this class.
85       *
86       * @since 1.3
87       */
88      @Override
89      public boolean equals(Object obj)
90      {
91          return super.equals(obj)
92                  && ObjectUtils.equals(getType(),
93                          ((FormFocusEvent) obj).getType());
94      }
95  
96      /**
97       * An enumeration class defining the different types of focus events. Every
98       * {@code FormFocusEvent} has such a type determining what exactly happened.
99       */
100     public static enum Type
101     {
102         /** A component gained focus. */
103         FOCUS_GAINED,
104 
105         /** A component lost focus. */
106         FOCUS_LOST
107     }
108 }