Search in sources :

Example 21 with CyEventHelper

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();
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ViewChangeRecord(org.cytoscape.view.model.events.ViewChangeRecord) Collection(java.util.Collection) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 22 with CyEventHelper

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);
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyEventHelper(org.cytoscape.event.CyEventHelper) VisualStyleSetEvent(org.cytoscape.view.vizmap.events.VisualStyleSetEvent) VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Example 23 with CyEventHelper

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;
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) DiscreteMappingImpl(org.cytoscape.view.vizmap.internal.mappings.DiscreteMappingImpl)

Example 24 with CyEventHelper

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;
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) ContinuousMappingImpl(org.cytoscape.view.vizmap.internal.mappings.ContinuousMappingImpl)

Example 25 with CyEventHelper

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);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ValueTranslator(org.cytoscape.view.vizmap.mappings.ValueTranslator)

Aggregations

CyEventHelper (org.cytoscape.event.CyEventHelper)63 CyNetworkView (org.cytoscape.view.model.CyNetworkView)19 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)19 CyNode (org.cytoscape.model.CyNode)15 UndoSupport (org.cytoscape.work.undo.UndoSupport)14 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)13 ArrayList (java.util.ArrayList)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetwork (org.cytoscape.model.CyNetwork)10 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)10 Test (org.junit.Test)10 Task (org.cytoscape.work.Task)9 CyTable (org.cytoscape.model.CyTable)8 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 CyEdge (org.cytoscape.model.CyEdge)7 CyRow (org.cytoscape.model.CyRow)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)5