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

Last change on this file since 33030 was 33030, checked in by donvip, 8 years ago

checkstyle

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