/**
   * Creates an instance of a ControlExample embedded inside the supplied parent Composite.
   *
   * @param parent the container of the example
   */
  public ControlExample(Composite parent) {
    initResources();
    tabFolder = new TabFolder(parent, SWT.NONE);
    tabs = createTabs();
    for (Tab tab : tabs) {
      TabItem item = new TabItem(tabFolder, SWT.NONE);
      item.setText(tab.getTabText());
      item.setControl(tab.createTabFolderPage(tabFolder));
      item.setData(tab);
    }

    /* Workaround: if the tab folder is wider than the screen,
     * Mac platforms clip instead of somehow scrolling the tab items.
     * We try to recover some width by using shorter tab names. */
    Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = parent.getMonitor().getClientArea();
    boolean isMac = SWT.getPlatform().equals("cocoa");
    if (size.x > monitorArea.width && isMac) {
      TabItem[] tabItems = tabFolder.getItems();
      for (int i = 0; i < tabItems.length; i++) {
        tabItems[i].setText(tabs[i].getShortTabText());
      }
    }
    startup = false;
  }
Ejemplo n.º 2
0
 /**
  * Adds the listener to the collection of listeners who will be notified when the user changes the
  * receiver's selection, by sending it one of the messages defined in the <code>SelectionListener
  * </code> interface.
  *
  * <p>When <code>widgetSelected</code> is called, the item field of the event object is valid. If
  * the receiver has <code>SWT.CHECK</code> style set and the check selection changes, the event
  * object detail field contains the value <code>SWT.CHECK</code>. <code>widgetDefaultSelected
  * </code> is typically called when an item is double-clicked.
  *
  * @param listener the listener which should be notified when the user changes the receiver's
  *     selection
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the listener is null
  *     </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>
  *
  * @see SelectionListener
  * @see SelectionEvent
  * @see #removeSelectionListener(SelectionListener)
  */
 public void addSelectionListener(SelectionListener listener) {
   checkWidget();
   if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   TypedListener typedListener = new TypedListener(listener);
   addListener(SWT.Selection, typedListener);
   addListener(SWT.DefaultSelection, typedListener);
 }
Ejemplo n.º 3
0
 /**
  * Finds the program that is associated with an extension. The extension may or may not begin with
  * a '.'. Note that a <code>Display</code> must already exist to guarantee that this method
  * returns an appropriate result.
  *
  * @param extension the program extension
  * @return the program or <code>null</code>
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT when extension is null
  *     </ul>
  */
 public static Program findProgram(String extension) {
   NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
   try {
     if (extension == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
     if (extension.length() == 0) return null;
     Program program = null;
     char[] chars;
     if (extension.charAt(0) != '.') {
       chars = new char[extension.length()];
       extension.getChars(0, chars.length, chars, 0);
     } else {
       chars = new char[extension.length() - 1];
       extension.getChars(1, extension.length(), chars, 0);
     }
     NSString ext = NSString.stringWithCharacters(chars, chars.length);
     if (ext != null) {
       byte[] fsRef = new byte[80];
       if (OS.LSGetApplicationForInfo(
               OS.kLSUnknownType, OS.kLSUnknownCreator, ext.id, OS.kLSRolesAll, fsRef, null)
           == OS.noErr) {
         long /*int*/ url = OS.CFURLCreateFromFSRef(OS.kCFAllocatorDefault(), fsRef);
         if (url != 0) {
           NSString bundlePath = new NSURL(url).path();
           NSBundle bundle = NSBundle.bundleWithPath(bundlePath);
           if (bundle != null) program = getProgram(bundle);
           OS.CFRelease(url);
         }
       }
     }
     return program;
   } finally {
     pool.release();
   }
 }
Ejemplo n.º 4
0
  /** Export the selected values from the table to a csv file */
  private void export() {

    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    String[] filterNames = new String[] {"CSV Files", "All Files (*)"};
    String[] filterExtensions = new String[] {"*.csv;", "*"};
    String filterPath = "/";
    String platform = SWT.getPlatform();
    if (platform.equals("win32") || platform.equals("wpf")) {
      filterNames = new String[] {"CSV Files", "All Files (*.*)"};
      filterExtensions = new String[] {"*.csv", "*.*"};
      filterPath = "c:\\";
    }
    dialog.setFilterNames(filterNames);
    dialog.setFilterExtensions(filterExtensions);
    dialog.setFilterPath(filterPath);
    try {
      dialog.setFileName(this.getCurrentKey() + ".csv");
    } catch (Exception e) {
      dialog.setFileName("export.csv");
    }
    String fileName = dialog.open();

    FileOutputStream fos;
    OutputStreamWriter out;
    try {
      fos = new FileOutputStream(fileName);
      out = new OutputStreamWriter(fos, "UTF-8");
    } catch (Exception e) {
      MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
      messageBox.setMessage("Error creating export file " + fileName + " : " + e.getMessage());
      messageBox.open();
      return;
    }

    Vector<TableItem> sel = new Vector<TableItem>(this.dataTable.getSelection().length);

    sel.addAll(Arrays.asList(this.dataTable.getSelection()));
    Collections.reverse(sel);

    for (TableItem item : sel) {
      String date = item.getText(0);
      String value = item.getText(1);
      try {
        out.write(date + ";" + value + "\n");
      } catch (IOException e) {
        continue;
      }
    }

    try {
      out.close();
      fos.close();
    } catch (IOException e) {
      MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
      messageBox.setMessage("Error writing export file " + fileName + " : " + e.getMessage());
      messageBox.open();
      e.printStackTrace();
    }
  }
Ejemplo n.º 5
0
 /**
  * Positions the TableCursor over the cell at the given row and column in the parent table.
  *
  * @param row the TableItem of the row for the cell to select
  * @param column the index of column for the cell to select
  * @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>
  */
 public void setSelection(TableItem row, int column) {
   checkWidget();
   int columnCount = table.getColumnCount();
   int maxColumnIndex = columnCount == 0 ? 0 : columnCount - 1;
   if (row == null || row.isDisposed() || column < 0 || column > maxColumnIndex)
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   setRowColumn(table.indexOf(row), column, false);
 }
Ejemplo n.º 6
0
 /**
  * Positions the TableCursor over the cell at the given row and column in the parent table.
  *
  * @param row the index of the row for the cell to select
  * @param column the index of column for the cell to select
  * @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>
  */
 public void setSelection(int row, int column) {
   checkWidget();
   int columnCount = table.getColumnCount();
   int maxColumnIndex = columnCount == 0 ? 0 : columnCount - 1;
   if (row < 0 || row >= table.getItemCount() || column < 0 || column > maxColumnIndex)
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   setRowColumn(row, column, false);
 }
Ejemplo n.º 7
0
 /**
  * Removes the listener from the collection of listeners who will be notified when the user
  * changes the receiver's selection.
  *
  * @param listener the listener which should no longer be notified
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the listener is null
  *     </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>
  *
  * @see SelectionListener
  * @see #addSelectionListener(SelectionListener)
  * @since 3.0
  */
 public void removeSelectionListener(SelectionListener listener) {
   checkWidget();
   if (listener == null) {
     SWT.error(SWT.ERROR_NULL_ARGUMENT);
   }
   removeListener(SWT.Selection, listener);
   removeListener(SWT.DefaultSelection, listener);
 }
Ejemplo n.º 8
0
 /**
  * Set the horizontal alignment of the CLabel. Use the values LEFT, CENTER and RIGHT to align
  * image and text within the available space.
  *
  * @param align the alignment style of LEFT, RIGHT or CENTER
  * @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
  *       <li>ERROR_INVALID_ARGUMENT - if the value of align is not one of SWT.LEFT, SWT.RIGHT or
  *           SWT.CENTER
  *     </ul>
  */
 public void setAlignment(int align) {
   checkWidget();
   if (align != SWT.LEFT && align != SWT.RIGHT && align != SWT.CENTER) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (this.align != align) {
     this.align = align;
     redraw();
   }
 }
Ejemplo n.º 9
0
 /**
  * Executes the program with the file as the single argument in the operating system. It is the
  * responsibility of the programmer to ensure that the file contains valid data for this program.
  *
  * @param fileName the file or program name
  * @return <code>true</code> if the file is launched, otherwise <code>false</code>
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT when fileName is null
  *     </ul>
  */
 public boolean execute(String fileName) {
   if (fileName == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
   try {
     NSWorkspace workspace = NSWorkspace.sharedWorkspace();
     NSURL url = getURL(fileName);
     NSArray urls = NSArray.arrayWithObject(url);
     return workspace.openURLs(urls, NSString.stringWith(identifier), 0, null, 0);
   } finally {
     pool.release();
   }
 }
Ejemplo n.º 10
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.º 11
0
 /**
  * Launches the operating system executable associated with the file or URL (http:// or https://).
  * If the file is an executable then the executable is launched. The program is launched with the
  * specified working directory only when the <code>workingDir</code> exists and <code>fileName
  * </code> is an executable. Note that a <code>Display</code> must already exist to guarantee that
  * this method returns an appropriate result.
  *
  * @param fileName the file name or program name or URL (http:// or https://)
  * @param workingDir the name of the working directory or null
  * @return <code>true</code> if the file is launched, otherwise <code>false</code>
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT when fileName is null
  *     </ul>
  *
  * @since 3.6
  */
 public static boolean launch(String fileName, String workingDir) {
   if (fileName == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
   try {
     if (workingDir != null && isExecutable(fileName)) {
       try {
         Compatibility.exec(new String[] {fileName}, null, workingDir);
         return true;
       } catch (IOException e) {
         return false;
       }
     }
     NSURL url = getURL(fileName);
     NSWorkspace workspace = NSWorkspace.sharedWorkspace();
     return workspace.openURL(url);
   } finally {
     pool.release();
   }
 }
Ejemplo n.º 12
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.º 13
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.º 14
0
 public void createPartControl(org.eclipse.swt.widgets.Composite frame) {
   final org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHandler tooltip =
       new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHandler(frame.getShell());
   org.eclipse.swt.layout.GridLayout layout = new org.eclipse.swt.layout.GridLayout();
   layout.numColumns = 3;
   frame.setLayout(layout);
   java.lang.String platform = SWT.getPlatform();
   java.lang.String helpKey = "F1";
   if (platform.equals("gtk")) {
     helpKey = "Ctrl+F1";
   }
   if (platform.equals("carbon") || platform.equals("cocoa")) {
     helpKey = "Help";
   }
   org.eclipse.swt.widgets.ToolBar bar = new org.eclipse.swt.widgets.ToolBar(frame, SWT.BORDER);
   for (int i = 0; i < 5; i++) {
     org.eclipse.swt.widgets.ToolItem item = new org.eclipse.swt.widgets.ToolItem(bar, SWT.PUSH);
     item.setText(
         getResourceString("ToolItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("ToolItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("ToolItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   org.eclipse.swt.layout.GridData gridData = new org.eclipse.swt.layout.GridData();
   gridData.horizontalSpan = 3;
   bar.setLayoutData(gridData);
   tooltip.activateHoverHelp(bar);
   org.eclipse.swt.widgets.Table table = new org.eclipse.swt.widgets.Table(frame, SWT.BORDER);
   for (int i = 0; i < 4; i++) {
     org.eclipse.swt.widgets.TableItem item =
         new org.eclipse.swt.widgets.TableItem(table, SWT.PUSH);
     item.setText(getResourceString("Item", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData("TIP_IMAGE", images[hhiInformation]);
     item.setText(
         getResourceString("TableItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("TableItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("TableItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   table.setLayoutData(new org.eclipse.swt.layout.GridData(GridData.VERTICAL_ALIGN_FILL));
   tooltip.activateHoverHelp(table);
   org.eclipse.swt.widgets.Tree tree = new org.eclipse.swt.widgets.Tree(frame, SWT.BORDER);
   for (int i = 0; i < 4; i++) {
     org.eclipse.swt.widgets.TreeItem item = new org.eclipse.swt.widgets.TreeItem(tree, SWT.PUSH);
     item.setText(getResourceString("Item", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData("TIP_IMAGE", images[hhiWarning]);
     item.setText(
         getResourceString("TreeItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("TreeItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("TreeItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   tree.setLayoutData(new org.eclipse.swt.layout.GridData(GridData.VERTICAL_ALIGN_FILL));
   tooltip.activateHoverHelp(tree);
   org.eclipse.swt.widgets.Button button = new org.eclipse.swt.widgets.Button(frame, SWT.PUSH);
   button.setText(getResourceString("Hello.text"));
   button.setData("TIP_TEXT", getResourceString("Hello.tooltip"));
   tooltip.activateHoverHelp(button);
 }
Ejemplo n.º 15
0
  /**
   * Specify a gradient of colours to be drawn in the background of the CLabel.
   *
   * <p>For example, to draw a gradient that varies from dark blue to white in the vertical,
   * direction use the following call to setBackground:
   *
   * <pre>
   * clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE),
   * 	                           display.getSystemColor(SWT.COLOR_WHITE)},
   * 	                 new int[] {100}, true);
   * </pre>
   *
   * @param colors an array of Color that specifies the colors to appear in the gradient in order of
   *     appearance from left/top to right/bottom; The value <code>null</code> clears the background
   *     gradient; the value <code>null</code> can be used inside the array of Color to specify the
   *     background color.
   * @param percents an array of integers between 0 and 100 specifying the percent of the
   *     width/height of the widget at which the color should change; the size of the percents array
   *     must be one less than the size of the colors array.
   * @param vertical indicate the direction of the gradient. True is vertical and false is
   *     horizontal.
   * @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
   *       <li>ERROR_INVALID_ARGUMENT - if the values of colors and percents are not consistent
   *     </ul>
   *
   * @since 3.0
   */
  public void setBackground(Color[] colors, int[] percents, boolean vertical) {
    checkWidget();
    if (colors != null) {
      if (percents == null || percents.length != colors.length - 1) {
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
      }
      if (getDisplay().getDepth() < 15) {
        // Don't use gradients on low color displays
        colors = new Color[] {colors[colors.length - 1]};
        percents = new int[] {};
      }
      for (int i = 0; i < percents.length; i++) {
        if (percents[i] < 0 || percents[i] > 100) {
          SWT.error(SWT.ERROR_INVALID_ARGUMENT);
        }
        if (i > 0 && percents[i] < percents[i - 1]) {
          SWT.error(SWT.ERROR_INVALID_ARGUMENT);
        }
      }
    }

    // Are these settings the same as before?
    final Color background = getBackground();
    if (backgroundImage == null) {
      if ((gradientColors != null)
          && (colors != null)
          && (gradientColors.length == colors.length)) {
        boolean same = false;
        for (int i = 0; i < gradientColors.length; i++) {
          same =
              (gradientColors[i] == colors[i])
                  || ((gradientColors[i] == null) && (colors[i] == background))
                  || ((gradientColors[i] == background) && (colors[i] == null));
          if (!same) break;
        }
        if (same) {
          for (int i = 0; i < gradientPercents.length; i++) {
            same = gradientPercents[i] == percents[i];
            if (!same) break;
          }
        }
        if (same && this.gradientVertical == vertical) return;
      }
    } else {
      backgroundImage = null;
    }
    // Store the new settings
    if (colors == null) {
      gradientColors = null;
      gradientPercents = null;
      gradientVertical = false;
    } else {
      gradientColors = new Color[colors.length];
      for (int i = 0; i < colors.length; ++i)
        gradientColors[i] = (colors[i] != null) ? colors[i] : background;
      gradientPercents = new int[percents.length];
      for (int i = 0; i < percents.length; ++i) gradientPercents[i] = percents[i];
      gradientVertical = vertical;
    }
    // Refresh with the new settings
    redraw();
  }
Ejemplo n.º 16
0
  /**
   * Create a GLCanvas widget using the attributes described in the GLData object provided.
   *
   * @param parent a composite widget
   * @param style the bitwise OR'ing of widget styles
   * @param data the requested attributes of the GLCanvas
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT when the data is null
   *       <li>ERROR_UNSUPPORTED_DEPTH when the requested attributes cannot be provided
   *     </ul>
   *     </ul>
   */
  public GLCanvas(Composite parent, int style, GLData data) {
    super(parent, style);
    if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    int glxAttrib[] = new int[MAX_ATTRIBUTES];
    int pos = 0;
    glxAttrib[pos++] = GLX.GLX_RGBA;
    if (data.doubleBuffer) glxAttrib[pos++] = GLX.GLX_DOUBLEBUFFER;
    if (data.stereo) glxAttrib[pos++] = GLX.GLX_STEREO;
    if (data.redSize > 0) {
      glxAttrib[pos++] = GLX.GLX_RED_SIZE;
      glxAttrib[pos++] = data.redSize;
    }
    if (data.greenSize > 0) {
      glxAttrib[pos++] = GLX.GLX_GREEN_SIZE;
      glxAttrib[pos++] = data.greenSize;
    }
    if (data.blueSize > 0) {
      glxAttrib[pos++] = GLX.GLX_BLUE_SIZE;
      glxAttrib[pos++] = data.blueSize;
    }
    if (data.alphaSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ALPHA_SIZE;
      glxAttrib[pos++] = data.alphaSize;
    }
    if (data.depthSize > 0) {
      glxAttrib[pos++] = GLX.GLX_DEPTH_SIZE;
      glxAttrib[pos++] = data.depthSize;
    }
    if (data.stencilSize > 0) {
      glxAttrib[pos++] = GLX.GLX_STENCIL_SIZE;
      glxAttrib[pos++] = data.stencilSize;
    }
    if (data.accumRedSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ACCUM_RED_SIZE;
      glxAttrib[pos++] = data.accumRedSize;
    }
    if (data.accumGreenSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ACCUM_GREEN_SIZE;
      glxAttrib[pos++] = data.accumGreenSize;
    }
    if (data.accumBlueSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ACCUM_BLUE_SIZE;
      glxAttrib[pos++] = data.accumBlueSize;
    }
    if (data.accumAlphaSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ACCUM_ALPHA_SIZE;
      glxAttrib[pos++] = data.accumAlphaSize;
    }
    if (data.sampleBuffers > 0) {
      glxAttrib[pos++] = GLX.GLX_SAMPLE_BUFFERS;
      glxAttrib[pos++] = data.sampleBuffers;
    }
    if (data.samples > 0) {
      glxAttrib[pos++] = GLX.GLX_SAMPLES;
      glxAttrib[pos++] = data.samples;
    }
    glxAttrib[pos++] = 0;
    OS.gtk_widget_realize(handle);
    int /*long*/ window = OS.GTK_WIDGET_WINDOW(handle);
    int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay(window);
    int /*long*/ infoPtr = GLX.glXChooseVisual(xDisplay, OS.XDefaultScreen(xDisplay), glxAttrib);
    if (infoPtr == 0) {
      dispose();
      SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
    }
    vinfo = new XVisualInfo();
    GLX.memmove(vinfo, infoPtr, XVisualInfo.sizeof);
    OS.XFree(infoPtr);
    int /*long*/ screen = OS.gdk_screen_get_default();
    int /*long*/ gdkvisual = OS.gdk_x11_screen_lookup_visual(screen, vinfo.visualid);
    // FIXME- share lists
    // context = GLX.glXCreateContext (xDisplay, info, share == null ? 0 : share.context, true);
    context = GLX.glXCreateContext(xDisplay, vinfo, 0, true);
    if (context == 0) SWT.error(SWT.ERROR_NO_HANDLES);
    GdkWindowAttr attrs = new GdkWindowAttr();
    attrs.width = 1;
    attrs.height = 1;
    attrs.event_mask =
        OS.GDK_KEY_PRESS_MASK
            | OS.GDK_KEY_RELEASE_MASK
            | OS.GDK_FOCUS_CHANGE_MASK
            | OS.GDK_POINTER_MOTION_MASK
            | OS.GDK_BUTTON_PRESS_MASK
            | OS.GDK_BUTTON_RELEASE_MASK
            | OS.GDK_ENTER_NOTIFY_MASK
            | OS.GDK_LEAVE_NOTIFY_MASK
            | OS.GDK_EXPOSURE_MASK
            | OS.GDK_VISIBILITY_NOTIFY_MASK
            | OS.GDK_POINTER_MOTION_HINT_MASK;
    attrs.window_type = OS.GDK_WINDOW_CHILD;
    attrs.visual = gdkvisual;
    glWindow = OS.gdk_window_new(window, attrs, OS.GDK_WA_VISUAL);
    OS.gdk_window_set_user_data(glWindow, handle);
    if ((style & SWT.NO_BACKGROUND) != 0) OS.gdk_window_set_back_pixmap(window, 0, false);
    xWindow = OS.gdk_x11_drawable_get_xid(glWindow);
    OS.gdk_window_show(glWindow);

    Listener listener =
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Paint:
                /**
                 * Bug in MESA. MESA does some nasty sort of polling to try and ensure that their
                 * buffer sizes match the current X state. This state can be updated using
                 * glViewport(). FIXME: There has to be a better way of doing this.
                 */
                int[] viewport = new int[4];
                GLX.glGetIntegerv(GLX.GL_VIEWPORT, viewport);
                GLX.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
                break;
              case SWT.Resize:
                Rectangle clientArea = getClientArea();
                OS.gdk_window_move(glWindow, clientArea.x, clientArea.y);
                OS.gdk_window_resize(glWindow, clientArea.width, clientArea.height);
                break;
              case SWT.Dispose:
                int /*long*/ window = OS.GTK_WIDGET_WINDOW(handle);
                int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay(window);
                if (context != 0) {
                  if (GLX.glXGetCurrentContext() == context) {
                    GLX.glXMakeCurrent(xDisplay, 0, 0);
                  }
                  GLX.glXDestroyContext(xDisplay, context);
                  context = 0;
                }
                if (glWindow != 0) {
                  OS.gdk_window_destroy(glWindow);
                  glWindow = 0;
                }
                break;
            }
          }
        };
    addListener(SWT.Resize, listener);
    addListener(SWT.Paint, listener);
    addListener(SWT.Dispose, listener);
  }
Ejemplo n.º 17
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.º 18
0
 void paint(Event event) {
   if (row == null) return;
   int columnIndex = column == null ? 0 : table.indexOf(column);
   GC gc = event.gc;
   gc.setBackground(getBackground());
   gc.setForeground(getForeground());
   gc.fillRectangle(event.x, event.y, event.width, event.height);
   int x = 0;
   Point size = getSize();
   Image image = row.getImage(columnIndex);
   if (image != null) {
     Rectangle imageSize = image.getBounds();
     int imageY = (size.y - imageSize.height) / 2;
     gc.drawImage(image, x, imageY);
     x += imageSize.width;
   }
   String text = row.getText(columnIndex);
   if (text.length() > 0) {
     Rectangle bounds = row.getBounds(columnIndex);
     Point extent = gc.stringExtent(text);
     // Temporary code - need a better way to determine table trim
     String platform = SWT.getPlatform();
     if ("win32".equals(platform)) { // $NON-NLS-1$
       if (table.getColumnCount() == 0 || columnIndex == 0) {
         x += 2;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 6;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 6;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2;
             break;
         }
       }
     } else {
       if (table.getColumnCount() == 0) {
         x += 5;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 5;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 2;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2 + 2;
             break;
         }
       }
     }
     int textY = (size.y - extent.y) / 2;
     gc.drawString(text, x, textY);
   }
   if (isFocusControl()) {
     Display display = getDisplay();
     gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
     gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
     gc.drawFocus(0, 0, size.x, size.y);
   }
 }