Author: mes
Date: 2011-05-04 16:21:14 -0700 (Wed, 04 May 2011)
New Revision: 24931
Added:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenuPopulator.java
Removed:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenuManager.java
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenu.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutSettingsDialog.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/SettingsAction.java
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
Log:
moved layout menu handling into service metadata
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenu.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenu.java
2011-05-04 23:19:56 UTC (rev 24930)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenu.java
2011-05-04 23:21:14 UTC (rev 24931)
@@ -62,7 +62,6 @@
public class LayoutMenu extends JMenu implements MenuListener {
private final static long serialVersionUID = 1202339874255880L;
List<CyLayoutAlgorithm> subMenuList;
- LayoutMenuManager menuMgr;
private CyApplicationManager appMgr;
private TaskManager tm;
@@ -71,11 +70,10 @@
*
* @param menuName DOCUMENT ME!
*/
- public LayoutMenu(String menuName, LayoutMenuManager menuMgr,
CyApplicationManager appMgr,TaskManager tm) {
+ public LayoutMenu(String menuName, CyApplicationManager
appMgr,TaskManager tm) {
super(menuName);
addMenuListener(this);
subMenuList = new ArrayList<CyLayoutAlgorithm>();
- this.menuMgr = menuMgr;
this.appMgr = appMgr;
this.tm = tm;
}
@@ -141,10 +139,7 @@
boolean enableMenuItem = checkEnabled();
- // Now, add each layout, as appropriate
- for (CyLayoutAlgorithm layout:
menuMgr.getLayoutsInMenu(getText())) {
- // Make sure we don't have any lingering locked nodes
- //layout.unlockAllNodes();
+ for ( CyLayoutAlgorithm layout : subMenuList ) {
if ((layout.supportsNodeAttributes().size() > 0)
|| (layout.supportsEdgeAttributes().size() > 0)) {
Deleted:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenuManager.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenuManager.java
2011-05-04 23:19:56 UTC (rev 24930)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenuManager.java
2011-05-04 23:21:14 UTC (rev 24931)
@@ -1,172 +0,0 @@
-/*
- File: LayoutMenuManager.java
-
- Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
-
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
- 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.CyLayoutAlgorithm;
-import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
-import org.cytoscape.work.TaskManager;
-import org.cytoscape.application.swing.CySwingApplication;
-import org.cytoscape.session.CyApplicationManager;
-
-import javax.swing.*;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
-import java.util.*;
-
-
-public class LayoutMenuManager implements MenuListener {
-
- private Map<String, List<CyLayoutAlgorithm>> menuAlgorithmMap;
- private Map<String, LayoutMenu> menuMap;
- private Set<CyLayoutAlgorithm> existingLayouts;
- private CyApplicationManager appMgr;
- private TaskManager tm;
-
- private CyLayoutAlgorithmManager cyLayoutAlgorithmManager;
-
- public LayoutMenuManager(CySwingApplication swingApp,
CyLayoutAlgorithmManager cyLayoutAlgorithmManager, CyApplicationManager appMgr,
TaskManager tm) {
- menuAlgorithmMap = new
HashMap<String,List<CyLayoutAlgorithm>>();
- menuMap = new HashMap<String,LayoutMenu>();
- existingLayouts = new HashSet<CyLayoutAlgorithm>();
- this.cyLayoutAlgorithmManager = cyLayoutAlgorithmManager;
- this.appMgr = appMgr;
- this.tm = tm;
-
- swingApp.getJMenu("Layout").addMenuListener(this);
- }
-
- public void menuCanceled(MenuEvent e) { };
-
- public void menuDeselected(MenuEvent e) { };
-
- public void menuSelected(MenuEvent e) {
- Object o = e.getSource();
- if ( o instanceof JMenu )
- updateMenus((JMenu)o);
- }
-
- private void updateMenus(JMenu parentMenu) {
-
- // first add all layouts from cylayouts if they're not already
there
- for ( CyLayoutAlgorithm la :
cyLayoutAlgorithmManager.getAllLayouts() )
- if ( !existingLayouts.contains(la) )
- addLayout(la);
-
- // now remove any existing layouts that are no longer in
cylayouts
- Set<CyLayoutAlgorithm> newLayouts = new
HashSet<CyLayoutAlgorithm>(cyLayoutAlgorithmManager.getAllLayouts());
- for ( CyLayoutAlgorithm la : existingLayouts )
- if ( !newLayouts.contains(la) )
- removeLayout(la);
-
- // now update the menus if necessary
- for ( String name : menuMap.keySet() ) {
- LayoutMenu lm = menuMap.get(name);
- int size = menuAlgorithmMap.get(name).size();
-
- // if the menu is not already there and
- // actually contains layouts, add it
- if ( !parentMenu.isMenuComponent(lm) && size > 0 )
- parentMenu.add(lm);
-
- // remove any menus that don't contain any layouts
- else if ( parentMenu.isMenuComponent(lm) && size <= 0 )
- parentMenu.remove(lm);
- }
- }
-
- private void addLayout(CyLayoutAlgorithm layout) {
-
- String menuName = cyLayoutAlgorithmManager.getMenuName(layout);
- if (menuName == null )
- return;
-
- existingLayouts.add(layout);
-
- // make sure the list is set up for this name
- if ( !menuAlgorithmMap.containsKey(menuName) ) {
- List<CyLayoutAlgorithm> menuList = new
ArrayList<CyLayoutAlgorithm>();
- menuAlgorithmMap.put(menuName, menuList);
- }
-
- // add layout to the list of layouts for this name
- menuAlgorithmMap.get(menuName).add(layout);
-
- // make sure the menu is set up
- if ( !menuMap.containsKey(menuName) ) {
- LayoutMenu menu = new LayoutMenu(menuName, this,
appMgr, tm);
- menuMap.put(menuName, menu);
- }
-
- // add layout to the menu for this name
- menuMap.get(menuName).add(layout);
- }
-
- private void removeLayout(CyLayoutAlgorithm layout) {
-
- for (String menu : menuAlgorithmMap.keySet()) {
-
- List<CyLayoutAlgorithm> menuList =
menuAlgorithmMap.get(menu);
-
- if (menuList.indexOf(layout) >= 0) {
- menuList.remove(layout);
- menuMap.get(menu).remove(layout);
- existingLayouts.remove(layout);
- return;
- }
- }
- }
-
- /**
- * Get all of the layouts associated with a specific
- * menu.
- *
- * @param menu The name of the menu
- * @return a List of all layouts associated with this menu (could be
null)
- */
- List<CyLayoutAlgorithm> getLayoutsInMenu(String menu) {
- return menuAlgorithmMap.get(menu);
- }
-
- /**
- * Get all of the menus (categories of layouts) currently defined.
- *
- * @return a Collection of Strings representing each of the menus
- */
- Set<String> getLayoutMenuNames() {
- return menuAlgorithmMap.keySet();
- }
-}
Added:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenuPopulator.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenuPopulator.java
(rev 0)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutMenuPopulator.java
2011-05-04 23:21:14 UTC (rev 24931)
@@ -0,0 +1,106 @@
+/*
+ File: LayoutMenuManager.java
+
+ Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ 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.CyLayoutAlgorithm;
+import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
+import org.cytoscape.work.TaskManager;
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.session.CyApplicationManager;
+
+import javax.swing.*;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+import java.util.*;
+
+
+public class LayoutMenuPopulator {
+
+ private Map<String, List<CyLayoutAlgorithm>> menuAlgorithmMap;
+ private Map<String, LayoutMenu> menuMap;
+ private CyApplicationManager appMgr;
+ private TaskManager tm;
+ private CySwingApplication swingApp;
+
+ public LayoutMenuPopulator(CySwingApplication swingApp,
CyApplicationManager appMgr, TaskManager tm) {
+ menuAlgorithmMap = new
HashMap<String,List<CyLayoutAlgorithm>>();
+ menuMap = new HashMap<String,LayoutMenu>();
+ this.appMgr = appMgr;
+ this.tm = tm;
+ this.swingApp = swingApp;
+ }
+
+ public void addLayout(CyLayoutAlgorithm layout, Map props) {
+
+ String menuName = (String)props.get("preferredMenu");
+ if (menuName == null )
+ menuName = "Layout";
+
+ // make sure the list is set up for this name
+ if ( !menuAlgorithmMap.containsKey(menuName) ) {
+ List<CyLayoutAlgorithm> menuList = new
ArrayList<CyLayoutAlgorithm>();
+ menuAlgorithmMap.put(menuName, menuList);
+ }
+
+ // add layout to the list of layouts for this name
+ menuAlgorithmMap.get(menuName).add(layout);
+
+ // make sure the menu is set up
+ if ( !menuMap.containsKey(menuName) ) {
+ LayoutMenu menu = new LayoutMenu(menuName, appMgr, tm);
+ menuMap.put(menuName, menu);
+ swingApp.getJMenu("Layout").add(menu);
+ }
+
+ // add layout to the menu for this name
+ menuMap.get(menuName).add(layout);
+ }
+
+ public void removeLayout(CyLayoutAlgorithm layout, Map props) {
+
+ for (String menu : menuAlgorithmMap.keySet()) {
+
+ List<CyLayoutAlgorithm> menuList =
menuAlgorithmMap.get(menu);
+
+ if (menuList.indexOf(layout) >= 0) {
+ menuList.remove(layout);
+ menuMap.get(menu).remove(layout);
+ return;
+ }
+ }
+ }
+}
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutSettingsDialog.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutSettingsDialog.java
2011-05-04 23:19:56 UTC (rev 24930)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/LayoutSettingsDialog.java
2011-05-04 23:21:14 UTC (rev 24931)
@@ -70,22 +70,21 @@
private CyLayoutAlgorithmManager cyLayoutAlgorithmManager;
private CySwingApplication desktop;
- private LayoutMenuManager menuMgr;
private CyApplicationManager appMgr;
private GUITaskManager taskManager;
/**
* Creates a new LayoutSettingsDialog object.
*/
- public LayoutSettingsDialog(final CyLayoutAlgorithmManager
cyLayoutAlgorithmManager, final CySwingApplication desktop,
- final LayoutMenuManager menuMgr, final
CyApplicationManager appMgr,
+ public LayoutSettingsDialog(final CyLayoutAlgorithmManager
cyLayoutAlgorithmManager,
+ final CySwingApplication desktop,
+ final CyApplicationManager appMgr,
final GUITaskManager taskManager)
{
super(desktop.getJFrame(), "Layout Settings", false);
initializeOnce(); // Initialize the components we only do once
this.cyLayoutAlgorithmManager = cyLayoutAlgorithmManager;
this.desktop = desktop;
- this.menuMgr = menuMgr;
this.appMgr = appMgr;
this.taskManager = taskManager;
}
@@ -164,18 +163,8 @@
algorithmSelector.setRenderer(new MyItemRenderer());
algorithmSelector.addItem("Select algorithm to view settings");
- // Get the list of known layout menus
- Set<String> menus = menuMgr.getLayoutMenuNames();
-
- for (String menu : menus) {
- if (menus.size() > 1)
- algorithmSelector.addItem(menu);
-
- for (CyLayoutAlgorithm algo :
menuMgr.getLayoutsInMenu(menu)) {
- // TODO might want a check here to see if
algorithm has any tunables
- algorithmSelector.addItem(algo);
- }
- }
+ for ( CyLayoutAlgorithm algo :
cyLayoutAlgorithmManager.getAllLayouts())
+ algorithmSelector.addItem(algo);
}
private class AlgorithmActionListener implements ActionListener {
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/SettingsAction.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/SettingsAction.java
2011-05-04 23:19:56 UTC (rev 24930)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/layout/ui/SettingsAction.java
2011-05-04 23:21:14 UTC (rev 24931)
@@ -45,22 +45,20 @@
private CyLayoutAlgorithmManager cyl;
private CySwingApplication desk;
- private LayoutMenuManager menuMgr;
private GUITaskManager tm;
- public SettingsAction(final CyLayoutAlgorithmManager cyl, final
CySwingApplication desk, final LayoutMenuManager menuMgr, final
CyApplicationManager appMgr, final GUITaskManager tm)
+ public SettingsAction(final CyLayoutAlgorithmManager cyl, final
CySwingApplication desk, final CyApplicationManager appMgr, final
GUITaskManager tm)
{
super("Settings...",appMgr);
setPreferredMenu("Layout");
setMenuGravity(3.0f);
this.cyl = cyl;
this.desk = desk;
- this.menuMgr = menuMgr;
this.tm = tm;
}
public void actionPerformed(ActionEvent e) {
- LayoutSettingsDialog settingsDialog = new
LayoutSettingsDialog(cyl, desk, menuMgr, applicationManager, tm);
+ LayoutSettingsDialog settingsDialog = new
LayoutSettingsDialog(cyl, desk, applicationManager, tm);
settingsDialog.actionPerformed(e);
}
Modified:
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
---
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-05-04 23:19:56 UTC (rev 24930)
+++
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-05-04 23:21:14 UTC (rev 24931)
@@ -325,4 +325,10 @@
<osgi:listener bind-method="addCyProperty"
unbind-method="removeCyProperty"
ref="configDirPropertyWriter" />
</osgi:set>
+
+ <osgi:set id="layoutSet"
interface="org.cytoscape.view.layout.CyLayoutAlgorithm"
+ cardinality="0..N">
+ <osgi:listener bind-method="addLayout"
+ unbind-method="removeLayout" ref="layoutMenuPopulator"
/>
+ </osgi:set>
</beans>
Modified:
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
---
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-05-04 23:19:56 UTC (rev 24930)
+++
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-05-04 23:21:14 UTC (rev 24931)
@@ -163,10 +163,8 @@
<constructor-arg ref="cytoscapePropertiesServiceRef" />
</bean>
-->
- <!-- not a CyAction, but adds menu -->
- <bean id="layoutMenuManager"
class="org.cytoscape.internal.layout.ui.LayoutMenuManager">
+ <bean id="layoutMenuPopulator"
class="org.cytoscape.internal.layout.ui.LayoutMenuPopulator">
<constructor-arg ref="cytoscapeDesktop" />
- <constructor-arg ref="cyLayoutsServiceRef" />
<constructor-arg ref="cyApplicationManagerServiceRef" />
<constructor-arg ref="guiTaskManagerServiceRef" />
</bean>
@@ -181,7 +179,6 @@
<bean id="settingsAction"
class="org.cytoscape.internal.layout.ui.SettingsAction">
<constructor-arg ref="cyLayoutsServiceRef" />
<constructor-arg ref="cytoscapeDesktop" />
- <constructor-arg ref="layoutMenuManager" />
<constructor-arg ref="cyApplicationManagerServiceRef" />
<constructor-arg ref="guiTaskManagerServiceRef" />
</bean>
--
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.