Author: pwang
Date: 2011-12-13 17:27:58 -0800 (Tue, 13 Dec 2011)
New Revision: 27785

Added:
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SetPreferredLayoutTask.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SetPreferredLayoutTaskFactory.java
Modified:
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/LayoutSettingsDialog.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SettingsAction.java
Log:
Fixed bug#513

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2011-12-14 00:58:03 UTC (rev 27784)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/CyActivator.java
       2011-12-14 01:27:58 UTC (rev 27785)
@@ -252,7 +252,7 @@
                                                                                
           cyServiceRegistrarServiceRef);
                SettingsAction settingsAction = new 
SettingsAction(cyLayoutsServiceRef, cytoscapeDesktop,
                                                                   
cyApplicationManagerServiceRef,
-                                                                  
panelTaskManagerServiceRef);
+                                                                  
panelTaskManagerServiceRef, cytoscapePropertiesServiceRef);
                HelpContentsTaskFactory helpContentsTaskFactory = new 
HelpContentsTaskFactory(cyHelpBroker,
                                                                                
              cytoscapeDesktop);
                HelpContactHelpDeskTaskFactory helpContactHelpDeskTaskFactory = 
new HelpContactHelpDeskTaskFactory(openBrowserServiceRef);

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/LayoutSettingsDialog.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/LayoutSettingsDialog.java
    2011-12-14 00:58:03 UTC (rev 27784)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/LayoutSettingsDialog.java
    2011-12-14 01:27:58 UTC (rev 27785)
@@ -32,6 +32,7 @@
 
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.property.CyProperty;
 import org.cytoscape.view.layout.CyLayoutAlgorithm;
 import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
 
@@ -72,6 +73,7 @@
        private CySwingApplication desktop;
        private CyApplicationManager appMgr;
        private PanelTaskManager taskManager;
+       private CyProperty cytoscapePropertiesServiceRef;
 
        /**
         * Creates a new LayoutSettingsDialog object.
@@ -79,15 +81,23 @@
        public LayoutSettingsDialog(final CyLayoutAlgorithmManager 
cyLayoutAlgorithmManager, 
                                    final CySwingApplication desktop,
                                    final CyApplicationManager appMgr,
-                                   final PanelTaskManager taskManager)
+                                   final PanelTaskManager taskManager,
+                                   final CyProperty 
cytoscapePropertiesServiceRef)
        {
                super(desktop.getJFrame(), "Layout Settings", false);
+
                initializeOnce(); // Initialize the components we only do once
+
+               
+               initComponents();
+               
                this.cyLayoutAlgorithmManager = cyLayoutAlgorithmManager;
                this.desktop = desktop;
                this.appMgr = appMgr;
                this.taskManager = taskManager;
-               this.setPreferredSize(new Dimension(300, 150));
+               this.cytoscapePropertiesServiceRef = 
cytoscapePropertiesServiceRef;
+               
+               this.setPreferredSize(new Dimension(350, 200));
        }
 
        /**
@@ -113,6 +123,147 @@
                }
        }
 
+
+    /** This method is called from within the constructor to
+     * initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is
+     * always regenerated by the Form Editor.
+     */
+    @SuppressWarnings("unchecked")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">
+    private void initComponents() {
+        java.awt.GridBagConstraints gridBagConstraints;
+
+        jTabbedPane1 = new javax.swing.JTabbedPane();
+        pnlLayoutSettings = new javax.swing.JPanel();
+        pnlSetPreferredLayout = new javax.swing.JPanel();
+        lbSelectLayoutAlgorithm = new javax.swing.JLabel();
+        cmbLayoutAlgorithms = new javax.swing.JComboBox();
+        pnlButtons = new javax.swing.JPanel();
+        btnOK = new javax.swing.JButton();
+        btnCancel = new javax.swing.JButton();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+        setName("Form"); // NOI18N
+        getContentPane().setLayout(new java.awt.GridBagLayout());
+
+        jTabbedPane1.setName("tabPanelLayoutSettings"); // NOI18N
+
+        pnlLayoutSettings.setName("pnlLayoutSettings"); // NOI18N
+        pnlLayoutSettings.setLayout(new java.awt.GridBagLayout());
+//        org.jdesktop.application.ResourceMap resourceMap = 
org.jdesktop.application.Application.getInstance(cytoscape3gui.Cytoscape3GUIApp.class).getContext().getResourceMap(LayoutSettingsDialog.class);
+//        jTabbedPane1.addTab("Layout Settings", pnlLayoutSettings); // NOI18N
+        jTabbedPane1.addTab("Layout Settings", this.mainPanel);
+        
+
+        pnlSetPreferredLayout.setName("pnlSetPreferredLayout"); // NOI18N
+        pnlSetPreferredLayout.setLayout(new java.awt.GridBagLayout());
+
+        lbSelectLayoutAlgorithm.setText("Please select preferred layout 
algorithm."); // NOI18N
+        lbSelectLayoutAlgorithm.setName("lbSelectLayoutAlgorithm"); // NOI18N
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        gridBagConstraints.insets = new java.awt.Insets(20, 10, 5, 0);
+        pnlSetPreferredLayout.add(lbSelectLayoutAlgorithm, gridBagConstraints);
+
+        cmbLayoutAlgorithms.setModel(new javax.swing.DefaultComboBoxModel(new 
String[] { " " }));
+        cmbLayoutAlgorithms.setName("cmbLayoutAlgorithms"); // NOI18N
+        cmbLayoutAlgorithms.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                cmbLayoutAlgorithmsItemStateChanged(evt);
+            }
+        });
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 1;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        gridBagConstraints.weightx = 1.0;
+        gridBagConstraints.insets = new java.awt.Insets(5, 10, 10, 10);
+        pnlSetPreferredLayout.add(cmbLayoutAlgorithms, gridBagConstraints);
+
+        pnlButtons.setName("pnlButtons"); // NOI18N
+
+        btnOK.setText("OK"); // NOI18N
+        btnOK.setName("btnOK"); // NOI18N
+        btnOK.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                btnOKActionPerformed(evt);
+            }
+        });
+        pnlButtons.add(btnOK);
+
+        btnCancel.setText("Cancel"); // NOI18N
+        btnCancel.setName("btnCancel"); // NOI18N
+        btnCancel.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                btnCancelActionPerformed(evt);
+            }
+        });
+        pnlButtons.add(btnCancel);
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints.weighty = 1.0;
+        gridBagConstraints.insets = new java.awt.Insets(10, 10, 20, 10);
+        pnlSetPreferredLayout.add(pnlButtons, gridBagConstraints);
+
+        jTabbedPane1.addTab("Set preferred layout", pnlSetPreferredLayout); // 
NOI18N
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
+        gridBagConstraints.weightx = 1.0;
+        gridBagConstraints.weighty = 1.0;
+        getContentPane().add(jTabbedPane1, gridBagConstraints);
+
+        pack();
+    }// </editor-fold>
+
+    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {
+               CyLayoutAlgorithm layout = (CyLayoutAlgorithm) 
this.cmbLayoutAlgorithms.getSelectedItem();
+
+               SetPreferredLayoutTaskFactory factory = new 
SetPreferredLayoutTaskFactory(layout, this.cytoscapePropertiesServiceRef);
+               this.taskManager.execute(factory);
+    }
+
+    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
+       // Cancel button is clicked
+       this.dispose();
+    }
+
+    // Enable the OK button only if an algorithm is selected
+    private void cmbLayoutAlgorithmsItemStateChanged(java.awt.event.ItemEvent 
evt) {
+               Object o = this.cmbLayoutAlgorithms.getSelectedItem();
+               // if it's a string, that means it's the instructions
+               if (!(o instanceof String)) {
+                       this.btnOK.setEnabled(true);
+               }
+               else {
+                       this.btnOK.setEnabled(false);
+               }
+    }
+
+    // Variables declaration - do not modify
+    private javax.swing.JButton btnCancel;
+    private javax.swing.JButton btnOK;
+    private javax.swing.JComboBox cmbLayoutAlgorithms;
+    private javax.swing.JTabbedPane jTabbedPane1;
+    private javax.swing.JLabel lbSelectLayoutAlgorithm;
+    private javax.swing.JPanel pnlButtons;
+    private javax.swing.JPanel pnlLayoutSettings;
+    private javax.swing.JPanel pnlSetPreferredLayout;
+    // End of variables declaration
+
+       
+       
+       
        private void initializeOnce() {
                setDefaultCloseOperation(HIDE_ON_CLOSE);
 
@@ -152,7 +303,7 @@
                buttonBox.add(doneButton);
                
buttonBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
                mainPanel.add(buttonBox);
-               setContentPane(mainPanel);
+//             setContentPane(mainPanel);
        }
 
        private void initialize() {
@@ -165,6 +316,16 @@
 
                for ( CyLayoutAlgorithm algo : 
cyLayoutAlgorithmManager.getAllLayouts()) 
                        algorithmSelector.addItem(algo);
+               
+               // For the tabbedPanel "Set preferred Layout"
+               this.cmbLayoutAlgorithms.removeAllItems();
+               
+               // Add the "instructions"
+               this.cmbLayoutAlgorithms.setRenderer(new MyItemRenderer());
+               this.cmbLayoutAlgorithms.addItem("Select preferred algorithm");
+
+               for ( CyLayoutAlgorithm algo : 
cyLayoutAlgorithmManager.getAllLayouts()) 
+                       this.cmbLayoutAlgorithms.addItem(algo); 
        }
 
        private class AlgorithmActionListener implements ActionListener {

Added: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SetPreferredLayoutTask.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SetPreferredLayoutTask.java
                          (rev 0)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SetPreferredLayoutTask.java
  2011-12-14 01:27:58 UTC (rev 27785)
@@ -0,0 +1,62 @@
+/*
+ Copyright (c) 2006, 2010-2011, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.internal.layout.ui;
+
+
+import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
+import org.cytoscape.view.layout.CyLayoutAlgorithm;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.AbstractTask;
+
+import java.util.Properties;
+
+
+public class SetPreferredLayoutTask extends AbstractTask {
+       private static final String DEF_LAYOUT = "force-directed";
+
+       private Properties props;
+       private final CyLayoutAlgorithm layout;
+
+       public SetPreferredLayoutTask(final CyLayoutAlgorithm layout, final 
Properties props)
+       {
+               this.props    = props;
+               this.layout = layout;
+       }
+       
+
+       public void run(TaskMonitor tm) {
+               tm.setProgress(0.1);
+
+               String pref = layout.getName(); 
//CyLayoutAlgorithmManager.DEFAULT_LAYOUT_NAME;
+               
+               if(props != null) 
+                       props.setProperty("preferredLayoutAlgorithm", pref);
+
+               tm.setProgress(1.0);
+       }
+}

Added: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SetPreferredLayoutTaskFactory.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SetPreferredLayoutTaskFactory.java
                           (rev 0)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SetPreferredLayoutTaskFactory.java
   2011-12-14 01:27:58 UTC (rev 27785)
@@ -0,0 +1,29 @@
+package org.cytoscape.internal.layout.ui;
+
+
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.undo.UndoSupport;
+import org.cytoscape.view.layout.CyLayoutAlgorithm;
+
+import java.util.Properties; 
+
+
+public class SetPreferredLayoutTaskFactory implements TaskFactory {
+
+       private final Properties props;
+       private final CyLayoutAlgorithm o;
+       
+       public SetPreferredLayoutTaskFactory(final CyLayoutAlgorithm o, final 
CyProperty<Properties> p)
+       {
+               this.o = o;
+               this.props       = p.getProperties();           
+       }
+
+       public TaskIterator createTaskIterator() {
+               return new TaskIterator(new SetPreferredLayoutTask(o, props));
+       }
+}

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SettingsAction.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SettingsAction.java
  2011-12-14 00:58:03 UTC (rev 27784)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/SettingsAction.java
  2011-12-14 01:27:58 UTC (rev 27785)
@@ -33,6 +33,7 @@
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.application.swing.AbstractCyAction;
+import org.cytoscape.property.CyProperty;
 import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
 import org.cytoscape.work.swing.PanelTaskManager;
 
@@ -46,8 +47,10 @@
        private CyLayoutAlgorithmManager cyl;
        private CySwingApplication desk;
        private PanelTaskManager tm;
+       private CyProperty cytoscapePropertiesServiceRef;
 
-       public SettingsAction(final CyLayoutAlgorithmManager cyl, final 
CySwingApplication desk, final CyApplicationManager appMgr, final 
PanelTaskManager tm)
+       public SettingsAction(final CyLayoutAlgorithmManager cyl, final 
CySwingApplication desk, final CyApplicationManager appMgr, 
+                       final PanelTaskManager tm, CyProperty 
cytoscapePropertiesServiceRef)
        {
                super("Settings...",appMgr,"networkAndView");
                setPreferredMenu("Layout");
@@ -55,10 +58,11 @@
                this.cyl = cyl;
                this.desk = desk;
                this.tm = tm;
+               this.cytoscapePropertiesServiceRef = 
cytoscapePropertiesServiceRef;
        }
 
        public void actionPerformed(ActionEvent e) {
-               LayoutSettingsDialog settingsDialog = new 
LayoutSettingsDialog(cyl, desk, applicationManager, tm);
+               LayoutSettingsDialog settingsDialog = new 
LayoutSettingsDialog(cyl, desk, applicationManager, tm, 
this.cytoscapePropertiesServiceRef);
                settingsDialog.actionPerformed(e);
        }
 }

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