source: josm/src/org/openstreetmap/josm/gui/MainApplet.java@ 283

Last change on this file since 283 was 283, checked in by imi, 19 years ago
  • fixed lots of typos (thanks Bruce)
File size: 4.4 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.GridBagLayout;
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.HashMap;
11import java.util.LinkedList;
12import java.util.Map;
13
14import javax.swing.JApplet;
15import javax.swing.JLabel;
16import javax.swing.JOptionPane;
17import javax.swing.JPanel;
18import javax.swing.JPasswordField;
19import javax.swing.JTextField;
20
21import org.openstreetmap.josm.Main;
22import org.openstreetmap.josm.actions.JosmAction;
23import org.openstreetmap.josm.data.ServerSidePreferences;
24import org.openstreetmap.josm.tools.GBC;
25
26public class MainApplet extends JApplet {
27
28 public static final class UploadPreferencesAction extends JosmAction {
29 public UploadPreferencesAction() {
30 super(tr("Upload Preferences"), "upload-preferences", tr("Upload the current preferences to the server"), KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK, true);
31 }
32 public void actionPerformed(ActionEvent e) {
33 ((ServerSidePreferences)Main.pref).upload();
34 }
35 }
36
37 private final class MainCaller extends Main {
38 private MainCaller() {
39 setContentPane(contentPane);
40 setJMenuBar(menu);
41 setBounds(bounds);
42 }
43 }
44
45 private final static String[][] paramInfo = {
46 {"username", tr("string"), tr("Name of the user.")},
47 {"password", tr("string"), tr("OSM Password.")},
48 {"geometry", tr("string"), tr("Resize the applet to the given geometry (format: WIDTHxHEIGHT)")},
49 {"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")},
50 {"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")},
51 {"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")},
52 {"reset-preferences", tr("any"),tr("If specified, reset the configuration instead of reading it.")}
53 };
54
55 private Map<String, Collection<String>> args = new HashMap<String, Collection<String>>();
56 private UploadPreferencesAction uploadPreferences = new UploadPreferencesAction();
57
58 @Override public String[][] getParameterInfo() {
59 return paramInfo;
60 }
61
62 @Override public void init() {
63 for (String[] s : paramInfo) {
64 Collection<String> p = readParameter(s[0], args.get(s[0]));
65 if (p != null)
66 args.put(s[0], p);
67 }
68 if (!args.containsKey("geometry") && getParameter("width") != null && getParameter("height") != null) {
69 args.put("geometry", Arrays.asList(new String[]{getParameter("width")+"x"+getParameter("height")}));
70 }
71 }
72
73 @Override public void start() {
74 String username = args.containsKey("username") ? args.get("username").iterator().next() : null;
75 String password = args.containsKey("password") ? args.get("password").iterator().next() : null;
76 if (username == null || password == null) {
77 JPanel p = new JPanel(new GridBagLayout());
78 p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,20,0));
79 JTextField user = new JTextField(username == null ? "" : username);
80 p.add(user, GBC.eol().fill(GBC.HORIZONTAL));
81 p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,20,0));
82 JPasswordField pass = new JPasswordField(password == null ? "" : password);
83 p.add(pass, GBC.eol().fill(GBC.HORIZONTAL));
84 JOptionPane.showMessageDialog(null, p);
85 username = user.getText();
86 password = new String(pass.getPassword());
87 args.put("password", Arrays.asList(new String[]{password}));
88 }
89
90 Main.applet = true;
91 Main.pref = new ServerSidePreferences(getCodeBase());
92 ((ServerSidePreferences)Main.pref).download(username, password);
93
94 Main.preConstructorInit(args);
95 Main.parent = this;
96 new MainCaller().postConstructorProcessCmdLine(args);
97
98 MainMenu m = Main.main.menu; // shortcut
99
100 // remove offending stuff from JOSM (that would break the SecurityManager)
101 m.remove(m.fileMenu);
102 m.editMenu.add(uploadPreferences);
103 m.open.setEnabled(false);
104 m.exit.setEnabled(false);
105 m.save.setEnabled(false);
106 m.saveAs.setEnabled(false);
107 m.gpxExport.setEnabled(false);
108 }
109
110 private Collection<String> readParameter(String s, Collection<String> v) {
111 String param = getParameter(s);
112 if (param != null) {
113 if (v == null)
114 v = new LinkedList<String>();
115 v.addAll(Arrays.asList(param.split(";")));
116 }
117 return v;
118 }
119}
Note: See TracBrowser for help on using the repository browser.