Author: kono
Date: 2012-01-13 14:31:48 -0800 (Fri, 13 Jan 2012)
New Revision: 28016

Modified:
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/icon/TextIcon.java
   
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/DefaultViewEditorImpl.java
Log:
fixes #578 Long text will be omitted by icon generator.  Remaining text will be 
displayed as tooltip.

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/icon/TextIcon.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/icon/TextIcon.java
       2012-01-13 22:14:49 UTC (rev 28015)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/icon/TextIcon.java
       2012-01-13 22:31:48 UTC (rev 28016)
@@ -6,12 +6,19 @@
 import java.awt.Graphics2D;
 import java.awt.RenderingHints;
 
+import javax.swing.JComponent;
+
 public class TextIcon extends VisualPropertyIcon<Object> {
 
        private static final long serialVersionUID = -4217147694751380332L;
 
-       private static final int FONT_SIZE = 20;
-       private static final Font FONT = new Font("SansSerif", Font.BOLD, 
FONT_SIZE);
+       private static final int FONT_SIZE_DEFAULT = 20;
+       private static final int FONT_SIZE_SMALL = 16;
+       
+       private static final int MAX_TEXT_LEN = 5;
+       
+       private static final Font FONT = new Font("SansSerif", Font.BOLD, 
FONT_SIZE_DEFAULT);
+       private static final Font FONT_SMALL = new Font("SansSerif", Font.BOLD, 
FONT_SIZE_SMALL);
 
        public TextIcon(final Object value, final int width, final int height, 
final String name) {
                super(value, width, height, name);
@@ -27,10 +34,19 @@
                final Font original = g2d.getFont();
                
                if (value != null) {
+                       String text = value.toString();
+                       final int textLen = text.length();
+                       
                        g2d.setColor(color);
-                       g2d.setFont(FONT);
+                       if(textLen>MAX_TEXT_LEN) {
+                               text = text.substring(0, 5) + "...";
+                               g2d.setFont(FONT_SMALL);
+                       } else
+                               g2d.setFont(FONT);
+                       
                        final int cHeight = c.getHeight();
-                       g2d.drawString(value.toString(), x+leftPad+5, y + 
(cHeight/2) - 5);
+                       
+                       g2d.drawString(text, x+leftPad+5, y + (cHeight/2) - 5);
                }
 
                g2d.setFont(original);

Modified: 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/DefaultViewEditorImpl.java
===================================================================
--- 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/DefaultViewEditorImpl.java
    2012-01-13 22:14:49 UTC (rev 28015)
+++ 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/DefaultViewEditorImpl.java
    2012-01-13 22:31:48 UTC (rev 28016)
@@ -608,12 +608,16 @@
 
                                final RenderingEngine<?> presentation = 
cyApplicationManager.getCurrentRenderingEngine();
 
-                               if (presentation != null)
+                               if (presentation != null) {
+                                       final Object defValue = 
selectedStyle.getDefaultValue(vp);
                                        icon = presentation.createIcon(vp, 
selectedStyle.getDefaultValue(vp), ICON_WIDTH, ICON_HEIGHT);
+                                       if(defValue != null)
+                                               
setToolTipText(defValue.toString());
+                               }
                        }
                        
                        setText(vp.getDisplayName());
-                       setToolTipText(vp.getDisplayName());
+                       
                        setIcon(icon);
                        setFont(isSelected ? SELECTED_FONT : NORMAL_FONT);
 
@@ -621,9 +625,6 @@
                        this.setVerticalAlignment(CENTER);
                        this.setIconTextGap(ICON_GAP);
 
-                       if (vp != null && vp.getRange().getType() != null && 
vp.getRange().getType().equals(String.class))
-                               this.setToolTipText(vp.getDefault().toString());
-
                        setBackground(isSelected ? SELECTED_COLOR : 
list.getBackground());
                        setForeground(isSelected ? SELECTED_FONT_COLOR : 
list.getForeground());
 

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