use of org.gephi.statistics.spi.StatisticsBuilder 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.statistics.spi.StatisticsBuilder in project gephi by gephi.
the class StatisticsModelImpl method readXML.
public void readXML(XMLStreamReader reader) throws XMLStreamException {
Collection<? extends StatisticsUI> uis = Lookup.getDefault().lookupAll(StatisticsUI.class);
Collection<? extends StatisticsBuilder> builders = Lookup.getDefault().lookupAll(StatisticsBuilder.class);
boolean end = false;
while (reader.hasNext() && !end) {
int type = reader.next();
switch(type) {
case XMLStreamReader.START_ELEMENT:
String name = reader.getLocalName();
if ("report".equalsIgnoreCase(name)) {
String classStr = reader.getAttributeValue(null, "class");
Class reportClass = null;
for (StatisticsBuilder builder : builders) {
if (builder.getStatisticsClass().getName().equals(classStr)) {
reportClass = builder.getStatisticsClass();
}
}
if (reportClass != null) {
String report = reader.getAttributeValue(null, "value");
report = unembedImages(report);
reportMap.put(reportClass, report);
}
}
break;
case XMLStreamReader.END_ELEMENT:
if ("statisticsmodel".equalsIgnoreCase(reader.getLocalName())) {
end = true;
}
break;
}
}
}
use of org.gephi.statistics.spi.StatisticsBuilder in project gephi by gephi.
the class StatisticsControllerImpl method execute.
@Override
public void execute(final Statistics statistics, LongTaskListener listener) {
StatisticsBuilder builder = getBuilder(statistics.getClass());
LongTaskExecutor executor = new LongTaskExecutor(true, "Statistics " + builder.getName(), 10);
if (listener != null) {
executor.setLongTaskListener(listener);
}
if (statistics instanceof DynamicStatistics) {
final DynamicLongTask dynamicLongTask = new DynamicLongTask((DynamicStatistics) statistics);
executor.execute(dynamicLongTask, new Runnable() {
@Override
public void run() {
executeDynamic((DynamicStatistics) statistics, dynamicLongTask);
}
}, builder.getName(), null);
} else {
LongTask task = statistics instanceof LongTask ? (LongTask) statistics : null;
executor.execute(task, new Runnable() {
@Override
public void run() {
execute(statistics);
}
}, builder.getName(), null);
}
}
Aggregations