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.components.model;
17  
18  import net.sf.jguiraffe.gui.builder.event.FormEvent;
19  
20  import org.apache.commons.lang.builder.EqualsBuilder;
21  import org.apache.commons.lang.builder.HashCodeBuilder;
22  
23  /**
24   * <p>
25   * An event class reporting a change in the expanded state of a tree's node.
26   * </p>
27   * <p>
28   * Tree components support event listeners that are notified when a node of the
29   * tree is expanded or collapsed. These listeners are passed an event object of
30   * this type containing all data available.
31   * </p>
32   *
33   * @author Oliver Heger
34   * @version $Id: TreeExpansionEvent.java 205 2012-01-29 18:29:57Z oheger $
35   */
36  public class TreeExpansionEvent extends FormEvent
37  {
38      /**
39       * The serial version UID.
40       */
41      private static final long serialVersionUID = 1078903161051276615L;
42  
43      /** Stores the path to the modified node. */
44      private final transient TreeNodePath path;
45  
46      /** The type of this event. */
47      private final Type type;
48  
49      /**
50       * Creates a new instance of <code>TreeExpansionEvent</code> and initializes
51       * it.
52       *
53       * @param source the source of this event
54       * @param handler the component handler affected (this is a handler for a
55       *        tree component)
56       * @param name the name of the component
57       * @param type the type of this event
58       * @param path the path to the node whose state has changed
59       */
60      public TreeExpansionEvent(Object source, TreeHandler handler, String name,
61              Type type, TreeNodePath path)
62      {
63          super(source, handler, name);
64          this.type = type;
65          this.path = path;
66      }
67  
68      /**
69       * Returns the path to the node whose state has changed. This is the node
70       * that triggered this event.
71       *
72       * @return the path of the node affected
73       */
74      public TreeNodePath getPath()
75      {
76          return path;
77      }
78  
79      /**
80       * Returns the handler for the tree component that is the source of this
81       * event.
82       *
83       * @return the handler for the tree component
84       */
85      public TreeHandler getTreeHandler()
86      {
87          return (TreeHandler) getHandler();
88      }
89  
90      /**
91       * Returns the type of this event.
92       *
93       * @return the event type
94       */
95      public Type getType()
96      {
97          return type;
98      }
99  
100     /**
101      * {@inheritDoc} This implementation takes the additional fields into
102      * account declared by this class.
103      *
104      * @since 1.3
105      */
106     @Override
107     public int hashCode()
108     {
109         return new HashCodeBuilder().appendSuper(super.hashCode())
110                 .append(getType()).append(getPath()).toHashCode();
111     }
112 
113     /**
114      * {@inheritDoc} This implementation also checks the additional fields
115      * declared by this class.
116      *
117      * @since 1.3
118      */
119     @Override
120     public boolean equals(Object obj)
121     {
122         if (!super.equals(obj))
123         {
124             return false;
125         }
126         TreeExpansionEvent c = (TreeExpansionEvent) obj;
127         return new EqualsBuilder().append(getType(), c.getType())
128                 .append(getPath(), c.getPath()).isEquals();
129     }
130 
131     /**
132      * An enumeration class defining the different types of a {@code
133      * TreeExpansionEvent}.
134      */
135     public static enum Type
136     {
137         /** A node of the tree was collapsed. */
138         NODE_COLLAPSE,
139 
140         /** A node of the tree was expanded. */
141         NODE_EXPAND
142     }
143 }