use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class FilterModelPersistenceProvider method readQuery.
private Query readQuery(XMLStreamReader reader, FilterModelImpl model) throws XMLStreamException {
String builderClassName = reader.getAttributeValue(null, "builder");
String filterClassName = reader.getAttributeValue(null, "filter");
FilterBuilder builder = null;
for (FilterBuilder fb : model.getLibrary().getLookup().lookupAll(FilterBuilder.class)) {
if (fb.getClass().getName().equals(builderClassName)) {
if (filterClassName != null) {
if (fb.getFilter(model.getWorkspace()).getClass().getName().equals(filterClassName)) {
builder = fb;
break;
}
} else {
builder = fb;
break;
}
}
}
if (builder == null) {
for (CategoryBuilder catBuilder : Lookup.getDefault().lookupAll(CategoryBuilder.class)) {
for (FilterBuilder fb : catBuilder.getBuilders(model.getWorkspace())) {
if (fb.getClass().getName().equals(builderClassName)) {
if (filterClassName != null) {
if (fb.getFilter(model.getWorkspace()).getClass().getName().equals(filterClassName)) {
builder = fb;
break;
}
} else {
builder = fb;
break;
}
}
}
}
}
if (builder != null) {
//Create filter
Filter filter = builder.getFilter(model.getWorkspace());
Query query;
if (filter instanceof Operator) {
query = new OperatorQueryImpl((Operator) filter);
} else {
query = new FilterQueryImpl(builder, filter);
}
FilterProperty property = null;
boolean end = false;
while (reader.hasNext() && !end) {
Integer eventType = reader.next();
if (eventType.equals(XMLEvent.START_ELEMENT)) {
String name = reader.getLocalName();
if ("parameter".equalsIgnoreCase(name)) {
int index = Integer.parseInt(reader.getAttributeValue(null, "index"));
property = query.getFilter().getProperties()[index];
}
} else if (eventType.equals(XMLStreamReader.CHARACTERS) && property != null) {
try {
PropertyEditor editor = property.getPropertyEditor();
if (editor == null) {
editor = PropertyEditorManager.findEditor(property.getValueType());
}
if (editor != null) {
String textValue = reader.getText();
if (editor instanceof AttributeColumnPropertyEditor) {
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = gc.getGraphModel(model.getWorkspace());
((AttributeColumnPropertyEditor) editor).setGraphModel(graphModel);
}
editor.setAsText(textValue);
property.setValue(editor.getValue());
model.updateParameters(query);
if (editor instanceof AttributeColumnPropertyEditor) {
((AttributeColumnPropertyEditor) editor).setGraphModel(null);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
property = null;
if ("query".equalsIgnoreCase(reader.getLocalName())) {
end = true;
}
}
}
return query;
}
return null;
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class EdgePencil method updatePanel.
private void updatePanel() {
if (edgePencilPanel != null) {
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
if (gc.getGraphModel() != null) {
edgePencilPanel.setType(gc.getGraphModel().isDirected() || gc.getGraphModel().isMixed());
}
sourceNode = null;
edgePencilPanel.setStatus(NbBundle.getMessage(EdgePencil.class, "EdgePencil.status1"));
}
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class HeatMap method getListeners.
@Override
public ToolEventListener[] getListeners() {
listeners = new ToolEventListener[1];
listeners[0] = new NodeClickEventListener() {
@Override
public void clickNodes(Node[] nodes) {
try {
Node n = nodes[0];
Color[] colors;
float[] positions;
if (heatMapPanel.isUsePalette()) {
colors = heatMapPanel.getSelectedPalette().getColors();
positions = heatMapPanel.getSelectedPalette().getPositions();
dontPaintUnreachable = true;
} else {
gradientColors = colors = heatMapPanel.getGradientColors();
gradientPositions = positions = heatMapPanel.getGradientPositions();
dontPaintUnreachable = heatMapPanel.isDontPaintUnreachable();
}
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
AbstractShortestPathAlgorithm algorithm;
if (gc.getGraphModel().isDirected()) {
DirectedGraph graph = gc.getGraphModel().getDirectedGraphVisible();
algorithm = new BellmanFordShortestPathAlgorithm(graph, n);
algorithm.compute();
} else {
Graph graph = gc.getGraphModel().getGraphVisible();
algorithm = new DijkstraShortestPathAlgorithm(graph, n);
algorithm.compute();
}
//Color
LinearGradient linearGradient = new LinearGradient(colors, positions);
//Algorithm
double maxDistance = algorithm.getMaxDistance();
if (!dontPaintUnreachable) {
//+1 to have the maxdistance nodes a ratio<1
maxDistance++;
}
if (maxDistance > 0) {
for (Entry<Node, Double> entry : algorithm.getDistances().entrySet()) {
Node node = entry.getKey();
if (!Double.isInfinite(entry.getValue())) {
float ratio = (float) (entry.getValue() / maxDistance);
Color c = linearGradient.getValue(ratio);
node.setColor(c);
} else if (!dontPaintUnreachable) {
Color c = colors[colors.length - 1];
node.setColor(c);
}
}
}
Color c = colors[0];
n.setColor(c);
heatMapPanel.setStatus(NbBundle.getMessage(HeatMap.class, "HeatMap.status.maxdistance") + new DecimalFormat("#.##").format(algorithm.getMaxDistance()));
} catch (Exception e) {
Logger.getLogger("").log(Level.SEVERE, "", e);
}
}
};
return listeners;
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class DefaultProcessor method process.
protected void process(ContainerUnloader container, Workspace workspace) {
//Architecture
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
graphModel = graphController.getGraphModel(workspace);
//Get graph
Graph graph = graphModel.getGraph();
GraphFactory factory = graphModel.factory();
//Time Format & Time zone
graphModel.setTimeFormat(container.getTimeFormat());
graphModel.setTimeZone(container.getTimeZone());
//Progress
Progress.start(progressTicket, container.getNodeCount() + container.getEdgeCount());
//Attributes - Creates columns for properties
flushColumns(container);
//Counters
int addedNodes = 0, addedEdges = 0;
//Create all nodes
ElementIdType elementIdType = container.getElementIdType();
for (NodeDraft draftNode : container.getNodes()) {
String idString = draftNode.getId();
Object id = toElementId(elementIdType, idString);
Node node = graph.getNode(id);
boolean newNode = false;
if (node == null) {
node = factory.newNode(id);
addedNodes++;
newNode = true;
}
flushToNode(draftNode, node);
if (newNode) {
graph.addNode(node);
}
Progress.progress(progressTicket);
}
//Create all edges and push to data structure
for (EdgeDraft draftEdge : container.getEdges()) {
String idString = draftEdge.getId();
Object id = toElementId(elementIdType, idString);
String sourceId = draftEdge.getSource().getId();
String targetId = draftEdge.getTarget().getId();
Node source = graph.getNode(toElementId(elementIdType, sourceId));
Node target = graph.getNode(toElementId(elementIdType, targetId));
Object type = draftEdge.getType();
int edgeType = graphModel.addEdgeType(type);
Edge edge = graph.getEdge(source, target, edgeType);
boolean newEdge = false;
if (edge == null) {
switch(container.getEdgeDefault()) {
case DIRECTED:
edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), true);
break;
case UNDIRECTED:
edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), false);
break;
case MIXED:
boolean directed = draftEdge.getDirection() == null || !draftEdge.getDirection().equals(EdgeDirection.UNDIRECTED);
edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), directed);
break;
}
addedEdges++;
newEdge = true;
}
flushToEdge(draftEdge, edge);
if (newEdge) {
graph.addEdge(edge);
}
Progress.progress(progressTicket);
}
//Report
int touchedNodes = container.getNodeCount();
int touchedEdges = container.getEdgeCount();
if (touchedNodes != addedNodes || touchedEdges != addedEdges) {
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Nodes loaded: {0} ({1} added)", new Object[] { touchedNodes, addedNodes });
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Edges loaded: {0} ({1} added)", new Object[] { touchedEdges, addedEdges });
} else {
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Nodes loaded: {0}", new Object[] { touchedNodes });
Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Edges loaded: {0}", new Object[] { touchedEdges });
}
Progress.finish(progressTicket);
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class DefaultProcessor method processConfiguration.
protected void processConfiguration(ContainerUnloader container, Workspace workspace) {
//Configuration
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
Configuration configuration = new Configuration();
configuration.setTimeRepresentation(container.getTimeRepresentation());
if (container.getEdgeTypeLabelClass() != null) {
configuration.setEdgeLabelType(container.getEdgeTypeLabelClass());
}
configuration.setNodeIdType(container.getElementIdType().getTypeClass());
configuration.setEdgeIdType(container.getElementIdType().getTypeClass());
ColumnDraft weightColumn = container.getEdgeColumn("weight");
if (weightColumn != null && weightColumn.isDynamic()) {
if (container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
configuration.setEdgeWeightType(IntervalDoubleMap.class);
} else {
configuration.setEdgeWeightType(TimestampDoubleMap.class);
}
}
graphController.getGraphModel(workspace).setConfiguration(configuration);
}
Aggregations