Revision 417

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/toc/TOCRenderer.java
6 6
 */
7 7
package com.iver.cit.gvsig.gui.toc;
8 8

  
9
import java.awt.BorderLayout;
9 10
import java.awt.Color;
10 11
import java.awt.Component;
11 12
import java.awt.Dimension;
......
25 26
import javax.swing.tree.DefaultMutableTreeNode;
26 27
import javax.swing.tree.TreeCellRenderer;
27 28

  
28

  
29
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
30 29
import com.iver.cit.gvsig.fmap.layers.FLayer;
31
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
32
import com.iver.cit.gvsig.fmap.rendering.LegendInfo;
33
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
34
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
35
import com.iver.cit.gvsig.fmap.rendering.styling.SymbolPreviewDrawer;
36
import com.iver.cit.gvsig.gui.Panels.FPreviewSymbol;
37 30

  
38 31

  
32

  
39 33
/**
40 34
 * Renderer que actua sobre el TOC.
41 35
 *
......
50 44
    */
51 45
    private Border bordeNormal = BorderFactory.createEmptyBorder();
52 46
    
53
    // public Color m_color;
54 47
	private JCheckBox check;
55 48
	private JLabel label;
56
    // GridBagLayout gridBagLayout = new GridBagLayout();
57
    private FPreviewSymbol colorPanel; // = new PanelColor();
58 49

  
59 50
	private static final Font BIGGER_FONT = 
60 51
									  new Font("SansSerif", Font.BOLD, 12);
......
69 60
        // this.setLayout(new BorderLayout());
70 61
        
71 62
		check = new JCheckBox();
72
		colorPanel = new FPreviewSymbol();
73
		colorPanel.setMinimumSize(new Dimension(25,20));
74 63
		label = new JLabel();
75 64
		
76 65

  
......
104 93
		this.add(colorPanel);
105 94
		this.add(label); */  
106 95

  
107
		SpringLayout theLayout = new SpringLayout();
96
		SpringLayout theLayout = new SpringLayout();		 
108 97
		this.setLayout(theLayout);
109 98

  
110 99
		int rows = 1;
111
		int cols = 3;
100
		int cols = 2;
101
				
102
		/* this.setLayout(new BorderLayout());
112 103
		
113

  
104
		this.add(check, BorderLayout.WEST);
105
		this.add(label, BorderLayout.CENTER);
106
		*/ 
107
		/*
108
		GridBagLayout gridbag = new GridBagLayout();
109
        GridBagConstraints c = new GridBagConstraints();
110
        
111
        this.setLayout(gridbag);
112
        this.add(check);
113
        c.gridwidth = GridBagConstraints.REMAINDER;
114
        c.fill = GridBagConstraints.HORIZONTAL;
115
        this.add(label, c);
116
        */
114 117
		
115
		this.add(check);
116
		this.add(colorPanel);
117
		this.add(label);
118 118
//		Adjust constraints for the text field so it's at
119 119
//		(<label's right edge> + 5, 5).
120
		theLayout.putConstraint(SpringLayout.WEST, colorPanel,
121
						   5,
122
						   SpringLayout.EAST, check);
120
		this.add(check);
121
		this.add(label);  
122

  
123 123
		theLayout.putConstraint(SpringLayout.WEST, label,
124 124
						   5,
125
						   SpringLayout.EAST, colorPanel);
126
						   
127
		/* theLayout.putConstraint(SpringLayout.NORTH, textField,
128
						   5,
129
						   SpringLayout.NORTH, contentPane); */
130
		   
125
						   SpringLayout.EAST, check); 
131 126

  
132
		/* //		  Lay out the panel.
133
		SpringUtilities.makeCompactGrid(this, //parent
134
										rows, cols,
135
										3, 3,  //initX, initY
136
										3, 3); //xPad, yPad */ 
137

  
138

  
139 127
		this.setBorder(bordeSeleccionado);
140 128

  
141 129
        check.setBackground(UIManager.getColor("Button.background"));
142 130
        label.setForeground(UIManager.getColor("Tree.textForeground"));
143 131
        
144

  
145
        colorPanel.setPreferredSize(new Dimension(25,20));
146
        /*
147
         * TODO implementar bien
148
        FSymbol sym = new FSymbol(FConstant.SYMBOL_TYPE_FILL, Color.WHITE);
149
        colorPanel.setSymbol(sym);
150
        */
151
		// this.setMinimumSize(new Dimension(55,70));
152
		// this.setMinimumSize(new Dimension(55,70));
153
        // add(m_panelContenedor);
154 132
        
155 133
    }
156 134

  
......
171 149
    public Component getTreeCellRendererComponent(JTree tree, Object value,
172 150
        boolean isSelected, boolean expanded, boolean leaf, int row,
173 151
        boolean hasFocus) {
174
        
175
        // super.getTreeCellRendererComponent(tree,value,isSelected,expanded, leaf, row, hasFocus);
176
        
177
        int widthTree = tree.getWidth()-24;
178
        Dimension sizeNode;
179
        if (widthTree < 100) widthTree = 100;
180
        
152
                
181 153
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) value;
182 154
		String stringValue = "";
183 155
		this.setBackground(UIManager.getColor("Button.background"));
184 156
		this.label.setFont(tree.getFont());
157
		System.out.println("ancho tree=" + tree.getWidth());
158
        int widthTree = tree.getWidth()-30;
159
        Dimension sizeNode;
160
        
161
		this.setPreferredSize(new Dimension(widthTree,18));
162
		
163
		
185 164

  
186
		// this.setPreferredSize(new Dimension(widthTree,20));
187
		sizeNode = new Dimension(widthTree,18);
188
				
189
        if (n.getUserObject() instanceof FTheme)
190
        {
191
        	FTheme elTema = (FTheme) n.getUserObject(); 
192
        	FLayer lyr = elTema.getLayer();
165
		if (n.getUserObject() instanceof ITocItem)
166
		{
167
	       	ITocItem item = (ITocItem) n.getUserObject();	       	
168
			stringValue = item.getLabel();
169
			if (widthTree < 100) widthTree = 100;
193 170
			
194
			sizeNode = new Dimension(widthTree,25);        	
195
			stringValue = lyr.getName();
196
			colorPanel.setVisible(true);
197
			colorPanel.setBackground(UIManager.getColor("Button.background"));
198
			check.setVisible(true);
199
			check.setSelected(lyr.isVisible());		
200
			if (lyr instanceof FLayer)
171
			sizeNode = new Dimension(100,18);			
172
			if (item instanceof TocItemBranch)
201 173
			{
174
				TocItemBranch branch = (TocItemBranch) item;
175
				sizeNode = new Dimension(widthTree,25);
176
				FLayer lyr = branch.getLayer();
177
				check.setVisible(true);
178
				check.setSelected(lyr.isVisible());		
202 179
				if (lyr.isActive())
203 180
				{				
204 181
					this.setBorder(bordeSeleccionado);
......
207 184
				else
208 185
				{				
209 186
					this.setBorder(bordeNormal);
210
				}
211

  
212
				/* if (lyr instanceof FLyrRaster)
213
				{
214
					colorPanel.setTextDescrip("raster");
215
				}
216
				if (lyr instanceof FLyrDgnG)
217
				{
218
					colorPanel.setTextDescrip("dgn");
219
				}
220
				if (lyr instanceof FLyrDxfG)
221
				{
222
					colorPanel.setTextDescrip("dxf");
223
				}
224
				if (lyr instanceof FLyrWMS)
225
				{
226
					colorPanel.setTextDescrip("wms");
227
				}
228
				*/
229
				if (lyr instanceof FLyrVect)
230
				{				
231
					FLyrVect lyrVect = (FLyrVect) lyr;
232
					LegendInfo legendInfo = lyrVect.getLegendInfo();				
233
					if (legendInfo instanceof SingleSymbolLegend)
234
					{				
235
						FStyle2D sym = legendInfo.getDefaultSymbol();
236
						colorPanel.setVisible(true);
237
						try {
238
							colorPanel.setType(lyrVect.getShapeType());
239
						} catch (DriverIOException e) {
240
							// TODO Auto-generated catch block
241
							e.printStackTrace();
242
						}
243
						colorPanel.setSymbol(sym);	
244
						// colorPanel.repaint();
245
	
246
					}
247
					else
248
					{
249
						colorPanel.setVisible(false);
250
					}
251
				}
187
				}				
188
	        }
189
			else
190
			{
191
				check.setVisible(false);
192
				this.setBorder(bordeNormal);			
193
				
252 194
			}
253
        }
254
		if (n.getUserObject() instanceof FStyle2D)
255
		{
256
			FStyle2D sym = (FStyle2D) n.getUserObject();
257
			// stringValue = sym.m_Descrip;
258
			colorPanel.setVisible(true);
259
			check.setVisible(false);
260
			colorPanel.setSymbol(sym);			
261
			this.setBorder(bordeNormal);			
262
			
263
		}
264
		this.setPreferredSize(sizeNode);
265
        label.setText(stringValue);
195
	        label.setText(stringValue);
196
	        label.setIcon(item.getIcon());
197
	        this.setPreferredSize(sizeNode);
198
		}		
199
		// this.setPreferredSize(new Dimension(tree.getWidth()-60,24)); // sizeNode);
266 200

  
267 201
        if (leaf) {
268 202
            // label.setIcon(UIManager.getIcon("Tree.leafIcon"));

Also available in: Unified diff