Author: pwang
Date: 2010-10-19 09:59:24 -0700 (Tue, 19 Oct 2010)
New Revision: 22285

Added:
   
cytoscape/trunk/application/src/main/java/cytoscape/actions/ApplyLayoutAction.java
Removed:
   
cytoscape/trunk/application/src/main/java/cytoscape/actions/ApplyLayoutMouseAdapter.java
Log:
Use CytoscapeAction

Added: 
cytoscape/trunk/application/src/main/java/cytoscape/actions/ApplyLayoutAction.java
===================================================================
--- 
cytoscape/trunk/application/src/main/java/cytoscape/actions/ApplyLayoutAction.java
                          (rev 0)
+++ 
cytoscape/trunk/application/src/main/java/cytoscape/actions/ApplyLayoutAction.java
  2010-10-19 16:59:24 UTC (rev 22285)
@@ -0,0 +1,92 @@
+package cytoscape.actions;
+
+import java.awt.event.ActionEvent;
+import cytoscape.Cytoscape;
+import cytoscape.CytoscapeInit;
+import cytoscape.layout.CyLayoutAlgorithm;
+import cytoscape.layout.CyLayouts;
+import cytoscape.task.ui.JTaskConfig;
+import cytoscape.task.util.TaskManager;
+import cytoscape.util.CytoscapeAction;
+import cytoscape.view.CyNetworkView;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import cytoscape.layout.LayoutTask;
+import java.util.List;
+import java.util.Iterator;
+
+public class ApplyLayoutAction extends CytoscapeAction implements 
PropertyChangeListener {
+
+       private static final long serialVersionUID = -576925581582912345L;
+       
+       private String layoutName;
+       private CyLayoutAlgorithm alg;
+       private JButton applyLayoutButton;
+       
+       public ApplyLayoutAction(JButton button){
+               applyLayoutButton = button;
+
+               layoutName = 
CytoscapeInit.getProperties().get("defaultLayoutAlgorithm").toString();
+               
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(Cytoscape.PREFERENCES_UPDATED,this);
+       }
+       
+       
+       public void actionPerformed(ActionEvent ae) {
+               
+               List<CyNetworkView> viewList = 
Cytoscape.getSelectedNetworkViews();
+               if (viewList.isEmpty()|| viewList.size() == 0 || 
Cytoscape.getCurrentNetworkView() == Cytoscape.getNullNetworkView()){
+                       return;
+               }
+               
+               alg = CyLayouts.getLayout(layoutName);
+               
+               if (alg ==null){
+                       // Can not find the layout algorithm specified
+                       JOptionPane.showMessageDialog(Cytoscape.getDesktop(), 
"Unknown layout algorithm -- "+layoutName,"Warning", JOptionPane.ERROR_MESSAGE);
+                       return;
+               }
+               
+               Iterator<CyNetworkView> it = viewList.iterator();
+               
+               while (it.hasNext()){
+                       CyNetworkView view = it.next();
+                       
+                       // Create Task
+                       LayoutTask task = new LayoutTask(alg, view);
+                                               
+                       // Configure JTask Dialog Pop-Up Box
+                       JTaskConfig jTaskConfig = new JTaskConfig();
+                       jTaskConfig.setOwner(Cytoscape.getDesktop());
+                       jTaskConfig.displayCloseButton(true);
+                       jTaskConfig.displayStatus(true);
+                       jTaskConfig.displayCancelButton(false);
+                       jTaskConfig.setAutoDispose(true);
+
+                       // Execute Task in New Thread; pop open JTask Dialog 
Box.
+                       TaskManager.executeTask(task, jTaskConfig);
+               }
+       }
+       
+       public boolean isInMenuBar(){
+               return false;
+       }
+       
+       public boolean isInToolBar(){
+               return false;
+       }
+       
+       public void propertyChange(PropertyChangeEvent e) {
+
+               if 
(e.getPropertyName().equalsIgnoreCase(Cytoscape.PREFERENCES_UPDATED)){
+                       String newLayoutName = 
CytoscapeInit.getProperties().get("defaultLayoutAlgorithm").toString();
+
+                       if (!newLayoutName.equalsIgnoreCase(layoutName)){
+                               layoutName = newLayoutName;
+                               applyLayoutButton.setToolTipText("Apply 
"+layoutName+" layout");
+                       }
+               }
+       }
+
+}

Deleted: 
cytoscape/trunk/application/src/main/java/cytoscape/actions/ApplyLayoutMouseAdapter.java
===================================================================
--- 
cytoscape/trunk/application/src/main/java/cytoscape/actions/ApplyLayoutMouseAdapter.java
    2010-10-19 16:15:12 UTC (rev 22284)
+++ 
cytoscape/trunk/application/src/main/java/cytoscape/actions/ApplyLayoutMouseAdapter.java
    2010-10-19 16:59:24 UTC (rev 22285)
@@ -1,136 +0,0 @@
-package cytoscape.actions;
-
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-
-import cytoscape.Cytoscape;
-import cytoscape.CytoscapeInit;
-import cytoscape.layout.CyLayoutAlgorithm;
-import cytoscape.layout.CyLayouts;
-import cytoscape.task.Task;
-import cytoscape.task.TaskMonitor;
-import cytoscape.task.ui.JTaskConfig;
-import cytoscape.task.util.TaskManager;
-import cytoscape.view.CyNetworkView;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import javax.swing.JButton;
-import javax.swing.JOptionPane;
-
-public class ApplyLayoutMouseAdapter extends MouseAdapter implements 
PropertyChangeListener {
-       private JButton applyLayoutButton;
-       private String layoutName;
-       
-       public ApplyLayoutMouseAdapter(JButton button){
-               applyLayoutButton = button;
-               this.layoutName = 
CytoscapeInit.getProperties().get("defaultLayoutAlgorithm").toString();
-               
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(Cytoscape.PREFERENCES_UPDATED,this);
-       }
-       
-       public void propertyChange(PropertyChangeEvent e) {
-
-               if 
(e.getPropertyName().equalsIgnoreCase(Cytoscape.PREFERENCES_UPDATED)){
-                       String newLayoutName = 
CytoscapeInit.getProperties().get("defaultLayoutAlgorithm").toString();
-
-                       if (!newLayoutName.equalsIgnoreCase(layoutName)){
-                               layoutName = newLayoutName;
-                               applyLayoutButton.setToolTipText("Apply 
"+layoutName+" layout");
-                       }
-               }
-       }
-       
-       public void mouseClicked(MouseEvent e) {
-               //Apply layout
-               
-               if ( Cytoscape.getCurrentNetworkView() == null || 
Cytoscape.getCurrentNetworkView() == Cytoscape.getNullNetworkView()){
-                       return;
-               }
-               if (CyLayouts.getLayout(layoutName)==null){
-                       // Can not find the layout algorithm specified
-                       JOptionPane.showMessageDialog(Cytoscape.getDesktop(), 
"Unknown layout algorithm -- "+layoutName,"Warning", JOptionPane.ERROR_MESSAGE);
-                       return;
-               }
-
-               // Create Task
-               ApplyLayoutTask task = new ApplyLayoutTask(layoutName);
-
-               // Configure JTask Dialog Pop-Up Box
-               JTaskConfig jTaskConfig = new JTaskConfig();
-               jTaskConfig.setOwner(Cytoscape.getDesktop());
-               jTaskConfig.displayCloseButton(true);
-               jTaskConfig.displayStatus(true);
-               jTaskConfig.displayCancelButton(false);
-               jTaskConfig.setAutoDispose(true);
-
-               // Execute Task in New Thread; pop open JTask Dialog Box.
-               TaskManager.executeTask(task, jTaskConfig);
-       }
-
-       public void mousePressed(MouseEvent e) {
-               applyLayoutButton.setSelected(true);
-       }
-       public void mouseReleased(MouseEvent e) {
-               applyLayoutButton.setSelected(false);
-       }
-       
-       //
-       class ApplyLayoutTask implements Task {
-               private TaskMonitor taskMonitor;
-               private String layoutName;
-
-               /**
-                * Constructor.
-                */
-               public ApplyLayoutTask(String layoutAlgorithmName) {
-                       this.layoutName = layoutAlgorithmName;
-               }
-
-               /**
-                * Executes Task
-                */
-               public void run() {
-                       taskMonitor.setStatus("Applying "+layoutName+" 
layout...");
-                       taskMonitor.setPercentCompleted(-1);
-
-                       CyLayoutAlgorithm fd = CyLayouts.getLayout(layoutName);
-                       fd.setSelectedOnly(false);
-                       fd.getSettings().updateValues();
-                       fd.updateSettings();                                    
-                       CyNetworkView view = Cytoscape.getCurrentNetworkView();
-                       if (view != null){
-                               view.applyLayout(fd);
-                               view.redrawGraph(true, true);                   
                        
-                       }
-
-                       taskMonitor.setPercentCompleted(100);
-                       taskMonitor.setStatus("Done!");
-               }
-
-               /**
-                * Halts the Task: Not Currently Implemented.
-                */
-               public void halt() {
-                       // Task can not currently be halted.
-               }
-
-               /**
-                * Sets the Task Monitor.
-                *
-                * @param taskMonitor
-                *            TaskMonitor Object.
-                */
-               public void setTaskMonitor(TaskMonitor taskMonitor) throws 
IllegalThreadStateException {
-                       this.taskMonitor = taskMonitor;
-               }
-
-               /**
-                * Gets the Task Title.
-                *
-                * @return Task Title.
-                */
-               public String getTitle() {
-                       return new String("Apply "+layoutName+" layout");
-               }
-       }
-
-}

-- 
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.

Reply via email to