use of org.gephi.preview.spi.Renderer in project gephi by gephi.
the class PreviewModelImpl method initManagedRenderers.
/**
* Makes sure that, if more than one plugin extends a default renderer, only the one with the lowest position is enabled initially.
*/
private void initManagedRenderers() {
Renderer[] registeredRenderers = previewController.getRegisteredRenderers();
Set<String> replacedRenderers = new HashSet<>();
managedRenderers = new ManagedRenderer[registeredRenderers.length];
for (int i = 0; i < registeredRenderers.length; i++) {
Renderer r = registeredRenderers[i];
Class superClass = r.getClass().getSuperclass();
if (superClass != null && superClass.getName().startsWith("org.gephi.preview.plugin.renderers.")) {
managedRenderers[i] = new ManagedRenderer(r, !replacedRenderers.contains(superClass.getName()));
replacedRenderers.add(superClass.getName());
} else {
managedRenderers[i] = new ManagedRenderer(r, true);
}
}
}
use of org.gephi.preview.spi.Renderer in project gephi by gephi.
the class PreviewNode method createSheet.
@Override
protected Sheet createSheet() {
Sheet sheet = Sheet.createDefault();
PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
Set<Renderer> enabledRenderers = null;
if (controller.getModel() != null && controller.getModel().getManagedRenderers() != null) {
enabledRenderers = new HashSet<>();
for (ManagedRenderer mr : controller.getModel().getManagedRenderers()) {
if (mr.isEnabled()) {
enabledRenderers.add(mr.getRenderer());
}
}
}
PreviewModel model = controller.getModel();
if (model != null) {
PreviewProperties properties = model.getProperties();
Map<String, Sheet.Set> sheetSets = new HashMap<>();
for (PreviewProperty property : properties.getProperties()) {
Object source = property.getSource();
boolean propertyEnabled = true;
if (source instanceof Renderer) {
propertyEnabled = enabledRenderers == null || enabledRenderers.contains((Renderer) source);
}
if (propertyEnabled) {
String category = property.getCategory();
Sheet.Set sheetSet = sheetSets.get(category);
if (sheetSet == null) {
sheetSet = Sheet.createPropertiesSet();
sheetSet.setDisplayName(category);
sheetSet.setName(category);
}
Node.Property nodeProperty = null;
PreviewProperty[] parents = properties.getParentProperties(property);
PreviewProperty[] children = properties.getChildProperties(property);
if (parents.length > 0) {
nodeProperty = new ChildPreviewPropertyWrapper(property, parents);
} else if (children.length > 0) {
nodeProperty = new ParentPreviewPropertyWrapper(property, children);
} else {
nodeProperty = new PreviewPropertyWrapper(property);
}
sheetSet.put(nodeProperty);
sheetSets.put(category, sheetSet);
}
}
//Ordered
Sheet.Set nodeSet = sheetSets.remove(PreviewProperty.CATEGORY_NODES);
Sheet.Set nodeLabelSet = sheetSets.remove(PreviewProperty.CATEGORY_NODE_LABELS);
Sheet.Set edgeSet = sheetSets.remove(PreviewProperty.CATEGORY_EDGES);
Sheet.Set arrowsSet = sheetSets.remove(PreviewProperty.CATEGORY_EDGE_ARROWS);
Sheet.Set edgeLabelSet = sheetSets.remove(PreviewProperty.CATEGORY_EDGE_LABELS);
if (nodeSet != null) {
sheet.put(nodeSet);
}
if (nodeLabelSet != null) {
sheet.put(nodeLabelSet);
}
if (edgeSet != null) {
sheet.put(edgeSet);
}
if (arrowsSet != null) {
sheet.put(arrowsSet);
}
if (edgeLabelSet != null) {
sheet.put(edgeLabelSet);
}
for (Sheet.Set sheetSet : sheetSets.values()) {
sheet.put(sheetSet);
}
}
return sheet;
}
use of org.gephi.preview.spi.Renderer in project gephi by gephi.
the class RendererManager method restoreRenderersList.
/**
* Restores the original order of the renderers list, preserving their enabled state.
*/
private void restoreRenderersList() {
PreviewModel model = previewController.getModel();
Set<Renderer> enabledRenderers = null;
if (model != null && model.getManagedRenderers() != null) {
enabledRenderers = new HashSet<>();
enabledRenderers.addAll(Arrays.asList(model.getManagedEnabledRenderers()));
}
renderersList.clear();
for (Renderer r : previewController.getRegisteredRenderers()) {
renderersList.add(new RendererCheckBox(r, enabledRenderers == null || enabledRenderers.contains(r)));
}
updateModelManagedRenderers();
}
Aggregations