Revision 41178

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/toc/gui/TOCRenderer.java
27 27
import java.awt.Component;
28 28
import java.awt.Dimension;
29 29
import java.awt.Font;
30
import java.awt.FontMetrics;
30 31
import java.awt.Rectangle;
31 32

  
32 33
import javax.swing.Icon;
......
52 53
    private static final long serialVersionUID = -6733445768959238193L;
53 54
    private JCheckBox check;
54 55
    private JLabel label;
56
    private static int MARGIN  = 100;
55 57

  
56 58
    private final Color editingColor;
57 59
    
......
89 91
        theLayout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.EAST,
90 92
            check);
91 93
    }
94
    
95
    /**
96
     * Gets the dimension of the node.  
97
     * @param item
98
     * @param font
99
     * @return
100
     */
101
    private Dimension getNodeDimension(ITocItem item, Font font) {
102
    	int textWidth = 0;
103
        int textHeight = 0;
104
        if(font != null && item.getLabel() != null) {
105
        	FontMetrics metrics = this.getFontMetrics(font);
106
        	textWidth = metrics.stringWidth(item.getLabel());
107
        	textHeight = metrics.getHeight();
108
        }
109
        Dimension itemSize = item.getSize();
110
        
111
        int w = (int)Math.max(textWidth, itemSize.getWidth());
112
        int h = (int)Math.max(textHeight, itemSize.getHeight());
113
        
114
        return new Dimension(w + MARGIN, h);
115
    }
92 116

  
93 117
    /**
94 118
     * M?todo llamado una vez por cada nodo, y todas las veces que se redibuja
......
125 149
            }
126 150

  
127 151
            this.validate();
128
            Dimension sizeNode = item.getSize(); // Se fija en el resize del TOC
152
            
153
            Dimension sizeNode = getNodeDimension(item, tree.getFont());
154
            
129 155
            this.setPreferredSize(sizeNode);
130 156

  
131 157
            if (item instanceof TocItemBranch) {

Also available in: Unified diff