use of org.gephi.appearance.spi.TransformerUI in project gephi by gephi.
the class AppearanceModelImpl method initTransformerUIs.
private Map<Class, TransformerUI> initTransformerUIs() {
//Index UIs
Map<Class, TransformerUI> uis = new HashMap<>();
for (TransformerUI ui : Lookup.getDefault().lookupAll(TransformerUI.class)) {
Class transformerClass = ui.getTransformerClass();
if (transformerClass == null) {
throw new NullPointerException("Transformer class can' be null");
}
if (uis.containsKey(transformerClass)) {
throw new RuntimeException("A Transformer can't be attach to multiple TransformerUI");
}
uis.put(transformerClass, ui);
}
return uis;
}
use of org.gephi.appearance.spi.TransformerUI in project gephi by gephi.
the class AppearanceUIController method setSelectedTransformerUI.
public void setSelectedTransformerUI(TransformerUI ui) {
if (graphObserver != null) {
graphObserver.destroy();
graphObserver = null;
}
if (model != null) {
TransformerUI oldValue = model.getSelectedTransformerUI();
if (!oldValue.equals(ui)) {
model.setAutoApply(false);
model.setSelectedTransformerUI(ui);
Function function = model.getSelectedFunction();
if (function != null) {
model.refreshSelectedFunction();
if (!function.isSimple()) {
graphObserver = new GraphChangeObserver(function.getGraph(), function instanceof AttributeFunction ? ((AttributeFunction) function).getColumn() : null);
graphObserver.start();
}
}
firePropertyChangeEvent(AppearanceUIModelEvent.SELECTED_TRANSFORMER_UI, oldValue, ui);
}
}
}
use of org.gephi.appearance.spi.TransformerUI in project gephi by gephi.
the class AppearanceUIModel method refreshSelectedFunctions.
private void refreshSelectedFunctions(String elementClass) {
Set<Function> functionSet = new HashSet<>();
Graph graph = graphController.getGraphModel(appearanceModel.getWorkspace()).getGraph();
for (Function func : elementClass.equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions(graph) : appearanceModel.getEdgeFunctions(graph)) {
TransformerUI ui = func.getUI();
if (ui != null) {
functionSet.add(func);
}
}
for (Function func : functionSet) {
Function oldFunc = selectedFunction.get(elementClass).get(func.getUI());
if (oldFunc == null || !functionSet.contains(oldFunc)) {
if (func.isSimple()) {
selectedFunction.get(elementClass).put(func.getUI(), func);
}
}
}
}
use of org.gephi.appearance.spi.TransformerUI in project gephi by gephi.
the class AppearanceTopComponent method refreshCombo.
private void refreshCombo() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
if (model != null) {
TransformerUI ui = model.getSelectedTransformerUI();
if (ui != null && model.isAttributeTransformerUI(ui)) {
//Ranking
Function selectedColumn = model.getSelectedFunction();
attibuteBox.removeItemListener(attributeListener);
comboBoxModel.addElement(NO_SELECTION);
comboBoxModel.setSelectedItem(NO_SELECTION);
List<Function> rows = new ArrayList<>();
rows.addAll(model.getFunctions());
Collections.sort(rows, new Comparator<Function>() {
@Override
public int compare(Function o1, Function o2) {
if (o1.isAttribute() && !o2.isAttribute()) {
return 1;
} else if (!o1.isAttribute() && o2.isAttribute()) {
return -1;
}
return o1.toString().compareTo(o2.toString());
}
});
for (Function r : rows) {
comboBoxModel.addElement(r);
if (selectedColumn != null && selectedColumn.equals(r)) {
comboBoxModel.setSelectedItem(r);
}
}
attributeListener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (model != null) {
if (!attibuteBox.getSelectedItem().equals(NO_SELECTION)) {
Function selectedItem = (Function) attibuteBox.getSelectedItem();
Function selectedFunction = model.getSelectedFunction();
if (selectedFunction != selectedItem) {
controller.setSelectedFunction(selectedItem);
}
} else {
controller.setSelectedFunction(null);
}
}
}
};
attibuteBox.addItemListener(attributeListener);
}
}
attibuteBox.setModel(comboBoxModel);
}
});
}
use of org.gephi.appearance.spi.TransformerUI in project gephi by gephi.
the class AppearanceUIModel method getFunctions.
public Collection<Function> getFunctions() {
Graph graph = graphController.getGraphModel(appearanceModel.getWorkspace()).getGraph();
List<Function> functions = new ArrayList<>();
for (Function func : selectedElementClass.equalsIgnoreCase(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions(graph) : appearanceModel.getEdgeFunctions(graph)) {
TransformerUI ui = func.getUI();
if (ui != null && ui.getDisplayName().equals(getSelectedTransformerUI().getDisplayName())) {
if (ui.getCategory().equals(selectedCategory.get(selectedElementClass))) {
functions.add(func);
}
}
}
return functions;
}
Aggregations