Hello,
I am having problems with the drag and drop aspects of my project. Initially the drag and drop properities worked correctly, and the mouse changed correctly. In order to enhance the usability of the rest of my project i decided to change the mouse to a WAIT_CURSOR when the event takes more than 300 miliseconds. This aspect also works correctly, except when the drag and drop is used. When i try to drag and drop, the entire program freezes. Here is an example of the code that i am using for the mouse change:
public class WaitCursorEventQueue extends EventQueue{
private Cursor cursor;
MDSCMPGraphApplet mdscmpGraphApplet;
public WaitCursorEventQueue(int delay, MDSCMPGraphApplet mdscmpGraphApplet) {
this.delay = delay;
this.mdscmpGraphApplet = mdscmpGraphApplet;
waitTimer = new WaitCursorTimer();
waitTimer.setDaemon(true);
waitTimer.setPriority(Thread.MIN_PRIORITY);
waitTimer.start();
}
protected void dispatchEvent(AWTEvent event) {
waitTimer.startTimer(event.getSource());
try {
events = event;
super.dispatchEvent(event);
}
finally {
waitTimer.stopTimer();
}
}
public static AWTEvent getCurrentEvent(){
return events;
}
private int delay;
private WaitCursorTimer waitTimer;
static AWTEvent events;
private class WaitCursorTimer extends Thread {
synchronized void startTimer(Object source) {
this.source = source;
notify();
}
synchronized void stopTimer() {
if (parent == null)
interrupt();
else {
parent.setCursor(null);
parent = null;
}
}
public synchronized void run() {
while (true) {
try {
wait();
wait(delay);
if (source instanceof Component)
parent = SwingUtilities.getRoot((Component)source);
else if (source instanceof MenuComponent) {
MenuContainer mParent = ((MenuComponent)source).getParent();
if (mParent instanceof Component)
parent = SwingUtilities.getRoot((Component)mParent);
}
if (parent != null && parent.isShowing()){
parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
}catch (InterruptedException ie) { }
}
}
private Object source;
private Component parent;
}
}
If you have any ideas i would really appreciate it!!!
Thank you for you help,
Lora
I am having problems with the drag and drop aspects of my project. Initially the drag and drop properities worked correctly, and the mouse changed correctly. In order to enhance the usability of the rest of my project i decided to change the mouse to a WAIT_CURSOR when the event takes more than 300 miliseconds. This aspect also works correctly, except when the drag and drop is used. When i try to drag and drop, the entire program freezes. Here is an example of the code that i am using for the mouse change:
public class WaitCursorEventQueue extends EventQueue{
private Cursor cursor;
MDSCMPGraphApplet mdscmpGraphApplet;
public WaitCursorEventQueue(int delay, MDSCMPGraphApplet mdscmpGraphApplet) {
this.delay = delay;
this.mdscmpGraphApplet = mdscmpGraphApplet;
waitTimer = new WaitCursorTimer();
waitTimer.setDaemon(true);
waitTimer.setPriority(Thread.MIN_PRIORITY);
waitTimer.start();
}
protected void dispatchEvent(AWTEvent event) {
waitTimer.startTimer(event.getSource());
try {
events = event;
super.dispatchEvent(event);
}
finally {
waitTimer.stopTimer();
}
}
public static AWTEvent getCurrentEvent(){
return events;
}
private int delay;
private WaitCursorTimer waitTimer;
static AWTEvent events;
private class WaitCursorTimer extends Thread {
synchronized void startTimer(Object source) {
this.source = source;
notify();
}
synchronized void stopTimer() {
if (parent == null)
interrupt();
else {
parent.setCursor(null);
parent = null;
}
}
public synchronized void run() {
while (true) {
try {
wait();
wait(delay);
if (source instanceof Component)
parent = SwingUtilities.getRoot((Component)source);
else if (source instanceof MenuComponent) {
MenuContainer mParent = ((MenuComponent)source).getParent();
if (mParent instanceof Component)
parent = SwingUtilities.getRoot((Component)mParent);
}
if (parent != null && parent.isShowing()){
parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
}catch (InterruptedException ie) { }
}
}
private Object source;
private Component parent;
}
}
If you have any ideas i would really appreciate it!!!
Thank you for you help,
Lora