blob: 7a271bf1e09a94215ed1983e998cddd4e41b6b88 (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
package org.eclipse.papyrus.diagram.common.figure.node;
import java.util.List;
import org.eclipse.draw2d.AbstractLayout;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.papyrus.diagram.common.Activator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
public class DiagramNodeFigure extends RectangleFigure {
/**
* @deprecated use org.eclipse.papyrus.diagram.common.figure.layout.
* PropertiesCompartmentLayoutManager instead
*/
private class PropertiesCompatmentLayoutManager extends AbstractLayout {
/**
*
* {@inheritDoc}
*/
@Override
protected Dimension calculatePreferredSize(IFigure container, int hint, int hint2) {
int minimumWith = 0;
int minimumHeight = 0;
// display name
for(int i = 0; i < container.getChildren().size(); i++) {
minimumHeight = minimumHeight + ((IFigure)container.getChildren().get(i)).getPreferredSize().height;
}
return new Dimension(minimumWith, minimumHeight);
}
/**
*
* {@inheritDoc}
*/
public void layout(IFigure container) {
List childrenList = container.getChildren();
for(int i = 0; i < container.getChildren().size(); i++) {
Rectangle bound = new Rectangle(((IFigure)childrenList.get(i)).getBounds());
bound.setSize(((IFigure)childrenList.get(i)).getPreferredSize());
if(i > 0) {
bound.y = ((IFigure)childrenList.get(i - 1)).getBounds().getBottomLeft().y - 1;
bound.x = getBounds().x;
bound.width = container.getBounds().width;
} else {
bound.x = container.getBounds().x + 2;
bound.y = container.getBounds().y + 2;
bound.width = container.getBounds().width;
}
((IFigure)childrenList.get(i)).setBounds(bound);
}
}
}
protected WrappingLabel iconLabel;
public DiagramNodeFigure() {
super();
FontData[] fontdata2 = { new FontData("Arial", 10, SWT.BOLD) };
Font font2 = Activator.getFontManager().get(fontdata2);
this.iconLabel = new WrappingLabel("");
this.iconLabel.setForegroundColor(ColorConstants.red);
this.iconLabel.setBackgroundColor(ColorConstants.red);
this.iconLabel.setFont(font2);
this.iconLabel.setOpaque(false);
this.add(this.iconLabel);
ToolbarLayout toolbarLayout = new ToolbarLayout();
toolbarLayout.setSpacing(5);
toolbarLayout.setVertical(false);
this.setLayoutManager(new PropertiesCompatmentLayoutManager());
}
public WrappingLabel getIconContainer() {
return iconLabel;
}
public void setIcon(Image image) {
Image initialImage = image;
ImageDescriptor visDesc = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.diagram.common", "/icons/obj16/call.gif");
// Overlay custom image over base image
// OverlayVisibilityIcon overlayIcon = new
// OverlayVisibilityIcon(initialImage, visDesc);
// image = overlayIcon.getImage();
getIconContainer().setIcon(image, 0);
getIconContainer().setIcon(visDesc.createImage(), 1);
}
}
|