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

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

save

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