View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
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    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.html;
16  
17  import java.util.EventObject;
18  
19  /**
20   * This is the event class for notifications about changes to the attributes of the
21   * HtmlElement.
22   *
23   * @author Ahmed Ashour
24   * @see HtmlAttributeChangeListener
25   */
26  public class HtmlAttributeChangeEvent extends EventObject {
27  
28      private final String name_;
29      private final String value_;
30  
31      /**
32       * Constructs a new AttributeEvent from the given element, for the given attribute name and attribute value.
33       *
34       * @param element the element that is sending the event
35       * @param name the name of the attribute that changed on the element
36       * @param value the value of the attribute that has been added, removed, or replaced
37       */
38      public HtmlAttributeChangeEvent(final HtmlElement element, final String name, final String value) {
39          super(element);
40          name_ = name;
41          value_ = value;
42      }
43  
44      /**
45       * Returns the HtmlElement that changed.
46       * @return the HtmlElement that sent the event
47       */
48      public HtmlElement getHtmlElement() {
49          return (HtmlElement) getSource();
50      }
51  
52      /**
53       * Returns the name of the attribute that changed on the element.
54       * @return the name of the attribute that changed on the element
55       */
56      public String getName() {
57          return name_;
58      }
59  
60      /**
61       * Returns the value of the attribute that has been added, removed, or replaced.
62       * If the attribute was added, this is the value of the attribute.
63       * If the attribute was removed, this is the value of the removed attribute.
64       * If the attribute was replaced, this is the old value of the attribute.
65       *
66       * @return the value of the attribute that has been added, removed, or replaced
67       */
68      public String getValue() {
69          return value_;
70      }
71  }