Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / colortable / ui / library / RasterColorTablesFactory.java @ 1086

History | View | Annotate | Download (2.93 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.basic.tool.colortable.ui.library;
23

    
24
import java.util.ArrayList;
25
import java.util.List;
26

    
27
import org.gvsig.fmap.dal.coverage.RasterLocator;
28
import org.gvsig.fmap.dal.coverage.RasterManager;
29
import org.gvsig.fmap.dal.coverage.datastruct.ColorItem;
30
import org.gvsig.fmap.dal.coverage.datastruct.ColorTableLibrary;
31
import org.gvsig.fmap.dal.coverage.exception.FilePaletteException;
32
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
33
import org.gvsig.gui.ColorTablePainter;
34
import org.gvsig.gui.ColorTablesFactory;
35
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
36

    
37
/**
38
 * Factory for color tables. This factory is useful to register color tables
39
 * in gvSIG.
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 *
42
 */
43
public class RasterColorTablesFactory implements ColorTablesFactory {
44
        private ColorTableLibrary tableLib               = null;
45
        
46
        public RasterColorTablesFactory() {
47
                RasterManager rManager = RasterLocator.getManager();
48
                tableLib = rManager.getDataStructFactory().getColorTableLibrary();                
49
        }
50
        
51
        /*
52
         * (non-Javadoc)
53
         * @see org.gvsig.gui.ColorTablesFactory#createColorTables()
54
         */
55
        public List<ColorTablePainter> createColorTables() {
56
                try {
57
                        List<ColorTablePainter> result = new ArrayList<ColorTablePainter>();
58
                        ArrayList<String> fileList = tableLib.getPaletteFileList(ColorTableLibraryPanel.palettesPath);
59
                        for (int i = 0; i < fileList.size(); i++) {
60
                                ArrayList<ColorItem> paletteItems = new ArrayList<ColorItem>();
61
                                String paletteName = tableLib.loadPalette(ColorTableLibraryPanel.palettesPath, (String) fileList.get(i), paletteItems);
62

    
63
                                if (paletteItems.size() <= 0)
64
                                        continue;
65

    
66
                                ColorTable colorTable = tableLib.createColorTable();
67
                                colorTable.setName(paletteName);
68
                                colorTable.createPaletteFromColorItems(paletteItems, true);
69
                                colorTable.setInterpolated(true);
70

    
71
                                ColorTablePainter painter = new ColorTableIconPainter(colorTable);
72
                                result.add(painter);
73
                        }
74
                        return result;
75
                } catch (FilePaletteException e) {
76
                        RasterToolsUtil.messageBoxError(e.getMessage(), this, e);
77
                }
78
                return null;
79
        }
80

    
81
}