use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-impl by cytoscape.
the class DNodeView method getParentCustomGraphicsProperty.
@SuppressWarnings({ "rawtypes", "unchecked" })
private VisualProperty<CyCustomGraphics> getParentCustomGraphicsProperty(final VisualProperty<?> vp) {
VisualProperty<CyCustomGraphics> parent = null;
// Use the visual property tree to retrieve its parent.
final VisualLexiconNode lexNode = lexicon.getVisualLexiconNode(vp);
final Collection<VisualLexiconNode> leavs = lexNode.getParent().getChildren();
for (VisualLexiconNode vlNode : leavs) {
if (vlNode.getVisualProperty().getRange().getType().equals(CyCustomGraphics.class)) {
parent = (VisualProperty<CyCustomGraphics>) vlNode.getVisualProperty();
break;
}
}
if (parent == null)
logger.error("Associated CustomGraphics VisualProperty is missing for " + vp.getDisplayName());
return parent;
}
use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-impl by cytoscape.
the class AbstractDViewModel method propagateLockedVisualProperty.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void propagateLockedVisualProperty(final VisualProperty parent, final Collection<VisualLexiconNode> roots, final Object value) {
final LinkedList<VisualLexiconNode> nodes = new LinkedList<>();
nodes.addAll(roots);
while (!nodes.isEmpty()) {
final VisualLexiconNode node = nodes.pop();
final VisualProperty vp = node.getVisualProperty();
if (!isDirectlyLocked(vp)) {
if (parent.getClass() == vp.getClass()) {
// Caller should already have write lock to modify this
synchronized (getDGraphView().m_lock) {
allLocks.put(vp, value);
}
applyVisualProperty(vp, value);
}
nodes.addAll(node.getChildren());
}
}
}
use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-impl by cytoscape.
the class AbstractDViewModel method setLockedValue.
@Override
public <T, V extends T> void setLockedValue(final VisualProperty<? extends T> vp, final V value) {
synchronized (getDGraphView().m_lock) {
directLocks.put(vp, value);
allLocks.put(vp, value);
applyVisualProperty(vp, value);
VisualLexiconNode node = lexicon.getVisualLexiconNode(vp);
propagateLockedVisualProperty(vp, node.getChildren(), value);
}
fireViewChangedEvent(vp, value, true);
}
use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-impl by cytoscape.
the class VisualPropertySheet method createMenuItems.
private void createMenuItems() {
final JPopupMenu rootMenu = getVpsMenu();
// Remove previous menu items
menuItemMap.clear();
final int length = rootMenu.getSubElements() != null ? rootMenu.getSubElements().length : 0;
for (int i = 0; i < length; i++) rootMenu.remove(i);
// Add new menu items
final VisualLexicon lexicon = model.getVisualLexicon();
final VisualProperty<?> rootVp = model.getRootVisualProperty();
final VisualLexiconNode rootNode = lexicon.getVisualLexiconNode(rootVp);
// Menu Items for showing/hiding each VP Sheet Item
// ------------------------------------------------
// -- Visual Properties --
final Queue<VisualLexiconNode> queue = new PriorityQueue<>(50, new Comparator<VisualLexiconNode>() {
@Override
public int compare(final VisualLexiconNode n1, final VisualLexiconNode n2) {
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.PRIMARY);
return collator.compare(VisualPropertySheetItemModel.createTitle(n1.getVisualProperty()), VisualPropertySheetItemModel.createTitle(n2.getVisualProperty()));
}
});
queue.addAll(rootNode.getChildren());
final Map<VisualLexiconNode, JComponent> menuMap = new HashMap<>();
menuMap.put(rootNode, rootMenu);
final VisualStyle style = model.getVisualStyle();
final Set<VisualProperty<?>> disabledProps = new HashSet<>();
// final Set<VisualPropertyDependency<?>> depSet = style.getAllVisualPropertyDependencies();
// for (final VisualPropertyDependency<?> dep : depSet) {
// // To do the same as in Cytoscape v2.8, we only care about these dependencies
// if (!dep.getIdString().equals("arrowColorMatchesEdge") && !dep.getIdString().equals("nodeSizeLocked"))
// continue; // TODO: revisit these requirements and remove this workaround.
// In general, the user should not be able to lock the child properties of an enabled dependency.
// if (dep.isDependencyEnabled())
// disabledProps.addAll(dep.getVisualProperties());
// else
// disabledProps.add(dep.getParentVisualProperty());
// }
final Set<VisualLexiconNode> nextNodes = new HashSet<>();
while (!queue.isEmpty()) {
final VisualLexiconNode curNode = queue.poll();
final VisualProperty<?> vp = curNode.getVisualProperty();
if (vp.getTargetDataType() == model.getTargetDataType()) {
final Collection<VisualLexiconNode> children = curNode.getChildren();
nextNodes.addAll(children);
if (PropertySheetUtil.isCompatible(vp)) {
VisualLexiconNode parentNode = curNode.getParent();
boolean leaf = children.isEmpty();
final VisualPropertySheetItem<?> vpSheetItem = getItem(vp);
final String label = vpSheetItem != null ? vpSheetItem.getModel().getTitle() : VisualPropertySheetItemModel.createTitle(vp);
if (!leaf) {
// Non-leaf visual property...
final JMenuItem nonLeafMenu = new JMenu(label);
menuMap.put(curNode, nonLeafMenu);
menuMap.get(parentNode).add(nonLeafMenu);
// So this VP can also be added as a child of itself
parentNode = curNode;
}
if (vpSheetItem != null) {
final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(label, vpSheetItem.isVisible());
mi.addActionListener(evt -> {
// Show/hide the Visual Property Sheet Item
setVisible(vpSheetItem, !vpSheetItem.isVisible());
});
menuMap.get(parentNode).add(mi);
menuItemMap.put(vpSheetItem, mi);
if (parentNode == curNode)
menuMap.get(parentNode).add(new JSeparator());
// Should this visual property be disabled?
if (disabledProps.contains(vp))
mi.setEnabled(false);
}
}
}
queue.addAll(nextNodes);
nextNodes.clear();
}
// -- Visual Property Dependencies --
final TreeSet<VisualPropertyDependency<?>> depTreeSet = new TreeSet<>((VisualPropertyDependency<?> d1, VisualPropertyDependency<?> d2) -> {
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.PRIMARY);
return collator.compare(d1.getDisplayName(), d2.getDisplayName());
});
depTreeSet.addAll(style.getAllVisualPropertyDependencies());
for (final VisualPropertyDependency<?> dep : depTreeSet) {
final VisualPropertySheetItem<?> vpSheetItem = getItem(dep);
if (vpSheetItem != null) {
final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(dep.getDisplayName(), vpSheetItem.isVisible());
mi.addActionListener(evt -> {
// Show/hide the Visual Property Sheet Item
setVisible(vpSheetItem, !vpSheetItem.isVisible());
});
final VisualLexiconNode parentNode = lexicon.getVisualLexiconNode(dep.getParentVisualProperty());
JComponent parentMenu = menuMap.get(parentNode);
if (// just add it directly to the popup menu
parentMenu == null)
parentMenu = rootMenu;
parentMenu.add(mi);
menuItemMap.put(vpSheetItem, mi);
}
}
// ------------------------------------------------
if (menuMap.size() > 1) {
rootMenu.add(new JSeparator());
{
final JMenuItem mi = new JMenuItem("Show All");
mi.addActionListener(evt -> {
for (Entry<VisualPropertySheetItem<?>, JCheckBoxMenuItem> entry : menuItemMap.entrySet()) setVisible(entry.getKey(), true);
});
rootMenu.add(mi);
}
{
final JMenuItem mi = new JMenuItem("Hide All");
mi.addActionListener(evt -> {
for (Entry<VisualPropertySheetItem<?>, JCheckBoxMenuItem> entry : menuItemMap.entrySet()) setVisible(entry.getKey(), false);
});
rootMenu.add(mi);
}
getVpsBtn().setEnabled(true);
} else {
getVpsBtn().setEnabled(false);
}
}
use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-impl by cytoscape.
the class AbstractApplyHandler method apply.
@Override
public void apply(final CyRow row, final View<T> view) {
if (updateDependencyMaps)
updateDependencyMaps();
// Clear visual properties first
view.clearVisualProperties();
// Get current Visual Lexicon
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final VisualLexicon lexicon = appMgr.getCurrentNetworkViewRenderer().getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT).getVisualLexicon();
final LinkedList<VisualLexiconNode> descendants = new LinkedList<VisualLexiconNode>();
descendants.addAll(lexicon.getVisualLexiconNode(rootVisualProperty).getChildren());
while (!descendants.isEmpty()) {
final VisualLexiconNode node = descendants.pop();
final VisualProperty<?> vp = node.getVisualProperty();
if (vp.getTargetDataType() != targetDataType)
// Because NETWORK has node/edge properties as descendants as well
continue;
final VisualMappingFunction<?, ?> mapping = style.getVisualMappingFunction(vp);
final Object value = mapping != null ? mapping.getMappedValue(row) : null;
if (value == null) {
// Apply the default value...
applyDefaultValue(view, vp, lexicon);
} else {
// Apply the mapped value...
applyMappedValue(view, vp, value);
}
descendants.addAll(node.getChildren());
}
}
Aggregations