Search in sources :

Example 6 with Function

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

the class StandardTest method test.

@Test
public void test() {
    Graph graph = generateGraph();
    AppearanceModelImpl model = new AppearanceModelImpl(workspace);
    Function[] funcs = model.getNodeFunctions(graph);
//        for(Function f: funcs) {
//            System.out.println(f);
//        }     
}
Also used : Function(org.gephi.appearance.api.Function) Graph(org.gephi.graph.api.Graph) Test(org.testng.annotations.Test)

Example 7 with Function

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

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

the class AppearanceUIController method setSelectedFunction.

public void setSelectedFunction(Function function) {
    if (graphObserver != null) {
        graphObserver.destroy();
        graphObserver = null;
    }
    if (model != null) {
        Function oldValue = model.getSelectedFunction();
        if ((oldValue == null && function != null) || (oldValue != null && function == null) || (function != null && oldValue != null && !oldValue.equals(function))) {
            model.setAutoApply(false);
            model.setSelectedFunction(function);
            firePropertyChangeEvent(AppearanceUIModelEvent.SELECTED_FUNCTION, oldValue, function);
            if (function != null && !function.isSimple()) {
                graphObserver = new GraphChangeObserver(function.getGraph(), function instanceof AttributeFunction ? ((AttributeFunction) function).getColumn() : null);
                graphObserver.start();
            }
        }
    }
}
Also used : Function(org.gephi.appearance.api.Function) AttributeFunction(org.gephi.appearance.api.AttributeFunction) AttributeFunction(org.gephi.appearance.api.AttributeFunction)

Example 9 with Function

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

the class AppearanceUIModel method replaceSelectedFunction.

public synchronized Function replaceSelectedFunction() {
    Graph graph = graphController.getGraphModel(appearanceModel.getWorkspace()).getGraph();
    Function sFunction = getSelectedFunction();
    if (sFunction instanceof AttributeFunction) {
        AttributeFunction af = (AttributeFunction) sFunction;
        for (Function func : getSelectedElementClass().equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions(graph) : appearanceModel.getEdgeFunctions(graph)) {
            if (func instanceof AttributeFunction) {
                if (af.getColumn().equals(((AttributeFunction) func).getColumn()) && sFunction.getUI().getCategory().equals(func.getUI().getCategory())) {
                    return func;
                }
            }
        }
    }
    return null;
}
Also used : Function(org.gephi.appearance.api.Function) AttributeFunction(org.gephi.appearance.api.AttributeFunction) Graph(org.gephi.graph.api.Graph) AttributeFunction(org.gephi.appearance.api.AttributeFunction)

Example 10 with Function

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

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