source: osm/applications/editors/josm/plugins/smed2/src/panels/PanelMain.java@ 30006

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

save

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