Search in sources :

Example 1 with Function

use of org.gephi.appearance.api.Function in project gephi by gephi.

the class AppearanceUIController method setSelectedElementClass.

public void setSelectedElementClass(String elementClass) {
    if (graphObserver != null) {
        graphObserver.destroy();
        graphObserver = null;
    }
    if (!elementClass.equals(NODE_ELEMENT) && !elementClass.equals(EDGE_ELEMENT)) {
        throw new RuntimeException("Element class has to be " + NODE_ELEMENT + " or " + EDGE_ELEMENT);
    }
    if (model != null) {
        String oldValue = model.getSelectedElementClass();
        if (!oldValue.equals(elementClass)) {
            model.setSelectedElementClass(elementClass);
            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_ELEMENT_CLASS, oldValue, elementClass);
        }
    }
}
Also used : Function(org.gephi.appearance.api.Function) AttributeFunction(org.gephi.appearance.api.AttributeFunction) AttributeFunction(org.gephi.appearance.api.AttributeFunction)

Example 2 with Function

use of org.gephi.appearance.api.Function 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 Function

use of org.gephi.appearance.api.Function in project gephi by gephi.

the class AppearanceUIController method setSelectedCategory.

public void setSelectedCategory(TransformerCategory category) {
    if (graphObserver != null) {
        graphObserver.destroy();
        graphObserver = null;
    }
    if (model != null) {
        TransformerCategory oldValue = model.getSelectedCategory();
        if (!oldValue.equals(category)) {
            model.setSelectedCategory(category);
            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_CATEGORY, oldValue, category);
        }
    }
}
Also used : Function(org.gephi.appearance.api.Function) AttributeFunction(org.gephi.appearance.api.AttributeFunction) TransformerCategory(org.gephi.appearance.spi.TransformerCategory) AttributeFunction(org.gephi.appearance.api.AttributeFunction)

Example 4 with Function

use of org.gephi.appearance.api.Function in project gephi by gephi.

the class AppearanceUIModel method saveTransformerProperties.

public void saveTransformerProperties() {
    Function func = getSelectedFunction();
    if (func != null) {
        Transformer transformer = func.getTransformer();
        Map<String, Object> props = savedProperties.get(func);
        if (props == null) {
            props = new HashMap<>();
            savedProperties.put(func, new HashMap<String, Object>());
        }
        for (Map.Entry<String, Method[]> entry : getProperties(transformer).entrySet()) {
            String name = entry.getKey();
            Method getMethod = entry.getValue()[0];
            try {
                Object o = getMethod.invoke(transformer);
                props.put(name, o);
            } catch (Exception ex) {
            }
        }
    }
}
Also used : Function(org.gephi.appearance.api.Function) AttributeFunction(org.gephi.appearance.api.AttributeFunction) Transformer(org.gephi.appearance.spi.Transformer) PartitionTransformer(org.gephi.appearance.spi.PartitionTransformer) RankingTransformer(org.gephi.appearance.spi.RankingTransformer) Method(java.lang.reflect.Method) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with Function

use of org.gephi.appearance.api.Function 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)

Aggregations

Function (org.gephi.appearance.api.Function)13 AttributeFunction (org.gephi.appearance.api.AttributeFunction)12 Graph (org.gephi.graph.api.Graph)6 TransformerUI (org.gephi.appearance.spi.TransformerUI)5 HashMap (java.util.HashMap)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 PartitionTransformer (org.gephi.appearance.spi.PartitionTransformer)2 RankingTransformer (org.gephi.appearance.spi.RankingTransformer)2 Transformer (org.gephi.appearance.spi.Transformer)2 TransformerCategory (org.gephi.appearance.spi.TransformerCategory)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 Test (org.testng.annotations.Test)1