1 | package org.openstreetmap.josm.gui;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.GridBagLayout;
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.HashMap;
|
---|
9 | import java.util.LinkedList;
|
---|
10 | import java.util.Map;
|
---|
11 |
|
---|
12 | import javax.swing.JApplet;
|
---|
13 | import javax.swing.JLabel;
|
---|
14 | import javax.swing.JOptionPane;
|
---|
15 | import javax.swing.JPanel;
|
---|
16 | import javax.swing.JPasswordField;
|
---|
17 | import javax.swing.JTextField;
|
---|
18 |
|
---|
19 | import org.openstreetmap.josm.Main;
|
---|
20 | import org.openstreetmap.josm.data.ServerSidePreferences;
|
---|
21 | import org.openstreetmap.josm.tools.GBC;
|
---|
22 |
|
---|
23 | public class MainApplet extends JApplet {
|
---|
24 |
|
---|
25 | private final class MainCaller extends Main {
|
---|
26 | private MainCaller() {
|
---|
27 | setContentPane(contentPane);
|
---|
28 | setJMenuBar(menu);
|
---|
29 | setBounds(bounds);
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | private final static String[][] paramInfo = {
|
---|
34 | {"username", tr("string"), tr("Name of the user.")},
|
---|
35 | {"password", tr("string"), tr("OSM Password.")},
|
---|
36 | {"geometry", tr("string"), tr("Size the applet to the given geometry (format: WIDTHxHEIGHT)")},
|
---|
37 | {"download", tr("string;string;..."), tr("Download each. Can be x1,y1,x2,y2 an url containing lat=y&lon=x&zoom=z or a filename")},
|
---|
38 | {"downloadgps", tr("string;string;..."), tr("Download each as raw gps. Can be x1,y1,x2,y2 an url containing lat=y&lon=x&zoom=z or a filename")},
|
---|
39 | {"selection", tr("string;string;..."), tr("Add each to the initial selection. Can be a google-like search string or an url which returns osm-xml")},
|
---|
40 | {"reset-preferences", tr("any"),tr("If specified, reset the configuration instead of reading it.")}
|
---|
41 | };
|
---|
42 |
|
---|
43 | private Map<String, Collection<String>> args = new HashMap<String, Collection<String>>();
|
---|
44 |
|
---|
45 | @Override public String[][] getParameterInfo() {
|
---|
46 | return paramInfo;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override public void init() {
|
---|
50 | for (String[] s : paramInfo) {
|
---|
51 | Collection<String> p = readParameter(s[0], args.get(s[0]));
|
---|
52 | if (p != null)
|
---|
53 | args.put(s[0], p);
|
---|
54 | }
|
---|
55 | if (!args.containsKey("geometry") && getParameter("width") != null && getParameter("height") != null) {
|
---|
56 | args.put("geometry", Arrays.asList(new String[]{getParameter("width")+"x"+getParameter("height")}));
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override public void start() {
|
---|
61 | String username = args.containsKey("username") ? args.get("username").iterator().next() : null;
|
---|
62 | String password = args.containsKey("password") ? args.get("password").iterator().next() : null;
|
---|
63 | if (username == null || password == null) {
|
---|
64 | JPanel p = new JPanel(new GridBagLayout());
|
---|
65 | p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,20,0));
|
---|
66 | JTextField user = new JTextField(username == null ? "" : username);
|
---|
67 | p.add(user, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
68 | p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,20,0));
|
---|
69 | JPasswordField pass = new JPasswordField(password == null ? "" : password);
|
---|
70 | p.add(pass, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
71 | JOptionPane.showMessageDialog(null, p);
|
---|
72 | username = user.getText();
|
---|
73 | password = new String(pass.getPassword());
|
---|
74 | args.put("password", Arrays.asList(new String[]{password}));
|
---|
75 | }
|
---|
76 |
|
---|
77 | Main.applet = true;
|
---|
78 | Main.pref = new ServerSidePreferences(getCodeBase(), username);
|
---|
79 |
|
---|
80 | Main.preConstructorInit(args);
|
---|
81 | Main.parent = this;
|
---|
82 | new MainCaller().postConstructorProcessCmdLine(args);
|
---|
83 |
|
---|
84 | MainMenu m = Main.main.menu; // shortcut
|
---|
85 |
|
---|
86 | // remove offending stuff from JOSM (that would break the SecurityManager)
|
---|
87 | m.remove(m.fileMenu);
|
---|
88 | m.open.setEnabled(false);
|
---|
89 | m.exit.setEnabled(false);
|
---|
90 | m.save.setEnabled(false);
|
---|
91 | m.saveAs.setEnabled(false);
|
---|
92 | m.gpxExport.setEnabled(false);
|
---|
93 | }
|
---|
94 |
|
---|
95 | private Collection<String> readParameter(String s, Collection<String> v) {
|
---|
96 | String param = getParameter(s);
|
---|
97 | if (param != null) {
|
---|
98 | if (v == null)
|
---|
99 | v = new LinkedList<String>();
|
---|
100 | v.addAll(Arrays.asList(param.split(";")));
|
---|
101 | }
|
---|
102 | return v;
|
---|
103 | }
|
---|
104 | }
|
---|