Package chrriis.common

Examples of chrriis.common.ObjectRegistry


  }

  @Override
  public void destroy() {
    // Dispose all SWT controls (simulate dead peer).
    ObjectRegistry controlRegistry = SWTNativeComponent.getControlRegistry();
    for(int instanceID: controlRegistry.getInstanceIDs()) {
      final Control control = (Control)controlRegistry.get(instanceID);
      controlRegistry.remove(instanceID);
      control.getDisplay().asyncExec(new Runnable() {
        public void run() {
          control.getShell().dispose();
        }
      });
View Full Code Here


  /**
   * Get the control, which is only valid when in the native context.
   * @return the control, or null.
   */
  public Control getControl() {
    ObjectRegistry controlRegistry = SWTNativeComponent.getControlRegistry();
    return controlRegistry == null? null: (Control)controlRegistry.get(componentID);
  }
View Full Code Here

  /**
   * Get the native component, which is only valid when in the local context.
   * @return the native component, or null.
   */
  public NativeComponent getNativeComponent() {
    ObjectRegistry nativeComponentRegistry = SWTNativeComponent.getNativeComponentRegistry();
    return nativeComponentRegistry == null? null: (NativeComponent)nativeComponentRegistry.get(componentID);
  }
View Full Code Here

    }
  }

  static Control[] getControls() {
    List<Control> controlList = new ArrayList<Control>();
    ObjectRegistry controlRegistry = getControlRegistry();
    for(int instanceID: controlRegistry.getInstanceIDs()) {
      Control nativeComponent = (Control)controlRegistry.get(instanceID);
      if(nativeComponent != null) {
        controlList.add(nativeComponent);
      }
    }
    return controlList.toArray(new Control[0]);
View Full Code Here

      throw new IllegalStateException("Failed to create a Shell!");
    }
    @Override
    public Object run(Object[] args) throws Exception {
      // We need to synchronize: a non-UI thread may send a message thinking the component is valid, but the message would be invalid as the control is not yet in the registry.
      ObjectRegistry controlRegistry = SWTNativeComponent.getControlRegistry();
      synchronized(controlRegistry) {
        final int componentID = (Integer)args[0];
        Object canvasHandle = args[1];
        final Shell shell = createShell(canvasHandle);
        shell.addControlListener(new ControlAdapter() {
          private boolean isAdjusting;
          @Override
          public void controlMoved(ControlEvent e) {
            if(isAdjusting) {
              return;
            }
            Shell shell = (Shell)e.widget;
            Point location = shell.getLocation();
            if(location.x != 0 || location.y != 0) {
              // On Linux Ubuntu, I found that the location cannot be forced and this would cause a stack overflow.
              isAdjusting = true;
              shell.setLocation(0, 0);
              isAdjusting = false;
            }
          }
        });
        shell.setLayout(new FillLayout());
        Composite controlComposite = new Composite(shell, SWT.NONE);
        controlComposite.setLayout(new FillLayout());
        Control control = (Control)controlRegistry.get(componentID);
        if(control != null) {
          Shell oldShell = control.getShell();
          control.setParent(controlComposite);
          oldShell.dispose();
        } else {
          String nativeComponentClassName = (String)args[2];
          Object nativePeerCreationParameters = args[3];
          Method createControlMethod = Class.forName(nativeComponentClassName).getDeclaredMethod("createControl", Composite.class, Object[].class);
          createControlMethod.setAccessible(true);
          control = (Control)createControlMethod.invoke(null, controlComposite, nativePeerCreationParameters);
          if(Boolean.parseBoolean(NSSystemPropertySWT.COMPONENTS_DEBUG_PRINTCREATION.get())) {
            System.err.println("Created control: " + componentID);
          }
          control.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              if(Boolean.parseBoolean(NSSystemPropertySWT.COMPONENTS_DEBUG_PRINTDISPOSAL.get())) {
                System.err.println("Disposed control: " + componentID);
              }
            }
          });
          controlRegistry.add(control, componentID);
          configureControl(control, componentID);
        }
        shell.setVisible (true);
        shell.getDisplay().asyncExec(new Runnable() {
          public void run() {
View Full Code Here

TOP

Related Classes of chrriis.common.ObjectRegistry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.