svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.raster.tools / org.gvsig.raster.tools.swing / org.gvsig.raster.tools.swing.impl / src / main / java / org / gvsig / raster / tools / swing / impl / converttype / ConvertTypePanelController.java @ 43876
History | View | Annotate | Download (5.83 KB)
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.raster.tools.swing.impl.converttype; |
24 |
|
25 |
import java.util.Locale; |
26 |
|
27 |
import javax.swing.DefaultComboBoxModel; |
28 |
import javax.swing.JComponent; |
29 |
import javax.swing.JOptionPane; |
30 |
|
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
import org.gvsig.fmap.dal.exception.DataException; |
35 |
import org.gvsig.fmap.dal.raster.RasterStore; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.raster.api.RasterLayer; |
38 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
39 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
40 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
41 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
42 |
import org.gvsig.raster.swing.buffer.save.SaveBufferDialog; |
43 |
import org.gvsig.raster.tools.lib.api.exceptions.RasterToolCreatingPanelException; |
44 |
import org.gvsig.raster.tools.swing.api.converttype.ConvertTypePanel; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.i18n.I18nManager; |
47 |
import org.gvsig.tools.locator.LocatorException; |
48 |
|
49 |
/**
|
50 |
* @author fdiaz
|
51 |
*/
|
52 |
public class ConvertTypePanelController extends ConvertTypePanelView implements ConvertTypePanel { |
53 |
|
54 |
/**
|
55 |
*
|
56 |
*/
|
57 |
private static final long serialVersionUID = -6375247704720616896L; |
58 |
|
59 |
private static final Logger logger = LoggerFactory.getLogger(ConvertTypePanelController.class); |
60 |
|
61 |
private RasterLayer layer;
|
62 |
|
63 |
/**
|
64 |
* @throws RasterToolCreatingPanelException
|
65 |
*/
|
66 |
public ConvertTypePanelController() throws RasterToolCreatingPanelException { |
67 |
translate(); |
68 |
initializeComponents(); |
69 |
} |
70 |
|
71 |
public void set(FLayer layer) throws RasterToolCreatingPanelException{ |
72 |
this.layer = (RasterLayer) layer;
|
73 |
} |
74 |
|
75 |
|
76 |
@Override
|
77 |
public JComponent asJComponent() { |
78 |
return this; |
79 |
} |
80 |
|
81 |
private void initializeComponents() { |
82 |
|
83 |
cmbType.setModel(new DefaultComboBoxModel(BufferType.values())); |
84 |
|
85 |
cmbType.setSelectedIndex(0);
|
86 |
cmbType.setEditable(false);
|
87 |
|
88 |
} |
89 |
|
90 |
private void translate() { |
91 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
92 |
|
93 |
lblType.setText(i18nManager.getTranslation(lblType.getText())); |
94 |
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* @param locale
|
99 |
*
|
100 |
*/
|
101 |
public void setLocate(Locale locale) { |
102 |
Locale l = super.getLocale(); |
103 |
if (!l.equals(locale)) {
|
104 |
translate(); |
105 |
} |
106 |
super.setLocale(locale);
|
107 |
} |
108 |
|
109 |
|
110 |
@Override
|
111 |
public void fetch(SaveBufferDialog saveBufferDialog) { |
112 |
|
113 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
114 |
// TODO:
|
115 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
116 |
|
117 |
final RasterStore store = layer.getRasterStore();
|
118 |
Buffer buffer;
|
119 |
try {
|
120 |
buffer = store.getRasterSet(); |
121 |
} catch (DataException e) {
|
122 |
logger.error("Error creating raster store's buffer", e);
|
123 |
JOptionPane.showMessageDialog(
|
124 |
null,
|
125 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_buffer")).append(":") |
126 |
.append(e.getLocalizedMessage()), i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
127 |
return;
|
128 |
} |
129 |
if (buffer != null) { |
130 |
|
131 |
Buffer convertedBuffer = null; |
132 |
int type = ((BufferType) cmbType.getSelectedItem()).getType();
|
133 |
if(type < buffer.getBandTypes()[0]){ |
134 |
int answer = JOptionPane.showConfirmDialog( |
135 |
null,
|
136 |
i18nManager.getTranslation("the_destination_buffer_will_lose_data_relative_to_the_source_buffer_the_source_buffer_will_not_be_modified_do_you_wish_to_continue"),
|
137 |
i18nManager.getTranslation("question"), JOptionPane.YES_NO_OPTION); |
138 |
if(answer!=JOptionPane.YES_OPTION){ |
139 |
return;
|
140 |
} |
141 |
} |
142 |
try {
|
143 |
convertedBuffer = bufferManager.createConvertedTypeBuffer(buffer, type); |
144 |
} catch (LocatorException | BufferException e1) {
|
145 |
logger.warn("Can't create converted type buffer.", e1);
|
146 |
return;
|
147 |
} |
148 |
saveBufferDialog.setBuffer(convertedBuffer); |
149 |
} |
150 |
} |
151 |
|
152 |
enum BufferType {
|
153 |
|
154 |
TYPE_BYTE(BufferManager.TYPE_BYTE, "byte"),
|
155 |
// TYPE_USHORT(BufferManager.TYPE_USHORT, "ushort"),
|
156 |
TYPE_SHORT(BufferManager.TYPE_SHORT, "short"),
|
157 |
TYPE_INT(BufferManager.TYPE_INT, "int"),
|
158 |
TYPE_FLOAT(BufferManager.TYPE_FLOAT, "float"),
|
159 |
TYPE_DOUBLE(BufferManager.TYPE_DOUBLE, "double");
|
160 |
|
161 |
private int type; |
162 |
|
163 |
private String displayName; |
164 |
|
165 |
private BufferType(int code, String name) { |
166 |
this.type = code;
|
167 |
this.displayName = name;
|
168 |
} |
169 |
|
170 |
public int getType() { |
171 |
return this.type; |
172 |
} |
173 |
|
174 |
public String getDisplayName() { |
175 |
return this.displayName; |
176 |
} |
177 |
|
178 |
@Override
|
179 |
public String toString() { |
180 |
return this.displayName; |
181 |
} |
182 |
|
183 |
} |
184 |
|
185 |
} |