Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8bd8febf7b2301160c6b3fecf202941af34e3898 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
 * Copyright (c) 2012 CEA LIST.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.papyrus.uml.diagram.timing.custom.figures;

import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.RotatableDecoration;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

public class EllipseDecoration extends Ellipse implements RotatableDecoration {

	public EllipseDecoration() {
		setPreferredSize(new Dimension(5, 5));
	}

	@Override
	public void setLocation(final Point p) {
		final Dimension delta = getPreferredSize().getScaled(0.5).getNegated();
		super.setLocation(p.getTranslated(delta));
	}

	public void setReferencePoint(final Point p) {
		// nothing
	}

	@Override
	protected void fillShape(final Graphics graphics) {
		final Color oldBack = graphics.getBackgroundColor();
		graphics.setBackgroundColor(graphics.getForegroundColor());
		graphics.fillOval(getOptimizedBounds());
		graphics.setBackgroundColor(oldBack);
	}

	private Rectangle getOptimizedBounds() {
		final float lineInset = Math.max(1.0f, getLineWidthFloat()) / 2.0f;
		final int inset = (int)Math.floor(lineInset);
		final Rectangle r = Rectangle.SINGLETON.setBounds(getBounds());
		r.x += inset;
		r.y += inset;
		return r;
	}

	@Override
	protected void outlineShape(final Graphics graphics) {
		// no outline
	}
}

Back to the top