Search in sources :

Example 1 with CoreOptions

use of org.eclipse.elk.core.options.CoreOptions in project elk by eclipse.

the class ElkUtil method applyConfiguredNodeScaling.

/**
 * Applies the scaling factor configured in terms of {@link CoreOptions#SCALE_FACTOR} to {@code node}'s
 * size data, and updates the layout data of {@code node}'s ports and labels accordingly.<br>
 * <b>Note:</b> The scaled layout data won't be reverted during the layout process, see
 * {@link CoreOptions#SCALE_FACTOR}.
 *
 * @param node
 *            the node to be scaled
 */
public static void applyConfiguredNodeScaling(final ElkNode node) {
    final double scalingFactor = node.getProperty(CoreOptions.SCALE_FACTOR);
    if (scalingFactor == 1) {
        return;
    }
    node.setDimensions(scalingFactor * node.getWidth(), scalingFactor * node.getHeight());
    final Iterable<ElkLabel> portLabels = Iterables.concat(Iterables.transform(node.getPorts(), p -> p.getLabels()));
    for (ElkShape shape : Iterables.concat(node.getLabels(), node.getPorts(), portLabels)) {
        shape.setLocation(scalingFactor * shape.getX(), scalingFactor * shape.getY());
        shape.setDimensions(scalingFactor * shape.getWidth(), scalingFactor * shape.getHeight());
        final KVector anchor = shape.getProperty(CoreOptions.PORT_ANCHOR);
        if (anchor != null) {
            anchor.x *= scalingFactor;
            anchor.y *= scalingFactor;
        }
    }
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) Iterables(com.google.common.collect.Iterables) ListIterator(java.util.ListIterator) PortSide(org.eclipse.elk.core.options.PortSide) ContentAlignment(org.eclipse.elk.core.options.ContentAlignment) ElkGraphFactory(org.eclipse.elk.graph.ElkGraphFactory) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) KVectorChain(org.eclipse.elk.core.math.KVectorChain) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Strings(com.google.common.base.Strings) LabelAdapter(org.eclipse.elk.core.util.adapters.GraphAdapters.LabelAdapter) Lists(com.google.common.collect.Lists) Map(java.util.Map) GraphValidationException(org.eclipse.elk.core.validation.GraphValidationException) PortAdapter(org.eclipse.elk.core.util.adapters.GraphAdapters.PortAdapter) Iterator(java.util.Iterator) PortConstraints(org.eclipse.elk.core.options.PortConstraints) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVector(org.eclipse.elk.core.math.KVector) Collection(java.util.Collection) SizeOptions(org.eclipse.elk.core.options.SizeOptions) Set(java.util.Set) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) EObject(org.eclipse.emf.ecore.EObject) ElkShape(org.eclipse.elk.graph.ElkShape) Maps(com.google.common.collect.Maps) File(java.io.File) ElkConnectableShape(org.eclipse.elk.graph.ElkConnectableShape) List(java.util.List) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) Direction(org.eclipse.elk.core.options.Direction) IValidatingGraphElementVisitor(org.eclipse.elk.core.validation.IValidatingGraphElementVisitor) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement) GraphIssue(org.eclipse.elk.core.validation.GraphIssue) ElkEdge(org.eclipse.elk.graph.ElkEdge) Pattern(java.util.regex.Pattern) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkShape(org.eclipse.elk.graph.ElkShape) KVector(org.eclipse.elk.core.math.KVector)

Example 2 with CoreOptions

use of org.eclipse.elk.core.options.CoreOptions in project elk by eclipse.

the class LayoutMetaDataService method getInstance.

/**
 * Returns the singleton instance of the layout data service.
 *
 * @param loader
 *      The class loader object. This is not explicitly a class loader since elkjs cannot handle it.
 *
 * @return the singleton instance
 */
public static synchronized LayoutMetaDataService getInstance(final Object loader) {
    if (instance == null) {
        instance = new LayoutMetaDataService();
        // Be sure to load CoreOptions first
        instance.registerLayoutMetaDataProviders(new CoreOptions());
        // running on Equinox since this will only find services in the realm of this class's class loader)
        for (ILayoutMetaDataProvider provider : java.util.ServiceLoader.load(ILayoutMetaDataProvider.class, (ClassLoader) loader)) {
            instance.registerLayoutMetaDataProviders(provider);
        }
        // Try to make the ELK service plug-in load our services
        try {
            Class.forName("org.eclipse.elk.core.service.ElkServicePlugin");
        } catch (Exception e) {
        // If the service plug-in is not available, that's no problem; we'll simply use our default factory
        }
    // elkjs-exclude-end
    }
    return instance;
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions)

Aggregations

CoreOptions (org.eclipse.elk.core.options.CoreOptions)2 Strings (com.google.common.base.Strings)1 Iterables (com.google.common.collect.Iterables)1 Iterators (com.google.common.collect.Iterators)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)1 KVector (org.eclipse.elk.core.math.KVector)1 KVectorChain (org.eclipse.elk.core.math.KVectorChain)1 ContentAlignment (org.eclipse.elk.core.options.ContentAlignment)1 Direction (org.eclipse.elk.core.options.Direction)1