[28648] | 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;
|
---|
[29995] | 9 | import java.util.ArrayList;
|
---|
| 10 | import java.util.Iterator;
|
---|
[28648] | 11 |
|
---|
| 12 | import javax.swing.*;
|
---|
| 13 |
|
---|
[29996] | 14 | import messages.Messages;
|
---|
| 15 |
|
---|
[28722] | 16 | import org.openstreetmap.josm.Main;
|
---|
| 17 |
|
---|
[29995] | 18 | import s57.S57att.Att;
|
---|
| 19 | import s57.S57obj.Obj;
|
---|
| 20 | import seamap.SeaMap.*;
|
---|
| 21 | import smed2.S57en;
|
---|
[28938] | 22 | import smed2.Smed2Action;
|
---|
| 23 |
|
---|
[28648] | 24 | public class PanelMain extends JPanel {
|
---|
| 25 |
|
---|
[29995] | 26 | public static JTextArea decode = null;
|
---|
[28648] | 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 | };
|
---|
[29215] | 33 | private JButton importButton = null;
|
---|
| 34 | final JFileChooser ifc = new JFileChooser();
|
---|
| 35 | private ActionListener alImport = new ActionListener() {
|
---|
[28722] | 36 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
[29215] | 37 | if (e.getSource() == importButton) {
|
---|
[28938] | 38 | messageBar.setText("Select file");
|
---|
[29215] | 39 | int returnVal = ifc.showOpenDialog(Main.parent);
|
---|
[28722] | 40 | if (returnVal == JFileChooser.APPROVE_OPTION) {
|
---|
[29215] | 41 | Smed2Action.panelS57.startImport(ifc.getSelectedFile());
|
---|
[28938] | 42 | } else {
|
---|
| 43 | messageBar.setText("");
|
---|
| 44 | }
|
---|
[28722] | 45 | }
|
---|
| 46 | }
|
---|
| 47 | };
|
---|
[28648] | 48 |
|
---|
[29215] | 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 |
|
---|
[28648] | 65 | public PanelMain() {
|
---|
| 66 |
|
---|
| 67 | setLayout(null);
|
---|
| 68 | setSize(new Dimension(480, 480));
|
---|
| 69 |
|
---|
| 70 | messageBar = new JTextField();
|
---|
[29215] | 71 | messageBar.setBounds(70, 430, 290, 20);
|
---|
[28648] | 72 | messageBar.setEditable(false);
|
---|
| 73 | messageBar.setBackground(Color.WHITE);
|
---|
| 74 | add(messageBar);
|
---|
[29215] | 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);
|
---|
[28648] | 83 | saveButton = new JButton();
|
---|
[28938] | 84 | saveButton.setBounds(370, 430, 100, 20);
|
---|
[28648] | 85 | saveButton.setText(tr("Save"));
|
---|
| 86 | add(saveButton);
|
---|
| 87 | saveButton.addActionListener(alSave);
|
---|
| 88 |
|
---|
[29995] | 89 | decode = new JTextArea();
|
---|
| 90 | decode.setBounds(0, 0, 480, 420);
|
---|
| 91 | decode.setTabSize(1);
|
---|
| 92 | add(decode);
|
---|
[28648] | 93 | }
|
---|
[29881] | 94 |
|
---|
[29995] | 95 | public void parseMark(Feature feature) {
|
---|
| 96 | decode.setText("Selected feature:\n");
|
---|
[29996] | 97 | decode.append("\t" + tr("Type") + ": " + Messages.getString(feature.type.name()) + "\n");
|
---|
[29995] | 98 | if (feature.atts.get(Att.OBJNAM) != null) {
|
---|
[29996] | 99 | decode.append("\t" + tr("Name") + ": " + feature.atts.get(Att.OBJNAM).val + "\n");
|
---|
[29995] | 100 | }
|
---|
| 101 | decode.append("\tObjects:\n");
|
---|
| 102 | for (Obj obj : feature.objs.keySet()) {
|
---|
[29996] | 103 | decode.append("\t\t" + Messages.getString(obj.name()) + "\n");
|
---|
[29995] | 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:
|
---|
[29996] | 110 | decode.append("\t\t\t" + Messages.getString(att.name()) + ": " + S57en.enums.get(att).get(item.val) + "\n");
|
---|
[29995] | 111 | break;
|
---|
| 112 | case L:
|
---|
[29996] | 113 | decode.append("\t\t\t" + Messages.getString(att.name()) + ": ");
|
---|
[29995] | 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:
|
---|
[29996] | 125 | decode.append("\t\t\t" + Messages.getString(att.name()) + ": " + item.val + "\n");
|
---|
[29995] | 126 | }
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[29996] | 133 | public void clearMark() {
|
---|
| 134 | decode.setText(tr("No feature selected"));
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[29881] | 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 |
|
---|
[28648] | 144 | }
|
---|