⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtualeventsource.java

📁 Java 3D Desktop Environment旨在使用Java 3D来创建一个3D桌面环境。功能包括:分布式的应用程序
💻 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 + -