use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class GenerateDiscreteValuesAction method actionPerformed.
// ==[ PUBLIC METHODS ]=============================================================================================
@Override
public void actionPerformed(final ActionEvent e) {
final VisualPropertySheet selVpSheet = getVizMapperMainPanel().getSelectedVisualPropertySheet();
if (selVpSheet == null)
return;
final Set<VisualPropertySheetItem<?>> vpSheetItems = selVpSheet.getSelectedItems();
new Thread() {
@Override
public void run() {
final Map<DiscreteMapping<?, ?>, Map<Object, Object>> previousMappingValues = new HashMap<DiscreteMapping<?, ?>, Map<Object, Object>>();
final Map<DiscreteMapping<?, ?>, Map<Object, ?>> newMappingValues = new HashMap<DiscreteMapping<?, ?>, Map<Object, ?>>();
for (final VisualPropertySheetItem<?> vpsItem : vpSheetItems) {
final VisualPropertySheetItemModel<?> model = vpsItem.getModel();
final VisualProperty<?> vp = (VisualProperty<?>) model.getVisualProperty();
final Class<?> vpValueType = vp.getRange().getType();
final Class<?> generatorType = generator.getDataType();
final PropertySheetPanel propSheetPnl = vpsItem.getPropSheetPnl();
final Item value = (Item) propSheetPnl.getTable().getValueAt(0, 0);
if (value.isProperty()) {
final VizMapperProperty<?, ?, ?> prop = (VizMapperProperty<?, ?, ?>) value.getProperty();
if (vpValueType.isAssignableFrom(generatorType) || ((generator instanceof NumberSeriesMappingGenerator || generator instanceof RandomNumberMappingGenerator) && Number.class.isAssignableFrom(vpValueType)))
generateValues(vpsItem, prop.getValue().toString(), vp, previousMappingValues, newMappingValues);
}
}
// Undo support
if (!previousMappingValues.isEmpty()) {
final UndoSupport undo = servicesUtil.get(UndoSupport.class);
undo.postEdit(new GenerateValuesEdit(previousMappingValues, newMappingValues));
}
}
}.start();
}
use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class GenerateDiscreteValuesAction method generateValues.
// ==[ PRIVATE METHODS ]============================================================================================
@SuppressWarnings({ "rawtypes", "unchecked" })
private void generateValues(final VisualPropertySheetItem<?> vpsItem, final String attrName, final VisualProperty<?> vp, final Map<DiscreteMapping<?, ?>, Map<Object, Object>> previousMappingValues, final Map<DiscreteMapping<?, ?>, Map<Object, ?>> newMappingValues) {
final VisualStyle style = servicesUtil.get(VisualMappingManager.class).getCurrentVisualStyle();
final VisualMappingFunction<?, ?> mapping = style.getVisualMappingFunction(vp);
if (!(mapping instanceof DiscreteMapping))
return;
final DiscreteMapping<Object, Object> dm = (DiscreteMapping) mapping;
final PropertySheetPanel propSheetPnl = vpsItem.getPropSheetPnl();
final SortedSet<Object> keySet = new TreeSet<Object>();
final Map<Object, Object> previousValues = new HashMap<Object, Object>();
for (final Property p : propSheetPnl.getProperties()) {
final VizMapperProperty<?, ?, ?> vmp = (VizMapperProperty<?, ?, ?>) p;
if (vmp.getCellType().equals(CellType.DISCRETE)) {
keySet.add(vmp.getKey());
// Save the current value for undo
previousValues.put(vmp.getKey(), vmp.getValue());
}
}
if (!keySet.isEmpty()) {
// Generate values
final Map<Object, ?> newValues = generator.generateMap(keySet);
// Save the mapping->old_values for undo
previousMappingValues.put(dm, previousValues);
// Save the mapping->new_values for redo
newMappingValues.put(dm, newValues);
// Update the visual mapping
dm.putAll(newValues);
}
}
use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class EditSelectedDiscreteValuesAction method actionPerformed.
// ==[ PUBLIC METHODS ]=============================================================================================
/**
* Edit all selected cells at once. This is for Discrete Mapping only.
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void actionPerformed(final ActionEvent e) {
final VizMapperMainPanel vizMapperMainPanel = getVizMapperMainPanel();
if (vizMapperMainPanel == null)
return;
final VisualPropertySheet vpSheet = vizMapperMainPanel.getSelectedVisualPropertySheet();
if (vpSheet == null)
return;
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 || selected.length == 0 || !(model.getVisualMappingFunction() instanceof DiscreteMapping))
continue;
// Test with the first selected item
final DiscreteMapping dm = (DiscreteMapping) model.getVisualMappingFunction();
final VisualProperty vp = dm.getVisualProperty();
Object newValue = null;
try {
// Get new value
newValue = editorManager.showVisualPropertyValueEditor(vizMapperMainPanel, vp, vp.getDefault());
} catch (Exception ex) {
logger.error("Could not edit value.", ex);
}
if (newValue == null)
continue;
final Map<Object, Object> newValues = new HashMap<Object, Object>();
final Map<Object, Object> previousValues = new HashMap<Object, Object>();
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) {
// Save the current value for undo
previousValues.put(prop.getKey(), prop.getValue());
// New value
newValues.put(prop.getKey(), newValue);
}
}
}
// Save the mapping->old_values for undo
if (!previousValues.isEmpty())
previousMappingValues.put(dm, previousValues);
// Save the mapping->new_values for redo
if (!newValues.isEmpty())
newMappingValues.put(dm, newValues);
// Update the visual mapping
dm.putAll(newValues);
}
// Undo support
if (!previousMappingValues.isEmpty()) {
final UndoSupport undo = servicesUtil.get(UndoSupport.class);
undo.postEdit(new EditSelectedDiscreteValuesEdit());
}
}
use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class EditSelectedDiscreteValuesAction 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
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) {
enabled = true;
break;
}
}
}
}
}
}
setEnabled(enabled);
}
use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.
the class VizMapPropertyBuilder method createMappingProperties.
public <K, V> void createMappingProperties(final VisualMappingFunction<K, V> visualMapping, final PropertySheetPanel propertySheetPanel, final VisualMappingFunctionFactory factory) {
final String attrName = visualMapping.getMappingColumnName();
if (attrName == null)
return;
removeMappingProperties(propertySheetPanel);
final VisualProperty<V> vp = visualMapping.getVisualProperty();
final VisualPropertyEditor<V> vpEditor = editorManager.getVisualPropertyEditor(vp);
if (visualMapping instanceof DiscreteMapping) {
// Discrete Mapping
// This set should not contain null!
final SortedSet<Object> attrSet = new TreeSet<Object>();
final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
final CyNetwork network = appMgr.getCurrentNetwork();
if (network != null) {
final Set<CyIdentifiable> graphObjects = new HashSet<CyIdentifiable>();
if (network != null) {
if (vp.getTargetDataType().equals(CyNode.class)) {
graphObjects.addAll(network.getNodeList());
} else if (vp.getTargetDataType().equals(CyEdge.class)) {
graphObjects.addAll(network.getEdgeList());
} else if (vp.getTargetDataType().equals(CyNetwork.class)) {
graphObjects.add(network);
} else {
throw new IllegalArgumentException("Data type not supported: " + vp.getTargetDataType());
}
}
if (vp.getTargetDataType() == CyNetwork.class) {
final CyRow row = network.getRow(network);
final CyColumn column = row.getTable().getColumn(attrName);
if (column != null)
processDiscretValues(row, attrName, column, column.getType(), attrSet);
} else {
// Make sure all data sets have the same data type.
if (!graphObjects.isEmpty()) {
final CyIdentifiable firstEntry = graphObjects.iterator().next();
final CyRow firstRow = network.getRow(firstEntry);
final CyColumn column = firstRow.getTable().getColumn(attrName);
if (column != null) {
final Class<?> type = column.getType();
for (final CyIdentifiable go : graphObjects) {
final CyRow row = network.getRow(go);
processDiscretValues(row, attrName, column, type, attrSet);
}
}
}
}
}
// Also keep current mapping entries that have non-null values
for (final Map.Entry<K, V> entry : ((DiscreteMapping<K, V>) visualMapping).getAll().entrySet()) {
if (entry.getValue() != null)
attrSet.add(entry.getKey());
}
setDiscreteProps(vp, visualMapping, attrSet, vpEditor, propertySheetPanel);
} else if (visualMapping instanceof ContinuousMapping) {
// TODO: How do we decide when to reset the range tracer for this mapping?
final VizMapperProperty<String, VisualMappingFunction, VisualMappingFunction<K, V>> graphicalView = new VizMapperProperty<String, VisualMappingFunction, VisualMappingFunction<K, V>>(CellType.CONTINUOUS, visualMapping.getVisualProperty().getDisplayName() + "_" + GRAPHICAL_MAP_VIEW, visualMapping.getClass());
graphicalView.setShortDescription("Continuous Mapping from " + visualMapping.getMappingColumnName() + " to " + visualMapping.getVisualProperty().getDisplayName());
graphicalView.setValue(visualMapping);
graphicalView.setDisplayName("Current Mapping");
propertySheetPanel.addProperty(2, graphicalView);
final PropertySheetTable table = propertySheetPanel.getTable();
final PropertyRendererRegistry rendReg = (PropertyRendererRegistry) table.getRendererFactory();
final PropertyEditorRegistry cellEditorFactory = (PropertyEditorRegistry) table.getEditorFactory();
final PropertyEditor continuousCellEditor = editorManager.getContinuousEditor(vp);
if (continuousCellEditor == null) {
throw new NullPointerException("Continuous Mapping cell editor is null.");
} else {
// Renderer for Continuous mapping icon cell
final TableCellRenderer continuousRenderer = vpEditor.getContinuousTableCellRenderer((ContinuousMappingEditor<? extends Number, V>) continuousCellEditor);
rendReg.registerRenderer(graphicalView, continuousRenderer);
continuousCellEditor.setValue(visualMapping);
cellEditorFactory.registerEditor(graphicalView, continuousCellEditor);
}
} else if (visualMapping instanceof PassthroughMapping && (attrName != null)) {
// Doesn't need to display the mapped values!
} else {
throw new IllegalArgumentException("Unsupported mapping type: " + visualMapping);
}
propertySheetPanel.getTable().repaint();
propertySheetPanel.repaint();
}
Aggregations