Skip to content
Snippets Groups Projects
Commit b4dea152 authored by Simon Barner's avatar Simon Barner
Browse files

GREEN (with refactoring of shared code)

Issue-Ref: 4261
Issue-Url: af3#4261



Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent 12ab1d7e
No related branches found
No related tags found
1 merge request!183Improve the safetycases editor
DefaultLayoutConstants.java 10ba39d25701f7aff7ef545ec69e42a6117ae7b1 GREEN
HorizontalDiagramTapeMeasure.java 4f45e2f20c7db54271493fd198b9a20dfd2c87b8 YELLOW
DiagramTapeMeasure.java 4ac1310faa82746f0a66e684677588cbcdfcdde9 GREEN
HorizontalDiagramTapeMeasure.java 98bcb18ed5171c5ff191225cf21a305d5ef06440 GREEN
IAutoLayouter.java 8f22d3813491159151a8753dd683a5043554fb67 GREEN
IAutoLayouterTapeMeasure.java 5ef5c7d0a124714d582de283d3915d8b4bf7fda8 GREEN
KielerAutoLayouter.java 9cc7943ff90c55851b81bf7c4cde7b279992e925 YELLOW
LayoutKeyConstants.java e4082f9c08890b656bf3fe1b74a866eef24232fb YELLOW
VerticalDiagramTapeMeasure.java d18b28706615def11ec2ef1e0f547cbfd5434c8a YELLOW
VerticalDiagramTapeMeasure.java 0b83af2189b4f55d0dfe121ae4e86cee064c5164 GREEN
/*-------------------------------------------------------------------------+
| Copyright 2018 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.layout;
import static java.lang.Math.max;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_WIDTH;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeSize;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import org.fortiss.tooling.base.model.base.EntryConnectorBase;
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.element.IModelElement;
import org.fortiss.tooling.base.model.layout.Dimension;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.geometry.Bounds;
import javafx.scene.text.Text;
/**
* {@link IAutoLayouterTapeMeasure} base class of models to be displayed in JavaFX-based editors.
*
* @author barner
*/
public abstract class DiagramTapeMeasure implements IAutoLayouterTapeMeasure {
/**
* Returns the an estimation of the text extent of the given {@code element}'s label (may be
* {@code null}).
*/
protected Bounds getTextExtent(IModelElement element) {
if(!(element instanceof INamedElement)) {
return null;
}
String name = ((INamedElement)element).getName();
Text text = new Text(name);
return text.getBoundsInLocal();
}
/**
* Returns the maximum of the given length and a default length derived from the element's
* connector count.
*/
protected int getElementLength(int length, IHierarchicElement element) {
int numElemConnectors = element.getConnectors().size();
int numElemInputConnectors =
pickInstanceOf(EntryConnectorBase.class, element.getConnectors()).size();
int numConnectors = max(numElemInputConnectors, numElemConnectors - numElemInputConnectors);
return max((1 + 2 * numConnectors) * DEFAULT_CONNECTOR_SIZE, length);
}
/** {@inheritDoc} */
@Override
public int getElementWidth(IHierarchicElement element) {
Dimension dimension = getNodeSize((ILayoutedModelElement)element);
int width = max(DEFAULT_SHAPE_MINIMUM_WIDTH, dimension.getWidth());
Bounds textExtent = getTextExtent(element);
if(textExtent != null) {
width = max(width, (int)textExtent.getWidth() + 6 * DEFAULT_GRID_SIZE);
}
return width;
}
/** {@inheritDoc} */
@Override
public int getElementHeight(IHierarchicElement element) {
Dimension dimension = getNodeSize((ILayoutedModelElement)element);
return dimension.getHeight();
}
/** {@inheritDoc} */
@Override
public int getConnectorWidth(IConnector connector) {
return DEFAULT_CONNECTOR_SIZE;
}
/** {@inheritDoc} */
@Override
public int getConnectorHeight(IConnector connector) {
return DEFAULT_CONNECTOR_SIZE;
}
/** {@inheritDoc} */
@Override
public int getConnectionWidth(IConnection connection) {
Bounds textExtend = getTextExtent(connection);
return textExtend != null ? (int)textExtend.getWidth() : 0;
}
/** {@inheritDoc} */
@Override
public int getConnectorLabelWidth(IConnector connector) {
Bounds textExtend = getTextExtent(connector);
return textExtend != null ? (int)textExtend.getWidth() : 0;
}
}
......@@ -15,95 +15,21 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.layout;
import static java.lang.Math.max;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_WIDTH;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeSize;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import org.fortiss.tooling.base.model.base.EntryConnectorBase;
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.element.IModelElement;
import org.fortiss.tooling.base.model.layout.Dimension;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.geometry.Bounds;
import javafx.scene.text.Text;
/**
* {@link IAutoLayouterTapeMeasure} specialization to for automatic layout of models to be displayed
* in JavaFX-based editors.
* {@link IAutoLayouterTapeMeasure} specialization for automatic horizontal layout of models to be
* displayed in JavaFX-based editors.
*
* @author barner
*/
public class HorizontalDiagramTapeMeasure implements IAutoLayouterTapeMeasure {
/**
* Returns the an estimation of the text extent of the given {@code element}'s label (may be
* {@code null}).
*/
private Bounds getTextExtent(IModelElement element) {
if(!(element instanceof INamedElement)) {
return null;
}
String name = ((INamedElement)element).getName();
Text text = new Text(name);
return text.getBoundsInLocal();
}
/** {@inheritDoc} */
@Override
public int getElementWidth(IHierarchicElement element) {
Dimension dimension = getNodeSize((ILayoutedModelElement)element);
int width = max(DEFAULT_SHAPE_MINIMUM_WIDTH, dimension.getWidth());
Bounds textExtent = getTextExtent(element);
if(textExtent != null) {
width = max(width, (int)textExtent.getWidth() + 6 * DEFAULT_GRID_SIZE);
}
return width;
}
public class HorizontalDiagramTapeMeasure extends DiagramTapeMeasure {
/** {@inheritDoc} */
@Override
public int getElementHeight(IHierarchicElement element) {
Dimension dimension = getNodeSize((ILayoutedModelElement)element);
int numElemConnectors = element.getConnectors().size();
int numElemInputConnectors =
pickInstanceOf(EntryConnectorBase.class, element.getConnectors()).size();
int numConnectors = max(numElemInputConnectors, numElemConnectors - numElemInputConnectors);
return max((1 + 2 * numConnectors) * DEFAULT_CONNECTOR_SIZE, dimension.getHeight());
}
/** {@inheritDoc} */
@Override
public int getConnectorWidth(IConnector connector) {
return DEFAULT_CONNECTOR_SIZE;
}
/** {@inheritDoc} */
@Override
public int getConnectorHeight(IConnector connector) {
return DEFAULT_CONNECTOR_SIZE;
}
int height = super.getElementHeight(element);
/** {@inheritDoc} */
@Override
public int getConnectionWidth(IConnection connection) {
Bounds textExtend = getTextExtent(connection);
return textExtend != null ? (int)textExtend.getWidth() : 0;
}
/** {@inheritDoc} */
@Override
public int getConnectorLabelWidth(IConnector connector) {
Bounds textExtend = getTextExtent(connector);
return textExtend != null ? (int)textExtend.getWidth() : 0;
return getElementLength(height, element);
}
}
......@@ -15,94 +15,21 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.layout;
import static java.lang.Math.max;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_WIDTH;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeSize;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import org.fortiss.tooling.base.model.base.EntryConnectorBase;
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.element.IModelElement;
import org.fortiss.tooling.base.model.layout.Dimension;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.geometry.Bounds;
import javafx.scene.text.Text;
/**
* {@link IAutoLayouterTapeMeasure} specialization to for automatic vertical layout of models to be
* {@link IAutoLayouterTapeMeasure} specialization for automatic vertical layout of models to be
* displayed in JavaFX-based editors.
*
* @author barner
*/
public class VerticalDiagramTapeMeasure implements IAutoLayouterTapeMeasure {
/**
* Returns the an estimation of the text extent of the given {@code element}'s label (may be
* {@code null}).
*/
private Bounds getTextExtent(IModelElement element) {
if(!(element instanceof INamedElement)) {
return null;
}
String name = ((INamedElement)element).getName();
Text text = new Text(name);
return text.getBoundsInLocal();
}
public class VerticalDiagramTapeMeasure extends DiagramTapeMeasure {
/** {@inheritDoc} */
@Override
public int getElementWidth(IHierarchicElement element) {
Dimension dimension = getNodeSize((ILayoutedModelElement)element);
int numElemConnectors = element.getConnectors().size();
int numElemInputConnectors =
pickInstanceOf(EntryConnectorBase.class, element.getConnectors()).size();
int numConnectors = max(numElemInputConnectors, numElemConnectors - numElemInputConnectors);
int width = max(DEFAULT_SHAPE_MINIMUM_WIDTH, dimension.getWidth());
Bounds textExtent = getTextExtent(element);
if(textExtent != null) {
width = max(width, (int)textExtent.getWidth() + 6 * DEFAULT_GRID_SIZE);
}
return max((1 + 2 * numConnectors) * DEFAULT_CONNECTOR_SIZE, width);
}
int width = super.getElementWidth(element);
/** {@inheritDoc} */
@Override
public int getElementHeight(IHierarchicElement element) {
Dimension dimension = getNodeSize((ILayoutedModelElement)element);
return dimension.getHeight();
}
/** {@inheritDoc} */
@Override
public int getConnectorWidth(IConnector connector) {
return DEFAULT_CONNECTOR_SIZE;
}
/** {@inheritDoc} */
@Override
public int getConnectorHeight(IConnector connector) {
return DEFAULT_CONNECTOR_SIZE;
}
/** {@inheritDoc} */
@Override
public int getConnectionWidth(IConnection connection) {
Bounds textExtend = getTextExtent(connection);
return textExtend != null ? (int)textExtend.getWidth() : 0;
}
/** {@inheritDoc} */
@Override
public int getConnectorLabelWidth(IConnector connector) {
Bounds textExtend = getTextExtent(connector);
return textExtend != null ? (int)textExtend.getWidth() : 0;
return getElementLength(width, element);
}
}
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