Search in sources :

Example 41 with Graph

use of org.gephi.graph.api.Graph 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 42 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class MergeNodes method execute.

@Override
public void execute() {
    Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
    GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
    Node newNode = gec.mergeNodes(graph, nodes, selectedNode, columns, mergeStrategies, deleteMergedNodes);
    Lookup.getDefault().lookup(DataTablesController.class).setNodeTableSelection(new Node[] { newNode });
    NbPreferences.forModule(MergeNodes.class).putBoolean(DELETE_MERGED_NODES_SAVED_PREFERENCES, deleteMergedNodes);
}
Also used : Graph(org.gephi.graph.api.Graph) GraphElementsController(org.gephi.datalab.api.GraphElementsController) Node(org.gephi.graph.api.Node) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 43 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class ActionsToolbar method initContent.

private void initContent() {
    //Center on graph
    final JButton centerOnGraphButton = new JButton();
    centerOnGraphButton.setToolTipText(NbBundle.getMessage(VizBarController.class, "ActionsToolbar.centerOnGraph"));
    centerOnGraphButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/centerOnGraph.png")));
    centerOnGraphButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            VizController.getInstance().getGraphIO().centerOnGraph();
        }
    });
    add(centerOnGraphButton);
    //Center on zero
    /*final JButton centerOnZeroButton = new JButton();
         centerOnZeroButton.setToolTipText(NbBundle.getMessage(VizBarController.class, "ActionsToolbar.centerOnZero"));
         centerOnZeroButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/centerOnZero.png")));
         centerOnZeroButton.addActionListener(new ActionListener() {

         public void actionPerformed(ActionEvent e) {
         VizController.getInstance().getGraphIO().centerOnZero();
         }
         });
         add(centerOnZeroButton);*/
    //Reset colors
    final JColorButton resetColorButton = new JColorButton(color, true, false);
    resetColorButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetColors"));
    resetColorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            color = resetColorButton.getColor();
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            GraphModel gm = gc.getGraphModel();
            Graph graph = gm.getGraphVisible();
            for (Node n : graph.getNodes()) {
                n.setR(color.getRed() / 255f);
                n.setG(color.getGreen() / 255f);
                n.setB(color.getBlue() / 255f);
                n.setAlpha(1f);
            }
            for (Edge e : graph.getEdges()) {
                e.setR(color.getRed() / 255f);
                e.setG(color.getGreen() / 255f);
                e.setB(color.getBlue() / 255f);
                e.setAlpha(0f);
            }
        }
    });
    add(resetColorButton);
    //Reset sizes
    //Reset label colors
    final JButton resetLabelColorButton = new JButton();
    resetLabelColorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelColor.png")));
    resetLabelColorButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelColors"));
    resetLabelColorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            GraphModel gm = gc.getGraphModel();
            Graph graph = gm.getGraphVisible();
            for (Node n : graph.getNodes().toArray()) {
                n.getTextProperties().setColor(Color.BLACK);
                n.getTextProperties().setAlpha(0f);
            }
            for (Edge e : graph.getEdges().toArray()) {
                e.getTextProperties().setColor(Color.BLACK);
                e.getTextProperties().setAlpha(0f);
            }
        }
    });
    add(resetLabelColorButton);
    //Reset label visible
    final JButton resetLabelVisibleButton = new JButton();
    resetLabelVisibleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelVisible.png")));
    resetLabelVisibleButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelVisible"));
    resetLabelVisibleButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            GraphModel gm = gc.getGraphModel();
            Graph graph = gm.getGraphVisible();
            for (Node n : graph.getNodes()) {
                n.getTextProperties().setVisible(true);
            }
            for (Edge e : graph.getEdges()) {
                e.getTextProperties().setVisible(true);
            }
        }
    });
    add(resetLabelVisibleButton);
}
Also used : ActionEvent(java.awt.event.ActionEvent) Node(org.gephi.graph.api.Node) JButton(javax.swing.JButton) JColorButton(org.gephi.ui.components.JColorButton) Graph(org.gephi.graph.api.Graph) ActionListener(java.awt.event.ActionListener) GraphModel(org.gephi.graph.api.GraphModel) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 44 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class ExporterGDF method execute.

@Override
public boolean execute() {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel(workspace);
    Graph graph = exportVisible ? graphModel.getGraphVisible() : graphModel.getGraph();
    graph.readLock();
    try {
        exportData(graph, graphModel);
    } catch (Exception e) {
        Logger.getLogger(ExporterGDF.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        graph.readUnlock();
        Progress.finish(progressTicket);
    }
    return !cancel;
}
Also used : Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) GraphController(org.gephi.graph.api.GraphController)

Example 45 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class ExporterGraphML method execute.

@Override
public boolean execute() {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel(workspace);
    Graph graph = exportVisible ? graphModel.getGraphVisible() : graphModel.getGraph();
    graph.readLock();
    try {
        exportData(createDocument(), graph);
    } catch (Exception e) {
        Logger.getLogger(ExporterGraphML.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        graph.readUnlock();
        Progress.finish(progressTicket);
    }
    return !cancel;
}
Also used : Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) GraphController(org.gephi.graph.api.GraphController) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

Graph (org.gephi.graph.api.Graph)104 GraphModel (org.gephi.graph.api.GraphModel)57 Node (org.gephi.graph.api.Node)50 DirectedGraph (org.gephi.graph.api.DirectedGraph)43 Test (org.testng.annotations.Test)36 GraphController (org.gephi.graph.api.GraphController)27 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)24 Edge (org.gephi.graph.api.Edge)21 Column (org.gephi.graph.api.Column)9 ArrayList (java.util.ArrayList)8 Function (org.gephi.appearance.api.Function)6 GraphView (org.gephi.graph.api.GraphView)6 AttributeFunction (org.gephi.appearance.api.AttributeFunction)5 AppearanceController (org.gephi.appearance.api.AppearanceController)4 AppearanceModel (org.gephi.appearance.api.AppearanceModel)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 TransformerUI (org.gephi.appearance.spi.TransformerUI)3 GraphElementsController (org.gephi.datalab.api.GraphElementsController)3 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)3