Search in sources :

Example 1 with TransformerUI

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;
}
Also used : HashMap(java.util.HashMap) TransformerUI(org.gephi.appearance.spi.TransformerUI)

Example 2 with TransformerUI

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);
        }
    }
}
Also used : Function(org.gephi.appearance.api.Function) AttributeFunction(org.gephi.appearance.api.AttributeFunction) AttributeFunction(org.gephi.appearance.api.AttributeFunction) TransformerUI(org.gephi.appearance.spi.TransformerUI)

Example 3 with TransformerUI

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);
            }
        }
    }
}
Also used : Function(org.gephi.appearance.api.Function) AttributeFunction(org.gephi.appearance.api.AttributeFunction) Graph(org.gephi.graph.api.Graph) TransformerUI(org.gephi.appearance.spi.TransformerUI) HashSet(java.util.HashSet)

Example 4 with TransformerUI

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);
        }
    });
}
Also used : Function(org.gephi.appearance.api.Function) RankingFunction(org.gephi.appearance.api.RankingFunction) AttributeFunction(org.gephi.appearance.api.AttributeFunction) ItemEvent(java.awt.event.ItemEvent) ArrayList(java.util.ArrayList) List(java.util.List) ItemListener(java.awt.event.ItemListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TransformerUI(org.gephi.appearance.spi.TransformerUI) Comparator(java.util.Comparator)

Example 5 with TransformerUI

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;
}
Also used : Function(org.gephi.appearance.api.Function) AttributeFunction(org.gephi.appearance.api.AttributeFunction) Graph(org.gephi.graph.api.Graph) ArrayList(java.util.ArrayList) TransformerUI(org.gephi.appearance.spi.TransformerUI)

Aggregations

TransformerUI (org.gephi.appearance.spi.TransformerUI)6 AttributeFunction (org.gephi.appearance.api.AttributeFunction)5 Function (org.gephi.appearance.api.Function)5 Graph (org.gephi.graph.api.Graph)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 RankingFunction (org.gephi.appearance.api.RankingFunction)1 TransformerCategory (org.gephi.appearance.spi.TransformerCategory)1