Search in sources :

Example 6 with VisualPropertyDependency

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

the class CySessionManagerImpl method updateVisualStyle.

/**
 * @param source the Visual Style that will provide the new properties and values.
 * @param target the Visual Style that will be updated.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void updateVisualStyle(final VisualStyle source, final VisualStyle target, final RenderingEngineManager engineManager) {
    // First clean up the target
    final HashSet<VisualMappingFunction<?, ?>> mapingSet = new HashSet<>(target.getAllVisualMappingFunctions());
    for (final VisualMappingFunction<?, ?> mapping : mapingSet) target.removeVisualMappingFunction(mapping.getVisualProperty());
    final Set<VisualPropertyDependency<?>> depList = new HashSet<VisualPropertyDependency<?>>(target.getAllVisualPropertyDependencies());
    for (final VisualPropertyDependency<?> dep : depList) target.removeVisualPropertyDependency(dep);
    // Copy the default visual properties, mappings and dependencies from source to target
    final VisualLexicon lexicon = engineManager.getDefaultVisualLexicon();
    final Set<VisualProperty<?>> properties = lexicon.getAllVisualProperties();
    for (final VisualProperty vp : properties) {
        if (!vp.equals(BasicVisualLexicon.NETWORK) && !vp.equals(BasicVisualLexicon.NODE) && !vp.equals(BasicVisualLexicon.EDGE))
            target.setDefaultValue(vp, source.getDefaultValue(vp));
    }
    for (final VisualPropertyDependency<?> dep : source.getAllVisualPropertyDependencies()) target.addVisualPropertyDependency(dep);
    for (final VisualMappingFunction<?, ?> mapping : source.getAllVisualMappingFunctions()) target.addVisualMappingFunction(mapping);
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) VisualProperty(org.cytoscape.view.model.VisualProperty) HashSet(java.util.HashSet)

Example 7 with VisualPropertyDependency

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

the class VizMapperMediator method createVisualPropertySheetItems.

@SuppressWarnings("rawtypes")
private Set<VisualPropertySheetItem<?>> createVisualPropertySheetItems(final Class<? extends CyIdentifiable> type, final VisualLexicon lexicon, final VisualStyle style) {
    final Set<VisualPropertySheetItem<?>> items = new HashSet<>();
    if (lexicon == null || style == null)
        return items;
    final Collection<VisualProperty<?>> vpList = lexicon.getAllDescendants(BasicVisualLexicon.NETWORK);
    final CyNetworkView curNetView = vmProxy.getCurrentNetworkView();
    final Set<View<CyNode>> selectedNodeViews = vmProxy.getSelectedNodeViews(curNetView);
    final Set<View<CyEdge>> selectedEdgeViews = vmProxy.getSelectedEdgeViews(curNetView);
    final Set<View<CyNetwork>> selectedNetViews = curNetView != null ? Collections.singleton((View<CyNetwork>) curNetView) : Collections.EMPTY_SET;
    final RenderingEngine<CyNetwork> engine = vizMapperMainPanel.getRenderingEngine();
    for (final VisualProperty<?> vp : vpList) {
        if (vp.getTargetDataType() != type || vp instanceof DefaultVisualizableVisualProperty)
            continue;
        if (!vmProxy.isSupported(vp))
            continue;
        // Create model
        final VisualPropertySheetItemModel<?> model = new VisualPropertySheetItemModel(vp, style, engine, lexicon);
        final Set values;
        if (vp.getTargetDataType() == CyNode.class) {
            values = getDistinctLockedValues(vp, selectedNodeViews);
            updateVpInfoLockedState(model, values, selectedNodeViews);
        } else if (vp.getTargetDataType() == CyEdge.class) {
            values = getDistinctLockedValues(vp, selectedEdgeViews);
            updateVpInfoLockedState(model, values, selectedEdgeViews);
        } else {
            values = getDistinctLockedValues(vp, selectedNetViews);
            updateVpInfoLockedState(model, values, selectedNetViews);
        }
        // Create View
        final VisualPropertySheetItem<?> sheetItem = new VisualPropertySheetItem(model, vizMapPropertyBuilder, servicesUtil);
        items.add(sheetItem);
        // Add listeners to item and model:
        if (model.isVisualMappingAllowed()) {
            sheetItem.getPropSheetPnl().addPropertySheetChangeListener(evt -> {
                if (evt.getPropertyName().equals("value") && evt.getSource() instanceof VizMapperProperty)
                    updateMappingStatus(sheetItem);
            });
        }
        // Set the updated values to the visual style
        model.addPropertyChangeListener("defaultValue", evt -> {
            final VisualStyle vs = model.getVisualStyle();
            vs.setDefaultValue((VisualProperty) vp, evt.getNewValue());
        });
        model.addPropertyChangeListener("visualMappingFunction", evt -> {
            final VisualStyle vs = model.getVisualStyle();
            if (evt.getNewValue() == null && vs.getVisualMappingFunction(vp) != null)
                vs.removeVisualMappingFunction(vp);
            else if (evt.getNewValue() != null && !evt.getNewValue().equals(vs.getVisualMappingFunction(vp)))
                vs.addVisualMappingFunction((VisualMappingFunction<?, ?>) evt.getNewValue());
            updateMappingStatus(sheetItem);
        });
    }
    // Add dependencies
    final Set<VisualPropertyDependency<?>> dependencies = style.getAllVisualPropertyDependencies();
    for (final VisualPropertyDependency<?> dep : dependencies) {
        if (dep.getParentVisualProperty().getTargetDataType() != type)
            continue;
        if (!vmProxy.isSupported(dep))
            continue;
        final VisualPropertySheetItemModel<?> model = new VisualPropertySheetItemModel(dep, style, engine, lexicon);
        final VisualPropertySheetItem<?> sheetItem = new VisualPropertySheetItem(model, vizMapPropertyBuilder, servicesUtil);
        items.add(sheetItem);
    }
    return items;
}
Also used : Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyEdge(org.cytoscape.model.CyEdge) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty)

Example 8 with VisualPropertyDependency

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

the class VisualStyleFactoryTest method testCopyVisualStyle.

@Test
@SuppressWarnings("unchecked")
public void testCopyVisualStyle() {
    final VisualStyle vs1 = new VisualStyleImpl("Style 1", serviceRegistrar);
    // Add a few default values
    vs1.setDefaultValue(NODE_FILL_COLOR, Color.LIGHT_GRAY);
    vs1.setDefaultValue(NODE_SIZE, 64.0);
    vs1.setDefaultValue(EDGE_LABEL_COLOR, Color.GREEN);
    vs1.setDefaultValue(EDGE_LABEL_FONT_SIZE, 32);
    vs1.setDefaultValue(NETWORK_BACKGROUND_PAINT, Color.YELLOW);
    // Add a mapping
    final DiscreteMapping<String, Paint> dm1 = new DiscreteMappingImpl<>("myattr1", String.class, NODE_FILL_COLOR, eventHelper);
    dm1.putMapValue("a", Color.CYAN);
    dm1.putMapValue("b", Color.BLUE);
    vs1.addVisualMappingFunction(dm1);
    // Add a dependency
    final Set<VisualProperty<Double>> depProps = new HashSet<>();
    depProps.add(NODE_WIDTH);
    depProps.add(NODE_HEIGHT);
    final VisualPropertyDependency<Double> dep1 = new VisualPropertyDependency<>("nodeSizeDep", "Lock Node W/H", depProps, lexicon);
    dep1.setDependency(false);
    vs1.addVisualPropertyDependency(dep1);
    // Copy the style and test it
    final VisualStyle vs2 = factory.createVisualStyle(vs1);
    assertNotEquals(vs1, vs2);
    assertEquals(vs1.getTitle(), vs2.getTitle());
    assertEquals(Color.LIGHT_GRAY, vs2.getDefaultValue(NODE_FILL_COLOR));
    assertEquals(new Double(64.0), vs2.getDefaultValue(NODE_SIZE));
    assertEquals(Color.GREEN, vs2.getDefaultValue(EDGE_LABEL_COLOR));
    assertEquals(new Integer(32), vs2.getDefaultValue(EDGE_LABEL_FONT_SIZE));
    assertEquals(Color.YELLOW, vs2.getDefaultValue(NETWORK_BACKGROUND_PAINT));
    final DiscreteMapping<String, Paint> dm2 = (DiscreteMapping<String, Paint>) vs2.getVisualMappingFunction(NODE_FILL_COLOR);
    assertEquals("myattr1", dm2.getMappingColumnName());
    assertEquals(2, dm2.getAll().size());
    assertEquals(Color.CYAN, dm2.getMapValue("a"));
    assertEquals(Color.BLUE, dm2.getMapValue("b"));
    final Set<VisualPropertyDependency<?>> depSet2 = vs2.getAllVisualPropertyDependencies();
    assertEquals(vs1.getAllVisualPropertyDependencies().size(), depSet2.size());
    boolean depFound = false;
    for (final VisualPropertyDependency<?> dep : depSet2) {
        if (dep.getIdString().equals("nodeSizeDep")) {
            depFound = true;
            assertTrue("The copied dependency is not a new instance", dep != dep1);
            assertEquals(dep1.getDisplayName(), dep.getDisplayName());
            assertEquals(dep1.getParentVisualProperty(), dep.getParentVisualProperty());
            assertFalse(dep.isDependencyEnabled());
            assertEquals(2, dep.getVisualProperties().size());
            assertTrue(dep.getVisualProperties().contains(NODE_WIDTH));
            assertTrue(dep.getVisualProperties().contains(NODE_HEIGHT));
            break;
        }
    }
    assertTrue("VisualPropertyDependency was not copied.", depFound);
}
Also used : DiscreteMappingImpl(org.cytoscape.view.vizmap.internal.mappings.DiscreteMappingImpl) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) Paint(java.awt.Paint) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) VisualProperty(org.cytoscape.view.model.VisualProperty) NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) HashSet(java.util.HashSet) AbstractVisualStyleFactoryTest(org.cytoscape.view.vizmap.AbstractVisualStyleFactoryTest) Test(org.junit.Test)

Example 9 with VisualPropertyDependency

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

the class DGraphView method drawSnapshot.

/**
 * This method is called by the BirdsEyeView to get a snapshot of the graphics.
 */
// TODO: Need to fix up scaling and sizing.
public void drawSnapshot(VolatileImage img, GraphLOD lod, Paint bgPaint, double xMin, double yMin, double xCenter, double yCenter, double scaleFactor) {
    // First paint the background
    m_backgroundCanvas.drawCanvas(img, xMin, yMin, xCenter, yCenter, scaleFactor);
    // final VisualMappingManager vmm = serviceRegistrar.getService(VisualMappingManager.class);
    final Set<VisualPropertyDependency<?>> dependencies = vmm.getVisualStyle(this).getAllVisualPropertyDependencies();
    // synchronized (m_lock) {
    try {
        // System.out.println("Calling renderGraph to draw snapshot: bgPaint="+bgPaint);
        GraphRenderer.renderGraph(this, dummySpacialFactory.createSpacialIndex2D(), lod, m_nodeDetails, m_edgeDetails, new LongHash(), new GraphGraphics(img, false, false), bgPaint, xCenter, yCenter, scaleFactor, haveZOrder, dependencies);
    } catch (Exception e) {
        // We probably had a node or edge view removed out from underneath us.  Just quietly return, but
        // set content changed so we redraw again
        setContentChanged();
    }
    // }
    // Finally, draw the foreground
    m_foregroundCanvas.drawCanvas(img, xMin, yMin, xCenter, yCenter, scaleFactor);
}
Also used : LongHash(org.cytoscape.util.intr.LongHash) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) GraphGraphics(org.cytoscape.graph.render.immed.GraphGraphics) IOException(java.io.IOException)

Example 10 with VisualPropertyDependency

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

the class DGraphView method renderSubgraph.

int renderSubgraph(GraphGraphics graphics, final GraphLOD lod, Paint bgColor, double xCenter, double yCenter, double scale, LongHash hash, List<CyNode> nodeList, List<CyEdge> edgeList) {
    // the overhead of creating the SpacialIndex2D and CySubNetwork
    if (!largeModel || ((nodeList.size() + edgeList.size()) >= (m_drawPersp.getNodeCount() + m_drawPersp.getEdgeCount()) / 4))
        return renderGraph(graphics, lod, bgColor, xCenter, yCenter, scale, hash);
    // Make a copy of the nodes and edges arrays to avoid a conflict with selection events
    // The assumption here is that these arrays are relatively small
    List<CyNode> nodes = new ArrayList<>(nodeList);
    List<CyEdge> edges = new ArrayList<>(edgeList);
    // Make sure the graphics is initialized
    if (!graphics.isInitialized())
        graphics.clear(bgColor, xCenter, yCenter, scale);
    Color bg = (Color) bgColor;
    if (bg != null)
        bg = new Color(bg.getRed(), bg.getBlue(), bg.getGreen(), 0);
    // Create our private spacial index.
    final SpacialIndex2DFactory spacialFactory = serviceRegistrar.getService(SpacialIndex2DFactory.class);
    SpacialIndex2D sub_spacial = spacialFactory.createSpacialIndex2D();
    // And our private subnetwork
    CySubNetwork net = new MinimalNetwork(SUIDFactory.getNextSUID());
    for (CyEdge edge : edges) {
        nodes.add(edge.getTarget());
        nodes.add(edge.getSource());
    }
    for (CyNode node : nodes) {
        long idx = node.getSUID();
        if (m_spacial.exists(idx, m_extentsBuff, 0)) {
            if (!sub_spacial.exists(idx, new float[4], 0))
                sub_spacial.insert(idx, m_extentsBuff[0], m_extentsBuff[1], m_extentsBuff[2], m_extentsBuff[3], 0.0);
            net.addNode(node);
        }
    }
    for (CyEdge edge : edges) {
        net.addEdge(edge);
    }
    int lastRenderDetail = 0;
    try {
        // final VisualMappingManager vmm = serviceRegistrar.getService(VisualMappingManager.class);
        final Set<VisualPropertyDependency<?>> dependencies = vmm.getVisualStyle(this).getAllVisualPropertyDependencies();
        synchronized (m_lock) {
            lastRenderDetail = GraphRenderer.renderGraph(this, sub_spacial, lod, m_nodeDetails, m_edgeDetails, hash, graphics, null, xCenter, yCenter, scale, haveZOrder, dependencies);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    setContentChanged(false);
    setViewportChanged(false);
    m_visualChanged = true;
    return lastRenderDetail;
}
Also used : Color(java.awt.Color) ArrayList(java.util.ArrayList) CyEdge(org.cytoscape.model.CyEdge) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) IOException(java.io.IOException) SpacialIndex2DFactory(org.cytoscape.spacial.SpacialIndex2DFactory) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) CyNode(org.cytoscape.model.CyNode) SpacialIndex2D(org.cytoscape.spacial.SpacialIndex2D) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Aggregations

VisualPropertyDependency (org.cytoscape.view.vizmap.VisualPropertyDependency)11 HashSet (java.util.HashSet)5 VisualProperty (org.cytoscape.view.model.VisualProperty)5 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)4 Paint (java.awt.Paint)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 CyNetwork (org.cytoscape.model.CyNetwork)3 VisualLexicon (org.cytoscape.view.model.VisualLexicon)3 TexturePaint (java.awt.TexturePaint)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 Dependency (org.cytoscape.io.internal.util.vizmap.model.Dependency)2 CyEdge (org.cytoscape.model.CyEdge)2 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ComponentAdapter (java.awt.event.ComponentAdapter)1