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

The following examples show how to use org.eclipse.swt.graphics.GC#setLineStyle() . 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: 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 2
Source File: IndentGuidePainter.java    From IndentGuide with MIT License 6 votes vote down vote up
private void handleDrawRequest(GC gc, int x, int y, int w, int h) {
	int startLine = fTextWidget.getLineIndex(y);
	int endLine = fTextWidget.getLineIndex(y + h - 1);
	if (startLine <= endLine && startLine < fTextWidget.getLineCount()) {
		Color fgColor = gc.getForeground();
		LineAttributes lineAttributes = gc.getLineAttributes();
		gc.setForeground(Activator.getDefault().getColor());
		gc.setLineStyle(lineStyle);
		gc.setLineWidth(lineWidth);
		spaceWidth = gc.getAdvanceWidth(' ');
		if (fIsAdvancedGraphicsPresent) {
			int alpha = gc.getAlpha();
			gc.setAlpha(this.lineAlpha);
			drawLineRange(gc, startLine, endLine, x, w);
			gc.setAlpha(alpha);
		} else {
			drawLineRange(gc, startLine, endLine, x, w);
		}
		gc.setForeground(fgColor);
		gc.setLineAttributes(lineAttributes);
	}
}
 
Example 3
Source File: VerticalIndentGuidesPainter.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
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);
        }
    };
}
 
Example 4
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 5
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 6
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
void paintScale(final GC gc) {
	gc.setBackground(IGamaColors.BLACK.color());
	final int BAR_WIDTH = 1;
	final int BAR_HEIGHT = 8;
	final int x = 0;
	final int y = 0;
	final int margin = 20;
	final int width = scalebar.getBounds().width - 2 * margin;
	final int height = scalebar.getBounds().height;
	final int barStartX = x + 1 + BAR_WIDTH / 2 + margin;
	final int barStartY = y + height - BAR_HEIGHT / 2;

	final Path path = new Path(WorkbenchHelper.getDisplay());
	path.moveTo(barStartX, barStartY - BAR_HEIGHT + 2);
	path.lineTo(barStartX, barStartY + 2);
	path.moveTo(barStartX, barStartY - BAR_HEIGHT / 2 + 2);
	path.lineTo(barStartX + width, barStartY - BAR_HEIGHT / 2 + 2);
	path.moveTo(barStartX + width, barStartY - BAR_HEIGHT + 2);
	path.lineTo(barStartX + width, barStartY + 2);

	gc.setForeground(IGamaColors.WHITE.color());
	gc.setLineStyle(SWT.LINE_SOLID);
	gc.setLineWidth(BAR_WIDTH);
	gc.drawPath(path);
	gc.setFont(coord.getFont());
	drawStringCentered(gc, "0", barStartX, barStartY - 6, false);
	drawStringCentered(gc, getScaleRight(), barStartX + width, barStartY - 6, false);
	path.dispose();
}
 
Example 7
Source File: BorderPainter.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void paintControl(PaintEvent e) {
  Composite composite = (Composite) e.widget;
  Rectangle bounds = composite.getBounds();
  GC gc = e.gc;
  gc.setLineStyle(SWT.LINE_DOT);
  gc.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y);
}
 
Example 8
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 9
Source File: TmfXYChartViewer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw the grid lines
 *
 * @param bounds
 *            The bounds of the control
 * @param gc
 *            Graphics context
 */
private void drawGridLines(GC gc) {
    Rectangle bounds = fSwtChart.getPlotArea().getBounds();
    Color foreground = fSwtChart.getAxisSet().getXAxis(0).getGrid().getForeground();
    gc.setForeground(foreground);
    gc.setAlpha(foreground.getAlpha());
    gc.setLineStyle(SWT.LINE_DOT);
    for (int x : fTimeScaleCtrl.getTickList()) {
        gc.drawLine(x, 0, x,  bounds.height);
    }
    gc.setAlpha(255);
}
 
Example 10
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 11
Source File: DefaultInsertMarkRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the insertion mark.  The bounds of the renderer
 * need not be set.
 * 
 * @param gc
 * @param value  must be a {@link Rectangle} with height == 0.
 */
public void paint(GC gc, Object value)
{
	Rectangle r = (Rectangle)value;

	gc.setLineStyle(SWT.LINE_SOLID);
	gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));

	gc.drawLine(r.x, r.y-1, r.x+r.width, r.y-1);
	gc.drawLine(r.x, r.y  , r.x+r.width, r.y  );
	gc.drawLine(r.x, r.y+1, r.x+r.width, r.y+1);

	gc.drawLine(r.x-1,  r.y-2,  r.x-1,   r.y+2);
	gc.drawLine(r.x-2,  r.y-3,  r.x-2,   r.y+3);
}
 
Example 12
Source File: BaseSwtParameter.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleEvent(Event event) {
	if (parent == null || control.isDisposed()) {
		return;
	}

	Rectangle boundsInParent = control.getBounds();
	if (boundsInParent.width == 0 || boundsInParent.height == 0) {
		return;
	}
	Rectangle bounds = control.getBounds();
	GC gc = event.gc;
	Display display = event.display;
	if (gc == null || display == null) {
		return;
	}

	int x = boundsInParent.x - width + 18;
	int x2 = x + width - 22;
	int y = boundsInParent.y;
	int y2 = boundsInParent.y + (bounds.height / 2);
	gc.setLineStyle(SWT.LINE_DASH);
	gc.setLineDash(new int[] {
		3,
		2
	});
	gc.setForeground(display.getSystemColor(parent.isEnabled()
			? SWT.COLOR_WIDGET_FOREGROUND : SWT.COLOR_WIDGET_LIGHT_SHADOW));
	gc.drawLine(x, y, x, y2);
	gc.drawLine(x, y2, x2, y2);

	x++;
	y++;
	y2++;
	x2++;
	gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
	gc.drawLine(x, y, x, y2);
	gc.drawLine(x, y2, x2, y2);

}
 
Example 13
Source File: MarkerEditorComposite.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void paintMarker( GC gc, Marker currentMarker, Location location )
{
	// Paint an icon sample, not a real icon in the Fill
	Marker renderMarker = currentMarker;
	int markerSize = 4;
	if ( currentMarker.getType( ) == MarkerType.ICON_LITERAL )
	{
		renderMarker = currentMarker.copyInstance( );
		renderMarker.setFill( ImageImpl.create( UIHelper.getURL( "icons/obj16/marker_icon.gif" ).toString( ) ) ); //$NON-NLS-1$
		// To prevent the icon being too small in UI, use the original size
		// for icon
		markerSize = 0;
	}

	idrSWT.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT, gc );
	final MarkerRenderer mr = new MarkerRenderer( idrSWT,
			StructureSource.createUnknown( null ),
			location,
			LineAttributesImpl.create( ( getMarker( ).isSetVisible( ) && getMarker( ).isVisible( ) ) ? ColorDefinitionImpl.BLUE( )
					: ColorDefinitionImpl.GREY( ),
					LineStyle.SOLID_LITERAL,
					1 ),
			isMarkerTypeEnabled( ) ? ColorDefinitionImpl.create( 80,
					168,
					218 ) : ColorDefinitionImpl.GREY( ),
			renderMarker,
			markerSize,
			null,
			false,
			false );
	try
	{
		mr.draw( idrSWT );
		ChartWizard.removeException( ChartWizard.MarkerEdiCom_ID );
	}
	catch ( ChartException ex )
	{
		ChartWizard.showException( ChartWizard.MarkerEdiCom_ID,
				ex.getLocalizedMessage( ) );
	}

	// Render a boundary line to indicate focus
	if ( cnvMarker.isFocusControl( ) )
	{
		gc.setLineStyle( SWT.LINE_DOT );
		gc.setForeground( Display.getCurrent( )
				.getSystemColor( SWT.COLOR_BLACK ) );
		gc.drawRectangle( 0, 0, getSize( ).x - 21, this.getSize( ).y - 5 );
	}

}
 
Example 14
Source File: SwtTextRenderer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void renderBorder( IChartComputation cComp, GC gc, Label la, int iLabelLocation,
		Location lo ) throws ChartException
{
	// RENDER THE OUTLINE/BORDER
	final LineAttributes lia = la.getOutline( );
	if ( lia != null
			&& lia.isVisible( )
			&& lia.getColor( ) != null )
	{
		RotatedRectangle rr = cComp.computePolygon( _sxs,
				iLabelLocation,
				la,
				lo.getX( ),
				lo.getY( ),
				null );

		final int iOldLineStyle = gc.getLineStyle( );
		final int iOldLineWidth = gc.getLineWidth( );

		final Color cFG = (Color) _sxs.getColor( lia.getColor( ) );
		gc.setForeground( cFG );

		R31Enhance.setAlpha( gc, lia.getColor( ) );

		int iLineStyle = SWT.LINE_SOLID;
		switch ( lia.getStyle( ).getValue( ) )
		{
			case ( LineStyle.DOTTED                      ) :
				iLineStyle = SWT.LINE_DOT;
				break;
			case ( LineStyle.DASH_DOTTED                      ) :
				iLineStyle = SWT.LINE_DASHDOT;
				break;
			case ( LineStyle.DASHED                      ) :
				iLineStyle = SWT.LINE_DASH;
				break;
		}
		gc.setLineStyle( iLineStyle );
		gc.setLineWidth( lia.getThickness( ) );

		gc.drawPolygon( rr.getSwtPoints( ) );

		gc.setLineStyle( iOldLineStyle );
		gc.setLineWidth( iOldLineWidth );
		cFG.dispose( );
	}
}
 
Example 15
Source File: AbstractPaintManager.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void drawLockedDateRangeMarker(final GanttComposite ganttComposite, final ISettings settings, final IColorManager colorManager, final GanttEvent ge, final GC gc, final boolean threeDee, final int dayWidth, final int y, final int startLoc, final int end, final Rectangle bounds) {
    int start = startLoc;
    final int maxY = settings.getEventHeight();
    final int topY = y - 2;
    int xEnd = end;

    gc.setForeground(ColorCache.getColor(188, 188, 188));
    gc.setLineStyle(SWT.LINE_SOLID);
    gc.setLineWidth(1);

    // we don't draw any extras on the hours view, it doesn't behave like the others
    int extra = dayWidth;
    if (ganttComposite.getCurrentView() == ISettings.VIEW_DAY) {
        extra = 0;
    }

    if (start != -1 && xEnd != -1) {
        // no need to draw beyond what we can see, and it's extremely slow to draw dots anyway, so we need this to be as fast as can be
        if (start < 0) {
            start = -1;
        }
        if (xEnd > bounds.width) {
            xEnd = bounds.width + 1;
        }

        // space it slightly or we'll draw on top of event borders
        gc.drawRectangle(start - 1, topY, xEnd - start + extra + 2, maxY + 4);
    } else {
        //gc.setLineStyle(SWT.LINE_SOLID);
        if (start != -1) {
            gc.drawRectangle(start - 4, topY + 1, 2, 3 + maxY);
            gc.drawLine(start - 2, topY + 1, start + 5, topY + 1);
            gc.drawLine(start - 2, topY + 4 + maxY, start + 5, topY + 4 + maxY);
        }
        if (xEnd != -1) {
            xEnd += extra;
            gc.drawRectangle(xEnd + 2, topY + 1, 2, 3 + maxY);
            gc.drawLine(xEnd + 2, topY + 1, xEnd - 5, topY + 1);
            gc.drawLine(xEnd + 2, topY + 4 + maxY, xEnd - 5, topY + 4 + maxY);
        }
    }

    //gc.setLineWidth(1);
    //gc.setLineStyle(SWT.LINE_SOLID);
}
 
Example 16
Source File: FillChooserComposite.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
void paintControl( PaintEvent pe )
{
	Color cBlack = new Color( this.getDisplay( ), 0, 0, 0 );
	Color cWhite = new Color( this.getDisplay( ), 255, 255, 255 );
	GC gc = pe.gc;
	gc.setForeground( cBlack );

	int iCellWidth = this.getSize( ).x / ROW_SIZE;
	int iCellHeight = this.getSize( ).y / COLUMN_SIZE;
	boolean isFound = false;
	for ( int iR = 0; iR < COLUMN_SIZE; iR++ )
	{
		for ( int iC = 0; iC < ROW_SIZE; iC++ )
		{
			int index = iR * ROW_SIZE + iC;
			try
			{
				gc.setBackground( colorMap[index] );
			}
			catch ( Throwable e )
			{
				e.printStackTrace( );
			}
			gc.fillRectangle( iC * iCellWidth,
					iR * iCellHeight,
					iCellWidth,
					iCellHeight );
			// Highlight currently selected color if it exists in this
			// list
			if ( selectedIndex == index
					|| !isFound
					&& colorSelection != null
					&& colorSelection.equals( colorMap[index] ) )
			{
				isFound = true;
				selectedIndex = index;
				if ( colorSelection == null )
				{
					colorSelection = colorMap[index];
				}

				if ( isFocusControl( ) )
				{
					gc.setLineStyle( SWT.LINE_DOT );
				}
				gc.drawRectangle( iC * iCellWidth,
						iR * iCellHeight,
						iCellWidth - 2,
						iCellHeight - 2 );
				gc.setForeground( cWhite );
				gc.drawRectangle( iC * iCellWidth + 1, iR
						* iCellHeight
						+ 1, iCellWidth - 3, iCellHeight - 3 );
				gc.setForeground( cBlack );
			}
		}
	}
	if ( !isFound )
	{
		clearColorSelection( );
	}
	cBlack.dispose( );
	cWhite.dispose( );
	gc.dispose( );
}
 
Example 17
Source File: LineCanvas.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void paintControl( PaintEvent pe )
{
	if ( isEnabled( ) && isFocusControl( ) )
	{
		isFocusIn = true;
	}

	Color cForeground = null;
	Color cBackground = null;
	if ( this.isEnabled( ) )
	{
		cForeground = getDisplay( ).getSystemColor( SWT.COLOR_LIST_FOREGROUND );
		cBackground = getDisplay( ).getSystemColor( SWT.COLOR_LIST_BACKGROUND );
	}
	else
	{
		cForeground = getDisplay( ).getSystemColor( SWT.COLOR_DARK_GRAY );
		cBackground = getDisplay( ).getSystemColor( SWT.COLOR_WIDGET_BACKGROUND );
	}

	GC gc = pe.gc;
	if ( isFocusIn )
	{
		gc.setBackground( getDisplay( ).getSystemColor( SWT.COLOR_LIST_SELECTION ) );
		gc.setForeground( getDisplay( ).getSystemColor( SWT.COLOR_LIST_SELECTION_TEXT ) );
	}
	else
	{
		gc.setBackground( cBackground );
		gc.setForeground( cForeground );
	}

	gc.fillRectangle( 0, 0, this.getSize( ).x, this.getSize( ).y );
	gc.setLineStyle( iLineStyle );
	gc.setLineWidth( iLineWidth );
	gc.drawLine( 10,
			this.getSize( ).y / 2,
			this.getSize( ).x - 10,
			this.getSize( ).y / 2 );

}
 
Example 18
Source File: BranchRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void paint(GC gc, Object value) {
	Rectangle bounds = getBounds();
	
	int xLeft = bounds.x;
	int yTop = bounds.y - 1;
	
	int yBottom = yTop + bounds.height;
	int yMiddle = toggleBounds.y + toggleBounds.height / 2;
	int yToggleBottom = toggleBounds.y + toggleBounds.height - 1;
	int yToggleTop = toggleBounds.y;
	
	int oldStyle = gc.getLineStyle();
	Color oldForeground = gc.getForeground();
	int[] oldLineDash = gc.getLineDash();
	
	gc.setForeground(getDisplay().getSystemColor(
			isSelected() ? 
					SWT.COLOR_LIST_SELECTION_TEXT 
					: SWT.COLOR_WIDGET_NORMAL_SHADOW));

	int dy = bounds.y % 2;

	// Set line style to dotted
	gc.setLineDash(LINE_STYLE);
	
	// Adjust line positions by a few pixels to create correct effect
	yToggleTop --;
	yTop ++;
	yToggleBottom ++;
	
	// Adjust full height
	// If height is even, we shorten to an odd number of pixels, and start at the original y offset
	if (bounds.height % 2 == 0) {
		yBottom -= 1;
	}
	// If height is odd, we alternate based on the row offset
	else {
		yTop += dy;
		yBottom -= dy;
	}

	// Adjust ascender and descender
	yToggleBottom += dy;

	if ((yToggleTop - yTop + 1) % 2 == 0)
		yToggleTop -= 1;
	if ((yToggleBottom - yBottom + 1) % 2 == 0)
		yToggleBottom += dy == 1 ? -1 : 1;
	
	for (int i = 0; i < branches.length; i++) {
		// Calculate offsets for this branch
		int xRight = xLeft + indent;
		int xMiddle = xLeft + toggleBounds.width / 2;
		int xMiddleBranch = xMiddle;
		int xToggleRight = xLeft + toggleBounds.width;

		int dx = 0;
		xRight --;
		xMiddleBranch += 2;
		xToggleRight --;
		
		if (indent % 2 == 0) {
			xRight -= 1;
		}
		else {
			dx = xLeft % 2;
			xLeft += dx;
			xRight -= dx;
		}
		
		// Render line segments
		if ((branches[i] & H_FULL) == H_FULL)
			gc.drawLine(xLeft, yMiddle, xRight, yMiddle);
		if ((branches[i] & H_RIGHT) == H_RIGHT)
			gc.drawLine(xMiddleBranch, yMiddle, xRight, yMiddle);
		if ((branches[i] & H_CENTRE_TOGGLE) == H_CENTRE_TOGGLE)
			gc.drawLine(xMiddleBranch, yMiddle, xToggleRight, yMiddle);
		if ((branches[i] & H_LEFT_TOGGLE) == H_LEFT_TOGGLE)
			gc.drawLine(xLeft, yMiddle, xToggleRight, yMiddle);
		if ((branches[i] & V_FULL) == V_FULL)
			gc.drawLine(xMiddle, yTop, xMiddle, yBottom);
		if ((branches[i] & V_TOP) == V_TOP)
			gc.drawLine(xMiddle, yTop, xMiddle, yMiddle);
		if ((branches[i] & ASCENDER) == ASCENDER)
			gc.drawLine(xMiddle, yTop, xMiddle, yToggleTop);
		if ((branches[i] & DESCENDER) == DESCENDER)
			gc.drawLine(xMiddle, yToggleBottom, xMiddle, yBottom);
		
		xLeft += indent - dx;
	}

	gc.setLineDash(oldLineDash);
	gc.setLineStyle(oldStyle);
	gc.setForeground(oldForeground);
}
 
Example 19
Source File: DataTableDecorator.java    From arx with Apache License 2.0 4 votes vote down vote up
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
    int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;

    // check how many border lines are configured for that cell
    List<String> labels = cell.getConfigLabels().getLabels();

    int leftBorderThickness = 0;
    int rightBorderThickness = 0;
    int topBorderThickness = 0;
    int bottomBorderThickness = 0;

    if (labels.contains(LEFT_LINE_BORDER_LABEL)) leftBorderThickness = borderThickness;
    if (labels.contains(RIGHT_LINE_BORDER_LABEL)) rightBorderThickness = borderThickness;
    if (labels.contains(TOP_LINE_BORDER_LABEL)) topBorderThickness = borderThickness;
    if (labels.contains(BOTTOM_LINE_BORDER_LABEL)) bottomBorderThickness = borderThickness;

    Rectangle interiorBounds = new Rectangle(rectangle.x + leftBorderThickness,
                                             rectangle.y + topBorderThickness,
                                             (rectangle.width - leftBorderThickness - rightBorderThickness),
                                             (rectangle.height - topBorderThickness - bottomBorderThickness));
    super.paintCell(cell, gc, interiorBounds, configRegistry);

    if (borderStyle == null ||
        borderThickness <= 0 ||
        (leftBorderThickness == 0 && rightBorderThickness == 0 && topBorderThickness == 0 && bottomBorderThickness == 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 correction = 0;

        if ((borderThickness % 2) == 0) {
            shift = borderThickness / 2;
        } else {
            shift = borderThickness / 2;
            correction = 1;
        }

        if (leftBorderThickness >= 1) {
            borderArea.x += shift;
            borderArea.width -= shift;
        }

        if (rightBorderThickness >= 1) {
            borderArea.width -= shift + correction;
        }

        if (topBorderThickness >= 1) {
            borderArea.y += shift;
            borderArea.height -= shift;
        }

        if (bottomBorderThickness >= 1) {
            borderArea.height -= shift + correction;
        }
    }

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

    // if all borders are set draw a rectangle
    if (leftBorderThickness > 0 && rightBorderThickness > 0 && topBorderThickness > 0 && bottomBorderThickness > 0) {
        gc.drawRectangle(borderArea);
    }
    // else draw a line for every set border
    else {
        Point topLeftPos = new Point(borderArea.x, borderArea.y);
        Point topRightPos = new Point(borderArea.x + borderArea.width, borderArea.y);
        Point bottomLeftPos = new Point(borderArea.x, borderArea.y + borderArea.height);
        Point bottomRightPos = new Point(borderArea.x + borderArea.width, borderArea.y + borderArea.height);

        if (leftBorderThickness > 0) {
            gc.drawLine(topLeftPos.x, topLeftPos.y, bottomLeftPos.x, bottomLeftPos.y);
        }
        if (rightBorderThickness > 0) {
            gc.drawLine(topRightPos.x, topRightPos.y, bottomRightPos.x, bottomRightPos.y);
        }
        if (topBorderThickness > 0) {
            gc.drawLine(topLeftPos.x, topLeftPos.y, topRightPos.x, topRightPos.y);
        }
        if (bottomBorderThickness > 0) {
            gc.drawLine(bottomLeftPos.x, bottomLeftPos.y, bottomRightPos.x, bottomRightPos.y);
        }
    }

    // Restore GC settings
    gc.setForeground(originalForeground);
    gc.setLineWidth(originalLineWidth);
    gc.setLineStyle(originalLineStyle);
}
 
Example 20
Source File: SymbolHelper.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Draw a cross, an X symbol
 *
 * @param gc
 *            the graphics context to draw to
 * @param color
 *            the color of the symbol
 * @param symbolSize
 *            the size of the symbol (radius in pixels)
 * @param centerX
 *            the center point x coordinate
 * @param centerY
 *            the center point y coordinate
 */
public static void drawCross(GC gc, Color color, int symbolSize, int centerX, int centerY) {
    int prevLs = gc.getLineStyle();
    int prevLw = gc.getLineWidth();
    Color oldColor = gc.getForeground();
    gc.setForeground(color);
    gc.setLineWidth(Math.max(2, symbolSize / 4));
    gc.drawLine(centerX - symbolSize, centerY - symbolSize, centerX + symbolSize, centerY + symbolSize);
    gc.drawLine(centerX - symbolSize, centerY + symbolSize, centerX + symbolSize, centerY - symbolSize);
    gc.setLineStyle(prevLs);
    gc.setLineWidth(prevLw);
    gc.setForeground(oldColor);
}