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);
          }
        });
  }
Exemplo n.º 2
0
  /** Creates new form EigenvectorCentralityPanel */
  public EigenvectorCentralityPanel() {
    initComponents();

    // Disable directed if the graph is undirecteds
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    if (graphController.getGraphModel().isUndirected()) {
      directedRadioButton.setEnabled(false);
    }
  }
 @Override
 public void execute(Statistics statistics) {
   if (statistics instanceof DynamicStatistics) {
     executeDynamic((DynamicStatistics) statistics, null);
   } else {
     GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
     GraphModel graphModel = graphController.getGraphModel();
     statistics.execute(graphModel);
     model.addReport(statistics);
   }
 }
Exemplo n.º 4
0
  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);
  }
 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);
  }
Exemplo n.º 7
0
  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);
  }
  private void executeDynamic(DynamicStatistics statistics, DynamicLongTask dynamicLongTask) {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();

    double window = statistics.getWindow();
    double tick = statistics.getTick();

    GraphView currentView = graphModel.getVisibleView();
    Interval bounds = statistics.getBounds();
    if (bounds == null) {
      if (currentView.isMainView()) {
        bounds = graphModel.getTimeBounds();
      } else {
        bounds = currentView.getTimeInterval();
      }
      statistics.setBounds(bounds);
    }

    if (dynamicLongTask != null) {
      // Count
      int c = (int) ((bounds.getHigh() - window - bounds.getLow()) / tick);
      dynamicLongTask.start(c);
    }

    // Init
    statistics.execute(graphModel);

    // Loop
    for (double low = bounds.getLow(); low <= bounds.getHigh() - window; low += tick) {
      double high = low + window;

      Graph graph = graphModel.getGraphVisible();

      graph.writeLock();

      GraphView view = graphModel.createView();
      Subgraph g = graphModel.getGraph(view);

      TimeIndex<Node> nodeIndex = graphModel.getNodeTimeIndex(currentView);
      if (Double.isInfinite(nodeIndex.getMinTimestamp())
          && Double.isInfinite(nodeIndex.getMaxTimestamp())) {
        for (Node node : graph.getNodes()) {
          g.addNode(node);
        }
      } else {
        for (Node node : nodeIndex.get(new Interval(low, high))) {
          g.addNode(node);
        }
      }

      TimeIndex<Edge> edgeIndex = graphModel.getEdgeTimeIndex(currentView);
      if (Double.isInfinite(edgeIndex.getMinTimestamp())
          && Double.isInfinite(edgeIndex.getMaxTimestamp())) {
        for (Edge edge : graph.getEdges()) {
          if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
            g.addEdge(edge);
          }
        }
      } else {
        for (Edge edge : edgeIndex.get(new Interval(low, high))) {
          if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
            g.addEdge(edge);
          }
        }
      }

      graph.writeUnlock();

      statistics.loop(g.getView(), new Interval(low, high));

      // Cancelled?
      if (dynamicLongTask != null && dynamicLongTask.isCancelled()) {
        return;
      } else if (dynamicLongTask != null) {
        dynamicLongTask.progress();
      }
    }
    statistics.end();
    model.addReport(statistics);
  }
Exemplo n.º 9
0
  @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);
    }
  }
Exemplo n.º 10
0
  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);
      if (node == null) {
        node = factory.newNode(id);
        addedNodes++;
      }
      flushToNode(draftNode, node);

      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);
      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++;
      }
      flushToEdge(draftEdge, edge);

      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);
  }