use of org.eclipse.elk.graph.properties.IProperty in project lingua-franca by lf-lang.
the class ReactionPortAdjustment method modify.
@Override
public boolean modify(IStyleModifier.StyleModificationContext context) {
try {
KGraphElement node = context.getGraphElement();
if (node instanceof KNode) {
KNode knode = (KNode) node;
// Find root node
KNode parent = knode;
while (parent.eContainer() != null) {
parent = (KNode) parent.eContainer();
}
// Get viewer (this is a bit brittle because it fetches the viewer from some internal property)
Map.Entry<IProperty<?>, Object> first = IterableExtensions.findFirst(parent.getAllProperties().entrySet(), it -> {
return it.getKey().getId().equals("de.cau.cs.kieler.klighd.viewer") || it.getKey().getId().equals("klighd.layout.viewer");
});
Object viewer = first != null ? first.getValue() : null;
ILayoutRecorder recorder = null;
if (viewer instanceof IViewer) {
recorder = ((IViewer) viewer).getViewContext().getLayoutRecorder();
}
if (!knode.getPorts().isEmpty()) {
if (IterableExtensions.head(knode.getPorts()).getYpos() != 0 && !knode.getProperty(ReactionPortAdjustment.PROCESSED)) {
// important for incremental update animation
if (recorder != null) {
recorder.startRecording();
}
List<KPort> in = IterableExtensions.toList(IterableExtensions.sortBy(IterableExtensions.filter(knode.getPorts(), it -> {
return it.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST && !it.hasProperty(CoreOptions.PORT_BORDER_OFFSET);
}), it -> {
return it.getYpos();
}));
List<KPort> out = IterableExtensions.toList(IterableExtensions.sortBy(IterableExtensions.filter(knode.getPorts(), it -> {
return it.getProperty(CoreOptions.PORT_SIDE) == PortSide.EAST && !it.hasProperty(CoreOptions.PORT_BORDER_OFFSET);
}), it -> {
return it.getYpos();
}));
// Adjust
adjustPositions(IterableExtensions.indexed(in), in.size(), true);
adjustPositions(IterableExtensions.indexed(out), out.size(), false);
knode.setProperty(ReactionPortAdjustment.PROCESSED, true);
if (recorder != null) {
recorder.stopRecording(0);
}
} else if (IterableExtensions.head(knode.getPorts()).getYpos() == 0) {
knode.setProperty(PROCESSED, false);
}
}
}
} catch (Exception e) {
e.printStackTrace();
// do not disturb rendering process
}
return false;
}
use of org.eclipse.elk.graph.properties.IProperty in project elk by eclipse.
the class ComponentsProcessor method pack.
/**
* Pack the given components into a single graph.
*
* @param components
* a list of components
* @return a single graph that contains all components
*/
@SuppressWarnings("unchecked")
public TGraph pack(final List<TGraph> components) {
if (components.size() == 1) {
return components.get(0);
} else if (components.size() <= 0) {
return new TGraph();
}
// assign priorities and sizes
for (TGraph graph : components) {
int priority = 0;
double minx = Integer.MAX_VALUE, miny = Integer.MAX_VALUE;
double maxx = Integer.MIN_VALUE, maxy = Integer.MIN_VALUE;
for (TNode node : graph.getNodes()) {
priority += node.getProperty(MrTreeOptions.PRIORITY);
minx = Math.min(minx, node.getPosition().x);
miny = Math.min(miny, node.getPosition().y);
maxx = Math.max(maxx, node.getPosition().x + node.getSize().x);
maxy = Math.max(maxy, node.getPosition().y + node.getSize().y);
}
graph.setProperty(MrTreeOptions.PRIORITY, priority);
graph.setProperty(InternalProperties.BB_UPLEFT, new KVector(minx, miny));
graph.setProperty(InternalProperties.BB_LOWRIGHT, new KVector(maxx, maxy));
}
// sort the components by their priority and size
Collections.sort(components, new Comparator<TGraph>() {
public int compare(final TGraph graph1, final TGraph graph2) {
int prio = graph2.getProperty(MrTreeOptions.PRIORITY) - graph1.getProperty(MrTreeOptions.PRIORITY);
if (prio == 0) {
KVector size1 = graph1.getProperty(InternalProperties.BB_LOWRIGHT).clone().sub(graph1.getProperty(InternalProperties.BB_UPLEFT));
KVector size2 = graph2.getProperty(InternalProperties.BB_LOWRIGHT).clone().sub(graph2.getProperty(InternalProperties.BB_UPLEFT));
return Double.compare(size1.x * size1.y, size2.x * size2.y);
}
return prio;
}
});
TGraph result = new TGraph();
result.copyProperties(components.get(0));
// determine the maximal row width by the maximal box width and the total area
double maxRowWidth = 0.0f;
double totalArea = 0.0f;
for (TGraph graph : components) {
KVector size = graph.getProperty(InternalProperties.BB_LOWRIGHT).clone().sub(graph.getProperty(InternalProperties.BB_UPLEFT));
maxRowWidth = Math.max(maxRowWidth, size.x);
totalArea += size.x * size.y;
}
maxRowWidth = Math.max(maxRowWidth, (float) Math.sqrt(totalArea) * result.getProperty(MrTreeOptions.ASPECT_RATIO));
double spacing = result.getProperty(MrTreeOptions.SPACING_NODE_NODE).doubleValue();
// place nodes iteratively into rows
double xpos = 0, ypos = 0, highestBox = 0, broadestRow = spacing;
for (TGraph graph : components) {
KVector size = graph.getProperty(InternalProperties.BB_LOWRIGHT).clone().sub(graph.getProperty(InternalProperties.BB_UPLEFT));
if (xpos + size.x > maxRowWidth) {
// place the graph into the next row
xpos = 0;
ypos += highestBox + spacing;
highestBox = 0;
}
moveGraph(result, graph, xpos, ypos);
broadestRow = Math.max(broadestRow, xpos + size.x);
highestBox = Math.max(highestBox, size.y);
xpos += size.x + spacing;
}
Map<IProperty<?>, Object> propMerge = new HashMap<IProperty<?>, Object>();
Map<IProperty<?>, Object> debug = new HashMap<IProperty<?>, Object>();
for (TGraph tGraph : components) {
boolean debugMode = tGraph.getProperty(CoreOptions.DEBUG_MODE);
Map<IProperty<?>, Object> propComp = tGraph.getAllProperties();
for (Entry<IProperty<?>, Object> entry : propComp.entrySet()) {
if (propMerge.containsKey(entry.getKey())) {
if (entry.getKey().getDefault() != entry.getValue()) {
if (debugMode && debug.containsKey(entry.getKey())) {
System.err.println("Found different values for property " + entry.getKey().getId() + " in components.");
} else {
propMerge.put(entry.getKey(), entry.getValue());
result.setProperty((IProperty<Object>) entry.getKey(), entry.getValue());
if (debugMode) {
debug.put(entry.getKey(), entry.getValue());
}
}
}
} else {
propMerge.put(entry.getKey(), entry.getValue());
result.setProperty((IProperty<Object>) entry.getKey(), entry.getValue());
}
}
}
return result;
}
use of org.eclipse.elk.graph.properties.IProperty in project elk by eclipse.
the class EMapPropertyHolderImpl method copyProperties.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public IPropertyHolder copyProperties(IPropertyHolder source) {
if (source == null) {
return this;
}
if (source instanceof EMapPropertyHolder) {
EMapPropertyHolder other = (EMapPropertyHolder) source;
EMap<IProperty<?>, Object> ourProps = this.getProperties();
for (Map.Entry<IProperty<?>, Object> entry : other.getProperties()) {
Object value = entry.getValue();
if (value instanceof IPropertyValueProxy) {
IPropertyValueProxy proxy = (IPropertyValueProxy) value;
Object newValue = proxy.resolveValue(entry.getKey());
if (newValue != null) {
entry.setValue(newValue);
value = newValue;
}
}
ourProps.put(entry.getKey(), value);
}
} else {
this.getProperties().putAll(source.getAllProperties());
}
return this;
}
use of org.eclipse.elk.graph.properties.IProperty in project elk by eclipse.
the class ElkReflectTest method testSimpleProperty.
/**
* Tests the simple {@link Property} class, in particular, that the {@link Property#getDefault()} method behaves
* correctly.
*/
@Test
public void testSimpleProperty() throws IllegalAccessException {
final Iterable<Class<?>> allKnownProperties = Iterables.concat(providers, otherPropertyFiles);
for (Class<?> p : allKnownProperties) {
Field[] resolverFields = p.getDeclaredFields();
for (Field f : resolverFields) {
if (f.getType().isAssignableFrom(IProperty.class)) {
// required for private static fields
f.setAccessible(true);
// get the property
IProperty<?> property = (IProperty<?>) f.get(null);
checkPropertyDefault(property);
}
}
}
}
use of org.eclipse.elk.graph.properties.IProperty in project elk by eclipse.
the class EMapPropertyHolderImpl method getAllProperties.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public Map<IProperty<?>, Object> getAllProperties() {
EMap<IProperty<?>, Object> props = getProperties();
// check for unresolved properties
for (Map.Entry<IProperty<?>, Object> entry : props) {
if (entry.getValue() instanceof IPropertyValueProxy && entry.getKey() != null) {
IPropertyValueProxy proxy = (IPropertyValueProxy) entry.getValue();
// Try to resolve the proxy's value, maybe the layout option was
// registered by now. If not, we preserve the proxy.
Object value = proxy.resolveValue(entry.getKey());
if (value != null) {
entry.setValue(value);
}
}
}
return props.map();
}
Aggregations