Search in sources :

Example 6 with StateEdit

use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.

the class OnePairShortestPathFilter method callFilter.

/**
 * Calls backend filter.
 */
private void callFilter() {
    if (startSet != null && startSet.size() > 0 && endSet != null && endSet.size() > 0) {
        final SimpleMonitor monitor = new SimpleMonitor("preparing...", (startSet.size() * endSet.size()) + 1);
        Thread filterThread = new Thread("shortest path filter thread") {

            public void run() {
                // contains results
                Set<ONDEXConcept> concepts = null;
                Set<ONDEXRelation> relations = null;
                boolean useweights = !(ANselection == null || ANselection.equals(// no nullpointer danger because of
                defVal));
                // lazy
                // evaluation!
                boolean aborted = false;
                StringBuilder messages = new StringBuilder("Errors occurred during operation:\n");
                long before = System.currentTimeMillis();
                // multiple filter calls
                Iterator<ONDEXConcept> it = startSet.iterator();
                while (it.hasNext()) {
                    ONDEXConcept startConcept = it.next();
                    Iterator<ONDEXConcept> it2 = endSet.iterator();
                    while (it2.hasNext()) {
                        ONDEXConcept endConcept = it2.next();
                        if (startConcept.equals(endConcept))
                            continue;
                        String message = null;
                        // create new filter
                        Filter filter = new Filter();
                        try {
                            // construct filter arguments
                            ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
                            fa.addOption(ArgumentNames.STARTCONCEPT_ARG, startConcept.getId());
                            fa.addOption(ArgumentNames.STOPCONCEPT_ARG, endConcept.getId());
                            fa.addOption(ArgumentNames.ONLYDIRECTED_ARG, dirBox.isSelected());
                            fa.addOption(ArgumentNames.USEWEIGHTS_ARG, useweights);
                            if (useweights)
                                fa.addOption(ArgumentNames.WEIGHTATTRIBUTENAME_ARG, ANselection);
                            fa.addOption(ArgumentNames.INVERSE_WEIGHT_ARG, invBox.isSelected());
                            filter.addONDEXListener(new ONDEXLogger());
                            filter.setONDEXGraph(graph);
                            filter.setArguments(fa);
                            filter.start();
                        } catch (Exception e) {
                            if (e.getMessage() != null)
                                message = e.getMessage();
                            else
                                message = e.toString();
                        }
                        if (message == null) {
                            if (concepts == null) {
                                concepts = filter.getVisibleConcepts();
                                relations = filter.getVisibleRelations();
                            } else {
                                concepts = BitSetFunctions.or(concepts, filter.getVisibleConcepts());
                                relations = BitSetFunctions.or(relations, filter.getVisibleRelations());
                            }
                        } else {
                            messages.append(message + "\n");
                        }
                        aborted = !monitor.next(MonitoringToolKit.calculateWaitingTime(before, monitor));
                        if (aborted) {
                            break;
                        }
                    }
                    if (aborted) {
                        break;
                    }
                }
                if (!aborted) {
                    if (concepts != null) {
                        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
                        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
                        desktop.setRunningProcess(this.getName());
                        // set all relations to invisible
                        for (ONDEXRelation r : graph.getRelations()) {
                            graph.setVisibility(r, false);
                        }
                        // set all concepts to invisible
                        for (ONDEXConcept c : graph.getConcepts()) {
                            graph.setVisibility(c, false);
                        }
                        // first set concepts visible
                        for (ONDEXConcept c : concepts) {
                            graph.setVisibility(c, true);
                        }
                        // second set relations visible
                        for (ONDEXRelation r : relations) {
                            graph.setVisibility(r, true);
                        }
                        // propagate change to viewer
                        viewer.getVisualizationViewer().getModel().fireStateChanged();
                        edit.end();
                        viewer.getUndoManager().addEdit(edit);
                        desktop.getOVTK2Menu().updateUndoRedo(viewer);
                        desktop.notifyTerminationOfProcess();
                        monitor.complete();
                    } else {
                        monitor.complete();
                        JOptionPane.showMessageDialog(OVTK2Desktop.getInstance().getMainFrame(), messages.toString(), "Error", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        };
        OVTKProgressMonitor.start(OVTK2Desktop.getInstance().getMainFrame(), "Shortest path filter", monitor);
        filterThread.start();
    }
}
Also used : OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) SimpleMonitor(net.sourceforge.ondex.tools.threading.monitoring.SimpleMonitor) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.onepairshortestpath.Filter) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger)

Example 7 with StateEdit

use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.

the class AllPairsShortestPathFilter method filter.

/**
 * starts the actual filter.
 *
 * @param attributeName
 *            the ID of the attribute name that contains the edge weight.
 * @param directed
 *            to switch between directed/undirected mode.
 */
private void filter(String attributeName, boolean directed, boolean inverse) throws InvalidPluginArgumentException {
    StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
    OVTK2Desktop desktop = OVTK2Desktop.getInstance();
    desktop.setRunningProcess(this.getName());
    ArgumentDefinition<?>[] args = filter.getArgumentDefinitions();
    ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
    String name = null;
    Object value = null;
    for (ArgumentDefinition<?> arg : args) {
        name = arg.getName();
        if (name.equals(ArgumentNames.WEIGHTATTRIBUTENAME_ARG))
            value = attributeName;
        else if (name.equals(ArgumentNames.ONLYDIRECTED_ARG))
            value = Boolean.valueOf(directed);
        fa.addOption(name, value);
        if (name.equals(ArgumentNames.INVERSE_WEIGHT_ARG))
            value = Boolean.valueOf(inverse);
    }
    filter.setONDEXGraph(graph);
    filter.setArguments(fa);
    OVTKProgressMonitor.notifyInitializationDone(filter);
    filter.start();
    // set all concepts to visible
    for (ONDEXConcept c : graph.getConcepts()) {
        graph.setVisibility(c, true);
    }
    // set all relations to invisible
    for (ONDEXRelation r : graph.getRelations()) {
        graph.setVisibility(r, false);
    }
    // set filter results to visible
    for (ONDEXRelation r : filter.getVisibleRelations()) {
        graph.setVisibility(r, true);
    }
    // propagate change to viewer
    viewer.getVisualizationViewer().getModel().fireStateChanged();
    edit.end();
    viewer.getUndoManager().addEdit(edit);
    desktop.getOVTK2Menu().updateUndoRedo(viewer);
    desktop.notifyTerminationOfProcess();
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) ArgumentDefinition(net.sourceforge.ondex.args.ArgumentDefinition) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)

Example 8 with StateEdit

use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.

the class RelationTypeFilter method callFilter.

/**
 * Calls backend filter.
 */
private void callFilter() throws InvalidPluginArgumentException {
    if (targets != null && targets.size() > 0) {
        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
        desktop.setRunningProcess(this.getName());
        // new instance of filter and set arguments
        Filter filter = new Filter();
        // construct filter arguments
        ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
        Iterator<RelationType> it = targets.iterator();
        while (it.hasNext()) {
            fa.addOption(Filter.TARGETRTSET_ARG, it.next().getId());
        }
        filter.setONDEXGraph(graph);
        filter.setArguments(fa);
        // execute filter
        filter.start();
        // get results from filter
        Set<ONDEXConcept> concepts = filter.getInVisibleConcepts();
        Set<ONDEXRelation> relations = filter.getInVisibleRelations();
        // check for visibility selection
        if (visibility) {
            // first set concepts visible
            for (ONDEXConcept c : concepts) {
                graph.setVisibility(c, true);
            }
            // second set relations visible
            for (ONDEXRelation r : relations) {
                graph.setVisibility(r, true);
            }
        } else {
            // change visibility of relations
            for (ONDEXRelation r : relations) {
                graph.setVisibility(r, false);
            }
            // change visibility of concepts
            for (ONDEXConcept c : concepts) {
                graph.setVisibility(c, false);
            }
        }
        // propagate change to viewer
        viewer.getVisualizationViewer().getModel().fireStateChanged();
        edit.end();
        viewer.getUndoManager().addEdit(edit);
        desktop.getOVTK2Menu().updateUndoRedo(viewer);
        desktop.notifyTerminationOfProcess();
    }
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.relationtype.Filter) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) RelationType(net.sourceforge.ondex.core.RelationType) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)

Example 9 with StateEdit

use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.

the class ThresholdFilter method callFilter.

/**
 * Calls backend filter.
 */
private void callFilter() throws InvalidPluginArgumentException {
    StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
    OVTK2Desktop desktop = OVTK2Desktop.getInstance();
    desktop.setRunningProcess(this.getName());
    // setup filter and start
    Filter filter = new Filter();
    // compile filter arguments
    ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
    fa.addOption(Filter.CONCEPTMODE_ARG, conceptModeSelected);
    fa.addOption(Filter.TARGETAN_ARG, targetAttributeName.getId());
    fa.addOption(Filter.SIG_ARG, (double) ((XYPlot) chart.getPlot()).getDomainCrosshairValue());
    fa.addOption(Filter.INVERSE_ARG, inverseFiltering.isSelected());
    fa.addOption(Filter.ABSOLUTE_ARG, useAbsoluteValues.isSelected());
    fa.addOption(Filter.NO_ATT_ARG, hideNoAttributeElements.isSelected());
    filter.setONDEXGraph(graph);
    filter.setArguments(fa);
    filter.start();
    // set visible concepts again visible
    Set<ONDEXConcept> concepts = filter.getVisibleConcepts();
    Set<ONDEXRelation> relations = filter.getVisibleRelations();
    // remove unconnected nodes
    if (hideUnconnectedConcepts.isSelected()) {
        concepts = StandardFunctions.filteroutUnconnected(graph, concepts, relations);
    }
    // assigns a number in Attribute per connected component
    if (subsets.isAssignCategories()) {
        AttributeName att = createAttName(graph, subsets.getCategoryName(), Integer.class);
        Set<ONDEXConcept> unprocessedConcepts = BitSetFunctions.copy(concepts);
        Set<ONDEXRelation> unprocessedRelations = BitSetFunctions.copy(relations);
        Set<Integer> takenIds = new HashSet<Integer>();
        Integer lastId = 1;
        while (unprocessedConcepts.size() > 0) {
            BitSet[] group = StandardFunctions.getAllConnected(unprocessedConcepts.iterator().next(), graph, unprocessedRelations);
            Set<ONDEXConcept> concGroup = BitSetFunctions.create(graph, ONDEXConcept.class, group[0]);
            unprocessedConcepts = BitSetFunctions.andNot(unprocessedConcepts, concGroup);
            SortedMap<Integer, Object> prevalence = StandardFunctions.gdsRanking(graph, concGroup, att.getId());
            Integer groupID = 1;
            if (prevalence.size() != 0)
                groupID = Integer.valueOf(prevalence.get(prevalence.lastKey()).toString());
            if (groupID == null || takenIds.contains(groupID)) {
                groupID = lastId + 1;
                while (takenIds.contains(groupID)) groupID++;
                lastId = groupID;
            }
            takenIds.add(groupID);
            // taken from JAVA Doc how to iterate a BitSet
            for (int i = group[0].nextSetBit(0); i >= 0; i = group[0].nextSetBit(i + 1)) {
                ONDEXConcept c = graph.getConcept(i);
                if (c.getAttribute(att) != null) {
                    c.deleteAttribute(att);
                }
                c.createAttribute(att, groupID, false);
            }
        }
    }
    Set<ONDEXConcept> invisibleConcepts = BitSetFunctions.andNot(graph.getConcepts(), concepts);
    Set<ONDEXRelation> invisibleRelations = BitSetFunctions.andNot(graph.getRelations(), relations);
    // set visible concepts again visible
    for (ONDEXConcept c : concepts) {
        graph.setVisibility(c, true);
    }
    // set visible relations again visible
    for (ONDEXRelation r : relations) {
        graph.setVisibility(r, true);
    }
    // set invisible relations invisible
    for (ONDEXRelation r : invisibleRelations) {
        graph.setVisibility(r, false);
    }
    // set invisible concepts invisible
    for (ONDEXConcept c : invisibleConcepts) {
        graph.setVisibility(c, false);
    }
    // propagate change to viewer
    viewer.getVisualizationViewer().getModel().fireStateChanged();
    edit.end();
    viewer.getUndoManager().addEdit(edit);
    desktop.getOVTK2Menu().updateUndoRedo(viewer);
    desktop.notifyTerminationOfProcess();
}
Also used : OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) BitSet(java.util.BitSet) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) XYPlot(org.jfree.chart.plot.XYPlot) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.significance.Filter) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) AttributeName(net.sourceforge.ondex.core.AttributeName) HashSet(java.util.HashSet)

Example 10 with StateEdit

use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.

the class EntityMenuItem method init.

/**
 * Adds ActionListener to item and sets viewer and entity set.
 *
 * @param v
 *            OVTK2Viewer
 * @param e
 *            Set<E>
 */
public void init(final OVTK2PropertiesAggregator v, final Set<E> e) {
    this.viewer = v;
    this.entities = e;
    // required to trigger any action
    item.addActionListener(new ActionListener() {

        public final void actionPerformed(ActionEvent e) {
            // set to waiting cursor
            Cursor cursor = v.getVisualizationViewer().getCursor();
            v.getVisualizationViewer().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            RootPaneContainer root = findRoot((Component) v);
            root.getGlassPane().setVisible(true);
            root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            // StateEdit system, start edit
            StateEdit edit = null;
            if (getUndoPropertyName() != null) {
                edit = new StateEdit(new VisibilityUndo(v.getONDEXJUNGGraph()), Config.language.getProperty(getUndoPropertyName()));
                v.getUndoManager().addEdit(edit);
                if (v instanceof OVTK2Viewer)
                    OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(v);
            }
            try {
                // trigger action
                doAction();
            } finally {
                // StateEdit system, end edit
                if (edit != null) {
                    v.getVisualizationViewer().repaint();
                    edit.end();
                }
                // restore cursor
                root.getGlassPane().setVisible(false);
                v.getVisualizationViewer().setCursor(cursor);
            }
            v.getVisualizationViewer().repaint();
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) RootPaneContainer(javax.swing.RootPaneContainer) Cursor(java.awt.Cursor) Component(java.awt.Component) StateEdit(javax.swing.undo.StateEdit) OVTK2Viewer(net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)

Aggregations

StateEdit (javax.swing.undo.StateEdit)23 VisibilityUndo (net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)23 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)21 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)20 OVTK2Desktop (net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop)16 ONDEXPluginArguments (net.sourceforge.ondex.ONDEXPluginArguments)13 OVTK2Filter (net.sourceforge.ondex.ovtk2.filter.OVTK2Filter)12 HashSet (java.util.HashSet)7 PropertyVetoException (java.beans.PropertyVetoException)4 ConceptClass (net.sourceforge.ondex.core.ConceptClass)4 ONDEXLogger (net.sourceforge.ondex.logging.ONDEXLogger)4 InvalidPluginArgumentException (net.sourceforge.ondex.InvalidPluginArgumentException)3 RelationType (net.sourceforge.ondex.core.RelationType)3 BitSet (java.util.BitSet)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JComboBox (javax.swing.JComboBox)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 Attribute (net.sourceforge.ondex.core.Attribute)2 IntegerStringWrapper (net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper)2