diff --git a/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF index 339fec8410e14439feaf712988d6cf383bdfe534..94f2d8e1b4f4e3eb36942eeb499b4812a7b7e725 100644 --- a/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF @@ -10,11 +10,14 @@ Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: fortiss Export-Package: org.fortiss.tooling.kernel.base.ui, + org.fortiss.tooling.kernel.base.ui.action, org.fortiss.tooling.kernel.base.ui.command, org.fortiss.tooling.kernel.base.ui.dnd, org.fortiss.tooling.kernel.base.ui.editor, + org.fortiss.tooling.kernel.base.ui.editor.gef, org.fortiss.tooling.kernel.base.ui.editpart, org.fortiss.tooling.kernel.base.ui.editpart.anchor, + org.fortiss.tooling.kernel.base.ui.editpart.figure, org.fortiss.tooling.kernel.base.ui.editpart.policy, org.fortiss.tooling.kernel.base.ui.layout, org.fortiss.tooling.kernel.base.ui.layout.constants, diff --git a/org.fortiss.tooling.base.ui/trunk/icons/overlay/ellipse-reflections.png b/org.fortiss.tooling.base.ui/trunk/icons/overlay/ellipse-reflections.png new file mode 100644 index 0000000000000000000000000000000000000000..1aceeffcc70ea56b0112100f1db06e579b64fb58 Binary files /dev/null and b/org.fortiss.tooling.base.ui/trunk/icons/overlay/ellipse-reflections.png differ diff --git a/org.fortiss.tooling.base.ui/trunk/icons/overlay/linear-blend-round.png b/org.fortiss.tooling.base.ui/trunk/icons/overlay/linear-blend-round.png new file mode 100644 index 0000000000000000000000000000000000000000..655dba892742ff937ac9e2c52371445ce57ca900 Binary files /dev/null and b/org.fortiss.tooling.base.ui/trunk/icons/overlay/linear-blend-round.png differ diff --git a/org.fortiss.tooling.base.ui/trunk/icons/overlay/radial-blend.png b/org.fortiss.tooling.base.ui/trunk/icons/overlay/radial-blend.png new file mode 100644 index 0000000000000000000000000000000000000000..660c0cef02162e057ce2c4a262f261472a6a1a87 Binary files /dev/null and b/org.fortiss.tooling.base.ui/trunk/icons/overlay/radial-blend.png differ diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/SnapToGridSupport.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/SnapToGridSupport.java new file mode 100644 index 0000000000000000000000000000000000000000..8cf8f5dcc8e60a047e1aadebb7159abea2d4b790 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/SnapToGridSupport.java @@ -0,0 +1,43 @@ +/*--------------------------------------------------------------------------+ +$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.kernel.base.ui.editpart; + +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.SnapToGrid; + +/** + * Adapter support for snap to grid edit policies. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public final class SnapToGridSupport { + /** + * Adapter code for snap to grid feature. + */ + public static Object snapToGridAdapter(GraphicalEditPart editPart) { + final Boolean val = (Boolean) editPart.getViewer().getProperty( + SnapToGrid.PROPERTY_GRID_ENABLED); + if (val != null && val.booleanValue()) { + return new SnapToGrid(editPart); + } + return null; + } +} diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/connector/RectangularConnectorEditPartBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/connector/RectangularConnectorEditPartBase.java new file mode 100644 index 0000000000000000000000000000000000000000..0612689aac486f6ede58dc02f47fae76a8ffe237 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/connector/RectangularConnectorEditPartBase.java @@ -0,0 +1,162 @@ +/*--------------------------------------------------------------------------+ +$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.kernel.base.ui.editpart.connector; + +import java.util.ArrayList; +import java.util.List; + +import org.conqat.lib.commons.collections.CollectionUtils; +import org.eclipse.draw2d.ChopboxAnchor; +import org.eclipse.draw2d.ConnectionAnchor; +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +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.kernel.base.ui.editpart.ConnectorEditPartBase; +import org.fortiss.tooling.kernel.base.ui.editpart.policy.ConnectionGraphicalNodeEditPolicy; +import org.fortiss.tooling.kernel.base.ui.editpart.policy.RemoveEditPolicy; +import org.fortiss.tooling.kernel.base.ui.layout.constants.RecommendedLayoutConstants; + +/** + * The super class of the connector edit parts used with rectangular shapes. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public abstract class RectangularConnectorEditPartBase<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; + + /** Creates the edit part. */ + public RectangularConnectorEditPartBase(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; + } + + /** Returns the figure used for the connector. */ + protected IFigure getConnectorFigure() { + if (connectorFigure == null) { + connectorFigure = createConnectorFigure(); + } + return connectorFigure; + } + + /** Creates the figure used for the connector. */ + protected abstract IFigure createConnectorFigure(); + + /** {@inheritDoc} */ + @Override + protected ConnectionAnchor defaultConnectionAnchor() { + return new ChopboxAnchor(getConnectorFigure()); + } + + /** {@inheritDoc} */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + + refreshSourceConnections(); + refreshTargetConnections(); + + for (ConnectionEditPart editPart : (List<ConnectionEditPart>) getSourceConnections()) { + editPart.refresh(); + } + for (ConnectionEditPart editPart : (List<ConnectionEditPart>) getTargetConnections()) { + editPart.refresh(); + } + } + + /** {@inheritDoc} */ + @Override + protected void createEditPolicies() { + installEditPolicy(EditPolicy.COMPONENT_ROLE, new RemoveEditPolicy()); + + installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, + new ConnectionGraphicalNodeEditPolicy()); + } + + /** Returns the root element for this connector edit part. */ + protected abstract IHierarchicElement getRootHierarchicElement(); + + /** + * Returns whether the underlying connector edit part acts as a destination + * connector in the current view (i.e. edit part). + */ + protected abstract boolean isReceiving(); + + /** {@inheritDoc} */ + @Override + protected List<IConnection> getModelSourceConnections() { + if (!isReceiving()) { + return filterConnections(modelElement.getOutgoingList(), + getRootHierarchicElement()); + } + return CollectionUtils.emptyList(); + } + + /** {@inheritDoc} */ + @Override + protected List<IConnection> getModelTargetConnections() { + if (isReceiving()) { + return filterConnections(modelElement.getIncomingList(), + getRootHierarchicElement()); + } + return CollectionUtils.emptyList(); + } + + /** Filters any channels not owned by the given owner. */ + private List<IConnection> filterConnections(List<IConnection> connections, + IHierarchicElement owner) { + List<IConnection> result = new ArrayList<IConnection>(); + for (IConnection channel : connections) { + if (channel.eContainer() == owner) { + result.add(channel); + } + } + return result; + } +} diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/figure/PrettyRoundedRectangle.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/figure/PrettyRoundedRectangle.java new file mode 100644 index 0000000000000000000000000000000000000000..b2e3c2b94121ba541c8e77ae3a8b87834d78d109 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/kernel/base/ui/editpart/figure/PrettyRoundedRectangle.java @@ -0,0 +1,134 @@ +/*--------------------------------------------------------------------------+ +$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.kernel.base.ui.editpart.figure; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.Shape; +import org.eclipse.draw2d.geometry.Insets; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.fortiss.tooling.kernel.base.ui.ToolingBaseUIActivator; + +/** + * This shape consists of a rounded rectangle that is surrounded by transparent + * insets. The rounded rectangle is filled with {@link #getBackgroundColor()}. A + * light top-down gradient from white to the background color is painted over + * the background color to achieve a 3 dimensional reflection effect. + * <p> + * Anti-aliasing is enabled for smooth corners of the rounded rectangle. + * + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +// TODO (FH): add glossy effect: see commented code below +public class PrettyRoundedRectangle extends Shape { + + /** The radius to use for the rounded corners of this shape. */ + protected final int cornerRadius; + + /** The transparent insets surrounding this shape. */ + protected final Insets insets; + + /** A linear blend applied at the top. */ + protected static final Image linearBlend = ToolingBaseUIActivator + .getImageDescriptor("icons/overlay/linear-blend-round.png") + .createImage(); + + /** A radial blend applied at the bottom. */ + protected static final Image radialBlend = ToolingBaseUIActivator + .getImageDescriptor("icons/overlay/radial-blend.png").createImage(); + + /** Creates a new {@link PrettyRoundedRectangle} with given {@link Insets}. */ + public PrettyRoundedRectangle(int cornerRadius, Insets insets) { + this.cornerRadius = cornerRadius; + this.insets = insets; + } + + /** {@inheritDoc} */ + @Override + protected void fillShape(Graphics gfx) { + // final EVisualStyle style = EVisualStyle.get(); + gfx.pushState(); + // if (style == EVisualStyle.Glossy) { + // // Glossy style. + // final Rectangle b = getCroppedBounds(); + // gfx.setBackgroundColor(ColorConstants.black); + // gfx.setAlpha(48); + // gfx.fillRoundRectangle(b.getCopy().translate(5, 5), cornerRadius, + // cornerRadius); + // gfx.restoreState(); + // gfx.fillRoundRectangle(b, cornerRadius, cornerRadius); + // gfx.setAlpha(255); + // gfx.drawImage(linearBlend, new Rectangle(linearBlend.getBounds()), + // b.getCopy().resize(-1, -b.height / 2 - 1)); + // gfx.setAlpha(200); + // gfx.drawImage( + // radialBlend, + // new Rectangle(radialBlend.getBounds()), + // b.getCopy().resize(-1, -b.height / 2 - 1) + // .translate(0, b.height / 2)); + // } else { + // Traditional style is default. + gfx.fillRoundRectangle(getCroppedBounds(), cornerRadius, cornerRadius); + gfx.setForegroundColor(ColorConstants.white); + gfx.setAlpha(200); + gfx.fillGradient(getCroppedBounds().resize(0, -cornerRadius), true); + // } + gfx.popState(); + } + + /** Returns a copy of the bounds cropped by the insets. */ + protected Rectangle getCroppedBounds() { + return bounds.getCropped(insets); + } + + /** + * {@inheritDoc} + * <p> + * Additionally enables anti-aliasing. + */ + @Override + protected void outlineShape(Graphics gfx) { + // final EVisualStyle style = EVisualStyle.get(); + gfx.pushState(); + gfx.setAntialias(SWT.ON); + // if (style == EVisualStyle.Glossy) { + // // Glossy style. + // gfx.setLineCap(SWT.CAP_ROUND); + // final int scale = (int) gfx.getAbsoluteScale(); + // gfx.setLineWidth(scale + 1); + // final Color bg = gfx.getBackgroundColor(); + // final Color bgdark = new Color(bg.getDevice(), max(0, + // (bg.getRed() - 80)), max(0, (bg.getGreen() - 80)), max(0, + // (bg.getBlue() - 80))); + // gfx.setForegroundColor(bgdark); + // gfx.drawRoundRectangle(getCroppedBounds().resize(-1, -1), + // cornerRadius, cornerRadius); + // bgdark.dispose(); + // } else { + // Traditional style is default. + gfx.drawRoundRectangle(getCroppedBounds().resize(-1, -1), cornerRadius, + cornerRadius); + // } + gfx.popState(); + } +}