View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.utils;
19  
20  import com.google.gwt.dom.client.Document;
21  import com.google.gwt.dom.client.ImageElement;
22  import com.google.gwt.event.dom.client.HasLoadHandlers;
23  import com.google.gwt.event.dom.client.LoadEvent;
24  import com.google.gwt.event.dom.client.LoadHandler;
25  import com.google.gwt.event.shared.HandlerRegistration;
26  import com.google.gwt.user.client.DOM;
27  import com.google.gwt.user.client.Event;
28  import com.google.gwt.user.client.ui.Widget;
29  
30  /**
31   * Simple image class which fires load events even
32   * if it is not attached to the DOM.
33   * @author laaglu
34   */
35  public class SimpleImage extends Widget implements HasLoadHandlers {
36  	public SimpleImage() {
37  		setElement(Document.get().createImageElement());
38  	    DOM.setEventListener(getElement(), this);    
39  	    DOM.sinkEvents(getElement(), Event.getTypeInt(LoadEvent.getType().getName()) | DOM.getEventsSunk(getElement()));
40  
41  	}
42  	
43  	public void setSrc(String url) {
44  		getElement().<ImageElement>cast().setSrc(url);
45  	}
46  	
47  	@Override
48  	public HandlerRegistration addLoadHandler(LoadHandler handler) {
49  		return addDomHandler(handler, LoadEvent.getType());
50  	}
51  	public String getSrc() {
52  		return getElement().<ImageElement>cast().getSrc();
53  	}
54  
55  	public int getHeight() {
56  		return getElement().<ImageElement>cast().getHeight();
57  	}
58  
59  	public int getWidth() {
60  		return getElement().<ImageElement>cast().getWidth();
61  	}
62  }