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 / export / dbf / swing / panels / EncodingPanel.java @ 43925
History | View | Annotate | Download (4.42 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.export.dbf.swing.panels; |
25 |
|
26 |
import javax.swing.DefaultListModel; |
27 |
import javax.swing.JComponent; |
28 |
|
29 |
import org.gvsig.fmap.dal.DataStoreParameters; |
30 |
|
31 |
import org.gvsig.metadata.MetadataLocator; |
32 |
import org.gvsig.metadata.MetadataManager; |
33 |
import org.gvsig.tools.ToolsLocator; |
34 |
import org.gvsig.tools.dynobject.DynField; |
35 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
36 |
import org.gvsig.tools.dynobject.DynStruct; |
37 |
import org.gvsig.tools.i18n.I18nManager; |
38 |
import org.gvsig.tools.swing.api.ListElement; |
39 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
40 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
41 |
import org.gvsig.export.dbf.service.ExportDBFParameters; |
42 |
import org.gvsig.export.ExportParameters; |
43 |
import org.gvsig.export.swing.JExportProcessPanel; |
44 |
import org.gvsig.export.swing.spi.ExportPanel; |
45 |
import org.gvsig.export.swing.spi.ExportPanelValidationException; |
46 |
|
47 |
/**
|
48 |
* @author gvSIG Team
|
49 |
* @version $Id$
|
50 |
*
|
51 |
*/
|
52 |
public class EncodingPanel |
53 |
extends EncodingPanelView
|
54 |
implements ExportPanel
|
55 |
{ |
56 |
|
57 |
private final ExportDBFParameters parameters; |
58 |
private final JExportProcessPanel processPanel; |
59 |
|
60 |
public EncodingPanel(JExportProcessPanel processPanel, ExportParameters parameters) {
|
61 |
super();
|
62 |
this.processPanel = processPanel;
|
63 |
this.parameters = (ExportDBFParameters) parameters;
|
64 |
this.initComponents();
|
65 |
} |
66 |
|
67 |
private void initComponents() { |
68 |
MetadataManager metadataManager = MetadataLocator.getMetadataManager(); |
69 |
DynStruct dynStruct = metadataManager.getDefinition("DBF");
|
70 |
DynField dynField = dynStruct.getDynField("Encoding");
|
71 |
|
72 |
DefaultListModel model = new DefaultListModel(); |
73 |
DynObjectValueItem[] encodings = dynField.getAvailableValues();
|
74 |
for (DynObjectValueItem encoding : encodings) {
|
75 |
model.addElement(new ListElement(encoding.getLabel(),encoding.getValue()));
|
76 |
} |
77 |
this.lstEncoding.setModel(model);
|
78 |
this.lstEncoding.setSelectedIndex(0); |
79 |
|
80 |
String sourceProviderName = this.parameters.getSourceFeatureStore().getProviderName(); |
81 |
if( sourceProviderName.equalsIgnoreCase("Shape") || sourceProviderName.equalsIgnoreCase("DBF") ) { |
82 |
DataStoreParameters params = this.parameters.getSourceFeatureStore().getParameters();
|
83 |
String encoding = (String) params.getDynValue("Encoding"); |
84 |
ListElement.setSelected(this.lstEncoding, encoding);
|
85 |
} |
86 |
this.translate();
|
87 |
} |
88 |
|
89 |
private void translate() { |
90 |
ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager(); |
91 |
i18nc.translate(this.lblEncoding);
|
92 |
} |
93 |
|
94 |
public String getEncoding() { |
95 |
ListElement encoding = (ListElement) this.lstEncoding.getSelectedValue();
|
96 |
if( encoding==null ) { |
97 |
return null; |
98 |
} |
99 |
return (String) encoding.getValue(); |
100 |
} |
101 |
|
102 |
@Override
|
103 |
public JComponent asJComponent() { |
104 |
return this; |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public String getIdPanel() { |
109 |
return this.getClass().getSimpleName(); |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public String getTitlePanel() { |
114 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
115 |
return i18nManager.getTranslation("_Select_encoding"); |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public boolean validatePanel() throws ExportPanelValidationException { |
120 |
return true; |
121 |
} |
122 |
|
123 |
@Override
|
124 |
public void enterPanel() { |
125 |
// Do nothing
|
126 |
} |
127 |
|
128 |
@Override
|
129 |
public void exitPanel() { |
130 |
this.parameters.setEncoding(this.getEncoding()); |
131 |
} |
132 |
} |