Search in sources :

Example 1 with PropertySheetPanel

use of com.l2fprod.common.propertysheet.PropertySheetPanel 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();
}
Also used : PropertySheetPanel(com.l2fprod.common.propertysheet.PropertySheetPanel) VisualPropertySheet(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) UndoSupport(org.cytoscape.work.undo.UndoSupport) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualPropertySheetItemModel(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItemModel) Item(com.l2fprod.common.propertysheet.PropertySheetTableModel.Item) VisualPropertySheetItem(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem) NumberSeriesMappingGenerator(org.cytoscape.view.vizmap.gui.internal.util.mapgenerator.NumberSeriesMappingGenerator) VisualProperty(org.cytoscape.view.model.VisualProperty) RandomNumberMappingGenerator(org.cytoscape.view.vizmap.gui.internal.util.mapgenerator.RandomNumberMappingGenerator) HashMap(java.util.HashMap) Map(java.util.Map) VisualPropertySheetItem(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem)

Example 2 with PropertySheetPanel

use of com.l2fprod.common.propertysheet.PropertySheetPanel 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);
    }
}
Also used : PropertySheetPanel(com.l2fprod.common.propertysheet.PropertySheetPanel) HashMap(java.util.HashMap) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) TreeSet(java.util.TreeSet) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) Property(com.l2fprod.common.propertysheet.Property) VisualProperty(org.cytoscape.view.model.VisualProperty)

Example 3 with PropertySheetPanel

use of com.l2fprod.common.propertysheet.PropertySheetPanel 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 4 with PropertySheetPanel

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

the class CellEditorEventHandler method processEvent.

/**
 * Execute commands based on PropertyEditor's local event.
 *
 * In this handler, we should handle the following:
 * <ul>
 * <li>Mapping Type change
 * <li>Attribute Name Change
 * </ul>
 *
 * Other old global events (ex. Cytoscape.NETWORK_LOADED) is replaced by new
 * events.
 *
 * @param e PCE to be processed in this handler.
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void processEvent(final PropertyChangeEvent e) {
    final Object newVal = e.getNewValue();
    final Object oldVal = e.getOldValue();
    // Check update is necessary or not.
    if (newVal == null && oldVal == null)
        return;
    // Same value. No change required.
    if (newVal != null && newVal.equals(oldVal))
        return;
    final VisualPropertySheetItem<?> vpSheetItem = vizMapperMediator.getCurrentVisualPropertySheetItem();
    final PropertySheetPanel propSheetPnl = vpSheetItem != null ? vpSheetItem.getPropSheetPnl() : null;
    if (propSheetPnl == null)
        return;
    final VizMapperProperty<?, ?, ?> prop = vizMapperMediator.getCurrentVizMapperProperty();
    if (prop == null)
        return;
    final VisualProperty<?> vp = vpSheetItem.getModel().getVisualProperty();
    final VisualMappingFunction mapping = vpSheetItem.getModel().getVisualMappingFunction();
    if (prop.getCellType() == CellType.DISCRETE && mapping instanceof DiscreteMapping) {
        // Discrete mapping value changed:
        // -------------------------------
        // Create new map entry and register it.
        final DiscreteMapping<Object, Object> discMap = (DiscreteMapping<Object, Object>) mapping;
        setDiscreteMappingEntry(prop.getKey(), oldVal, newVal, discMap);
    } else {
        VisualMappingFunction newMapping = mapping;
        String undoName = null;
        if (prop.getCellType() == CellType.VISUAL_PROPERTY_TYPE) {
            // -----------------------
            if (newVal != null && e.getSource() instanceof AttributeComboBoxPropertyEditor) {
                final AttributeComboBoxPropertyEditor editor = (AttributeComboBoxPropertyEditor) e.getSource();
                final VisualMappingFunctionFactory factory = (VisualMappingFunctionFactory) propSheetPnl.getTable().getValueAt(1, 1);
                newMapping = switchColumn(factory, editor, prop, newVal.toString(), propSheetPnl);
                vpSheetItem.getModel().setVisualMappingFunction(newMapping);
                if (newMapping == null)
                    vpSheetItem.getModel().setMappingColumnName(prop.getValue() != null ? prop.getValue().toString() : null);
                undoName = "Set Mapping Column";
            }
        } else if (prop.getCellType() == CellType.MAPPING_TYPE) {
            // Mapping type changed:
            // -----------------------
            // Parent is always root.
            // TODO: refactor--this class should not have to know the row/column where the value is
            Object controllingAttrName = propSheetPnl.getTable().getValueAt(0, 1);
            if (vp != null && controllingAttrName != null && (newVal == null || newVal instanceof VisualMappingFunctionFactory)) {
                newMapping = switchMappingType(prop, vp, (VisualMappingFunctionFactory) oldVal, (VisualMappingFunctionFactory) newVal, controllingAttrName.toString(), propSheetPnl);
                vpSheetItem.getModel().setVisualMappingFunction(newMapping);
                undoName = "Set Mapping Type";
            }
        }
        if (newMapping != mapping && undoName != null) {
            // Add undo support
            final VisualMappingFunction myNewMapping = newMapping;
            final UndoSupport undo = servicesUtil.get(UndoSupport.class);
            undo.postEdit(new AbstractCyEdit(undoName) {

                @Override
                public void undo() {
                    vpSheetItem.getModel().setVisualMappingFunction(mapping);
                }

                @Override
                public void redo() {
                    vpSheetItem.getModel().setVisualMappingFunction(myNewMapping);
                }
            });
        }
    }
}
Also used : PropertySheetPanel(com.l2fprod.common.propertysheet.PropertySheetPanel) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) UndoSupport(org.cytoscape.work.undo.UndoSupport) AbstractCyEdit(org.cytoscape.work.undo.AbstractCyEdit) AttributeComboBoxPropertyEditor(org.cytoscape.view.vizmap.gui.internal.view.editor.propertyeditor.AttributeComboBoxPropertyEditor)

Aggregations

PropertySheetPanel (com.l2fprod.common.propertysheet.PropertySheetPanel)4 VisualProperty (org.cytoscape.view.model.VisualProperty)3 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)3 HashMap (java.util.HashMap)2 VisualMappingFunctionFactory (org.cytoscape.view.vizmap.VisualMappingFunctionFactory)2 VizMapperProperty (org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)2 UndoSupport (org.cytoscape.work.undo.UndoSupport)2 Property (com.l2fprod.common.propertysheet.Property)1 PropertyEditorRegistry (com.l2fprod.common.propertysheet.PropertyEditorRegistry)1 PropertyRendererRegistry (com.l2fprod.common.propertysheet.PropertyRendererRegistry)1 Item (com.l2fprod.common.propertysheet.PropertySheetTableModel.Item)1 Container (java.awt.Container)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 JScrollPane (javax.swing.JScrollPane)1 VisualMappingFunction (org.cytoscape.view.vizmap.VisualMappingFunction)1 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1 NumberSeriesMappingGenerator (org.cytoscape.view.vizmap.gui.internal.util.mapgenerator.NumberSeriesMappingGenerator)1 RandomNumberMappingGenerator (org.cytoscape.view.vizmap.gui.internal.util.mapgenerator.RandomNumberMappingGenerator)1