Skip to content

Commit

Permalink
Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ptziegler committed Sep 27, 2024
1 parent 18273d9 commit 9985300
Show file tree
Hide file tree
Showing 7 changed files with 430 additions and 468 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2005 CHISEL Group, University of Victoria, Victoria, BC,
* Copyright 2005, 2024 CHISEL Group, University of Victoria, Victoria, BC,
* Canada.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,34 +17,49 @@
import java.util.List;
import java.util.Map;

import org.eclipse.zest.layouts.LayoutEntity;
import org.eclipse.zest.layouts.LayoutGraph;
import org.eclipse.zest.layouts.LayoutRelationship;
import org.eclipse.zest.layouts.LayoutAlgorithm;
import org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle;
import org.eclipse.zest.layouts.interfaces.ContextListener;
import org.eclipse.zest.layouts.interfaces.EntityLayout;
import org.eclipse.zest.layouts.interfaces.ExpandCollapseManager;
import org.eclipse.zest.layouts.interfaces.GraphStructureListener;
import org.eclipse.zest.layouts.interfaces.LayoutContext;
import org.eclipse.zest.layouts.interfaces.LayoutListener;
import org.eclipse.zest.layouts.interfaces.NodeLayout;
import org.eclipse.zest.layouts.interfaces.PruningListener;
import org.eclipse.zest.layouts.interfaces.SubgraphLayout;

import org.eclipse.draw2d.EventListenerList;

/**
* Create a very simple graph that can be used in the layout algorithms
*
* @author Casey Best
* @author Chris Callendar
*/
public class SimpleGraph implements LayoutGraph {
public class SimpleGraph implements LayoutContext {

Map<Object, SimpleNode> objectsToNodes;
List<SimpleRelationship> relationships;
LayoutAlgorithm algorithm;
ExpandCollapseManager expandCollapseManager;
EventListenerList listeners;
DisplayIndependentRectangle bounds;

public SimpleGraph() {
objectsToNodes = new HashMap<>();
relationships = new ArrayList<>();
listeners = new EventListenerList();
bounds = new DisplayIndependentRectangle();
}

/**
* Adds the node.
*
* @param node The node to add.
*/
@Override
public void addEntity(LayoutEntity node) {
objectsToNodes.put(((SimpleNode) node).getRealObject(), (SimpleNode) node);
public void addEntity(SimpleNode node) {
objectsToNodes.put(node.getRealObject(), node);
}

/**
Expand Down Expand Up @@ -107,9 +122,8 @@ public void addRelationship(SimpleNode srcNode, SimpleNode destNode, boolean bid
* @see ca.uvic.cs.chisel.layouts.LayoutGraph#addRelationship(ca.uvic.cs.chisel.
* layouts.LayoutRelationship)
*/
@Override
public void addRelationship(LayoutRelationship relationship) {
relationships.add((SimpleRelationship) relationship);
public void addRelationship(SimpleRelationship relationship) {
relationships.add(relationship);
}

/**
Expand All @@ -118,26 +132,133 @@ public void addRelationship(LayoutRelationship relationship) {
* SimpleNodes, not the real objects. You must still manipulate them yourself.
*/
@Override
public List<SimpleNode> getEntities() {
return new ArrayList<>(objectsToNodes.values());
public SimpleNode[] getNodes() {
return objectsToNodes.values().toArray(SimpleNode[]::new);
}

/**
* Returns a list of SimpleRelationships that represent the objects added to
* this graph using addRelationship.
*/
@Override
public List<SimpleRelationship> getRelationships() {
return relationships;
public SimpleRelationship[] getConnections() {
return relationships.toArray(SimpleRelationship[]::new);
}

@Override
public SimpleRelationship[] getConnections(EntityLayout layoutEntity1, EntityLayout layoutEntity2) {
List<SimpleRelationship> relationships = new ArrayList<>();
for (SimpleRelationship relationship : this.relationships) {
if (relationship.getSource() == layoutEntity1 && relationship.getTarget() == layoutEntity2) {
relationships.add(relationship);
}
}
return relationships.toArray(SimpleRelationship[]::new);
}

public void setBounds(double x, double y, double width, double height) {
bounds.x = x;
bounds.y = y;
bounds.width = width;
bounds.height = height;
}

@Override
public DisplayIndependentRectangle getBounds() {
return bounds;
}

@Override
public boolean isBoundsExpandable() {
return false;
}

@Override
public SubgraphLayout[] getSubgraphs() {
return new SubgraphLayout[0];
}

@Override
public SubgraphLayout createSubgraph(NodeLayout[] nodes) {
throw new UnsupportedOperationException();
}

@Override
public boolean isPruningEnabled() {
return false;
}

@Override
public boolean isBackgroundLayoutEnabled() {
return false;
}

@Override
public void flushChanges(boolean animationHint) {
}

@Override
public void setMainLayoutAlgorithm(LayoutAlgorithm algorithm) {
this.algorithm = algorithm;
}

@Override
public LayoutAlgorithm getMainLayoutAlgorithm() {
return algorithm;
}

@Override
public void setExpandCollapseManager(ExpandCollapseManager expandCollapseManager) {
this.expandCollapseManager = expandCollapseManager;
}

@Override
public ExpandCollapseManager getExpandCollapseManager() {
return expandCollapseManager;
}

@Override
public void addLayoutListener(LayoutListener listener) {
listeners.addListener(LayoutListener.class, listener);
}

@Override
public void removeLayoutListener(LayoutListener listener) {
listeners.removeListener(LayoutListener.class, listener);
}

@Override
public void addGraphStructureListener(GraphStructureListener listener) {
listeners.addListener(GraphStructureListener.class, listener);
}

@Override
public void removeGraphStructureListener(GraphStructureListener listener) {
listeners.removeListener(GraphStructureListener.class, listener);
}

@Override
public void addContextListener(ContextListener listener) {
listeners.addListener(ContextListener.class, listener);
}

@Override
public void removeContextListener(ContextListener listener) {
listeners.removeListener(ContextListener.class, listener);
}

@Override
public void addPruningListener(PruningListener listener) {
listeners.addListener(PruningListener.class, listener);
}

@Override
public void removePruningListener(PruningListener listener) {
listeners.removeListener(PruningListener.class, listener);
}

/**
* Checks the relationships to see if they are all bidirectional.
*
* @return boolean if all edges are bidirectional.
*/
@Override
public boolean isBidirectional() {
return relationships.stream().anyMatch(SimpleRelationship::isBidirectionalInLayout);
public SimpleNode[] getEntities() {
return getNodes();
}
}
Loading

0 comments on commit 9985300

Please sign in to comment.