Search in sources :

Example 1 with VisualPropertyEditor

use of org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor 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();
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) ContinuousMappingEditor(org.cytoscape.view.vizmap.gui.editor.ContinuousMappingEditor) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) TreeSet(java.util.TreeSet) CyIdentifiable(org.cytoscape.model.CyIdentifiable) HashSet(java.util.HashSet) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyColumn(org.cytoscape.model.CyColumn) CyEdge(org.cytoscape.model.CyEdge) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) CyApplicationManager(org.cytoscape.application.CyApplicationManager) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) VisualPropertyEditor(org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor) PropertyEditor(java.beans.PropertyEditor) Map(java.util.Map)

Example 2 with VisualPropertyEditor

use of org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor in project cytoscape-impl by cytoscape.

the class VizMapPropertyBuilder method setDiscreteProps.

/**
 * Set value, title, and renderer for each property in the category. This
 * list should be created against all available attribute values.
 */
private <K, V> void setDiscreteProps(VisualProperty<V> vp, VisualMappingFunction<K, V> mapping, SortedSet<Object> attrSet, VisualPropertyEditor<V> vpEditor, PropertySheetPanel propertySheetPanel) {
    if (attrSet == null)
        return;
    final Map<K, V> discMapping = ((DiscreteMapping<K, V>) mapping).getAll();
    V val = null;
    VizMapperProperty<K, V, VisualMappingFunction<K, V>> valProp;
    String strVal;
    final PropertySheetTable table = propertySheetPanel.getTable();
    final PropertyRendererRegistry cellRendererFactory = (PropertyRendererRegistry) table.getRendererFactory();
    final PropertyEditorRegistry cellEditorFactory = (PropertyEditorRegistry) table.getEditorFactory();
    for (final Object key : attrSet) {
        valProp = new VizMapperProperty<K, V, VisualMappingFunction<K, V>>(CellType.DISCRETE, (K) key, mapping.getVisualProperty().getRange().getType());
        strVal = key.toString();
        valProp.setDisplayName(strVal);
        // but we don't know the type of the list items.
        if (mapping.getMappingColumnType() == String.class && !(key instanceof String))
            val = discMapping.get(key.toString());
        else
            val = discMapping.get(key);
        if (val != null)
            valProp.setType(val.getClass());
        propertySheetPanel.addProperty(valProp);
        if (vpEditor != null) {
            final TableCellRenderer renderer = vpEditor.getDiscreteTableCellRenderer();
            if (renderer != null)
                cellRendererFactory.registerRenderer(valProp, renderer);
            PropertyEditor cellEditor = null;
            if (vpEditor instanceof VisualPropertyEditor2) {
                cellEditor = ((VisualPropertyEditor2) vpEditor).getPropertyEditor(vp);
            } else {
                cellEditor = vpEditor.getPropertyEditor();
            }
            if (cellEditor != null)
                cellEditorFactory.registerEditor(valProp, cellEditor);
        }
        valProp.setValue(val);
        valProp.setInternalValue(mapping);
    }
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) VisualPropertyEditor(org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor) PropertyEditor(java.beans.PropertyEditor) VisualPropertyEditor2(org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor2)

Aggregations

PropertyEditorRegistry (com.l2fprod.common.propertysheet.PropertyEditorRegistry)2 PropertyRendererRegistry (com.l2fprod.common.propertysheet.PropertyRendererRegistry)2 PropertySheetTable (com.l2fprod.common.propertysheet.PropertySheetTable)2 PropertyEditor (java.beans.PropertyEditor)2 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 VisualMappingFunction (org.cytoscape.view.vizmap.VisualMappingFunction)2 VisualPropertyEditor (org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor)2 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 CyColumn (org.cytoscape.model.CyColumn)1 CyEdge (org.cytoscape.model.CyEdge)1 CyIdentifiable (org.cytoscape.model.CyIdentifiable)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyRow (org.cytoscape.model.CyRow)1 ContinuousMappingEditor (org.cytoscape.view.vizmap.gui.editor.ContinuousMappingEditor)1 VisualPropertyEditor2 (org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor2)1