svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.dbf / src / main / java / org / gvsig / exportto / swing / prov / dbf / panel / EncodingPanel.java @ 43920
History | View | Annotate | Download (4.05 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 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 3
|
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 |
package org.gvsig.exportto.swing.prov.dbf.panel; |
25 |
|
26 |
import javax.swing.DefaultListModel; |
27 |
import javax.swing.JComponent; |
28 |
|
29 |
import org.gvsig.exportto.swing.prov.dbf.ExportDBFOptions; |
30 |
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
31 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
32 |
import org.gvsig.fmap.dal.DataStoreParameters; |
33 |
|
34 |
import org.gvsig.metadata.MetadataLocator; |
35 |
import org.gvsig.metadata.MetadataManager; |
36 |
import org.gvsig.tools.ToolsLocator; |
37 |
import org.gvsig.tools.dynobject.DynField; |
38 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
39 |
import org.gvsig.tools.dynobject.DynStruct; |
40 |
import org.gvsig.tools.i18n.I18nManager; |
41 |
import org.gvsig.tools.swing.api.ListElement; |
42 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
43 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
44 |
|
45 |
/**
|
46 |
* @author gvSIG Team
|
47 |
* @version $Id$
|
48 |
*
|
49 |
*/
|
50 |
public class EncodingPanel |
51 |
extends EncodingPanelView
|
52 |
implements ExporttoSwingProviderPanel
|
53 |
{ |
54 |
|
55 |
private final ExportDBFOptions options; |
56 |
|
57 |
|
58 |
public EncodingPanel(ExportDBFOptions options) {
|
59 |
super();
|
60 |
this.options = options;
|
61 |
initComponents(); |
62 |
} |
63 |
|
64 |
private void initComponents() { |
65 |
MetadataManager metadataManager = MetadataLocator.getMetadataManager(); |
66 |
DynStruct dynStruct = metadataManager.getDefinition("DBF");
|
67 |
DynField dynField = dynStruct.getDynField("Encoding");
|
68 |
|
69 |
DefaultListModel model = new DefaultListModel(); |
70 |
DynObjectValueItem[] encodings = dynField.getAvailableValues();
|
71 |
for (DynObjectValueItem encoding : encodings) {
|
72 |
model.addElement(new ListElement(encoding.getLabel(),encoding.getValue()));
|
73 |
} |
74 |
this.lstEncoding.setModel(model);
|
75 |
this.lstEncoding.setSelectedIndex(0); |
76 |
|
77 |
String sourceProviderName = this.options.getSourceFeatureStore().getProviderName(); |
78 |
if( sourceProviderName.equalsIgnoreCase("Shape") || sourceProviderName.equalsIgnoreCase("DBF") ) { |
79 |
DataStoreParameters params = this.options.getSourceFeatureStore().getParameters();
|
80 |
String encoding = (String) params.getDynValue("Encoding"); |
81 |
ListElement.setSelected(this.lstEncoding, encoding);
|
82 |
} |
83 |
this.translate();
|
84 |
} |
85 |
|
86 |
private void translate() { |
87 |
ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager(); |
88 |
i18nc.translate(this.lblEncoding);
|
89 |
} |
90 |
|
91 |
public String getEncoding() { |
92 |
ListElement encoding = (ListElement) this.lstEncoding.getSelectedValue();
|
93 |
if( encoding==null ) { |
94 |
return null; |
95 |
} |
96 |
return (String) encoding.getValue(); |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public String getPanelTitle() { |
101 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
102 |
return i18nManager.getTranslation("_Select_encoding"); |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public boolean isValidPanel() throws ExporttoPanelValidationException { |
107 |
this.options.setEncoding(this.getEncoding()); |
108 |
return true; |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public void enterPanel() { |
113 |
// Do nothing
|
114 |
} |
115 |
|
116 |
@Override
|
117 |
public JComponent asJComponent() { |
118 |
return this; |
119 |
} |
120 |
} |