예제 #1
0
  public WebInterfaceDialog(@NotNull Shell parentShell) {
    shell = new Shell(parentShell, SWT.PRIMARY_MODAL | SWT.DIALOG_TRIM);
    shell.setLayout(Util.createFormLayout(5));
    shell.setText(Msg.web_interface.get());

    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new RowLayout());

    Button enableButton = new Button(comp, SWT.CHECK);
    enableButton.setText(Msg.enable_web_interface.get());

    enableButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            /*
             * TODO web interface: start or stop web interface
             * TODO web interface: also stop web interface automatically when the program exits (in Main class)
             * TODO web interface: remove comment in ProgramConf.Int.WebInterfacePageSize.
             */
          }
        });

    Button closeButton = new Button(shell, SWT.PUSH);
    closeButton.setText(Msg.close.get());
    closeButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            shell.close();
          }
        });

    FormDataFactory fdf = FormDataFactory.getInstance();
    fdf.bottom().right().minWidth(Util.BTW).applyTo(closeButton);
    fdf.reset().bottom(closeButton).left().top().right().applyTo(comp);
  }
예제 #2
0
  /**
   * Creates an input dialog instance. The dialog remains invisible until {@link #open()} is called.
   *
   * @param parent The parent shell.
   * @param title The window title for this input dialog.
   * @param msg The message to display on this input dialog.
   * @param defaultValue The default value for the input field.
   */
  public InputDialog(Shell parent, String title, String msg, String defaultValue) {
    shell = new Shell(parent, SWT.PRIMARY_MODAL | SWT.DIALOG_TRIM | SWT.RESIZE);
    shell.setText(title);

    Label label = new Label(shell, SWT.NONE);
    text = new Combo(shell, SWT.BORDER | SWT.SINGLE);
    Util.selectAllOnFocus(text);
    Label fillerLabel = new Label(shell, SWT.NONE);
    Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    Button okBt = new Button(shell, SWT.PUSH);
    Button cancelBt = new Button(shell, SWT.PUSH);

    label.setText(msg);
    text.setText(defaultValue);
    text.setSelection(new Point(0, text.getText().length()));
    okBt.setText(AppUtil.Messages.ok.get());
    cancelBt.setText(AppUtil.Messages.cancel.get());
    Button[] okCancelBts = Util.maybeSwapButtons(okBt, cancelBt);

    shell.setLayout(Util.createFormLayout(5));
    FormDataFactory fdf = FormDataFactory.getInstance();
    fdf.top().left().right().applyTo(label);
    fdf.top(label).applyTo(text);
    fdf.reset().minWidth(Util.BTW).bottom().right().applyTo(okCancelBts[1]);
    fdf.right(okCancelBts[1]).applyTo(okCancelBts[0]);
    fdf.reset().left().right().bottom(okCancelBts[1]).applyTo(separator);
    fdf.top(text).bottom(separator).applyTo(fillerLabel);

    okBt.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            answer = text.getText();
            shell.close();
          }
        });

    cancelBt.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            shell.close();
          }
        });

    text.addKeyListener(
        new KeyAdapter() {
          public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
              answer = text.getText();
              shell.close();
            }
          }
        });
  }