Esempio n. 1
0
  public void init(Shell parentShell) {
    shell = ShellFactory.createShell(parentShell, SWT.BORDER | SWT.TITLE | SWT.CLOSE | SWT.RESIZE);
    Utils.setShellIcon(shell);
    if (Constants.isOSX) monospace = new Font(shell.getDisplay(), "Courier", 12, SWT.NORMAL);
    else monospace = new Font(shell.getDisplay(), "Courier New", 8, SWT.NORMAL);

    shell.setText(
        MessageText.getString("window.welcome.title", new String[] {Constants.AZUREUS_VERSION}));

    display = shell.getDisplay();

    GridLayout layout = new GridLayout();
    shell.setLayout(layout);

    GridData data;

    cWhatsNew = new Composite(shell, SWT.BORDER);
    data = new GridData(GridData.FILL_BOTH);
    cWhatsNew.setLayoutData(data);
    cWhatsNew.setLayout(new FillLayout());

    Button bClose = new Button(shell, SWT.PUSH);
    bClose.setText(MessageText.getString("Button.close"));
    data = new GridData();
    data.widthHint = 70;
    data.horizontalAlignment = Constants.isOSX ? SWT.CENTER : SWT.RIGHT;
    bClose.setLayoutData(data);

    Listener closeListener =
        new Listener() {
          public void handleEvent(Event event) {
            close();
          }
        };

    bClose.addListener(SWT.Selection, closeListener);
    shell.addListener(SWT.Close, closeListener);

    shell.setDefaultButton(bClose);

    shell.addListener(
        SWT.Traverse,
        new Listener() {
          public void handleEvent(Event e) {
            if (e.character == SWT.ESC) {
              close();
            }
          }
        });

    shell.setSize(750, 500);
    Utils.centreWindow(shell);
    shell.layout();
    shell.open();
    pullWhatsNew(cWhatsNew);
  }
  private void createDialog(Shell applicationShell) {
    if (dialog == null || dialog.isDisposed()) {
      dialog = new Shell(applicationShell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);

      if (applicationShell.getImage() != null) {
        dialog.setImage(applicationShell.getImage());
      }

      dialog.addListener(
          SWT.Close,
          new Listener() {
            public void handleEvent(Event event) {
              hideCustomPanelChildren();
            }
          });

      dialog.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent arg0) {
              disposeImages();
            }
          });

      if (fileDialogMode != VFS_DIALOG_SAVEAS) {
        dialog.setText(Messages.getString("VfsFileChooserDialog.openFile")); // $NON-NLS-1$
      } else {
        dialog.setText(Messages.getString("VfsFileChooserDialog.saveAs")); // $NON-NLS-1$
      }
      dialog.setLayout(new GridLayout());
      dialog.setBackgroundMode(SWT.INHERIT_FORCE);
      dialog.setBackground(dialog.getDisplay().getSystemColor(SWT.COLOR_WHITE));
      createCustomUIPanel(dialog);
    }
  }
Esempio n. 3
0
  /* (non-Javadoc)
   * @see javax.microedition.lcdui.Displayable#handleShowEvent()
   */
  void eswtHandleShowCurrentEvent() {
    // If it alert is first displayable, default
    // displayable should be shown behind alert
    if (topShell.isVisible() == false && nextDisplayable == null) {
      topShell.setVisible(true);
    }
    super.eswtHandleShowCurrentEvent();
    topShell.addListener(SWT.Resize, resizeListener);

    // add key filter for scrollable text composite
    org.eclipse.swt.widgets.Display.getCurrent().addFilter(SWT.KeyDown, keyListener);
    org.eclipse.swt.widgets.Display.getCurrent().addFilter(SWT.Traverse, keyListener);
    org.eclipse.swt.widgets.Display.getCurrent().addFilter(SWT.MouseUp, keyListener);
    resetTimerTask(true);
  }
  /** This method initializes shell */
  private void initShell(final Shell shell) {
    FormLayout formLayout = new FormLayout();
    shell.setLayout(formLayout);

    // load and set icon
    Image image = new Image(shell.getDisplay(), Labels.getInstance().getImageAsStream("icon"));
    shell.setImage(image);

    shell.addListener(
        SWT.Close,
        new Listener() {
          public void handleEvent(Event event) {
            // save dimensions!
            guiConfig.setMainWindowSize(shell.getSize(), shell.getMaximized());
          }
        });
  }
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Widget");

    final Table table = new Table(shell, SWT.MULTI);
    table.setLinesVisible(true);
    table.setBounds(10, 10, 100, 100);
    for (int i = 0; i < 9; i++) {
      new TableItem(table, SWT.NONE).setText("item" + i);
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.pack();
    button.setLocation(10, 140);
    button.addListener(
        SWT.Selection,
        event -> {
          Point tableSize = table.getSize();
          GC gc = new GC(table);
          final Image image = new Image(display, tableSize.x, tableSize.y);
          gc.copyArea(image, 0, 0);
          gc.dispose();

          Shell popup = new Shell(shell);
          popup.setText("Image");
          popup.addListener(SWT.Close, e -> image.dispose());

          Canvas canvas = new Canvas(popup, SWT.NONE);
          canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10);
          canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));
          popup.pack();
          popup.open();
        });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Esempio n. 6
0
  MapShell(Display parent) {
    display = parent;
    mapShell = new Shell(display, SWT.MIN | SWT.CLOSE | SWT.RESIZE);
    mapShell.setText(RadarConsts.PROGRAM_NAME + " " + RadarConsts.VERSION);
    mapShell.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            saveWindowPosition();
          }
        });
    mapShell.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            renderMap();
          }
        });

    mapShell.setBackground(parent.getSystemColor(SWT.COLOR_BLACK));
  }
Esempio n. 7
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;
  }
 public static void main(String[] args) {
   Display display = new Display();
   final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
   shell.setText("Underline, Strike Out");
   Font font = shell.getFont();
   String text = "Here is some text that is underlined or struck out or both.";
   final TextLayout layout = new TextLayout(display);
   layout.setText(text);
   TextStyle style1 = new TextStyle(font, null, null);
   style1.underline = true;
   layout.setStyle(style1, 26, 35);
   TextStyle style2 = new TextStyle(font, null, null);
   style2.strikeout = true;
   layout.setStyle(style2, 40, 49);
   TextStyle style3 = new TextStyle(font, null, null);
   style3.underline = true;
   style3.strikeout = true;
   layout.setStyle(style3, 54, 57);
   shell.addListener(
       SWT.Paint,
       new Listener() {
         @Override
         public void handleEvent(Event event) {
           Point point = new Point(10, 10);
           int width = shell.getClientArea().width - 2 * point.x;
           layout.setWidth(width);
           layout.draw(event.gc, point.x, point.y);
         }
       });
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   layout.dispose();
   display.dispose();
 }
 public static void main(String[] args) {
   Display display = new Display();
   final Shell shell = new Shell(display);
   shell.setText("Text Editor");
   Menu bar = new Menu(shell, SWT.BAR);
   shell.setMenuBar(bar);
   MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
   fileItem.setText("&File");
   Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
   fileItem.setMenu(fileMenu);
   MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH);
   saveItem.setText("&Save\tCtrl+S");
   saveItem.setAccelerator(SWT.MOD1 + 'S');
   saveItem.addListener(SWT.Selection, e -> shell.setModified(false));
   MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
   exitItem.setText("Exit");
   exitItem.addListener(SWT.Selection, e -> shell.close());
   Text text = new Text(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
   text.addListener(SWT.Modify, e -> shell.setModified(true));
   shell.addListener(
       SWT.Close,
       e -> {
         if (shell.getModified()) {
           MessageBox box = new MessageBox(shell, SWT.PRIMARY_MODAL | SWT.OK | SWT.CANCEL);
           box.setText(shell.getText());
           box.setMessage("You have unsaved changes, do you want to exit?");
           e.doit = box.open() == SWT.OK;
         }
       });
   shell.setLayout(new FillLayout());
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
Esempio n. 10
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;
  }
Esempio n. 11
0
  /**
   * Init with listener
   *
   * @param azureus_core
   * @param parent
   * @param linkURL
   * @param referrer
   * @param listener
   */
  public OpenUrlWindow(
      final Shell parent,
      String linkURL,
      boolean default_magnet,
      final String referrer,
      final TorrentDownloaderCallBackInterface listener) {

    final Shell shell =
        ShellFactory.createShell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE);
    shell.setText(MessageText.getString("openUrl.title"));
    Utils.setShellIcon(shell);

    GridData gridData;
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    shell.setLayout(layout);

    // URL field

    Label label = new Label(shell, SWT.NULL);
    label.setText(MessageText.getString("openUrl.url"));
    gridData = new GridData();
    label.setLayoutData(gridData);

    final Text url = new Text(shell, SWT.BORDER);

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 400;
    gridData.horizontalSpan = 2;
    url.setLayoutData(gridData);
    if (linkURL == null) Utils.setTextLinkFromClipboard(shell, url, true, default_magnet);
    else url.setText(linkURL);
    url.setSelection(url.getText().length());

    // help field
    Label help_label = new Label(shell, SWT.NULL);
    help_label.setText(MessageText.getString("openUrl.url.info"));
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    help_label.setLayoutData(gridData);

    Label space = new Label(shell, SWT.NULL);
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    space.setLayoutData(gridData);

    // referrer field

    Label referrer_label = new Label(shell, SWT.NULL);
    referrer_label.setText(MessageText.getString("openUrl.referrer"));
    gridData = new GridData();
    referrer_label.setLayoutData(gridData);

    final Combo referrer_combo = new Combo(shell, SWT.BORDER);

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 150;
    gridData.grabExcessHorizontalSpace = true;
    referrer_combo.setLayoutData(gridData);

    final StringList referrers =
        COConfigurationManager.getStringListParameter("url_open_referrers");
    StringIterator iter = referrers.iterator();
    while (iter.hasNext()) {
      referrer_combo.add(iter.next());
    }

    if (referrer != null && referrer.length() > 0) {

      referrer_combo.setText(referrer);

    } else if (last_referrer != null) {

      referrer_combo.setText(last_referrer);
    }

    Label referrer_info = new Label(shell, SWT.NULL);
    referrer_info.setText(MessageText.getString("openUrl.referrer.info"));

    // line

    Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END);
    gridData.horizontalSpan = 3;
    labelSeparator.setLayoutData(gridData);

    // buttons

    Composite panel = new Composite(shell, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 3;
    panel.setLayout(layout);
    gridData =
        new GridData(
            GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_END);
    gridData.horizontalSpan = 3;
    gridData.grabExcessHorizontalSpace = true;
    panel.setLayoutData(gridData);

    new Label(panel, SWT.NULL);

    Button ok = new Button(panel, SWT.PUSH);
    gridData =
        new GridData(
            GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_END);
    gridData.widthHint = 70;
    gridData.grabExcessHorizontalSpace = true;
    ok.setLayoutData(gridData);
    ok.setText(MessageText.getString("Button.ok"));
    ok.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            last_referrer = referrer_combo.getText().trim();

            if (!referrers.contains(last_referrer)) {
              referrers.add(last_referrer);
              COConfigurationManager.setParameter("url_open_referrers", referrers);
              COConfigurationManager.save();
            }

            COConfigurationManager.setParameter(CONFIG_REFERRER_DEFAULT, last_referrer);
            COConfigurationManager.save();

            String url_str = url.getText();

            url_str = UrlUtils.parseTextForURL(url_str, true);

            if (url_str == null) {
              url_str = UrlUtils.parseTextForMagnets(url.getText());
            }

            if (url_str == null) {

              url_str = url.getText();
            }

            new FileDownloadWindow(parent, url_str, last_referrer, null, null, listener);
            shell.dispose();
          }
        });

    shell.setDefaultButton(ok);

    Button cancel = new Button(panel, SWT.PUSH);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gridData.grabExcessHorizontalSpace = false;
    gridData.widthHint = 70;
    cancel.setLayoutData(gridData);
    cancel.setText(MessageText.getString("Button.cancel"));
    cancel.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            shell.dispose();
          }
        });

    shell.addListener(
        SWT.Traverse,
        new Listener() {

          public void handleEvent(Event e) {

            if (e.character == SWT.ESC) {
              shell.dispose();
            }
          }
        });

    Point p = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    if (p.x > 800) {

      p.x = 800;
    }

    shell.setSize(p);

    Utils.createURLDropTarget(shell, url);

    Utils.centreWindow(shell);

    shell.open();
  }
Esempio n. 12
0
  public static void main(String[] args) {
    final Display display = new Display();
    final Image image = display.getSystemImage(SWT.ICON_INFORMATION);
    final Shell shell = new Shell(display, SWT.NO_TRIM);
    Region region = new Region();
    final ImageData imageData = image.getImageData();
    if (imageData.alphaData != null) {
      Rectangle pixel = new Rectangle(0, 0, 1, 1);
      for (int y = 0; y < imageData.height; y++) {
        for (int x = 0; x < imageData.width; x++) {
          if (imageData.getAlpha(x, y) == 255) {
            pixel.x = imageData.x + x;
            pixel.y = imageData.y + y;
            region.add(pixel);
          }
        }
      }
    } else {
      ImageData mask = imageData.getTransparencyMask();
      Rectangle pixel = new Rectangle(0, 0, 1, 1);
      for (int y = 0; y < mask.height; y++) {
        for (int x = 0; x < mask.width; x++) {
          if (mask.getPixel(x, y) != 0) {
            pixel.x = imageData.x + x;
            pixel.y = imageData.y + y;
            region.add(pixel);
          }
        }
      }
    }
    shell.setRegion(region);

    Listener l =
        new Listener() {
          /** The x/y of the MouseDown, relative to top-left of the shell. */
          int startX, startY;

          @Override
          public void handleEvent(Event e) {
            if (e.type == SWT.KeyDown && e.character == SWT.ESC) {
              shell.dispose();
            }
            if (e.type == SWT.MouseDown && e.button == 1) {
              Point p = shell.toDisplay(e.x, e.y);
              Point loc = shell.getLocation();
              startX = p.x - loc.x;
              startY = p.y - loc.y;
            }
            if (e.type == SWT.MouseMove && (e.stateMask & SWT.BUTTON1) != 0) {
              Point p = shell.toDisplay(e.x, e.y);
              p.x -= startX;
              p.y -= startY;
              shell.setLocation(p);
            }
            if (e.type == SWT.Paint) {
              e.gc.drawImage(image, imageData.x, imageData.y);
            }
          }
        };
    shell.addListener(SWT.KeyDown, l);
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseMove, l);
    shell.addListener(SWT.Paint, l);

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    region.dispose();
    image.dispose();
    display.dispose();
  }
  public static void main(String[] args) {
    final Display display = new Display();
    // Shell must be created with style SWT.NO_TRIM
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    // define a region that looks like a key hole
    Region region = new Region();
    region.add(circle(67, 67, 67));
    region.subtract(circle(20, 67, 50));
    region.subtract(new int[] {67, 50, 55, 105, 79, 105});
    // define the shape of the shell using setRegion
    shell.setRegion(region);
    Rectangle size = region.getBounds();
    shell.setSize(size.width, size.height);
    // add ability to move shell around
    Listener l =
        new Listener() {
          /** The x/y of the MouseDown, relative to top-left of the shell. */
          Point origin;

          @Override
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.MouseDown:
                Point point = shell.toDisplay(e.x, e.y);
                Point loc = shell.getLocation();
                origin = new Point(point.x - loc.x, point.y - loc.y);
                break;
              case SWT.MouseUp:
                origin = null;
                break;
              case SWT.MouseMove:
                if (origin != null) {
                  Point p = display.map(shell, null, e.x, e.y);
                  shell.setLocation(p.x - origin.x, p.y - origin.y);
                }
                break;
            }
          }
        };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);
    // add ability to close shell
    Button b = new Button(shell, SWT.PUSH);
    b.setBackground(shell.getBackground());
    b.setText("close");
    b.pack();
    b.setLocation(10, 68);
    b.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            shell.close();
          }
        });
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    region.dispose();
    display.dispose();
  }
    protected authDialog(
        AESemaphore _sem,
        Display display,
        String realm,
        boolean is_tracker,
        String target,
        String details) {
      sem = _sem;

      if (display.isDisposed()) {

        sem.releaseForever();

        return;
      }

      final String ignore_key = "IgnoreAuth:" + realm + ":" + target + ":" + details;

      if (RememberedDecisionsManager.getRememberedDecision(ignore_key) == 1) {

        Debug.out(
            "Authentication for "
                + realm
                + "/"
                + target
                + "/"
                + details
                + " ignored as told not to ask again");

        sem.releaseForever();

        return;
      }

      shell = ShellFactory.createMainShell(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

      Utils.setShellIcon(shell);
      Messages.setLanguageText(shell, "authenticator.title");

      GridLayout layout = new GridLayout();
      layout.numColumns = 3;

      shell.setLayout(layout);

      GridData gridData;

      // realm

      Label realm_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(realm_label, "authenticator.realm");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      realm_label.setLayoutData(gridData);

      Label realm_value = new Label(shell, SWT.NULL);
      realm_value.setText(realm.replaceAll("&", "&&"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      realm_value.setLayoutData(gridData);

      // target

      Label target_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(
          target_label, is_tracker ? "authenticator.tracker" : "authenticator.location");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      target_label.setLayoutData(gridData);

      Label target_value = new Label(shell, SWT.NULL);
      target_value.setText(target.replaceAll("&", "&&"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      target_value.setLayoutData(gridData);

      if (details != null) {

        Label details_label = new Label(shell, SWT.NULL);
        Messages.setLanguageText(
            details_label, is_tracker ? "authenticator.torrent" : "authenticator.details");
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 1;
        details_label.setLayoutData(gridData);

        Label details_value = new Label(shell, SWT.NULL);
        details_value.setText(details.replaceAll("&", "&&"));
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 2;
        details_value.setLayoutData(gridData);
      }
      // user

      Label user_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(user_label, "authenticator.user");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      user_label.setLayoutData(gridData);

      final Text user_value = new Text(shell, SWT.BORDER);
      user_value.setText("");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      user_value.setLayoutData(gridData);

      user_value.addListener(
          SWT.Modify,
          new Listener() {
            public void handleEvent(Event event) {
              username = user_value.getText();
            }
          });

      // password

      Label password_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(password_label, "authenticator.password");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      password_label.setLayoutData(gridData);

      final Text password_value = new Text(shell, SWT.BORDER);
      password_value.setEchoChar('*');
      password_value.setText("");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      password_value.setLayoutData(gridData);

      password_value.addListener(
          SWT.Modify,
          new Listener() {
            public void handleEvent(Event event) {
              password = password_value.getText();
            }
          });

      // persist

      Label blank_label = new Label(shell, SWT.NULL);
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      blank_label.setLayoutData(gridData);

      final Button checkBox = new Button(shell, SWT.CHECK);
      checkBox.setText(MessageText.getString("authenticator.savepassword"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      checkBox.setLayoutData(gridData);
      checkBox.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              persist = checkBox.getSelection();
            }
          });

      final Button dontAsk = new Button(shell, SWT.CHECK);
      dontAsk.setText(MessageText.getString("general.dont.ask.again"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      dontAsk.setLayoutData(gridData);
      dontAsk.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              RememberedDecisionsManager.setRemembered(ignore_key, dontAsk.getSelection() ? 1 : 0);
            }
          });

      // line

      Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      gridData.horizontalSpan = 3;
      labelSeparator.setLayoutData(gridData);

      // buttons

      new Label(shell, SWT.NULL);

      Button bOk = new Button(shell, SWT.PUSH);
      Messages.setLanguageText(bOk, "Button.ok");
      gridData =
          new GridData(
              GridData.FILL_HORIZONTAL
                  | GridData.HORIZONTAL_ALIGN_END
                  | GridData.HORIZONTAL_ALIGN_FILL);
      gridData.grabExcessHorizontalSpace = true;
      gridData.widthHint = 70;
      bOk.setLayoutData(gridData);
      bOk.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              close(true);
            }
          });

      Button bCancel = new Button(shell, SWT.PUSH);
      Messages.setLanguageText(bCancel, "Button.cancel");
      gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
      gridData.grabExcessHorizontalSpace = false;
      gridData.widthHint = 70;
      bCancel.setLayoutData(gridData);
      bCancel.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              close(false);
            }
          });

      shell.setDefaultButton(bOk);

      shell.addListener(
          SWT.Traverse,
          new Listener() {
            public void handleEvent(Event e) {
              if (e.character == SWT.ESC) {
                close(false);
              }
            }
          });

      shell.pack();

      Utils.centreWindow(shell);

      shell.open();
    }
Esempio n. 15
0
  protected void check() {
    if (display.isDisposed()) return;

    shell = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    Utils.setShellIcon(shell);
    shell.setText(MessageText.getString("dialog.associations.title"));

    GridLayout layout = new GridLayout();
    layout.numColumns = 3;

    shell.setLayout(layout);

    GridData gridData;

    // text

    Label user_label = new Label(shell, SWT.NULL);
    Messages.setLanguageText(user_label, "dialog.associations.prompt");
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 3;
    user_label.setLayoutData(gridData);

    final Button checkBox = new Button(shell, SWT.CHECK);
    checkBox.setSelection(true);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 3;
    checkBox.setLayoutData(gridData);
    Messages.setLanguageText(checkBox, "dialog.associations.askagain");

    // line

    Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    labelSeparator.setLayoutData(gridData);

    // buttons

    new Label(shell, SWT.NULL);

    Button bYes = new Button(shell, SWT.PUSH);
    bYes.setText(MessageText.getString("Button.yes"));
    gridData =
        new GridData(
            GridData.FILL_HORIZONTAL
                | GridData.HORIZONTAL_ALIGN_END
                | GridData.HORIZONTAL_ALIGN_FILL);
    gridData.grabExcessHorizontalSpace = true;
    gridData.widthHint = 70;
    bYes.setLayoutData(gridData);
    bYes.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            close(true, checkBox.getSelection());
          }
        });

    Button bNo = new Button(shell, SWT.PUSH);
    bNo.setText(MessageText.getString("Button.no"));
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gridData.grabExcessHorizontalSpace = false;
    gridData.widthHint = 70;
    bNo.setLayoutData(gridData);
    bNo.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            close(false, checkBox.getSelection());
          }
        });

    bYes.setFocus();
    shell.setDefaultButton(bYes);

    shell.addListener(
        SWT.Traverse,
        new Listener() {
          public void handleEvent(Event e) {
            if (e.character == SWT.ESC) {
              close(false, true);
            }
          }
        });

    shell.pack();

    Utils.centreWindow(shell);

    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
  }
Esempio n. 16
0
    protected authDialog(
        AESemaphore _sem, Display display, String realm, String tracker, String torrent_name) {
      sem = _sem;

      if (display.isDisposed()) {

        sem.release();

        return;
      }

      shell = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

      Utils.setShellIcon(shell);
      Messages.setLanguageText(shell, "authenticator.title");

      GridLayout layout = new GridLayout();
      layout.numColumns = 3;

      shell.setLayout(layout);

      GridData gridData;

      // realm

      Label realm_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(realm_label, "authenticator.realm");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      realm_label.setLayoutData(gridData);

      Label realm_value = new Label(shell, SWT.NULL);
      realm_value.setText(realm.replaceAll("&", "&&"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      realm_value.setLayoutData(gridData);

      // tracker

      Label tracker_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(tracker_label, "authenticator.tracker");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      tracker_label.setLayoutData(gridData);

      Label tracker_value = new Label(shell, SWT.NULL);
      tracker_value.setText(tracker.replaceAll("&", "&&"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      tracker_value.setLayoutData(gridData);

      if (torrent_name != null) {

        Label torrent_label = new Label(shell, SWT.NULL);
        Messages.setLanguageText(torrent_label, "authenticator.torrent");
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 1;
        torrent_label.setLayoutData(gridData);

        Label torrent_value = new Label(shell, SWT.NULL);
        torrent_value.setText(torrent_name.replaceAll("&", "&&"));
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 2;
        torrent_value.setLayoutData(gridData);
      }
      // user

      Label user_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(user_label, "authenticator.user");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      user_label.setLayoutData(gridData);

      final Text user_value = new Text(shell, SWT.BORDER);
      user_value.setText("");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      user_value.setLayoutData(gridData);

      user_value.addListener(
          SWT.Modify,
          new Listener() {
            public void handleEvent(Event event) {
              username = user_value.getText();
            }
          });

      // password

      Label password_label = new Label(shell, SWT.NULL);
      Messages.setLanguageText(password_label, "authenticator.password");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      password_label.setLayoutData(gridData);

      final Text password_value = new Text(shell, SWT.BORDER);
      password_value.setEchoChar('*');
      password_value.setText("");
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      password_value.setLayoutData(gridData);

      password_value.addListener(
          SWT.Modify,
          new Listener() {
            public void handleEvent(Event event) {
              password = password_value.getText();
            }
          });

      // persist

      Label blank_label = new Label(shell, SWT.NULL);
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 1;
      blank_label.setLayoutData(gridData);

      final Button checkBox = new Button(shell, SWT.CHECK);
      checkBox.setText(MessageText.getString("authenticator.savepassword"));
      gridData = new GridData(GridData.FILL_BOTH);
      gridData.horizontalSpan = 2;
      checkBox.setLayoutData(gridData);
      checkBox.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              persist = checkBox.getSelection();
            }
          });

      // line

      Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
      gridData = new GridData(GridData.FILL_HORIZONTAL);
      gridData.horizontalSpan = 3;
      labelSeparator.setLayoutData(gridData);

      // buttons

      new Label(shell, SWT.NULL);

      Button bOk = new Button(shell, SWT.PUSH);
      Messages.setLanguageText(bOk, "Button.ok");
      gridData =
          new GridData(
              GridData.FILL_HORIZONTAL
                  | GridData.HORIZONTAL_ALIGN_END
                  | GridData.HORIZONTAL_ALIGN_FILL);
      gridData.grabExcessHorizontalSpace = true;
      gridData.widthHint = 70;
      bOk.setLayoutData(gridData);
      bOk.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              close(true);
            }
          });

      Button bCancel = new Button(shell, SWT.PUSH);
      Messages.setLanguageText(bCancel, "Button.cancel");
      gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
      gridData.grabExcessHorizontalSpace = false;
      gridData.widthHint = 70;
      bCancel.setLayoutData(gridData);
      bCancel.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event e) {
              close(false);
            }
          });

      shell.setDefaultButton(bOk);

      shell.addListener(
          SWT.Traverse,
          new Listener() {
            public void handleEvent(Event e) {
              if (e.character == SWT.ESC) {
                close(false);
              }
            }
          });

      shell.pack();

      Utils.centreWindow(shell);

      shell.open();

      shell.forceActive();
    }