Search in sources :

Example 26 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.

the class RowsSetViewUpdater method updateView.

private final void updateView(final RowsSetEvent e) {
    boolean refreshView = false;
    boolean refreshOtherViews = false;
    // Acquire services once to avoid performance overhead of repeated lookup
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    final CyColumnIdentifierFactory columnIdentifierFactory = serviceRegistrar.getService(CyColumnIdentifierFactory.class);
    final CyNetworkViewManager networkViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
    final VisualMappingManager visualMappingManager = serviceRegistrar.getService(VisualMappingManager.class);
    final RenderingEngine<CyNetwork> renderer = applicationManager.getCurrentRenderingEngine();
    final CyNetwork network = applicationManager.getCurrentNetwork();
    if (network == null)
        return;
    // 1: Update current network view
    final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
    CyNetworkView networkView = null;
    if (views.isEmpty())
        return;
    else
        networkView = views.iterator().next();
    final VisualStyle vs = visualMappingManager.getVisualStyle(networkView);
    Map<CyRow, View<? extends CyIdentifiable>> rowViewMap = tracker.getRowViewMap(networkView);
    for (final RowSetRecord record : e.getPayloadCollection()) {
        final CyRow row = record.getRow();
        final String columnName = record.getColumn();
        final CyColumn column = row.getTable().getColumn(columnName);
        if (column == null)
            continue;
        final VirtualColumnInfo virtualColInfo = column.getVirtualColumnInfo();
        final boolean virtual = virtualColInfo.isVirtual();
        final View<? extends CyIdentifiable> v = rowViewMap.get(row);
        if (v == null)
            continue;
        if (v.getModel() instanceof CyNode) {
            final CyNode node = (CyNode) v.getModel();
            if (network.containsNode(node) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
                vs.apply(row, v);
                refreshView = false;
            }
        } else if (v.getModel() instanceof CyEdge) {
            final CyEdge edge = (CyEdge) v.getModel();
            if (network.containsEdge(edge) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
                vs.apply(row, v);
                refreshView = false;
            }
        }
        // If virtual, it may be used in other networks.
        if (refreshView && virtual)
            refreshOtherViews = true;
    // if (refreshView)
    // vs.apply(record.getRow(), (View<? extends CyIdentifiable>) v);
    }
    if (refreshView) {
        vs.apply(networkView);
        networkView.updateView();
        if (refreshOtherViews) {
            // Check other views. If update is required, set the flag.
            for (final CyNetworkView view : networkViewManager.getNetworkViewSet()) {
                if (view == networkView)
                    continue;
                final VisualStyle style = visualMappingManager.getVisualStyle(view);
                if (style == vs) {
                    // Same style is in use. Need to apply.
                    netViewMediator.setUpdateFlag(view);
                }
            }
        }
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyColumnIdentifierFactory(org.cytoscape.view.presentation.property.values.CyColumnIdentifierFactory) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 27 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.

the class ApplyVisualStyleTaskTest method testRun.

@Test
public void testRun() throws Exception {
    NetworkViewTestSupport nvts = new NetworkViewTestSupport();
    TaskMonitor tm = mock(TaskMonitor.class);
    final CyNetworkView view = nvts.getNetworkView();
    final Set<CyNetworkView> views = new HashSet<CyNetworkView>();
    views.add(view);
    ApplyVisualStyleTask task = new ApplyVisualStyleTask(views, serviceRegistrar);
    final List<VisualStyle> vsList = new ArrayList<VisualStyle>();
    VisualStyle style1 = mock(VisualStyle.class);
    vsList.add(style1);
    task.styles = new ListSingleSelection<VisualStyle>(vsList);
    task.styles.setSelectedValue(style1);
    task.run(tm);
    verify(style1, times(1)).apply(view);
}
Also used : TaskMonitor(org.cytoscape.work.TaskMonitor) ArrayList(java.util.ArrayList) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.

the class ViewUtils method applyStyle.

public static void applyStyle(final Collection<? extends CyIdentifiable> elements, final Collection<CyNetworkView> networkViews, final VisualMappingManager cyStyleManager) {
    if (elements == null || networkViews == null)
        return;
    for (CyNetworkView netView : networkViews) {
        final CyNetwork net = netView.getModel();
        final VisualStyle style = cyStyleManager.getVisualStyle(netView);
        for (CyIdentifiable entry : elements) {
            View<? extends CyIdentifiable> view = null;
            if (entry instanceof CyNode)
                view = netView.getNodeView((CyNode) entry);
            else if (entry instanceof CyEdge)
                view = netView.getEdgeView((CyEdge) entry);
            if (view != null)
                style.apply(net.getRow(entry), view);
        }
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 29 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.

the class NetworkAddedSetCurrent method handleEvent.

@Override
public void handleEvent(NetworkViewAddedEvent e) {
    e.getNetworkView().setVisualProperty(BasicVisualLexicon.NETWORK_WIDTH, 300.0);
    e.getNetworkView().setVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT, 300.0);
    JPanel temp = new JPanel();
    VisualStyle vs = vman.getVisualStyle(e.getNetworkView());
    vs.apply(e.getNetworkView());
    final RenderingEngine<CyNetwork> renderingEngine = rfactory.createRenderingEngine(temp, e.getNetworkView());
    rman.addRenderingEngine(renderingEngine);
    appManager.setCurrentRenderingEngine(renderingEngine);
}
Also used : JPanel(javax.swing.JPanel) CyNetwork(org.cytoscape.model.CyNetwork) VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Example 30 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.

the class VisualMappingManagerImpl method getVisualStyle.

/**
 * Returns an associated Visual Style for the View Model.
 */
@Override
public VisualStyle getVisualStyle(CyNetworkView nv) {
    if (nv == null) {
        logger.warn("Attempting to get the visual style for a null network view; " + "returning the default visual style.");
        return getDefaultVisualStyle();
    }
    synchronized (lock) {
        VisualStyle style = network2VisualStyleMap.get(nv);
        // Not registered yet. Provide default style.
        if (style == null) {
            style = getDefaultVisualStyle();
            network2VisualStyleMap.put(nv, style);
        }
        return style;
    }
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Aggregations

VisualStyle (org.cytoscape.view.vizmap.VisualStyle)100 CyNetworkView (org.cytoscape.view.model.CyNetworkView)42 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)37 CyNetwork (org.cytoscape.model.CyNetwork)35 CyNode (org.cytoscape.model.CyNode)30 CyEdge (org.cytoscape.model.CyEdge)24 CyEventHelper (org.cytoscape.event.CyEventHelper)14 HashSet (java.util.HashSet)13 VisualProperty (org.cytoscape.view.model.VisualProperty)12 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)12 Paint (java.awt.Paint)11 HashMap (java.util.HashMap)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)11 Color (java.awt.Color)10 ArrayList (java.util.ArrayList)10 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)9 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)9 ContinuousMapping (org.cytoscape.view.vizmap.mappings.ContinuousMapping)9 View (org.cytoscape.view.model.View)8