[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Fri Oct 27 20:55:14 UTC 2006
gordonp
Fri Oct 27 16:55:14 EDT 2006
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv23914/src/main/ca/ucalgary/seahawk/gui
Modified Files:
MobyServicesGUI.java
Log Message:
Handle long tooltips better now, using multiline HTML rather than truncating
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyServicesGUI.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java 2006/10/27 20:11:01 1.4
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyServicesGUI.java 2006/10/27 20:55:14 1.5
@@ -23,7 +23,7 @@
// After this many, subdivide the services for an object into sublists based of service ontology
public final static int MAX_SERVICES_PER_SUBMENU = 12;
- public final static int MAX_SERVICE_DESC_LEN = 100;
+ public final static int MAX_SERVICE_DESC_LEN = 50;
public final static String CLIPBOARD_CMD = "clipboard";
/** Always spring MOBY response in a new window if this modifier is present for a click */
public final static int USE_DEFAULT_HANDLER_MASK = ActionEvent.SHIFT_MASK;
@@ -928,8 +928,8 @@
String serviceDesc = service.getDescription();
String serviceAuthority = service.getAuthority();
if(serviceDesc != null && serviceDesc.length() > 0){
- if(serviceDesc.length() > MAX_SERVICE_DESC_LEN+3){
- serviceDesc = serviceDesc.substring(0, MAX_SERVICE_DESC_LEN) + "...";
+ if(serviceDesc.length() > MAX_SERVICE_DESC_LEN){
+ serviceDesc = htmlifyToolTipText(serviceDesc);
}
sdesc = serviceDesc;
}
@@ -974,7 +974,7 @@
String menuToolTip = commonAncestorDesc + type.getDescription();
if(menuToolTip.length() > MAX_SERVICE_DESC_LEN){
// Cut down really long ancestry descs to the last part (most precise)
- menuToolTip = "..." + menuToolTip.substring(menuToolTip.length()-MAX_SERVICE_DESC_LEN);
+ menuToolTip = htmlifyToolTipText(menuToolTip);
}
menu.setToolTipText(menuToolTip);
parentMenu.add(menu);
@@ -1002,6 +1002,46 @@
}
}
+ /**
+ * By turning the tool tip text into HTML, we can make it multiline
+ */
+ protected String htmlifyToolTipText(String text){
+ int maxLine = MAX_SERVICE_DESC_LEN;
+ StringBuffer result = null;
+
+ while(true){
+ result = new StringBuffer("<html>");
+ StringTokenizer st = new StringTokenizer(text, " \t\n");
+ int lineCharCount = 0;
+
+ if(st.hasMoreTokens()){
+ result.append(st.nextToken());
+ lineCharCount = result.length()-6;
+ }
+ while(st.hasMoreTokens()){
+ String word = st.nextToken();
+ if(lineCharCount != 0 && lineCharCount + word.length() >= maxLine){
+ result.append("<br>" + word);
+ lineCharCount = word.length();
+ continue;
+ }
+ result.append(" " + word);
+ lineCharCount += word.length()+1;
+
+ if(lineCharCount > maxLine){ //single word is bigger than preset width, redo layout
+ maxLine = lineCharCount;
+ break;
+ }
+ }
+ result.append("</html>");
+ if(!st.hasMoreTokens()){ //used up all the text, didn't break previous loop abnormally
+ break;
+ }
+ } //end layout block
+
+ return result.toString();
+ }
+
public JMenu addNameDivSubMenu(JMenu parentMenu, MobyService[] services){
if(services == null || services.length == 0){
return null;
@@ -1044,7 +1084,7 @@
String menuToolTip = commonAncestorDesc + desc;
if(menuToolTip.length() > MAX_SERVICE_DESC_LEN){
// Cut down really long ancestry descs to the last part (most precise)
- menuToolTip = "..." + menuToolTip.substring(menuToolTip.length()-MAX_SERVICE_DESC_LEN);
+ menuToolTip = htmlifyToolTipText(menuToolTip);
}
menu.setToolTipText(menuToolTip);
parentMenu.add(menu);
More information about the MOBY-guts
mailing list