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