Search in sources :

Example 1 with VisualPropertyEditor2

use of org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor2 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)1 PropertyRendererRegistry (com.l2fprod.common.propertysheet.PropertyRendererRegistry)1 PropertySheetTable (com.l2fprod.common.propertysheet.PropertySheetTable)1 PropertyEditor (java.beans.PropertyEditor)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 VisualMappingFunction (org.cytoscape.view.vizmap.VisualMappingFunction)1 VisualPropertyEditor (org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor)1 VisualPropertyEditor2 (org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor2)1 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)1