Ejemplo n.º 1
0
  /**
   * Sets the font that the receiver will use to paint textual information for the specified cell in
   * this item to the font specified by the argument, or to the default font for that kind of
   * control if the argument is null.
   *
   * @param index the column index
   * @param font the new font (or null)
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   *
   * @since 3.0
   */
  public void setFont(int index, Font font) {
    checkWidget();
    if (font != null && font.isDisposed()) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return;
    if (cellFont == null) {
      if (font == null) return;
      cellFont = new Font[count];
    }
    Font oldFont = cellFont[index];
    if (oldFont == font) return;
    cellFont[index] = font;
    if (oldFont != null && oldFont.equals(font)) return;

    int modelIndex =
        parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
    int /*long*/ fontHandle = font != null ? font.handle : 0;
    OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_FONT, fontHandle, -1);
    /*
     * Bug in GTK.  When using fixed-height-mode,
     * row changes do not cause the row to be repainted.  The fix is to
     * invalidate the row when it is cleared.
     */
    if ((parent.style & SWT.VIRTUAL) != 0) {
      if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
        redraw();
      }
    }
    cached = true;

    if (font != null) {
      boolean customDraw =
          (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns[index].customDraw;
      if (!customDraw) {
        if ((parent.style & SWT.VIRTUAL) == 0) {
          int /*long*/ parentHandle = parent.handle;
          int /*long*/ column = 0;
          if (parent.columnCount > 0) {
            column = parent.columns[index].handle;
          } else {
            column = OS.gtk_tree_view_get_column(parentHandle, index);
          }
          if (column == 0) return;
          int /*long*/ textRenderer = parent.getTextRenderer(column);
          int /*long*/ imageRenderer = parent.getPixbufRenderer(column);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, textRenderer, display.cellDataProc, parentHandle, 0);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, imageRenderer, display.cellDataProc, parentHandle, 0);
        }
        if (parent.columnCount == 0) {
          parent.firstCustomDraw = true;
        } else {
          parent.columns[index].customDraw = true;
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Creates a new <code>Shell</code>. This Shell is the root for the SWT widgets that will be
   * embedded within the AWT canvas.
   *
   * @param display the display for the new Shell
   * @param parent the parent <code>java.awt.Canvas</code> of the new Shell
   * @return a <code>Shell</code> to be the parent of the embedded SWT widgets
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the display is null
   *       <li>ERROR_NULL_ARGUMENT - if the parent is null
   *       <li>ERROR_INVALID_ARGUMENT - if the parent's peer is not created
   *     </ul>
   *
   * @since 3.0
   */
  public static Shell new_Shell(final Display display, final Canvas parent) {
    if (display == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    int /*long*/ handle = 0;

    try {
      loadLibrary();
      handle = getAWTHandle(parent);
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e);
    }
    if (handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " [peer not created]");

    final Shell shell = Shell.cocoa_new(display, handle);
    final ComponentListener listener =
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            display.asyncExec(
                new Runnable() {
                  public void run() {
                    if (shell.isDisposed()) return;
                    Dimension dim = parent.getSize();
                    shell.setSize(dim.width, dim.height);
                  }
                });
          }
        };
    parent.addComponentListener(listener);
    shell.addListener(
        SWT.Dispose,
        new Listener() {
          public void handleEvent(Event event) {
            parent.removeComponentListener(listener);
          }
        });
    shell.setVisible(true);
    return shell;
  }
Ejemplo n.º 3
0
 /**
  * Sets the receiver's background color to the color specified by the argument, or to the default
  * system color for the item if the argument is null.
  *
  * @param color the new color (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @since 2.0
  */
 public void setBackground(Color color) {
   checkWidget();
   if (color != null && color.isDisposed()) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (_getBackground().equals(color)) return;
   GdkColor gdkColor = color != null ? color.handle : null;
   OS.gtk_list_store_set(parent.modelHandle, handle, Table.BACKGROUND_COLUMN, gdkColor, -1);
   /*
    * Bug in GTK.  When using fixed-height-mode,
    * row changes do not cause the row to be repainted.  The fix is to
    * invalidate the row when it is cleared.
    */
   if ((parent.style & SWT.VIRTUAL) != 0) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
       redraw();
     }
   }
   cached = true;
 }
Ejemplo n.º 4
0
 /**
  * Sets the font that the receiver will use to paint textual information for this item to the font
  * specified by the argument, or to the default font for that kind of control if the argument is
  * null.
  *
  * @param font the new font (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @since 3.0
  */
 public void setFont(Font font) {
   checkWidget();
   if (font != null && font.isDisposed()) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   Font oldFont = this.font;
   if (oldFont == font) return;
   this.font = font;
   if (oldFont != null && oldFont.equals(font)) return;
   int /*long*/ fontHandle = font != null ? font.handle : 0;
   OS.gtk_list_store_set(parent.modelHandle, handle, Table.FONT_COLUMN, fontHandle, -1);
   /*
    * Bug in GTK.  When using fixed-height-mode,
    * row changes do not cause the row to be repainted.  The fix is to
    * invalidate the row when it is cleared.
    */
   if ((parent.style & SWT.VIRTUAL) != 0) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
       redraw();
     }
   }
   cached = true;
 }
Ejemplo n.º 5
0
 static {
   menuItemSelectedFunc = new Callback(ToolBar.class, "MenuItemSelectedProc", 2);
   if (menuItemSelectedFunc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
 }
Ejemplo n.º 6
0
 /**
  * Returns a <code>java.awt.Frame</code> which is the embedded frame associated with the specified
  * composite.
  *
  * @param parent the parent <code>Composite</code> of the <code>java.awt.Frame</code>
  * @return a <code>java.awt.Frame</code> the embedded frame or <code>null</code>.
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the parent is null
  *     </ul>
  *
  * @since 3.2
  */
 public static Frame getFrame(Composite parent) {
   if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if ((parent.getStyle() & SWT.EMBEDDED) == 0) return null;
   return (Frame) parent.getData(EMBEDDED_FRAME_KEY);
 }
Ejemplo n.º 7
0
  /**
   * Creates a new <code>java.awt.Frame</code>. This frame is the root for the AWT components that
   * will be embedded within the composite. In order for the embedding to succeed, the composite
   * must have been created with the SWT.EMBEDDED style.
   *
   * <p>IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. When a
   * lightweight component is added as a child of the embedded frame, the cursor does not change. In
   * order to work around both these problems, it is strongly recommended that a heavyweight
   * component such as <code>java.awt.Panel</code> be added to the frame as the root of all
   * components.
   *
   * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code>
   * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the parent is null
   *       <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style
   *     </ul>
   *
   * @since 3.0
   */
  public static Frame new_Frame(final Composite parent) {
    if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if ((parent.getStyle() & SWT.EMBEDDED) == 0) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }

    final int /*long*/ handle = parent.view.id;

    Class clazz = null;
    try {
      String className =
          embeddedFrameClass != null ? embeddedFrameClass : "apple.awt.CEmbeddedFrame";
      if (embeddedFrameClass == null) {
        clazz = Class.forName(className, true, ClassLoader.getSystemClassLoader());
      } else {
        clazz = Class.forName(className);
      }
    } catch (ClassNotFoundException cne) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, cne);
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_UNSPECIFIED, e, " [Error while starting AWT]");
    }

    initializeSwing();
    Object value = null;
    Constructor constructor = null;
    try {
      constructor = clazz.getConstructor(new Class[] {long.class});
      value = constructor.newInstance(new Object[] {new Long(handle)});
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e);
    }
    final Frame frame = (Frame) value;
    frame.addNotify();

    parent.setData(EMBEDDED_FRAME_KEY, frame);

    /* Forward the iconify and deiconify events */
    final Listener shellListener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Deiconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_DEICONIFIED));
                      }
                    });
                break;
              case SWT.Iconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));
                      }
                    });
                break;
            }
          }
        };
    Shell shell = parent.getShell();
    shell.addListener(SWT.Deiconify, shellListener);
    shell.addListener(SWT.Iconify, shellListener);

    /*
     * Generate the appropriate events to activate and deactivate
     * the embedded frame. This is needed in order to make keyboard
     * focus work properly for lightweights.
     */
    Listener listener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Dispose:
                Shell shell = parent.getShell();
                shell.removeListener(SWT.Deiconify, shellListener);
                shell.removeListener(SWT.Iconify, shellListener);
                parent.setVisible(false);
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        try {
                          frame.dispose();
                        } catch (Throwable e) {
                        }
                      }
                    });
                break;
              case SWT.FocusIn:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(true)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
              case SWT.Deactivate:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (!frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(false)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
            }
          }
        };

    parent.addListener(SWT.FocusIn, listener);
    parent.addListener(SWT.Deactivate, listener);
    parent.addListener(SWT.Dispose, listener);

    parent
        .getDisplay()
        .asyncExec(
            new Runnable() {
              public void run() {
                if (parent.isDisposed()) return;
                final Rectangle clientArea = parent.getClientArea();
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.setSize(clientArea.width, clientArea.height);
                        frame.validate();

                        // Bug in Cocoa AWT? For some reason the frame isn't showing up on first
                        // draw.
                        // Toggling visibility seems to be the only thing that works.
                        frame.setVisible(false);
                        frame.setVisible(true);
                      }
                    });
              }
            });

    return frame;
  }
Ejemplo n.º 8
0
  int PromptAuth(long /*int*/ aChannel, int level, long /*int*/ authInfo, long /*int*/ _retval) {
    nsIAuthInformation auth = new nsIAuthInformation(authInfo);

    Browser browser = getBrowser();
    if (browser != null) {
      Mozilla mozilla = (Mozilla) browser.webBrowser;
      /*
       * Do not invoke the listeners if this challenge has been failed too many
       * times because a listener is likely giving incorrect credentials repeatedly
       * and will do so indefinitely.
       */
      if (mozilla.authCount++ < 3) {
        for (int i = 0; i < mozilla.authenticationListeners.length; i++) {
          AuthenticationEvent event = new AuthenticationEvent(browser);
          event.location = mozilla.lastNavigateURL;
          mozilla.authenticationListeners[i].authenticate(event);
          if (!event.doit) {
            XPCOM.memmove(_retval, new boolean[] {false});
            return XPCOM.NS_OK;
          }
          if (event.user != null && event.password != null) {
            nsEmbedString string = new nsEmbedString(event.user);
            int rc = auth.SetUsername(string.getAddress());
            if (rc != XPCOM.NS_OK) SWT.error(rc);
            string.dispose();
            string = new nsEmbedString(event.password);
            rc = auth.SetPassword(string.getAddress());
            if (rc != XPCOM.NS_OK) SWT.error(rc);
            string.dispose();
            XPCOM.memmove(_retval, new boolean[] {true});
            return XPCOM.NS_OK;
          }
        }
      }
    }

    /* no listener handled the challenge, so show an authentication dialog */

    String checkLabel = null;
    boolean[] checkValue = new boolean[1];
    String[] userLabel = new String[1], passLabel = new String[1];

    String title = SWT.getMessage("SWT_Authentication_Required"); // $NON-NLS-1$

    /* get initial username and password values */

    long /*int*/ ptr = XPCOM.nsEmbedString_new();
    int rc = auth.GetUsername(ptr);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    int length = XPCOM.nsEmbedString_Length(ptr);
    long /*int*/ buffer = XPCOM.nsEmbedString_get(ptr);
    char[] chars = new char[length];
    XPCOM.memmove(chars, buffer, length * 2);
    userLabel[0] = new String(chars);
    XPCOM.nsEmbedString_delete(ptr);

    ptr = XPCOM.nsEmbedString_new();
    rc = auth.GetPassword(ptr);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    length = XPCOM.nsEmbedString_Length(ptr);
    buffer = XPCOM.nsEmbedString_get(ptr);
    chars = new char[length];
    XPCOM.memmove(chars, buffer, length * 2);
    passLabel[0] = new String(chars);
    XPCOM.nsEmbedString_delete(ptr);

    /* compute the message text */

    ptr = XPCOM.nsEmbedString_new();
    rc = auth.GetRealm(ptr);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    length = XPCOM.nsEmbedString_Length(ptr);
    buffer = XPCOM.nsEmbedString_get(ptr);
    chars = new char[length];
    XPCOM.memmove(chars, buffer, length * 2);
    String realm = new String(chars);
    XPCOM.nsEmbedString_delete(ptr);

    nsIChannel channel = new nsIChannel(aChannel);
    long /*int*/[] uri = new long /*int*/[1];
    rc = channel.GetURI(uri);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    if (uri[0] == 0) Mozilla.error(XPCOM.NS_NOINTERFACE);

    nsIURI nsURI = new nsIURI(uri[0]);
    long /*int*/ host = XPCOM.nsEmbedCString_new();
    rc = nsURI.GetHost(host);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    length = XPCOM.nsEmbedCString_Length(host);
    buffer = XPCOM.nsEmbedCString_get(host);
    byte[] bytes = new byte[length];
    XPCOM.memmove(bytes, buffer, length);
    String hostString = new String(bytes);
    XPCOM.nsEmbedCString_delete(host);
    nsURI.Release();

    String message;
    if (realm.length() > 0 && hostString.length() > 0) {
      message =
          Compatibility.getMessage(
              "SWT_Enter_Username_and_Password", new String[] {realm, hostString}); // $NON-NLS-1$
    } else {
      message = ""; // $NON-NLS-1$
    }

    /* open the prompter */
    Shell shell = browser == null ? new Shell() : browser.getShell();
    PromptDialog dialog = new PromptDialog(shell);
    boolean[] result = new boolean[1];
    dialog.promptUsernameAndPassword(
        title, message, checkLabel, userLabel, passLabel, checkValue, result);

    XPCOM.memmove(_retval, result);
    if (result[0]) {
        /* User selected OK */
      nsEmbedString string = new nsEmbedString(userLabel[0]);
      rc = auth.SetUsername(string.getAddress());
      if (rc != XPCOM.NS_OK) SWT.error(rc);
      string.dispose();

      string = new nsEmbedString(passLabel[0]);
      rc = auth.SetPassword(string.getAddress());
      if (rc != XPCOM.NS_OK) SWT.error(rc);
      string.dispose();
    }

    return XPCOM.NS_OK;
  }
Ejemplo n.º 9
0
  /**
   * Creates a new <code>java.awt.Frame</code>. This frame is the root for the AWT components that
   * will be embedded within the composite. In order for the embedding to succeed, the composite
   * must have been created with the SWT.EMBEDDED style.
   *
   * <p>IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. When a
   * lightweight component is added as a child of the embedded frame, the cursor does not change. In
   * order to work around both these problems, it is strongly recommended that a heavyweight
   * component such as <code>java.awt.Panel</code> be added to the frame as the root of all
   * components.
   *
   * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code>
   * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the parent is null
   *       <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style
   *     </ul>
   *
   * @since 3.0
   */
  public static Frame new_Frame(final Composite parent) {
    if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if ((parent.getStyle() & SWT.EMBEDDED) == 0) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    int /*long*/ handle = parent.embeddedHandle;
    /*
     * Some JREs have implemented the embedded frame constructor to take an integer
     * and other JREs take a long.  To handle this binary incompatibility, use
     * reflection to create the embedded frame.
     */
    Class clazz = null;
    try {
      String className =
          embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.X11.XEmbeddedFrame";
      clazz = Class.forName(className);
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e, " [need JDK 1.5 or greater]");
    }
    initializeSwing();
    Object value = null;
    Constructor constructor = null;
    try {
      constructor = clazz.getConstructor(new Class[] {int.class, boolean.class});
      value =
          constructor.newInstance(new Object[] {new Integer((int) /*64*/ handle), Boolean.TRUE});
    } catch (Throwable e1) {
      try {
        constructor = clazz.getConstructor(new Class[] {long.class, boolean.class});
        value = constructor.newInstance(new Object[] {new Long(handle), Boolean.TRUE});
      } catch (Throwable e2) {
        SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e2);
      }
    }
    final Frame frame = (Frame) value;
    parent.setData(EMBEDDED_FRAME_KEY, frame);
    if (Device.DEBUG) {
      loadLibrary();
      setDebug(frame, true);
    }
    try {
      /* Call registerListeners() to make XEmbed focus traversal work */
      Method method = clazz.getMethod("registerListeners", null);
      if (method != null) method.invoke(value, null);
    } catch (Throwable e) {
    }
    final AWTEventListener awtListener =
        new AWTEventListener() {
          public void eventDispatched(AWTEvent event) {
            if (event.getID() == WindowEvent.WINDOW_OPENED) {
              final Window window = (Window) event.getSource();
              if (window.getParent() == frame) {
                parent
                    .getDisplay()
                    .asyncExec(
                        new Runnable() {
                          public void run() {
                            if (parent.isDisposed()) return;
                            Shell shell = parent.getShell();
                            loadLibrary();
                            int /*long*/ awtHandle = getAWTHandle(window);
                            if (awtHandle == 0) return;
                            int /*long*/ xWindow =
                                OS.gdk_x11_drawable_get_xid(
                                    OS.GTK_WIDGET_WINDOW(OS.gtk_widget_get_toplevel(shell.handle)));
                            OS.XSetTransientForHint(
                                OS.gdk_x11_display_get_xdisplay(OS.gdk_display_get_default()),
                                awtHandle,
                                xWindow);
                          }
                        });
              }
            }
          }
        };
    frame.getToolkit().addAWTEventListener(awtListener, AWTEvent.WINDOW_EVENT_MASK);
    final Listener shellListener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Deiconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_DEICONIFIED));
                      }
                    });
                break;
              case SWT.Iconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));
                      }
                    });
                break;
            }
          }
        };
    Shell shell = parent.getShell();
    shell.addListener(SWT.Deiconify, shellListener);
    shell.addListener(SWT.Iconify, shellListener);

    Listener listener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Dispose:
                Shell shell = parent.getShell();
                shell.removeListener(SWT.Deiconify, shellListener);
                shell.removeListener(SWT.Iconify, shellListener);
                parent.setVisible(false);
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.getToolkit().removeAWTEventListener(awtListener);
                        frame.dispose();
                      }
                    });
                break;
              case SWT.Resize:
                if (Library.JAVA_VERSION >= Library.JAVA_VERSION(1, 6, 0)) {
                  final Rectangle clientArea = parent.getClientArea();
                  EventQueue.invokeLater(
                      new Runnable() {
                        public void run() {
                          frame.setSize(clientArea.width, clientArea.height);
                        }
                      });
                }
                break;
            }
          }
        };
    parent.addListener(SWT.Dispose, listener);
    parent.addListener(SWT.Resize, listener);

    parent
        .getDisplay()
        .asyncExec(
            new Runnable() {
              public void run() {
                if (parent.isDisposed()) return;
                final Rectangle clientArea = parent.getClientArea();
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.setSize(clientArea.width, clientArea.height);
                        frame.validate();
                      }
                    });
              }
            });
    return frame;
  }
Ejemplo n.º 10
0
 static Table checkNull(Table control) {
   if (control == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   return control;
 }