Commit 38d6c087 authored by Simon Barner's avatar Simon Barner
Browse files

Add support to render one character label within the circle representing the...

Add support to render one character label within the circle representing the connector. It can be used to distinguish different connector types.
refs 2562,3035
parent e27c38fe
ConnectionEditPartBase.java 53a128af53e251a89a44eda4b85c89ff6c8db5a1 GREEN
ConnectorEditPartBase.java 1e7bf37dff30ee099eadbcfc0193b847aa7d16e3 GREEN
ConnectorEditPartBase.java bc811ad8d69ec19816599755bfa825422a1dc487 YELLOW
DiagramEditPartBase.java 7a5305c8dc86f29e05873b28284244328b3e5a20 GREEN
ElementEditPartBase.java c2a8f7ca01360eb7866adb34a162d696665ec5f8 GREEN
ExtendedLayerRootEditPart.java 1b8206ef963b5b174a02656a5bfc84a2953fe650 GREEN
......
......@@ -38,7 +38,11 @@ import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
......@@ -63,6 +67,25 @@ public abstract class ConnectorEditPartBase<T extends ILayoutedModelElement & IC
super(modelElement);
}
/** {@link Font} to be used to render the label returned by {@link #getFigureLabel()}. */
private static Font FIGURE_LABEL_FONT = createFigureLabelFont();
/** Helper method to create the font for label returned by {@link #getFigureLabel()}. */
private static Font createFigureLabelFont() {
final Font defaultFont = JFaceResources.getDefaultFont();
// There is at least one FontData
final String fontName = defaultFont.getFontData()[0].getName();
return new Font(Display.getCurrent(), fontName, DEFAULT_CONNECTOR_SIZE / 4, SWT.NORMAL);
}
/**
* Returns the optional one {@link Character} label to be rendered within the circle
* representing the connector.
*/
protected Character getFigureLabel() {
return null;
}
/** {@inheritDoc} */
@Override
protected IFigure createBaseFigure() {
......@@ -81,6 +104,19 @@ public abstract class ConnectorEditPartBase<T extends ILayoutedModelElement & IC
int oneFourth = DEFAULT_CONNECTOR_SIZE / 4;
int half = DEFAULT_CONNECTOR_SIZE / 2;
base.add(connector, new Rectangle(oneFourth, oneFourth, half, half));
if(getFigureLabel() != null) {
final Label label = new Label(getFigureLabel().toString());
if(isTarget()) {
label.setForegroundColor(getTargetForegroundColor());
} else {
label.setForegroundColor(getTargetBackgroundColor());
}
label.setFont(FIGURE_LABEL_FONT);
base.add(label, new Rectangle(0, 0, DEFAULT_CONNECTOR_SIZE, DEFAULT_CONNECTOR_SIZE));
}
return base;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment