Author: mes
Date: 2011-01-18 15:35:37 -0800 (Tue, 18 Jan 2011)
New Revision: 23498
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/ExitAction.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PreferenceAction.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PrintAction.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/RedoAction.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/UndoAction.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeMenuBar.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeMenus.java
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeToolBar.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:
updates to support menu and toolbar gravity
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/ExitAction.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/ExitAction.java
2011-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/ExitAction.java
2011-01-18 23:35:37 UTC (rev 23498)
@@ -66,6 +66,7 @@
this.shutdown = shutdown;
setPreferredMenu("File");
setAcceleratorKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
ActionEvent.CTRL_MASK));
+ setMenuGravity(1000.0f);
}
/**
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PreferenceAction.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PreferenceAction.java
2011-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PreferenceAction.java
2011-01-18 23:35:37 UTC (rev 23498)
@@ -68,6 +68,7 @@
this.pdf = pdf;
System.out.println("PreferenceAction()...");
setPreferredMenu("Edit.Preferences");
+ setMenuGravity(10.0f);
}
/**
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PrintAction.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PrintAction.java
2011-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/PrintAction.java
2011-01-18 23:35:37 UTC (rev 23498)
@@ -55,6 +55,7 @@
import org.cytoscape.session.CyApplicationManager;
import org.cytoscape.view.model.CyNetworkViewManager;
import org.cytoscape.view.presentation.RenderingEngine;
+import org.cytoscape.property.CyProperty;
/**
@@ -72,11 +73,12 @@
/**
* Creates a new PrintAction object.
*/
- public PrintAction(CyApplicationManager appMgr, Properties props ) {
+ public PrintAction(CyApplicationManager appMgr, CyProperty<Properties>
p ) {
super(MENU_LABEL, appMgr );
setPreferredMenu("File");
+ setMenuGravity(7.0f);
setAcceleratorKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_P,
ActionEvent.CTRL_MASK));
- this.props = props;
+ this.props = p.getProperties();
}
/**
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/RedoAction.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/RedoAction.java
2011-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/RedoAction.java
2011-01-18 23:35:37 UTC (rev 23498)
@@ -66,6 +66,7 @@
setAcceleratorKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_Y,
ActionEvent.CTRL_MASK));
setPreferredMenu("Edit");
setEnabled(true);
+ setMenuGravity(1.1f);
this.undo = undo;
}
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/UndoAction.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/UndoAction.java
2011-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/actions/UndoAction.java
2011-01-18 23:35:37 UTC (rev 23498)
@@ -66,6 +66,7 @@
setAcceleratorKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_Z,
ActionEvent.CTRL_MASK));
setPreferredMenu("Edit");
setEnabled(true);
+ setMenuGravity(1.0f);
this.undo = undo;
}
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeMenuBar.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeMenuBar.java
2011-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeMenuBar.java
2011-01-18 23:35:37 UTC (rev 23498)
@@ -38,6 +38,7 @@
import javax.swing.*;
+import java.awt.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -47,15 +48,22 @@
import org.cytoscape.application.swing.CyAction;
import org.cytoscape.util.swing.JMenuTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class CytoscapeMenuBar extends JMenuBar {
private final static long serialVersionUID = 1202339868642259L;
+ private final static Logger logger =
LoggerFactory.getLogger(CytoscapeMenuBar.class);
+
public static final String DEFAULT_MENU_SPECIFIER = "Tools";
protected Set actionMembersSet = null;
protected Map<Action,JMenuItem> actionMenuItemMap = null;
protected JMenuTracker menuTracker;
+ private Map<Component,Float> componentGravity;
+
/**
* The Menu->Integer "effective last index"
* Map for Menus with menu items that want to be at the end.
@@ -69,6 +77,7 @@
menuEffectiveLastIndexMap = new HashMap<JMenu,Integer>();
actionMenuItemMap = new HashMap<Action,JMenuItem>();
menuTracker = new JMenuTracker(this);
+ componentGravity = new HashMap<Component,Float>();
// Load the first menu, just to please the layouter. Also make
sure the
// menu bar doesn't get too small.
@@ -95,7 +104,7 @@
JMenuItem menu_item = null;
if (actionMenuItemMap != null) {
- menu_item = (JMenuItem) actionMenuItemMap.get(action);
+ menu_item = actionMenuItemMap.get(action);
}
if (menu_item != null) {
@@ -103,7 +112,7 @@
}
JMenu menu = getMenu(menu_name);
- menu_item = createJMenuItem(action);
+ menu_item = createMenuItem(action);
// Add an Accelerator Key, if wanted
KeyStroke accelerator = action.getAcceleratorKeyStroke();
@@ -111,12 +120,38 @@
menu_item.setAccelerator(accelerator);
menu.addMenuListener(action);
- menu.add(menu_item);
+ int index = getInsertLocation(menu,action.getMenuGravity());
+ logger.info("Inserted action for menu: " + menu_name +
+ " with gravity: " + action.getMenuGravity());
+ menu.insert(menu_item,index);
actionMenuItemMap.put(action, menu_item);
return true;
- }
+ }
+ public void addSeparator(String menu_name, float gravity) {
+ if ( menu_name == null || menu_name == "")
+ menu_name = DEFAULT_MENU_SPECIFIER;
+
+ JMenu menu = getMenu(menu_name);
+ int index = getInsertLocation(menu,gravity);
+ menu.insertSeparator(index);
+ Component sepx = menu.getMenuComponent(index);
+ componentGravity.put(sepx,gravity);
+ }
+
+ private int getInsertLocation(JMenu menu, float newGravity) {
+ for ( int i = 0; i < menu.getMenuComponentCount(); i++ ) {
+ Component item = menu.getMenuComponent(i);
+ if ( componentGravity.containsKey(item) ) {
+ if ( newGravity < componentGravity.get(item) ) {
+ return i;
+ }
+ }
+ }
+ return menu.getMenuComponentCount();
+ }
+
/**
* If the given Action has a present and false inMenuBar property,
return;
* otherwise if there's a menu item for the action, remove it. Its menu
is
@@ -128,7 +163,7 @@
return false;
}
- JMenuItem menu_item = (JMenuItem)
actionMenuItemMap.remove(action);
+ JMenuItem menu_item = actionMenuItemMap.remove(action);
if (menu_item == null) {
return false;
@@ -151,6 +186,12 @@
return true;
}
+ public JMenu addMenu(String menu_string, float gravity) {
+ JMenu menu = getMenu(menu_string);
+ componentGravity.put(menu,gravity);
+ return menu;
+ }
+
/**
* @return the menu named in the given String. The String may contain
* multiple menu names, separated by dots ('.'). If any
contained
@@ -162,17 +203,24 @@
if ( menu_string == null )
menu_string = DEFAULT_MENU_SPECIFIER;
- final JMenu menu = menuTracker.getMenu(menu_string, -1);
+ final JMenu menu = menuTracker.getMenu(menu_string);
+ if ( !componentGravity.containsKey(menu) )
+ componentGravity.put(menu,100.0f);
revalidate();
repaint();
return menu;
}
- private JMenuItem createJMenuItem(CyAction action) {
+ private JMenuItem createMenuItem(CyAction action) {
+ JMenuItem ret;
if ( action.useCheckBoxMenuItem() )
- return new JCheckBoxMenuItem(action);
+ ret = new JCheckBoxMenuItem(action);
+ else
+ ret = new JMenuItem(action);
- return new JMenuItem(action);
+ componentGravity.put(ret,action.getMenuGravity());
+
+ return ret;
}
public JMenuBar getJMenuBar() {
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeMenus.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeMenus.java
2011-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeMenus.java
2011-01-18 23:35:37 UTC (rev 23498)
@@ -45,34 +45,54 @@
final private CytoscapeMenuBar menuBar;
final private CytoscapeToolBar toolBar;
- private final Map<String,JMenu> menus;
-
public CytoscapeMenus(CytoscapeMenuBar menuBar, CytoscapeToolBar
toolBar) {
this.menuBar = menuBar;
this.toolBar = toolBar;
- menus = new HashMap<String,JMenu>();
+ menuBar.addMenu("File",0.0f);
+ menuBar.addMenu("File.New",0.0f);
+ menuBar.addMenu("File.New.Network",0.0f);
+ menuBar.addMenu("File.Import",5.0f);
+ menuBar.addMenu("File.Export",5.1f);
+ menuBar.addMenu("Edit",0.0f);
+ menuBar.addMenu("View",0.0f);
+ menuBar.addMenu("Select",0.0f);
+ menuBar.addMenu("Layout",0.0f);
+ menuBar.addMenu("Plugins",0.0f);
+ menuBar.addMenu("Tools",0.0f);
+ menuBar.addMenu("Help",0.0f);
- addMenu("File");
- addMenu("File.New");
- addMenu("File.New.Network");
- addMenu("File.Import");
- addMenu("File.Export");
- addMenu("Edit");
- addMenu("View");
- addMenu("Select");
- addMenu("Layout");
- addMenu("Plugins");
- addMenu("Help");
- }
+ menuBar.addSeparator("File",2.0f);
+ menuBar.addSeparator("File",4.0f);
+ menuBar.addSeparator("File",6.0f);
+ menuBar.addSeparator("File",8.0f);
- private void addMenu(String s) {
- JMenu m = menuBar.getMenu(s);
- menus.put(s,m);
+ menuBar.addSeparator("Edit",2.0f);
+ menuBar.addSeparator("Edit",4.0f);
+ menuBar.addSeparator("Edit",6.0f);
+
+ menuBar.addSeparator("View",2.0f);
+ menuBar.addSeparator("View",4.0f);
+ menuBar.addSeparator("View",6.0f);
+
+ menuBar.addSeparator("Select",2.0f);
+ menuBar.addSeparator("Select",4.0f);
+
+ menuBar.addSeparator("Layout",2.0f);
+ menuBar.addSeparator("Layout",4.0f);
+
+ menuBar.addSeparator("Plugins",2.0f);
+
+ menuBar.addSeparator("Help",2.0f);
+
+ toolBar.addSeparator(2.0f);
+ toolBar.addSeparator(4.0f);
+ toolBar.addSeparator(6.0f);
+ toolBar.addSeparator(8.0f);
}
public JMenu getJMenu(String s) {
- return menus.get(s);
+ return menuBar.getMenu(s);
}
public JMenuBar getJMenuBar() {
Modified:
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeToolBar.java
===================================================================
---
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeToolBar.java
2011-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/java/org/cytoscape/internal/view/CytoscapeToolBar.java
2011-01-18 23:35:37 UTC (rev 23498)
@@ -36,6 +36,7 @@
*/
package org.cytoscape.internal.view;
+import java.awt.Component;
import javax.swing.*;
import java.util.HashMap;
import java.util.Map;
@@ -53,8 +54,8 @@
public class CytoscapeToolBar extends JToolBar {
private final static long serialVersionUID = 1202339868655256L;
private Map<CyAction,JButton> actionButtonMap;
- private SortedMap<String,Integer> groupNameCount;
- private List<JButton> buttonList;
+ private List orderedList;
+ private Map<Object,Float> componentGravity;
/**
* Default constructor delegates to the superclass void constructor and
then
@@ -63,14 +64,14 @@
public CytoscapeToolBar() {
super("Cytoscape Tools");
actionButtonMap = new HashMap<CyAction,JButton>();
- groupNameCount = new TreeMap<String,Integer>();
- buttonList = new ArrayList<JButton>();
+ componentGravity = new HashMap<Object,Float>();
+ orderedList = new ArrayList();
}
/**
* If the given Action has an absent or false inToolBar property,
return;
* otherwise delegate to addAction( String, Action ) with the value of
its
- * preferredButtonGroup property, or null if it does not have that
property.
+ * gravity property.
*/
public boolean addAction(CyAction action) {
@@ -87,19 +88,16 @@
button.setBorderPainted(false);
button.setRolloverEnabled(true);
button.setText("");
+ componentGravity.put(button,action.getToolbarGravity());
// If SHORT_DESCRIPTION exists, use this as tool-tip
String shortDescription = (String)
action.getValue(Action.SHORT_DESCRIPTION);
if (shortDescription != null)
button.setToolTipText(shortDescription);
- String button_group_name = action.getPreferredButtonGroup();
- if ( button_group_name == null )
- button_group_name = "";
-
actionButtonMap.put(action, button);
- int addInd = getActionIndex(button_group_name);
- buttonList.add(addInd, button );
+ int addInd = getInsertLocation(action.getToolbarGravity());
+ orderedList.add(addInd, button);
addButtons();
@@ -107,36 +105,38 @@
}
private void addButtons() {
- for ( JButton b : buttonList)
- remove(b);
- for ( JButton b : buttonList)
- add(b);
+ removeAll();
+ for ( Object o : orderedList) {
+ if ( o instanceof JButton ) {
+ add((JButton)o);
+ } else if ( o instanceof Float ) {
+ addSeparator();
+ }
+ }
validate();
}
+ public void addSeparator(float gravity) {
+ Float key = new Float(gravity);
+ componentGravity.put(key, gravity);
+ int addInd = getInsertLocation(gravity);
+ orderedList.add(addInd, key);
+ }
- /**
- * Returns the appropriate index for placing the action as the last
item in
- * a group where the groups themselves are ordered lexicographically by
name.
- */
- private int getActionIndex(String name) {
- if ( !groupNameCount.containsKey(name) )
- groupNameCount.put(name,0);
-
- int index = 0;
- for ( String groupName : groupNameCount.keySet() ) {
- final int groupCount =
groupNameCount.get(groupName).intValue();
- index += groupCount;
- if ( name.equals( groupName ) ) {
- groupNameCount.put( groupName, groupCount + 1 );
- break;
- }
- }
- //System.out.println("calculated action index: " + index + "
for group name: " + name);
- return index;
- }
+ private int getInsertLocation(float newGravity) {
+ for ( int i = 0; i < orderedList.size(); i++ ) {
+ Object item = orderedList.get(i);
+ if ( componentGravity.containsKey(item) ) {
+ if ( newGravity < componentGravity.get(item) ) {
+ return i;
+ }
+ }
+ }
+ return orderedList.size();
+ }
+
/**
* If the given Action has an absent or false inToolBar property,
return;
* otherwise if there's a button for the action, remove it.
@@ -149,16 +149,18 @@
return false;
}
+ orderedList.remove(button);
remove(button);
return true;
- }
+ }
public JToolBar getJToolBar() {
return this;
}
+ // use by toolbar updater to keep things properly enabled/disabled
Collection<CyAction> getAllToolBarActions() {
return actionButtonMap.keySet();
}
-}
+}
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-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-01-18 23:35:37 UTC (rev 23498)
@@ -85,8 +85,8 @@
<osgi:reference id="openBrowserServiceRef"
interface="org.cytoscape.util.swing.OpenBrowser" />
- <!-- <osgi:service id="printActionService" ref="printAction"
interface="cytoscape.view.CyAction"
- /> -->
+ <osgi:service id="printActionService" ref="printAction"
+ interface="org.cytoscape.application.swing.CyAction" />
<osgi:service id="exitActionService" ref="exitAction"
interface="org.cytoscape.application.swing.CyAction" />
<osgi:service id="undoActionService" ref="undoAction"
@@ -200,12 +200,12 @@
<osgi:service id="helpContentsTaskFactoryService"
ref="helpContentsTaskFactory"
interface="org.cytoscape.work.TaskFactory">
<osgi:service-properties>
- <entry key="preferredButtonGroup" value="z-help" />
<entry key="preferredMenu" value="Help" />
<entry key="tooltip" value="Show Help Contents..." />
<entry key="title" value="Contents..." />
<entry key="inToolBar" value="true" />
<entry key="iconName"
value="/images/ximian/stock_help.png" />
+ <entry key="toolBarGravity" value="7.0f" />
<!-- acceleratorCombo KeyEvent.VK_F1, 0 -->
</osgi:service-properties>
</osgi:service>
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-01-18 23:35:14 UTC (rev 23497)
+++
core3/swing-application-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-01-18 23:35:37 UTC (rev 23498)
@@ -113,13 +113,11 @@
<constructor-arg ref="cyNetworkManagerServiceRef" />
</bean>
- <!--
<bean id="printAction"
class="org.cytoscape.internal.actions.PrintAction">
- <constructor-arg ref="cyNetworkManagerServiceRef" />
+ <constructor-arg ref="cyApplicationManagerServiceRef" />
<constructor-arg ref="cytoscapePropertiesServiceRef" />
- <constructor-arg ref="presentationManagerServiceRef" />
</bean>
- -->
+
<bean id="exitAction" class="org.cytoscape.internal.actions.ExitAction">
<constructor-arg ref="cyApplicationManagerServiceRef" />
<constructor-arg ref="cytoscapeShutdown" />
--
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.