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);
}
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);
}
}
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;
}
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();
}
}
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) {
}
}
Aggregations