Example #1
0
  /**
   * creates the style range of the StyledText for the range of the contained editor
   *
   * <p>XXX problem will occur if there is a newline in the position. Working on this! code folding.
   */
  private StyleRange[] createStyleRange(ContainedEditorManager c, Position p) {
    int offset = p.offset;
    int length = p.length;

    Rectangle rect = c.getControl().getBounds();
    int ascent = rect.height - 4;
    int descent = 4;

    // use two style ranges

    // first style range covers the entire size of the contained editor
    StyleRange first = new StyleRange();
    first.start = offset;
    first.length = Math.min(1, length);
    first.background = this.containingEditor.colorManager.getColor(new RGB(255, 255, 255));
    first.metrics =
        new GlyphMetrics(
            ascent + ContainingEditor.MARGIN,
            descent + ContainingEditor.MARGIN,
            rect.width + 2 * ContainingEditor.MARGIN);

    // this style range is hidden.  the height and width are 0
    StyleRange second = new StyleRange();
    second.start = offset + 1;
    second.length = length - 1;
    second.background = this.containingEditor.colorManager.getColor(new RGB(255, 255, 255));
    second.metrics = new GlyphMetrics(0, 0, 0);
    second.font = TINY_FONT;

    return new StyleRange[] {first, second};
  }
Example #2
0
  /**
   * Create the composite.
   *
   * @param parent
   * @param style
   */
  public FeatureOffset(Composite parent, int style) {
    super(parent, style);
    setLayout(new GridLayout(3, true));

    stylerange = new StyleRange();
    stylerange.background = AndrospyMain.shell.getDisplay().getSystemColor(SWT.COLOR_YELLOW);

    txtSrch = new Text(this, SWT.BORDER);
    txtSrch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    Button btnSearch = new Button(this, SWT.NONE);
    btnSearch.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            String srch = txtSrch.getText();
            String fulltext = text.getText();
            if (srch != "" && fulltext != "") {
              find(srch, fulltext);
            }
          }
        });
    GridData gd_btnSearch = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_btnSearch.widthHint = 104;
    btnSearch.setLayoutData(gd_btnSearch);
    btnSearch.setText("lk.score.androphsy.main.Search");

    text = new StyledText(this, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    GridData gd_text = new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1);
    gd_text.heightHint = 230;
    text.setLayoutData(gd_text);

    lblOffset = new Label(this, SWT.NONE);
    lblOffset.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblOffset.setText("Offset:");

    txtOffset = new Text(this, SWT.BORDER);
    txtOffset.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    btnHexView = new Button(this, SWT.NONE);
    btnHexView.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            if (txtOffset.getText().equals("")) {
              MessageBox msbox = new MessageBox(getShell(), SWT.ICON_ERROR);
              msbox.setMessage("ERROR - Hex View");
              msbox.setText("Offset value cannot be null");
              msbox.open();
              return;
            }
            hv.getHexdump(txtOffset.getText());
          }
        });
    btnHexView.setText("Hex View");

    hv = new HexViewer(this, SWT.NONE);
    hv.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
  }
  private void drawCurrentLine(LineBackgroundEvent event, final IRegion lineRegion) {
    final StyledText textWidget = fViewer.getTextWidget();
    final int offset = event.lineOffset;
    final RGBa lineHighlight = getCurrentTheme().getLineHighlight();
    event.lineBackground = getColorManager().getColor(lineHighlight.toRGB());

    // In this case, we should be overriding the bg of the style ranges for the line too!
    if (textWidget.isDisposed()) {
      return;
    }
    // FIXME Only change bg colors of visible ranges!
    int replaceLength = 160;
    if (lineRegion != null) {
      replaceLength = Math.min(replaceLength, lineRegion.getLength());
    }

    // be safe about offsets
    int charCount = textWidget.getCharCount();
    if (offset + replaceLength > charCount) {
      replaceLength = charCount - offset;
      if (replaceLength < 0) {
        // Just playing safe here
        replaceLength = 0;
      }
    }
    final StyleRange[] ranges = textWidget.getStyleRanges(offset, replaceLength, true);
    if (ranges == null || ranges.length == 0) {
      return;
    }
    Color background = textWidget.getBackground();
    final int[] positions = new int[ranges.length << 1];
    int x = 0;
    boolean apply = false;
    for (StyleRange range : ranges) {
      if (range.background != null) {
        if (!range.background.equals(background)) {
          positions[x] = range.start;
          positions[x + 1] = range.length;
          x += 2;
          continue;
        }
        apply = true;
      }
      range.background = null;
      positions[x] = range.start;
      positions[x + 1] = range.length;
      x += 2;
    }

    if (apply) {
      textWidget.setStyleRanges(offset, replaceLength, positions, ranges);
    }
  }
Example #4
0
 private void removeHighlightingCategory(
     org.eclipse.jface.text.IDocument document, String category) {
   org.eclipse.jface.text.Position[] positions = positionHelper.getPositions(document, category);
   if (category.equals(
       bento.language.bentocomp.resource.bento.ui.BentoPositionCategory.BRACKET.toString())) {
     org.eclipse.swt.custom.StyleRange styleRange;
     for (org.eclipse.jface.text.Position position : positions) {
       org.eclipse.jface.text.Position tmpPosition = convertToWidgetPosition(position);
       if (tmpPosition != null) {
         styleRange = getStyleRangeAtPosition(tmpPosition);
         styleRange.borderStyle = org.eclipse.swt.SWT.NONE;
         styleRange.borderColor = null;
         styleRange.background = null;
         textWidget.setStyleRange(styleRange);
       }
     }
   }
   positionHelper.removePositions(document, category);
 }