Search in sources :

Example 1 with PropertyRendererRegistry

use of com.l2fprod.common.propertysheet.PropertyRendererRegistry 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 PropertyRendererRegistry

use of com.l2fprod.common.propertysheet.PropertyRendererRegistry 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);
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 3 with PropertyRendererRegistry

use of com.l2fprod.common.propertysheet.PropertyRendererRegistry 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"));
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 4 with PropertyRendererRegistry

use of com.l2fprod.common.propertysheet.PropertyRendererRegistry in project cytoscape-impl by cytoscape.

the class VisualPropertySheetItem method getPropSheetPnl.

public PropertySheetPanel getPropSheetPnl() {
    if (propSheetPnl == null) {
        propSheetPnl = new PropertySheetPanel();
        propSheetPnl.setToolBarVisible(false);
        propSheetPnl.setMode(PropertySheetPanel.VIEW_AS_FLAT_LIST);
        propSheetPnl.setTable(getPropSheetTbl());
        propSheetPnl.getTable().setEditorFactory(new PropertyEditorRegistry());
        propSheetPnl.getTable().setRendererFactory(new PropertyRendererRegistry());
        final VisualMappingFunction<?, T> mapping = model.getVisualMappingFunction();
        if (mapping == null) {
            // Create the properties for a new visual mapping
            final VisualProperty<?> vp = (VisualProperty<?>) model.getVisualProperty();
            vizMapPropertyBuilder.buildProperty(vp, propSheetPnl);
        } else {
            // There is already a visual mapping for this style's property
            final VisualMappingFunctionFactory mappingFactory = vizMapPropertyBuilder.getMappingFactory(mapping);
            vizMapPropertyBuilder.buildProperty(mapping, propSheetPnl, mappingFactory);
            updateMappingRowHeight();
        }
        // This is necessary because the Property Sheet Table steals the mouse wheel event
        // which prevents the parent scroll pane from receiving it when the mouse is over the property sheet panel.
        final Container c = propSheetPnl.getTable().getParent().getParent();
        if (c instanceof JScrollPane)
            c.addMouseWheelListener(new CustomMouseWheelListener((JScrollPane) c));
    }
    return propSheetPnl;
}
Also used : PropertySheetPanel(com.l2fprod.common.propertysheet.PropertySheetPanel) JScrollPane(javax.swing.JScrollPane) PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) Container(java.awt.Container) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) VisualProperty(org.cytoscape.view.model.VisualProperty)

Example 5 with PropertyRendererRegistry

use of com.l2fprod.common.propertysheet.PropertyRendererRegistry 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();
    }
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) CellType(org.cytoscape.view.vizmap.gui.internal.event.CellType) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) Property(com.l2fprod.common.propertysheet.Property) VisualProperty(org.cytoscape.view.model.VisualProperty) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)

Aggregations

PropertyRendererRegistry (com.l2fprod.common.propertysheet.PropertyRendererRegistry)6 PropertyEditorRegistry (com.l2fprod.common.propertysheet.PropertyEditorRegistry)5 VisualProperty (org.cytoscape.view.model.VisualProperty)4 VisualMappingFunction (org.cytoscape.view.vizmap.VisualMappingFunction)4 VizMapperProperty (org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)4 PropertySheetTable (com.l2fprod.common.propertysheet.PropertySheetTable)3 CyIdentifiable (org.cytoscape.model.CyIdentifiable)3 VisualMappingFunctionFactory (org.cytoscape.view.vizmap.VisualMappingFunctionFactory)3 PropertyEditor (java.beans.PropertyEditor)2 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 VisualPropertyEditor (org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor)2 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)2 Property (com.l2fprod.common.propertysheet.Property)1 PropertySheetPanel (com.l2fprod.common.propertysheet.PropertySheetPanel)1 Container (java.awt.Container)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 JScrollPane (javax.swing.JScrollPane)1