📄 virtualeventsource.java
字号:
package org.j3de.events;
import javax.swing.event.EventListenerList;
import org.j3de.exception.ExceptionHandler;
import org.j3de.input.ActivationManager;
import org.j3de.input.ActivationListener;
public class VirtualEventSource implements EventSource {
private boolean isActive;
private EventListenerList eventlisteners;
public VirtualEventSource(EventSource source, ActivationManager manager) {
eventlisteners = new EventListenerList();
manager.addActivationListener(new ActivationListener() {
public void setActivation(boolean isActive) {
VirtualEventSource.this.isActive = isActive;
}
});
source.addJ3deEventDispatcher(new J3deEventDispatcher() {
public void dispatchEvent(J3deEvent event) throws EventDispatcherDeactivatedException,
InvalidListenerInterfaceException {
if (isActive)
fireActionEvent(event);
}
});
}
public void addJ3deEventDispatcher(J3deEventDispatcher dispatcher) {
eventlisteners.add(J3deEventDispatcher.class, dispatcher);
}
public void removeJ3deEventDispatcher(J3deEventDispatcher dispatcher) {
eventlisteners.add(J3deEventDispatcher.class, dispatcher);
}
private void fireActionEvent(J3deEvent event) {
// Guaranteed to return a non-null array
Object[] listeners = eventlisteners.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==J3deEventDispatcher.class) {
try {
((J3deEventDispatcher)listeners[i+1]).dispatchEvent(event);
} catch (Exception e) {
ExceptionHandler.handleException(e);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -