Search in sources :

Example 11 with StateEdit

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

the class OVTK2Viewer method keyPressed.

@Override
public void keyPressed(KeyEvent arg0) {
    if (arg0.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK) {
        if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("h")) {
            hideSelection();
        } else if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("c")) {
            center();
        } else if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("g")) {
            StateEdit edit = new StateEdit(new VisibilityUndo(this.getONDEXJUNGGraph()), Config.language.getProperty("Undo.RemoveComplement"));
            undoManager.addEdit(edit);
            OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(this);
            Set<ONDEXConcept> allnodes = new HashSet<ONDEXConcept>(graph.getVertices());
            allnodes.removeAll(this.getPickedNodes());
            for (ONDEXConcept allnode : allnodes) {
                graph.setVisibility(allnode, false);
            }
            edit.end();
        } else if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("n")) {
            selectNeighboursOfSelection();
        } else if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("w")) {
            showAllRelations();
        } else if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("d")) {
            changeStroke();
        } else if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("z")) {
            if (undoManager.canUndo()) {
                undoManager.undo();
                OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(this);
                visviewer.repaint();
            }
        } else if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("y")) {
            if (undoManager.canRedo()) {
                undoManager.redo();
                OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(this);
                visviewer.repaint();
            }
        } else if (KeyEvent.getKeyText(arg0.getKeyCode()).equalsIgnoreCase("a")) {
            PickedState<ONDEXConcept> pickState = visviewer.getPickedVertexState();
            for (ONDEXConcept n : graph.getVertices()) pickState.pick(n, true);
        }
        this.getVisualizationViewer().getModel().fireStateChanged();
    } else if (arg0.getKeyCode() == KeyEvent.VK_F5) {
        VisualisationUtils.relayout(this, OVTK2Desktop.getInstance().getMainFrame());
    } else if (arg0.getKeyCode() == KeyEvent.VK_F11) {
        try {
            this.setMaximum(!this.isMaximum);
        } catch (PropertyVetoException e) {
            ErrorDialog.show(e);
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) HashSet(java.util.HashSet)

Example 12 with StateEdit

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

the class OVTK2Viewer method hideSelection.

/**
 * Hides any selection for nodes or edges in the graph.
 */
public void hideSelection() {
    StateEdit edit = new StateEdit(new VisibilityUndo(this.getONDEXJUNGGraph()), Config.language.getProperty("Undo.HideSelection"));
    undoManager.addEdit(edit);
    OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(this);
    // hide edges first
    for (ONDEXRelation ondexEdge : getPickedEdges()) {
        getONDEXJUNGGraph().setVisibility(ondexEdge, false);
    }
    // hide nodes next
    for (ONDEXConcept ondexNode : getPickedNodes()) {
        getONDEXJUNGGraph().setVisibility(ondexNode, false);
    }
    // update viewer
    getVisualizationViewer().getModel().fireStateChanged();
    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 13 with StateEdit

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

the class VisualizationHandler method setSelectedSubset.

/**
 * Makes the select subset visible in the graph
 */
public void setSelectedSubset(ONDEXGraph graph, Set<ONDEXConcept> cs, Set<ONDEXRelation> rs) {
    Set<OVTK2PropertiesAggregator> vs = new HashSet<OVTK2PropertiesAggregator>();
    for (Entry<OVTK2PropertiesAggregator, ONDEXJUNGGraph> ent : graphs.entrySet()) {
        if (ent.getKey().getONDEXJUNGGraph().equals(graph)) {
            vs.add(ent.getKey());
        }
    }
    for (OVTK2PropertiesAggregator viewer : vs) {
        StateEdit edit = null;
        if (viewer instanceof OVTK2PropertiesAggregator) {
            edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), Config.language.getProperty("Undo.HideSelection"));
            viewer.getUndoManager().addEdit(edit);
            OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(viewer);
        }
        ONDEXJUNGGraph jung = viewer.getONDEXJUNGGraph();
        // hide nodes next
        for (ONDEXConcept c : cs) {
            jung.setVisibility(c, true);
        }
        // hide edges first
        for (ONDEXRelation r : rs) {
            jung.setVisibility(r, true);
        }
        // update viewer
        viewer.getVisualizationViewer().getModel().fireStateChanged();
        if (edit != null)
            edit.end();
    }
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2PropertiesAggregator(net.sourceforge.ondex.ovtk2.ui.OVTK2PropertiesAggregator) ONDEXJUNGGraph(net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) StateEdit(javax.swing.undo.StateEdit) HashSet(java.util.HashSet) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)

Example 14 with StateEdit

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

the class RelationTypeMissingFilter method callFilter.

/**
 * Calls backend filter.
 */
private void callFilter() throws InvalidPluginArgumentException {
    if (rts != null && rts.size() > 0 && ccs != null && ccs.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<ConceptClass> it = ccs.iterator();
        while (it.hasNext()) {
            fa.addOption(Filter.TARGETCC_ARG, it.next().getId());
        }
        Iterator<RelationType> it2 = rts.iterator();
        while (it2.hasNext()) {
            fa.addOption(Filter.TARGETRT_ARG, it2.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 : ConceptClass(net.sourceforge.ondex.core.ConceptClass) 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.relationtypemissing.Filter) RelationType(net.sourceforge.ondex.core.RelationType) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation)

Example 15 with StateEdit

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

the class ShortestPathFilter 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());
        // contains results
        Set<ONDEXConcept> concepts = null;
        Set<ONDEXRelation> relations = null;
        boolean useweights = !(ANselection == null || ANselection.equals(// no nullpointer danger because of lazy
        defVal));
        // multiple filter calls
        for (ONDEXConcept target : targets) {
            // create new filter
            Filter filter = new Filter();
            // construct filter arguments
            ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
            fa.addOption(ArgumentNames.SEEDCONCEPT_ARG, target.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();
            if (concepts == null) {
                concepts = filter.getVisibleConcepts();
                relations = filter.getVisibleRelations();
            } else {
                concepts = BitSetFunctions.or(concepts, filter.getVisibleConcepts());
                relations = BitSetFunctions.or(relations, filter.getVisibleRelations());
            }
        }
        if (concepts != null) {
            // 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();
    }
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.shortestpath.Filter) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger) StateEdit(javax.swing.undo.StateEdit) 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