Package org.eclipse.swt.custom

Examples of org.eclipse.swt.custom.StyledText


        Label lblRequirement = new Label(contents, SWT.NONE);
        lblRequirement.setText("Requirement Info");
        lblRequirement.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));

        StyledText txtRequirement = new StyledText(contents, SWT.WRAP | SWT.BORDER);
        txtRequirement.setEditable(false);
        txtRequirement.setCaret(null);
        //        txtRequirement.setBackground(contents.getBackground());
        txtRequirement.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));

        @SuppressWarnings("unused")
        Label lblSpacer = new Label(contents, SWT.NONE);

        Label lblCandidates = new Label(contents, SWT.NONE);
        lblCandidates.setText("Candidates");
        lblCandidates.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));

        Composite lowerPanel = new Composite(contents, SWT.NONE);
        Table tbl = new Table(lowerPanel, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);

        viewer = new CheckboxTableViewer(tbl);
        viewer.setContentProvider(ArrayContentProvider.getInstance());
        viewer.setLabelProvider(new CapabilityResourceLabelProvider());

        btnUp = new Button(lowerPanel, SWT.PUSH);
        btnUp.setText("Move Up");
        btnUp.setEnabled(false);

        btnDown = new Button(lowerPanel, SWT.PUSH);
        btnDown.setText("Move Down");
        btnDown.setEnabled(false);

        Composite cmpPreferences = new Composite(contents, SWT.NONE);
        btnSavePreference = new Button(cmpPreferences, SWT.CHECK | SWT.WRAP);
        txtSavePreference = new StyledText(cmpPreferences, SWT.WRAP);
        txtSavePreference.setEditable(false);
        txtSavePreference.setCaret(null);
        txtSavePreference.setBackground(contents.getBackground());
        txtSavePreference.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));

        // Events
        txtSavePreference.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                btnSavePreference.setSelection(!btnSavePreference.getSelection());
            }
        });

        // Load data
        StyledString label = createRequirementText();
        txtRequirement.setText(label.getString());
        txtRequirement.setStyleRanges(label.getStyleRanges());

        viewer.setInput(candidates);

        updateSavePreferenceText();

        // Layout
        GridLayout layout;
        GridData gd;

        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        contents.setLayoutData(gd);
        layout = new GridLayout(1, false);
        contents.setLayout(layout);

        gd = new GridData(SWT.FILL, SWT.NONE, true, false);
        gd.horizontalIndent = 5;
        txtRequirement.setLayoutData(gd);
        gd = new GridData(SWT.FILL, SWT.NONE, true, false);

        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        lowerPanel.setLayoutData(gd);
View Full Code Here


        Label lblRequirement = new Label(contents, SWT.NONE);
        lblRequirement.setText("Requirement Info");
        lblRequirement.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));

        StyledText txtRequirement = new StyledText(contents, SWT.WRAP | SWT.BORDER);
        txtRequirement.setEditable(false);
        txtRequirement.setCaret(null);
        //        txtRequirement.setBackground(contents.getBackground());
        txtRequirement.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));

        new Label(contents, SWT.NONE);

        Label lblCandidates = new Label(contents, SWT.NONE);
        lblCandidates.setText("Candidates");
        lblCandidates.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));

        Composite lowerPanel = new Composite(contents, SWT.NONE);
        Table tbl = new Table(lowerPanel, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);

        viewer = new CheckboxTableViewer(tbl);
        viewer.setContentProvider(ArrayContentProvider.getInstance());
        viewer.setLabelProvider(new CapabilityResourceLabelProvider());

        btnUp = new Button(lowerPanel, SWT.PUSH);
        btnUp.setText("Move Up");
        btnUp.setEnabled(false);

        btnDown = new Button(lowerPanel, SWT.PUSH);
        btnDown.setText("Move Down");
        btnDown.setEnabled(false);

        Composite cmpPreferences = new Composite(contents, SWT.NONE);
        btnSavePreference = new Button(cmpPreferences, SWT.CHECK | SWT.WRAP);
        txtSavePreference = new StyledText(cmpPreferences, SWT.WRAP);
        txtSavePreference.setEditable(false);
        txtSavePreference.setCaret(null);
        txtSavePreference.setBackground(contents.getBackground());
        txtSavePreference.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));

        // Events
        txtSavePreference.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                btnSavePreference.setSelection(!btnSavePreference.getSelection());
            }
        });

        // Load data
        StyledString label = createRequirementText();
        txtRequirement.setText(label.getString());
        txtRequirement.setStyleRanges(label.getStyleRanges());

        viewer.setInput(candidates);

        updateSavePreferenceText();

        // Layout
        GridLayout layout;
        GridData gd;

        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        contents.setLayoutData(gd);
        layout = new GridLayout(1, false);
        contents.setLayout(layout);

        gd = new GridData(SWT.FILL, SWT.NONE, true, false);
        gd.horizontalIndent = 5;
        txtRequirement.setLayoutData(gd);
        gd = new GridData(SWT.FILL, SWT.NONE, true, false);

        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        lowerPanel.setLayoutData(gd);
View Full Code Here

    Integer id = getEditorId(editor);
    if (!installedEditors.containsKey(id)) {
      // install key listener for Tab key
      try {
        ITextViewer textViewer = EclipseEmmetHelper.getTextViewer(editor);
        StyledText widget = textViewer.getTextWidget();
        widget.addVerifyKeyListener(getKeyListener(editor));
        installedEditors.put(id, editor);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
View Full Code Here

      return;
   
    Integer id = getEditorId(editor);
    if (installedEditors.containsKey(id)) {
      try {
        StyledText widget = EclipseEmmetHelper.getTextViewer(editor).getTextWidget();
        widget.removeVerifyKeyListener(getKeyListener(editor));
        installedEditors.remove(id);
        keyListeners.remove(id);
      } catch (Exception e) {
        e.printStackTrace();
      }
View Full Code Here

     * @param store
     *            the preference store from which to read colors
     */
  private void initializeViewerColors(ISourceViewer viewer, IPreferenceStore store) {

    StyledText styledText= viewer.getTextWidget();

    // ---------- background color ----------------------
    Color color= store.getBoolean(PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR)
      ? null
      : createColor(store, PreferenceConstants.EDITOR_BACKGROUND_COLOR, styledText.getDisplay());
    styledText.setBackground(color);

    if (fBackgroundColor != null)
      fBackgroundColor.dispose();

    fBackgroundColor= color;
View Full Code Here

        catch (InterruptedException e) { /* normal termination */ }
    }
   
    private boolean isEditorVisible()
    {
        StyledText widget = ((SourceViewer) sourceViewer).getTextWidget();       
        return widget != null && widget.isVisible();
    }
View Full Code Here

        // the problem is, we might be called after the ISourceViewer
        // has been disposed; this occurs BEFORE dispose() is invoked
        // on the PerlEditor, so there seems to be no good way to
        // synchronise properly
        if (sourceViewer == null) return;
        StyledText widget = sourceViewer.getTextWidget();
        if (widget == null || widget.isDisposed()) return;
        Display display = widget.getDisplay();
        if (display == null) return;
        final IDocument doc = sourceViewer.getDocument();
        if (doc == null) return;

        // We reconcile on the main (Display) thread in order to avoid
View Full Code Here

    protected void createNavigationActions()
    {
        super.createNavigationActions();

        IAction action;
        StyledText textWidget = getSourceViewer().getTextWidget();

        action = new SmartLineStartAction(textWidget, false);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
        setAction(ITextEditorActionDefinitionIds.LINE_START, action);

        action = new SmartLineStartAction(textWidget, true);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
        setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);

        action = new NextWordAction(ST.WORD_NEXT, false, false);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT);
        setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action);
        textWidget.setKeyBinding(SWT.MOD1 | SWT.ARROW_RIGHT, SWT.NULL);

        action = new NextWordAction(ST.SELECT_WORD_NEXT, true, false);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT);
        setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action);
        textWidget.setKeyBinding(SWT.MOD1 | SWT.MOD2 | SWT.ARROW_RIGHT, SWT.NULL);

        action = new NextWordAction(ST.DELETE_WORD_NEXT, false, true);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD);
        setAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, action);
        textWidget.setKeyBinding(SWT.MOD1 | SWT.DEL, SWT.NULL);
       
        action = new PreviousWordAction(ST.WORD_PREVIOUS, false, false);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS);
        setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action);
        textWidget.setKeyBinding(SWT.MOD1 | SWT.ARROW_LEFT, SWT.NULL);

        action = new PreviousWordAction(ST.SELECT_WORD_PREVIOUS, true, false);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS);
        setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action);
        textWidget.setKeyBinding(SWT.MOD1 | SWT.MOD2 | SWT.ARROW_LEFT, SWT.NULL);
       
        action = new PreviousWordAction(ST.DELETE_WORD_PREVIOUS, false, true);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD);
        setAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, action);
        textWidget.setKeyBinding(SWT.MOD1 | SWT.BS, SWT.NULL);
       
        // Only unbind default backspace action from textWidget if there is a key binding
        // for "Delete Previous" registered through Preferences > Keys. Otherwise we'd lose
        // backspace functionality:

        IBindingService service = (IBindingService) getSite().getService(IBindingService.class);
        if (service.getActiveBindingsFor(ITextEditorActionDefinitionIds.DELETE_PREVIOUS).length > 0)
        {
            action = new BackspaceAction(ST.DELETE_PREVIOUS);
            action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_PREVIOUS);
            setAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS, action);
            textWidget.setKeyBinding(SWT.BS, SWT.NULL);
        }
    }
View Full Code Here

        }
    }
   
    private void skipChar()
    {
        StyledText text = viewer.getTextWidget();
        text.setCaretOffset(text.getCaretOffset()+1);
    }
View Full Code Here

  public void highlight(String title, StyledTextComp wText) {

    // set up lexer process
    String script = wText.getText();
    StyledText canvas = wText.getStyledText();
    byte[] utf8Script = null;
    int[] encodingBytes = null;

    try {
      utf8Script = script.getBytes("UTF-8");
      encodingBytes = new int[utf8Script.length+1];
      int runner = 0;
      for (int i = 0; i < utf8Script.length; i++) {
        runner += (utf8Script[i] < 0 && -((int)utf8Script[i])+128 > 192)?1:0;
        encodingBytes[i] = runner;
      }
      encodingBytes[encodingBytes.length-1] = runner;
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      return;
    }

    List<String> lines = new ArrayList<String>(canvas.getLineCount());

    LexerSource lexerSource = new ByteArrayLexerSource(title, utf8Script, lines, 0, true);

    lexer.reset();
    lexer.setSource(lexerSource);
    lexer.setState(RubyYaccLexer.LexState.EXPR_BEG);

    // remember bounds of current token
    int leftTokenBorder = 0;
    int rightTokenBorder = 0;
    int t = 0;
    int prevt = 0;
    int lastCommentEnd = 0;

    ArrayList<StyleRange> ranges = new ArrayList<StyleRange>(200);
    ArrayList<Integer> intRanges = new ArrayList<Integer>(400);

    try {
     
      boolean keepParsing = true;
     
      while (keepParsing) {
       
        /* take care of comments, which are stripped out by the lexer */
        int[] upcomingComment = null;
        while ((rightTokenBorder >= lastCommentEnd || rightTokenBorder == 0 ) && (upcomingComment = getUpcomingCommentPos(utf8Script, rightTokenBorder)) != null){
          leftTokenBorder = upcomingComment[0];
          rightTokenBorder = leftTokenBorder + upcomingComment[1];
          lastCommentEnd = rightTokenBorder;
          //System.out.println("Found comment -> [" + leftTokenBorder + "," + rightTokenBorder + "]");
          ranges.add(tokenToStyleRange(TOKEN_COMMENT, null, prevt));

          int left = leftTokenBorder - encodingBytes[leftTokenBorder];
          int right = rightTokenBorder-encodingBytes[rightTokenBorder]- left;
         
          intRanges.add(left);
          intRanges.add(right);
        }
       
        /* read language syntax */
        int oldOffset = lexerSource.getOffset();
        keepParsing = lexer.advance();
        prevt = t;
        t = lexer.token();
        Object v = lexer.value();

        leftTokenBorder = oldOffset;
        if (leftTokenBorder < lastCommentEnd && lexerSource.getOffset() > lastCommentEnd){
          leftTokenBorder = lastCommentEnd;
        }
        rightTokenBorder = lexerSource.getOffset();       
       
        //System.out.println("Found token " + t + " -> " + lexer.value() + " [" + leftTokenBorder + "," + rightTokenBorder + "]");

        // skip whitespace and error formatting
        if (t != '\n' && t != -1){
          ranges.add(tokenToStyleRange(t, v, prevt));
          int left = leftTokenBorder - encodingBytes[leftTokenBorder];
          int right = rightTokenBorder-encodingBytes[rightTokenBorder]- (leftTokenBorder - encodingBytes[leftTokenBorder]);
          intRanges.add(left);
          intRanges.add(right);
        }
     
      }

      // don't mind anything that might go wrong during parsing
    } catch (SyntaxException e) {
      // apply the latest style to the rest of the file in case there is a syntax error
      if (ranges.size() > 0) {
        ranges.remove(ranges.size() - 1);
        intRanges.remove(intRanges.size()-1);
        intRanges.remove(intRanges.size()-1);
      }
      ranges.add(tokenToStyleRange(t, null, prevt));
      int left = leftTokenBorder - encodingBytes[leftTokenBorder];
      intRanges.add(left);
      intRanges.add(wText.getText().length() - left);

    } catch (Exception e) {
      // the lexer will sometimes throw a non-syntax exception when confronted with malformed input
      //e.printStackTrace();
    }
   
    // don't mind swt errors in case some unforseen input brought the style ranges out of order
    try {
      canvas.setStyleRanges(ArrayUtils.toPrimitive(intRanges.toArray(new Integer[0])), ranges.toArray(new StyleRange[0]));
    }
    catch (Exception e){
      //e.printStackTrace();
    }
   
View Full Code Here

TOP

Related Classes of org.eclipse.swt.custom.StyledText

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.