use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class VizMapPropertyBuilder method buildProperty.
/**
* Build the properties for an existing Visual Mapping Function.
* @param <K> data type of attribute to be mapped.
* @param <V> data type of Visual Property.
*/
public <K, V> void buildProperty(final VisualMappingFunction<K, V> visualMapping, final PropertySheetPanel propertySheetPanel, final VisualMappingFunctionFactory factory) {
if (visualMapping == null)
throw new IllegalArgumentException("'visualMapping' must not be null.");
if (propertySheetPanel == null)
throw new IllegalArgumentException("'propertySheetPanel' must not be null.");
if (factory == null)
throw new IllegalArgumentException("'factory' must not be null.");
final VisualProperty<V> vp = visualMapping.getVisualProperty();
final VizMapperProperty<VisualProperty<V>, String, VisualMappingFunctionFactory> columnProp = new VizMapperProperty<VisualProperty<V>, String, VisualMappingFunctionFactory>(CellType.VISUAL_PROPERTY_TYPE, vp, String.class);
// Build Property object
columnProp.setDisplayName(COLUMN);
columnProp.setValue(visualMapping.getMappingColumnName());
columnProp.setInternalValue(factory);
final String attrName = visualMapping.getMappingColumnName();
final VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<K, V>> mapTypeProp = new VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<K, V>>(CellType.MAPPING_TYPE, MAPPING_TYPE, VisualMappingFunctionFactory.class);
if (attrName == null)
columnProp.setValue(null);
((PropertyRendererRegistry) propertySheetPanel.getTable().getRendererFactory()).registerRenderer(columnProp, defaultTableCellRenderer);
mapTypeProp.setDisplayName(MAPPING_TYPE);
// Set mapping type as string.
mapTypeProp.setValue(factory);
mapTypeProp.setInternalValue(visualMapping);
((PropertyRendererRegistry) propertySheetPanel.getTable().getRendererFactory()).registerRenderer(mapTypeProp, defaultTableCellRenderer);
// TODO: Should refactor factory.
propertySheetPanel.addProperty(0, columnProp);
propertySheetPanel.addProperty(1, mapTypeProp);
final PropertyEditorRegistry propEditorRegistry = (PropertyEditorRegistry) propertySheetPanel.getTable().getEditorFactory();
propEditorRegistry.registerEditor(columnProp, editorManager.getDataTableComboBoxEditor((Class<? extends CyIdentifiable>) vp.getTargetDataType()));
propEditorRegistry.registerEditor(mapTypeProp, editorManager.getDefaultComboBoxEditor("mappingTypeEditor"));
// Mapping Editor
createMappingProperties(visualMapping, propertySheetPanel, factory);
}
use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class VizMapPropertyBuilder method buildProperty.
/**
* Build the properties for a new Visual Mapping Function.
* @param <V> data type of Visual Property.
*/
public <V> void buildProperty(final VisualProperty<V> visualProperty, final PropertySheetPanel propertySheetPanel) {
if (visualProperty == null)
throw new IllegalArgumentException("'visualProperty' must not be null.");
if (propertySheetPanel == null)
throw new IllegalArgumentException("'propertySheetPanel' must not be null.");
// TODO: Refactor--create new view component for mapping editor???
final VizMapperProperty<VisualProperty<V>, String, VisualMappingFunctionFactory> columnProp = new VizMapperProperty<VisualProperty<V>, String, VisualMappingFunctionFactory>(CellType.VISUAL_PROPERTY_TYPE, visualProperty, String.class);
// Build Property object
columnProp.setDisplayName(COLUMN);
((PropertyRendererRegistry) propertySheetPanel.getTable().getRendererFactory()).registerRenderer(columnProp, defaultTableCellRenderer);
final VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<?, V>> mapTypeProp = new VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<?, V>>(CellType.MAPPING_TYPE, MAPPING_TYPE, VisualMappingFunctionFactory.class);
mapTypeProp.setDisplayName(MAPPING_TYPE);
((PropertyRendererRegistry) propertySheetPanel.getTable().getRendererFactory()).registerRenderer(mapTypeProp, defaultTableCellRenderer);
propertySheetPanel.addProperty(0, columnProp);
propertySheetPanel.addProperty(1, mapTypeProp);
propertySheetPanel.repaint();
final PropertyEditorRegistry propEditorRegistry = (PropertyEditorRegistry) propertySheetPanel.getTable().getEditorFactory();
propEditorRegistry.registerEditor(columnProp, editorManager.getDataTableComboBoxEditor((Class<? extends CyIdentifiable>) visualProperty.getTargetDataType()));
propEditorRegistry.registerEditor(mapTypeProp, editorManager.getDefaultComboBoxEditor("mappingTypeEditor"));
}
use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class VizMapPropertyBuilder method removeMappingProperties.
protected void removeMappingProperties(final PropertySheetPanel propertySheetPanel) {
final Property[] properties = propertySheetPanel.getProperties();
if (properties != null) {
final PropertySheetTable table = propertySheetPanel.getTable();
final PropertyRendererRegistry rendReg = (PropertyRendererRegistry) table.getRendererFactory();
for (final Property p : properties) {
if (p instanceof VizMapperProperty) {
final CellType cellType = ((VizMapperProperty<?, ?, ?>) p).getCellType();
if (cellType == CellType.CONTINUOUS || cellType == CellType.DISCRETE) {
if (cellType == CellType.CONTINUOUS) {
// TODO: Update range trace?
rendReg.unregisterRenderer(p);
}
propertySheetPanel.removeProperty(p);
}
}
}
table.repaint();
propertySheetPanel.repaint();
}
}
use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty 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.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class RemoveSelectedDiscreteValuesAction method updateEnableState.
@Override
public void updateEnableState() {
boolean enabled = false;
final VizMapperMainPanel vizMapperMainPanel = getVizMapperMainPanel();
VisualPropertySheet vpSheet = null;
if (vizMapperMainPanel != null)
vpSheet = vizMapperMainPanel.getSelectedVisualPropertySheet();
if (vpSheet != null) {
for (final VisualPropertySheetItem<?> vpSheetItem : vpSheet.getSelectedItems()) {
final VisualPropertySheetItemModel<?> model = vpSheetItem.getModel();
final PropertySheetTable table = vpSheetItem.getPropSheetPnl().getTable();
final int[] selected = table.getSelectedRows();
if (selected != null && model.getVisualMappingFunction() instanceof DiscreteMapping) {
// Make sure the selected rows have at least one Discrete Mapping entry with non-null value
for (int i = 0; i < selected.length; i++) {
final Item item = (Item) table.getValueAt(selected[i], 0);
if (item != null && item.getProperty() instanceof VizMapperProperty) {
final VizMapperProperty<?, ?, ?> prop = (VizMapperProperty<?, ?, ?>) item.getProperty();
if (prop.getCellType() == CellType.DISCRETE && prop.getValue() != null) {
enabled = true;
break;
}
}
}
}
}
}
setEnabled(enabled);
}
Aggregations