use of org.gephi.graph.api.GraphController in project gephi-plugins-bootcamp by gephi.
the class RemoveSelfLoopsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
//Get the current graph model
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = gc.getGraphModel();
if (graphModel != null) {
//Remove self loops
int removed = 0;
Graph graph = graphModel.getGraph();
graph.writeLock();
for (Edge edge : graph.getEdges().toArray()) {
if (edge.isSelfLoop()) {
graph.removeEdge(edge);
removed++;
}
}
graph.writeUnlock();
//Notification message
NotifyDescriptor d = new NotifyDescriptor.Message(removed + " self-loop have been removed", NotifyDescriptor.INFORMATION_MESSAGE);
DialogDisplayer.getDefault().notify(d);
} else {
//Error message
NotifyDescriptor d = new NotifyDescriptor.Message("No active workspace", NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(d);
}
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class ActionsToolbar method initContent.
private void initContent() {
//Center on graph
final JButton centerOnGraphButton = new JButton();
centerOnGraphButton.setToolTipText(NbBundle.getMessage(VizBarController.class, "ActionsToolbar.centerOnGraph"));
centerOnGraphButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/centerOnGraph.png")));
centerOnGraphButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
VizController.getInstance().getGraphIO().centerOnGraph();
}
});
add(centerOnGraphButton);
//Center on zero
/*final JButton centerOnZeroButton = new JButton();
centerOnZeroButton.setToolTipText(NbBundle.getMessage(VizBarController.class, "ActionsToolbar.centerOnZero"));
centerOnZeroButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/centerOnZero.png")));
centerOnZeroButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
VizController.getInstance().getGraphIO().centerOnZero();
}
});
add(centerOnZeroButton);*/
//Reset colors
final JColorButton resetColorButton = new JColorButton(color, true, false);
resetColorButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetColors"));
resetColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
color = resetColorButton.getColor();
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel gm = gc.getGraphModel();
Graph graph = gm.getGraphVisible();
for (Node n : graph.getNodes()) {
n.setR(color.getRed() / 255f);
n.setG(color.getGreen() / 255f);
n.setB(color.getBlue() / 255f);
n.setAlpha(1f);
}
for (Edge e : graph.getEdges()) {
e.setR(color.getRed() / 255f);
e.setG(color.getGreen() / 255f);
e.setB(color.getBlue() / 255f);
e.setAlpha(0f);
}
}
});
add(resetColorButton);
//Reset sizes
//Reset label colors
final JButton resetLabelColorButton = new JButton();
resetLabelColorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelColor.png")));
resetLabelColorButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelColors"));
resetLabelColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel gm = gc.getGraphModel();
Graph graph = gm.getGraphVisible();
for (Node n : graph.getNodes().toArray()) {
n.getTextProperties().setColor(Color.BLACK);
n.getTextProperties().setAlpha(0f);
}
for (Edge e : graph.getEdges().toArray()) {
e.getTextProperties().setColor(Color.BLACK);
e.getTextProperties().setAlpha(0f);
}
}
});
add(resetLabelColorButton);
//Reset label visible
final JButton resetLabelVisibleButton = new JButton();
resetLabelVisibleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelVisible.png")));
resetLabelVisibleButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelVisible"));
resetLabelVisibleButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel gm = gc.getGraphModel();
Graph graph = gm.getGraphVisible();
for (Node n : graph.getNodes()) {
n.getTextProperties().setVisible(true);
}
for (Edge e : graph.getEdges()) {
e.getTextProperties().setVisible(true);
}
}
});
add(resetLabelVisibleButton);
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class DynamicSettingsPanel method setup.
public void setup(DynamicStatistics dynamicStatistics) {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel();
TimeFormat timeFormat = graphModel.getTimeFormat();
//Bounds
GraphView currentView = graphModel.getVisibleView();
if (currentView.isMainView()) {
bounds = graphModel.getTimeBounds();
} else {
bounds = currentView.getTimeInterval();
}
String boundsStr = timeFormat.print(bounds.getLow()) + " - " + timeFormat.print(bounds.getHigh());
currentIntervalLabel.setText(boundsStr);
//TimeUnit
if (timeFormat.equals(TimeFormat.DOUBLE)) {
windowTimeUnitCombo.setVisible(false);
tickTimeUnitCombo.setVisible(false);
}
//Set latest selected item
if (!timeFormat.equals(TimeFormat.DOUBLE)) {
loadDefaultTimeUnits();
}
//Window and tick
double initValue = 0.;
if (bounds.getHigh() - bounds.getLow() > 1) {
initValue = 1.;
}
if (timeFormat.equals(TimeFormat.DOUBLE)) {
windowTextField.setText(initValue + "");
tickTextField.setText(initValue + "");
} else {
windowTextField.setText("" + windowTimeUnit.convert((long) initValue, TimeUnit.MILLISECONDS));
tickTextField.setText("" + tickTimeUnit.convert((long) initValue, TimeUnit.MILLISECONDS));
}
//Add listeners
windowTimeUnitCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getItem() != windowTimeUnitCombo.getSelectedItem()) {
refreshWindowTimeUnit();
}
}
});
tickTimeUnitCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getItem() != tickTimeUnitCombo.getSelectedItem()) {
refreshTickTimeUnit();
}
}
});
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class StatisticsFrontEnd method run.
private void run() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel();
//Create Statistics
StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
StatisticsControllerUI controllerUI = Lookup.getDefault().lookup(StatisticsControllerUI.class);
StatisticsBuilder builder = controller.getBuilder(statisticsUI.getStatisticsClass());
currentStatistics = builder.getStatistics();
if (currentStatistics != null) {
if (currentStatistics instanceof DynamicStatistics && !graphModel.isDynamic()) {
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(StatisticsFrontEnd.class, "StatisticsFrontEnd.notDynamicGraph"), NotifyDescriptor.WARNING_MESSAGE));
return;
}
LongTaskListener listener = new LongTaskListener() {
@Override
public void taskFinished(LongTask task) {
showReport();
}
};
JPanel settingsPanel = statisticsUI.getSettingsPanel();
if (currentStatistics instanceof DynamicStatistics) {
DynamicSettingsPanel dynamicPanel = new DynamicSettingsPanel();
statisticsUI.setup(currentStatistics);
dynamicPanel.setup((DynamicStatistics) currentStatistics);
JPanel dynamicSettingsPanel = DynamicSettingsPanel.createCounpoundPanel(dynamicPanel, settingsPanel);
final DialogDescriptor dd = new DialogDescriptor(dynamicSettingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
if (dynamicSettingsPanel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) dynamicSettingsPanel;
vp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
}
if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
dynamicPanel.unsetup((DynamicStatistics) currentStatistics);
statisticsUI.unsetup();
controllerUI.execute(currentStatistics, listener);
}
} else if (settingsPanel != null) {
statisticsUI.setup(currentStatistics);
final DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
if (settingsPanel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) settingsPanel;
vp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
}
if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
statisticsUI.unsetup();
controllerUI.execute(currentStatistics, listener);
}
} else {
statisticsUI.setup(currentStatistics);
controllerUI.execute(currentStatistics, listener);
}
}
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class ExporterGDF method execute.
@Override
public boolean execute() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel(workspace);
Graph graph = exportVisible ? graphModel.getGraphVisible() : graphModel.getGraph();
graph.readLock();
try {
exportData(graph, graphModel);
} catch (Exception e) {
Logger.getLogger(ExporterGDF.class.getName()).log(Level.SEVERE, null, e);
} finally {
graph.readUnlock();
Progress.finish(progressTicket);
}
return !cancel;
}
Aggregations