Search in sources :

Example 6 with GraphController

use of org.gephi.graph.api.GraphController in project gephi-plugins-bootcamp by gephi.

the class RemoveSelfLoopsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    //Get the current graph model
    GraphController gc = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = gc.getGraphModel();
    if (graphModel != null) {
        //Remove self loops
        int removed = 0;
        Graph graph = graphModel.getGraph();
        graph.writeLock();
        for (Edge edge : graph.getEdges().toArray()) {
            if (edge.isSelfLoop()) {
                graph.removeEdge(edge);
                removed++;
            }
        }
        graph.writeUnlock();
        //Notification message
        NotifyDescriptor d = new NotifyDescriptor.Message(removed + " self-loop have been removed", NotifyDescriptor.INFORMATION_MESSAGE);
        DialogDisplayer.getDefault().notify(d);
    } else {
        //Error message
        NotifyDescriptor d = new NotifyDescriptor.Message("No active workspace", NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(d);
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 7 with GraphController

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

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

the class DynamicSettingsPanel method setup.

public void setup(DynamicStatistics dynamicStatistics) {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    TimeFormat timeFormat = graphModel.getTimeFormat();
    //Bounds
    GraphView currentView = graphModel.getVisibleView();
    if (currentView.isMainView()) {
        bounds = graphModel.getTimeBounds();
    } else {
        bounds = currentView.getTimeInterval();
    }
    String boundsStr = timeFormat.print(bounds.getLow()) + " - " + timeFormat.print(bounds.getHigh());
    currentIntervalLabel.setText(boundsStr);
    //TimeUnit
    if (timeFormat.equals(TimeFormat.DOUBLE)) {
        windowTimeUnitCombo.setVisible(false);
        tickTimeUnitCombo.setVisible(false);
    }
    //Set latest selected item
    if (!timeFormat.equals(TimeFormat.DOUBLE)) {
        loadDefaultTimeUnits();
    }
    //Window and tick
    double initValue = 0.;
    if (bounds.getHigh() - bounds.getLow() > 1) {
        initValue = 1.;
    }
    if (timeFormat.equals(TimeFormat.DOUBLE)) {
        windowTextField.setText(initValue + "");
        tickTextField.setText(initValue + "");
    } else {
        windowTextField.setText("" + windowTimeUnit.convert((long) initValue, TimeUnit.MILLISECONDS));
        tickTextField.setText("" + tickTimeUnit.convert((long) initValue, TimeUnit.MILLISECONDS));
    }
    //Add listeners
    windowTimeUnitCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getItem() != windowTimeUnitCombo.getSelectedItem()) {
                refreshWindowTimeUnit();
            }
        }
    });
    tickTimeUnitCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getItem() != tickTimeUnitCombo.getSelectedItem()) {
                refreshTickTimeUnit();
            }
        }
    });
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) ItemEvent(java.awt.event.ItemEvent) GraphModel(org.gephi.graph.api.GraphModel) ItemListener(java.awt.event.ItemListener) GraphView(org.gephi.graph.api.GraphView) GraphController(org.gephi.graph.api.GraphController)

Example 9 with GraphController

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

the class StatisticsFrontEnd method run.

private void run() {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    //Create Statistics
    StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
    StatisticsControllerUI controllerUI = Lookup.getDefault().lookup(StatisticsControllerUI.class);
    StatisticsBuilder builder = controller.getBuilder(statisticsUI.getStatisticsClass());
    currentStatistics = builder.getStatistics();
    if (currentStatistics != null) {
        if (currentStatistics instanceof DynamicStatistics && !graphModel.isDynamic()) {
            DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(StatisticsFrontEnd.class, "StatisticsFrontEnd.notDynamicGraph"), NotifyDescriptor.WARNING_MESSAGE));
            return;
        }
        LongTaskListener listener = new LongTaskListener() {

            @Override
            public void taskFinished(LongTask task) {
                showReport();
            }
        };
        JPanel settingsPanel = statisticsUI.getSettingsPanel();
        if (currentStatistics instanceof DynamicStatistics) {
            DynamicSettingsPanel dynamicPanel = new DynamicSettingsPanel();
            statisticsUI.setup(currentStatistics);
            dynamicPanel.setup((DynamicStatistics) currentStatistics);
            JPanel dynamicSettingsPanel = DynamicSettingsPanel.createCounpoundPanel(dynamicPanel, settingsPanel);
            final DialogDescriptor dd = new DialogDescriptor(dynamicSettingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
            if (dynamicSettingsPanel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) dynamicSettingsPanel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
                dynamicPanel.unsetup((DynamicStatistics) currentStatistics);
                statisticsUI.unsetup();
                controllerUI.execute(currentStatistics, listener);
            }
        } else if (settingsPanel != null) {
            statisticsUI.setup(currentStatistics);
            final DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
            if (settingsPanel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) settingsPanel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
                statisticsUI.unsetup();
                controllerUI.execute(currentStatistics, listener);
            }
        } else {
            statisticsUI.setup(currentStatistics);
            controllerUI.execute(currentStatistics, listener);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) LongTaskListener(org.gephi.utils.longtask.api.LongTaskListener) DynamicStatistics(org.gephi.statistics.spi.DynamicStatistics) StatisticsBuilder(org.gephi.statistics.spi.StatisticsBuilder) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) NotifyDescriptor(org.openide.NotifyDescriptor) StatisticsController(org.gephi.statistics.api.StatisticsController) LongTask(org.gephi.utils.longtask.spi.LongTask) ChangeEvent(javax.swing.event.ChangeEvent) GraphModel(org.gephi.graph.api.GraphModel) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) GraphController(org.gephi.graph.api.GraphController) StatisticsControllerUI(org.gephi.desktop.statistics.api.StatisticsControllerUI)

Example 10 with GraphController

use of org.gephi.graph.api.GraphController 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)

Aggregations

GraphController (org.gephi.graph.api.GraphController)28 GraphModel (org.gephi.graph.api.GraphModel)19 Graph (org.gephi.graph.api.Graph)12 Node (org.gephi.graph.api.Node)9 Edge (org.gephi.graph.api.Edge)7 Column (org.gephi.graph.api.Column)5 TimeFormat (org.gephi.graph.api.TimeFormat)4 MouseClickEventListener (org.gephi.tools.spi.MouseClickEventListener)3 NodeClickEventListener (org.gephi.tools.spi.NodeClickEventListener)3 ArrayList (java.util.ArrayList)2 AbstractShortestPathAlgorithm (org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm)2 BellmanFordShortestPathAlgorithm (org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm)2 DijkstraShortestPathAlgorithm (org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm)2 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)2 GraphFactory (org.gephi.graph.api.GraphFactory)2 GraphView (org.gephi.graph.api.GraphView)2 DynamicStatistics (org.gephi.statistics.spi.DynamicStatistics)2 NotifyDescriptor (org.openide.NotifyDescriptor)2 Color (java.awt.Color)1 Font (java.awt.Font)1