1 38 package com.gargoylesoftware.htmlunit; 39 40 import java.util.EventObject ; 41 42 49 public final class WebWindowEvent extends EventObject { 50 private static final long serialVersionUID = 6693838158619061745L; 51 private final Page oldPage_; 52 private final Page newPage_; 53 private final int type_; 54 55 56 public static final int OPEN = 1; 57 58 59 public static final int CLOSE = 2; 60 61 62 public static final int CHANGE = 3; 63 64 72 public WebWindowEvent( 73 final WebWindow webWindow, 74 final int type, 75 final Page oldPage, 76 final Page newPage ) { 77 super(webWindow); 78 oldPage_ = oldPage; 79 newPage_ = newPage; 80 81 switch( type ) { 82 case OPEN: 83 case CLOSE: 84 case CHANGE: 85 type_ = type; 86 break; 87 88 default: 89 throw new IllegalArgumentException ( 90 "type must be one of OPEN, CLOSE, CHANGE but got "+type); 91 } 92 } 93 94 95 101 public boolean equals( final Object object ) { 102 if( getClass() == object.getClass() ) { 103 final WebWindowEvent event = (WebWindowEvent)object; 104 return isEqual(getSource(), event.getSource()) 105 && getEventType() == event.getEventType() 106 && isEqual(getOldPage(), event.getOldPage()) 107 && isEqual(getNewPage(), event.getNewPage()); 108 } 109 return false; 110 } 111 112 113 117 public int hashCode() { 118 return source.hashCode(); 119 } 120 121 125 public Page getOldPage() { 126 return oldPage_; 127 } 128 129 130 134 public Page getNewPage() { 135 return newPage_; 136 } 137 138 139 143 public WebWindow getWebWindow() { 144 return (WebWindow)getSource(); 145 } 146 147 148 private boolean isEqual( final Object object1, final Object object2 ) { 149 final boolean result; 150 151 if( object1 == null && object2 == null ) { 152 result = true; 153 } 154 else if( object1 == null || object2 == null ) { 155 result = false; 156 } 157 else { 158 result = object1.equals(object2); 159 } 160 161 return result; 162 } 163 164 165 169 public String toString() { 170 final StringBuffer buffer = new StringBuffer (80); 171 buffer.append("WebWindowEvent(source=["); 172 buffer.append(getSource()); 173 buffer.append("] type=["); 174 switch( type_ ) { 175 case OPEN: 176 buffer.append("OPEN"); 177 break; 178 case CLOSE: 179 buffer.append("CLOSE"); 180 break; 181 case CHANGE: 182 buffer.append("CHANGE"); 183 break; 184 default: 185 buffer.append(type_); 186 break; 187 } 188 buffer.append("] oldPage=["); 189 buffer.append(getOldPage()); 190 buffer.append("] newPage=["); 191 buffer.append(getNewPage()); 192 buffer.append("])"); 193 194 return buffer.toString(); 195 } 196 197 198 public int getEventType() { 199 return type_; 200 } 201 } 202 | Popular Tags |