Java Code Examples for org.eclipse.swt.graphics.GC#setLineWidth()

The following examples show how to use org.eclipse.swt.graphics.GC#setLineWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwtScatterChart.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private void drawHoveringCross(GC gc) {
    if (fHoveredPoint == null) {
        return;
    }

    gc.setLineWidth(1);
    gc.setLineStyle(SWT.LINE_SOLID);
    gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

    /* Vertical line */
    gc.drawLine(fHoveringPoint.x, 0, fHoveringPoint.x, getChart().getPlotArea().getSize().y);

    /* Horizontal line */
    gc.drawLine(0, fHoveringPoint.y, getChart().getPlotArea().getSize().x, fHoveringPoint.y);
}
 
Example 2
Source File: OscilloscopeDispatcher.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private Image createGridImage() {
	Display display = Display.getDefault();
	int width = getOscilloscope().getGridSquareSize();
	Image image = new Image(display, width, width);
	GC gc = new GC(image);

	gc.setAdvanced(true);
	gc.setBackground(getOscilloscope().getGridBackground());
	gc.fillRectangle(0, 0, width, width);

	gc.setForeground(getOscilloscope().getGridForeground());
	gc.setLineWidth(getOscilloscope().getGridLineWidth());
	gc.drawLine(width/2, 0, width/2, width);
	gc.drawLine(0, width/2, width, width/2);
	gc.dispose();
	return image;
}
 
Example 3
Source File: BoxDecoratorImpl.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private void drawRect(final GC gc, final Box b, final int x, final int y, final int width, final int height) {
	if (b.isOn && settings.getHighlightWidth() > 0 && settings.getHighlightColor(b.level) != null) {
		gc.setLineStyle(settings.getHighlightLineStyleSWTInt());
		gc.setLineWidth(settings.getHighlightWidth());
		gc.setForeground(settings.getHighlightColor(b.level));
		if (settings.getHighlightDrawLine()) {
			gc.drawLine(x, y, x, y + b.rec.height);
		} else {
			// 3D
			// gc.drawLine(x-1, y+3, x-1, y + b.rec.height+1);
			// gc.drawLine(x-1, y + b.rec.height +1, x+b.rec.width-1, y +
			// b.rec.height +1);
			// gc.drawPoint(x, y+b.rec.height);
			drawRectangle(gc, x, y, width, height);
		}
	} else if (!b.isOn && settings.getBorderWidth() > 0 && settings.getBorderColor(b.level) != null) {
		gc.setLineStyle(settings.getBorderLineStyleSWTInt());
		gc.setLineWidth(settings.getBorderWidth());
		gc.setForeground(settings.getBorderColor(b.level));
		if (settings.getBorderDrawLine()) {
			gc.drawLine(x, y + 1, x, y + b.rec.height - 1);
		} else {
			drawRectangle(gc, x, y, width, height);
		}
	}
}
 
Example 4
Source File: XYChartLegendImageProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void drawStyleLine(GC gc, Color lineColor, int imageWidth, int imageHeight, @NonNull OutputElementStyle appearance) {
    Color prev = gc.getForeground();
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider2();
    LineStyle lineStyle = LineStyle.valueOf((String) presProvider.getStyleOrDefault(appearance, StyleProperties.SERIES_STYLE, StyleProperties.SeriesStyle.SOLID));
    if (lineStyle != LineStyle.NONE) {
        gc.setForeground(lineColor);
        gc.setLineWidth(((Number) presProvider.getFloatStyleOrDefault(appearance, StyleProperties.WIDTH, 1.0f)).intValue());
        gc.setLineStyle(lineStyle.ordinal());
        gc.drawLine(0, imageHeight / 2, imageWidth, imageHeight / 2);
        gc.setForeground(prev);
    }
}
 
Example 5
Source File: RendererBase.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method to restore attribute values saved with <code>saveGCAttributes</code>.
 * 
 * @param gc GC to restore attributes for
 */
protected void restoreGCAttributes(GC gc) {
    if (_bgColor == null) {
        throw new RuntimeException("no attributes saved");
    }
    gc.setBackground(_bgColor);
    gc.setForeground(_fgColor);
    gc.setFont(_font);
    gc.setLineWidth(_lineWidth);
}
 
Example 6
Source File: Histogram.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw a time range window
 *
 * @param imageGC
 *            the GC
 * @param rangeStartTime
 *            the range start time
 * @param rangeDuration
 *            the range duration
 */
protected void drawTimeRangeWindow(GC imageGC, long rangeStartTime, long rangeDuration) {

    if (fScaledData == null) {
        return;
    }

    // Map times to histogram coordinates
    double bucketSpan = fScaledData.fBucketDuration;
    long startTime = Math.min(rangeStartTime, rangeStartTime + rangeDuration);
    double rangeWidth = (Math.abs(rangeDuration) / bucketSpan);

    int left = (int) ((startTime - fDataModel.getFirstBucketTime()) / bucketSpan);
    int right = (int) (left + rangeWidth);
    int center = (left + right) / 2;
    int height = fCanvas.getSize().y;
    int arc = Math.min(15, (int) rangeWidth);

    // Draw the selection window
    imageGC.setForeground(fTimeRangeColor);
    imageGC.setLineWidth(1);
    imageGC.setLineStyle(SWT.LINE_SOLID);
    imageGC.drawRoundRectangle(left, 0, (int) rangeWidth, height - 1, arc, arc);

    // Fill the selection window
    imageGC.setBackground(fTimeRangeColor);
    imageGC.setAlpha(35);
    imageGC.fillRoundRectangle(left + 1, 1, (int) rangeWidth - 1, height - 2, arc, arc);
    imageGC.setAlpha(255);

    // Draw the cross hair
    imageGC.setForeground(fTimeRangeColor);
    imageGC.setLineWidth(1);
    imageGC.setLineStyle(SWT.LINE_SOLID);

    int chHalfWidth = ((rangeWidth < 60) ? (int) ((rangeWidth * 2) / 3) : 40) / 2;
    imageGC.drawLine(center - chHalfWidth, height / 2, center + chHalfWidth, height / 2);
    imageGC.drawLine(center, (height / 2) - chHalfWidth, center, (height / 2) + chHalfWidth);
}
 
Example 7
Source File: TimeGraphLegend.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void draw(GC gc) {
    Rectangle r = getClientArea();
    gc.setBackground(fColor);
    gc.fillRectangle(r);
    gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
    gc.setLineWidth(2);
    gc.drawRectangle(1, 1, r.width - 2, r.height - 2);
}
 
Example 8
Source File: RoundedComposite.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/** Updates the rounded rectangle background. */
private void paint(final PaintEvent e) {

  final Color backgroundToUse = getBackground();
  final Color borderToUser =
      border != null ? border : getDisplay().getSystemColor(SWT.COLOR_BLACK);

  final Rectangle bounds = getBounds();
  final Rectangle clientArea = getClientArea();

  final GC gc = e.gc;

  gc.setBackground(parent.getBackground());
  gc.fillRectangle(new Rectangle(e.x, e.y, e.width, e.height));

  PaintUtils.drawRoundedRectangle(gc, clientArea, backgroundToUse);

  if ((style & SWT.BORDER) != 0) PaintUtils.drawRoundedBorder(gc, clientArea, borderToUser);

  /*
   * If the control shall be displayed as a separator, we draw a
   * horizontal line
   */

  // FIXME why is this using constants of another util class ?
  if ((style & SWT.SEPARATOR) != 0) {
    final int top = (bounds.height - PaintUtils.LINE_WEIGHT) / 2;

    gc.setLineWidth(PaintUtils.LINE_WEIGHT);
    gc.setForeground(backgroundToUse);
    gc.drawLine(PaintUtils.ARC / 2, top, bounds.width - PaintUtils.ARC / 2, top);
  }
}
 
Example 9
Source File: XYChartLegendImageProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void drawStyleLine(GC gc, Color lineColor, int imageWidth, int imageHeight, @NonNull OutputElementStyle appearance) {
    Color prev = gc.getForeground();
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider();
    LineStyle lineStyle = LineStyle.valueOf((String) presProvider.getStyleOrDefault(appearance, StyleProperties.SERIES_STYLE, StyleProperties.SeriesStyle.SOLID));
    if (lineStyle != LineStyle.NONE) {
        gc.setForeground(lineColor);
        gc.setLineWidth(((Number) presProvider.getFloatStyleOrDefault(appearance, StyleProperties.WIDTH, 1.0f)).intValue());
        gc.setLineStyle(lineStyle.ordinal());
        gc.drawLine(0, imageHeight / 2, imageWidth, imageHeight / 2);
        gc.setForeground(prev);
    }
}
 
Example 10
Source File: EyeButton.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawEye(final GC gc, final Color clr) {
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setLineWidth(2);

	final Rectangle rect = getClientArea();
	final int eyeWidth = (int) (rect.width * .7);
	final int eyeHeight = (int) (rect.height * .5);
	gc.setForeground(clr);
	gc.drawOval((int) (rect.width * .15), (int) (rect.height * .25), eyeWidth, eyeHeight);

	gc.setBackground(clr);
	gc.fillOval(rect.width / 2 - CIRCLE_RAY / 2, rect.height / 2 - CIRCLE_RAY / 2, CIRCLE_RAY, CIRCLE_RAY);
}
 
Example 11
Source File: LEDSeparator.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void onPaint(Event e) {
	GC gc = e.gc;
	gc.setBackground(getBackground());
	gc.fillRectangle(getClientArea());
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setForeground(getForeground());
	gc.setLineWidth(1);
	gc.drawLine(0, getClientArea().height / 2, getClientArea().width, getClientArea().height / 2);
}
 
Example 12
Source File: SComposite.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void paintControl(GC gc) {
	if((borderStyle & BORDER) != 0) {
		if(advancedGraphics) {
			gc.setAntialias(SWT.ON);
		}

		gc.setLineWidth(borderWidth);

		Rectangle r = getClientArea();

		if((borderStyle & SQUARE) != 0) {
			if((borderStyle & FLAT) == 0) {
				gc.setForeground(WHITE);
				gc.drawLine(r.x+1,r.y+1, r.x+1,r.y+r.height-3);
				gc.drawLine(r.x+1,r.y+1, r.x+r.width-3,r.y+1);
			}
			gc.setForeground(borderColor);
			gc.drawRectangle(r.x,r.y, r.width-1,r.height-1);
		} else {
			if((borderStyle & FLAT) == 0) {
				gc.setForeground(WHITE);
				gc.drawLine(r.x+1,r.y+1, r.x+1,r.y+r.height-3);
				gc.drawLine(r.x+1,r.y+1, r.x+r.width-3,r.y+1);
			}
			gc.setForeground(borderColor);
			gc.drawRoundRectangle(r.x+(borderWidth/2),r.y+(borderWidth/2), r.width-borderWidth,r.height-borderWidth, borderWidth*5, borderWidth*5);
		}
	}
}
 
Example 13
Source File: PaintUtils.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
public static void drawRoundedBorder(GC gc, Rectangle bounds, Color borderColor) {
  Color backupBackground = gc.getBackground();
  int backupLineWidth = gc.getLineWidth();

  gc.setLineWidth(LINE_WEIGHT);
  gc.setForeground(borderColor);
  gc.drawRoundRectangle(
      bounds.x, bounds.y, bounds.width - LINE_WEIGHT, bounds.height - LINE_WEIGHT, ARC, ARC);

  gc.setBackground(backupBackground);
  gc.setLineWidth(backupLineWidth);
}
 
Example 14
Source File: ViewLattice.java    From arx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws a node.
 *
 * @param g
 */
private void drawNodes(final GC g) {

    // Prepare
    Rectangle bounds = new Rectangle(0, 0, (int)nodeWidth, (int)nodeHeight);
    Transform transform = new Transform(g.getDevice());
    
    // Set style
    g.setLineWidth(STROKE_WIDTH_NODE);
    g.setFont(font);

    // Draw nodes
    for (List<ARXNode> level : lattice) {
        for (ARXNode node : level) {
            
            // Obtain coordinates
            double[] center = (double[]) node.getAttributes().get(ATTRIBUTE_CENTER);
            bounds.x = (int)(center[0] - nodeWidth / 2d);
            bounds.y = (int)(center[1] - nodeHeight / 2d);
            
            // Clipping
            if (bounds.intersects(new Rectangle(0, 0, screen.x, screen.y))) { 
                
                // Retrieve/compute text rendering data
                SerializablePath path = (SerializablePath) node.getAttributes().get(ATTRIBUTE_PATH);
                Point extent = (Point) node.getAttributes().get(ATTRIBUTE_EXTENT);
                if (path == null || path.getPath() == null) {
                    String text = (String) node.getAttributes().get(ATTRIBUTE_LABEL);
                    path = new SerializablePath(new Path(canvas.getDisplay()));
                    path.getPath().addString(text, 0, 0, font);
                    node.getAttributes().put(ATTRIBUTE_PATH, path);
                    extent = g.textExtent(text);
                    node.getAttributes().put(ATTRIBUTE_EXTENT, extent);
                }
        
                // Degrade if too far away
                if (bounds.width <= 4) {
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
        
                    // Draw real node
                } else {
                    
                    // Fill background
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    if (node != getSelectedNode()) {
                        g.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw line
                    g.setLineWidth(getOuterStrokeWidth(node, bounds.width));
                    g.setForeground(getOuterColor(node));
                    g.setAntialias(SWT.ON);
                    if (node != getSelectedNode()) {
                        g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.drawRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw text
                    if (bounds.width >= 20) {
                        
                        // Enable anti-aliasing
                        g.setTextAntialias(SWT.ON);
                        
                        // Compute position and factor
                        float factor1 = (bounds.width * 0.7f) / (float)extent.x;
                        float factor2 = (bounds.height * 0.7f) / (float)extent.y;
                        float factor = Math.min(factor1, factor2);
                        int positionX = bounds.x + (int)(((float)bounds.width - (float)extent.x * factor) / 2f); 
                        int positionY = bounds.y + (int)(((float)bounds.height - (float)extent.y * factor) / 2f);
                        
                        // Initialize transformation
                        transform.identity();
                        transform.translate(positionX, positionY);
                        transform.scale(factor, factor);
                        g.setTransform(transform);
                        
                        // Draw and reset
                        g.setBackground(COLOR_BLACK);
                        g.fillPath(path.getPath());
                        g.setTransform(null);
                        g.setTextAntialias(SWT.OFF);
                    }
                }
            }
        }
    }
    
    // Clean up
    transform.dispose();
}
 
Example 15
Source File: ViewLattice.java    From arx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the connections.
 *
 * @param g
 */
private void drawConnections(GC g) {
    
    // Prepare
    Set<ARXNode> done = new HashSet<ARXNode>();
    int[] clip = new int[4];

    // Set style
    g.setLineWidth(STROKE_WIDTH_CONNECTION);
    g.setForeground(COLOR_LINE);

    // For each node
    for (List<ARXNode> level : lattice) {
        for (ARXNode node1 : level) {

            // Obtain coordinates
            double[] center1 = (double[]) node1.getAttributes().get(ATTRIBUTE_CENTER);
            
            // Draw
            for (final ARXNode node2 : node1.getSuccessors()) {
                
                boolean visible = (Boolean)node2.getAttributes().get(ATTRIBUTE_VISIBLE);
                if (visible && !done.contains(node2)) {

                   // Obtain coordinates
                   double[] center2 = (double[]) node2.getAttributes().get(ATTRIBUTE_CENTER);
                       
                   // Perform clipping
                   if (liangBarsky(0, screen.x, 0, screen.y, 
                                   center1[0], center1[1],
                                   center2[0], center2[1],
                                   clip)) {
                       
                       // Draw
                       g.drawLine(clip[0], clip[1], clip[2], clip[3]);
                   }
                }
            }

            // Add to set of already processed nodes
            done.add(node1);
        }
    }
}
 
Example 16
Source File: RemoteCursorStrategy.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @param annotation An RemoteCursorAnnotation passed by the {@link AnnotationPainter}
 * @param offset offset of the end of the Selection
 * @param length always 0, will be ignored
 */
@Override
public void draw(
    Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
  Point currentCursorPosition = textWidget.getLocationAtOffset(offset);

  // clearing mode
  if (gc == null) {
    /*
     * Redraw the surrounding area of the cursor. Because we draw a line
     * with a width larger than 1, we have to clear the area around the
     * actual coordinates (start a bit more left, and extend a bit to
     * the right).
     */
    textWidget.redraw(
        currentCursorPosition.x - CURSOR_WIDTH / 2,
        currentCursorPosition.y,
        CURSOR_WIDTH + 1,
        textWidget.getLineHeight(),
        false);

    return;
  }

  final Color oldBackground = gc.getBackground();
  final Color oldForeground = gc.getForeground();

  /*
   * Draw the cursor line
   */
  gc.setBackground(color);
  gc.setForeground(color);

  gc.setLineWidth(CURSOR_WIDTH);
  gc.drawLine(
      currentCursorPosition.x,
      currentCursorPosition.y,
      currentCursorPosition.x,
      currentCursorPosition.y + textWidget.getLineHeight());

  // set back the colors like they were before
  gc.setBackground(oldBackground);
  gc.setForeground(oldForeground);
}
 
Example 17
Source File: LineBorderDecorator.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
	int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
	
	Rectangle interiorBounds =
		new Rectangle(
				rectangle.x + borderThickness,
				rectangle.y + borderThickness,
				rectangle.width - (borderThickness * 2),
				rectangle.height - (borderThickness * 2)
		);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
	
	if (borderStyle == null || borderThickness <= 0) {
		return;
	}
	
	// Save GC settings
	Color originalForeground = gc.getForeground();
	int originalLineWidth = gc.getLineWidth();
	int originalLineStyle = gc.getLineStyle();

	gc.setLineWidth(borderThickness);

	Rectangle borderArea = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
	if (borderThickness >= 1) {
		int shift = 0;
		int areaShift = 0;
		if ((borderThickness % 2) == 0) {
			shift = borderThickness / 2;
			areaShift = (shift * 2);
		} else {
			shift = borderThickness / 2;
			areaShift = (shift * 2) + 1;
		}
		borderArea.x += shift;
		borderArea.y += shift;
		borderArea.width -= areaShift;
		borderArea.height -= areaShift;
	}

	gc.setLineStyle(LineStyleEnum.toSWT(borderStyle.getLineStyle()));
	gc.setForeground(borderStyle.getColor());
	gc.drawRectangle(borderArea);

	// Restore GC settings
	gc.setForeground(originalForeground);
	gc.setLineWidth(originalLineWidth);
	gc.setLineStyle(originalLineStyle);
}
 
Example 18
Source File: TimeSlot.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void paintControl(PaintEvent e) {
			GC gc = e.gc;
			Color oldForeground = gc.getForeground();
			Color oldBackground = gc.getBackground();
			Point controlSize = getSize();

			// Draw basic background here
			try {
				// Draw "time bar" on left side
				gc.setBackground(WHITE);
				gc.setForeground(WHITE);
				gc.fillRectangle(0, 0, TIME_BAR_WIDTH, controlSize.y);
				gc.setForeground(CELL_BORDER_LIGHT);
				int lineStyle = gc.getLineStyle();
				gc.setLineStyle(SWT.LINE_DOT);
				gc.drawLine(TIME_BAR_WIDTH + 1, 0, TIME_BAR_WIDTH + 1,
						controlSize.y);
				gc.setLineStyle(lineStyle);
				gc.setForeground(TIME_BAR_COLOR);
				gc.drawLine(controlSize.x - 1, 0, controlSize.x - 1,
						controlSize.y);
				if (isMinutesAfterHour(0)) {
					gc.setForeground(CELL_BORDER_EMPHASIZED);
				} else {
					gc.setForeground(CELL_BORDER_LIGHT);
				}
//				gc.drawLine(TIME_BAR_WIDTH + 2, 0, controlSize.x - 2, 0);
				if (isMinutesAfterHour(0) || isMinutesAfterHour(30) && !isAllDay()) {
					gc.drawLine(0, 0, controlSize.x, 0);
				}
			} finally {
				gc.setBackground(oldBackground);
				gc.setForeground(oldForeground);
			}

			// Draw focus rubberband if we're focused
			int oldLineStyle = gc.getLineStyle();
			int oldLineWidth = gc.getLineWidth();
			try {
				if (focusControl) {
					gc.setLineStyle(SWT.LINE_DASH);
					gc.setLineWidth(FOCUS_LINE_WIDTH);
					gc.setForeground(FOCUS_RUBBERBAND);
					Point parentSize = getSize();
					gc.drawRectangle(FOCUS_LINE_WIDTH,
							FOCUS_LINE_WIDTH, parentSize.x - 4,
							parentSize.y - 3);
				}

				gc.setForeground(CELL_BACKGROUND_LIGHT);
			} finally {
				gc.setForeground(oldForeground);
				gc.setLineStyle(oldLineStyle);
				gc.setLineWidth(oldLineWidth);
			}
		}
 
Example 19
Source File: Plotter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < this.chan.length; c++) {

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			PositionPolyLine(l1);
			PositionPolyLine(l2);

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(this.chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && this.chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0
					&& l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}
 
Example 20
Source File: Oscilloscope.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < chan.length; c++) {

			if (chan[c].tailSize <= 0) {
				chan[c].stack.popNegate(0);
				continue;
			}

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0 && l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}