Hi Beni!
I was building a tree within a CDockable, and noticed that key events would not be forwarded from the dockable to the components added to it. Instead, the dockable adds itself as a listener on those components.
In order to make F5 refresh the tree I had in the dockable when the key was pressed with focus on the dockable I wrote a patch to the KeyboardController class which will enable it forward every key event to the underlying components without entering in an infinite loop (since it also receives events dispatched to them bakc).
The patch is: add the following field to the class:
/** event being processed and dispatched to components of a dockable **/
private KeyEvent eventBeingProcessed = null;
Add the following method:
/**
* Redispatching the given event to the dockable components so they can also
* do something with it.
*/
public void redispatchEvent(DockElement element, KeyEvent event) {
Component component = element.asDockable().getComponent();
if(eventBeingProcessed == null && component != null
&& component instanceof Container) {
eventBeingProcessed = event;
for (Component childComponent : ((Container)component).getComponents()) {
childComponent.dispatchEvent(event);
}
}
eventBeingProcessed = null;
}
and then to each of the fireKeyPressed, fireKeyReleased and fireKeyTyped method, add the method call within the if( representative != null ){ … } block. For example, this i the new fireKeyPressed:
protected void fireKeyPressed( KeyEvent event ){
if( !event.isConsumed() ){
DockElementRepresentative representative = controller.searchElement( event.getComponent() );
if( representative != null ){
DockElement element = representative.getElement();
List<KeyboardListener> list = keyListeners.affected( element );
loop:for( KeyboardListener listener : list ){
if( listener.keyPressed( element, event )){
event.consume();
break loop;
}
}
**redispatchEvent(element, event);**
}
}
for( KeyListener listener : globalListeners.toArray( new KeyListener[ globalListeners.size() ] )){
listener.keyPressed( event );
}
}
This way all components added to the dockable’s content pane will also receive the key events that were fired when focus was on the dockable and not on it’s content, making much easier to implement key event handling there.
Hope this helps! Let me know what you think.
I’m working on a bug with the dividers. When I drag them and stop pressing the mouse button but keep the mouse moving fast, the divider won’t change the mouse pointer back to an arrow. It keeps it with the divider mouse pointer until I pass it over again slower.
Thanks,
Eduardo Born