[MOBY-guts] biomoby commit

Dmitry Repchevski drepchevski at dev.open-bio.org
Thu May 27 12:17:58 UTC 2010


drepchevski
Thu May 27 08:17:58 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/org/inb/biomoby/central/gui/renderer
In directory dev.open-bio.org:/tmp/cvs-serv11585/renderer

Modified Files:
	EntityTreeCellRenderer.java 
Log Message:
Entity description popup added.
moby-live/Java/src/main/org/inb/biomoby/central/gui/renderer EntityTreeCellRenderer.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/inb/biomoby/central/gui/renderer/EntityTreeCellRenderer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/inb/biomoby/central/gui/renderer/EntityTreeCellRenderer.java	2009/12/17 11:40:49	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/inb/biomoby/central/gui/renderer/EntityTreeCellRenderer.java	2010/05/27 12:17:58	1.2
@@ -10,7 +10,13 @@
 
 package org.inb.biomoby.central.gui.renderer;
 
+import java.awt.Color;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import javax.swing.JToolTip;
 import javax.swing.JTree;
+import javax.swing.UIManager;
 import javax.swing.tree.DefaultMutableTreeNode;
 import org.inb.biomoby.shared.registry.AbstractEntity;
 
@@ -22,6 +28,8 @@
 
 public class EntityTreeCellRenderer extends AbstractTreeCellRenderer
 {
+    private final static int MAX_WIDTH = 300;
+
     @Override
     public AbstractTreeCellRenderer getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
     {
@@ -40,7 +48,9 @@
             else if (object instanceof AbstractEntity)
             {
                 AbstractEntity entity = (AbstractEntity)object;
+                
                 setText(entity.getName());
+                setToolTipText(tree, entity.getDescription());
             }
             else
             {
@@ -50,4 +60,71 @@
 
         return renderer;
     }
+
+    private void setToolTipText(JTree tree, String s)
+    {
+        if (s != null && s.length() > 0)
+        {
+            JToolTip toolTip = tree.createToolTip();
+            toolTip.setTipText(s);
+
+            if (toolTip.getMinimumSize().width < MAX_WIDTH)
+            {
+                setToolTipText(s);
+            }
+            else
+            {
+                Color background = toolTip.getBackground();
+                if (background == null)
+                {
+                    background = UIManager.getLookAndFeel().getDefaults().getColor("ToolTip.background");
+
+                    if (background == null)
+                    {
+                        background = Color.WHITE;
+                    }
+                }
+
+                Color foreground = toolTip.getForeground();
+                if (foreground == null)
+                {
+                    foreground = UIManager.getLookAndFeel().getDefaults().getColor("ToolTip.foreground");
+
+                    if (foreground == null)
+                    {
+                        foreground = Color.BLACK;
+                    }
+                }
+
+                StringBuilder sb = new StringBuilder();
+                sb.append("<html>");
+                sb.append("<div style='width: ").append(MAX_WIDTH).append("px;'>");
+                sb.append("<font style='font-weight: normal;");
+                sb.append("background-color: rgb(");
+                sb.append(background.getRed()).append(",").append(background.getGreen()).append(",").append(background.getBlue()).append(");");
+                sb.append("color: rgb(");
+                sb.append(foreground.getRed()).append(",").append(foreground.getGreen()).append(",").append(foreground.getBlue()).append(");");
+                sb.append("'>");
+
+                BufferedReader reader = new BufferedReader(new StringReader(s));
+
+                try
+                {
+                    String line;
+                    while((line = reader.readLine()) != null)
+                    {
+                        sb.append(line);
+                        sb.append("<br/>");
+                    }
+                }
+                catch(IOException ex) {}
+
+                sb.append("</font>");
+                sb.append("</div>");
+                sb.append("</html>");
+
+                setToolTipText(sb.toString());
+            }
+        }
+    }
 }




More information about the MOBY-guts mailing list