public void clusterize(final Clusterer clusterer) { // Get Graph GraphController gc = Lookup.getDefault().lookup(GraphController.class); final GraphModel graphModel = gc.getModel(); // Model final ClusteringModel model = Lookup.getDefault() .lookup(ProjectController.class) .getCurrentWorkspace() .getLookup() .lookup(ClusteringModel.class); // LongTask LongTask task = null; if (clusterer instanceof LongTask) { task = (LongTask) clusterer; } executor.execute( task, new Runnable() { public void run() { model.setRunning(true); clusterer.execute(graphModel); writeColumns(clusterer); model.setRunning(false); } }); }
public boolean requireUpdate() { if (graph == null) { // Try to get a graph GraphModel graphModel = controller.getModel(); if (graphModel != null) { graph = graphModel.getHierarchicalGraphVisible(); } } // Refresh reader if sight changed Graph g = graph; if (g != null) { if (g.getGraphModel().getVisibleView().getViewId() != graphView) { reset(); } return g.getNodeVersion() > nodeVersion || g.getEdgeVersion() > edgeVersion; } return false; }
public void updateWorld() { // System.out.println("update world"); cacheMarker++; GraphModel graphModel = controller.getModel(); if (graphModel == null) { engine.worldUpdated(cacheMarker); return; } if (gm != null && gm != graphModel) { reset(); } gm = graphModel; HierarchicalGraph graph; if (graphModel.isDirected()) { undirected = false; graph = graphModel.getHierarchicalDirectedGraphVisible(); } else if (graphModel.isUndirected()) { undirected = true; graph = graphModel.getHierarchicalUndirectedGraphVisible(); } else if (graphModel.isMixed()) { undirected = false; graph = graphModel.getHierarchicalMixedGraphVisible(); } else { undirected = false; graph = graphModel.getHierarchicalDirectedGraphVisible(); } if (dynamicModel == null) { DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class); dynamicModel = dynamicController.getModel(); } graphView = graph.getView().getViewId(); ModelClass[] object3dClasses = engine.getModelClasses(); graph.readLock(); ModelClass nodeClass = object3dClasses[AbstractEngine.CLASS_NODE]; if (nodeClass.isEnabled() && (graph.getNodeVersion() > nodeVersion || modeManager.requireModeChange())) { updateNodes(graph); nodeClass.setCacheMarker(cacheMarker); } ModelClass edgeClass = object3dClasses[AbstractEngine.CLASS_EDGE]; if (edgeClass.isEnabled() && (graph.getEdgeVersion() > edgeVersion || modeManager.requireModeChange())) { updateEdges(graph); updateMetaEdges(graph); edgeClass.setCacheMarker(cacheMarker); if (!undirected && vizConfig.isShowArrows()) { object3dClasses[AbstractEngine.CLASS_ARROW].setCacheMarker(cacheMarker); } } ModelClass potatoClass = object3dClasses[AbstractEngine.CLASS_POTATO]; if (potatoClass.isEnabled() && (graph.getNodeVersion() > nodeVersion || modeManager.requireModeChange())) { updatePotatoes(graph); potatoClass.setCacheMarker(cacheMarker); } nodeVersion = graph.getNodeVersion(); edgeVersion = graph.getEdgeVersion(); graph.readUnlock(); engine.worldUpdated(cacheMarker); }
public PreviewUIControllerImpl() { listeners = new ArrayList<PropertyChangeListener>(); ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); graphController = Lookup.getDefault().lookup(GraphController.class); pc.addWorkspaceListener( new WorkspaceListener() { public void initialize(Workspace workspace) { workspace.add(new PreviewUIModelImpl()); enableRefresh(); } public void select(Workspace workspace) { // Make sure AttributeModel is created before graph model: Lookup.getDefault().lookup(AttributeController.class).getModel(); graphModel = graphController.getModel(); graphModel.addGraphListener(PreviewUIControllerImpl.this); model = workspace.getLookup().lookup(PreviewUIModelImpl.class); if (model == null) { model = new PreviewUIModelImpl(); workspace.add(model); } fireEvent(SELECT, model); } public void unselect(Workspace workspace) { if (graphModel != null) { graphModel.removeGraphListener(PreviewUIControllerImpl.this); graphModel = null; } fireEvent(UNSELECT, model); } public void close(Workspace workspace) {} public void disable() { if (graphModel != null) { graphModel.removeGraphListener(PreviewUIControllerImpl.this); graphModel = null; } fireEvent(SELECT, null); model = null; } }); if (pc.getCurrentWorkspace() != null) { model = pc.getCurrentWorkspace().getLookup().lookup(PreviewUIModelImpl.class); if (model == null) { model = new PreviewUIModelImpl(); pc.getCurrentWorkspace().add(model); } graphModel = graphController.getModel(); graphModel.addGraphListener(this); } previewController = Lookup.getDefault().lookup(PreviewController.class); // Register editors // Overriding default Preview API basic editors that don't support CustomEditor PropertyEditorManager.registerEditor(EdgeColor.class, EdgeColorPropertyEditor.class); PropertyEditorManager.registerEditor( DependantOriginalColor.class, DependantOriginalColorPropertyEditor.class); PropertyEditorManager.registerEditor(DependantColor.class, DependantColorPropertyEditor.class); }
@Test public void testPNG() { try { // Init a project - and therefore a workspace ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); pc.newProject(); Workspace workspace = pc.getCurrentWorkspace(); // Append container to graph structure String sample = "/org/gephi/desktop/welcome/samples/Les Miserables.gexf"; final InputStream stream = WelcomeTopComponent.class.getResourceAsStream(sample); ImportController importController = Lookup.getDefault().lookup(ImportController.class); FileImporter fileImporter = importController.getFileImporter(".gexf"); Container container = importController.importFile(stream, fileImporter); importController.process(container, new DefaultProcessor(), workspace); // Add self loop GraphController graphController = Lookup.getDefault().lookup(GraphController.class); Graph graph = graphController.getModel().getGraph(); Node node = graph.getNode(12); System.out.println("Self loop " + node.getNodeData().getLabel()); graph.addEdge(graphController.getModel().factory().newEdge(node, node, 31, true)); // Set label edges for (Edge edge : graphController.getModel().getGraph().getEdges()) { edge.getEdgeData().setLabel("Label test"); } // svg document // attribute ??? AttributeController attributeController = Lookup.getDefault().lookup(AttributeController.class); AttributeModel attributeModel = null; // preview PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class); PreviewModel previewModel = previewController.getModel(workspace); PreviewProperties previewProperties = previewModel.getProperties(); previewController.refreshPreview(workspace); previewModel.getProperties().putValue("width", 1000); previewModel.getProperties().putValue("height", 1000); ProcessingTarget target = (ProcessingTarget) previewController.getRenderTarget(RenderTarget.PROCESSING_TARGET, workspace); previewProperties.putValue(LegendModel.LEGEND_PROPERTIES, new LegendModel(workspace)); LegendModel legendManager = previewProperties.getValue(LegendModel.LEGEND_PROPERTIES); Integer itemIndex = legendManager.getCurrentIndex(); // creating item Item item = addGroupsItem(itemIndex, graph, attributeModel); // Item item = addTextItem(itemIndex, graph, attributeModel); // add item LegendController.getInstance().addItemToLegendModel(workspace, item); // render previewController.refreshPreview(workspace); previewController.render(target); File fileToSave = new File("/Volumes/edubecks/edubecks/Untitled.png"); OutputStream fos = new FileOutputStream(fileToSave); Writer writer = new OutputStreamWriter(fos, "UTF-8"); // // saving // int width = 1000; // int height = 1000; // PGraphicsJava2D pg2 = (PGraphicsJava2D) target.getGraphics(); // BufferedImage img = new BufferedImage(width, height, // BufferedImage.TYPE_INT_ARGB); // // System.out.println("@Var: pg2.pixels: "+pg2.pixels); // img.setRGB(0, 0, width, height, pg2.pixels, 0, width); // ImageIO.write(img, "png", fileToSave); // stream.close(); PNGExporter pngExporter = new PNGExporter(); // pngExporter.setHeight(2000); // pngExporter.setWidth(2000); pngExporter.setWorkspace(workspace); pngExporter.setOutputStream(fos); pngExporter.execute(); } catch (Exception e) { Exceptions.printStackTrace(e); } }