Revision 47483

View differences:

tags/org.gvsig.desktop-2.0.430/license.txt
1
gvSIG. Desktop Geographic Information System.
2

  
3
Copyright (C) 2007-2023 gvSIG Association.
4

  
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 3
8
of the License, or (at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

  
15
 You should have received a copy of the GNU General Public License 
16
along with this program. If not, see <https://www.gnu.org/licenses/>. 
17

  
18
For any additional information, do not hesitate to contact us
19
at info AT gvsig.com, or visit our website www.gvsig.com.
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/MapContextRasterSwingLocator.java
1
package org.gvsig.fmap.mapcontext.raster.swing;
2
/* gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2017 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25

  
26
import org.gvsig.tools.locator.BaseLocator;
27

  
28
/**
29
 * This locator is the entry point for the raster buffer swing library,
30
 *
31
 * @author gvSIG team
32
 * @version $Id$
33
 */
34
public class MapContextRasterSwingLocator extends BaseLocator {
35

  
36
    /**
37
     * Chart swing manager name.
38
     */
39
    public static final String SWING_MANAGER_NAME =
40
        "Mapcontext.raster.swing.manager";
41

  
42
    /**
43
     * Chart swing manager description.
44
     */
45
    public static final String SWING_MANAGER_DESCRIPTION =
46
        "UIManager of MapContext Raster library";
47

  
48
    private static final String LOCATOR_NAME = "Mapcontext.raster.swing.locator";
49

  
50
    /**
51
     * Unique instance.
52
     */
53
    private static final MapContextRasterSwingLocator INSTANCE =
54
        new MapContextRasterSwingLocator();
55

  
56
    /**
57
     * Return the singleton instance.
58
     *
59
     * @return the singleton instance
60
     */
61
    public static MapContextRasterSwingLocator getInstance() {
62
        return INSTANCE;
63
    }
64

  
65
    /**
66
     * Return the Locator's name
67
     *
68
     * @return a String with the Locator's name
69
     */
70
    public final String getLocatorName() {
71
        return LOCATOR_NAME;
72
    }
73

  
74
    /**
75
     * Registers the Class implementing the PersistenceManager interface.
76
     *
77
     * @param clazz
78
     *            implementing the PersistenceManager interface
79
     */
80
    public static void registerSwingManager(
81
        Class<? extends MapContextRasterSwingManager> clazz) {
82
        getInstance().register(SWING_MANAGER_NAME, SWING_MANAGER_DESCRIPTION,
83
            clazz);
84
    }
85

  
86
    /**
87
     * Gets the instance of the {@link ScriptingUIManager} registered.
88
     *
89
     * @return {@link ScriptingUIManager}
90
     */
91
    public static MapContextRasterSwingManager getSwingManager() {
92
        return (MapContextRasterSwingManager) getInstance()
93
            .get(SWING_MANAGER_NAME);
94
    }
95

  
96
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/MapContextRasterSwingLibrary.java
1
package org.gvsig.fmap.mapcontext.raster.swing;
2

  
3
/* gvSIG. Desktop Geographic Information System.
4
 *
5
 * Copyright ? 2007-2017 gvSIG Association
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 * MA  02110-1301, USA.
21
 *
22
 * For any additional information, do not hesitate to contact us
23
 * at info AT gvsig.com, or visit our website www.gvsig.com.
24
 */
25
import org.gvsig.tools.library.AbstractLibrary;
26
import org.gvsig.tools.library.LibraryException;
27
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
28

  
29

  
30

  
31

  
32
/**
33
 * @author fdiaz
34
 *
35
 */
36
public class MapContextRasterSwingLibrary extends AbstractLibrary{
37

  
38
    @Override
39
    public void doRegistration() {
40
        registerAsAPI(MapContextRasterSwingLibrary.class);
41
//        this.require(RasterLibrary.class);
42
//        this.require(BufferLibrary.class);
43
    }
44

  
45
    @Override
46
    protected void doInitialize() throws LibraryException {
47
    }
48

  
49
    @Override
50
    protected void doPostInitialize() throws LibraryException {
51
        // Validate there is any implementation registered.
52
        MapContextRasterSwingManager manager =
53
            MapContextRasterSwingLocator.getSwingManager();
54
        if (manager == null) {
55
            throw new ReferenceNotRegisteredException(
56
                MapContextRasterSwingLocator.SWING_MANAGER_NAME,
57
                MapContextRasterSwingLocator.getInstance());
58
        }
59
    }
60

  
61

  
62
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/export/ExportRasterPanel.java
1
package org.gvsig.fmap.mapcontext.raster.swing.export;
2

  
3
import java.nio.Buffer;
4

  
5
import org.gvsig.tools.swing.api.Component;
6

  
7

  
8
public interface ExportRasterPanel extends Component {
9

  
10
//    /**
11
//     * @param layer
12
//     */
13
//    public boolean fetch(FLayer layer);
14

  
15
    /**
16
     * @param buffer
17
     */
18
    public void set(Buffer buffer);
19

  
20
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/SelectableBandDescriptorsTableModel.java
1
package org.gvsig.fmap.mapcontext.raster.swing;
2

  
3
import org.gvsig.raster.swing.buffer.SelectableBandsTableModel;
4

  
5

  
6
/**
7
 * @author fdiaz
8
 *
9
 */
10
public interface SelectableBandDescriptorsTableModel extends SelectableBandsTableModel {
11

  
12
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/operations/OperationListPanel.java
1
package org.gvsig.fmap.mapcontext.raster.swing.operations;
2

  
3
import java.awt.event.ActionListener;
4

  
5
import javax.swing.event.ListSelectionListener;
6
import javax.swing.event.TableModelListener;
7

  
8
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory;
9
import org.gvsig.raster.lib.buffer.api.operations.OperationList;
10
import org.gvsig.raster.lib.buffer.api.operations.OperationListEntry;
11
import org.gvsig.tools.swing.api.Component;
12

  
13
/**
14
 * @author fdiaz
15
 *
16
 */
17
public interface OperationListPanel extends Component {
18

  
19
    public static String ADD_ACTION_COMMAND = "add_operation_entry";
20
    public static String UPDATE_ACTION_COMMAND = "update_operation_entry";
21
    public static String UP_ACTION_COMMAND = "up_operation_entry";
22
    public static String DOWN_ACTION_COMMAND = "down_operation_entry";
23
    public static String REMOVE_ACTION_COMMAND = "remove_operation_entry";
24

  
25
    /**
26
     * @param operationList
27
     * @return
28
     */
29
    public boolean fetch(OperationList operationList);
30

  
31
    /**
32
     * @param operationList
33
     */
34
    public void set(OperationList operationList);
35

  
36
    /**
37
     * @param layer
38
     * @return
39
     */
40
    public OperationListEntry getSelected();
41

  
42
    /**
43
     * @param listener
44
     */
45
    public void addListSelectionListener(ListSelectionListener listener);
46

  
47
    /**
48
     * @param listener
49
     */
50
    public void addTableModelListener(TableModelListener listener);
51

  
52
    /**
53
     * @param enable
54
     */
55
    public void enableAdd(boolean enable);
56

  
57
    /**
58
     * @param enable
59
     */
60
    public void enableUpdate(boolean enable);
61

  
62
    /**
63
     * @param operationListEntry
64
     */
65
    public void add(OperationListEntry operationListEntry);
66

  
67
    /**
68
     * @param listener
69
     */
70
    void addActionListener(ActionListener listener);
71

  
72
    /**
73
    *
74
    */
75
    public void clearSelection();
76

  
77
    /**
78
     * @param row
79
     */
80
    public void select(int row);
81

  
82
    /**
83
     * @return
84
     */
85
    public int getSelectedRow();
86

  
87
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/operations/OperationSelectorPanel.java
1
package org.gvsig.fmap.mapcontext.raster.swing.operations;
2

  
3
import javax.swing.event.ListSelectionListener;
4

  
5
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory;
6
import org.gvsig.tools.swing.api.Component;
7

  
8

  
9

  
10
/**
11
 * @author fdiaz
12
 *
13
 */
14
public interface OperationSelectorPanel extends Component {
15

  
16
    /**
17
     * @param layer
18
     * @return
19
     */
20
    public OperationFactory getSelected();
21

  
22
    /**
23
     * @param layer
24
     * @return
25
     */
26
    public void clearSelection();
27

  
28
    /**
29
     * @param listener
30
     */
31
    public void addListSelectionListener(ListSelectionListener listener);
32

  
33
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/MapContextRasterSwingManager.java
1
package org.gvsig.fmap.mapcontext.raster.swing;
2
/* gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2017 gvSIG Association
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25

  
26
import java.util.List;
27

  
28
import org.gvsig.fmap.dal.raster.BandDescriptor;
29
import org.gvsig.fmap.mapcontext.raster.swing.bands.BandsPanel;
30
import org.gvsig.fmap.mapcontext.raster.swing.export.ExportRasterPanel;
31
import org.gvsig.fmap.mapcontext.raster.swing.operations.OperationListPanel;
32
import org.gvsig.fmap.mapcontext.raster.swing.operations.OperationSelectorPanel;
33
import org.gvsig.fmap.mapcontext.raster.swing.previewer.OneLayerPreviewer;
34
import org.gvsig.fmap.mapcontext.raster.swing.transparency.TransparencyPanel;
35
import org.gvsig.tools.service.Manager;
36

  
37

  
38
/**
39
 *
40
 * @see MapContextRasterSwingManager
41
 * @author gvSIG team
42
 * @version $Id$
43
 */
44
public interface MapContextRasterSwingManager extends Manager{
45

  
46
    /**
47
     * @return
48
     */
49
    public SelectableBandDescriptorsTableModel createSelectableBandDescriptorsTableModel(List<BandDescriptor> descriptors) ;
50

  
51
    /**
52
     * @return
53
     */
54
    public TransparencyPanel createTransparencyPanel();
55

  
56
    /**
57
     * @return
58
     */
59
    public BandsPanel createBandsPanel();
60

  
61

  
62
    /**
63
     * @return
64
     */
65
    public ExportRasterPanel createExportRaster();
66

  
67
    /**
68
     * @return
69
     */
70
    public OneLayerPreviewer createOneLayerPreviewer();
71

  
72
    /**
73
     * @return
74
     */
75
    public OperationListPanel createOperationListPanel();
76

  
77
    /**
78
     * @return
79
     */
80
    OperationSelectorPanel createOperationSelectorPanel();
81

  
82
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/bands/BandsPanel.java
1
package org.gvsig.fmap.mapcontext.raster.swing.bands;
2

  
3
import org.gvsig.tools.dispose.Disposable;
4
import org.gvsig.tools.swing.api.Component;
5
import org.gvsig.fmap.mapcontext.layers.FLayer;
6

  
7

  
8

  
9
/**
10
 * @author fdiaz
11
 *
12
 */
13
public interface BandsPanel extends Component, Disposable {
14

  
15
    /**
16
     * @param layer
17
     * @return
18
     */
19
    public boolean fetch(FLayer layer);
20

  
21
    /**
22
     * @param layer
23
     */
24
    public void set(FLayer layer);
25

  
26
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/previewer/OneLayerPreviewer.java
1
package org.gvsig.fmap.mapcontext.raster.swing.previewer;
2

  
3
import org.cresques.cts.IProjection;
4

  
5
import org.gvsig.fmap.mapcontext.layers.FLayer;
6
import org.gvsig.tools.dispose.Disposable;
7
import org.gvsig.tools.swing.api.Component;
8

  
9

  
10
/**
11
 * @author fdiaz
12
 *
13
 */
14
public interface OneLayerPreviewer extends Component, Disposable {
15

  
16
    /**
17
     * @param projection
18
     */
19
    public void setProjection(IProjection projection);
20

  
21
    /**
22
     * @param layer
23
     */
24
    public void setLayer(FLayer layer);
25

  
26
    /**
27
     * @return
28
     */
29
    public FLayer getLayer();
30

  
31
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/transparency/TransparencyPanel.java
1
package org.gvsig.fmap.mapcontext.raster.swing.transparency;
2

  
3
import java.awt.Color;
4

  
5
import org.gvsig.fmap.mapcontext.layers.FLayer;
6
import org.gvsig.tools.swing.api.Component;
7

  
8

  
9

  
10
/**
11
 * @author fdiaz
12
 *
13
 */
14
public interface TransparencyPanel extends Component {
15

  
16
    /**
17
     * Fetch the layer with the panel's values.
18
     *
19
     * @param layer
20
     * @return
21
     */
22
    public boolean fetch(FLayer layer);
23

  
24
    /**
25
     * Sets the layer
26
     *
27
     * @param layer
28
     */
29
    public void set(FLayer layer);
30

  
31
    /**
32
     * Sets the color.
33
     * @param color
34
     */
35
    public void setColor(Color color);
36

  
37
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.mapcontext.raster.swing.MapContextRasterSwingLibrary
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.api/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <parent>
4
        <groupId>org.gvsig</groupId>
5
        <artifactId>org.gvsig.fmap.mapcontext.swing</artifactId>
6
        <version>2.0.430</version>
7
      </parent>
8
    <artifactId>org.gvsig.fmap.mapcontext.swing.api</artifactId>
9
    <name>${project.artifactId}</name>
10
    <dependencies>
11
        <dependency>
12
            <groupId>org.gvsig</groupId>
13
            <artifactId>org.gvsig.tools.swing.api</artifactId>
14
            <scope>compile</scope>
15
        </dependency>
16
        <dependency>
17
            <groupId>org.gvsig</groupId>
18
            <artifactId>org.gvsig.raster.lib.buffer.api</artifactId>
19
            <scope>compile</scope>
20
        </dependency>
21
        <dependency>
22
            <groupId>org.gvsig</groupId>
23
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
24
            <scope>compile</scope>
25
        </dependency>
26
        <dependency>
27
            <groupId>org.gvsig</groupId>
28
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
29
            <scope>compile</scope>
30
        </dependency>
31
        <dependency>
32
            <groupId>org.gvsig</groupId>
33
            <artifactId>org.gvsig.raster.swing.buffer.api</artifactId>
34
            <scope>compile</scope>
35
        </dependency>
36
    </dependencies>
37
</project>
0 38

  
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <parent>
4
        <groupId>org.gvsig</groupId>
5
        <artifactId>org.gvsig.desktop.library</artifactId>
6
        <version>2.0.430</version>
7
      </parent>
8
    <groupId>org.gvsig</groupId>
9
    <artifactId>org.gvsig.fmap.mapcontext.swing</artifactId>
10
    <packaging>pom</packaging>
11
    <name>${project.artifactId}</name>
12
    <modules>
13
        <module>org.gvsig.fmap.mapcontext.swing.api</module>
14
        <module>org.gvsig.fmap.mapcontext.swing.impl</module>
15
    </modules>
16
</project>
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.impl/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/impl/bands/BandsPanelController.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2017 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontext.raster.swing.impl.bands;
24

  
25
import java.awt.color.ColorSpace;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.awt.event.ItemEvent;
29
import java.awt.event.ItemListener;
30
import java.io.File;
31
import java.util.ArrayList;
32
import java.util.Iterator;
33
import java.util.List;
34
import java.util.Locale;
35

  
36
import javax.swing.JComponent;
37
import javax.swing.JFileChooser;
38
import javax.swing.JOptionPane;
39
import javax.swing.ListSelectionModel;
40
import javax.swing.event.ListSelectionEvent;
41
import javax.swing.event.ListSelectionListener;
42
import javax.swing.filechooser.FileFilter;
43
import javax.swing.table.DefaultTableColumnModel;
44
import javax.swing.table.TableColumn;
45
import javax.swing.table.TableColumnModel;
46
import javax.swing.table.TableModel;
47

  
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

  
51
import org.gvsig.fmap.dal.DALLocator;
52
import org.gvsig.fmap.dal.DataManager;
53
import org.gvsig.fmap.dal.DataServerExplorerParameters;
54
import org.gvsig.fmap.dal.exception.DataException;
55
import org.gvsig.fmap.dal.exception.InitializeException;
56
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
57
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
58
import org.gvsig.fmap.dal.raster.BandDescriptor;
59
import org.gvsig.fmap.dal.raster.RasterStore;
60
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter;
61
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
62
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
63
import org.gvsig.fmap.mapcontext.layers.FLayer;
64
import org.gvsig.fmap.mapcontext.raster.api.RasterLayer;
65
import org.gvsig.fmap.mapcontext.raster.swing.bands.BandsPanel;
66
import org.gvsig.raster.lib.buffer.api.BufferLocator;
67
import org.gvsig.raster.lib.buffer.api.BufferManager;
68
import org.gvsig.raster.lib.buffer.api.NoData;
69
import org.gvsig.raster.lib.legend.api.RasterLegend;
70
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
71
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
72
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
73
import org.gvsig.tools.ToolsLocator;
74
import org.gvsig.tools.dispose.DisposeUtils;
75
import org.gvsig.tools.dynobject.DynObject;
76
import org.gvsig.tools.i18n.I18nManager;
77
import org.gvsig.tools.swing.api.ToolsSwingLocator;
78
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
79

  
80
/**
81
 * @author fdiaz
82
 *
83
 */
84
public class BandsPanelController extends BandsPanelView implements BandsPanel, ActionListener, ListSelectionListener {
85

  
86
    /**
87
     *
88
     */
89
    private static final long serialVersionUID = 8255630092178065352L;
90
    @SuppressWarnings("unused")
91
    private static final Logger LOG = LoggerFactory.getLogger(BandsPanelController.class);
92
    private RasterLayer layer;
93

  
94
    private static final String RASTER_FILTER = "All_raster_supported";
95

  
96
    // FLayer layer;
97

  
98
    /**
99
     * @param layer
100
     */
101
    @SuppressWarnings("unchecked")
102
    public BandsPanelController() {
103
        DisposeUtils.bind(this);
104
        translate();
105
        initializeComponents();
106
    }
107

  
108
    private void initializeComponents() {
109
        this.btnAdd.addActionListener(this);
110
        this.btnRemove.addActionListener(this);
111
        tblBands.setRowSelectionAllowed(true);
112
        tblBands.setColumnSelectionAllowed(false);
113
        tblBands.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
114
        tblBands.getSelectionModel().addListSelectionListener(this);
115
        BandsTableModel model = new BandsTableModel();
116
        tblBands.setModel(model);
117

  
118
        tblBands.setColumnModel(new DefaultTableColumnModel());
119
        TableColumnModel columnModel = tblBands.getColumnModel();
120
        columnModel.setColumnSelectionAllowed(false);
121
        for (int i = 0; i < model.getColumnCount(); i++) {
122
            TableColumn tableColumn = new TableColumn(i);
123
            tableColumn.setIdentifier(model.getColumnName(i));
124
            tableColumn.setHeaderValue(model.getColumnName(i));
125
            columnModel.addColumn(tableColumn);
126
        }
127

  
128
        cboColorSpaces.addItem(ColorInterpretation.RGB);
129
        cboColorSpaces.addItem(ColorInterpretation.CMYK);
130
        cboColorSpaces.addItem(ColorInterpretation.HSL);
131
        //FIXME: Uncomment when a operation to convert RGB to/from HSL is implemented.
132
//        cboColorSpaces.addItem(ColorInterpretation.YCBCR);
133
        cboColorSpaces.addItemListener(new ItemListener() {
134

  
135
            @Override
136
            public void itemStateChanged(ItemEvent e) {
137
                doChangeColorColumnCellEditor();
138
            }
139
        });
140

  
141
        // FIXME: esto ser?a lo que habr?a que cambiar si se desea implementar
142
        // otros espacios de color
143
//        columnModel.getColumn(0).setCellEditor(new ColorInterpretationCellEditor(BandsTableModel.RGBColorSpace));
144
        columnModel.getColumn(0).setCellRenderer(new ColorInterpretationCellRenderer());
145

  
146
        columnModel.getColumn(1).setCellRenderer(new NoDataCellRenderer());
147
        // columnModel.getColumn(1).setCellEditor(new NoDataCellEditor());
148

  
149
        columnModel.getColumn(2).setCellRenderer(new DataTypeCellRenderer());
150

  
151
    }
152

  
153
    private void translate() {
154
        I18nManager i18nManager = ToolsLocator.getI18nManager();
155
        lblBands.setText(i18nManager.getTranslation(lblBands.getText()));
156
        lblColorSpace.setText(i18nManager.getTranslation(lblColorSpace.getText()));
157
        cboColorSpaces.setToolTipText(i18nManager.getTranslation(cboColorSpaces.getToolTipText()));
158
        btnAdd.setText(i18nManager.getTranslation(btnAdd.getText()));
159
        btnAdd.setToolTipText(i18nManager.getTranslation(btnAdd.getToolTipText()));
160
        btnRemove.setText(i18nManager.getTranslation(btnRemove.getText()));
161
        btnRemove.setToolTipText(i18nManager.getTranslation(btnRemove.getToolTipText()));
162
    }
163

  
164
    /**
165
     * @param locale
166
     *
167
     */
168
    public void setLocate(Locale locale) {
169
        Locale l = super.getLocale();
170
        if (!l.equals(locale)) {
171
            translate();
172
        }
173
        super.setLocale(locale);
174
    }
175

  
176
    /**
177
     * @param layer
178
     */
179
    @SuppressWarnings("unchecked")
180
    public void set(FLayer layer) {
181
        if(this.layer!=null){
182
            DisposeUtils.dispose(this.layer);
183
        }
184
        this.layer = (RasterLayer) layer;
185
        DisposeUtils.bind(layer);
186
        RasterLegend legend = this.layer.getLegend();
187
        ColorInterpretation colorInterpretation = null;
188
        if (legend != null) {
189
            colorInterpretation = legend.getColorInterpretation();
190
        }
191
        RasterStore store = this.layer.getRasterStore();
192
        addBands(store, colorInterpretation);
193
    }
194

  
195
    /**
196
     * @param colorInterpretation
197
     * @param store
198
     * @param model
199
     */
200
    private void addBands(RasterStore store, ColorInterpretation colorInterpretation) {
201
        String colorSpace = "";
202
        if (colorInterpretation.hasAnyCMYKBand()) {
203
            colorSpace = ColorInterpretation.CMYK;
204
        } else if (colorInterpretation.hasAnyHSLBand()) {
205
            colorSpace = ColorInterpretation.HSL;
206
        } else if (colorInterpretation.hasAnyHSLBand()) {
207
            colorSpace = ColorInterpretation.YCBCR;
208
        } else {
209
            colorSpace = ColorInterpretation.RGB;
210
        }
211
        cboColorSpaces.setSelectedItem(colorSpace);
212
        doChangeColorColumnCellEditor();
213

  
214
        BandsTableModel model = ((BandsTableModel) tblBands.getModel());
215
        for (int i = 0; i < store.getBands(); i++) {
216
            BandDescriptor bandDescriptor = store.getBandDescriptor(i);
217

  
218
            RasterStoreBand rasterStoreBand = new RasterStoreBand(bandDescriptor.getStore(), bandDescriptor.getBand());
219
            NoData noData = bandDescriptor.getNoData();
220
            if (noData != null) {
221
                rasterStoreBand.setNoDataNumber(noData.getValue());
222
            }
223
            rasterStoreBand.setBandName(bandDescriptor.getName());
224
            rasterStoreBand.setDataType(bandDescriptor.getDataType());
225

  
226
            if (colorInterpretation != null) {
227
                rasterStoreBand.setBandColorInterpretation(colorInterpretation.get(i));
228
            } else {
229
                rasterStoreBand.setBandColorInterpretation(ColorInterpretation.UNDEFINED_BAND);
230
            }
231
            model.add(rasterStoreBand);
232
            DisposeUtils.disposeQuietly(rasterStoreBand);
233
            model.fireTableDataChanged();
234
        }
235
    }
236

  
237
    /**
238
     * @param layer
239
     */
240
    public boolean fetch(FLayer layer) {
241
        RasterLayer rasterLayer = (RasterLayer) layer;
242
        RasterStore store = rasterLayer.getRasterStore();
243
        RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager();
244
        if (willBeChangedBands(store)) {
245
            store.clearAdditionalBands();
246
            BandsTableModel model = (BandsTableModel) tblBands.getModel();
247
            BufferManager bufferManager = BufferLocator.getBufferManager();
248

  
249
            for (int index = 0; index < model.getRowCount(); index++) {
250
                RasterStoreBand rasterStoreBand = model.getElementAt(index);
251
                RasterStore subStore = rasterStoreBand.getStore();
252
                int band = rasterStoreBand.getBand();
253
                if (subStore != store) {
254
                    try {
255
                        store.addBand(subStore, band);
256
                    } catch (DataException e) {
257
                        ThreadSafeDialogsManager dlgManager = ToolsSwingLocator.getThreadSafeDialogsManager();
258
                        String message = "_cant_add_band_XbandX_from_store_XsourceX_to_store_XtargetX";
259
                        String title = "_error_adding_bands";
260
                        dlgManager.messageDialog(message, new String[] { String.valueOf(band), subStore.getName(),
261
                            store.getName() }, title, JOptionPane.WARNING_MESSAGE);
262
                        LOG.warn(message, e);
263
                        return false;
264
                    }
265
                }
266
                BandDescriptor bandDescriptor = store.getBandDescriptor(index);
267
                NoData noData = bandDescriptor.getNoData();
268
                Number value = null;
269
                value = rasterStoreBand.getNoDataNumber();
270

  
271
                if (noData == null) {
272
                    noData = bufferManager.createNoData(value, null);
273
                } else {
274
                    noData.setValue((Number) value);
275
                }
276
                bandDescriptor.setNoData(noData);
277
            }
278
            rasterLayer.recalculateStatistics();
279

  
280
            List<String> colorInterpretations = getColorInterpretations();
281

  
282
            boolean createNewLegend = true;
283
            RasterLegend oldLegend = rasterLayer.getLegend();
284
            if(oldLegend!=null){
285
                ColorInterpretation oldColorInterpretation = oldLegend.getColorInterpretation();
286
                if(oldColorInterpretation.length()==colorInterpretations.size()){
287
                    for (int band=0; band<oldColorInterpretation.length(); band++) {
288
                        oldColorInterpretation.setColorInterpValue(band, colorInterpretations.get(band));
289
                    }
290
                    createNewLegend = false;
291
                }
292
            }
293

  
294
            if(createNewLegend) {
295
                ColorInterpretation colorInterpretation =
296
                    rasterLegendManager.createColorInterpretation(colorInterpretations.toArray(new String[0]));
297

  
298
                RasterLegend legend = rasterLegendManager.createLegend(colorInterpretation);
299
                rasterLayer.setLegend(legend);
300
            }
301

  
302

  
303
            rasterLayer.getMapContext().invalidate();
304
        }
305

  
306
        return true;
307
    }
308

  
309
    private List<String> getColorInterpretations(){
310
        List<String> colorInterpretations = new ArrayList();
311
        BandsTableModel model = (BandsTableModel) tblBands.getModel();
312

  
313
        for (int index = 0; index < model.getRowCount(); index++) {
314
            RasterStoreBand rasterStoreBand = model.getElementAt(index);
315
            RasterStore subStore = rasterStoreBand.getStore();
316
            int band = rasterStoreBand.getBand();
317
            colorInterpretations.add(rasterStoreBand.getBandColorInterpretation());
318
        }
319
        return colorInterpretations;
320
    }
321

  
322
    private boolean willBeChangedBands(RasterStore store){
323

  
324
        BandsTableModel model = (BandsTableModel) tblBands.getModel();
325

  
326
        if(store.getBands()!=model.getRowCount()){
327
            return true;
328
        }
329
        ColorInterpretation colorInterpretation = this.layer.getLegend().getColorInterpretation();
330
        for (int index = 0; index < model.getRowCount(); index++) {
331
            RasterStoreBand rasterStoreBand = model.getElementAt(index);
332
            RasterStore subStore = rasterStoreBand.getStore();
333
            int band = rasterStoreBand.getBand();
334
            BandDescriptor bandDescriptor = store.getBandDescriptor(index);
335
            if (bandDescriptor.getStore() != subStore || bandDescriptor.getBand() != band
336
                || isChangedNoData(bandDescriptor.getNoData(), rasterStoreBand.getNoDataNumber())
337
                || !(rasterStoreBand.getBandColorInterpretation().equals(colorInterpretation.get(index)))
338
               ){
339
                return true;
340
            }
341
        }
342
        return false;
343
    }
344

  
345
    private boolean isChangedNoData(NoData noData, Number number){
346
        if(noData!=null){
347
            return noData.getValue()!=number;
348
        } else {
349
            return number!=null;
350
        }
351
    }
352

  
353
    @Override
354
    public JComponent asJComponent() {
355
        return this;
356
    }
357

  
358
    @SuppressWarnings("unchecked")
359
    @Override
360
    public void actionPerformed(ActionEvent e) {
361
        if (e.getSource() == btnRemove) {
362
            BandsTableModel model = (BandsTableModel) tblBands.getModel();
363
            model.removeElementAt(tblBands.getSelectedRow());
364
            model.fireTableDataChanged();
365

  
366
        } else if (e.getSource() == btnAdd) {
367
            DataManager manager = DALLocator.getDataManager();
368

  
369
            JFileChooser fileChooser = createJFileChooser();
370
            int result = fileChooser.showOpenDialog(this);
371

  
372
            if (result == JFileChooser.APPROVE_OPTION) {
373
                File[] files = fileChooser.getSelectedFiles();
374
                for (File file : files) {
375

  
376
                    DataServerExplorerParameters fileExplorerParams;
377
                    try {
378
                        fileExplorerParams = manager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
379
                        FilesystemServerExplorer explorer =
380
                            (FilesystemServerExplorer) manager.openServerExplorer(FilesystemServerExplorer.NAME,
381
                                fileExplorerParams);
382
                        String type = explorer.getProviderName(file);
383
                        DynObject params = manager.createStoreParameters(type);
384
                        if (params.getDynClass().getDynField("file") != null) {
385
                            params.setDynValue("file", file);
386
                        }
387
                        // FIXME: ?se le pone la proyecci?n del raster principal
388
                        // o se busca la que tenga el archivo si la tiene?
389
                        if (params.getDynClass().getDynField("crs") != null) {
390
                            params.setDynValue("crs", this.layer.getProjection());
391
                        }
392
                        RasterStore store = (RasterStore) manager.openStore(type, params);
393
                        DisposeUtils.disposeQuietly(explorer);
394

  
395
                        addBands(store, null);
396
                        DisposeUtils.disposeQuietly(store);
397

  
398
                    } catch (InitializeException | ProviderNotRegisteredException | ValidateDataParametersException e1) {
399
                        LOG.warn("Can't add bands from the file '" + file.getName() + "'", e1);
400
                        // e1.printStackTrace();
401
                    }
402
                }
403
            }
404
        }
405
    }
406

  
407
    @Override
408
    public void valueChanged(ListSelectionEvent e) {
409
        if (e.getSource() == tblBands.getSelectionModel()) {
410
            if (tblBands.getSelectedRow() >= 0) {
411
                if (this.layer.getRasterStore() != ((BandsTableModel) tblBands.getModel()).getElementAt(
412
                    tblBands.getSelectedRow()).getStore()) {
413
                    btnRemove.setEnabled(true);
414
                } else {
415
                    btnRemove.setEnabled(false);
416
                }
417
            } else {
418
                btnRemove.setEnabled(false);
419
            }
420
        }
421
    }
422

  
423
    private JFileChooser createJFileChooser() {
424
        I18nManager i18nManager = ToolsLocator.getI18nManager();
425
        JFileChooser fileChooser = new JFileChooser();
426

  
427
        int mode = FilesystemServerExplorer.MODE_RASTER;
428
        FilesystemServerExplorer explorer;
429

  
430
        DataManager dm = DALLocator.getDataManager();
431
        FilesystemServerExplorerParameters param;
432
        try {
433
            param =
434
                (FilesystemServerExplorerParameters) dm.createServerExplorerParameters(FilesystemServerExplorer.NAME);
435
            explorer = (FilesystemServerExplorer) dm.openServerExplorer(FilesystemServerExplorer.NAME, param);
436
        } catch (Exception e) {
437
            throw new RuntimeException(e);
438
        }
439

  
440
        FilesystemFileFilter filter = explorer.getFilter(mode, i18nManager.getTranslation(RASTER_FILTER));
441

  
442
        fileChooser.setMultiSelectionEnabled(true);
443
        fileChooser.setAcceptAllFileFilterUsed(false);
444
        fileChooser.setFileFilter(new MyFileFilter(filter));
445
        DisposeUtils.dispose(explorer);
446

  
447
        return fileChooser;
448
    }
449

  
450
    /**
451
     * @author fdiaz
452
     *
453
     */
454
    public class MyFileFilter extends FileFilter {
455

  
456
        public FilesystemFileFilter filter = null;
457

  
458
        /**
459
         * @param params
460
         */
461
        public MyFileFilter(FilesystemFileFilter params) {
462
            this.filter = params;
463
        }
464

  
465
        /**
466
         * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
467
         */
468
        public boolean accept(File f) {
469
            if (f.isDirectory()) {
470
                return true;
471
            }
472
            return filter.accept(f);
473

  
474
        }
475

  
476
        /**
477
         * @see javax.swing.filechooser.FileFilter#getDescription()
478
         */
479
        public String getDescription() {
480
            return filter.getDescription();
481
        }
482

  
483
        /**
484
         * @return
485
         */
486
        public String getName() {
487
            return filter.getDataStoreProviderName();
488
        }
489
    }
490

  
491
    @Override
492
    public void dispose() {
493
        if(!ToolsLocator.getDisposableManager().release(this)){
494
            return;
495
        }
496
        DisposeUtils.dispose(this.layer);
497
        this.layer = null;
498

  
499
        BandsTableModel model = (BandsTableModel) tblBands.getModel();
500

  
501
        for (int index = 0; index < model.getRowCount(); index++) {
502
            RasterStoreBand rasterStoreBand = model.getElementAt(index);
503
            DisposeUtils.disposeQuietly(rasterStoreBand);
504
        }
505
    }
506

  
507
    private void doChangeColorColumnCellEditor() {
508
        TableColumnModel columnModel = tblBands.getColumnModel();
509

  
510
        String selectedItem = (String)cboColorSpaces.getSelectedItem();
511
        if(selectedItem.equalsIgnoreCase(ColorInterpretation.RGB)){
512

  
513
            columnModel.getColumn(0).setCellEditor(new ColorInterpretationCellEditor(BandsTableModel.RGBColorSpace));
514
        }
515
        if(selectedItem.equalsIgnoreCase(ColorInterpretation.CMYK)){
516
            columnModel.getColumn(0).setCellEditor(new ColorInterpretationCellEditor(BandsTableModel.CMYKColorSpace));
517
        }
518
        if(selectedItem.equalsIgnoreCase(ColorInterpretation.HSL)){
519
            columnModel.getColumn(0).setCellEditor(new ColorInterpretationCellEditor(BandsTableModel.HSLColorSpace));
520
        }
521
        if(selectedItem.equalsIgnoreCase(ColorInterpretation.YCBCR)){
522
            columnModel.getColumn(0).setCellEditor(new ColorInterpretationCellEditor(BandsTableModel.YCBCRColorSpace));
523
        }
524

  
525
        TableModel bandModel = tblBands.getModel();
526
        for (int i = 0; i < tblBands.getRowCount(); i++) {
527
            bandModel.setValueAt(ColorInterpretation.UNDEFINED_BAND, i, 0);
528
        }
529
    }
530
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.impl/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/impl/bands/ColorInterpretationCellEditor.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2017 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontext.raster.swing.impl.bands;
24

  
25
import java.awt.Component;
26
import java.util.List;
27

  
28
import javax.swing.AbstractCellEditor;
29
import javax.swing.JComboBox;
30
import javax.swing.JTable;
31
import javax.swing.table.TableCellEditor;
32

  
33
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
34
import org.gvsig.tools.ToolsLocator;
35

  
36

  
37
/**
38
 * @author fdiaz
39
 *
40
 */
41
public class ColorInterpretationCellEditor extends AbstractCellEditor implements TableCellEditor {
42

  
43
    /**
44
     *
45
     */
46
    private static final long serialVersionUID = 8964406967059115883L;
47
    private List<String> colorSpace;
48
    private JComboBox<ItemColor> comboBox;
49
    /**
50
     * @param colorSpace
51
     */
52
    public ColorInterpretationCellEditor(List<String> colorSpace) {
53
        this.colorSpace = colorSpace;
54
    }
55

  
56
    @Override
57
    public Object getCellEditorValue() {
58
        return ((ItemColor)comboBox.getSelectedItem()).key;
59
    }
60

  
61
    @Override
62
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
63

  
64
        comboBox = new JComboBox<ItemColor>();
65
        int i=0;
66
        int selected=i;
67
        comboBox.addItem(new ItemColor(ColorInterpretation.UNDEFINED_BAND));
68
        if(ColorInterpretation.UNDEFINED_BAND.equalsIgnoreCase((String)value)){
69
            selected=i;
70
        };
71
        i++;
72
        for (String string : colorSpace) {
73
            comboBox.addItem(new ItemColor(string));
74
            if(string.equalsIgnoreCase((String)value)){
75
                selected=i;
76
            };
77
            i++;
78
        }
79
        comboBox.addItem(new ItemColor(ColorInterpretation.GRAY_BAND));
80
        if(ColorInterpretation.GRAY_BAND.equalsIgnoreCase((String)value)){
81
            selected=i;
82
        };
83
        i++;
84
        comboBox.addItem(new ItemColor(ColorInterpretation.PALETTE_BAND));
85
        if(ColorInterpretation.PALETTE_BAND.equalsIgnoreCase((String)value)){
86
            selected=i;
87
        };
88
        i++;
89

  
90
        comboBox.setSelectedItem(selected);
91
        return comboBox;
92
    }
93

  
94
    class ItemColor {
95
        private String key;
96

  
97
        public ItemColor(String key){
98
            this.key = key;
99
        }
100

  
101
        public String toString() {
102
            return ToolsLocator.getI18nManager().getTranslation(key);
103
        }
104

  
105
    }
106

  
107
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.impl/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/impl/bands/ColorInterpretationCellRenderer.java
1
package org.gvsig.fmap.mapcontext.raster.swing.impl.bands;
2

  
3
import java.awt.Component;
4

  
5
import javax.swing.JTable;
6
import javax.swing.table.DefaultTableCellRenderer;
7

  
8
import org.gvsig.tools.ToolsLocator;
9

  
10

  
11
/**
12
 * @author fdiaz
13
 *
14
 */
15
public class ColorInterpretationCellRenderer extends DefaultTableCellRenderer {
16

  
17
    /**
18
     *
19
     */
20
    private static final long serialVersionUID = -7247329247015852062L;
21

  
22
    @Override
23
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
24
        int row, int column) {
25

  
26
        Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
27

  
28
        String colorInterpretation = ((String) value);
29
        setText(ToolsLocator.getI18nManager().getTranslation(colorInterpretation));
30

  
31
        return cellComponent;
32
    }
33

  
34

  
35
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.impl/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/impl/bands/NoDataCellRenderer.java
1
package org.gvsig.fmap.mapcontext.raster.swing.impl.bands;
2

  
3
import java.awt.Component;
4

  
5
import javax.swing.JTable;
6
import javax.swing.table.DefaultTableCellRenderer;
7

  
8
import org.gvsig.raster.lib.buffer.api.BufferManager;
9

  
10

  
11
/**
12
 * @author fdiaz
13
 *
14
 */
15
public class NoDataCellRenderer extends DefaultTableCellRenderer {
16

  
17
    /**
18
     *
19
     */
20
    private static final long serialVersionUID = 7654022330175662292L;
21

  
22
    @Override
23
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
24
        int row, int column) {
25
        Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
26
        if(value==null){
27
            setText("");
28
        } else {
29
            Number number = (Number)value;
30
            int dataType = ((Integer) table.getValueAt(row, BandsTableModel.COLUMN_DATA_TYPE)).intValue();
31
            switch (dataType) {
32
            case BufferManager.TYPE_BYTE:
33
                setText(new Integer(number.intValue() & 0xff).toString());
34
                break;
35
            case BufferManager.TYPE_USHORT:
36
                setText(new Integer(number.intValue() & 0xffff).toString());
37
                break;
38
            default:
39
                setText(number.toString());
40
                break;
41
            }
42
        }
43
        return component;
44
    }
45

  
46
}
tags/org.gvsig.desktop-2.0.430/org.gvsig.desktop.library/org.gvsig.fmap.mapcontext.swing/org.gvsig.fmap.mapcontext.swing.impl/src/main/java/org/gvsig/fmap/mapcontext/raster/swing/impl/bands/BandsTableModel.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2017 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontext.raster.swing.impl.bands;
24

  
25
import java.util.ArrayList;
26
import java.util.Arrays;
27
import java.util.List;
28

  
29
import javax.swing.table.AbstractTableModel;
30

  
31
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
33

  
34
import org.gvsig.raster.lib.buffer.api.BufferLocator;
35
import org.gvsig.raster.lib.buffer.api.BufferManager;
36
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.dataTypes.CoercionException;
39
import org.gvsig.tools.dispose.DisposeUtils;
40
import org.gvsig.tools.i18n.I18nManager;
41
import org.gvsig.tools.locator.LocatorException;
42

  
43

  
44

  
45
/**
46
 * @author fdiaz
47
 *
48
 */
49
public class BandsTableModel extends AbstractTableModel {
50

  
51
    /**
52
     *
53
     */
54
    private static final long serialVersionUID = 5993288441174158255L;
55
    private static final Logger LOG = LoggerFactory.getLogger(BandsTableModel.class);
56

  
57

  
58
    List<RasterStoreBand> rasterStoreBands;
59

  
60
    public static final List<String> RGBColorSpace = Arrays.asList(ColorInterpretation.RED_BAND, ColorInterpretation.GREEN_BAND, ColorInterpretation.BLUE_BAND, ColorInterpretation.ALPHA_BAND);
61
    public static final List<String> CMYKColorSpace = Arrays.asList(ColorInterpretation.CYAN_BAND, ColorInterpretation.MAGENTA_BAND, ColorInterpretation.YELLOW_BAND, ColorInterpretation.BLACK_BAND, ColorInterpretation.ALPHA_BAND);
62
    public static final List<String> HSLColorSpace = Arrays.asList(ColorInterpretation.HUE_BAND, ColorInterpretation.SATURATION_BAND, ColorInterpretation.LIGHTNESS_BAND, ColorInterpretation.ALPHA_BAND);
63
    public static final List<String> YCBCRColorSpace = Arrays.asList(ColorInterpretation.YCBCR_CB_BAND, ColorInterpretation.YCBCR_CR_BAND, ColorInterpretation.YCBCR_Y_BAND, ColorInterpretation.ALPHA_BAND);
64
    public static final List<List<String>> ColorSpaces = Arrays.asList(RGBColorSpace, CMYKColorSpace, HSLColorSpace, YCBCRColorSpace);
65
    public static final List<String> ColorSpaceNames = Arrays.asList(ColorInterpretation.RGB, ColorInterpretation.CMYK, ColorInterpretation.HSL, ColorInterpretation.YCBCR);
66

  
67
    public static final int COLUMN_COLOR = 0;
68
    public static final int COLUMN_NODATA = 1;
69
    public static final int COLUMN_DATA_TYPE = 2;
70
    public static final int COLUMN_STORE_NAME = 3;
71
    public static final int COLUMN_BAND = 4;
72
    public static final int COLUMN_BAND_NAME = 5;
73
    public static final int COLUMN_STORE_FULL_NAME = 6;
74

  
75

  
76
    /**
77
     *
78
     */
79
    public BandsTableModel() {
80
        rasterStoreBands = new ArrayList<RasterStoreBand>();
81
    }
82

  
83
    @Override
84
    public int getRowCount() {
85
        return rasterStoreBands.size();
86
    }
87

  
88
    @Override
89
    public int getColumnCount() {
90
        return 7;
91
    }
92

  
93
    @Override
94
    public Object getValueAt(int rowIndex, int columnIndex) {
95
        RasterStoreBand rasterStoreBand = rasterStoreBands.get(rowIndex);
96
        switch (columnIndex) {
97
        case COLUMN_COLOR:
98
            return rasterStoreBand.getBandColorInterpretation();
99
        case COLUMN_NODATA:
100
            return rasterStoreBand.getNoDataNumber();
101
        case COLUMN_DATA_TYPE:
102
            return rasterStoreBand.getDataType();
103
        case COLUMN_STORE_NAME:
104
            return rasterStoreBand.getStore().getName();
105
        case COLUMN_BAND:
106
            return rasterStoreBand.getBand();
107
        case COLUMN_BAND_NAME:
108
            return rasterStoreBand.getBandName();
109
        case COLUMN_STORE_FULL_NAME:
110
            return rasterStoreBand.getStore().getFullName();
111
        }
112
        return null;
113
    }
114

  
115
    @Override
116
    public String getColumnName(int column) {
117
        I18nManager i18nManager = ToolsLocator.getI18nManager();
118
        switch (column) {
119
        case COLUMN_COLOR:
120
            return i18nManager.getTranslation("_color");
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff