use of org.cytoscape.view.vizmap.VisualStyle 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.VisualStyle in project cytoscape-impl by cytoscape.
the class VizMapperMediator method createVisualPropertySheets.
private void createVisualPropertySheets(final boolean resetDefaultVisibleItems) {
final VisualStyle style = vmProxy.getCurrentVisualStyle();
final VisualLexicon lexicon = vmProxy.getCurrentVisualLexicon();
invokeOnEDT(() -> {
final VisualPropertySheet selVpSheet = getSelectedVisualPropertySheet();
final Class<? extends CyIdentifiable> selectedTargetDataType = selVpSheet != null ? selVpSheet.getModel().getTargetDataType() : null;
for (final Class<? extends CyIdentifiable> type : SHEET_TYPES) {
// Create Visual Property Sheet
final VisualPropertySheetModel model = new VisualPropertySheetModel(type, style, lexicon);
final VisualPropertySheet vpSheet = new VisualPropertySheet(model, servicesUtil);
vizMapperMainPanel.addVisualPropertySheet(vpSheet);
// Create Visual Property Sheet Items
final Set<VisualPropertySheetItem<?>> vpSheetItems = createVisualPropertySheetItems(vpSheet.getModel().getTargetDataType(), lexicon, style);
vpSheet.setItems(vpSheetItems);
// Add event listeners to the new components
addViewListeners(vpSheet);
// Add another menu item to the Properties menu
vpSheet.getVpsMenu().add(new JSeparator());
final JMenuItem mi = new JMenuItem("Make Default");
mi.addActionListener(evt -> saveDefaultVisibleItems(vpSheet));
vpSheet.getVpsMenu().add(mi);
}
updateVisibleItems(resetDefaultVisibleItems);
updateItemsStatus();
// Update panel's width
int minWidth = 200;
for (final VisualPropertySheet vpSheet : vizMapperMainPanel.getVisualPropertySheets()) {
minWidth = Math.max(minWidth, vpSheet.getMinimumSize().width);
}
vizMapperMainPanel.setPreferredSize(new Dimension(vizMapperMainPanel.getPropertiesPn().getMinimumSize().width + 20, vizMapperMainPanel.getPreferredSize().height));
// Select the same sheet that was selected before
final VisualPropertySheet vpSheet = vizMapperMainPanel.getVisualPropertySheet(selectedTargetDataType);
vizMapperMainPanel.setSelectedVisualPropertySheet(vpSheet);
});
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VizMapperMediator method updateVisualPropertySheets.
@SuppressWarnings("rawtypes")
private void updateVisualPropertySheets(final VisualStyle vs, final boolean resetDefaultVisibleItems) {
if (vs == null)
return;
final VisualPropertySheet curNetSheet = vizMapperMainPanel.getVisualPropertySheet(CyNetwork.class);
final VisualPropertySheetModel curModel = curNetSheet != null ? curNetSheet.getModel() : null;
final VisualStyle curStyle = curModel != null ? curModel.getVisualStyle() : null;
final CyNetworkView curNetView = vmProxy.getCurrentNetworkView();
final String newRendererId = curNetView != null ? curNetView.getRendererId() : "";
// If a different style or renderer, rebuild all property sheets
boolean rebuild = !vs.equals(curStyle) || !newRendererId.equals(curRendererId);
if (curNetView != null)
curRendererId = curNetView.getRendererId();
if (!rebuild) {
// Also check if dependencies have changed
final Map<String, VisualPropertyDependency<?>> map = new HashMap<>();
final Set<VisualPropertyDependency<?>> dependencies = vs.getAllVisualPropertyDependencies();
for (final VisualPropertyDependency<?> dep : dependencies) {
final Class<? extends CyIdentifiable> type = dep.getParentVisualProperty().getTargetDataType();
final VisualPropertySheet sheet = vizMapperMainPanel.getVisualPropertySheet(type);
if (sheet.getItem(dep) == null) {
// There's a new dependency!
rebuild = true;
break;
}
map.put(dep.getIdString(), dep);
}
if (!rebuild) {
final Set<VisualPropertySheet> vpSheets = vizMapperMainPanel.getVisualPropertySheets();
for (final VisualPropertySheet sheet : vpSheets) {
for (final VisualPropertySheetItem<?> item : sheet.getItems()) {
final VisualPropertyDependency<?> dep = item.getModel().getVisualPropertyDependency();
if (dep != null && !map.containsKey(dep.getIdString())) {
// This dependency has been removed from the Visual Style!
rebuild = true;
break;
}
}
}
}
}
if (rebuild) {
createVisualPropertySheets(resetDefaultVisibleItems);
} else {
// Just update the current Visual Property sheets
final Set<VisualPropertySheet> vpSheets = vizMapperMainPanel.getVisualPropertySheets();
for (final VisualPropertySheet sheet : vpSheets) {
for (final VisualPropertySheetItem<?> item : sheet.getItems()) {
// Update values
final VisualPropertySheetItemModel model = item.getModel();
model.update(vizMapperMainPanel.getRenderingEngine());
if (model.getVisualPropertyDependency() != null)
item.update();
// Also make sure items with mappings are visible
if (model.getVisualMappingFunction() != null)
item.setVisible(true);
}
}
if (resetDefaultVisibleItems)
updateVisibleItems(resetDefaultVisibleItems);
}
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VizMapperMediator method updateVisualStyleList.
private void updateVisualStyleList(final SortedSet<VisualStyle> styles, final boolean resetDefaultVisibleItems) {
attrProxy.setCurrentMappingType(null);
mappingFactoryProxy.setCurrentColumnName(null);
final RenderingEngineFactory<CyNetwork> engineFactory = vmProxy.getRenderingEngineFactory(previewNetView);
invokeOnEDT(() -> {
ignoreVisualStyleSelectedEvents = true;
vizMapperMainPanel.updateVisualStyles(styles, previewNetView, engineFactory);
final VisualStyle vs = vmProxy.getCurrentVisualStyle();
selectCurrentVisualStyle(vs);
updateVisualPropertySheets(vs, resetDefaultVisibleItems);
ignoreVisualStyleSelectedEvents = false;
});
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VizMapperMediator method selectCurrentVisualStyle.
private void selectCurrentVisualStyle(final VisualStyle vs) {
invokeOnEDT(() -> {
final VisualStyle selectedVs = vizMapperMainPanel.getSelectedVisualStyle();
// Switching styles. Need to reset the range tracer
ContinuousMappingEditorPanel.setTracer(new EditorValueRangeTracer(servicesUtil));
if (vs != null && !vs.equals(selectedVs))
vizMapperMainPanel.setSelectedVisualStyle(vs);
});
}
Aggregations