Author: paperwing
Date: 2012-03-12 16:21:57 -0700 (Mon, 12 Mar 2012)
New Revision: 28505
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/ContextMenuInputHandler.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/PopupMenuCreator.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/TaskFactoryListener.java
Log:
Added implementation of context menu creation based on implementation used by
Ding; about to run first tests with creating context menus based on node views
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/ContextMenuInputHandler.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/ContextMenuInputHandler.java
2012-03-12 23:09:12 UTC (rev 28504)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/ContextMenuInputHandler.java
2012-03-12 23:21:57 UTC (rev 28505)
@@ -6,20 +6,19 @@
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
+import org.cytoscape.model.CyNode;
import org.cytoscape.paperwing.internal.data.GraphicsData;
import org.cytoscape.paperwing.internal.task.PopupMenuCreator;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
/**
* Input handler responsible for creating the right-click context menu.
*/
public class ContextMenuInputHandler implements InputHandler {
- private PopupMenuCreator popupMenuCreator;
+ private PopupMenuCreator popupMenuCreator = null;
- public ContextMenuInputHandler() {
- popupMenuCreator = new PopupMenuCreator();
- }
-
@Override
public void processInput(KeyboardMonitor keys, MouseMonitor mouse,
GraphicsData graphicsData) {
@@ -28,14 +27,35 @@
}
private void processNetworkRightClickMenu(MouseMonitor mouse,
GraphicsData graphicsData){
+ if (popupMenuCreator == null) {
+ popupMenuCreator = new
PopupMenuCreator(graphicsData.getTaskManager());
+ }
+
Set<Integer> pressed = mouse.getPressed();
- if (pressed.contains(MouseEvent.BUTTON3)) {
- JPopupMenu menu = new JPopupMenu("Empty Menu");
- menu.add(new JMenuItem("Sample Action"));
+ CyNetworkView networkView = graphicsData.getNetworkView();
+
+ int nodeIndex =
graphicsData.getSelectionData().getHoverNodeIndex();
+ CyNode node = networkView.getModel().getNode(nodeIndex);
+
+ View<CyNode> nodeView = null;
+ if (node != null) {
+ nodeView = networkView.getNodeView(node);
+ }
+
+ if (pressed.contains(MouseEvent.BUTTON3) && nodeView != null) {
+
+
+ JPopupMenu popupMenu =
popupMenuCreator.createNodeMenu(nodeView,
+ networkView,
graphicsData.getVisualLexicon(),
+
graphicsData.getTaskFactoryListener().getNodeViewTaskFactories());
+
+
+ // menu.add(new JMenuItem("Sample Action"));
+
System.out.println("Creating context menu at : " +
mouse.x() + ", " + mouse.y());
- menu.show(graphicsData.getContainer(), mouse.x(),
mouse.y());
+ popupMenu.show(graphicsData.getContainer(), mouse.x(),
mouse.y());
}
}
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/PopupMenuCreator.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/PopupMenuCreator.java
2012-03-12 23:09:12 UTC (rev 28504)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/PopupMenuCreator.java
2012-03-12 23:21:57 UTC (rev 28505)
@@ -1,69 +1,175 @@
package org.cytoscape.paperwing.internal.task;
+import java.awt.event.ActionEvent;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
+import javax.swing.AbstractAction;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
+import org.cytoscape.paperwing.internal.data.GraphicsData;
import org.cytoscape.task.NodeViewTaskFactory;
+import org.cytoscape.util.swing.GravityTracker;
import org.cytoscape.util.swing.JMenuTracker;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualLexicon;
+import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TaskFactoryPredicate;
import org.cytoscape.work.swing.DialogTaskManager;
+import org.cytoscape.work.swing.DynamicSubmenuListener;
/**
* This class is responsible for creating and populating pop-up menus created
when right-clicking the network.
*/
public class PopupMenuCreator {
+
+ private DialogTaskManager taskManager;
+
+ // Large value to be used for the gravity value of
org.cytoscape.util.swing.GravityTracker
+ private double largeValue = Double.MAX_VALUE / 2.0;
- public void createNodeMenu(View<CyNode> nodeView,
+ public PopupMenuCreator(DialogTaskManager taskManager) {
+ this.taskManager = taskManager;
+ }
+
+ public JPopupMenu createNodeMenu(View<CyNode> nodeView,
CyNetworkView networkView,
- Map<NodeViewTaskFactory, Map<String, String>>
taskFactories,
- DialogTaskManager taskManager) {
-
- JPopupMenu menu = new JPopupMenu();
- JMenuTracker tracker = new JMenuTracker(menu);
+ VisualLexicon visualLexicon,
+ Map<NodeViewTaskFactory, Map<String, Object>>
taskFactories) {
- if (taskFactories.size() == 1) {
- NodeViewTaskFactory nodeViewTaskFactory =
taskFactories.keySet().iterator().next();
-
- nodeViewTaskFactory.setNodeView(nodeView, networkView);
- taskManager.execute(nodeViewTaskFactory);
-
- } else if (taskFactories.size() > 1) {
- for (Entry<NodeViewTaskFactory, Map<String, String>>
entry : taskFactories.entrySet()) {
+ JPopupMenu popupMenu = new JPopupMenu();
+ JMenuTracker tracker = new JMenuTracker(popupMenu);
+
+ if (taskFactories.size() >= 1) {
+ for (Entry<NodeViewTaskFactory, Map<String, Object>>
entry : taskFactories.entrySet()) {
- entry.getKey().setNodeView(nodeView,
networkView);
+ NodeViewTaskFactory nodeViewTaskFactory =
entry.getKey();
+ Map<String, Object> properties =
entry.getValue();
-
+ nodeViewTaskFactory.setNodeView(nodeView,
networkView);
+
+ createMenuItem(nodeView, visualLexicon,
popupMenu, nodeViewTaskFactory, tracker, properties);
}
}
+ return popupMenu;
+ }
+
+
+ private void createMenuItem(View<?> view, VisualLexicon visualLexicon,
JPopupMenu popupMenu, TaskFactory taskFactory,
+ JMenuTracker tracker, Map<String, Object>
properties) {
- /*
+ String title = null;
+ if (properties.get("title") != null) {
+ title = properties.get("title").toString();
+ }
- // build a menu of actions if more than factory exists
- if ( usableTFs.size() > 1) {
- String nodeLabel =
network.getRow(nv.getModel()).get("name",String.class);
- JPopupMenu menu = new JPopupMenu(nodeLabel);
- JMenuTracker tracker = new JMenuTracker(menu);
+ String tooltip = null;
+ if (properties.get("tooltip") != null) {
+ tooltip = properties.get("tooltip").toString();
+ }
+
+ String preferredMenu = null;
+ if (properties.get("preferredMenu") != null) {
+ preferredMenu =
properties.get("preferredMenu").toString();
+ }
+
+ // TODO: Ding implementation refers to a DynamicSubmenuListener
related to the SubMenuTaskManager,
+ // check if this is necessary for this implementation
+
+ // Below based on implementation from Ding
- for ( NodeViewTaskFactory nvtf : usableTFs ) {
- nvtf.setNodeView(nv, m_view);
- createMenuItem(nv, menu, nvtf, tracker,
m_view.nodeViewTFs.get( nvtf ));
+
+ Boolean useCheckBoxMenuItem =
Boolean.parseBoolean(String.valueOf(properties.get("useCheckBoxMenuItem")));
+ Object targetVisualProperty = properties.get("targetVP");
+ boolean isSelected = false;
+
+ // Update value for isSelected
+ if(view != null) {
+ if (targetVisualProperty != null &&
targetVisualProperty instanceof String ) {
+
+ Class<?> targetClass = CyNetwork.class;
+
+ if (view.getModel() instanceof CyNode)
+ targetClass = CyNode.class;
+ else if (view.getModel() instanceof CyEdge)
+ targetClass = CyEdge.class;
+
+ VisualProperty<?> visualProperty =
visualLexicon.lookup(CyNode.class, targetVisualProperty.toString());
+ if (visualProperty == null)
+ isSelected = false;
+ else
+ isSelected =
view.isValueLocked(visualProperty);
+ } else if ( targetVisualProperty instanceof
VisualProperty )
+ isSelected =
view.isValueLocked((VisualProperty<?>) targetVisualProperty);
+ }
+
+
+ // no title and no preferred menu
+ if (title == null && preferredMenu == null) {
+ title = "Unidentified Task: " +
Integer.toString(taskFactory.hashCode());
+ popupMenu.add(createMenuItem(taskFactory, title,
useCheckBoxMenuItem, tooltip));
+
+ // title, but no preferred menu
+ } else if (title != null && preferredMenu == null) {
+ popupMenu.add(createMenuItem(taskFactory, title,
useCheckBoxMenuItem, tooltip));
+
+ // no title, but preferred menu
+ } else if (title == null && preferredMenu != null) {
+ int last = preferredMenu.lastIndexOf(".");
+
+ // if the preferred menu is delimited
+ if (last > 0) {
+ title = preferredMenu.substring(last + 1);
+ preferredMenu = preferredMenu.substring(0,
last);
+ final GravityTracker gravityTracker =
tracker.getGravityTracker(preferredMenu);
+ final JMenuItem item =
createMenuItem(taskFactory, title,useCheckBoxMenuItem, tooltip);
+ if (useCheckBoxMenuItem) {
+ final JCheckBoxMenuItem checkBox =
(JCheckBoxMenuItem)item;
+ checkBox.setSelected(isSelected);
+ }
+ gravityTracker.addMenuItem(item, ++largeValue);
+ // otherwise just use the preferred menu as the
menuitem name
+ } else {
+ title = preferredMenu;
+ popupMenu.add( createMenuItem(taskFactory,
title, useCheckBoxMenuItem, tooltip) );
}
- menu.show(invoker, x, y);
-
- // execute the task directly if only one factory exists
- } else if ( usableTFs.size() == 1) {
- NodeViewTaskFactory tf = usableTFs.iterator().next();
- tf.setNodeView(nv, m_view);
- executeTask(tf);
+ // title and preferred menu
+ } else {
+ final GravityTracker gravityTracker =
tracker.getGravityTracker(preferredMenu);
+ gravityTracker.addMenuItem(createMenuItem(taskFactory,
title,useCheckBoxMenuItem, tooltip), ++largeValue);
}
+ }
- */
+ private JMenuItem createMenuItem(final TaskFactory taskFactory, String
title, boolean useCheckBoxMenuItem, String toolTipText) {
+ JMenuItem item;
+ AbstractAction action = new AbstractAction(title){
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ taskManager.execute(taskFactory);
+ }
+
+ };
+
+ if (useCheckBoxMenuItem)
+ item = new JCheckBoxMenuItem(action);
+ else
+ item = new JMenuItem(action);
+
+ if (taskFactory instanceof TaskFactoryPredicate)
+ item.setEnabled(((TaskFactoryPredicate)
taskFactory).isReady());
+
+ item.setToolTipText(toolTipText);
+ return item;
}
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/TaskFactoryListener.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/TaskFactoryListener.java
2012-03-12 23:09:12 UTC (rev 28504)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/task/TaskFactoryListener.java
2012-03-12 23:21:57 UTC (rev 28505)
@@ -14,56 +14,56 @@
* which are used in situations such as needing to execute a certain task via
the right-click menu.
*/
public class TaskFactoryListener implements CyListener {
- private Map<NodeViewTaskFactory, Map<String, String>>
nodeViewTaskFactories;
- private Map<EdgeViewTaskFactory, Map<String, String>>
edgeViewTaskFactories;
+ private Map<NodeViewTaskFactory, Map<String, Object>>
nodeViewTaskFactories;
+ private Map<EdgeViewTaskFactory, Map<String, Object>>
edgeViewTaskFactories;
- private Map<NetworkViewTaskFactory, Map<String, String>>
networkViewTaskFactories;
+ private Map<NetworkViewTaskFactory, Map<String, Object>>
networkViewTaskFactories;
public TaskFactoryListener() {
- nodeViewTaskFactories = new HashMap<NodeViewTaskFactory,
Map<String, String>>();
- edgeViewTaskFactories = new HashMap<EdgeViewTaskFactory,
Map<String, String>>();
- networkViewTaskFactories = new HashMap<NetworkViewTaskFactory,
Map<String, String>>();
+ nodeViewTaskFactories = new HashMap<NodeViewTaskFactory,
Map<String, Object>>();
+ edgeViewTaskFactories = new HashMap<EdgeViewTaskFactory,
Map<String, Object>>();
+ networkViewTaskFactories = new HashMap<NetworkViewTaskFactory,
Map<String, Object>>();
}
- public void addNodeViewTaskFactory(NodeViewTaskFactory taskFactory,
Map<String, String> properties) {
+ public void addNodeViewTaskFactory(NodeViewTaskFactory taskFactory,
Map<String, Object> properties) {
nodeViewTaskFactories.put(taskFactory, properties);
// printTaskFactoryDetails(taskFactory, properties);
}
- public void addEdgeViewTaskFactory(EdgeViewTaskFactory taskFactory,
Map<String, String> properties) {
+ public void addEdgeViewTaskFactory(EdgeViewTaskFactory taskFactory,
Map<String, Object> properties) {
edgeViewTaskFactories.put(taskFactory, properties);
// printTaskFactoryDetails(taskFactory, properties);
}
- public void addNetworkViewTaskFactory(NetworkViewTaskFactory
taskFactory, Map<String, String> properties) {
+ public void addNetworkViewTaskFactory(NetworkViewTaskFactory
taskFactory, Map<String, Object> properties) {
networkViewTaskFactories.put(taskFactory, properties);
// printTaskFactoryDetails(taskFactory, properties);
}
- public Map<NodeViewTaskFactory, Map<String, String>>
getNodeViewTaskFactories() {
+ public Map<NodeViewTaskFactory, Map<String, Object>>
getNodeViewTaskFactories() {
return nodeViewTaskFactories;
}
- public Map<EdgeViewTaskFactory, Map<String, String>>
getEdgeViewTaskFactories() {
+ public Map<EdgeViewTaskFactory, Map<String, Object>>
getEdgeViewTaskFactories() {
return edgeViewTaskFactories;
}
- public Map<NetworkViewTaskFactory, Map<String, String>>
getNetworkViewTaskFactories() {
+ public Map<NetworkViewTaskFactory, Map<String, Object>>
getNetworkViewTaskFactories() {
return networkViewTaskFactories;
}
- public void removeNodeViewTaskFactory(NodeViewTaskFactory taskFactory,
Map<String, String> properties) {
+ public void removeNodeViewTaskFactory(NodeViewTaskFactory taskFactory,
Map<String, Object> properties) {
nodeViewTaskFactories.put(taskFactory, properties);
}
- public void removeEdgeViewTaskFactory(EdgeViewTaskFactory taskFactory,
Map<String, String> properties) {
+ public void removeEdgeViewTaskFactory(EdgeViewTaskFactory taskFactory,
Map<String, Object> properties) {
edgeViewTaskFactories.put(taskFactory, properties);
}
- public void removeNetworkViewTaskFactory(NetworkViewTaskFactory
taskFactory, Map<String, String> properties) {
+ public void removeNetworkViewTaskFactory(NetworkViewTaskFactory
taskFactory, Map<String, Object> properties) {
networkViewTaskFactories.put(taskFactory, properties);
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.