Skip to content
Snippets Groups Projects
Commit f5f46474 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

fixed port edit part display

refactored default layout constants for connectors
parent 398e2513
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,6 @@ Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.editor.gef,
org.fortiss.tooling.base.ui.editpart,
org.fortiss.tooling.base.ui.editpart.anchor,
org.fortiss.tooling.base.ui.editpart.connector,
org.fortiss.tooling.base.ui.editpart.figure,
org.fortiss.tooling.base.ui.editpart.policy,
org.fortiss.tooling.base.ui.layout,
......
......@@ -15,7 +15,7 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editpart.connector;
package org.fortiss.tooling.base.ui.editpart;
import java.util.ArrayList;
import java.util.List;
......@@ -25,17 +25,18 @@ import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPolicy;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.ConnectorEditPartBase;
import org.fortiss.tooling.base.ui.editpart.figure.AntiAliasedEllipse;
import org.fortiss.tooling.base.ui.editpart.figure.LabeledConnectorFigure;
import org.fortiss.tooling.base.ui.editpart.policy.ConnectionGraphicalNodeEditPolicy;
import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy;
import org.fortiss.tooling.base.ui.layout.constants.RecommendedLayoutConstants;
......@@ -48,46 +49,37 @@ import org.fortiss.tooling.base.ui.layout.constants.RecommendedLayoutConstants;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class RectangularConnectorEditPartBase<T extends IConnector & ILayoutedModelElement>
public abstract class LabeledConnectorEditPartBase<T extends IConnector & ILayoutedModelElement>
extends ConnectorEditPartBase<T> {
/** The label used for the port. */
protected final Label label = new Label();
/** The figure used for the port itself. */
private IFigure connectorFigure;
private LabeledConnectorFigure connectorFigure;
/** Creates the edit part. */
public RectangularConnectorEditPartBase(T connector) {
public LabeledConnectorEditPartBase(T connector) {
super(connector);
}
/** {@inheritDoc} */
@Override
protected IFigure createFigure() {
connectorFigure = getConnectorFigure();
Figure composite = new Figure();
composite
.setSize(RecommendedLayoutConstants.RECTANGULAR_CONNECTOR_DIMENSION);
// TODO (BH): Clean this up....
// composite.setLayoutManager(new PortLabelLayoutManager());
// composite.add(connectorFigure, PortLabelLayoutManager.PORT);
// composite.add(label, PortLabelLayoutManager.LABEL);
return composite;
return getConnectorFigure();
}
/** Returns the figure used for the connector. */
protected IFigure getConnectorFigure() {
/** Returns the figure used for the connector (including the label). */
protected LabeledConnectorFigure getConnectorFigure() {
if (connectorFigure == null) {
connectorFigure = createConnectorFigure();
connectorFigure = new LabeledConnectorFigure(
createConnectorFigure(), label, getConnectorDimension(),
getConnectorFigureBounds());
}
return connectorFigure;
}
/** Creates the figure used for the connector. */
/** Creates the figure used for the connector (excluding the label). */
protected IFigure createConnectorFigure() {
Ellipse connector = new AntiAliasedEllipse();
......@@ -104,7 +96,7 @@ public abstract class RectangularConnectorEditPartBase<T extends IConnector & IL
/** {@inheritDoc} */
@Override
protected ConnectionAnchor defaultConnectionAnchor() {
return new ChopboxAnchor(getConnectorFigure());
return new ChopboxAnchor(connectorFigure.getBaseFigure());
}
/** {@inheritDoc} */
......@@ -142,7 +134,24 @@ public abstract class RectangularConnectorEditPartBase<T extends IConnector & IL
*/
protected abstract boolean isReceiving();
/** {@inheritDoc} */
/**
* Returns the dimension of the connector edit part (not only its visible
* figure part).
*/
protected Dimension getConnectorDimension() {
return RecommendedLayoutConstants.DEFAULT_CONNECTOR_DIMENSION;
}
/**
* Returns the bounds of the visible figure of the connector edit part.
*/
protected Rectangle getConnectorFigureBounds() {
return RecommendedLayoutConstants.DEFAULT_CONNECTOR_FIGURE_BOUNDS;
}
/**
* {@inheritDoc}
*/
@Override
protected List<IConnection> getModelSourceConnections() {
if (!isReceiving()) {
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editpart.figure;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LayoutManager;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
/**
* This class implements dynamic behavior of a labeled connector figure, which
* displays the label if the figure has no connections.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class LabeledConnectorFigure extends Figure {
/** Stores the base figure. */
private final IFigure baseFigure;
/** Stores the label figure. */
private final Label label;
/** Stores the default connector figure bounds. */
private final Rectangle connectorFigureBounds;
/** Stores the default dimension of the connector. */
private final Dimension connectorDimension;
/** Constructor. */
public LabeledConnectorFigure(IFigure baseFigure, Label label,
Dimension connectorDimension, Rectangle connectorFigureBounds) {
this.baseFigure = baseFigure;
this.label = label;
this.connectorDimension = connectorDimension;
this.connectorFigureBounds = connectorFigureBounds;
setSize(connectorDimension);
setLayoutManager(new TheLayoutManager());
add(baseFigure);
add(label);
}
/** Returns the underlying base figure. */
public IFigure getBaseFigure() {
return baseFigure;
}
/** A layout manager used for the label layouting. */
private class TheLayoutManager implements LayoutManager {
/** {@inheritDoc} */
@Override
public Object getConstraint(IFigure child) {
return null;
}
/** {@inheritDoc} */
@Override
public Dimension getMinimumSize(IFigure container, int wHint, int hHint) {
return container.getMinimumSize();
}
/** {@inheritDoc} */
@Override
public Dimension getPreferredSize(IFigure container, int wHint,
int hHint) {
return container.getPreferredSize();
}
/** {@inheritDoc} */
@Override
public void layout(IFigure container) {
Rectangle containerBounds = new Rectangle(container.getBounds());
// compute base bounds
Rectangle baseBounds = new Rectangle(connectorFigureBounds);
baseBounds.x += containerBounds.x;
baseBounds.y += containerBounds.y;
baseFigure.setBounds(baseBounds);
// compute label size
Rectangle labelTextBounds = label.getTextBounds();
Rectangle newBounds = new Rectangle(containerBounds);
newBounds.x += connectorDimension.width;
newBounds.y += (connectorDimension.height - labelTextBounds.height) / 2;
// +1 needed for proper display
newBounds.width += 1 + labelTextBounds.width;
newBounds.height = labelTextBounds.height;
label.setBounds(newBounds);
// compute container bounds
// +1 needed for proper display
containerBounds.width = labelTextBounds.width
+ connectorDimension.width + 1;
containerBounds.height = connectorDimension.height;
container.setBounds(containerBounds);
}
/** {@inheritDoc} */
@Override
public void remove(IFigure child) {
// nothing to do
}
/** {@inheritDoc} */
@Override
public void invalidate() {
// nothing to do
}
/** {@inheritDoc} */
@Override
public void setConstraint(IFigure child, Object constraint) {
// nothing to do
}
}
}
......@@ -40,7 +40,6 @@ public final class RecommendedLayoutConstants {
JFaceResources.getDefaultFont(), 0, SWT.BOLD);
// editor grid constants
/** The offset of the grid. */
public static final Point GRID_ORIGIN = new Point(0, 0);
......@@ -48,14 +47,6 @@ public final class RecommendedLayoutConstants {
public static final int GRID_SIZE = 12;
// oval shapes constants
/** The size of oval connectors. */
public static final int OVAL_CONNECTOR_SIZE = GRID_SIZE * 2;
/** Dimension used for oval connectors. */
public static final Dimension OVAL_CONNECTOR_DIMENSION = new Dimension(
OVAL_CONNECTOR_SIZE, OVAL_CONNECTOR_SIZE);
/** The minimal height of an oval shape. */
public static final int OVAL_SHAPE_MINIMUM_HEIGHT = GRID_SIZE * 6;
......@@ -66,6 +57,8 @@ public final class RecommendedLayoutConstants {
public static final int OVAL_SHAPE_MINIMUM_WIDTH = (int) (OVAL_SHAPE_MINIMUM_HEIGHT * OVAL_SHAPE_ASPECT_RATIO);
// rectangular shapes constants
/** The size of the insets of a rectangular shape. */
public static final int RECTANGULAR_SHAPE_INSETS = GRID_SIZE;
/** The minimum width of a rectangular shape. */
public static final int RECTANGULAR_SHAPE_MINIMUM_WIDTH = 9 * GRID_SIZE;
......@@ -73,18 +66,16 @@ public final class RecommendedLayoutConstants {
/** The minimum height of a rectangular shape. */
public static final int RECTANGULAR_SHAPE_MINIMUM_HEIGHT = 6 * GRID_SIZE;
/** The size of the insets of a rectangular shape. */
public static final int RECTANGULAR_SHAPE_INSETS = GRID_SIZE;
// connector default constants
/** The size of a rectangular connector. */
public static final int RECTANGULAR_CONNECTOR_SIZE = 2 * GRID_SIZE;
public static final int DEFAULT_CONNECTOR_SIZE = 2 * GRID_SIZE;
/** Dimension used for rectangular connector. */
public static final Dimension RECTANGULAR_CONNECTOR_DIMENSION = new Dimension(
RECTANGULAR_CONNECTOR_SIZE, RECTANGULAR_CONNECTOR_SIZE);
public static final Dimension DEFAULT_CONNECTOR_DIMENSION = new Dimension(
DEFAULT_CONNECTOR_SIZE, DEFAULT_CONNECTOR_SIZE);
/** The bounds used for the main figure of the rectangular connector. */
public static final Rectangle RECTANGULAR_CONNECTOR_FIGURE_BOUNDS = new Rectangle(
RECTANGULAR_CONNECTOR_SIZE / 4, RECTANGULAR_CONNECTOR_SIZE / 4,
RECTANGULAR_CONNECTOR_SIZE / 2, RECTANGULAR_CONNECTOR_SIZE / 2);
public static final Rectangle DEFAULT_CONNECTOR_FIGURE_BOUNDS = new Rectangle(
DEFAULT_CONNECTOR_SIZE / 4, DEFAULT_CONNECTOR_SIZE / 4,
DEFAULT_CONNECTOR_SIZE / 2, DEFAULT_CONNECTOR_SIZE / 2);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment