source: osm/applications/editors/josm/plugins/seachartedit/src/panels/PanelMain.java@ 31060

Last change on this file since 31060 was 31060, checked in by malcolmh, 10 years ago

[SeaChartEditor] refresh

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