Beispiel #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);
  }
  private AutoCloseable configGC(final GC gc) {
    final int lineStyle = gc.getLineStyle();
    final int alpha = gc.getAlpha();
    final int[] lineDash = gc.getLineDash();

    final Color foreground = gc.getForeground();
    final Color background = gc.getBackground();

    gc.setForeground(this.indentGuide.getColor(styledText));
    gc.setBackground(styledText.getBackground());
    gc.setAlpha(this.indentGuide.getTransparency());
    gc.setLineStyle(SWT.LINE_CUSTOM);
    gc.setLineDash(new int[] {1, 2});
    return new AutoCloseable() {

      @Override
      public void close() throws Exception {
        gc.setForeground(foreground);
        gc.setBackground(background);
        gc.setAlpha(alpha);
        gc.setLineStyle(lineStyle);
        gc.setLineDash(lineDash);
      }
    };
  }
Beispiel #3
0
 private void drawBorder(GC gc) {
   gc.setForeground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
   gc.setLineWidth(1);
   gc.setLineStyle(SWT.LINE_SOLID);
   gc.drawRectangle(
       pageClientArea.x, pageClientArea.y, pageClientArea.width - 1, pageClientArea.height - 1);
 }
Beispiel #4
0
  private void paint(PaintEvent event) {
    GC gc = event.gc;

    gc.setAntialias(SWT.ON);
    gc.setLineWidth(1);
    Rectangle rect = getClientArea();
    gc.setClipping(rect);
    gc.setForeground(getForeground());
    gc.setBackground(getForeground());

    Color[] palette = new Color[32];
    for (int i = 0; i < palette.length; i++) {
      float hue = 270.0f * i / (palette.length - 1);
      palette[palette.length - 1 - i] = new Color(Display.getDefault(), new RGB(hue, 1.0f, 1.0f));
      //			gc.setBackground(palette[i]);
      //			gc.fillRectangle(rect.x + i*rect.width/palette.length, rect.y, rect.width/palette.length,
      // 100);
    }

    frame.adjust();

    int x = (int) (rect.x - frame.offsetX);
    int y = (int) (rect.y - frame.offsetY);
    int extent = (int) (Math.min(rect.width, rect.height) * frame.scale);
    treeMap.paint(x, y, extent, gc, curve, palette);

    for (Color color : palette) color.dispose();

    gc.setAlpha(255);
    gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    gc.setLineStyle(SWT.LINE_DASHDOT);
    gc.setLineWidth(1);
    gc.drawRectangle(x - 1, y - 1, extent + 2, extent + 2);

    if (selection.size() > 0) {
      gc.setLineStyle(SWT.LINE_SOLID);
      gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
      for (TreeMap subtree : selection) {
        gc.drawRectangle(getItemBounds(subtree));
      }
    }
  }
 @Override
 public void paint(GC gc) {
   CanvasViewInfo lastRoot = mViewHierarchy.getRoot();
   if (lastRoot != null) {
     gc.setForeground(mOutlineColor);
     gc.setLineStyle(SwtDrawingStyle.OUTLINE.getLineStyle());
     int oldAlpha = gc.getAlpha();
     gc.setAlpha(SwtDrawingStyle.OUTLINE.getStrokeAlpha());
     drawOutline(gc, lastRoot);
     gc.setAlpha(oldAlpha);
   }
 }
 @Override
 public void paint(DrawComponent dc, GC g) {
   ShapeDrawComponent sdc = (ShapeDrawComponent) dc;
   Path path = convertShape(sdc.getGeneralShape());
   if (sdc.isFill()) {
     g.setBackground(ColorUtil.toSWTColor(sdc.getFillColor()));
     g.fillPath(path);
   }
   g.setForeground(ColorUtil.toSWTColor(sdc.getLineColor()));
   //    g.setLineWidth(sdc.getLineWidth());
   g.setLineWidth((int) sdc.getLineWidth());
   g.setLineStyle(convertLineStyle(sdc.getLineStyle()));
   g.drawPath(path);
 }
Beispiel #7
0
  @Override
  public void paint(GC gc) {
    if (mHoverRect != null) {
      // Translate the hover rectangle (in canvas coordinates) to control
      // coordinates
      int x = mHScale.translate(mHoverRect.x);
      int y = mVScale.translate(mHoverRect.y);
      int w = mHScale.scale(mHoverRect.width);
      int h = mVScale.scale(mHoverRect.height);

      boolean hoverIsSelected = false;
      List<SelectionItem> selections = mCanvas.getSelectionManager().getSelections();
      for (SelectionItem item : selections) {
        if (mHoverRect.equals(item.getViewInfo().getSelectionRect())) {
          hoverIsSelected = true;
          break;
        }
      }

      Color stroke = hoverIsSelected ? mHoverSelectStrokeColor : mHoverStrokeColor;
      Color fill = hoverIsSelected ? mHoverSelectFillColor : mHoverFillColor;

      if (stroke != null) {
        int oldAlpha = gc.getAlpha();
        gc.setForeground(stroke);
        gc.setLineStyle(hoverIsSelected ? HOVER_SELECTION.getLineStyle() : HOVER.getLineStyle());
        gc.setAlpha(hoverIsSelected ? HOVER_SELECTION.getStrokeAlpha() : HOVER.getStrokeAlpha());
        gc.drawRectangle(x, y, w, h);
        gc.setAlpha(oldAlpha);
      }

      if (fill != null) {
        int oldAlpha = gc.getAlpha();
        gc.setAlpha(hoverIsSelected ? HOVER_SELECTION.getFillAlpha() : HOVER.getFillAlpha());
        gc.setBackground(fill);
        gc.fillRectangle(x, y, w, h);
        gc.setAlpha(oldAlpha);
      }
    }
  }
Beispiel #8
0
  protected void buildBars() {
    long now = TimeUtil.getCurrentTime();
    if ((now - lastDrawTime) < REFRESH_INTERVAL || area == null) {
      return;
    }
    if (onGoing) return;
    onGoing = true;
    int width = area.width > 100 ? area.width : 100;
    int height = area.height > 50 ? area.height : 50;
    Image img = new Image(null, width, height);
    GC gc = new GC(img);
    try {
      lastDrawTime = now;
      double maxValue = 0;
      ArrayList<EqData> list = new ArrayList<EqData>();
      synchronized (valueSet) {
        for (EqData e : valueSet) {
          if (objSelMgr.isUnselectedObject(e.objHash)) {
            continue;
          }
          double max = ChartUtil.getEqMaxValue(e.asd.act1 + e.asd.act2 + e.asd.act3);
          if (max > maxValue) {
            maxValue = max;
          }
          list.add(e);
        }
      }
      size = list.size();
      if (size < 1) {
        datas = new EqData[0];
        return;
      }
      datas = list.toArray(new EqData[size]);
      unitHeight = (height - AXIS_PADDING) / size;

      if (unitHeight < MINIMUM_UNIT_HEIGHT) {
        unitHeight = MINIMUM_UNIT_HEIGHT;
      }

      // draw horizontal line
      gc.setForeground(XLogViewPainter.color_grid_narrow);
      gc.setLineStyle(SWT.LINE_DOT);
      for (int i = AXIS_PADDING + unitHeight; i <= height - unitHeight; i = i + unitHeight) {
        gc.drawLine(0, i, width, i);
      }

      // draw axis line
      gc.setForeground(black);
      gc.setLineStyle(SWT.LINE_SOLID);
      int verticalLineX = 6;
      gc.drawLine(verticalLineX, AXIS_PADDING, verticalLineX, height);
      gc.drawLine(verticalLineX, AXIS_PADDING, width, AXIS_PADDING);

      int groundWidth = area.width - verticalLineX;
      int barSpace = width - verticalLineX - (3 * BAR_WIDTH);
      int imgHeight = unitHeight - (BAR_PADDING_HEIGHT * 2);
      int mod = (int) (TimeUtil.getCurrentTime() % CYCLE_INTERVAL);
      for (int i = 0; i < datas.length; i++) {
        // draw objName
        String objName = datas[i].displayName;
        gc.setForeground(dark_gary);
        gc.setFont(verdana10Italic);
        int strWidth = gc.stringExtent(objName).x;
        while (groundWidth <= (strWidth + 5)) {
          objName = objName.substring(1);
          strWidth = gc.stringExtent(objName).x;
        }
        int x1 = width - strWidth - 5;
        int y1 =
            AXIS_PADDING + (unitHeight * i) + ((unitHeight - (gc.stringExtent(objName).y + 2)));
        gc.drawString(objName, x1, y1, true);
        if (datas[i].isAlive == false) {
          gc.setForeground(dark_gary);
          gc.setLineWidth(2);
          gc.drawLine(
              x1 - 1,
              y1 + (gc.stringExtent(objName).y / 2),
              x1 + gc.stringExtent(objName).x + 1,
              y1 + (gc.stringExtent(objName).y / 2));
        }
        gc.setLineWidth(1);
        ActiveSpeedData asd = datas[i].asd;
        long total = asd.act1 + asd.act2 + asd.act3;
        double reach = barSpace * (total / maxValue);
        int barX = verticalLineX + 1;
        if (total > 0) {
          try {
            // distribute bars to 3 types
            int noOfBars = (int) reach / BAR_WIDTH;
            int noOfAct1 = (int) (noOfBars * ((double) asd.act1 / total));
            int noOfAct2 = (int) (noOfBars * ((double) asd.act2 / total));
            int noOfAct3 = (int) (noOfBars * ((double) asd.act3 / total));
            int sediments = noOfBars - (noOfAct1 + noOfAct2 + noOfAct3);
            while (sediments > 0) {
              if (asd.act3 > 0) {
                noOfAct3++;
                sediments--;
              }
              if (sediments > 0 && asd.act2 > 0) {
                noOfAct2++;
                sediments--;
              }
              if (sediments > 0 && asd.act1 > 0) {
                noOfAct1++;
                sediments--;
              }
            }
            int barY = AXIS_PADDING + ((unitHeight * i) + BAR_PADDING_HEIGHT);
            Color lastColor = null;

            for (int j = 0; j < noOfAct3; j++) {
              // draw red bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac3,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac3;
            }
            for (int j = 0; j < noOfAct2; j++) {
              // draw yellow bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac2,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac2;
            }
            for (int j = 0; j < noOfAct1; j++) {
              // draw blue bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac1,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac1;
            }

            // draw tong-tong bar
            if (lastColor != null) {
              drawNemo(
                  gc,
                  lastColor,
                  barX + 1 + (int) calculateReach(mod, BAR_WIDTH * 0.7d),
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
            }
          } catch (Throwable th) {
            th.printStackTrace();
          }
        }

        // draw count text
        if (datas[i].isAlive) {
          gc.setFont(verdana10Bold);
          gc.setForeground(black);
          String v = Long.toString(total);
          gc.drawString(
              v,
              barX + (BAR_WIDTH * 2),
              AXIS_PADDING + (unitHeight * i) + ((unitHeight - gc.stringExtent(v).y) / 2),
              true);
        }
      }

      // draw scale text
      gc.setForeground(black);
      gc.setFont(verdana7);
      int max = (int) maxValue;
      String v = Integer.toString(max);
      String v2 = Integer.toString(max / 2);
      gc.drawString(v, width - gc.stringExtent(v).x - 2, 2, true);
      gc.drawString(
          v2, verticalLineX + ((width - verticalLineX) / 2) - gc.stringExtent(v2).x, 2, true);
      gc.drawString("0", verticalLineX, 2, true);
    } catch (Throwable th) {
      th.printStackTrace();
    } finally {
      gc.dispose();
      Image old = ibuffer;
      ibuffer = img;
      if (old != null) {
        old.dispose();
      }
      onGoing = false;
    }
  }
Beispiel #9
0
  @SuppressWarnings("deprecation")
  public void handleEvent(Event event) {

    curPaintArea = getVisibleRect();

    // System.out.println("event: " + event.type);
    if (event.type == SWT.MouseDown) {
      startX = event.x;
      startY = event.y;
      // start mouse activity
      mouseDown = true;
    } else if (event.type == SWT.MouseUp) {
      endX = event.x;
      endY = event.y;

      boolean mouseWasMoved = startX != endX || startY != endY;
      if (toolCanMove && mouseWasMoved) {
        // if the tool is able to move draw the moved image
        afterImageMove();
      }
      // stop mouse activity
      mouseDown = false;
      isDragging = false;
    } else if (event.type == SWT.Paint) {
      // System.out.println("PAINT CALLED (DOESN'T MEAN I'M DRAWING)");

      if (acceptRepaintRequests) {
        gc = event.gc;

        // System.out.println(toolCanDraw + "/" + toolCanMove + "/" + isDragging + "/" +
        // redrawBaseImage);

        /*
         * if the mouse is dragging and the current tool can
         * move the map we just draw what we already have
         * on white background. At the end of the moving
         * we will take care of adding the missing pieces.
         */
        if (toolCanMove && isDragging) {
          // System.out.println("toolCanMove && isDragging");
          if (gc != null && !gc.isDisposed() && swtImage != null) {
            /*
             * double buffer necessary, since the SWT.NO_BACKGROUND
             * needed by the canvas to properly draw background, doesn't
             * clean the parts outside the bounds of the moving panned image,
             * giving a spilling image effect.
             */
            Image tmpImage = new Image(getDisplay(), curPaintArea.width, curPaintArea.height);
            GC tmpGc = new GC(tmpImage);
            tmpGc.setBackground(white);
            tmpGc.fillRectangle(0, 0, curPaintArea.width, curPaintArea.height);
            tmpGc.drawImage(swtImage, imageOrigin.x, imageOrigin.y);
            gc.drawImage(tmpImage, 0, 0);
            tmpImage.dispose();
          }
          return;
        }

        /*
         * if the mouse is dragging and the current tool can
         * draw a boundingbox while dragging, we draw the box
         * keeping the current drawn image
         */
        if (toolCanDraw && toolManager.getCursorTool().isDrawing() && isDragging) {
          // System.out.println("draw box: " + startX + "/" + startY + "/" + endX +
          // "/" + endY);
          if (swtImage != null) {
            drawFinalImage(swtImage);
          }
          gc.setXORMode(true);

          org.eclipse.swt.graphics.Color fC = gc.getForeground();
          gc.setLineStyle(cursorToolLineStyle);
          gc.setLineWidth(cursorToolLineWidth);
          gc.setForeground(cursorToolColor);
          gc.drawRectangle(startX, startY, endX - startX, endY - startY);

          gc.setForeground(fC);
          gc.setXORMode(false);
          return;
        }

        if (!toolCanDraw && !toolCanMove && isDragging) {
          return;
        }

        if (curPaintArea == null || content == null || renderer == null) {
          return;
        }

        if (content.layers().size() == 0) {
          // if no layers available, return only if there are also no overlays

          gc.setForeground(yellow);
          gc.fillRectangle(0, 0, curPaintArea.width + 1, curPaintArea.height + 1);
          if (overlayImage == null) return;
        }

        final ReferencedEnvelope mapAOI = content.getViewport().getBounds();
        if (mapAOI == null) {
          return;
        }

        if (redrawBaseImage) {
          MapPaneEvent ev = new MapPaneEvent(this, MapPaneEvent.Type.RENDERING_STARTED);
          publishEvent(ev);

          baseImage =
              new BufferedImage(
                  curPaintArea.width + 1, curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);
          Graphics2D g2d = baseImage.createGraphics();
          g2d.fillRect(0, 0, curPaintArea.width + 1, curPaintArea.height + 1);
          g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

          // renderer.setContext(context);
          java.awt.Rectangle awtRectangle = Utils.toAwtRectangle(curPaintArea);
          renderer.paint(g2d, awtRectangle, mapAOI, getWorldToScreenTransform());
          // swtImage.dispose();

          if (swtImage != null && !swtImage.isDisposed()) {
            swtImage.dispose();
            swtImage = null;
          }
          // System.out.println("READRAWBASEIMAGE");
          swtImage =
              new Image(
                  getDisplay(),
                  awtToSwt(baseImage, curPaintArea.width + 1, curPaintArea.height + 1));
        }

        if (swtImage != null) {
          drawFinalImage(swtImage);
        }

        MapPaneEvent ev = new MapPaneEvent(this, MapPaneEvent.Type.RENDERING_STOPPED);
        publishEvent(ev);
        clearLabelCache = true;
        onRenderingCompleted();
        redrawBaseImage = false;
      }
    }
  }
 protected void highlightDifferences(GC gc) {
   // if the differencer is null then we are currently
   // in the middle of a content update, skip this paint
   // request
   if (mergeViewer.getDifferencer() == null) {
     return;
   }
   gc.setAdvanced(true);
   gc.setAntialias(SWT.ON);
   Tree tree = getTree();
   List<TreeDifference> differences = mergeViewer.getDifferencer().getLeftDifferences();
   if (mergeViewer.getLeftViewer() != this && mergeViewer.getAncestorTree() != this) {
     differences = mergeViewer.getDifferencer().getRightDifferences();
   }
   for (TreeDifference difference : differences) {
     if (differenceIsGraphical(difference)) {
       // we do not include graphical differences
       // at this time
       continue;
     }
     gc.setForeground(
         getMergeViewer()
             .getColor(
                 PlatformUI.getWorkbench().getDisplay(),
                 getMergeViewer().getStrokeColor(difference)));
     TreeItem item = getItemForDifference(difference);
     if (item == null || item.isDisposed()) {
       continue;
     }
     Rectangle highlightBounds =
         buildHighlightRectangle(
             item, difference.getIncludeChildren() && item.getExpanded(), gc, false, true);
     Rectangle itemBounds = buildHighlightRectangle(item, false, gc, false, true);
     boolean itemMatchesDifference = difference.getElement().equals(item.getData());
     if (!itemMatchesDifference && !(item.getData() instanceof EmptyElement)) {
       gc.setLineDash(new int[] {3});
       gc.setLineStyle(SWT.LINE_CUSTOM);
     } else {
       gc.setLineStyle(SWT.LINE_SOLID);
     }
     gc.drawRoundRectangle(
         highlightBounds.x,
         highlightBounds.y,
         highlightBounds.width,
         highlightBounds.height,
         5,
         5);
     if (mergeViewer.getLeftViewer() == this) {
       gc.drawLine(
           highlightBounds.x + highlightBounds.width,
           highlightBounds.y + (itemBounds.height / 2),
           tree.getClientArea().x + tree.getClientArea().width,
           highlightBounds.y + (itemBounds.height / 2));
     } else {
       gc.drawLine(
           highlightBounds.x,
           highlightBounds.y + (itemBounds.height / 2),
           tree.getClientArea().x,
           highlightBounds.y + (itemBounds.height / 2));
     }
     gc.setLineStyle(SWT.LINE_SOLID);
   }
 }