| 1 | /* Copyright 2014 Malcolm Herring
|
|---|
| 2 | *
|
|---|
| 3 | * This is free software: you can redistribute it and/or modify
|
|---|
| 4 | * it under the terms of the GNU General Public License as published by
|
|---|
| 5 | * the Free Software Foundation, version 3 of the License.
|
|---|
| 6 | *
|
|---|
| 7 | * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | package panels;
|
|---|
| 11 |
|
|---|
| 12 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 13 |
|
|---|
| 14 | import java.awt.Color;
|
|---|
| 15 | import java.awt.Dimension;
|
|---|
| 16 | import java.awt.Graphics;
|
|---|
| 17 | import java.awt.Graphics2D;
|
|---|
| 18 | import java.awt.event.ActionListener;
|
|---|
| 19 | import java.awt.image.BufferedImage;
|
|---|
| 20 | import java.io.IOException;
|
|---|
| 21 | import java.util.ArrayList;
|
|---|
| 22 |
|
|---|
| 23 | import javax.swing.ImageIcon;
|
|---|
| 24 | import javax.swing.JButton;
|
|---|
| 25 | import javax.swing.JFileChooser;
|
|---|
| 26 | import javax.swing.JPanel;
|
|---|
| 27 | import javax.swing.JTextArea;
|
|---|
| 28 | import javax.swing.JTextField;
|
|---|
| 29 |
|
|---|
| 30 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 31 | import org.openstreetmap.josm.spi.preferences.Config;
|
|---|
| 32 |
|
|---|
| 33 | import messages.Messages;
|
|---|
| 34 | import s57.S57att.Att;
|
|---|
| 35 | import s57.S57map.AttMap;
|
|---|
| 36 | import s57.S57map.Feature;
|
|---|
| 37 | import s57.S57obj.Obj;
|
|---|
| 38 | import s57.S57val.AttVal;
|
|---|
| 39 | import scedit.SCeditAction;
|
|---|
| 40 |
|
|---|
| 41 | public class PanelMain extends JPanel {
|
|---|
| 42 |
|
|---|
| 43 | BufferedImage img;
|
|---|
| 44 | int w, h, z, f;
|
|---|
| 45 | JTextField wt, ht, zt, ft;
|
|---|
| 46 | public static JTextArea decode = null;
|
|---|
| 47 | public static JTextField messageBar = null;
|
|---|
| 48 | public JButton saveButton = null;
|
|---|
| 49 | private ActionListener alSave = new ActionListener() {
|
|---|
| 50 | @Override
|
|---|
| 51 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 52 | }
|
|---|
| 53 | };
|
|---|
| 54 | private JButton importButton = null;
|
|---|
| 55 | JFileChooser ifc = new JFileChooser(Config.getPref().get("nceditplugin.encinpfile"));
|
|---|
| 56 | private ActionListener alImport = new ActionListener() {
|
|---|
| 57 | @Override
|
|---|
| 58 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 59 | if (e.getSource() == importButton) {
|
|---|
| 60 | SCeditAction.panelS57.setVisible(true);
|
|---|
| 61 | setStatus("Select S-57 ENC file for import", Color.yellow);
|
|---|
| 62 | int returnVal = ifc.showOpenDialog(MainApplication.getMainFrame());
|
|---|
| 63 | if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|---|
| 64 | try {
|
|---|
| 65 | Config.getPref().put("smed2plugin.encinpfile", ifc.getSelectedFile().getPath());
|
|---|
| 66 | SCeditAction.panelS57.startImport(ifc.getSelectedFile());
|
|---|
| 67 | } catch (IOException e1) {
|
|---|
| 68 | SCeditAction.panelS57.setVisible(false);
|
|---|
| 69 | setStatus("IO Exception", Color.red);
|
|---|
| 70 | }
|
|---|
| 71 | } else {
|
|---|
| 72 | SCeditAction.panelS57.setVisible(false);
|
|---|
| 73 | clrStatus();
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | };
|
|---|
| 78 |
|
|---|
| 79 | private JButton exportButton = null;
|
|---|
| 80 | final JFileChooser efc = new JFileChooser();
|
|---|
| 81 | private ActionListener alExport = new ActionListener() {
|
|---|
| 82 | @Override
|
|---|
| 83 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 84 | if (e.getSource() == exportButton) {
|
|---|
| 85 | SCeditAction.panelS57.setVisible(true);
|
|---|
| 86 | setStatus("Select S-57 ENC file for export", Color.yellow);
|
|---|
| 87 | int returnVal = efc.showOpenDialog(MainApplication.getMainFrame());
|
|---|
| 88 | if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|---|
| 89 | try {
|
|---|
| 90 | SCeditAction.panelS57.startExport(efc.getSelectedFile());
|
|---|
| 91 | } catch (IOException e1) {
|
|---|
| 92 | SCeditAction.panelS57.setVisible(false);
|
|---|
| 93 | setStatus("IO Exception", Color.red);
|
|---|
| 94 | }
|
|---|
| 95 | } else {
|
|---|
| 96 | SCeditAction.panelS57.setVisible(false);
|
|---|
| 97 | clrStatus();
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 | };
|
|---|
| 102 |
|
|---|
| 103 | public PanelMain() {
|
|---|
| 104 | setLayout(null);
|
|---|
| 105 | setSize(new Dimension(480, 480));
|
|---|
| 106 |
|
|---|
| 107 | w = h = z = f = 0;
|
|---|
| 108 | wt = new JTextField("0");
|
|---|
| 109 | wt.setBounds(10, 400, 40, 20);
|
|---|
| 110 | add(wt);
|
|---|
| 111 | ht = new JTextField("0");
|
|---|
| 112 | ht.setBounds(60, 400, 40, 20);
|
|---|
| 113 | add(ht);
|
|---|
| 114 | zt = new JTextField("0");
|
|---|
| 115 | zt.setBounds(110, 400, 40, 20);
|
|---|
| 116 | add(zt);
|
|---|
| 117 | ft = new JTextField("0");
|
|---|
| 118 | ft.setBounds(160, 400, 40, 20);
|
|---|
| 119 | add(ft);
|
|---|
| 120 |
|
|---|
| 121 | messageBar = new JTextField();
|
|---|
| 122 | messageBar.setBounds(70, 430, 290, 20);
|
|---|
| 123 | messageBar.setEditable(false);
|
|---|
| 124 | messageBar.setBackground(Color.WHITE);
|
|---|
| 125 | add(messageBar);
|
|---|
| 126 | importButton = new JButton(new ImageIcon(getClass().getResource("/images/importButton.png")));
|
|---|
| 127 | importButton.setBounds(10, 430, 20, 20);
|
|---|
| 128 | add(importButton);
|
|---|
| 129 | importButton.addActionListener(alImport);
|
|---|
| 130 | exportButton = new JButton(new ImageIcon(getClass().getResource("/images/exportButton.png")));
|
|---|
| 131 | exportButton.setBounds(40, 430, 20, 20);
|
|---|
| 132 | add(exportButton);
|
|---|
| 133 | exportButton.addActionListener(alExport);
|
|---|
| 134 | saveButton = new JButton();
|
|---|
| 135 | saveButton.setBounds(370, 430, 100, 20);
|
|---|
| 136 | saveButton.setText(tr("Save"));
|
|---|
| 137 | add(saveButton);
|
|---|
| 138 | saveButton.addActionListener(alSave);
|
|---|
| 139 |
|
|---|
| 140 | decode = new JTextArea();
|
|---|
| 141 | decode.setBounds(0, 0, 480, 420);
|
|---|
| 142 | decode.setTabSize(1);
|
|---|
| 143 | add(decode);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | @Override
|
|---|
| 147 | public void paintComponent(Graphics g) {
|
|---|
| 148 | super.paintComponent(g);
|
|---|
| 149 | Graphics2D g2 = (Graphics2D) g;
|
|---|
| 150 | g2.setBackground(new Color(0xb5d0d0));
|
|---|
| 151 | if (img != null) g2.clearRect(0, 0, img.getWidth(), img.getHeight());
|
|---|
| 152 | g2.drawImage(img, 0, 0, null);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | public static void setStatus(String text, Color bg) {
|
|---|
| 156 | messageBar.setBackground(bg);
|
|---|
| 157 | messageBar.setText(text);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | public static void clrStatus() {
|
|---|
| 161 | messageBar.setBackground(Color.white);
|
|---|
| 162 | messageBar.setText("");
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | public void parseMark(Feature feature) {
|
|---|
| 166 | decode.setText("Selected object:\n");
|
|---|
| 167 | decode.append("\t" + tr("Type") + ": " + Messages.getString(feature.type.name()) + "\n");
|
|---|
| 168 | if (feature.atts.get(Att.OBJNAM) != null) {
|
|---|
| 169 | decode.append("\t" + tr("Name") + ": " + feature.atts.get(Att.OBJNAM).val + "\n");
|
|---|
| 170 | }
|
|---|
| 171 | decode.append("\tObjects:\n");
|
|---|
| 172 | for (Obj obj : feature.objs.keySet()) {
|
|---|
| 173 | decode.append("\t\t" + Messages.getString(obj.name()) + "\n");
|
|---|
| 174 | if (feature.objs.get(obj).size() != 0) {
|
|---|
| 175 | for (AttMap atts : feature.objs.get(obj).values()) {
|
|---|
| 176 | for (Att att : atts.keySet()) {
|
|---|
| 177 | AttVal<?> item = atts.get(att);
|
|---|
| 178 | switch (item.conv) {
|
|---|
| 179 | case E:
|
|---|
| 180 | decode.append("\t\t\t" + Messages.getString(att.name()) + ": " +
|
|---|
| 181 | Messages.getString(((Enum<?>) ((ArrayList<?>) item.val).get(0)).name()) + "\n");
|
|---|
| 182 | break;
|
|---|
| 183 | case L:
|
|---|
| 184 | decode.append("\t\t\t" + Messages.getString(att.name()) + ": ");
|
|---|
| 185 | boolean first = true;
|
|---|
| 186 | for (Object val : (ArrayList<?>) item.val) {
|
|---|
| 187 | if (!first) {
|
|---|
| 188 | decode.append(", ");
|
|---|
| 189 | } else {
|
|---|
| 190 | first = false;
|
|---|
| 191 | }
|
|---|
| 192 | decode.append(Messages.getString(((Enum<?>) val).name()));
|
|---|
| 193 | }
|
|---|
| 194 | decode.append("\n");
|
|---|
| 195 | break;
|
|---|
| 196 | default:
|
|---|
| 197 | decode.append("\t\t\t" + Messages.getString(att.name()) + ": " + item.val + "\n");
|
|---|
| 198 | }
|
|---|
| 199 | }
|
|---|
| 200 | }
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | public void clearMark() {
|
|---|
| 206 | decode.setText(tr("No object selected"));
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|