Changeset 29851 in osm
- Timestamp:
- 2013-08-20T23:00:22+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/geochat/src/geochat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geochat/src/geochat/ChatPaneManager.java
r29590 r29851 11 11 import javax.swing.text.*; 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.gui.util.GuiHelper; 13 14 import static org.openstreetmap.josm.tools.I18n.tr; 14 15 … … 80 81 private static Color COLOR_ATTENTION = new Color(0, 0, 192); 81 82 82 private void addLineToChatPane( String userName, String line, int messageType ) {83 private void addLineToChatPane( String userName, String line, final int messageType ) { 83 84 if( line.length() == 0 ) 84 85 return; 85 86 if( !chatPanes.containsKey(userName) ) 86 87 createChatPane(userName); 87 if( !line.startsWith("\n") ) 88 line = "\n" + line; 89 Document doc = chatPanes.get(userName).pane.getDocument(); 90 try { 91 SimpleAttributeSet attrs = null; 92 if( messageType != MESSAGE_TYPE_DEFAULT ) { 93 attrs = new SimpleAttributeSet(); 94 if( messageType == MESSAGE_TYPE_INFORMATION ) 95 StyleConstants.setItalic(attrs, true); 96 else if( messageType == MESSAGE_TYPE_ATTENTION ) 97 StyleConstants.setForeground(attrs, COLOR_ATTENTION); 88 final String nline = line.startsWith("\n") ? line : "\n" + line; 89 final JTextPane thepane = chatPanes.get(userName).pane; 90 GuiHelper.runInEDT(new Runnable() { 91 public void run() { 92 Document doc = thepane.getDocument(); 93 try { 94 SimpleAttributeSet attrs = null; 95 if( messageType != MESSAGE_TYPE_DEFAULT ) { 96 attrs = new SimpleAttributeSet(); 97 if( messageType == MESSAGE_TYPE_INFORMATION ) 98 StyleConstants.setItalic(attrs, true); 99 else if( messageType == MESSAGE_TYPE_ATTENTION ) 100 StyleConstants.setForeground(attrs, COLOR_ATTENTION); 101 } 102 doc.insertString(doc.getLength(), nline, attrs); 103 } catch( BadLocationException ex ) { 104 // whatever 105 } 106 thepane.setCaretPosition(doc.getLength()); 98 107 } 99 doc.insertString(doc.getLength(), line, attrs); 100 } catch( BadLocationException ex ) { 101 // whatever 102 } 103 chatPanes.get(userName).pane.setCaretPosition(doc.getLength()); 108 }); 104 109 } 105 110 -
applications/editors/josm/plugins/geochat/src/geochat/ChatServerConnection.java
r29592 r29851 6 6 import java.net.URLEncoder; 7 7 import java.util.*; 8 import java.util.logging.*; 8 9 import org.json.JSONArray; 9 10 import org.json.JSONException; … … 348 349 + "&lon=" + pos.lonToString(CoordinateFormat.DECIMAL_DEGREES) 349 350 + "&uid=" + userId + "&last=" + lastId; 350 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 351 public void processJson( JSONObject json ) { 352 if( json == null ) { 353 // do nothing? 354 // fireLoginFailed(tr("Could not get server response, check logs")); 355 // logoutIntl(); // todo: uncomment? 356 } else if( json.has("error") ) { 357 fireLoginFailed(tr("Failed to get messages as {0}:", userName) + "\n" + json.getString("error")); 358 logoutIntl(); 359 } else { 360 if( json.has("users") ) { 361 Map<String, LatLon> users = parseUsers(json.getJSONArray("users")); 362 for( ChatServerConnectionListener listener : listeners ) 363 listener.updateUsers(users); 364 } 365 if( json.has("messages") ) { 366 List<ChatMessage> messages = parseMessages(json.getJSONArray("messages"), false); 367 for( ChatMessage m : messages ) 368 if( m.getId() > lastId ) 369 lastId = m.getId(); 370 for( ChatServerConnectionListener listener : listeners ) 371 listener.receivedMessages(needReset, messages); 372 } 373 if( json.has("private") ) { 374 List<ChatMessage> messages = parseMessages(json.getJSONArray("private"), true); 375 for( ChatMessage m : messages ) 376 if( m.getId() > lastId ) 377 lastId = m.getId(); 378 for( ChatServerConnectionListener listener : listeners ) 379 listener.receivedPrivateMessages(needFullReset, messages); 380 } 381 } 351 JSONObject json; 352 try { 353 json = JsonQueryUtil.query(query); 354 } catch( IOException ex ) { 355 json = null; // ? 356 } 357 if( json == null ) { 358 // do nothing? 359 // fireLoginFailed(tr("Could not get server response, check logs")); 360 // logoutIntl(); // todo: uncomment? 361 } else if( json.has("error") ) { 362 fireLoginFailed(tr("Failed to get messages as {0}:", userName) + "\n" + json.getString("error")); 363 logoutIntl(); 364 } else { 365 if( json.has("users") ) { 366 Map<String, LatLon> users = parseUsers(json.getJSONArray("users")); 367 for( ChatServerConnectionListener listener : listeners ) 368 listener.updateUsers(users); 369 } 370 if( json.has("messages") ) { 371 List<ChatMessage> messages = parseMessages(json.getJSONArray("messages"), false); 372 for( ChatMessage m : messages ) 373 if( m.getId() > lastId ) 374 lastId = m.getId(); 375 for( ChatServerConnectionListener listener : listeners ) 376 listener.receivedMessages(needReset, messages); 377 } 378 if( json.has("private") ) { 379 List<ChatMessage> messages = parseMessages(json.getJSONArray("private"), true); 380 for( ChatMessage m : messages ) 381 if( m.getId() > lastId ) 382 lastId = m.getId(); 383 for( ChatServerConnectionListener listener : listeners ) 384 listener.receivedPrivateMessages(needFullReset, messages); 385 } 386 } 382 387 // if( lastId > 0 && Main.pref.getBoolean("geochat.store.lastid", true) ) 383 388 // Main.pref.putLong("geochat.lastid", lastId); 384 }385 });386 389 } 387 390 -
applications/editors/josm/plugins/geochat/src/geochat/GeoChatPanel.java
r29590 r29851 15 15 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 16 16 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 17 import org.openstreetmap.josm.gui.util.GuiHelper; 17 18 import org.openstreetmap.josm.tools.GBC; 18 19 import static org.openstreetmap.josm.tools.I18n.tr; … … 202 203 if( comment != null ) 203 204 title = title + " (" + comment + ")"; 204 String alarm = alarmLevel <= 0 ? "" : alarmLevel == 1 ? "* " : "!!! "; 205 setTitle(alarm + title); 205 final String alarm = (alarmLevel <= 0 ? "" : alarmLevel == 1 ? "* " : "!!! ") + title; 206 GuiHelper.runInEDT(new Runnable() { 207 public void run() { 208 setTitle(alarm); 209 } 210 }); 206 211 } 207 212
Note:
See TracChangeset
for help on using the changeset viewer.