Search in sources :

Example 6 with ProjectController

use of org.gephi.project.api.ProjectController in project gephi-plugins-bootcamp by gephi.

the class StreamingDynamicGraph method generate.

@Override
public void generate(ContainerLoader container) {
    //Reset cancel
    cancel = false;
    //Start progress
    Progress.start(progressTicket);
    //Project
    ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
    ProjectControllerUI projectControllerUI = Lookup.getDefault().lookup(ProjectControllerUI.class);
    if (projectController.getCurrentProject() == null) {
        projectControllerUI.newProject();
    }
    //Get current graph
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    Graph graph = graphModel.getGraph();
    //Create list of nodes and a random obj
    List<Node> nodes = new ArrayList<Node>();
    Random random = new Random(232323);
    //Create nodes and edges until cancelled
    while (!cancel) {
        //Create a new node and assign random position
        Node n = graphModel.factory().newNode();
        n.setX(random.nextInt(2000) - 1000);
        n.setY(random.nextInt(2000) - 1000);
        //Create a new random time interval and set it to the node
        //Min value is 100
        double min = random.nextInt(2000) + 100;
        //Max value is 2099
        double max = random.nextInt(2000) + 100;
        Interval timeInterval = new Interval(min < max ? min : max, max > min ? max : min);
        n.addInterval(timeInterval);
        //Add the node to the graph
        graph.addNode(n);
        //Add a random number of edges between 0 and 3
        int nbedges = random.nextInt(4);
        for (int i = 0; i < nbedges; i++) {
            //Shuffle an index in the list of nodes 
            int index = random.nextInt(nodes.size() + 1);
            if (index < nodes.size()) {
                //Add an edge if not already exist
                Node m = nodes.get(index);
                if (n != m && graph.getEdge(n, m) == null) {
                    Edge e = graphModel.factory().newEdge(n, m);
                    graph.addEdge(e);
                }
            }
        }
        //Add the node to the list of nodes
        nodes.add(n);
        //Sleep some time
        try {
            Thread.sleep(delay);
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    Progress.finish(progressTicket);
}
Also used : ArrayList(java.util.ArrayList) ProjectController(org.gephi.project.api.ProjectController) Random(java.util.Random) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 7 with ProjectController

use of org.gephi.project.api.ProjectController in project gephi by gephi.

the class GraphTopComponent method initToolPanels.

private void initToolPanels() {
    final ToolController tc = Lookup.getDefault().lookup(ToolController.class);
    if (tc != null) {
        if (VizController.getInstance().getVizConfig().isToolbar()) {
            JPanel westPanel = new JPanel(new BorderLayout(0, 0));
            if (UIUtils.isAquaLookAndFeel()) {
                westPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
            }
            toolbar = tc.getToolbar();
            if (toolbar != null) {
                westPanel.add(toolbar, BorderLayout.CENTER);
            }
            selectionToolbar = new SelectionToolbar();
            actionsToolbar = new ActionsToolbar();
            westPanel.add(selectionToolbar, BorderLayout.NORTH);
            westPanel.add(actionsToolbar, BorderLayout.SOUTH);
            add(westPanel, BorderLayout.WEST);
        }
        if (VizController.getInstance().getVizConfig().isPropertiesbar()) {
            propertiesBar = tc.getPropertiesBar();
            if (propertiesBar != null) {
                add(propertiesBar, BorderLayout.NORTH);
            }
        }
    }
    //Workspace events
    ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
    projectController.addWorkspaceListener(new WorkspaceListener() {

        @Override
        public void initialize(Workspace workspace) {
        }

        @Override
        public void select(Workspace workspace) {
            if (toolbar != null) {
                toolbar.setEnabled(true);
            }
            if (propertiesBar != null) {
                propertiesBar.setEnabled(true);
            }
            if (actionsToolbar != null) {
                actionsToolbar.setEnabled(true);
            }
            if (selectionToolbar != null) {
                selectionToolbar.setEnabled(true);
            }
        }

        @Override
        public void unselect(Workspace workspace) {
        }

        @Override
        public void close(Workspace workspace) {
        }

        @Override
        public void disable() {
            if (toolbar != null) {
                toolbar.setEnabled(false);
            }
            if (tc != null) {
                //Unselect any selected tool
                tc.select(null);
            }
            if (propertiesBar != null) {
                propertiesBar.setEnabled(false);
            }
            if (actionsToolbar != null) {
                actionsToolbar.setEnabled(false);
            }
            if (selectionToolbar != null) {
                selectionToolbar.setEnabled(false);
            }
        }
    });
    boolean hasWorkspace = projectController.getCurrentWorkspace() != null;
    if (toolbar != null) {
        toolbar.setEnabled(hasWorkspace);
    }
    if (propertiesBar != null) {
        propertiesBar.setEnabled(hasWorkspace);
    }
    if (actionsToolbar != null) {
        actionsToolbar.setEnabled(hasWorkspace);
    }
    if (selectionToolbar != null) {
        selectionToolbar.setEnabled(hasWorkspace);
    }
}
Also used : JPanel(javax.swing.JPanel) WorkspaceListener(org.gephi.project.api.WorkspaceListener) BorderLayout(java.awt.BorderLayout) ToolController(org.gephi.tools.api.ToolController) ProjectController(org.gephi.project.api.ProjectController) Workspace(org.gephi.project.api.Workspace)

Example 8 with ProjectController

use of org.gephi.project.api.ProjectController in project gephi by gephi.

the class StandardTest method cleanUp.

@AfterMethod
public void cleanUp() {
    ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
    projectController.closeCurrentProject();
    workspace = null;
    graphModel = null;
}
Also used : ProjectController(org.gephi.project.api.ProjectController) AfterMethod(org.testng.annotations.AfterMethod)

Example 9 with ProjectController

use of org.gephi.project.api.ProjectController in project gephi by gephi.

the class VizController method refreshWorkspace.

public void refreshWorkspace() {
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    VizModel model = null;
    if (pc.getCurrentWorkspace() == null) {
        model = new VizModel(true);
    } else {
        model = pc.getCurrentWorkspace().getLookup().lookup(VizModel.class);
        if (model == null) {
            model = new VizModel(pc.getCurrentWorkspace());
            pc.getCurrentWorkspace().add(model);
        }
    }
    if (model != currentModel) {
        model.setListeners(currentModel.getListeners());
        model.getTextModel().setListeners(currentModel.getTextModel().getListeners());
        currentModel.setListeners(null);
        currentModel.getTextModel().setListeners(null);
        currentModel = model;
        currentModel.init();
    }
}
Also used : ProjectController(org.gephi.project.api.ProjectController)

Example 10 with ProjectController

use of org.gephi.project.api.ProjectController in project gephi by gephi.

the class ExportControllerImpl method exportStream.

@Override
public void exportStream(OutputStream stream, ByteExporter byteExporter) {
    if (byteExporter.getWorkspace() == null) {
        ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
        Workspace workspace = projectController.getCurrentWorkspace();
        byteExporter.setWorkspace(workspace);
    }
    byteExporter.setOutputStream(stream);
    try {
        byteExporter.execute();
    } catch (Exception ex) {
        try {
            stream.flush();
            stream.close();
        } catch (IOException exe) {
        }
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        throw new RuntimeException(ex);
    }
    try {
        stream.flush();
        stream.close();
    } catch (IOException ex) {
    }
}
Also used : IOException(java.io.IOException) ProjectController(org.gephi.project.api.ProjectController) IOException(java.io.IOException) Workspace(org.gephi.project.api.Workspace)

Aggregations

ProjectController (org.gephi.project.api.ProjectController)22 Workspace (org.gephi.project.api.Workspace)11 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)4 ContainerUnloader (org.gephi.io.importer.api.ContainerUnloader)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 JPanel (javax.swing.JPanel)2 GraphController (org.gephi.graph.api.GraphController)2 GraphModel (org.gephi.graph.api.GraphModel)2 WorkspaceInformation (org.gephi.project.api.WorkspaceInformation)2 WorkspaceListener (org.gephi.project.api.WorkspaceListener)2 WorkspaceProvider (org.gephi.project.api.WorkspaceProvider)2 DialogDescriptor (org.openide.DialogDescriptor)2 BorderLayout (java.awt.BorderLayout)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1