Changeset 35161 in osm for applications/editors/josm/plugins/geochat
- Timestamp:
- 2019-09-29T22:11:59+02:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/geochat/src/geochat
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geochat/src/geochat/ChatMessage.java
r33545 r35161 77 77 @Override 78 78 public boolean equals(Object obj) { 79 if (obj == null) { 80 return false; 81 } 82 if (getClass() != obj.getClass()) { 79 if (obj == null || getClass() != obj.getClass()) { 83 80 return false; 84 81 } -
applications/editors/josm/plugins/geochat/src/geochat/ChatPaneManager.java
r35160 r35161 16 16 import javax.swing.JTabbedPane; 17 17 import javax.swing.JTextPane; 18 import javax.swing.event.ChangeEvent;19 import javax.swing.event.ChangeListener;20 18 import javax.swing.text.BadLocationException; 21 19 import javax.swing.text.Document; … … 45 43 chatPanes = new HashMap<>(); 46 44 createChatPane(null); 47 tabs.addChangeListener(new ChangeListener() { 48 @Override 49 public void stateChanged(ChangeEvent e) { 50 updateActiveTabStatus(); 51 } 52 }); 45 tabs.addChangeListener(e -> updateActiveTabStatus()); 53 46 } 54 47 … … 90 83 } 91 84 92 public static int MESSAGE_TYPE_DEFAULT = 0;93 public static int MESSAGE_TYPE_INFORMATION = 1;94 public static int MESSAGE_TYPE_ATTENTION = 2;95 private static Color COLOR_ATTENTION = new Color(0, 0, 192);85 public static final int MESSAGE_TYPE_DEFAULT = 0; 86 public static final int MESSAGE_TYPE_INFORMATION = 1; 87 public static final int MESSAGE_TYPE_ATTENTION = 2; 88 private static final Color COLOR_ATTENTION = new Color(0, 0, 192); 96 89 97 90 private void addLineToChatPane(String userName, String line, final int messageType) { 98 if (line. length() == 0)91 if (line.isEmpty()) 99 92 return; 100 93 if (!chatPanes.containsKey(userName)) … … 261 254 public JScrollPane component; 262 255 public int notify; 263 264 256 } 265 257 } -
applications/editors/josm/plugins/geochat/src/geochat/ChatServerConnection.java
r35160 r35161 95 95 } else { 96 96 String query = "whoami&uid=" + uid; 97 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 98 @Override 99 public void processJson(JsonObject json) { 100 if (json != null && json.get("name") != null) 101 login(uid, json.getString("name")); 102 else if (userName != null && userName.length() > 1) 103 login(userName); 104 } 97 JsonQueryUtil.queryAsync(query, json -> { 98 if (json != null && json.get("name") != null) 99 login(uid, json.getString("name")); 100 else if (userName != null && userName.length() > 1) 101 login(userName); 105 102 }); 106 103 } … … 112 109 */ 113 110 public void autoLoginWithDelay(final String userName) { 114 if (userName == null || userName. length() == 0) {111 if (userName == null || userName.isEmpty()) { 115 112 checkLogin(); 116 113 return; … … 148 145 + "&lon=" + DecimalDegreesCoordinateFormat.INSTANCE.lonToString(pos) 149 146 + nameAttr; 150 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 151 @Override 152 public void processJson(JsonObject json) { 153 if (json == null) 154 fireLoginFailed(tr("Could not get server response, check logs")); 155 else if (json.get("error") != null) 156 fireLoginFailed(tr("Failed to login as {0}:", userName) + "\n" + json.getString("error")); 157 else if (json.get("uid") == null) 158 fireLoginFailed(tr("The server did not return user ID")); 159 else { 160 String name = json.get("name") != null ? json.getString("name") : userName; 161 login(json.getInt("uid"), name); 162 } 147 JsonQueryUtil.queryAsync(query, json -> { 148 if (json == null) 149 fireLoginFailed(tr("Could not get server response, check logs")); 150 else if (json.get("error") != null) 151 fireLoginFailed(tr("Failed to login as {0}:", userName) + "\n" + json.getString("error")); 152 else if (json.get("uid") == null) 153 fireLoginFailed(tr("The server did not return user ID")); 154 else { 155 String name = json.get("name") != null ? json.getString("name") : userName; 156 login(json.getInt("uid"), name); 163 157 } 164 158 }); … … 199 193 return; 200 194 String query = "logout&uid=" + userId; 201 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 202 @Override 203 public void processJson(JsonObject json) { 204 if (json != null && json.get("message") != null) { 205 logoutIntl(); 206 } 195 JsonQueryUtil.queryAsync(query, json -> { 196 if (json != null && json.get("message") != null) { 197 logoutIntl(); 207 198 } 208 199 }); … … 256 247 if (targetUser != null && targetUser.length() > 0) 257 248 query += "&to=" + URLEncoder.encode(targetUser, "UTF8"); 258 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 259 @Override 260 public void processJson(JsonObject json) { 261 if (json == null) 262 fireMessageFailed(tr("Could not get server response, check logs")); 263 else if (json.get("error") != null) 264 fireMessageFailed(json.getString("error")); 265 } 249 JsonQueryUtil.queryAsync(query, json -> { 250 if (json == null) 251 fireMessageFailed(tr("Could not get server response, check logs")); 252 else if (json.get("error") != null) 253 fireMessageFailed(json.getString("error")); 266 254 }); 267 255 } catch (UnsupportedEncodingException e) { -
applications/editors/josm/plugins/geochat/src/geochat/GeoChatPanel.java
r35160 r35161 17 17 import java.awt.Point; 18 18 import java.awt.RenderingHints; 19 import java.awt.event.ActionEvent;20 import java.awt.event.ActionListener;21 19 import java.io.IOException; 22 20 import java.text.SimpleDateFormat; … … 123 121 124 122 JButton loginButton = new JButton(tr("Login")); 125 loginButton.addActionListener(new ActionListener() { 126 @Override 127 public void actionPerformed(ActionEvent e) { 128 connection.login(nameField.getText()); 129 } 130 }); 123 loginButton.addActionListener(e -> connection.login(nameField.getText())); 131 124 nameField.setPreferredSize(new Dimension(nameField.getPreferredSize().width, loginButton.getPreferredSize().height)); 132 125 133 126 final JCheckBox autoLoginBox = new JCheckBox(tr("Enable autologin"), Config.getPref().getBoolean("geochat.autologin", true)); 134 autoLoginBox.addActionListener(new ActionListener() { 135 @Override 136 public void actionPerformed(ActionEvent e) { 137 Config.getPref().putBoolean("geochat.autologin", autoLoginBox.isSelected()); 138 } 139 }); 127 autoLoginBox.addActionListener(e -> Config.getPref().putBoolean("geochat.autologin", autoLoginBox.isSelected())); 140 128 141 129 JPanel panel = new JPanel(new GridBagLayout()); -
applications/editors/josm/plugins/geochat/src/geochat/JsonQueryCallback.java
r32544 r35161 9 9 * @author zverik 10 10 */ 11 @FunctionalInterface 11 12 public interface JsonQueryCallback { 12 13
Note:
See TracChangeset
for help on using the changeset viewer.