org.eclipse.draw2d.FigureUtilities Java Examples

The following examples show how to use org.eclipse.draw2d.FigureUtilities. 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: EditorRulerFigure.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private boolean canDrawNumber(String num, Point startPoint ,Graphics g)
{
	Transposer transposer = new Transposer();
	transposer.setEnabled( !isHorizontal() );
	Rectangle rect =  transposer.t( g.getClip( Rectangle.SINGLETON ));
	Dimension strSize = FigureUtilities.getStringExtents(num, getFont());
	startPoint = transposer.t(startPoint);
	
	if (strSize.width + startPoint.x > rect.x  +  rect.width)
	{
		return false;
	}
	rect = transposer.t( getEndRect( g
			.getClip( Rectangle.SINGLETON ) ));
	
	if (rect.width == 0)
	{
		return true;
	}
	if (strSize.width + startPoint.x > rect.x)
	{
		return false;
	}
	return true;
}
 
Example #2
Source File: TimeAxisFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void paintMarkers(Graphics graphics) {

		final Rectangle bounds = getBounds();
		graphics.setForegroundColor(ColorConstants.darkGray);
		graphics.setLineStyle(SWT.LINE_SOLID);

		final Insets insets = RootFigure.getFigure(this, TracksFigure.class).getInsets();
		final ITimelineStyleProvider styleProvider = RootFigure.getRootFigure(this).getStyleProvider();

		final Map<Double, Integer> markerPositions = getDetailFigure().getMarkerPositions();
		for (final Entry<Double, Integer> entry : markerPositions.entrySet()) {
			final String label = styleProvider.getTimeLabel(entry.getKey(), TimeUnit.NANOSECONDS);
			final int textWidth = FigureUtilities.getTextWidth(label, graphics.getFont());

			graphics.drawLine(entry.getValue() + bounds.x() + insets.left, bounds.y, entry.getValue() + bounds.x() + insets.left, bounds.y + 5);
			graphics.drawText(label, (entry.getValue() + bounds.x() + insets.left) - (textWidth / 2), bounds.y + 5);
		}
	}
 
Example #3
Source File: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void updateInfomation(String label)
{
	if (infoLabel == null)
	{
		return;
	}
	infoLabel.setText( label );
	Dimension size = FigureUtilities.getTextExtents(  label, infoLabel.getFont( ) );
	//Insets insets = getInfomationLabel( ).getInsets( );
	Insets insets = INSETS;
	Dimension newSize  = size.getCopy( ).expand( insets.getWidth( ), insets.getHeight( ) ) ;
	if (size.width > maxWidth)
	{
		maxWidth = size.width;
	}
	else
	{
		newSize = new Dimension(maxWidth, size.height).expand( insets.getWidth( ), insets.getHeight( ) );
	}
	infoLabel.setSize( newSize);
	setLabelLocation( );
	adjustLocation(  );
}
 
Example #4
Source File: Legend.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private int drawLegendOrComputeHeight(Graphics graphics, int upperMargin, boolean draw) {
	int hPos = bounds.x + INNER_GAP;
	int vPos = bounds.y + INNER_GAP + upperMargin;
	int i = 0;
	int totalHeight = ICON_WIDTH + INNER_GAP;
	for (Trace trace : traceList) {
		if (!trace.isVisible())
			continue;
		int hwidth = OUT_GAP + ICON_WIDTH + INNER_GAP
				+ +FigureUtilities.getTextExtents(trace.getName(), font==null?super.getFont():font).width;
		int hEnd = hPos + hwidth;
		if (hEnd > (bounds.x + bounds.width) && i > 0) {
			hPos = bounds.x + INNER_GAP;
			vPos += ICON_WIDTH + INNER_GAP;
			totalHeight += ICON_WIDTH + INNER_GAP;
			hEnd = hPos + hwidth;
		}

		if (draw) {
			drawTraceLegend(trace, graphics, hPos, vPos);
		}
		hPos = hEnd;
		i++;
	}
	return totalHeight;
}
 
Example #5
Source File: Axis.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Dimension getPreferredSize(final int wHint, final int hHint) {
	final Dimension d = super.getPreferredSize(wHint, hHint);
	if (isVisible()) {
		if (title != null) {
			if (isHorizontal())
				d.height += FigureUtilities.getTextExtents(title, titleFont).height;
			else
				d.width += FigureUtilities.getTextExtents(title, titleFont).height;
		}
	} else { // Not visible, flatten it to use zero height resp. width
		if (isHorizontal())
			d.height = 0;
		else
			d.width = 0;
	}
	return d;
}
 
Example #6
Source File: LinearScaleTicks.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gets max length of tick label.
 */
private void updateTickLabelMaxLengthAndHeight() {
	int maxLength = 0;
	int maxHeight = 0;
	for (int i = 0; i < tickLabels.size(); i++) {
		if (tickLabelVisibilities.size() > i && tickLabelVisibilities.get(i)) {
			Dimension p = FigureUtilities.getTextExtents(tickLabels.get(i), scale.getFont());
			if (tickLabels.get(0).startsWith(MINUS) && !tickLabels.get(i).startsWith(MINUS)) {
				p.width += FigureUtilities.getTextExtents(MINUS, scale.getFont()).width;
			}
			if (p.width > maxLength) {
				maxLength = p.width;
			}
			if (p.height > maxHeight) {
				maxHeight = p.height;
			}
		}
	}
	tickLabelMaxLength = maxLength;
	tickLabelMaxHeight = maxHeight;
}
 
Example #7
Source File: LinearScaleTicks.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * If it has enough space to draw the tick label
 */
private boolean hasSpaceToDraw(int previousPosition, int tickLabelPosition, String previousTickLabel,
		String tickLabel) {
	Dimension tickLabelSize = FigureUtilities.getTextExtents(tickLabel, scale.getFont());
	Dimension previousTickLabelSize = FigureUtilities.getTextExtents(previousTickLabel, scale.getFont());
	int interval = tickLabelPosition - previousPosition;
	int textLength = (int) (scale.isHorizontal() ? (tickLabelSize.width / 2.0 + previousTickLabelSize.width / 2.0)
			: tickLabelSize.height);
	boolean noLapOnPrevoius = true;

	boolean noLapOnEnd = true;
	// if it is not the end tick label
	if (tickLabelPosition != tickLabelPositions.get(tickLabelPositions.size() - 1)) {
		noLapOnPrevoius = interval > (textLength + TICK_LABEL_GAP);
		Dimension endTickLabelSize = FigureUtilities.getTextExtents(tickLabels.get(tickLabels.size() - 1),
				scale.getFont());
		interval = tickLabelPositions.get(tickLabelPositions.size() - 1) - tickLabelPosition;
		textLength = (int) (scale.isHorizontal() ? (tickLabelSize.width / 2.0 + endTickLabelSize.width / 2.0)
				: tickLabelSize.height);
		noLapOnEnd = interval > textLength + TICK_LABEL_GAP;
	}
	return noLapOnPrevoius && noLapOnEnd;
}
 
Example #8
Source File: TextFlow.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void paintSpecial_old( Graphics g, String text, int x, int y,
		boolean firstBox )
{
	if ( firstBox
			&& specialPREFIX.length( ) != 0
			&& text.indexOf( specialPREFIX ) == 0 )
	{
		int with = FigureUtilities.getTextWidth( specialPREFIX, g.getFont( ) );
		Color c = g.getForegroundColor( );

		g.setForegroundColor( ReportColorConstants.textFillColor );

		g.drawString( specialPREFIX, x, y );

		g.setForegroundColor( c );
		g.drawString( text.substring( specialPREFIX.length( ) ),
				x + with,
				y );
	}
	else
	{
		g.drawString( text, x, y );
	}
}
 
Example #9
Source File: LinearScaledMarker.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Dimension getPreferredSize(int wHint, int hHint) {
	updateTick();
	Dimension size = new Dimension(wHint, hHint);

	if (scale.isHorizontal()) {
		size.width = scale.getSize().width;
		size.height = FigureUtilities.getTextExtents("dummy", getFont()).height + GAP_BTW_MARK_LABEL + TICK_LENGTH;
	} else {
		updateTickLabelMaxLength();
		size.width = (int) tickLabelMaxLength + GAP_BTW_MARK_LABEL + TICK_LENGTH;
		size.height = scale.getSize().height;
	}
	return size;

}
 
Example #10
Source File: LinearScaledMarker.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * updates marker elements of ticks
 */
public void updateMarkerElements() {
	labels = new String[markersMap.size()];
	markerColorsList.clear();
	markerValues = new double[markersMap.size()];
	markerLabelDimensions = new Dimension[markersMap.size()];
	markerPositions = new int[markerValues.length];
	int i = 0;
	for (String label : markersMap.keySet()) {
		labels[i] = label;
		markerValues[i] = markersMap.get(label).value;
		markerPositions[i] = scale.getValuePosition(markerValues[i], true);
		markerLabelDimensions[i] = FigureUtilities.getTextExtents(label, getFont());
		markerColorsList.add(XYGraphMediaFactory.getInstance().getColor(markersMap.get(label).color));
		i++;
	}
}
 
Example #11
Source File: ShowDragInfomationProcessor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void updateInfomation(String label, Point p)
{
	if (labelFigure == null)
	{
		return;
	}
	labelFigure.setText( label );
	Dimension size = FigureUtilities.getTextExtents(  label, labelFigure.getFont( ) );
	//Insets insets = getInfomationLabel( ).getInsets( );
	Insets insets = INSETS;
	Dimension newSize  = size.getCopy( ).expand( insets.getWidth( ), insets.getHeight( ) ) ;
	if (size.width > maxWidth)
	{
		maxWidth = size.width;
	}
	else
	{
		newSize = new Dimension(maxWidth, size.height).expand( insets.getWidth( ), insets.getHeight( ) );
	}
	labelFigure.setSize( newSize);
	setLabelLocation( p );
	adjustLocation( p );
}
 
Example #12
Source File: LinearScaleTickLabels.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Draw the Y tick. To be overridden if needed.
 *
 * @param graphics
 *            the graphics context
 */
protected void drawYTick(Graphics graphics) {
	// draw tick labels
	graphics.setFont(scale.getFont());
	int fontHeight = ticks.getMaxHeight();
	for (int i = 0; i < ticks.getPositions().size(); i++) {
		if (ticks.getLabels().isEmpty()) {
			break;
		}

		if (ticks.isVisible(i)) {
			String label = ticks.getLabel(i);
			int x = 0;
			if (ticks.getLabel(0).startsWith(MINUS) && !label.startsWith(MINUS)) {
				x += FigureUtilities.getTextExtents(MINUS, getFont()).width;
			}
			int y = (int) Math.ceil(scale.getLength() - ticks.getPosition(i) - fontHeight / 2.0);
			graphics.drawText(label, x, y);
		}
	}
}
 
Example #13
Source File: ProcessEditPartFactory.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
public void relocate(CellEditor celleditor) {
	Text text = (Text) celleditor.getControl();
	Rectangle rect = getWrapLabel().getTextBounds().getCopy();
	getWrapLabel().translateToAbsolute(rect);
	if (!text.getFont().isDisposed()) {
		if (getWrapLabel().isTextWrapOn() && getWrapLabel().getText().length() > 0) {
			//Adjust editor location
			rect.x = rect.x - 5;
			if (rect.width < 75) {
				rect.width = 75;
			}
			rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
		} else {
			int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
			rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
		}
	}
	if (!rect.equals(new Rectangle(text.getBounds()))) {
		text.setBounds(rect.x, rect.y, rect.width, rect.height);
	}
}
 
Example #14
Source File: ScaledSliderFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void setLabel() {
	String text = getValueText();
	Dimension textSize = FigureUtilities.getStringExtents(text, label.getFont());
	label.setText(text);
	if(horizontal)
		label.setBounds(new Rectangle(
			thumb.getBounds().x + thumb.getBounds().width/2 
			- (textSize.width + 2*LABEL_MARGIN)/2,
			thumb.getBounds().y  - textSize.height - 2*LABEL_MARGIN,
			textSize.width + 2 * LABEL_MARGIN, textSize.height+LABEL_MARGIN));
	else
		label.setBounds(new Rectangle(
				thumb.getBounds().x - textSize.width - 3*LABEL_MARGIN,
				thumb.getBounds().y + thumb.getBounds().height/2 
			- (textSize.height + LABEL_MARGIN)/2, 
			textSize.width + 2 * LABEL_MARGIN, textSize.height+LABEL_MARGIN));
}
 
Example #15
Source File: RoundScaleTickLabels.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Updates the the draw area of each label.
 */
private void updateTickLabelAreas() {
	int  labelRadius;
	tickLabelAreas.clear();
	for(int i=0; i<tickLabelPositions.size(); i++) {
		Dimension ls = FigureUtilities.getTextExtents(tickLabels.get(i), scale.getFont());
		if(scale.getTickLabelSide() == LabelSide.Primary)	
			labelRadius = (int) (scale.getRadius() + 
					RoundScaleTickMarks.MAJOR_TICK_LENGTH + RoundScale.SPACE_BTW_MARK_LABEL +
						ls.width/2.0 * Math.abs(Math.cos(tickLabelPositions.get(i))) + 
						ls.height/2.0 * Math.abs(Math.sin(tickLabelPositions.get(i))));
		else 		
			labelRadius = (int) (scale.getRadius() - 
					RoundScaleTickMarks.MAJOR_TICK_LENGTH - RoundScale.SPACE_BTW_MARK_LABEL -
						ls.width/2.0 * Math.abs(Math.cos(tickLabelPositions.get(i))) - 
						ls.height/2.0 * Math.abs(Math.sin(tickLabelPositions.get(i))));
	
		Point lp = new PolarPoint(labelRadius, tickLabelPositions.get(i)).toRelativePoint(
				scale.getBounds());
		tickLabelAreas.add(new Rectangle(lp.x - ls.width/2, lp.y - ls.height/2, 
				ls.width, ls.height));   		
	}	
}
 
Example #16
Source File: TableViewGraphicalNodeEditPolicy.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
@Override
public void showTargetFeedback(Request request) {
	ERDiagram diagram = ERModelUtil.getDiagram(this.getHost().getRoot().getContents());

	if (diagram.isTooltip()) {
		ZoomManager zoomManager = ((ScalableFreeformRootEditPart) this
				.getHost().getRoot()).getZoomManager();
		double zoom = zoomManager.getZoom();

		TableView tableView = (TableView) this.getHost().getModel();
		Rectangle tableBounds = this.getHostFigure().getBounds();

		String name = TableViewEditPart.getTableViewName(tableView, diagram);

		Label label = new Label();
		label.setText(name);
		label.setBorder(new SimpleRaisedBorder());
		label.setBackgroundColor(ColorConstants.orange);
		label.setOpaque(true);

		Dimension dim = FigureUtilities.getTextExtents(name, Display
				.getCurrent().getSystemFont());

		label.setBounds(new Rectangle((int) (zoom * (tableBounds.x + 33)),
				(int) (zoom * (tableBounds.y + 5)),
				(int) (dim.width * 1.5), 20));

		this.addFeedback(label);
	}
	super.showTargetFeedback(request);
}
 
Example #17
Source File: EditorRulerFigure.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public Dimension getPreferredSize( int wHint, int hHint )
{
	Dimension prefSize = new Dimension( );
	if ( isHorizontal( ) )
	{
		prefSize.height = ( textMargin * 2 ) + BORDER_WIDTH
				+ FigureUtilities.getFontMetrics( getFont( ) ).getAscent( );
	}
	else
	{
		prefSize.width = ( textMargin * 2 ) + BORDER_WIDTH
				+ FigureUtilities.getFontMetrics( getFont( ) ).getAscent( );
	}
	return prefSize;
}
 
Example #18
Source File: ProcessEditPartFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
public void relocate(CellEditor celleditor) {
	Text text = (Text) celleditor.getControl();
	Rectangle rect = getLabel().getTextBounds().getCopy();
	getLabel().translateToAbsolute(rect);
	if (!text.getFont().isDisposed()) {
		int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
		rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
	}
	if (!rect.equals(new Rectangle(text.getBounds()))) {
		text.setBounds(rect.x, rect.y, rect.width, rect.height);
	}
}
 
Example #19
Source File: TableViewGraphicalNodeEditPolicy.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
public void showTargetFeedback(Request request) {
    final ERDiagram diagram = ERModelUtil.getDiagram(getHost().getRoot().getContents());

    if (diagram.isTooltip()) {
        final ZoomManager zoomManager = ((ScalableFreeformRootEditPart) getHost().getRoot()).getZoomManager();
        final double zoom = zoomManager.getZoom();

        final TableView tableView = (TableView) getHost().getModel();
        final Rectangle tableBounds = getHostFigure().getBounds();

        final String name = TableViewEditPart.getTableViewName(tableView, diagram);

        final Label label = new Label();
        label.setText(name);
        label.setBorder(new SimpleRaisedBorder());
        label.setBackgroundColor(ColorConstants.orange);
        label.setOpaque(true);

        final Dimension dim = FigureUtilities.getTextExtents(name, Display.getCurrent().getSystemFont());

        label.setBounds(new Rectangle(
                (int) (zoom * (tableBounds.x + 33)),
                (int) (zoom * (tableBounds.y + 5)),
                (int) (dim.width * 1.5), 20));

        addFeedback(label);
    }
    super.showTargetFeedback(request);
}
 
Example #20
Source File: TableViewGraphicalNodeEditPolicy.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@Override
public void showTargetFeedback(final Request request) {
    final ERDiagram diagram = (ERDiagram) getHost().getRoot().getContents().getModel();

    if (diagram.isTooltip()) {
        final ZoomManager zoomManager = ((ScalableFreeformRootEditPart) getHost().getRoot()).getZoomManager();
        final double zoom = zoomManager.getZoom();

        final TableView tableView = (TableView) getHost().getModel();
        final Rectangle tableBounds = getHostFigure().getBounds();

        final String name = TableViewEditPart.getTableViewName(tableView, diagram);

        final Label label = new Label();
        label.setText(name);
        label.setBorder(new SimpleRaisedBorder());
        label.setBackgroundColor(ColorConstants.orange);
        label.setOpaque(true);

        final Dimension dim = FigureUtilities.getTextExtents(name, Display.getCurrent().getSystemFont());

        label.setBounds(new Rectangle((int) (zoom * (tableBounds.x + 33)), (int) (zoom * (tableBounds.y + 5)), (int) (dim.width * 1.5), 20));

        addFeedback(label);
    }
    super.showTargetFeedback(request);
}
 
Example #21
Source File: GraphicsUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw vertical text.
 * 
 * @param graphics
 *            draw2D graphics.
 * @param text
 *            text to be drawn.
 * @param x
 *            the x coordinate of the text, which is the left upper corner.
 * @param y
 *            the y coordinate of the text, which is the left upper corner.
 */
public static final void drawVerticalText(Graphics graphics, String text, int x, int y, boolean upToDown) {
	try {
		if (SWT.getPlatform().startsWith("rap")) //$NON-NLS-1$
			throw new Exception();
		try {
			graphics.pushState();
			graphics.translate(x, y);
			if (upToDown) {
				graphics.rotate(90);
				graphics.drawText(text, 0, -FigureUtilities.getTextExtents(text, graphics.getFont()).height);
			} else {
				graphics.rotate(270);
				graphics.drawText(text, -FigureUtilities.getTextWidth(text, graphics.getFont()), 0);
			}
		} finally {
			graphics.popState();
		}
	} catch (Exception e) {// If rotate is not supported by the graphics.
		// final Dimension titleSize = FigureUtilities.getTextExtents(text,
		// graphics.getFont());

		// final int w = titleSize.height;
		// final int h = titleSize.width + 1;
		Image image = null;
		try {
			image = SingleSourceHelper2.createVerticalTextImage(text, graphics.getFont(),
					graphics.getForegroundColor().getRGB(), upToDown);
			graphics.drawImage(image, x, y);

		} finally {
			if (image != null)
				image.dispose();
		}
	}
}
 
Example #22
Source File: Legend.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Dimension getPreferredSize(int wHint, int hHint) {
	int maxWidth = 0;
	int hEnd = INNER_GAP;
	int height = ICON_WIDTH + INNER_GAP;
	// int i=0;
	for (Trace trace : traceList) {
		if (!trace.isVisible())
			continue;
		hEnd = hEnd + OUT_GAP + ICON_WIDTH + INNER_GAP
				+ +FigureUtilities.getTextExtents(trace.getName(), font==null?super.getFont():font).width;

		if (hEnd > wHint) {
			hEnd = INNER_GAP + OUT_GAP + ICON_WIDTH + INNER_GAP
					+ +FigureUtilities.getTextExtents(trace.getName(), font==null?super.getFont():font).width;
			height += ICON_WIDTH + INNER_GAP;
		}
		if (maxWidth < hEnd)
			maxWidth = hEnd;
	}
	
	if (preferredHeight != -1) {
		height=preferredHeight;
	}
	
	return new Dimension(maxWidth, height);
}
 
Example #23
Source File: LinearScale.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Calculate dimension of a textual form of object
 *
 * @param obj
 *            object
 * @return dimension
 */
@Override
public Dimension getDimension(Object obj) {
	if (obj == null)
		return new Dimension();
	if (obj instanceof String)
		return FigureUtilities.getTextExtents((String) obj, getFont());
	return FigureUtilities.getTextExtents(format(obj), getFont());
}
 
Example #24
Source File: LinearScale.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void calcMargin() {
	if (isHorizontal()) {
		margin = (int) Math
				.ceil(Math.max(FigureUtilities.getTextExtents(format(getRange().getLower(), true), getFont()).width,
						FigureUtilities.getTextExtents(format(getRange().getUpper(), true), getFont()).width)
						/ 2.0);
	} else
		margin = (int) Math.ceil(
				Math.max(FigureUtilities.getTextExtents(format(getRange().getLower(), true), getFont()).height,
						FigureUtilities.getTextExtents(format(getRange().getUpper(), true), getFont()).height)
						/ 2.0);
}
 
Example #25
Source File: LinearScaledMarker.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Gets max length of tick label.
 */
private void updateTickLabelMaxLength() {
	int maxLength = 0;

	for (int i = 0; i < labels.length; i++) {
		Dimension p = FigureUtilities.getTextExtents(labels[i], scale.getFont());
		if (p.width > maxLength) {
			maxLength = p.width;
		}
	}

	tickLabelMaxLength = maxLength;
}
 
Example #26
Source File: LinearScaleTickLabels.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw the X tick. To be overridden if needed.
 *
 * @param graphics
 *            the graphics context
 */
protected void drawXTick(Graphics graphics) {
	// draw tick labels
	graphics.setFont(scale.getFont());
	for (int i = 0; i < ticks.getPositions().size(); i++) {
		if (ticks.isVisible(i) == true) {
			String text = ticks.getLabel(i);
			int fontWidth = FigureUtilities.getTextExtents(text, getFont()).width;
			int x = (int) Math.ceil(ticks.getLabelPosition(i) - fontWidth / 2.0);// +
																					// offset);
			graphics.drawText(text, x, 0);
		}
	}
}
 
Example #27
Source File: ThermometerFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	boolean support3D = false;
	if(effect3D)
		 support3D = GraphicsUtil.testPatternSupported(graphics);
	
	if(effect3D && support3D){
		graphics.setBackgroundColor(fillColor);
		super.fillShape(graphics);
		//int l = (int) ((bounds.width - lineWidth)*0.293/2);
		Pattern backPattern = null;
		
		 backPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
			bounds.x + lineWidth, bounds.y + lineWidth, 
			bounds.x+bounds.width-lineWidth, bounds.y+bounds.height-lineWidth,
			WHITE_COLOR,255, fillColor, 0);			
		graphics.setBackgroundPattern(backPattern);
		super.fillShape(graphics);
		backPattern.dispose();
		
	}else{
		graphics.setBackgroundColor(fillColor);				
		super.fillShape(graphics);
	}				
	
	String valueString = getValueText();
	Dimension valueSize = 
		FigureUtilities.getTextExtents(valueString, getFont());
	if(valueSize.width < bounds.width) {				
		graphics.setForegroundColor(contrastFillColor);
		graphics.drawText(valueString, new Point(
				bounds.x + bounds.width/2 - valueSize.width/2,
				bounds.y + bounds.height/2 - valueSize.height/2));				
	}			
}
 
Example #28
Source File: SimpleSnapFeedbackPolicy.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
private Color createMixedColor() {
	return FigureUtilities.mixColors(getLocalBackgroundColor(), getParent().getBackgroundColor(),
			(double) opacity / FRAMES);
}
 
Example #29
Source File: Legend.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void drawTraceLegend(Trace trace, Graphics graphics, int hPos, int vPos) {
	graphics.pushState();
	if (Preferences.useAdvancedGraphics())
		graphics.setAntialias(SWT.ON);
	graphics.setForegroundColor(trace.getTraceColor());

	// limit size of symbol to ICON_WIDTH - INNER_GAP
	int maxSize = ((trace.getPointSize() > Math.floor((ICON_WIDTH - OUT_GAP) / 2))
			? (int) Math.floor((ICON_WIDTH - OUT_GAP))
			: trace.getPointSize());

	// draw symbol
	switch (trace.getTraceType()) {
	case BAR:
		trace.drawLine(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2 ),
				new Point(hPos + ICON_WIDTH / 2, vPos + ICON_WIDTH));
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2));
		break;
	case LINE_AREA:
		graphics.drawPolyline(new int[] { hPos, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH / 2, vPos + maxSize / 2,
				hPos + ICON_WIDTH - 1, vPos + ICON_WIDTH / 2, });
	case AREA:
		graphics.setBackgroundColor(trace.getTraceColor());
		if (Preferences.useAdvancedGraphics())
			graphics.setAlpha(trace.getAreaAlpha());
		graphics.fillPolygon(new int[] { hPos, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH / 2, vPos + maxSize / 2,
				hPos + ICON_WIDTH, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH, vPos + ICON_WIDTH, hPos,
				vPos + ICON_WIDTH });
		if (Preferences.useAdvancedGraphics())
			graphics.setAlpha(255);
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2));
		break;
	default:
		trace.drawLine(graphics, new Point(hPos, vPos + ICON_WIDTH / 2),
				new Point(hPos + ICON_WIDTH, vPos + ICON_WIDTH / 2));
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + ICON_WIDTH / 2));
		break;
	}

	// draw text
	Font previousFont = super.getFont();
	if (font != null) {
		graphics.setFont(font);
	}
	
	graphics.drawText(trace.getName(), hPos + ICON_WIDTH + INNER_GAP,
			vPos + ICON_WIDTH / 2 - FigureUtilities.getTextExtents(trace.getName(), getFont()).height / 2);
	
	graphics.setFont(previousFont);
	graphics.popState();
}
 
Example #30
Source File: Axis.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void paintClientArea(final Graphics graphics) {
	// Don't do anything when hidden
	if (!isVisible())
		return;

	super.paintClientArea(graphics);

	// graphics.pushState();
	if (title != null) {
		graphics.setFont(titleFont);
		final Dimension titleSize = FigureUtilities.getTextExtents(title, titleFont);
		if (isHorizontal()) {
			if (getTickLabelSide() == LabelSide.Primary)
				graphics.drawText(title, bounds.x + bounds.width / 2 - titleSize.width / 2,
						bounds.y + bounds.height - titleSize.height);
			else
				graphics.drawText(title, bounds.x + bounds.width / 2 - titleSize.width / 2, bounds.y);
		} else {
			final int w = titleSize.height;
			final int h = titleSize.width + 1;

			if (getTickLabelSide() == LabelSide.Primary) {
				GraphicsUtil.drawVerticalText(graphics, title, bounds.x, bounds.y + bounds.height / 2 - h / 2,
						false);
			} else {
				GraphicsUtil.drawVerticalText(graphics, title, bounds.x + bounds.width - w,
						bounds.y + bounds.height / 2 - h / 2, true);
			}
		}
	}
	// graphics.popState();

	// Show the start/end cursor or the 'rubberband' of a zoom operation?
	if (armed && end != null && start != null) {
		switch (zoomType) {
		case RUBBERBAND_ZOOM:
		case HORIZONTAL_ZOOM:
		case VERTICAL_ZOOM:
		case DYNAMIC_ZOOM:
			graphics.setLineStyle(SWTConstants.LINE_DOT);
			graphics.setLineWidth(1);
			graphics.setForegroundColor(revertBackColor);
			graphics.drawRectangle(start.x, start.y, end.x - start.x - 1, end.y - start.y - 1);
			break;

		default:
			break;
		}
	}
}