I think "this.sinkEvents(Event.ONDBLCLICK|Event.ONCLICK);" desn't
work.
I set a break-point in "onBrowserEvent", no matter I click or
doubleClick, the "DOM.eventGetType(event)" always be 1 that means
"Event.ONCLICK".
I tried to sink mousedown or mouseup along with
Event.ONDBLCLICK|Event.ONCLICK, but double-click is never sinked to
"onBrowserEvent". Only under one situation this could work:
Only sink the Event.ONDBLCLICK without Event.ONCLICK.
Doesn't anybody meet this problem before? is it a bug?
Ark
that is a good point. If you don't set a breakpoint but just traces you
will see that first to Event.ONCLICK are sent and after them one
Event.ONDBLCLICK.
This leads to the problem that you can't react only to double clicks
efficiently because you always get a single click before. Lets say you
have a table with a label which represents a link and is triggering the
link when a single click is executed on it. But you want to be able to
edit the link by doing a dbl click on it. I haven't found a way how to
solve that?
Does anybody have a workaround for that?
Dominik
thanks for your answer. I hadn't thought about that workaround, but it
sounds good. I hope that the GWT team might solve that issue in a more
coherent way.
Thanks for your help, anyway.
Dominik
I have had to create my own click listener (and added code to
onBrowserEvent) that is capable of
discerning leftClick, rightClick, shiftClick, ctrlClick, and
dblClick. It works like a charm
-jason
On Wednesday 25 October 2006 10:35, Jason Essington wrote:
> I suppose there could be a feature request here.
>
> I have had to create my own click listener (and added code to
> onBrowserEvent) that is capable of
> discerning leftClick, rightClick, shiftClick, ctrlClick, and
> dblClick. It works like a charm
--
"It is awfully easy to be hard-boiled about everything in the daytime, but
at night it is another thing." -- Ernest Hemingway, 'The Sun Also Rises'
/**
* Label que sobrescribe el metodo onBrowserEvent para mandarle el tipo
de
* evento
*
* @author Matias Leone
*
*/
public class LabelTeg extends Label {
private static final int TIMER = 40;
// Atributos que no me quedaba otra que redefinir
private ClickListenerCollection clickListeners;
private MouseListenerCollection mouseListeners;
private DoubleClickListenerTeg clickListenerTeg;
private Timer timer;
private int clicksCount;
// ==========================//
public LabelTeg() {
super();
sinkEvents( Event.ONDBLCLICK);
clicksCount = 0;
timer = new DoubleClickTimer( this );
}
// ==========================//
/**
* Creates a label with the specified text.
*
* @param text the new label's text
*/
public LabelTeg(String text) {
this();
setText(text);
}
// ==========================//
/**
* Creates a label with the specified text.
*
* @param text
* the new label's text
* @param wordWrap
* <code>false</code> to disable word wrapping
*/
public LabelTeg(String text, boolean wordWrap) {
this(text);
setWordWrap(wordWrap);
}
// ==========================//
/**
* Metodo redefinido para poder captar eventos de doble click sobre un
label
*
*/
public void onBrowserEvent(Event event) {
switch (DOM.eventGetType(event)) {
case Event.ONDBLCLICK:
clickListenerTeg.onDoubleClick(this);
return;
//Si fue click, vemos si corresponde a un doble click, sino
iniciamos un timer
case Event.ONCLICK:
if (this.clickListenerTeg != null) {
clicksCount++;
if ( clicksCount >= 2 ) {
timer.cancel();
clicksCount = 0;
} else {
timer.scheduleRepeating( TIMER );
}
}
break;
case Event.ONMOUSEDOWN:
case Event.ONMOUSEUP:
case Event.ONMOUSEMOVE:
case Event.ONMOUSEOVER:
case Event.ONMOUSEOUT:
if (mouseListeners != null)
mouseListeners.fireMouseEvent(this, event);
break;
}
}
// ==========================//
/**
* Atiende un evento de mouse que sea solo un click comun, y no un
doble click
*/
protected void atenderClickComun() {
timer.cancel();
clicksCount = 0;
if (clickListeners != null) {
clickListeners.fireClick(this);
}
}
// ==========================//
/**
* Agrega un captador de eventos del mouse para el Teg
*/
public void addDoubleClickListenerTeg(DoubleClickListenerTeg
mouseListener) {
this.clickListenerTeg = mouseListener;
}
// ==========================//
/**
* Quita un captador de eventos del mouse para el Teg
*/
public void removeDoubleClickListenerTeg(
DoubleClickListenerTeg mouseListener) {
this.clickListenerTeg = null;
}
// ==========================//
/* Metodos que no me quedaba otra que redefinir */
// ==========================//
public void removeClickListener(ClickListener listener) {
if (clickListeners != null)
clickListeners.remove(listener);
}
public void removeMouseListener(MouseListener listener) {
if (mouseListeners != null)
mouseListeners.remove(listener);
}
public void addClickListener(ClickListener listener) {
if (clickListeners == null)
clickListeners = new ClickListenerCollection();
clickListeners.add(listener);
}
public void addMouseListener(MouseListener listener) {
if (mouseListeners == null)
mouseListeners = new MouseListenerCollection();
mouseListeners.add(listener);
}
// ==========================//
/**
* Clase privada para el timer
*/
private class DoubleClickTimer extends Timer {
private LabelTeg labelTeg;
// ==========================//
public DoubleClickTimer(LabelTeg labelTeg) {
this.labelTeg = labelTeg;
}
// ==========================//
/**
* Avisa que fue un click comun
*/
public void run() {
labelTeg.atenderClickComun();
}
}
// ==========================//
}
This is the interface that the container of my Label must implement.
public interface DoubleClickListenerTeg {
/**
* Fired when the user double clicks on a widget.
*
* @param sender the widget sending the event.
*/
public void onDoubleClick(Widget sender);
}