1 | package panels;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.Color;
|
---|
6 | import java.awt.Dimension;
|
---|
7 | import java.awt.Rectangle;
|
---|
8 | import java.awt.event.ActionListener;
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.Iterator;
|
---|
11 |
|
---|
12 | import javax.swing.*;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.Main;
|
---|
15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
16 |
|
---|
17 | import s57.S57att.Att;
|
---|
18 | import s57.S57obj.Obj;
|
---|
19 | import s57.S57val;
|
---|
20 | import seamap.SeaMap;
|
---|
21 | import seamap.SeaMap.*;
|
---|
22 | import smed2.S57en;
|
---|
23 | import smed2.Smed2Action;
|
---|
24 |
|
---|
25 | public class PanelMain extends JPanel {
|
---|
26 |
|
---|
27 | public static JTextArea decode = null;
|
---|
28 | public static JTextField messageBar = null;
|
---|
29 | public JButton saveButton = null;
|
---|
30 | private ActionListener alSave = new ActionListener() {
|
---|
31 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
32 | }
|
---|
33 | };
|
---|
34 | private JButton importButton = null;
|
---|
35 | final JFileChooser ifc = new JFileChooser();
|
---|
36 | private ActionListener alImport = new ActionListener() {
|
---|
37 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
38 | if (e.getSource() == importButton) {
|
---|
39 | messageBar.setText("Select file");
|
---|
40 | int returnVal = ifc.showOpenDialog(Main.parent);
|
---|
41 | if (returnVal == JFileChooser.APPROVE_OPTION) {
|
---|
42 | Smed2Action.panelS57.startImport(ifc.getSelectedFile());
|
---|
43 | } else {
|
---|
44 | messageBar.setText("");
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 | };
|
---|
49 |
|
---|
50 | private JButton exportButton = null;
|
---|
51 | final JFileChooser efc = new JFileChooser();
|
---|
52 | private ActionListener alExport = new ActionListener() {
|
---|
53 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
54 | if (e.getSource() == exportButton) {
|
---|
55 | messageBar.setText("Select file");
|
---|
56 | int returnVal = efc.showOpenDialog(Main.parent);
|
---|
57 | if (returnVal == JFileChooser.APPROVE_OPTION) {
|
---|
58 | Smed2Action.panelS57.startExport(efc.getSelectedFile());
|
---|
59 | } else {
|
---|
60 | messageBar.setText("");
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | };
|
---|
65 |
|
---|
66 | public PanelMain() {
|
---|
67 |
|
---|
68 | setLayout(null);
|
---|
69 | setSize(new Dimension(480, 480));
|
---|
70 |
|
---|
71 | messageBar = new JTextField();
|
---|
72 | messageBar.setBounds(70, 430, 290, 20);
|
---|
73 | messageBar.setEditable(false);
|
---|
74 | messageBar.setBackground(Color.WHITE);
|
---|
75 | add(messageBar);
|
---|
76 | importButton = new JButton(new ImageIcon(getClass().getResource("/images/importButton.png")));
|
---|
77 | importButton.setBounds(10, 430, 20, 20);
|
---|
78 | add(importButton);
|
---|
79 | importButton.addActionListener(alImport);
|
---|
80 | exportButton = new JButton(new ImageIcon(getClass().getResource("/images/exportButton.png")));
|
---|
81 | exportButton.setBounds(40, 430, 20, 20);
|
---|
82 | add(exportButton);
|
---|
83 | exportButton.addActionListener(alExport);
|
---|
84 | saveButton = new JButton();
|
---|
85 | saveButton.setBounds(370, 430, 100, 20);
|
---|
86 | saveButton.setText(tr("Save"));
|
---|
87 | add(saveButton);
|
---|
88 | saveButton.addActionListener(alSave);
|
---|
89 |
|
---|
90 | decode = new JTextArea();
|
---|
91 | decode.setBounds(0, 0, 480, 420);
|
---|
92 | decode.setTabSize(1);
|
---|
93 | add(decode);
|
---|
94 | }
|
---|
95 |
|
---|
96 | public void parseMark(Feature feature) {
|
---|
97 | decode.setText("Selected feature:\n");
|
---|
98 | decode.append("\tType: " + S57en.ObjEN.get(feature.type) + "\n");
|
---|
99 | if (feature.atts.get(Att.OBJNAM) != null) {
|
---|
100 | decode.append("\tName: " + feature.atts.get(Att.OBJNAM).val + "\n");
|
---|
101 | }
|
---|
102 | decode.append("\tObjects:\n");
|
---|
103 | for (Obj obj : feature.objs.keySet()) {
|
---|
104 | decode.append("\t\t" + S57en.ObjEN.get(obj) + "\n");
|
---|
105 | if (feature.objs.get(obj).size() != 0) {
|
---|
106 | for (AttMap atts : feature.objs.get(obj).values()) {
|
---|
107 | for (Att att : atts.keySet()) {
|
---|
108 | AttItem item = atts.get(att);
|
---|
109 | switch (item.conv) {
|
---|
110 | case E:
|
---|
111 | decode.append("\t\t\t" + S57en.AttEN.get(att) + ": " + S57en.enums.get(att).get(item.val) + "\n");
|
---|
112 | break;
|
---|
113 | case L:
|
---|
114 | decode.append("\t\t\t" + S57en.AttEN.get(att) + ": ");
|
---|
115 | Iterator it = ((ArrayList)item.val).iterator();
|
---|
116 | while (it.hasNext()) {
|
---|
117 | Object val = it.next();
|
---|
118 | decode.append((String)S57en.enums.get(att).get(val));
|
---|
119 | if (it.hasNext()) {
|
---|
120 | decode.append(", ");
|
---|
121 | }
|
---|
122 | }
|
---|
123 | decode.append("\n");
|
---|
124 | break;
|
---|
125 | default:
|
---|
126 | decode.append("\t\t\t" + S57en.AttEN.get(att) + ": " + item.val + "\n");
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | private JRadioButton getButton(JRadioButton button, int x, int y, int w, int h, String title) {
|
---|
135 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
136 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
137 | button.setText(title);
|
---|
138 | return button;
|
---|
139 | }
|
---|
140 |
|
---|
141 | }
|
---|