use of org.cytoscape.view.presentation.property.values.LineType in project EnrichmentMapApp by BaderLab.
the class EMStyleBuilder method setEdgeLineType.
private void setEdgeLineType(VisualStyle vs, EMStyleOptions options) {
String col = CyEdge.INTERACTION;
DiscreteMapping<String, LineType> dm = (DiscreteMapping<String, LineType>) dmFactory.createVisualMappingFunction(col, String.class, EDGE_LINE_TYPE);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(dm);
try {
LineType sigLineType = LineTypeVisualProperty.DOT;
if (EDGE_LINE_TYPE.getRange().isDiscrete()) {
DiscreteRange<LineType> range = (DiscreteRange<LineType>) EDGE_LINE_TYPE.getRange();
Optional<LineType> first = range.values().stream().filter(v -> "MARQUEE_EQUAL".equalsIgnoreCase(v.getSerializableString())).findFirst();
if (first.isPresent())
sigLineType = first.get();
}
dm.putMapValue(Columns.EDGE_DATASET_VALUE_COMPOUND, LineTypeVisualProperty.SOLID);
dm.putMapValue(Columns.EDGE_INTERACTION_VALUE_SIG, sigLineType);
} finally {
eventHelper.unsilenceEventSource(dm);
}
vs.addVisualMappingFunction(dm);
}
use of org.cytoscape.view.presentation.property.values.LineType in project cytoscape-impl by cytoscape.
the class DEdgeView method applyVisualProperty.
/**
* This method sets a mapped value. NOT Defaults.
*/
@SuppressWarnings("unchecked")
@Override
protected <T, V extends T> void applyVisualProperty(final VisualProperty<? extends T> vpOriginal, V value) {
VisualProperty<?> vp = vpOriginal;
// Check to make sure our view hasn't gotten disconnected somewhere along the line
if (graphView.getEdgeView(this.getModel()) == null)
return;
// If value is null, simply use the VP's default value.
if (value == null)
value = (V) vp.getDefault();
if (vp == DVisualLexicon.EDGE_STROKE_SELECTED_PAINT) {
setSelectedPaint((Paint) value);
} else if (vp == DVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) {
setUnselectedPaint((Paint) value);
} else if (vp == DVisualLexicon.EDGE_WIDTH) {
final float w = ((Number) value).floatValue();
setStrokeWidth(w);
setStroke(DLineType.getDLineType(lineType).getStroke(w));
} else if (vp == DVisualLexicon.EDGE_LINE_TYPE) {
lineType = (LineType) value;
final Stroke newStroke = DLineType.getDLineType(lineType).getStroke(graphView.m_edgeDetails.getWidth(model));
setStroke(newStroke);
} else if (vp == DVisualLexicon.EDGE_TRANSPARENCY) {
setTransparency(((Number) value).intValue());
} else if (vp == DVisualLexicon.EDGE_LABEL_TRANSPARENCY) {
final int labelTransparency = ((Number) value).intValue();
setLabelTransparency(labelTransparency);
} else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_SELECTED_PAINT) {
setSourceEdgeEndSelectedPaint((Paint) value);
} else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_SELECTED_PAINT) {
setTargetEdgeEndSelectedPaint((Paint) value);
} else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_UNSELECTED_PAINT) {
setSourceEdgeEndPaint((Paint) value);
} else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_UNSELECTED_PAINT) {
setTargetEdgeEndPaint((Paint) value);
} else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_SIZE) {
setSourceArrowSize(((Number) value).doubleValue());
} else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_SIZE) {
setTargetArrowSize(((Number) value).doubleValue());
} else if (vp == BasicVisualLexicon.EDGE_SELECTED) {
setSelected((Boolean) value);
} else if (vp == BasicVisualLexicon.EDGE_TARGET_ARROW_SHAPE) {
final ArrowShape shape = (ArrowShape) value;
final String shapeID = shape.getSerializableString();
setTargetEdgeEnd(DArrowShape.parseArrowText(shapeID).getPresentationShape());
} else if (vp == BasicVisualLexicon.EDGE_SOURCE_ARROW_SHAPE) {
final ArrowShape shape = (ArrowShape) value;
final String shapeID = shape.getSerializableString();
setSourceEdgeEnd(DArrowShape.parseArrowText(shapeID).getPresentationShape());
} else if (vp == BasicVisualLexicon.EDGE_LABEL) {
setText(value.toString());
} else if (vp == BasicVisualLexicon.EDGE_LABEL_WIDTH) {
setLabelWidth(((Number) value).doubleValue());
} else if (vp == DVisualLexicon.EDGE_TOOLTIP) {
setToolTip(value.toString());
} else if (vp == DVisualLexicon.EDGE_LABEL_FONT_FACE) {
Font newFont = (Font) value;
final Font f = getFont();
if (f != null)
newFont = f.deriveFont((float) f.getSize());
setFont(newFont);
} else if (vp == DVisualLexicon.EDGE_LABEL_FONT_SIZE) {
float fontSize = ((Number) value).floatValue();
final Font f = getFont();
if (f != null)
setFont(f.deriveFont(fontSize));
} else if (vp == BasicVisualLexicon.EDGE_LABEL_COLOR) {
setTextPaint((Paint) value);
} else if (vp == BasicVisualLexicon.EDGE_VISIBLE) {
if (((Boolean) value).booleanValue()) {
graphView.showGraphObject(this);
isVisible = true;
} else {
graphView.hideGraphObject(this);
isVisible = false;
}
} else if (vp == DVisualLexicon.EDGE_CURVED) {
final Boolean curved = (Boolean) value;
if (curved)
setLineCurved(EdgeView.CURVED_LINES);
else
setLineCurved(EdgeView.STRAIGHT_LINES);
} else if (vp == DVisualLexicon.EDGE_BEND) {
setBend((Bend) value);
}
}
use of org.cytoscape.view.presentation.property.values.LineType in project cytoscape-impl by cytoscape.
the class VisualStyleSerializerTest method testCy283Vizmap.
@Test
@SuppressWarnings("unchecked")
public void testCy283Vizmap() throws Exception {
Properties props = loadVizmapProps("v283_vizmap.props");
Set<VisualStyle> styles = serializer.createVisualStyles(props);
assertEquals(6, styles.size());
assertVisualStylesNotNull(styles, new String[] { "default", "Sample1", "Solid", "Universe", "{Gal_Filt}: -(1:2),&[A*|B?]+%$#@!\\/;", /*Testing special chars*/
"Nested Network Style" });
// Test visual styles (defaults, mappings and dependencies)
// -----
VisualStyle sample1 = getVisualStyleByTitle(styles, "Sample1");
assertEquals(new Color(255, 255, 204), sample1.getDefaultValue(NETWORK_BACKGROUND_PAINT));
assertEquals(Color.BLACK, sample1.getDefaultValue(EDGE_UNSELECTED_PAINT));
assertEquals(Color.BLACK, sample1.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(255, 0, 1), sample1.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(Font.decode("Default-PLAIN-10"), sample1.getDefaultValue(EDGE_LABEL_FONT_FACE));
assertEquals(10, sample1.getDefaultValue(EDGE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(0, 10, 0), sample1.getDefaultValue(EDGE_LABEL_COLOR));
assertEquals(120, sample1.getDefaultValue(EDGE_LABEL_TRANSPARENCY).intValue());
assertEquals("", sample1.getDefaultValue(EDGE_LABEL));
assertEquals(LineTypeVisualProperty.SOLID, sample1.getDefaultValue(EDGE_LINE_TYPE));
assertEquals(1, sample1.getDefaultValue(EDGE_WIDTH).intValue());
assertEquals(180, sample1.getDefaultValue(EDGE_TRANSPARENCY).intValue());
assertEquals(ArrowShapeVisualProperty.NONE, sample1.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
assertEquals(ArrowShapeVisualProperty.CIRCLE, sample1.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
assertEquals("", sample1.getDefaultValue(EDGE_TOOLTIP));
assertEquals(new Color(10, 20, 0), sample1.getDefaultValue(NODE_BORDER_PAINT));
assertEquals(242, sample1.getDefaultValue(NODE_BORDER_TRANSPARENCY).intValue());
assertEquals(new Color(204, 204, 255), sample1.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(255, 255, 1), sample1.getDefaultValue(NODE_SELECTED_PAINT));
assertEquals(Font.decode("Dialog-BOLD-12"), sample1.getDefaultValue(NODE_LABEL_FONT_FACE));
assertEquals(12, sample1.getDefaultValue(NODE_LABEL_FONT_SIZE).intValue());
assertEquals("node", sample1.getDefaultValue(NODE_LABEL));
assertEquals(new Color(0, 0, 255), sample1.getDefaultValue(NODE_LABEL_COLOR));
assertEquals(220, sample1.getDefaultValue(NODE_LABEL_TRANSPARENCY).intValue());
assertEquals(30, sample1.getDefaultValue(NODE_HEIGHT).intValue());
assertEquals(70, sample1.getDefaultValue(NODE_WIDTH).intValue());
assertEquals(40, sample1.getDefaultValue(NODE_SIZE).intValue());
assertEquals(LineTypeVisualProperty.LONG_DASH, sample1.getDefaultValue(NODE_BORDER_LINE_TYPE));
assertEquals(0, sample1.getDefaultValue(NODE_BORDER_WIDTH).intValue());
assertEquals(250, sample1.getDefaultValue(NODE_TRANSPARENCY).intValue());
assertEquals(NodeShapeVisualProperty.ELLIPSE, sample1.getDefaultValue(NODE_SHAPE));
assertEquals(true, sample1.getDefaultValue(NODE_NESTED_NETWORK_IMAGE_VISIBLE));
assertEquals("My test...", sample1.getDefaultValue(NODE_TOOLTIP));
PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) sample1.getVisualMappingFunction(NODE_LABEL);
assertEquals(NAME, nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
PassthroughMapping<String, String> eLabelMp = (PassthroughMapping<String, String>) sample1.getVisualMappingFunction(EDGE_LABEL);
assertEquals(INTERACTION, eLabelMp.getMappingColumnName());
DiscreteMapping<String, Paint> eColorMp1 = (DiscreteMapping<String, Paint>) sample1.getVisualMappingFunction(EDGE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp1.getMappingColumnName());
assertEquals(String.class, eColorMp1.getMappingColumnType());
assertEquals(new Color(255, 0, 51), eColorMp1.getMapValue("pd"));
assertEquals(new Color(0, 204, 0), eColorMp1.getMapValue("pp"));
DiscreteMapping<String, Paint> eColorMp2 = (DiscreteMapping<String, Paint>) sample1.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp2.getMappingColumnName());
assertEquals(String.class, eColorMp2.getMappingColumnType());
assertEquals(new Color(255, 0, 51), eColorMp2.getMapValue("pd"));
assertEquals(new Color(0, 204, 0), eColorMp2.getMapValue("pp"));
DiscreteMapping<String, LineType> eTypeMp = (DiscreteMapping<String, LineType>) sample1.getVisualMappingFunction(EDGE_LINE_TYPE);
assertEquals(INTERACTION, eTypeMp.getMappingColumnName());
assertEquals(LineTypeVisualProperty.LONG_DASH, eTypeMp.getMapValue("pd"));
assertEquals(LineTypeVisualProperty.SOLID, eTypeMp.getMapValue("pp"));
VisualPropertyDependency<?> dep1 = getDependency(sample1, NODE_SIZE_LOCKED_DEPENDENCY);
assertFalse(dep1.isDependencyEnabled());
// -----
VisualStyle galFiltered = getVisualStyleByTitle(styles, "{Gal_Filt}: -(1:2),&[A*|B?]+%$#@!\\/;");
ContinuousMapping<Double, Paint> nColorMp = (ContinuousMapping<Double, Paint>) galFiltered.getVisualMappingFunction(NODE_FILL_COLOR);
assertEquals("gal4RGexp", nColorMp.getMappingColumnName());
assertEquals(Number.class, nColorMp.getMappingColumnType());
assertEquals(3, nColorMp.getPointCount());
assertEquals(-2.0249776914715767, nColorMp.getPoint(0).getValue(), 0.0001);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().equalValue);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().greaterValue);
assertEquals(Color.BLACK, nColorMp.getPoint(0).getRange().lesserValue);
assertEquals(0.20517408847808838, nColorMp.getPoint(1).getValue(), 0.0001);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().equalValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().greaterValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().lesserValue);
assertEquals(2.5, nColorMp.getPoint(2).getValue(), 0.0001);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(2).getRange().equalValue);
assertEquals(new Color(0, 0, 204), nColorMp.getPoint(2).getRange().greaterValue);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(2).getRange().lesserValue);
VisualPropertyDependency<?> dep2 = getDependency(galFiltered, NODE_SIZE_LOCKED_DEPENDENCY);
assertTrue(dep2.isDependencyEnabled());
// -----
VisualStyle nested = getVisualStyleByTitle(styles, "Nested Network Style");
DiscreteMapping<Boolean, Paint> nLabelColorMp = (DiscreteMapping<Boolean, Paint>) nested.getVisualMappingFunction(NODE_LABEL_COLOR);
assertEquals("has_nested_network", nLabelColorMp.getMappingColumnName());
assertEquals(Boolean.class, nLabelColorMp.getMappingColumnType());
assertEquals(new Color(0, 102, 204), nLabelColorMp.getMapValue(true));
}
use of org.cytoscape.view.presentation.property.values.LineType in project cytoscape-api by cytoscape.
the class LineTypeVisualProperty method parseSerializableString.
@Override
public LineType parseSerializableString(String value) {
LineType lineType = null;
if (value != null) {
value = value.toUpperCase();
lineType = lineTypes.get(value);
}
if (lineType == null) {
// Try to find it in the range (it might have been added by a private visual lexicon)
for (final LineType lt : LINE_TYPE_RANGE.values()) {
if (lt.getSerializableString().equalsIgnoreCase(value)) {
lineType = lt;
break;
}
}
}
if (lineType == null)
lineType = SOLID;
return lineType;
}
use of org.cytoscape.view.presentation.property.values.LineType in project cytoscape-impl by cytoscape.
the class VisualStyleSerializerTest method testCy252Vizmap.
@Test
@SuppressWarnings("unchecked")
public void testCy252Vizmap() throws Exception {
Properties props = loadVizmapProps("v252_vizmap.props");
Set<VisualStyle> styles = serializer.createVisualStyles(props);
assertEquals(5, styles.size());
assertVisualStylesNotNull(styles, new String[] { "default", "Sample1", "Sample2", "Sample3", "SimpleBioMoleculeEditor" });
// Test one style
// -----
VisualStyle s3 = getVisualStyleByTitle(styles, "Sample3");
assertEquals(new Color(0, 0, 0), s3.getDefaultValue(NETWORK_BACKGROUND_PAINT));
assertEquals(new Color(255, 255, 255), s3.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(255, 255, 0), s3.getDefaultValue(NODE_SELECTED_PAINT));
assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, s3.getDefaultValue(NODE_SHAPE));
assertEquals(80, s3.getDefaultValue(NODE_WIDTH).intValue());
assertEquals(30, s3.getDefaultValue(NODE_HEIGHT).intValue());
assertEquals(180, s3.getDefaultValue(NODE_TRANSPARENCY).intValue());
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(NODE_BORDER_PAINT));
assertEquals(2, s3.getDefaultValue(NODE_BORDER_WIDTH).intValue());
assertEquals(255, s3.getDefaultValue(NODE_BORDER_TRANSPARENCY).intValue());
assertEquals(new Font("Arial-BoldMT", Font.PLAIN, 12), s3.getDefaultValue(NODE_LABEL_FONT_FACE));
assertEquals(16, s3.getDefaultValue(NODE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(255, 255, 255), s3.getDefaultValue(NODE_LABEL_COLOR));
assertEquals(255, s3.getDefaultValue(NODE_LABEL_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s3.getDefaultValue(NODE_BORDER_LINE_TYPE));
assertEquals("", s3.getDefaultValue(NODE_TOOLTIP));
assertEquals(1, s3.getDefaultValue(EDGE_WIDTH).intValue());
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(EDGE_UNSELECTED_PAINT));
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(255, 0, 0), s3.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(255, s3.getDefaultValue(EDGE_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s3.getDefaultValue(EDGE_LINE_TYPE));
assertEquals(Font.decode("SanSerif-PLAIN-10"), s3.getDefaultValue(EDGE_LABEL_FONT_FACE));
assertEquals(14, s3.getDefaultValue(EDGE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(255, 255, 204), s3.getDefaultValue(EDGE_LABEL_COLOR));
assertEquals(255, s3.getDefaultValue(EDGE_LABEL_TRANSPARENCY).intValue());
assertEquals(ArrowShapeVisualProperty.NONE, s3.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
assertEquals(ArrowShapeVisualProperty.NONE, s3.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
assertEquals("", s3.getDefaultValue(EDGE_TOOLTIP));
PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(NODE_LABEL);
assertEquals(NAME, nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
PassthroughMapping<String, String> eLabelMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(EDGE_LABEL);
assertEquals(INTERACTION, eLabelMp.getMappingColumnName());
assertEquals(String.class, eLabelMp.getMappingColumnType());
PassthroughMapping<String, String> nTooltipMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(NODE_TOOLTIP);
assertEquals("gal4RGexp", nTooltipMp.getMappingColumnName());
assertEquals(String.class, nTooltipMp.getMappingColumnType());
ContinuousMapping<Double, Paint> nColorMp = (ContinuousMapping<Double, Paint>) s3.getVisualMappingFunction(NODE_FILL_COLOR);
assertEquals("gal4RGexp", nColorMp.getMappingColumnName());
assertEquals(Number.class, nColorMp.getMappingColumnType());
assertEquals(3, nColorMp.getPointCount());
assertEquals(-2.4059998989105242, nColorMp.getPoint(0).getValue(), 0.0001);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(0).getRange().equalValue);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(0).getRange().greaterValue);
assertEquals(Color.BLACK, nColorMp.getPoint(0).getRange().lesserValue);
assertEquals(-3.254413627473696E-8, nColorMp.getPoint(1).getValue(), 0.0001);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().equalValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().greaterValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().lesserValue);
assertEquals(1.2239999999999998, nColorMp.getPoint(2).getValue(), 0.0001);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(2).getRange().equalValue);
assertEquals(new Color(255, 255, 255), nColorMp.getPoint(2).getRange().greaterValue);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(2).getRange().lesserValue);
DiscreteMapping<String, Paint> eColorMp = (DiscreteMapping<String, Paint>) s3.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp.getMappingColumnName());
assertEquals(String.class, eColorMp.getMappingColumnType());
assertEquals(new Color(102, 255, 255), eColorMp.getMapValue("pd"));
assertEquals(new Color(255, 255, 255), eColorMp.getMapValue("pp"));
DiscreteMapping<String, LineType> eTypeMp = (DiscreteMapping<String, LineType>) s3.getVisualMappingFunction(EDGE_LINE_TYPE);
assertEquals(INTERACTION, eTypeMp.getMappingColumnName());
assertEquals(LineTypeVisualProperty.LONG_DASH, eTypeMp.getMapValue("pd"));
assertEquals(LineTypeVisualProperty.SOLID, eTypeMp.getMapValue("pp"));
VisualPropertyDependency<?> dep1 = getDependency(s3, NODE_SIZE_LOCKED_DEPENDENCY);
assertFalse(dep1.isDependencyEnabled());
}
Aggregations