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

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

save

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