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

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

save

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