Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / TocItemLeaf.java @ 8745

History | View | Annotate | Download (4.94 KB)

1
/*
2
 * Created on 03-dic-2004
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.gui.toc;
48

    
49
import java.awt.Dimension;
50
import java.awt.Graphics2D;
51
import java.awt.Rectangle;
52
import java.awt.datatransfer.DataFlavor;
53
import java.awt.datatransfer.UnsupportedFlavorException;
54
import java.awt.geom.AffineTransform;
55
import java.awt.image.BufferedImage;
56
import java.io.IOException;
57

    
58
import javax.swing.Icon;
59
import javax.swing.ImageIcon;
60

    
61
import com.iver.cit.gvsig.fmap.core.FShape;
62
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
63
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
64
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
65
import com.iver.cit.gvsig.fmap.rendering.styling.SymbolPreviewDrawer;
66

    
67
/**
68
 * @author FJP
69
 *
70
 * TODO To change the template for this generated type comment go to
71
 * Window - Preferences - Java - Code Generation - Code and Comments
72
 */
73
public class TocItemLeaf implements ITocItem {
74

    
75
        private FSymbol symbol;
76
        private String description;
77
        private int layerType;
78
        private static int w_1symbol = 20;
79
        private static int h_1symbol = 15;
80
        
81
        private Dimension sz;
82
        
83
        private static SymbolPreviewDrawer pSD = new SymbolPreviewDrawer();
84
        
85
    final public static DataFlavor INFO_FLAVOR =
86
            new DataFlavor(TocItemLeaf.class, "ItemLeaf");
87

    
88
        static DataFlavor flavors[] = {INFO_FLAVOR };
89
        
90
        
91
        public TocItemLeaf(FSymbol symbol, String description, int layerType)
92
        {
93
                this.symbol = symbol;
94
                this.description = description;
95
                this.layerType = layerType;
96
        }
97
        /* (non-Javadoc)
98
         * @see com.iver.cit.gvsig.gui.toc.ITocItem#getLabel()
99
         */
100
        public String getLabel() {
101
                return description;
102
        }
103

    
104
        /* (non-Javadoc)
105
         * @see com.iver.cit.gvsig.gui.toc.ITocItem#getIcon()
106
         */
107
        public Icon getIcon() {
108
                // System.out.println("Dentro de getIcon: layerType=" + layerType);
109
                BufferedImage img = null;
110
                
111
                switch (layerType)
112
                {
113
                        case FShape.POINT:
114
                        case FShape.LINE:
115
                        case FShape.POLYGON:
116
                        case FShape.MULTIPOINT:
117
                                img = new BufferedImage(w_1symbol, h_1symbol, BufferedImage.TYPE_INT_ARGB);
118
                                Graphics2D g2 = img.createGraphics();
119
                                Rectangle r = new Rectangle(w_1symbol, h_1symbol);                                
120
                                FGraphicUtilities.DrawSymbol(g2, AffineTransform.getScaleInstance(0.8,0.8), r, symbol);
121
                                break;                                                                        
122
                        case FShape.MULTI:
123
                                img = new BufferedImage(3*w_1symbol, h_1symbol, BufferedImage.TYPE_INT_ARGB);
124
                                g2 = img.createGraphics();
125
                                r = new Rectangle(3*w_1symbol, h_1symbol);
126
                                
127
                                FGraphicUtilities.DrawSymbol(g2, AffineTransform.getScaleInstance(0.8,0.8), r, symbol);
128
                                break;                                        
129
                        
130
                }
131
                if (img==null)return null;//TODO tipo de shape no soportado.
132
                return new ImageIcon(img);
133
        }
134
        
135
        /* (non-Javadoc)
136
         * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
137
         */
138
        public DataFlavor[] getTransferDataFlavors() {
139
                return flavors;
140
        }
141

    
142
        /* (non-Javadoc)
143
         * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
144
         */
145
        public boolean isDataFlavorSupported(DataFlavor dF) {
146
                return dF.equals(INFO_FLAVOR);
147
        }
148

    
149
        /* (non-Javadoc)
150
         * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
151
         */
152
        public Object getTransferData(DataFlavor dF) throws UnsupportedFlavorException, IOException {
153
            if (dF.equals(INFO_FLAVOR)) {
154
                return this;
155
              }
156
              else throw new UnsupportedFlavorException(dF);
157
        }
158
        /* (non-Javadoc)
159
         * @see com.iver.cit.gvsig.gui.toc.ITocItem#getSize()
160
         */
161
        public Dimension getSize() {
162
                return sz;
163
        }
164
        /* (non-Javadoc)
165
         * @see com.iver.cit.gvsig.gui.toc.ITocItem#setSize(java.awt.Dimension)
166
         */
167
        public void setSize(Dimension sz) {
168
                this.sz = sz;
169
                
170
        }
171
        
172

    
173
        /**
174
         * @return Returns the symbol.
175
         */
176
        public FSymbol getSymbol() {
177
                return symbol;
178
        }
179
}