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);
}
}
}
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();
}
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();
}
}
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();
}
}
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();
}
}
Aggregations