Examples of StyledText


Examples of org.eclipse.swt.custom.StyledText

    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

Examples of org.eclipse.swt.custom.StyledText

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

Examples of org.eclipse.swt.custom.StyledText

  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

Examples of org.eclipse.swt.custom.StyledText

     
      String errorMessage = e.getMessage();
     
      try{
 
        StyledText canvas = wText.getStyledText();
       
        // try to parse the error message
        Matcher m = pErrorMessage.matcher(errorMessage)
       
        if (m.find()){
          String errorSummary = "Error: "+m.group(1).trim();
          canvas.setData("lastErrorMessage",errorSummary);
          wlSyntaxCheck.setText(errorSummary);
          wlSyntaxCheck.setToolTipText(wlSyntaxCheck.getText());
        }
       
        // try to parse the error line
        m = pErrorLine.matcher(errorMessage)
 
        int errorLine = 0;
        int errorCol = 0;
        if (m.find()){
          errorLine = Integer.valueOf(m.group(1))-1;
          canvas.setData("lastErrorLine", errorLine);
          canvas.setLineBackground(errorLine, 1, errorLineColor);
        }
       
        // try to parse the actual error char
        m = pErrorChar.matcher(errorMessage);
       
        if (m.find()){
          errorCol = m.group(1).length();
          canvas.setSelection(canvas.getOffsetAtLine(errorLine)+errorCol);
        }
       
      }
      catch(Exception ex){
        //ex.printStackTrace();
View Full Code Here

Examples of org.kite9.diagram.primitives.StyledText

  public Key(String boldText, String bodyText, List<Symbol> symbols) {
    this(convert(symbols), boldText, bodyText);
  }

  public Key(List<TextLine> symbols, String boldText, String bodyText) {
    this.boldText = new StyledText(boldText);
    this.bodyText = new StyledText(bodyText);
    this.symbols = symbols;
    for (TextLine textLine : symbols) {
      textLine.setParent(this);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.