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

Last change on this file since 30022 was 30022, checked in by malcolmh, 11 years ago

save

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