Search in sources :

Example 16 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class MetricLayoutAlgorithm method genLevels.

private void genLevels() {
    filledLevels = badNodes.isEmpty() ? 0 : 1;
    final double step = (maxValue - minValue) / LEVELS;
    double actBound = minValue + step;
    for (int actLevel = 0; actLevel < LEVELS; ++actLevel) {
        final Iterator<NodeDescriptor> it = nodes.iterator();
        boolean isEmpty = true;
        while (it.hasNext()) {
            final NodeDescriptor node = it.next();
            final Double value = values.get(node);
            if (value != null && (value < actBound || Math.abs(value - actBound) <= EPSILON)) {
                levels.put(node, filledLevels);
                it.remove();
                isEmpty = false;
            }
        }
        if (!isEmpty) {
            filledLevels++;
        }
        actBound += step;
    }
    genLevelNumbers();
}
Also used : NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor)

Example 17 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class GraphEditor method initWindow.

/**
 * This method creates the items to show on the {@link Frame} , and adds
 * actions
 */
protected void initWindow() {
    drawArea = new JPanel();
    window.add(drawArea, BorderLayout.CENTER);
    drawArea.setSize(windowSize.width, windowSize.height);
    drawArea.setPreferredSize(new Dimension(windowSize.width, windowSize.height));
    menuBar = new JMenuBar();
    window.add(menuBar, BorderLayout.NORTH);
    final JMenu mnFile = new JMenu("File");
    final ActionListener saveGraph = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            String path = "";
            try {
                path = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path"));
            } catch (CoreException exc) {
                errorHandler.reportException("Error while reading persistent property", exc);
            }
            final String oldPath = path;
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    FileDialog dialog = new FileDialog(editorComposite.getShell(), SWT.SAVE);
                    dialog.setText("Save Pajek file");
                    dialog.setFilterPath(oldPath);
                    dialog.setFilterExtensions(new String[] { "*.net", "*.dot" });
                    String graphFilePath = dialog.open();
                    if (graphFilePath == null) {
                        return;
                    }
                    String newPath = graphFilePath.substring(0, graphFilePath.lastIndexOf(File.separator) + 1);
                    try {
                        QualifiedName name = new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path");
                        project.setPersistentProperty(name, newPath);
                        if ("dot".equals(graphFilePath.substring(graphFilePath.lastIndexOf('.') + 1, graphFilePath.length()))) {
                            GraphHandler.saveGraphToDot(graph, graphFilePath, project.getName());
                        } else {
                            GraphHandler.saveGraphToPajek(graph, graphFilePath);
                        }
                    } catch (BadLayoutException be) {
                        ErrorReporter.logExceptionStackTrace("Error while saving image to " + newPath, be);
                        errorHandler.reportErrorMessage("Bad layout\n\n" + be.getMessage());
                    } catch (Exception ce) {
                        ErrorReporter.logExceptionStackTrace("Error while saving image to " + newPath, ce);
                        errorHandler.reportException("Error while setting persistent property", ce);
                    }
                }
            });
        }
    };
    final JMenuItem mntmSave = new JMenuItem("Save (Ctrl+S)");
    mntmSave.addActionListener(saveGraph);
    mnFile.add(mntmSave);
    final ActionListener exportImage = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            String path = "";
            try {
                path = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path"));
            } catch (CoreException exc) {
                errorHandler.reportException("Error while reading persistent property", exc);
            }
            final String oldPath = path;
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    ExportImagePreferencesDialog prefDialog = new ExportImagePreferencesDialog(editorComposite.getShell());
                    ImageExportType mode = prefDialog.open();
                    FileDialog dialog = new FileDialog(editorComposite.getShell(), SWT.SAVE);
                    dialog.setText("Export image");
                    dialog.setFilterPath(oldPath);
                    dialog.setFilterExtensions(new String[] { "*.png" });
                    String graphFilePath = dialog.open();
                    if (graphFilePath == null) {
                        return;
                    }
                    String newPath = graphFilePath.substring(0, graphFilePath.lastIndexOf(File.separator) + 1);
                    try {
                        QualifiedName name = new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path");
                        project.setPersistentProperty(name, newPath);
                        handler.saveToImage(graphFilePath, mode);
                    } catch (BadLayoutException be) {
                        errorHandler.reportException("Error while saving image", be);
                        errorHandler.reportErrorMessage(be.getMessage());
                    } catch (CoreException ce) {
                        errorHandler.reportException("Error while setting persistent property", ce);
                    }
                }
            });
        }
    };
    final JMenuItem mntmExportToImage = new JMenuItem("Export to image file (Ctrl+E)");
    mntmExportToImage.addActionListener(exportImage);
    mnFile.add(mntmExportToImage);
    layoutMenu = new JMenu("Layout");
    layoutGroup = new ButtonGroup();
    layoutListener = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final IProgressMonitor monitor = Job.getJobManager().createProgressGroup();
            monitor.beginTask("Change layout", 100);
            if (!(e.getSource() instanceof LayoutEntry)) {
                errorHandler.reportErrorMessage("Unexpected error\n\nAn unusual error has been logged" + LOGENTRYNOTE);
                ErrorReporter.logError("The layout changing event's source is not of type \"LayoutEntry\"!");
                return;
            }
            final LayoutEntry layout = (LayoutEntry) e.getSource();
            if (handler.getVisualizator() != null) {
                drawArea.remove(handler.getVisualizator());
            }
            try {
                handler.changeLayout(layout, windowSize);
                drawArea.add(handler.getVisualizator());
                if (satView != null) {
                    satView.add(handler.getSatelliteViewer());
                }
                window.pack();
            } catch (BadLayoutException exc) {
                layout.setSelected(false);
                chosenLayout.setSelected(true);
                if (exc.getType() == ErrorType.EMPTY_GRAPH || exc.getType() == ErrorType.NO_OBJECT) {
                    return;
                }
                try {
                    handler.changeLayout(chosenLayout, windowSize);
                    drawArea.add(handler.getVisualizator());
                    if (satView != null) {
                        satView.add(handler.getSatelliteViewer());
                    }
                    window.pack();
                    monitor.done();
                } catch (BadLayoutException exc2) {
                    monitor.done();
                    if (exc2.getType() != ErrorType.CYCLIC_GRAPH && exc2.getType() != ErrorType.EMPTY_GRAPH) {
                        errorHandler.reportException("Error while creating layout", exc2);
                    } else {
                        errorHandler.reportErrorMessage(exc2.getMessage());
                    }
                } catch (IllegalStateException exc3) {
                    monitor.done();
                    errorHandler.reportException("Error while creating layout", exc3);
                }
                if (exc.getType() != ErrorType.CYCLIC_GRAPH && exc.getType() != ErrorType.EMPTY_GRAPH) {
                    errorHandler.reportException("Error while creating layout", exc);
                } else {
                    errorHandler.reportErrorMessage(exc.getMessage());
                }
            } catch (IllegalStateException exc) {
                layout.setSelected(false);
                chosenLayout.setSelected(true);
                try {
                    handler.changeLayout(chosenLayout, windowSize);
                    drawArea.add(handler.getVisualizator());
                    if (satView != null) {
                        satView.add(handler.getSatelliteViewer());
                    }
                    window.pack();
                    monitor.done();
                } catch (BadLayoutException exc2) {
                    monitor.done();
                    if (exc2.getType() != ErrorType.CYCLIC_GRAPH && exc2.getType() != ErrorType.EMPTY_GRAPH) {
                        errorHandler.reportException("Error while creating layout", exc2);
                    } else {
                        errorHandler.reportErrorMessage(exc2.getMessage());
                    }
                } catch (IllegalStateException exc3) {
                    monitor.done();
                    errorHandler.reportException("Error while creating layout", exc3);
                }
                errorHandler.reportException("Error while creating layout", exc);
            }
            chosenLayout = layout.newInstance();
            monitor.done();
        }
    };
    final JMenu findMenu = new JMenu("Find");
    final JMenuItem nodeByName = new JMenuItem("Node by name (Ctrl+F)");
    final GraphEditor thisEditor = this;
    nodeByName.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (wndFind != null) {
                        wndFind.close();
                    }
                    try {
                        wndFind = new FindWindow<NodeDescriptor>(editorComposite.getShell(), thisEditor, graph.getVertices());
                        wndFind.open();
                    } catch (IllegalArgumentException e) {
                        errorHandler.reportException("", e);
                    }
                }
            });
        }
    });
    findMenu.add(nodeByName);
    final JMenu tools = new JMenu("Tools");
    final JMenuItem findCircles = new JMenuItem("Show circles");
    final JMenuItem findPaths = new JMenuItem("Show parallel paths");
    final JMenuItem clearResults = new JMenuItem("Clear Results");
    findCircles.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent ev) {
            final Job circlesJob = new Job("Searching for circles") {

                @Override
                protected IStatus run(final IProgressMonitor monitor) {
                    if (graph == null) {
                        return null;
                    }
                    CircleCheck<NodeDescriptor, EdgeDescriptor> checker = new CircleCheck<NodeDescriptor, EdgeDescriptor>(graph);
                    if (checker.isCyclic()) {
                        for (EdgeDescriptor e : graph.getEdges()) {
                            e.setColour(Color.lightGray);
                        }
                        for (Deque<EdgeDescriptor> st : checker.getCircles()) {
                            for (EdgeDescriptor e : st) {
                                e.setColour(NodeColours.DARK_RED);
                            }
                        }
                        refresh();
                    } else {
                        errorHandler.reportInformation("Result:\n\nThis graph is not cyclic!");
                    }
                    return Status.OK_STATUS;
                }
            };
            // end job
            circlesJob.schedule();
        }
    });
    findPaths.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent ev) {
            final Job pathsJob = new Job("Searching for parallel paths") {

                @Override
                protected IStatus run(final IProgressMonitor monitor) {
                    if (graph == null) {
                        return null;
                    }
                    CheckParallelPaths<NodeDescriptor, EdgeDescriptor> checker = null;
                    checker = new CheckParallelPaths<NodeDescriptor, EdgeDescriptor>(graph);
                    if (checker.hasParallelPaths()) {
                        for (EdgeDescriptor e : graph.getEdges()) {
                            e.setColour(Color.lightGray);
                        }
                        for (Deque<EdgeDescriptor> list : checker.getPaths()) {
                            for (EdgeDescriptor e : list) {
                                e.setColour(NodeColours.DARK_RED);
                            }
                        }
                        refresh();
                    } else {
                        errorHandler.reportInformation("Result:\n\nThere are no parallel paths in this graph!");
                    }
                    return Status.OK_STATUS;
                }
            };
            // end job
            pathsJob.schedule();
        }
    });
    clearResults.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent ev) {
            for (final EdgeDescriptor e : graph.getEdges()) {
                e.setColour(Color.black);
            }
            refresh();
        }
    });
    tools.add(findCircles);
    tools.add(findPaths);
    tools.add(clearResults);
    menuBar.add(mnFile);
    menuBar.add(findMenu);
    menuBar.add(tools);
    menuBar.add(layoutMenu);
    // TODO implement refresh action
    /*
		 * JMenuItem RefreshMenu=new JMenuItem("Refresh"); ActionListener
		 * RefreshAction=new ActionListener() { public void
		 * actionPerformed(ActionEvent ev) { GraphGenerator.schedule(); } };
		 * RefreshMenu.addActionListener(RefreshAction);
		 *
		 * menuBar.add(RefreshMenu);
		 */
    handlerService.activateHandler(GRAPH_SEARCHCMD_ID, new AbstractHandler() {

        @Override
        public Object execute(final ExecutionEvent event) throws ExecutionException {
            nodeByName.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
        }
    });
    handlerService.activateHandler(GRAPH_SAVECMD_ID, new AbstractHandler() {

        @Override
        public Object execute(final ExecutionEvent event) throws ExecutionException {
            mntmSave.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
        }
    });
    handlerService.activateHandler(GRAPH_EXPORTCMD_ID, new AbstractHandler() {

        @Override
        public Object execute(final ExecutionEvent event) throws ExecutionException {
            mntmExportToImage.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
        }
    });
    try {
        generator.generateGraph();
        setLabeller(generator.getLabeler());
        setGraph(generator.getGraph());
    } catch (InterruptedException ex) {
        errorHandler.reportException("Error while creating the graph", ex);
    }
}
Also used : JPanel(javax.swing.JPanel) IStatus(org.eclipse.core.runtime.IStatus) BadLayoutException(org.eclipse.titanium.graph.visualization.BadLayoutException) ActionEvent(java.awt.event.ActionEvent) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) ImageExportType(org.eclipse.titanium.graph.visualization.GraphHandler.ImageExportType) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) AbstractHandler(org.eclipse.core.commands.AbstractHandler) CheckParallelPaths(org.eclipse.titanium.graph.utils.CheckParallelPaths) LayoutEntry(org.eclipse.titanium.graph.gui.utils.LayoutEntry) CircleCheck(org.eclipse.titanium.graph.utils.CircleCheck) JMenuItem(javax.swing.JMenuItem) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException) QualifiedName(org.eclipse.core.runtime.QualifiedName) Dimension(java.awt.Dimension) Deque(java.util.Deque) CoreException(org.eclipse.core.runtime.CoreException) BadLayoutException(org.eclipse.titanium.graph.visualization.BadLayoutException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ActionListener(java.awt.event.ActionListener) CoreException(org.eclipse.core.runtime.CoreException) ButtonGroup(javax.swing.ButtonGroup) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ExportImagePreferencesDialog(org.eclipse.titanium.graph.gui.dialogs.ExportImagePreferencesDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 18 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class ModuleGraphEditor method initWindow.

@Override
protected void initWindow() {
    super.initWindow();
    isom.addActionListener(layoutListener);
    layoutGroup.add(isom);
    layoutMenu.add(isom);
    kk.addActionListener(layoutListener);
    layoutGroup.add(kk);
    layoutMenu.add(kk);
    fr.addActionListener(layoutListener);
    layoutGroup.add(fr);
    layoutMenu.add(fr);
    spring.addActionListener(layoutListener);
    layoutMenu.add(spring);
    layoutGroup.add(spring);
    circle.addActionListener(layoutListener);
    layoutMenu.add(circle);
    layoutGroup.add(circle);
    final JMenu dagMenu = new JMenu("Directed layouts");
    layoutMenu.add(dagMenu);
    tdag.setSelected(true);
    tdag.addActionListener(layoutListener);
    dagMenu.add(tdag);
    layoutGroup.add(tdag);
    rtdag.addActionListener(layoutListener);
    dagMenu.add(rtdag);
    layoutGroup.add(rtdag);
    layoutMenu.add(metricLayoutMenu);
    final ActionListener changeMetrics = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            MetricsEntry metric = (MetricsEntry) e.getSource();
            chosenMetric = metric;
            for (NodeDescriptor node : graph.getVertices()) {
                ((MeasureableGraphHandler) handler).calculateColour(node, chosenMetric.getMetric());
            }
            drawArea.repaint();
            if (satView != null) {
                satView.repaint();
            }
        }
    };
    boolean isFirst = true;
    // Creating the metric-selection menu:
    JMenu actMenu = new JMenu(ModuleMetric.GROUP_NAME);
    JMenu actLayoutMenu = new JMenu(ModuleMetric.GROUP_NAME);
    metricsMenu.add(actMenu);
    metricLayoutMenu.add(actLayoutMenu);
    for (final ModuleMetric metric : ModuleMetric.values()) {
        if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
            continue;
        }
        final MetricsEntry item = new MetricsEntry(metric.getName(), metric);
        if (isFirst) {
            item.setSelected(true);
            chosenMetric = item;
            isFirst = false;
        }
        item.addActionListener(changeMetrics);
        metricsGroup.add(item);
        actMenu.add(item);
        final MetricsLayoutEntry layoutItem = new MetricsLayoutEntry(metric);
        layoutItem.addActionListener(layoutListener);
        layoutGroup.add(layoutItem);
        actLayoutMenu.add(layoutItem);
    }
    actMenu = new JMenu(AltstepMetric.GROUP_NAME);
    actLayoutMenu = new JMenu(AltstepMetric.GROUP_NAME);
    metricsMenu.add(actMenu);
    metricLayoutMenu.add(actLayoutMenu);
    for (final AltstepMetric metric : AltstepMetric.values()) {
        if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
            continue;
        }
        final MetricsEntry item = new MetricsEntry(metric.getName(), metric);
        item.addActionListener(changeMetrics);
        metricsGroup.add(item);
        actMenu.add(item);
        final MetricsLayoutEntry layoutItem = new MetricsLayoutEntry(metric);
        layoutItem.addActionListener(layoutListener);
        layoutGroup.add(layoutItem);
        actLayoutMenu.add(layoutItem);
    }
    actMenu = new JMenu(FunctionMetric.GROUP_NAME);
    actLayoutMenu = new JMenu(FunctionMetric.GROUP_NAME);
    metricLayoutMenu.add(actLayoutMenu);
    metricsMenu.add(actMenu);
    for (final FunctionMetric metric : FunctionMetric.values()) {
        if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
            continue;
        }
        final MetricsEntry item = new MetricsEntry(metric.getName(), metric);
        item.addActionListener(changeMetrics);
        metricsGroup.add(item);
        actMenu.add(item);
        final MetricsLayoutEntry layoutItem = new MetricsLayoutEntry(metric);
        layoutItem.addActionListener(layoutListener);
        layoutGroup.add(layoutItem);
        actLayoutMenu.add(layoutItem);
    }
    actMenu = new JMenu(TestcaseMetric.GROUP_NAME);
    actLayoutMenu = new JMenu(TestcaseMetric.GROUP_NAME);
    metricLayoutMenu.add(actLayoutMenu);
    metricsMenu.add(actMenu);
    for (final TestcaseMetric metric : TestcaseMetric.values()) {
        if (!PreferenceManager.isEnabledOnModuleGraph(metric)) {
            continue;
        }
        final MetricsEntry item = new MetricsEntry(metric.getName(), metric);
        item.addActionListener(changeMetrics);
        metricsGroup.add(item);
        actMenu.add(item);
        final MetricsLayoutEntry layoutItem = new MetricsLayoutEntry(metric);
        layoutItem.addActionListener(layoutListener);
        layoutGroup.add(layoutItem);
        actLayoutMenu.add(layoutItem);
    }
    final JMenuItem recalcItem = new JMenuItem("Recalculate metrics");
    recalcItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            WrapperStore.clearStore();
            GlobalParser.reAnalyzeSemantically();
            recolour(graph.getVertices());
            if (chosenLayout instanceof MetricsLayoutEntry) {
                chosenLayout.doClick();
            }
        }
    });
    metricsMenu.add(recalcItem);
    folderKnotCluster.addActionListener(new ClusteringAction("foldername", true));
    knotClusteringMenu.add(folderKnotCluster);
    folderGraphCluster.addActionListener(new ClusteringAction("foldername", false));
    graphClusteringMenu.add(folderGraphCluster);
    linkedKnotCluster.addActionListener(new ClusteringAction("linkedlocation", true));
    knotClusteringMenu.add(linkedKnotCluster);
    linkedGraphCluster.addActionListener(new ClusteringAction("linkedlocation", false));
    graphClusteringMenu.add(linkedGraphCluster);
    locationKnotCluster.addActionListener(new ClusteringAction("modulelocation", true));
    knotClusteringMenu.add(locationKnotCluster);
    locationGraphCluster.addActionListener(new ClusteringAction("modulelocation", false));
    graphClusteringMenu.add(locationGraphCluster);
    regKnotCluster.addActionListener(new ClusteringAction("regularexpression", true));
    knotClusteringMenu.add(regKnotCluster);
    regGraphCluster.addActionListener(new ClusteringAction("regularexpression", false));
    graphClusteringMenu.add(regGraphCluster);
    nameKnotCluster.addActionListener(new ClusteringAction("modulename", true));
    knotClusteringMenu.add(nameKnotCluster);
    nameGraphCluster.addActionListener(new ClusteringAction("modulename", false));
    nameClusteringMenu.add(nameGraphCluster);
    fullNameGraphCluster.addActionListener(new ClusteringAction("fullmodulenametree", false, (LayoutEntry) tdag));
    nameClusteringMenu.add(fullNameGraphCluster);
    sparseNameGraphCluster.addActionListener(new ClusteringAction("sparsemodulenametree", false, (LayoutEntry) tdag));
    nameClusteringMenu.add(sparseNameGraphCluster);
    autoKnotCluster.addActionListener(new ClusteringAction("automatic", true));
    knotClusteringMenu.add(autoKnotCluster);
    closeGraphClusters.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            chosenLayout.setSelected(false);
            tdag.setSelected(true);
            chosenLayout = (LayoutEntry) tdag;
            enableModuleMenus(true);
            setGraph(originalGraph);
        }
    });
    closeGraphClusters.setEnabled(false);
    menuBar.add(metricsMenu);
    clusteringMenu.add(knotClusteringMenu);
    graphClusteringMenu.add(nameClusteringMenu);
    clusteringMenu.add(graphClusteringMenu);
    clusteringMenu.add(closeGraphClusters);
    menuBar.add(clusteringMenu);
}
Also used : MeasureableGraphHandler(org.eclipse.titanium.graph.visualization.MeasureableGraphHandler) MetricsEntry(org.eclipse.titanium.graph.gui.utils.MetricsEntry) ActionEvent(java.awt.event.ActionEvent) MetricsLayoutEntry(org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) FunctionMetric(org.eclipse.titanium.metrics.FunctionMetric) TestcaseMetric(org.eclipse.titanium.metrics.TestcaseMetric) ModuleMetric(org.eclipse.titanium.metrics.ModuleMetric) ActionListener(java.awt.event.ActionListener) AltstepMetric(org.eclipse.titanium.metrics.AltstepMetric) MetricsLayoutEntry(org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry) LayoutEntry(org.eclipse.titanium.graph.gui.utils.LayoutEntry) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 19 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class AutomaticCluster method calculatePriority.

/**
 * Calculate the priority of the node. The lower it is, the higher change is
 * possible in the MQ.
 *
 * @param v
 *            The node
 */
private int calculatePriority(final NodeDescriptor v) {
    final int indexv = mapClusterIndex.get(v);
    int prior = 0;
    for (final NodeDescriptor w : moduleGraph.getNeighbors(v)) {
        final int indexw = mapClusterIndex.get(w);
        if (indexv == indexw) {
            prior++;
        } else {
            prior--;
        }
    }
    prior *= size.get(indexv);
    return prior;
}
Also used : NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor)

Example 20 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class AutomaticCluster method createCurrentClusters.

/**
 * Creates the clusters using the current state of the algorithm.
 */
private void createCurrentClusters() {
    clustersToCheck = new HashSet<Set<NodeDescriptor>>();
    for (final int i : indices) {
        final Set<NodeDescriptor> cluster = mapIndexCluster.get(i);
        cluster.clear();
    }
    for (final NodeDescriptor v : moduleGraph.getVertices()) {
        final Set<NodeDescriptor> cluster = mapIndexCluster.get(mapClusterIndex.get(v));
        cluster.add(v);
        v.setCluster(cluster);
    }
    for (final int i : indices) {
        final Set<NodeDescriptor> cluster = mapIndexCluster.get(i);
        if (!cluster.isEmpty()) {
            clustersToCheck.add(cluster);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor)

Aggregations

NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)30 EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)10 HashSet (java.util.HashSet)7 HashMap (java.util.HashMap)5 Set (java.util.Set)5 Dimension (java.awt.Dimension)4 CustomVisualizationViewer (org.eclipse.titanium.graph.gui.common.CustomVisualizationViewer)3 DirectedSparseGraph (edu.uci.ics.jung.graph.DirectedSparseGraph)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Point2D (java.awt.geom.Point2D)2 Matcher (java.util.regex.Matcher)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 IResource (org.eclipse.core.resources.IResource)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 ClusterNode (org.eclipse.titanium.graph.clustering.visualization.ClusterNode)2 LayoutEntry (org.eclipse.titanium.graph.gui.utils.LayoutEntry)2 MetricsLayoutEntry (org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry)2 Function (com.google.common.base.Function)1