use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class NodeChangeListener method handleEvent.
public void handleEvent(ViewChangedEvent<?> e) {
if (ignoreChanges) {
// System.out.println("Ignoring changes");
return;
}
CyNetworkView networkView = e.getSource();
if (!groupMap.containsKey(networkView))
return;
Set<CyNode> groupNodes = groupMap.get(networkView);
Set<CyNode> nodes = nodeMap.get(networkView);
Collection<?> payload = e.getPayloadCollection();
for (ViewChangeRecord vcr : (Collection<ViewChangeRecord>) payload) {
// Only care about nodes
if (!(vcr.getView().getModel() instanceof CyNode))
continue;
View<CyNode> nodeView = vcr.getView();
VisualProperty<?> property = vcr.getVisualProperty();
if (property.equals(BasicVisualLexicon.NODE_X_LOCATION) || property.equals(BasicVisualLexicon.NODE_Y_LOCATION) || property.equals(BasicVisualLexicon.NODE_WIDTH) || property.equals(BasicVisualLexicon.NODE_HEIGHT)) {
CyNode node = nodeView.getModel();
// System.out.println("Got geometry change for "+node);
if (groupNodes.contains(node)) {
// System.out.println("It's a group: "+node);
try {
updateGroupLocation(networkView, nodeView);
} catch (Exception ee) {
ee.printStackTrace();
}
}
// System.out.println("It's a node: "+node);
try {
updateNodeLocation(networkView, nodeView);
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
final CyEventHelper cyEventHelper = cyGroupManager.getService(CyEventHelper.class);
// Do we need to update the view?
cyEventHelper.flushPayloadEvents();
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class VisualMappingManagerImpl method setVisualStyle.
@Override
public void setVisualStyle(final VisualStyle vs, final CyNetworkView nv) {
if (nv == null)
throw new NullPointerException("Network view is null.");
boolean changed = false;
synchronized (lock) {
if (vs == null) {
changed = network2VisualStyleMap.remove(nv) != null;
} else {
final VisualStyle previousStyle = network2VisualStyleMap.put(nv, vs);
changed = !vs.equals(previousStyle);
}
if (this.visualStyles.contains(vs) == false)
this.visualStyles.add(vs);
}
if (changed) {
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.fireEvent(new VisualStyleSetEvent(this, vs, nv));
final CyApplicationManager appManager = serviceRegistrar.getService(CyApplicationManager.class);
if (appManager != null && nv.equals(appManager.getCurrentNetworkView()))
setCurrentVisualStyle(vs);
}
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class VisualStyleFactoryImpl method createDiscrete.
@SuppressWarnings({ "rawtypes", "unchecked" })
private <K, V> VisualMappingFunction<K, V> createDiscrete(final DiscreteMapping<K, V> originalMapping) {
final String attrName = originalMapping.getMappingColumnName();
final Class<K> colType = originalMapping.getMappingColumnType();
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
final DiscreteMapping<K, V> copyMapping = new DiscreteMappingImpl(attrName, colType, originalMapping.getVisualProperty(), eventHelper);
copyMapping.putAll(originalMapping.getAll());
return copyMapping;
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class VisualStyleFactoryImpl method createContinuous.
@SuppressWarnings({ "unchecked", "rawtypes" })
private <K, V> VisualMappingFunction<K, V> createContinuous(final ContinuousMapping<K, V> originalMapping) {
final String attrName = originalMapping.getMappingColumnName();
final Class<?> colType = originalMapping.getMappingColumnType();
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
final ContinuousMapping<K, V> copyMapping = new ContinuousMappingImpl(attrName, colType, originalMapping.getVisualProperty(), eventHelper);
List<ContinuousMappingPoint<K, V>> points = originalMapping.getAllPoints();
for (ContinuousMappingPoint<K, V> point : points) copyMapping.addPoint(point.getValue(), new BoundaryRangeValues<V>(point.getRange()));
return copyMapping;
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class PassthroughMappingFactory method createVisualMappingFunction.
@Override
@SuppressWarnings("unchecked")
public <K, V> VisualMappingFunction<K, V> createVisualMappingFunction(final String attributeName, final Class<K> attrValueType, final VisualProperty<V> vp) {
final ValueTranslator<?, ?> translator = TRANSLATORS.get(vp.getRange().getType());
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
if (translator != null)
return new PassthroughMappingImpl<>(attributeName, attrValueType, vp, (ValueTranslator<K, V>) translator, eventHelper);
else
return new PassthroughMappingImpl<>(attributeName, attrValueType, vp, (ValueTranslator<K, V>) DEFAULT_TRANSLATOR, eventHelper);
}
Aggregations