use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.
the class VisualPropertyIconFactory method createIcon.
public static <V> Icon createIcon(V value, int w, int h) {
if (value == null)
return null;
Icon icon = null;
if (value instanceof Color) {
icon = new ColorIcon((Color) value, w, h, value.toString());
} else if (value instanceof NodeShape) {
final DNodeShape dShape;
if (NodeShapeVisualProperty.isDefaultShape((NodeShape) value))
dShape = DNodeShape.getDShape((NodeShape) value);
else
dShape = (DNodeShape) value;
icon = new NodeIcon(dShape.getShape(), w, h, dShape.getDisplayName());
} else if (value instanceof LineType) {
icon = new StrokeIcon(DLineType.getDLineType((LineType) value).getStroke(2f), w, h, value.toString());
} else if (value instanceof CyCustomGraphics) {
final String name = ((CyCustomGraphics) value).getDisplayName();
if (name != null)
icon = new CustomGraphicsIcon(((CyCustomGraphics) value), w, h, name);
} else if (value instanceof ObjectPosition) {
icon = new ObjectPositionIcon((ObjectPosition) value, w, h, "Label");
} else if (value instanceof Font) {
icon = new FontFaceIcon((Font) value, w, h, "");
} else if (value instanceof ArrowShape) {
final ArrowShape arrowShape = (ArrowShape) value;
final DArrowShape dShape;
if (ArrowShapeVisualProperty.isDefaultShape(arrowShape))
dShape = DArrowShape.getArrowShape(arrowShape);
else
dShape = DArrowShape.NONE;
if (dShape.getShape() == null)
// No arrow
icon = new TextIcon(value, w, h, "");
else
icon = new ArrowIcon(dShape.getShape(), w, h, dShape.getDisplayName());
} else if (value instanceof Bend) {
icon = new EdgeBendIcon((Bend) value, w, h, value.toString());
} else {
// If not found, use return value of toString() as icon.
icon = new TextIcon(value, w, h, value.toString());
}
return icon;
}
use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.
the class EdgeBendPropertyEditor method editBend.
private void editBend() {
final Bend newVal = valueEditor.showEditor(null, bend);
if (newVal != null) {
setValue(newVal);
firePropertyChange(null, newVal);
}
}
use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.
the class EdgeBundlerTask method render.
private final void render(final Collection<View<CyEdge>> edges, final HandleFactory hf, final BendFactory bf, final VisualMappingManager vmm, final VisualMappingFunctionFactory discreteFactory) {
final VisualStyle style = vmm.getVisualStyle(view);
// Check existing mapping
VisualMappingFunction<?, Bend> bendMapping = style.getVisualMappingFunction(EDGE_BEND);
final Map<Long, Bend> mappingValues;
Map<Long, Bend> existingMap = null;
if (bendMapping != null && bendMapping instanceof DiscreteMapping) {
final String columnName = bendMapping.getMappingColumnName();
if (columnName.equals(BEND_MAP_COLUMN)) {
existingMap = ((DiscreteMapping<Long, Bend>) bendMapping).getAll();
} else {
bendMapping = (DiscreteMapping<Long, Bend>) discreteFactory.createVisualMappingFunction(BEND_MAP_COLUMN, Long.class, EDGE_BEND);
}
}
mappingValues = new HashMap<>();
final CyNetwork network = view.getModel();
final CyTable edgeTable = network.getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS);
final CyColumn bendMapColumn = edgeTable.getColumn(BEND_MAP_COLUMN);
if (bendMapColumn == null) {
edgeTable.createColumn(BEND_MAP_COLUMN, Long.class, false);
}
int ei = 0;
for (final View<CyEdge> edge : edges) {
final Long edgeId = edge.getModel().getSUID();
final View<CyNode> eSource = view.getNodeView(edge.getModel().getSource());
final View<CyNode> eTarget = view.getNodeView(edge.getModel().getTarget());
network.getRow(edge.getModel()).set(BEND_MAP_COLUMN, edgeId);
// Ignore self-edge
if (eSource.getSUID().equals(eTarget.getSUID()))
continue;
final Bend bend = bf.createBend();
final List<Handle> hlist = bend.getAllHandles();
for (int ni = 0; ni < numNubs; ni++) {
final double x = nubs[ni][0][ei];
final double y = nubs[ni][1][ei];
final Handle h = hf.createHandle(view, edge, x, y);
hlist.add(h);
}
mappingValues.put(edgeId, bend);
ei++;
}
if (bendMapping == null) {
// Create new discrete mapping for edge SUID to Edge Bend
final DiscreteMapping<Long, Bend> function = (DiscreteMapping<Long, Bend>) discreteFactory.createVisualMappingFunction(BEND_MAP_COLUMN, Long.class, EDGE_BEND);
style.addVisualMappingFunction(function);
function.putAll(mappingValues);
} else {
if (existingMap != null) {
mappingValues.putAll(existingMap);
}
((DiscreteMapping<Long, Bend>) bendMapping).putAll(mappingValues);
}
}
use of org.cytoscape.view.presentation.property.values.Bend in project cytoscape-impl by cytoscape.
the class GenericXGMMLReader method setEdgeViewProperties.
protected void setEdgeViewProperties(final CyNetworkView netView, final View<CyEdge> edgeView) {
final CyEdge edge = edgeView.getModel();
final Map<String, String> atts = readDataMgr.getGraphicsAttributes(edge);
setVisualProperties(netView, edgeView, atts);
// For 2.x compatibility
final Bend bend = edgeView.getVisualProperty(BasicVisualLexicon.EDGE_BEND);
if (bend != null && bend != EdgeBendVisualProperty.DEFAULT_EDGE_BEND) {
final List<Handle> handles = bend.getAllHandles();
for (final Handle handle : handles) handle.defineHandle(netView, edgeView, Double.NaN, Double.NaN);
}
}
Aggregations