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