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