source: osm/applications/editors/josm/plugins/smed2/src/s57/S57dat.java@ 29215

Last change on this file since 29215 was 29215, checked in by malcolmh, 12 years ago

save

File size: 5.7 KB
Line 
1package s57;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.Dimension;
6import java.awt.event.ActionListener;
7import java.io.File;
8import java.io.FileInputStream;
9import java.io.FileOutputStream;
10import java.io.IOException;
11
12import javax.swing.*;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.gui.layer.OsmDataLayer;
16import org.openstreetmap.josm.data.osm.DataSet;
17
18import panels.PanelMain;
19
20import smed2.Smed2Action;
21
22import s57.S57obj;
23import s57.S57att;
24import s57.S57val;
25
26public class S57dat extends JPanel {
27
28 private enum S57field { DSID, DSSI, DSPM, DSPR, DSRC, DSHT, DSAC, CATD, CATX, DDDF, DDDR, DDDI, DDOM, DDRF, DDSI, DDSC,
29 FRID, FOID, ATTF, NATF, FFPC, FFPT, FSPC, FSPT, VRID, ATTV, VRPC, VRPT, SGCC, SG2D, SG3D, ARCC, AR2D, EL2D, CT2D }
30 private enum S57dsid { RCNM, RCID, EXPP, INTU, DSNM, EDTN, UPDN, UADT, ISDT, STED, PRSP, PSDN, PRED, PROF, AGEN, COMT }
31 private enum S57dssi { DSTR, AALL, NALL, NOMR, NOCR, NOGR, NOLR, NOIN, NOCN, NOED, NOFA }
32 private enum S57dspm { RCNM, RCID, HDAT, VDAT, SDAT, CSCL, DUNO, HUNI, PUNI, COUN, COMF, SOMF, COMT }
33 private enum S57dspr { PROJ, PRP1, PRP2, PRP3, PRP4, FEAS, FNOR, FPMF, COMT }
34 private enum S57dsrc { RPID, RYCO, RXCO, CURP, FPMF, RXVL, RYVL, COMT }
35 private enum S57dsht { RCNM, RCID, PRCO, ESDT, LSDT, DCRT, CODT, COMT }
36 private enum S57dsac { RCNM, RCID, PACC, HACC, SACC, FPMF, COMT }
37 private enum S57catd { RCNM, RCID, FILE, LFIL, VOLM, IMPL, SLAT, WLON, NLAT, ELON, CRCS, COMT }
38 private enum S57catx { RCNM, RCID, NAM1, NAM2, COMT }
39 private enum S57dddf { RCNM, RCID, OORA, OAAC, OACO, OALL, OATY, DEFN, AUTH, COMT }
40 private enum S57dddr { RFTP, RFVL }
41 private enum S57dddi { RCNM, RCID, ATLB, ATDO, ADMU, ADFT, AUTH, COMT }
42 private enum S57ddom { RAVA, DVAL, DVSD, DEFN, AUTH }
43 private enum S57ddrf { RFTP, RFVL }
44 private enum S57ddsi { RCNM, RCID, OBLB }
45 private enum S57ddsc { ATLB, ASET, AUTH }
46 private enum S57frid { RCNM, RCID, PRIM, GRUP, OBJL, RVER, RUIN }
47 private enum S57foid { AGEN, FIDN, FIDS }
48 private enum S57attf { ATTL, ATVL }
49 private enum S57natf { ATTL, ATVL }
50 private enum S57ffpc { FFUI, FFIX, NFPT }
51 private enum S57ffpt { LNAM, RIND, COMT }
52 private enum S57fspc { FSUI, FSIX, NSPT }
53 private enum S57fspt { NAME, ORNT, USAG, MASK }
54 private enum S57vrid { RCNM, RCID, RVER, RUIN }
55 private enum S57attv { ATTL, ATVL }
56 private enum S57vrpc { VPUI, VPIX, NVPT }
57 private enum S57vrpt { NAME, ORNT, USAG, TOPI, MASK }
58 private enum S57sgcc { CCUI, CCIX, CCNC }
59 private enum S57sg2d { YCOO, XCOO }
60 private enum S57sg3d { YCOO, XCOO, VE3D }
61 private enum S57arcc { ATYP, SURF, ORDR, RESO, FPMF }
62 private enum S57ar2d { STPT, CTPT, ENPT, YCOO, XCOO }
63 private enum S57el2d { STPT, CTPT, ENPT, CDPM, CDPR, YCOO, XCOO }
64 private enum S57ct2d { YCOO, XCOO }
65
66 private File importFile;
67 private FileInputStream inp;
68 private File exportFile;
69 private FileOutputStream outp;
70 private OsmDataLayer layer;
71 private DataSet data;
72
73 private JButton importButton;
74 private ActionListener alImport = new ActionListener() {
75 public void actionPerformed(java.awt.event.ActionEvent e) {
76 if (e.getSource() == importButton) {
77 readFile();
78 Smed2Action.panelS57.setVisible(true);
79 Smed2Action.panelMain.setVisible(false);
80 PanelMain.messageBar.setText("File imported");
81 }
82 }
83 };
84 private JButton exportButton;
85 private ActionListener alExport = new ActionListener() {
86 public void actionPerformed(java.awt.event.ActionEvent e) {
87 if (e.getSource() == exportButton) {
88 writeFile();
89 Smed2Action.panelS57.setVisible(true);
90 Smed2Action.panelMain.setVisible(false);
91 PanelMain.messageBar.setText("File exported");
92 }
93 }
94 };
95 private JButton cancelButton;
96 private ActionListener alCancel = new ActionListener() {
97 public void actionPerformed(java.awt.event.ActionEvent e) {
98 if (e.getSource() == cancelButton) {
99 try {
100 inp.close();
101 } catch (IOException e1) {}
102 Smed2Action.panelS57.setVisible(false);
103 Smed2Action.panelMain.setVisible(true);
104 PanelMain.messageBar.setText("Operation cancelled");
105 }
106 }
107 };
108
109 public S57dat() {
110
111 setLayout(null);
112 setSize(new Dimension(480, 480));
113 cancelButton = new JButton();
114 cancelButton.setBounds(250, 430, 100, 20);
115 cancelButton.setText(tr("Cancel"));
116 cancelButton.addActionListener(alCancel);
117 add(cancelButton);
118 importButton = new JButton();
119 importButton.setBounds(370, 430, 100, 20);
120 importButton.setText(tr("Import"));
121 importButton.addActionListener(alImport);
122 add(importButton);
123 exportButton = new JButton();
124 exportButton.setBounds(370, 430, 100, 20);
125 exportButton.setText(tr("Export"));
126 exportButton.addActionListener(alExport);
127 add(exportButton);
128 }
129
130 public void startImport(File file) {
131 importFile = file;
132 try {
133 inp = new FileInputStream(file);
134 } catch (IOException e) {
135 PanelMain.messageBar.setText("Failed to open file");
136 return;
137 }
138 Smed2Action.panelMain.setVisible(false);
139 Smed2Action.panelS57.setVisible(true);
140 }
141
142 public void startExport(File file) {
143 exportFile = file;
144 try {
145 outp = new FileOutputStream(file);
146 } catch (IOException e) {
147 PanelMain.messageBar.setText("Failed to open file");
148 return;
149 }
150 Smed2Action.panelMain.setVisible(false);
151 Smed2Action.panelS57.setVisible(true);
152 }
153
154 private void writeFile() {
155 }
156
157 private void readFile() {
158 // Read & convert file.
159 // read record at a time
160 // read leader
161 // if DDR, build conversion tables
162 // if DR, build data structures
163 // Extract list of features & present on chooser panel
164 }
165
166 private void importData() {
167 data = new DataSet();
168 // Transfer selected features
169 layer = new OsmDataLayer(data, importFile.getName(), null);
170 layer.setUploadDiscouraged(true);
171 Main.main.addLayer(layer);
172
173 }
174}
Note: See TracBrowser for help on using the repository browser.