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);
    }
  }
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("SWT and Swing DND Example");
    GridLayout layout = new GridLayout(1, false);
    shell.setLayout(layout);

    Text swtText = new Text(shell, SWT.BORDER);
    swtText.setText("SWT Text");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    swtText.setLayoutData(data);
    setDragDrop(swtText);

    Composite comp = new Composite(shell, SWT.EMBEDDED);
    java.awt.Frame frame = SWT_AWT.new_Frame(comp);
    JTextField swingText = new JTextField(40);
    swingText.setText("Swing Text");
    swingText.setDragEnabled(true);
    frame.add(swingText);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = swingText.getPreferredSize().height;
    comp.setLayoutData(data);

    shell.setSize(400, 200);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setText("StyledText with underline and strike through");
   shell.setLayout(new FillLayout());
   StyledText text = new StyledText(shell, SWT.BORDER);
   text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
   // make 0123456789 appear underlined
   StyleRange style1 = new StyleRange();
   style1.start = 0;
   style1.length = 10;
   style1.underline = true;
   text.setStyleRange(style1);
   // make ABCDEFGHIJKLM have a strike through
   StyleRange style2 = new StyleRange();
   style2.start = 11;
   style2.length = 13;
   style2.strikeout = true;
   text.setStyleRange(style2);
   // make NOPQRSTUVWXYZ appear underlined and have a strike through
   StyleRange style3 = new StyleRange();
   style3.start = 25;
   style3.length = 13;
   style3.underline = true;
   style3.strikeout = true;
   text.setStyleRange(style3);
   shell.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
示例#4
0
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setText("Hi there, SWT!"); // Title bar
   shell.open();
   while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep();
   display.dispose();
 }
示例#5
0
文件: View.java 项目: shader/gdr
  public View(Controller controller) {
    this.controller = controller;
    display = new Display();
    shell = new Shell(display);
    shell.setText("Gallant Animation Viewer");

    shell.setLayout(new GridLayout());
  }
示例#6
0
 public void setTitle(String title, boolean append) {
   String text;
   if (append == true) {
     text = RadarConsts.PROGRAM_NAME + " " + RadarConsts.VERSION + " - " + title;
   } else {
     text = title;
   }
   mapShell.setText(text);
 }
示例#7
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);
  }
  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();
  }
示例#9
0
  /** Create contents of the window. */
  protected void createContents() {
    shlUCEditor = new Shell();
    shlUCEditor.setSize(722, 530);
    shlUCEditor.setText("µC Editor");
    shlUCEditor.setLayout(new GridLayout(1, false));

    Label lblAddElements = new Label(shlUCEditor, SWT.CENTER);
    lblAddElements.setFont(SWTResourceManager.getFont("Lucida Grande", 20, SWT.NORMAL));
    lblAddElements.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
    lblAddElements.setText("Microcontroller Editor");

    table = new Table(shlUCEditor, SWT.BORDER | SWT.FULL_SELECTION);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    TableColumn tblclmnType = new TableColumn(table, SWT.CENTER);
    tblclmnType.setWidth(123);
    tblclmnType.setText("Type");
    // Set not editable
    //		tblclmnType.setData(new UCEditorColumnData(false));

    TableColumn tblclmnName = new TableColumn(table, SWT.CENTER);
    tblclmnName.setWidth(193);
    tblclmnName.setText("Name");

    TableColumn tblclmnId = new TableColumn(table, SWT.CENTER);
    tblclmnId.setWidth(184);
    tblclmnId.setText("Port");

    // Allow the table to be edited
    //		table.addListener(SWT.MouseDoubleClick, new ElementsDoubleClickListener(this, table));

    Label label = new Label(shlUCEditor, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setAlignment(SWT.CENTER);
    label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));

    Label lblDoubleClickTo = new Label(shlUCEditor, SWT.NONE);
    lblDoubleClickTo.setText("Double click a microcontroller to make changes. ");

    Composite composite = new Composite(shlUCEditor, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    Button btnNewButton = new Button(composite, SWT.NONE);
    btnNewButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            addController();
          }
        });
    btnNewButton.setBounds(0, 0, 94, 28);
    btnNewButton.setText("Add Local Arduino");
  }
 /** Invokes as a standalone program. */
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display, SWT.SHELL_TRIM);
   shell.setLayout(new FillLayout());
   ControlExample instance = new ControlExample(shell);
   shell.setText(getResourceString("window.title"));
   setShellSize(instance, shell);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   instance.dispose();
   display.dispose();
 }
示例#11
0
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Snippet 346");

    Text text = new Text(shell, SWT.PASSWORD | SWT.BORDER);
    text.setTextChars(new char[] {'p', 'a', 's', 's'});
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
示例#12
0
 public static void main(String[] args) {
   Display display = Display.getDefault();
   Shell shell = new Shell(display);
   @SuppressWarnings("unused")
   MainWindow inst = new MainWindow(shell, SWT.NULL);
   shell.setLayout(new FillLayout());
   shell.setImage(SWTResourceManager.getImage("images/16x16.png"));
   shell.setText("Change This Title");
   shell.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif"));
   shell.layout();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
 }
 /**
  * Opens the dialog and returns the input
  *
  * @return String
  */
 public String open() {
   // Create the dialog window
   Shell shell = new Shell(getParent(), getStyle());
   shell.setText(getText());
   shell.setImage(UIUtils.getImageRegistry().get("sfdc_icon")); // $NON-NLS-1$
   createContents(shell);
   shell.pack();
   shell.open();
   Display display = getParent().getDisplay();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   // Return the entered value, or null
   return input;
 }
  private boolean save() {
    if (file == null) return saveAs();

    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    TableItem[] items = table.getItems();
    String[] lines = new String[items.length];
    for (int i = 0; i < items.length; i++) {
      String[] itemText = new String[table.getColumnCount()];
      for (int j = 0; j < itemText.length; j++) {
        itemText[j] = items[i].getText(j);
      }
      lines[i] = encodeLine(itemText);
    }

    FileWriter fileWriter = null;
    try {
      fileWriter = new FileWriter(file.getAbsolutePath(), false);
      for (int i = 0; i < lines.length; i++) {
        fileWriter.write(lines[i]);
      }
    } catch (FileNotFoundException e) {
      displayError(resMessages.getString("File_not_found") + "\n" + file.getName());
      return false;
    } catch (IOException e) {
      displayError(resMessages.getString("IO_error_write") + "\n" + file.getName());
      return false;
    } finally {
      shell.setCursor(null);
      waitCursor.dispose();

      if (fileWriter != null) {
        try {
          fileWriter.close();
        } catch (IOException e) {
          displayError(resMessages.getString("IO_error_close") + "\n" + file.getName());
          return false;
        }
      }
    }

    shell.setText(resMessages.getString("Title_bar") + file.getName());
    isModified = false;
    return true;
  }
示例#15
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));
  }
示例#16
0
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(new FillLayout());
   shell.setText("Mozilla");
   final Browser browser;
   try {
     browser = new Browser(shell, SWT.MOZILLA);
   } catch (SWTError e) {
     System.out.println("Could not instantiate Browser: " + e.getMessage());
     display.dispose();
     return;
   }
   shell.open();
   browser.setUrl("http://mozilla.org");
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
示例#17
0
  public void open() {

    Point size = new Point(400, 200);
    shell.setSize(size);

    Point l = getParent().getLocation();
    Point s = getParent().getSize();

    shell.setLocation(l.x + (s.x - size.x) / 2, l.y + (s.y - size.y) / 2);

    shell.setText(getText());
    shell.setImage(PenroseStudio.getImage(PenroseImage.LOGO));

    reset();

    shell.open();

    Display display = getParent().getDisplay();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
  }
示例#18
0
 public static void main(String[] args) {
   final Display display = new Display();
   final Image image = new Image(display, 16, 16);
   GC gc = new GC(image);
   gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
   gc.fillRectangle(image.getBounds());
   gc.dispose();
   final Shell shell = new Shell(display);
   shell.setText("Lazy Table");
   shell.setLayout(new FillLayout());
   final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
   table.setSize(200, 200);
   Thread thread =
       new Thread() {
         @Override
         public void run() {
           for (int i = 0; i < 20000; i++) {
             if (table.isDisposed()) return;
             final int[] index = new int[] {i};
             display.syncExec(
                 () -> {
                   if (table.isDisposed()) return;
                   TableItem item = new TableItem(table, SWT.NONE);
                   item.setText("Table Item " + index[0]);
                   item.setImage(image);
                 });
           }
         }
       };
   thread.start();
   shell.setSize(200, 200);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   image.dispose();
   display.dispose();
 }
示例#19
0
 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();
 }
示例#21
0
  /**
   * Constructor to create an editor to update/create an ontology entry
   *
   * @param display - points back to the display
   * @param oureditOntEntry - the entry being edited
   * @param ontParent - the edited item's parent in the hierarchy
   * @param newItem - true if this is a new item
   */
  public EditOntEntry(
      Display display, OntEntry oureditOntEntry, OntEntry ontParent, boolean newItem) {
    super();
    shell = new Shell(display, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL);
    shell.setText("OntEntry Information");
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.marginHeight = 5;
    gridLayout.makeColumnsEqualWidth = true;
    shell.setLayout(gridLayout);

    ourOntEntry = oureditOntEntry;
    ourParent = ontParent;

    if (newItem) {
      ourOntEntry.setName("");
      ourOntEntry.setImportance(Importance.MODERATE);
    }

    new Label(shell, SWT.NONE).setText("Name:");

    nameField = new Text(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL);
    nameField.setText(ourOntEntry.getName());
    GridData gridData =
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    DisplayUtilities.setTextDimensions(nameField, gridData, 75);
    gridData.horizontalSpan = 2;
    nameField.setLayoutData(gridData);

    new Label(shell, SWT.NONE).setText("Description:");

    descArea = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
    descArea.setText(ourOntEntry.getDescription());
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    DisplayUtilities.setTextDimensions(descArea, gridData, 75, 5);
    gridData.horizontalSpan = 2;
    gridData.heightHint = descArea.getLineHeight() * 3;
    descArea.setLayoutData(gridData);

    new Label(shell, SWT.NONE).setText("Importance:");
    importanceBox = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    Enumeration impEnum = Importance.elements();
    int l = 0;
    Importance itype;
    while (impEnum.hasMoreElements()) {
      itype = (Importance) impEnum.nextElement();
      importanceBox.add(itype.toString());
      if (itype.toString().compareTo(ourOntEntry.getImportance().toString()) == 0) {
        importanceBox.select(l);
      }
      l++;
    }
    // Error checking: if no such selection is valid, set it to select index 0
    if (importanceBox.getSelectionIndex() == -1) {
      importanceBox.select(0);
    }
    importanceBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    new Label(shell, SWT.NONE).setText(" ");
    new Label(shell, SWT.NONE).setText(" ");

    addButton = new Button(shell, SWT.PUSH);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    addButton.setLayoutData(gridData);
    if (newItem) {
      addButton.setText("Add");
      addButton.addSelectionListener(
          new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
              canceled = false;
              if (!nameField.getText().trim().equals("")) {
                ConsistencyChecker checker =
                    new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries");

                if (ourOntEntry.getName() == nameField.getText() || checker.check()) {
                  ourParent.addChild(ourOntEntry);
                  ourOntEntry.setLevel(ourParent.getLevel() + 1);
                  ourOntEntry.setName(nameField.getText());
                  ourOntEntry.setDescription(descArea.getText());
                  ourOntEntry.setImportance(
                      Importance.fromString(
                          importanceBox.getItem(importanceBox.getSelectionIndex())));

                  // comment before this made no sense...
                  ourOntEntry.setID(ourOntEntry.toDatabase(ourParent.getID()));
                  System.out.println("Name of added item = " + ourOntEntry.getName());

                  shell.close();
                  shell.dispose();
                }
              } else {
                MessageBox mbox = new MessageBox(shell, SWT.ICON_ERROR);
                mbox.setMessage("Need to provide the OntEntry name");
                mbox.open();
              }
            }
          });

    } else {
      addButton.setText("Save");
      addButton.addSelectionListener(
          new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
              canceled = false;

              ConsistencyChecker checker =
                  new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries");

              if (ourOntEntry.getName() == nameField.getText() || checker.check()) {
                ourOntEntry.setName(nameField.getText());
                ourOntEntry.setDescription(descArea.getText());
                ourOntEntry.setImportance(
                    Importance.fromString(
                        importanceBox.getItem(importanceBox.getSelectionIndex())));
                // since this is a save, not an add, the type and parent are ignored
                ourOntEntry.setID(ourOntEntry.toDatabase(0));

                //			RationaleDB db = RationaleDB.getHandle();
                //			db.addOntEntry(ourOntEntry);

                shell.close();
                shell.dispose();
              }
            }
          });
    }

    cancelButton = new Button(shell, SWT.PUSH);
    cancelButton.setText("Cancel");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    cancelButton.setLayoutData(gridData);
    cancelButton.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent event) {
            canceled = true;
            shell.close();
            shell.dispose();
          }
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
  }
示例#22
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();
  }
 /** {@inheritDoc} */
 protected void configureShell(Shell newShell) {
   super.configureShell(newShell);
   // Set title.
   newShell.setText("User Roles");
 }
示例#24
0
  public Shell open(Display display) {
    clipboard = new Clipboard(display);
    shell = new Shell(display);
    shell.setText("SWT Clipboard");
    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);
    parent.setLayout(new GridLayout(2, true));

    Group copyGroup = new Group(parent, SWT.NONE);
    copyGroup.setText("Copy From:");
    GridData data = new GridData(GridData.FILL_BOTH);
    copyGroup.setLayoutData(data);
    copyGroup.setLayout(new GridLayout(3, false));

    Group pasteGroup = new Group(parent, SWT.NONE);
    pasteGroup.setText("Paste To:");
    data = new GridData(GridData.FILL_BOTH);
    pasteGroup.setLayoutData(data);
    pasteGroup.setLayout(new GridLayout(3, false));

    Group controlGroup = new Group(parent, SWT.NONE);
    controlGroup.setText("Control API:");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    controlGroup.setLayoutData(data);
    controlGroup.setLayout(new GridLayout(5, false));

    Group typesGroup = new Group(parent, SWT.NONE);
    typesGroup.setText("Available Types");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    typesGroup.setLayoutData(data);
    typesGroup.setLayout(new GridLayout(2, false));

    status = new Label(parent, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = 60;
    status.setLayoutData(data);

    createTextTransfer(copyGroup, pasteGroup);
    createRTFTransfer(copyGroup, pasteGroup);
    createHTMLTransfer(copyGroup, pasteGroup);
    createFileTransfer(copyGroup, pasteGroup);
    createMyTransfer(copyGroup, pasteGroup);
    createControlTransfer(controlGroup);
    createAvailableTypes(typesGroup);

    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(
        Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();
    return shell;
  }
  public static void main(String[] args) {
    Shell shell = new Shell();
    Display display = shell.getDisplay();
    shell.setLayout(new FillLayout());
    shell.setText("ExpandBar Example");

    Menu menubar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(menubar);
    MenuItem fileItem = new MenuItem(menubar, SWT.CASCADE);
    fileItem.setText("&File");
    Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(submenu);
    item = new MenuItem(submenu, SWT.PUSH);
    item.setText("New ExpandItem");

    bar = new ExpandBar(shell, SWT.V_SCROLL);
    image = display.getSystemImage(SWT.ICON_QUESTION);

    // First item
    Composite composite = new Composite(bar, SWT.NONE);
    Menu popupmenu = new Menu(shell, SWT.POP_UP);
    MenuItem popupItem = new MenuItem(popupmenu, SWT.PUSH);
    popupItem.setText("Popup");
    composite.setMenu(popupmenu);

    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
    layout.verticalSpacing = 10;
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_ERROR));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_ERROR");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_INFORMATION");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_WARNING));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_WARNING");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_QUESTION");
    ExpandItem item1 = new ExpandItem(bar, SWT.NONE);
    item1.setText("What is your favorite icon");
    item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    item1.setControl(composite);
    item1.setImage(image);

    // Second item
    composite = new Composite(bar, SWT.NONE);
    layout = new GridLayout(2, true);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
    layout.verticalSpacing = 10;
    composite.setLayout(layout);
    Button button1 = new Button(composite, SWT.PUSH);
    button1.setText("Button 1");
    Button button2 = new Button(composite, SWT.PUSH);
    button2.setText("Button 2");

    ExpandItem item0 = new ExpandItem(bar, SWT.NONE);
    item0.setText("What is your favorite button");
    item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    item0.setControl(composite);
    item0.setImage(image);
    item0.setExpanded(false);

    item.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            ExpandItem item2 = new ExpandItem(bar, SWT.NONE);
            Composite composite = new Composite(bar, SWT.NONE);
            GridLayout layout = new GridLayout(2, false);
            composite.setLayout(layout);
            Label label = new Label(composite, SWT.NONE);
            label.setText("What is your name?");
            Composite pcomposite = new Composite(composite, SWT.NONE);
            Text text = new Text(pcomposite, SWT.NONE);
            item2.setText("New Question");
            text.pack();
            composite.pack();
            Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            item2.setHeight(size.y);
            item2.setControl(composite);
            item2.setImage(image);
            item2.setExpanded(true);
          }
        });

    bar.setSpacing(8);
    shell.setSize(400, 550);
    shell.open();
    System.out.println("------------------------------");
    System.out.println("getSize: " + button1.getSize());
    System.out.println("getBounds: " + button1.getBounds());
    System.out.println("computeSize: " + button1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    System.out.println("getLocation: " + button1.getLocation());

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    image.dispose();
    display.dispose();
  }
  private void openAddressBook(String name) {
    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resMessages.getString("File")
              + file.getName()
              + " "
              + resMessages.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resMessages.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resMessages.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);
      waitCursor.dispose();

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resMessages.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    for (int i = 0; i < data.length; i++) {
      tableInfo[i] = decodeLine(data[i]);
    }

    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resMessages.getString("Title_bar") + file.getName());
    isModified = false;
    this.file = file;
  }
示例#27
0
 @Override
 protected void configureShell(Shell newShell) {
   super.configureShell(newShell);
   newShell.setText(CoreMessages.dialog_about_title);
 }
示例#28
0
 private void newAddressBook() {
   shell.setText(resAddressBook.getString("Title_bar") + resAddressBook.getString("New_title"));
   file = null;
   isModified = false;
 }
示例#29
0
  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    try {
      GLContext.useContext(canvas);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    canvas.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
              GLContext.useContext(canvas);
            } catch (LWJGLException e) {
              e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
          }
        });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    shell.setText("SWT/LWJGL Example");
    shell.setSize(640, 480);
    shell.open();

    display.asyncExec(
        new Runnable() {
          int rot = 0;

          public void run() {
            if (!canvas.isDisposed()) {
              canvas.setCurrent();
              try {
                GLContext.useContext(canvas);
              } catch (LWJGLException e) {
                e.printStackTrace();
              }
              GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
              GL11.glClearColor(.3f, .5f, .8f, 1.0f);
              GL11.glLoadIdentity();
              GL11.glTranslatef(0.0f, 0.0f, -10.0f);
              float frot = rot;
              GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
              GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
              rot++;
              GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
              GL11.glColor3f(0.9f, 0.9f, 0.9f);
              drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
              canvas.swapBuffers();
              display.asyncExec(this);
            }
          }
        });

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
示例#30
0
  private void openAddressBook() {
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);

    fileDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"});
    fileDialog.setFilterNames(
        new String[] {
          resAddressBook.getString("Book_filter_name") + " (*.adr)",
          resAddressBook.getString("All_filter_name") + " (*.*)"
        });
    String name = fileDialog.open();

    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resAddressBook.getString("File")
              + file.getName()
              + " "
              + resAddressBook.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resAddressBook.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resAddressBook.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    int writeIndex = 0;
    for (int i = 0; i < data.length; i++) {
      String[] line = decodeLine(data[i]);
      if (line != null) tableInfo[writeIndex++] = line;
    }
    if (writeIndex != data.length) {
      String[][] result = new String[writeIndex][table.getColumnCount()];
      System.arraycopy(tableInfo, 0, result, 0, writeIndex);
      tableInfo = result;
    }
    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resAddressBook.getString("Title_bar") + fileDialog.getFileName());
    isModified = false;
    this.file = file;
  }