All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.future.earth.gwt.client.ui.button.FontAwesomeButton Maven / Gradle / Ivy

The newest version!
package eu.future.earth.gwt.client.ui.button;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.HasEnabled;

/**
 * Anchor styled as a button
 */
public class FontAwesomeButton extends Composite implements HasEnabled, HasClickHandlers, ClickHandler, Focusable {

	protected FocusPanel main = new FocusPanel();

	public FontAwesomeButton() {
		this(null);
	}

	public FontAwesomeButton(String newText) {
		super();
		initWidget(main);
		setSymbol(newText);
		main.addClickHandler(this);

		super.setStyleName("fontawesome-img-button");
	}

	private boolean enabled = true;

	public void setSymbol(String newText) {
		if (newText != null) {
			int i = Integer.parseInt(newText, 16);
			String news = Character.toString((char) i);

			main.getElement().setAttribute("symbol", news);
			// main.getElement().setAttribute("style", "content: \'\\" + newText + "\';");
			// main.getElement().appendChild(text.getElement());
			// text.setText(newText);
		}
	}

	@Override
	public void setEnabled(boolean newEnabled) {
		enabled = newEnabled;
		if (enabled) {
			super.addStyleName("enabled");
			super.removeStyleName("disabled");
		} else {
			super.addStyleName("disabled");
			super.removeStyleName("enabled");
		}
	}

	@Override
	public HandlerRegistration addClickHandler(ClickHandler handler) {
		return addHandler(handler, ClickEvent.getType());
	}

	@Override
	public boolean isEnabled() {
		return enabled;
	}

	@Override
	public void onBrowserEvent(Event event) {
		if (enabled) {
			super.onBrowserEvent(event);
		} else {
			event.preventDefault();
		}
	}

	@Override
	public void onClick(ClickEvent event) {

	}

	@Override
	public int getTabIndex() {
		return main.getTabIndex();
	}

	@Override
	public void setAccessKey(char key) {
		main.setAccessKey(key);
	}

	@Override
	public void setFocus(boolean focused) {
		main.setFocus(focused);
	}

	@Override
	public void setTabIndex(int index) {
		main.setTabIndex(index);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy