コード例 #1
0
  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);
    }
  }
コード例 #2
0
ファイル: StyledTextUtil.java プロジェクト: DevFactory/ccw
 public static void lightenStyledTextColors(StyledText st, double pct) {
   StyleRange[] srs = st.getStyleRanges();
   Color defaultFGColor = CCWPlugin.getColor(RGBUtil.lighten(st.getForeground().getRGB(), pct));
   for (int i = 0; i < srs.length; i++) {
     StyleRange oldSR = srs[i];
     StyleRange newSR = newStyleRange(oldSR);
     Color lightForeground =
         (oldSR.foreground == null)
             ? defaultFGColor
             : CCWPlugin.getColor(RGBUtil.lighten(oldSR.foreground.getRGB(), pct));
     newSR.foreground = lightForeground;
     st.setStyleRange(newSR);
   }
   st.setForeground(defaultFGColor);
 }
コード例 #3
0
ファイル: PyUnitViewTest.java プロジェクト: conbon/Pydev
  public void testLineTracker() throws Exception {
    // PyUnitViewTest fails because it depends on org.eclipse.debug.ui.console.IConsoleLineTracker
    // being able to be loaded. But IConsoleLineTracker is in a plug-in with an activator that in
    // turn relies on the workbench being loaded, leading to a test error. This isn't a problem
    // when run within Eclipse as a (plain) JUint test because the Activator is skipped.
    // Since the classes under test rely on IConsoleLineTracker, the test must be run as a
    // GUI enabled Plug-in test (i.e workbench started), however if you do that the test fails
    // because of interactions with other services in the workbench.
    if (PydevPlugin.getDefault() != null) {
      if (SharedCorePlugin.skipKnownFailures()) {
        return;
      }
    }
    PyUnitView pyUnitView = new PyUnitView();
    PyUnitTestRun testRun = new PyUnitTestRun(null);
    String error =
        "File \"Y:\\test_python\\src\\mod1\\mod2\\test_it2.py\", line 45, in testAnotherCase";
    PyUnitTestResult result =
        new PyUnitTestResult(
            testRun, "fail", "c:\\temp.py", "TestCase.foo", "", "\n\n" + error + "\nfoo\n", "0");

    Display display = Display.getCurrent();
    if (display == null) {
      display = Display.getDefault();
    }
    Shell composite = new Shell(display);
    composite.setLayout(new FillLayout());

    StyledText text = new StyledText(composite, 0);
    pyUnitView.setTextComponent(text);
    pyUnitView.getLineTracker().setOnlyCreateLinksForExistingFiles(false);
    pyUnitView.onSelectResult(result);

    // uncomment below to see results.
    //        composite.pack();
    //        composite.open();
    //
    //        while (!composite.isDisposed()) {
    //            if (!display.readAndDispatch()){
    //                display.sleep();
    //            }
    //        }

    StyleRange[] styleRanges = text.getStyleRanges();
    assertEquals(1, styleRanges.length);
    assertEquals(69, styleRanges[0].start);
    assertEquals(error.length(), styleRanges[0].length);
  }
コード例 #4
0
 /**
  * Returns the styles.
  *
  * @return StyleRange[]
  * @see StyledText#getStyleRanges()
  */
 public StyleRange[] getStyleRanges() {
   return textWidget.getStyleRanges();
 }