I have an interface where either a user can move an object, or moving a slider can move the object. I would like to find out what triggered the componentMoved method. It would be ideal if I could do this:
public void componentMoved(ComponentEvent ce){
if(ce.getSource() == Component.SOURCE_HUMAN){
// Do something here
}
}
I realise this isn't possible. Is there any other way of doing it (without implementing my own component listener from scratch)?
Set a Boolean variable sourceHuman in the MouseListener code that does the dragging. Then your componentMoved code would be something like:
Another approach would be to have two listeners, one for human movement and one for the slider. Then you would add the appropriate listener to the component BEFORE you invoke the code that does the actual moving of the component.