예제 #1
0
  /** @param gc */
  private void paintSpellError(GC gc) {
    if (ranges.isEmpty()) return;

    int lineStyle = gc.getLineStyle();
    int lineWidth = gc.getLineWidth();
    Color lineColor = gc.getForeground();
    gc.setLineWidth(2);
    gc.setLineStyle(SWT.LINE_DOT);
    gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_RED));
    int charCount = contentAdapter.getControlContents(control).length();
    Rectangle clipping = gc.getClipping();
    lineCache.clear();
    for (Object obj : ranges.values().toArray()) {
      SpellCheckEvent range = (SpellCheckEvent) obj;
      int start = range.getWordContextPosition();
      if (start < 0 || start >= charCount) continue;

      int length = Math.min(range.getInvalidWord().length(), charCount - start);
      if (length <= 0) continue;

      drawLines(gc, start, start + length - 1, clipping);
    }
    gc.setLineWidth(lineWidth);
    gc.setLineStyle(lineStyle);
    gc.setForeground(lineColor);
  }
  @Test
  public void testRestoresState() {
    dispatcher.dispatch();

    assertEquals(0, gc.getAlpha());
    assertEquals(0, gc.getLineWidth());
    assertNull(gc.getForeground());
  }
예제 #3
0
  /**
   * Paints the preview at the given x/y position
   *
   * @param gc the graphics context to paint it into
   * @param x the x coordinate to paint the preview at
   * @param y the y coordinate to paint the preview at
   */
  void paint(GC gc, int x, int y) {
    mTitleHeight = paintTitle(gc, x, y, true /*showFile*/);
    y += mTitleHeight;
    y += 2;

    int width = getWidth();
    int height = getHeight();
    if (mThumbnail != null && mError == null) {
      gc.drawImage(mThumbnail, x, y);

      if (mActive) {
        int oldWidth = gc.getLineWidth();
        gc.setLineWidth(3);
        gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
        gc.drawRectangle(x - 1, y - 1, width + 2, height + 2);
        gc.setLineWidth(oldWidth);
      }
    } else if (mError != null) {
      if (mThumbnail != null) {
        gc.drawImage(mThumbnail, x, y);
      } else {
        gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BORDER));
        gc.drawRectangle(x, y, width, height);
      }

      gc.setClipping(x, y, width, height);
      Image icon = IconFactory.getInstance().getIcon("renderError"); // $NON-NLS-1$
      ImageData data = icon.getImageData();
      int prevAlpha = gc.getAlpha();
      int alpha = 96;
      if (mThumbnail != null) {
        alpha -= 32;
      }
      gc.setAlpha(alpha);
      gc.drawImage(icon, x + (width - data.width) / 2, y + (height - data.height) / 2);

      String msg = mError;
      Density density = mConfiguration.getDensity();
      if (density == Density.TV || density == Density.LOW) {
        msg =
            "Broken rendering library; unsupported DPI. Try using the SDK manager "
                + "to get updated layout libraries.";
      }
      int charWidth = gc.getFontMetrics().getAverageCharWidth();
      int charsPerLine = (width - 10) / charWidth;
      msg = SdkUtils.wrap(msg, charsPerLine, null);
      gc.setAlpha(255);
      gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
      gc.drawText(msg, x + 5, y + HEADER_HEIGHT, true);
      gc.setAlpha(prevAlpha);
      gc.setClipping((Region) null);
    } else {
      gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BORDER));
      gc.drawRectangle(x, y, width, height);

      Image icon = IconFactory.getInstance().getIcon("refreshPreview"); // $NON-NLS-1$
      ImageData data = icon.getImageData();
      int prevAlpha = gc.getAlpha();
      gc.setAlpha(96);
      gc.drawImage(icon, x + (width - data.width) / 2, y + (height - data.height) / 2);
      gc.setAlpha(prevAlpha);
    }

    if (mActive) {
      int left = x;
      int prevAlpha = gc.getAlpha();
      gc.setAlpha(208);
      Color bg = mCanvas.getDisplay().getSystemColor(SWT.COLOR_WHITE);
      gc.setBackground(bg);
      gc.fillRectangle(left, y, x + width - left, HEADER_HEIGHT);
      gc.setAlpha(prevAlpha);

      y += 2;

      // Paint icons
      gc.drawImage(CLOSE_ICON, left, y);
      left += CLOSE_ICON_WIDTH;

      gc.drawImage(ZOOM_IN_ICON, left, y);
      left += ZOOM_IN_ICON_WIDTH;

      gc.drawImage(ZOOM_OUT_ICON, left, y);
      left += ZOOM_OUT_ICON_WIDTH;

      gc.drawImage(EDIT_ICON, left, y);
      left += EDIT_ICON_WIDTH;
    }
  }