Search in sources :

Example 1 with StateEdit

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

the class InteractiveGenomicFilter method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    /*
		 * change graph to genomic view
		 */
    if (cmd.equals("view")) {
        switchToGenomicLayout();
        if (viewer.isIcon()) {
            try {
                viewer.setIcon(false);
            } catch (PropertyVetoException pve) {
            // ignore, can't help
            }
        }
    } else /*
		 * populate table with user selection
		 */
    if (cmd.equals("update")) {
        panelConfig.removeAll();
        getSelection();
        panelConfig.add(new JScrollPane(searchTable));
        this.revalidate();
    } else /*
		 * insert a default row
		 */
    if (cmd.equals("insert")) {
        insertRow();
    } else /*
		 * reset table to default
		 */
    if (cmd.equals("clear")) {
        panelConfig.removeAll();
        defaultTable();
        panelConfig.add(new JScrollPane(searchTable));
        this.revalidate();
    } else if (cmd.equals("hide")) {
        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
        desktop.setRunningProcess(this.getName());
        if (toggleSearchResults) {
            // preserve for making visible again
            invisibleConcepts = new HashSet<ONDEXConcept>();
            invisibleRelations = new HashSet<ONDEXRelation>();
            // set relations that are NOT on a path to invisible
            for (ONDEXRelation r : graph.getEdges()) {
                if (rels != null && !rels.contains(r)) {
                    graph.setVisibility(r, false);
                    invisibleRelations.add(r);
                }
            }
            // now set concepts that become unconnected to invisible
            for (ONDEXConcept c : graph.getVertices()) {
                if (graph.getNeighborCount(c) == 0) {
                    graph.setVisibility(c, false);
                    invisibleConcepts.add(c);
                }
            }
            toggleSearchResults = false;
        } else {
            graph.setVisibility(invisibleConcepts, true);
            graph.setVisibility(invisibleRelations, true);
            toggleSearchResults = true;
        }
        viewer.getVisualizationViewer().getModel().fireStateChanged();
        edit.end();
        viewer.getUndoManager().addEdit(edit);
        desktop.getOVTK2Menu().updateUndoRedo(viewer);
        desktop.notifyTerminationOfProcess();
    } else /*
		 * do the search
		 */
    if (cmd.equals("searchRegion")) {
        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
        desktop.setRunningProcess(this.getName());
        toggleSearchResults = true;
        invisibleConcepts = null;
        invisibleRelations = null;
        performSearch();
        // if keywords are provided set not related genes to invisible
        if (!textFieldSearch.getText().trim().isEmpty())
            hideGenesButton.doClick();
        edit.end();
        viewer.getUndoManager().addEdit(edit);
        desktop.getOVTK2Menu().updateUndoRedo(viewer);
        desktop.notifyTerminationOfProcess();
        if (viewer.isIcon()) {
            try {
                viewer.setIcon(false);
            } catch (PropertyVetoException pve) {
            // ignore, can't help
            }
        }
    } else /*
		 * do the search
		 */
    if (cmd.equals("searchGenome")) {
        // get search keyword
        String keyword = textFieldSearch.getText();
        if (!keyword.isEmpty()) {
            toggleSearchResults = true;
            invisibleConcepts = null;
            invisibleRelations = null;
            StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
            OVTK2Desktop desktop = OVTK2Desktop.getInstance();
            desktop.setRunningProcess(this.getName());
            // set first entire graph to invisible
            setGraphVisible(false);
            searchGenome(keyword);
            // new Attribute layout
            GDSPositionLayout layout = new GDSPositionLayout(viewer);
            // propagate change to viewer
            VisualizationModel<ONDEXConcept, ONDEXRelation> model = viewer.getVisualizationViewer().getModel();
            model.setGraphLayout(layout);
            model.fireStateChanged();
            viewer.center();
            edit.end();
            viewer.getUndoManager().addEdit(edit);
            desktop.getOVTK2Menu().updateUndoRedo(viewer);
            desktop.notifyTerminationOfProcess();
            if (viewer.isIcon()) {
                try {
                    viewer.setIcon(false);
                } catch (PropertyVetoException pve) {
                // ignore, can't help
                }
            }
        }
    } else /*
		 * toggle inter-relations
		 */
    if (cmd.equals("relations")) {
        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
        desktop.setRunningProcess(this.getName());
        RelationType rt = graph.getMetaData().getRelationType("enc");
        toggleRelations = !toggleRelations;
        for (ONDEXRelation r : graph.getRelationsOfRelationType(rt)) {
            graph.setVisibility(r, toggleRelations);
        }
        viewer.getVisualizationViewer().getModel().fireStateChanged();
        edit.end();
        viewer.getUndoManager().addEdit(edit);
        desktop.getOVTK2Menu().updateUndoRedo(viewer);
        desktop.notifyTerminationOfProcess();
    } else /*
		 * actions that happen when changing chromosome or QTL column
		 */
    if (e.getSource() instanceof JComboBox) {
        Object obj = ((JComboBox) e.getSource()).getSelectedItem();
        if (obj instanceof String || searchTable == null) {
            return;
        }
        DefaultTableModel model = (DefaultTableModel) searchTable.getModel();
        int rowNum = searchTable.getSelectedRow();
        int colNum = searchTable.getSelectedColumn();
        IntegerStringWrapper isw = (IntegerStringWrapper) obj;
        if (colNum == 1) {
            ONDEXConcept chrom = graph.getConcept(isw.getValue());
            // ignore scaffolds
            if (chrom.getAttribute(anChromosome) != null) {
                int chromNum = (Integer) chrom.getAttribute(anChromosome).getValue();
                JComboBox qtlBox = createQTLComboBox(chromNum);
                DefaultCellEditor qtlEditor = new DefaultCellEditor(qtlBox);
                rm.addEditorForRow(rowNum, qtlEditor);
            }
        } else // QTL column
        if (colNum == 4) {
            ONDEXConcept qtl = graph.getConcept(isw.getValue());
            // TODO: why is colNum 4 sometimes of Type Chromosome?
            if (qtl.getOfType().getId().equals("QTL")) {
                Integer newBeg = (Integer) qtl.getAttribute(anBegin).getValue();
                Integer newEnd = (Integer) qtl.getAttribute(anEnd).getValue();
                model.setValueAt(newBeg, rowNum, 2);
                model.setValueAt(newEnd, rowNum, 3);
            } else {
            // System.out.println("COLUMN IS 4 BUT ELEMENT: "+
            // qtl.getOfType().getId());
            }
        }
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) IntegerStringWrapper(net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper) JComboBox(javax.swing.JComboBox) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) DefaultTableModel(javax.swing.table.DefaultTableModel) GDSPositionLayout(net.sourceforge.ondex.ovtk2.layout.GDSPositionLayout) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) DefaultCellEditor(javax.swing.DefaultCellEditor) PropertyVetoException(java.beans.PropertyVetoException) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) RelationType(net.sourceforge.ondex.core.RelationType) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation)

Example 2 with StateEdit

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

the class OVTK2Viewer method showAllRelations.

/**
 * Shows all relations between the currently visible nodes.
 */
public void showAllRelations() {
    StateEdit edit = new StateEdit(new VisibilityUndo(this.getONDEXJUNGGraph()), Config.language.getProperty("Undo.ShowAllRelations"));
    undoManager.addEdit(edit);
    OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(this);
    for (ONDEXConcept ondexNode : graph.getVertices()) {
        for (ONDEXRelation r : graph.getRelationsOfConcept(ondexNode)) {
            graph.setVisibility(r, true);
        }
    }
    edit.end();
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)

Example 3 with StateEdit

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

the class RelationNeighboursFilter method callFilter.

/**
 * Calls backend filter.
 *
 * @throws ParseException
 */
private void callFilter() throws Exception {
    if (targets != null && targets.size() > 0) {
        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
        desktop.setRunningProcess(this.getName());
        // this will also clear the concept list
        PickedState<ONDEXConcept> state = viewer.getVisualizationViewer().getPickedVertexState();
        state.clear();
        // contains results
        Set<ONDEXConcept> concepts = null;
        Set<ONDEXRelation> relations = null;
        // get depth
        depth = slider.getValue();
        // prevent self-loop in interactive mode
        state.removeItemListener(this);
        Set<String> ids = new HashSet<String>();
        // multiple filter calls
        for (ONDEXConcept target : targets) {
            ids.add(String.valueOf(target.getId()));
            // highlight seed concepts
            state.pick(target, true);
        }
        state.addItemListener(this);
        // create new filter
        Filter filter = new Filter();
        // construct filter arguments
        ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
        fa.addOptions(ArgumentNames.SEEDCONCEPT_ARG, ids.toArray(new String[ids.size()]));
        fa.addOption(ArgumentNames.DEPTH_ARG, Integer.valueOf(depth));
        // start filter
        filter.addONDEXListener(new ONDEXLogger());
        filter.setONDEXGraph(graph);
        filter.setArguments(fa);
        filter.start();
        // these are the filter results
        concepts = filter.getVisibleConcepts();
        relations = filter.getVisibleRelations();
        if (concepts != null) {
            // set all relations to invisible
            graph.setVisibility(graph.getRelations(), false);
            // set all concepts to invisible
            graph.setVisibility(graph.getConcepts(), false);
            // first set concepts visible
            graph.setVisibility(concepts, true);
            // second set relations visible
            graph.setVisibility(relations, true);
            // propagate change to viewer
            viewer.getVisualizationViewer().getModel().fireStateChanged();
        }
        // notify desktop
        edit.end();
        viewer.getUndoManager().addEdit(edit);
        desktop.getOVTK2Menu().updateUndoRedo(viewer);
        desktop.notifyTerminationOfProcess();
    }
}
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) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.relationneighbours.Filter) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger) HashSet(java.util.HashSet)

Example 4 with StateEdit

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

the class UnconnectedFilter method callFilter.

private void callFilter() throws InvalidPluginArgumentException {
    StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
    OVTK2Desktop desktop = OVTK2Desktop.getInstance();
    desktop.setRunningProcess(this.getName());
    Set<ONDEXConcept> concepts = new HashSet<ONDEXConcept>(graph.getConcepts());
    if (onVisibleOnly.isSelected() && !visibility) {
        System.out.println("Calculating visible concepts");
        concepts = new HashSet<ONDEXConcept>(graph.getVertices());
    }
    System.out.println("Filtering graph");
    // set visibility of concepts
    for (ONDEXConcept c : concepts) {
        if (graph.getRelationsOfConcept(c).size() == 0)
            graph.setVisibility(c, visibility);
        else // check for applying on visible relations
        if (onVisibleOnly.isSelected()) {
            boolean anyVisible = false;
            for (ONDEXRelation r : graph.getRelationsOfConcept(c)) {
                anyVisible = anyVisible || graph.isVisible(r);
                if (anyVisible)
                    break;
            }
            if (!anyVisible) {
                graph.setVisibility(c, visibility);
            }
        }
    }
    // 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) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) HashSet(java.util.HashSet)

Example 5 with StateEdit

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

the class DegreeFilter method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (ccs != null && ccs.size() > 0) {
        StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
        OVTK2Desktop desktop = OVTK2Desktop.getInstance();
        desktop.setRunningProcess(this.getName());
        // get user selection
        int in = (Integer) indegree.getValue();
        int out = (Integer) outdegree.getValue();
        // contains concepts to be removed
        Set<ONDEXConcept> change = new HashSet<ONDEXConcept>();
        // filter only on concepts of selected concept class
        Iterator<ConceptClass> it = ccs.iterator();
        while (it.hasNext()) {
            ConceptClass cc = it.next();
            Set<ONDEXConcept> concepts = graph.getConceptsOfConceptClass(cc);
            for (ONDEXConcept concept : concepts) {
                // looking at all relations of concept
                Set<ONDEXRelation> relations = graph.getRelationsOfConcept(concept);
                int inTotal = 0;
                int outTotal = 0;
                // count all incoming or outgoing relations
                for (ONDEXRelation relation : relations) {
                    if (relation.getFromConcept().equals(concept) && (rtsOut == null || rtsOut.contains(relation.getOfType()))) {
                        outTotal++;
                    } else if (relation.getToConcept().equals(concept) && (rtsIn == null || rtsIn.contains(relation.getOfType()))) {
                        inTotal++;
                    }
                }
                // default OR combination
                if (logical.getSelectedItem().equals("OR")) {
                    if (outcheck.isSelected()) {
                        String op = outop.getSelectedItem().toString();
                        if (op.equals("<") && outTotal < out) {
                            change.add(concept);
                        } else if (op.equals("=") && outTotal == out) {
                            change.add(concept);
                        } else if (op.equals(">") && outTotal > out) {
                            change.add(concept);
                        }
                    }
                    if (incheck.isSelected()) {
                        String op = inop.getSelectedItem().toString();
                        if (op.equals("<") && inTotal < in) {
                            change.add(concept);
                        } else if (op.equals("=") && inTotal == in) {
                            change.add(concept);
                        } else if (op.equals(">") && inTotal > in) {
                            change.add(concept);
                        }
                    }
                } else // for AND both degrees need to be set
                if (logical.getSelectedItem().equals("AND")) {
                    if (!outcheck.isSelected() || !incheck.isSelected()) {
                        JOptionPane.showInternalMessageDialog(OVTK2Desktop.getInstance().getDesktopPane(), "You need to specify both (in- and out-degree) to use the AND operation.", "Wrong settings", JOptionPane.WARNING_MESSAGE);
                        return;
                    } else {
                        boolean changeout = false;
                        String op = outop.getSelectedItem().toString();
                        if (op.equals("<") && outTotal < out) {
                            changeout = true;
                        } else if (op.equals("=") && outTotal == out) {
                            changeout = true;
                        } else if (op.equals(">") && outTotal > out) {
                            changeout = true;
                        }
                        boolean changein = false;
                        op = inop.getSelectedItem().toString();
                        if (op.equals("<") && inTotal < in) {
                            changein = true;
                        } else if (op.equals("=") && inTotal == in) {
                            changein = true;
                        } else if (op.equals(">") && inTotal > in) {
                            changein = true;
                        }
                        if (changeout && changein) {
                            change.add(concept);
                        }
                    }
                }
            }
        }
        // set concepts visibility
        for (ONDEXConcept c : change) {
            graph.setVisibility(c, visibility);
        }
        // set relations between nodes to visible
        if (visibility) {
            for (ONDEXConcept c : change) {
                Set<ONDEXRelation> relations = graph.getRelationsOfConcept(c);
                for (ONDEXRelation relation : relations) {
                    if (relation.getFromConcept().equals(c) && (rtsOut == null || rtsOut.contains(relation.getOfType()))) {
                        graph.setVisibility(relation.getToConcept(), visibility);
                        graph.setVisibility(relation, visibility);
                    } else if (relation.getToConcept().equals(c) && (rtsIn == null || rtsIn.contains(relation.getOfType()))) {
                        graph.setVisibility(relation.getFromConcept(), visibility);
                        graph.setVisibility(relation, visibility);
                    }
                }
            }
        }
        // propagate change to viewer
        viewer.getVisualizationViewer().getModel().fireStateChanged();
        edit.end();
        viewer.getUndoManager().addEdit(edit);
        desktop.getOVTK2Menu().updateUndoRedo(viewer);
        desktop.notifyTerminationOfProcess();
        used = true;
    }
}
Also used : ConceptClass(net.sourceforge.ondex.core.ConceptClass) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) HashSet(java.util.HashSet)

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