Esempio n. 1
0
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(new RowLayout());
   Text text = new Text(shell, SWT.MULTI | SWT.BORDER);
   String modifier = SWT.MOD1 == SWT.CTRL ? "Ctrl" : "Command";
   text.setText("Hit " + modifier + "+Return\nto see\nthe default button\nrun");
   text.addTraverseListener(
       e -> {
         switch (e.detail) {
           case SWT.TRAVERSE_RETURN:
             if ((e.stateMask & SWT.MOD1) != 0) e.doit = true;
         }
       });
   Button button = new Button(shell, SWT.PUSH);
   button.pack();
   button.setText("OK");
   button.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           System.out.println("OK selected");
         }
       });
   shell.setDefaultButton(button);
   shell.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
Esempio n. 2
0
  /**
   * Creates the input score text.
   *
   * @param main the main
   * @param player the player
   */
  private void createInputScoreText(Composite main, IPlayer player) {
    Text inputScoreText = this.toolkit.createText(main, "", SWT.CENTER | SWT.BORDER);
    inputScoreText.setFont(OpenDartsFormsToolkit.getFont(OpenDartsFormsToolkit.FONT_SCORE_INPUT));
    inputScoreText.setEnabled(false);
    this.playerScoreInput.put(player, inputScoreText);

    // Tooltip
    ShortcutsTooltip tooltip = new ShortcutsTooltip(inputScoreText);
    tooltip.setPopupDelay(200);

    // layout
    int indent = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth() + 2;
    GridDataFactory.fillDefaults()
        .grab(true, false)
        .indent(indent, SWT.DEFAULT)
        .hint(SWT.DEFAULT, 100)
        .applyTo(inputScoreText);

    // decoration
    ControlDecoration dec = new ControlDecoration(inputScoreText, SWT.TOP | SWT.LEFT);

    // listener
    TextInputListener listener =
        new TextInputListener(this.getSite().getShell(), inputScoreText, this.game, player, dec);
    inputScoreText.addKeyListener(listener);

    inputScoreText.addTraverseListener(new CancelTraverseListener());
  }
Esempio n. 3
0
  private void constructTextWidgets() {
    if (txfValue == null) {
      txfValue = new Text(pnlText, SWT.BORDER);
      txfValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

      txfValue.addModifyListener(
          new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent theEvent) {
              handleTextChange();
            }
          });

      txfValue.addVerifyListener(
          new VerifyListener() {
            @Override
            public void verifyText(VerifyEvent theEvent) {
              String text = theEvent.text;

              if ((text != null) && (text.length() > 0)) {
                for (int size = text.length(), i = 0; i < size; i++) {
                  if ((validChars != null) && (validChars.indexOf(text.charAt(i)) == -1)) {
                    theEvent.doit = false;
                    break;
                  } else if (!model.isValidValue(text)) {
                    theEvent.doit = false;
                    break;
                  }
                }
              }
            }
          });

      txfValue.addTraverseListener(
          new TraverseListener() {
            @Override
            public void keyTraversed(TraverseEvent theEvent) {
              // stops the enter key from putting in invisible characters
              if (theEvent.detail == SWT.TRAVERSE_RETURN) {
                theEvent.detail = SWT.TRAVERSE_NONE;
                theEvent.doit = true;
              }
            }
          });

      pnlText.pack();
    }
  }
Esempio n. 4
0
  public void createPartControl(Composite parent) {
    final Font monospaceFont =
        new Font(parent.getDisplay(), new FontData("Monospace", 12, SWT.NONE));
    final Color greenColor = parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN);
    final Color redColor = parent.getDisplay().getSystemColor(SWT.COLOR_DARK_RED);
    final Color blackColor = parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
    final Color greyColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);

    FillLayout fillLayout = (FillLayout) parent.getLayout();
    fillLayout.type = SWT.VERTICAL;

    Composite terminalComposite = new Composite(parent, SWT.NONE);
    terminalComposite.setLayout(new FormLayout());
    terminalComposite.setBackground(blackColor);

    TabFolder terminalPane = new TabFolder(terminalComposite, SWT.BOTTOM);
    terminalPane.setBackground(blackColor);
    FormData terminalLayoutData = new FormData();
    terminalLayoutData.top = new FormAttachment(0);
    terminalLayoutData.left = new FormAttachment(0);
    terminalLayoutData.right = new FormAttachment(100);
    terminalPane.setLayoutData(terminalLayoutData);

    TabItem outTabItem = new TabItem(terminalPane, SWT.NONE);
    outTabItem.setText("out");
    //    terminalDataLayer = new DataLayer(currentlySelectedExecutionRecordDataProvider);

    SelectionLayer selectionLayer = new SelectionLayer(terminalDataLayer);
    ViewportLayer viewPortLayer = new ViewportLayer(selectionLayer);
    viewPortLayer.setRegionName(GridRegion.BODY);
    ColumnHeaderLayer columnHeaderLayer =
        new ColumnHeaderLayer(new DataLayer(columnDataProvider), viewPortLayer, selectionLayer);
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, viewPortLayer, 0, 1);
    compositeLayer.setConfigLabelAccumulatorForRegion(GridRegion.BODY, configLabelAccumulator);
    terminalGrid = new NatTable(terminalPane, compositeLayer);
    terminalGrid.setTheme(new EarlGridTheme());
    terminalGrid.setBackground(blackColor);
    outTabItem.setControl(terminalGrid);

    TabItem errTabItem = new TabItem(terminalPane, SWT.NONE);
    errTabItem.setText("err");
    tabularErrorTable = new Table(terminalPane, SWT.VIRTUAL | SWT.HIDE_SELECTION);
    tabularErrorTable.setHeaderVisible(false);
    tabularErrorTable.setLinesVisible(true);
    //    tabularErrorTable.addListener(SWT.SetData, tabularErrorDataHandler);
    tabularErrorTable.setFont(monospaceFont);
    tabularErrorTable.setBackground(redColor);
    tabularErrorTable.setForeground(greyColor);
    errTabItem.setControl(tabularErrorTable);

    TabItem logTabItem = new TabItem(terminalPane, SWT.NONE);
    logTabItem.setText("log");
    tabularLogTable = new Table(terminalPane, SWT.VIRTUAL | SWT.HIDE_SELECTION);
    tabularLogTable.setHeaderVisible(false);
    tabularLogTable.setLinesVisible(true);
    //    tabularLogTable.addListener(SWT.SetData, tabularErrorDataHandler);
    tabularLogTable.setFont(monospaceFont);
    tabularLogTable.setBackground(greenColor);
    tabularLogTable.setForeground(greyColor);
    logTabItem.setControl(tabularLogTable);

    terminalPane.setSelection(0);

    commandLineTxt = new Text(terminalComposite, SWT.BORDER);
    FormData commandLineTxtLayoutData = new FormData();
    commandLineTxtLayoutData.left = new FormAttachment(terminalPane, 0, SWT.LEFT);
    commandLineTxtLayoutData.right = new FormAttachment(terminalPane, 0, SWT.RIGHT);
    commandLineTxtLayoutData.bottom = new FormAttachment(100);
    commandLineTxt.setLayoutData(commandLineTxtLayoutData);
    commandLineTxt.addFocusListener(commandLineFocusListener);
    commandLineTxt.addKeyListener(commandLineKeyListener);
    commandLineTxt.setFont(monospaceFont);
    commandLineTxt.setBackground(blackColor);
    commandLineTxt.setForeground(greyColor);
    commandLineTxt.addTraverseListener(preventTraversal);
    terminalLayoutData.bottom = new FormAttachment(commandLineTxt);

    monospaceFont.dispose();
  }
 public void addTraverseListener(TraverseListener tl) {
   wText.addTraverseListener(tl);
 }
Esempio n. 6
0
  private Control createText(Composite parent) {
    text = new Text(parent, textStyle);
    text.setTextLimit(7);
    text.addFocusListener(
        new FocusListener() {
          public void focusLost(FocusEvent e) {
            Display.getCurrent()
                .asyncExec(
                    new Runnable() {
                      public void run() {
                        if (text == null || text.isDisposed()) return;

                        if (isAncestorShell(text.getShell(), Display.getCurrent().getActiveShell()))
                          return;
                        textEditingFinished();
                      }
                    });
          }

          public void focusGained(FocusEvent e) {}
        });
    text.addTraverseListener(
        new TraverseListener() {
          public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
              fireCancelEditing();
              e.doit = false;
            } else if (e.detail == SWT.TRAVERSE_RETURN) {
              textEditingFinished();
              e.doit = false;
            }
          }
        });
    text.addVerifyListener(
        new VerifyListener() {
          public void verifyText(VerifyEvent e) {
            if (e.keyCode == 27 && e.stateMask == 0) {
              fireCancelEditing();
              e.doit = false;
            } else if (e.keyCode == 13) {
              textEditingFinished();
              e.doit = false;
            } else {
              if (COLOR_NONE_VALUE.equals(e.text)) {
                return;
              }
              char[] charArray = e.text.toCharArray();
              for (char character : charArray) {
                boolean isValid =
                    character == '#'
                        || (character >= 'A' && character <= 'F')
                        || (character >= 'a' && character <= 'f')
                        || (character >= '0' && character <= '9');
                if (!isValid) {
                  e.doit = false;
                  return;
                }
              }
            }
          }
        });
    text.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            if (modifying) return;
            String value = text.getText();
            if ((value == null || value.lastIndexOf('#') != 0) && !COLOR_NONE_VALUE.equals(value)) {
              value = ""; // $NON-NLS-1$
            }
            changeValue("".equals(value) ? null : value); // $NON-NLS-1$
          }
        });
    text.addKeyListener(
        new KeyListener() {
          public void keyReleased(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {
            if (e.character == '\r') {
              textEditingFinished();
              e.doit = false;
            }
          }
        });
    return text;
  }
Esempio n. 7
0
  /**
   * Create the filter text and adds listeners.
   *
   * @param parent <code>Composite</code> of the filter text
   */
  protected void createFilterText(Composite parent) {
    GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    gd.horizontalIndent = 15;
    filterText = createFilterTextControl(parent, SWT.SINGLE | SWT.BORDER, gd);
    filterText
        .getAccessible()
        .addAccessibleListener(
            new AccessibleAdapter() {
              /* (non-Javadoc)
               * @see org.eclipse.swt.accessibility.AccessibleListener#getName(org.eclipse.swt.accessibility.AccessibleEvent)
               */
              public void getName(AccessibleEvent e) {
                String filterTextString = filterText.getText();
                if (filterTextString.length() == 0) {
                  e.result = initialText;
                } else {
                  e.result = filterTextString;
                }
              }
            });

    filterText.addFocusListener(
        new FocusAdapter() {
          /* (non-Javadoc)
           * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
           */
          public void focusGained(FocusEvent e) {
            /* Running in an asyncExec because the selectAll() does not
             * appear to work when using mouse to give focus to text.
             */
            Display display = filterText.getDisplay();
            display.asyncExec(
                new Runnable() {
                  public void run() {
                    if (!filterText.isDisposed()) {
                      if (getInitialText().equals(filterText.getText().trim())) {
                        filterText.selectAll();
                      }
                    }
                  }
                });
          }
        });

    filterText.addKeyListener(
        new KeyAdapter() {
          /*
           * (non-Javadoc)
           *
           * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
           */
          public void keyPressed(KeyEvent e) {
            // on a CR we want to transfer focus to the list
            boolean hasItems = getViewer().getTable().getItemCount() > 0;
            if (hasItems && e.keyCode == SWT.ARROW_DOWN) {
              tableViewer.getTable().setFocus();
            } else if (e.character == SWT.CR) {
              return;
            }
          }
        });

    // enter key set focus to tree
    filterText.addTraverseListener(
        new TraverseListener() {
          public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
              e.doit = false;
              if (getViewer().getTable().getItemCount() == 0) {
                Display.getCurrent().beep();
              } else {
                // if the initial filter text hasn't changed, do not try to match
                boolean hasFocus = getViewer().getTable().setFocus();
                boolean textChanged = !getInitialText().equals(filterText.getText().trim());
                if (hasFocus && textChanged && filterText.getText().trim().length() > 0) {
                  TableItem item = getFirstMatchingItem(getViewer().getTable().getItems());
                  if (item != null) {
                    getViewer().getTable().setSelection(new TableItem[] {item});
                    ISelection sel = getViewer().getSelection();
                    getViewer().setSelection(sel, true);
                  }
                }
              }
            }
          }
        });

    filterText.addModifyListener(
        new ModifyListener() {
          /* (non-Javadoc)
           * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
           */
          public void modifyText(ModifyEvent e) {
            textChanged();
          }
        });
  }