From 38d6c087ce45b495d94e0fc1f947b3eb7011e285 Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Tue, 23 Jan 2018 09:31:33 +0000 Subject: [PATCH] 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 --- .../fortiss/tooling/base/ui/editpart/.ratings | 3 +- .../ui/editpart/ConnectorEditPartBase.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/.ratings b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/.ratings index 2cf983ec6..b55c3a0e2 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/.ratings +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/.ratings @@ -1,6 +1,5 @@ - ConnectionEditPartBase.java 53a128af53e251a89a44eda4b85c89ff6c8db5a1 GREEN -ConnectorEditPartBase.java 1e7bf37dff30ee099eadbcfc0193b847aa7d16e3 GREEN +ConnectorEditPartBase.java bc811ad8d69ec19816599755bfa825422a1dc487 YELLOW DiagramEditPartBase.java 7a5305c8dc86f29e05873b28284244328b3e5a20 GREEN ElementEditPartBase.java c2a8f7ca01360eb7866adb34a162d696665ec5f8 GREEN ExtendedLayerRootEditPart.java 1b8206ef963b5b174a02656a5bfc84a2953fe650 GREEN diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectorEditPartBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectorEditPartBase.java index 9d869412a..2d6ceaf93 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectorEditPartBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectorEditPartBase.java @@ -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; } -- GitLab