blob: fa146ba8af17148fc3b52c21d679f8a38c4bf870 (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/*****************************************************************************
* Copyright (c) 2009 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
*
* Contributors:
* Fadoi LAKHAL Fadoi.Lakhal@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.diagram.clazz.custom.figure;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
/** Use to create a containment circle figure */
public class ContainmentFigure extends Ellipse {
/**
* Fills the circle.
*
* @param graphics
* the graphics
*
* @see org.eclipse.draw2d.Shape#fillShape(org.eclipse.draw2d.Graphics)
*/
protected void fillShape(Graphics graphics) {
graphics.pushState();
graphics.setBackgroundColor(ColorConstants.white);
graphics.fillOval(getBounds());
graphics.popState();
Dimension dim = new Dimension(20, 20);
this.setMaximumSize(dim);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.draw2d.Shape#paintFigure(org.eclipse.draw2d.Graphics)
*/
public void paintFigure(Graphics graphics) {
graphics.setAntialias(SWT.LOW);
super.paintFigure(graphics);
graphics.pushState();
graphics.setBackgroundColor(ColorConstants.black);
/* Creates the cross in the circle */
Rectangle rect1 = getBounds().getCopy();
int scaleFactor_horizontale = rect1.height / 2;
int scaleFactor_verticale = rect1.width / 2;
Rectangle rect = getBounds().getCopy();
graphics.drawLine(rect1.x, rect1.y + scaleFactor_horizontale, rect1.x + (int)Math.floor(rect1.width * (scaleFactor_horizontale)), rect1.y - (1 - scaleFactor_horizontale));
graphics.drawLine(rect1.x + scaleFactor_verticale, rect1.y, rect1.x - (1 - scaleFactor_verticale), rect1.y + (int)Math.floor(rect1.height * (scaleFactor_verticale)));
graphics.popState();
}
}
|