use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualMappingManagerImpl method getSuggestedTitle.
private String getSuggestedTitle(String title) {
int i = 0;
String suggesteTitle = title;
while (true) {
suggesteTitle = title + "_" + (new Integer(i).toString());
boolean duplicated = false;
Iterator<VisualStyle> it = this.getAllVisualStyles().iterator();
while (it.hasNext()) {
VisualStyle exist_vs = it.next();
if (exist_vs.getTitle().equalsIgnoreCase(suggesteTitle)) {
duplicated = true;
break;
}
}
if (duplicated) {
i++;
continue;
}
break;
}
return suggesteTitle;
}
use of org.cytoscape.view.vizmap.VisualStyle 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.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualMappingManagerTest method setUp.
@Before
public void setUp() throws Exception {
final VisualStyleFactory factory = mock(VisualStyleFactory.class);
final VisualStyle dummyDefaultStyle = mock(VisualStyle.class);
when(factory.createVisualStyle(VisualMappingManagerImpl.DEFAULT_STYLE_NAME)).thenReturn(dummyDefaultStyle);
final CyEventHelper eventHelper = mock(CyEventHelper.class);
final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
vmm = new VisualMappingManagerImpl(factory, serviceRegistrar);
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class CellEditorEventHandler method switchMappingType.
private VisualMappingFunction<?, ?> switchMappingType(final VizMapperProperty<?, ?, ?> prop, final VisualProperty<?> vp, final VisualMappingFunctionFactory oldFactory, final VisualMappingFunctionFactory newFactory, final String controllingAttrName, final PropertySheetPanel propertySheetPanel) {
// This is the currently selected Visual Style.
final VisualStyle style = servicesUtil.get(VisualMappingManager.class).getCurrentVisualStyle();
final VisualMappingFunction<?, ?> mapping = style.getVisualMappingFunction(vp);
VisualMappingFunction<?, ?> newMapping = mapping;
final Class<?> newMappingType = newFactory.getMappingFunctionType();
if (mapping == null || mapping.getClass() != newMappingType || !mapping.getMappingColumnName().equals(controllingAttrName)) {
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
final CyNetwork currentNet = appMgr.getCurrentNetwork();
if (currentNet == null)
return newMapping;
// Mapping does not exist. Need to create new one.
final AttributeSet attrSet = attrProxy.getAttributeSet(currentNet, vp.getTargetDataType());
Class<?> attributeDataType = attrSet.getAttrMap().get(controllingAttrName);
if (attributeDataType == null) {
JOptionPane.showMessageDialog(null, "The current table does not have the selected column (\"" + controllingAttrName + "\").\nPlease select another column.", "Invalid Column.", JOptionPane.WARNING_MESSAGE);
prop.setValue(oldFactory);
return newMapping;
}
if (newMappingType == ContinuousMapping.class) {
if (!Number.class.isAssignableFrom(attributeDataType)) {
JOptionPane.showMessageDialog(null, "Selected column data type is not Number.\nPlease select a numerical column type.", "Incompatible Column Type.", JOptionPane.WARNING_MESSAGE);
prop.setValue(oldFactory);
return newMapping;
}
} else if (newMappingType == DiscreteMapping.class) {
if (attributeDataType == List.class)
attributeDataType = String.class;
}
// Create new mapping
newMapping = newFactory.createVisualMappingFunction(controllingAttrName, attributeDataType, vp);
// Keep old mapping values if the new mapping has the same type
if (oldFactory != null && oldFactory.getMappingFunctionType() == newMappingType)
copyMappingValues(mapping, newMapping);
}
// Disable listeners to avoid unnecessary updates
final PropertySheetTableModel model = (PropertySheetTableModel) propertySheetPanel.getTable().getModel();
final TableModelListener[] modelListeners = model.getTableModelListeners();
for (final TableModelListener tm : modelListeners) model.removeTableModelListener(tm);
vizMapPropertyBuilder.createMappingProperties(newMapping, propertySheetPanel, newFactory);
// Restore listeners
for (final TableModelListener tm : modelListeners) model.addTableModelListener(tm);
return newMapping;
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class CellEditorEventHandler method switchColumn.
@SuppressWarnings("unchecked")
private VisualMappingFunction<?, ?> switchColumn(final VisualMappingFunctionFactory factory, final AttributeComboBoxPropertyEditor editor, final VizMapperProperty<?, ?, ?> prop, final String columnName, final PropertySheetPanel propertySheetPanel) {
final VisualStyle currentStyle = servicesUtil.get(VisualMappingManager.class).getCurrentVisualStyle();
final VisualProperty<?> vp = (VisualProperty<?>) prop.getKey();
VisualMappingFunction<?, ?> mapping = currentStyle.getVisualMappingFunction(vp);
// Ignore if not compatible.
final CyNetworkTableManager netTblMgr = servicesUtil.get(CyNetworkTableManager.class);
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
Class<? extends CyIdentifiable> type = (Class<? extends CyIdentifiable>) editor.getTargetObjectType();
final CyTable table = netTblMgr.getTable(appMgr.getCurrentNetwork(), type, CyNetwork.DEFAULT_ATTRS);
final CyColumn column = table.getColumn(columnName);
if (column == null) {
JOptionPane.showMessageDialog(null, "The current table does not have the selected column (\"" + columnName + "\").\nPlease select another column.", "Invalid Column.", JOptionPane.WARNING_MESSAGE);
prop.setValue(mapping != null ? mapping.getMappingColumnName() : null);
return mapping;
}
final Class<?> dataType = column.getType();
if (factory != null && (mapping == null || !columnName.equals(mapping.getMappingColumnName()))) {
// Need to create new mapping function
if (ContinuousMapping.class.isAssignableFrom(factory.getMappingFunctionType()) && !Number.class.isAssignableFrom(dataType)) {
JOptionPane.showMessageDialog(null, "Continuous Mapper can be used with numbers only.\nPlease select a numerical column type.", "Incompatible Mapping Type.", JOptionPane.INFORMATION_MESSAGE);
prop.setValue(mapping != null ? mapping.getMappingColumnName() : null);
return mapping;
}
return switchMappingType(prop, vp, factory, factory, columnName, propertySheetPanel);
}
return mapping;
}
Aggregations