Changeset 29576 in osm for applications/editors/josm/plugins/geochat
- Timestamp:
- 2013-05-09T23:29:49+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/geochat/src/geochat
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geochat/src/geochat/ChatPaneManager.java
r29574 r29576 1 1 package geochat; 2 2 3 import java.awt.Color; 3 4 import java.awt.Component; 4 5 import java.awt.Font; … … 72 73 } 73 74 74 private void addLineToChatPane( String userName, String line, boolean italic ) { 75 public static int MESSAGE_TYPE_DEFAULT = 0; 76 public static int MESSAGE_TYPE_INFORMATION = 1; 77 public static int MESSAGE_TYPE_ATTENTION = 2; 78 private static Color COLOR_ATTENTION = new Color(0, 0, 192); 79 80 private void addLineToChatPane( String userName, String line, int messageType ) { 75 81 if( line.length() == 0 ) 76 82 return; … … 82 88 try { 83 89 SimpleAttributeSet attrs = null; 84 if( italic) {90 if( messageType != MESSAGE_TYPE_DEFAULT ) { 85 91 attrs = new SimpleAttributeSet(); 86 StyleConstants.setItalic(attrs, true); 92 if( messageType == MESSAGE_TYPE_INFORMATION ) 93 StyleConstants.setItalic(attrs, true); 94 else if( messageType == MESSAGE_TYPE_ATTENTION ) 95 StyleConstants.setForeground(attrs, COLOR_ATTENTION); 87 96 } 88 97 doc.insertString(doc.getLength(), line, attrs); … … 94 103 95 104 public void addLineToChatPane( String userName, String line ) { 96 addLineToChatPane(userName, line, false);105 addLineToChatPane(userName, line, MESSAGE_TYPE_DEFAULT); 97 106 } 98 107 … … 101 110 } 102 111 112 public void addLineToPublic( String line, int messageType ) { 113 addLineToChatPane(PUBLIC_PANE, line, messageType); 114 } 115 103 116 public void clearPublicChatPane() { 104 117 chatPanes.get(PUBLIC_PANE).pane.setText(""); 105 showNearbyUsers();106 }107 108 private void showNearbyUsers() {109 if( !panel.users.isEmpty() ) {110 StringBuilder sb = new StringBuilder(tr("Users mapping nearby:"));111 boolean first = true;112 for( String user : panel.users.keySet() ) {113 sb.append(first ? " " : ", ");114 sb.append(user);115 }116 addLineToPublic(sb.toString());117 }118 118 } 119 119 … … 192 192 } 193 193 194 public boolean hasSelectedText() { 195 String user = getActiveChatPane(); 196 if( user != null ) { 197 JTextPane pane = chatPanes.get(user).pane; 198 return pane.getSelectedText() != null; 199 } 200 return false; 201 } 202 203 public void copySelectedText() { 204 String user = getActiveChatPane(); 205 if( user != null ) 206 chatPanes.get(user).pane.copy(); 207 } 208 194 209 195 210 private class ChatTabTitleComponent extends JLabel { -
applications/editors/josm/plugins/geochat/src/geochat/ChatServerConnection.java
r29568 r29576 1 1 package geochat; 2 2 3 import java.io.IOException; 3 4 import java.io.UnsupportedEncodingException; 4 5 import java.net.URLEncoder; 5 6 import java.util.*; 6 import javax.swing.SwingUtilities;7 7 import org.json.JSONArray; 8 8 import org.json.JSONException; … … 143 143 } 144 144 145 /** 146 * Unregister the current user and do not call listeners. 147 * Makes synchronous request to the server. 148 */ 149 public void bruteLogout() throws IOException { 150 if( isLoggedIn() ) 151 JsonQueryUtil.query("logout&uid=" + userId); 152 } 153 145 154 private void fireMessageFailed( String reason ) { 146 155 for( ChatServerConnectionListener listener : listeners ) … … 248 257 249 258 public void run() { 259 // lastId = Main.pref.getLong("geochat.lastid", 0); 250 260 int interval = Main.pref.getInteger("geochat.interval", 2); 251 261 while( !stopping ) { … … 281 291 // reset messages 282 292 lastId = 0; 293 // Main.pref.put("geochat.lastid", null); 283 294 needReset = true; 284 295 } else … … 322 333 } 323 334 } 335 // if( lastId > 0 && Main.pref.getBoolean("geochat.store.lastid", true) ) 336 // Main.pref.putLong("geochat.lastid", lastId); 324 337 } 325 338 }); -
applications/editors/josm/plugins/geochat/src/geochat/GeoChatPanel.java
r29572 r29576 52 52 53 53 @Override 54 protected String autoComplete( String word ) {55 return autoCompleteUser(word );54 protected String autoComplete( String word, boolean atStart ) { 55 return autoCompleteUser(word, atStart); 56 56 } 57 57 }; … … 103 103 } 104 104 105 private String autoCompleteUser( String word ) { 105 @Override 106 public void destroy() { 107 try { 108 if( Main.pref.getBoolean("geochat.logout.on.close", true) ) { 109 connection.removeListener(this); 110 connection.bruteLogout(); 111 } 112 } catch( Throwable e ) { 113 Main.warn("Failed to logout from geochat server: " + e.getMessage()); 114 } 115 super.destroy(); 116 } 117 118 private String autoCompleteUser( String word, boolean atStart ) { 106 119 String result = null; 120 boolean singleUser = true; 107 121 for( String user : users.keySet() ) { 108 122 if( user.startsWith(word) ) { … … 110 124 result = user; 111 125 else { 126 singleUser = false; 112 127 int i = word.length(); 113 128 while( i < result.length() && i < user.length() && result.charAt(i) == user.charAt(i) ) … … 118 133 } 119 134 } 120 return result ;135 return result == null ? null : !singleUser ? result : atStart ? result + ": " : result + " "; 121 136 } 122 137 … … 159 174 if( !isDialogInCollapsedView() && alarmLevel > 1 ) 160 175 alarmLevel = 1; 161 String name = users.isEmpty() ? tr("GeoChat") :176 String title = users.isEmpty() ? tr("GeoChat") : 162 177 trn("GeoChat ({0} user)", "GeoChat ({0} users)", users.size(), users.size()); 163 178 String alarm = alarmLevel <= 0 ? "" : alarmLevel == 1 ? "* " : "!!! "; 164 setTitle(alarm + name);179 setTitle(alarm + title); 165 180 } 166 181 … … 218 233 for( String uname : this.users.keySet() ) { 219 234 if( !newUsers.containsKey(uname) ) 220 chatPanes.addLineToPublic(tr("User {0} has left", uname) );235 chatPanes.addLineToPublic(tr("User {0} has left", uname), ChatPaneManager.MESSAGE_TYPE_INFORMATION); 221 236 } 222 237 for( String uname : newUsers.keySet() ) { 223 238 if( !this.users.containsKey(uname) ) 224 chatPanes.addLineToPublic(tr("User {0} is mapping nearby", uname) );239 chatPanes.addLineToPublic(tr("User {0} is mapping nearby", uname), ChatPaneManager.MESSAGE_TYPE_INFORMATION); 225 240 } 226 241 this.users = newUsers; … … 254 269 sb.setLength(0); 255 270 formatMessage(sb, msg); 256 chatPanes.addLineToPublic Em(sb.toString());271 chatPanes.addLineToPublic(sb.toString(), ChatPaneManager.MESSAGE_TYPE_ATTENTION); 257 272 sb.setLength(0); 258 273 } else … … 262 277 if( alarm > 0 ) 263 278 chatPanes.notify(null, alarm); 279 } 280 if( replace ) 281 showNearbyUsers(); 282 } 283 284 private void showNearbyUsers() { 285 if( !users.isEmpty() ) { 286 StringBuilder sb = new StringBuilder(tr("Users mapping nearby:")); 287 boolean first = true; 288 for( String user : users.keySet() ) { 289 sb.append(first ? " " : ", "); 290 sb.append(user); 291 } 292 chatPanes.addLineToPublic(sb.toString(), ChatPaneManager.MESSAGE_TYPE_INFORMATION); 264 293 } 265 294 } -
applications/editors/josm/plugins/geochat/src/geochat/GeoChatPopupAdapter.java
r29568 r29576 43 43 44 44 JPopupMenu menu = new JPopupMenu(); 45 if( panel.chatPanes.hasSelectedText() ) 46 menu.add(new CopyTextAction()); 45 47 menu.add(new JCheckBoxMenuItem(new ToggleUserLayerAction())); 46 48 if( userMenu.getItemCount() > 0 ) … … 49 51 menu.add(new CloseTabAction()); 50 52 // menu.add(new ClearPaneAction()); 51 //menu.add(new LogoutAction());53 menu.add(new LogoutAction()); 52 54 return menu; 53 55 } … … 118 120 } 119 121 } 122 123 private class CopyTextAction extends AbstractAction { 124 public CopyTextAction() { 125 super(tr("Copy")); 126 // putValue(SMALL_ICON, ImageProvider.get("help")); 127 } 128 129 public void actionPerformed( ActionEvent e ) { 130 panel.chatPanes.copySelectedText(); 131 } 132 } 120 133 } -
applications/editors/josm/plugins/geochat/src/geochat/JPanelTextField.java
r29571 r29576 37 37 start--; 38 38 start++; 39 System.out.println("Autocomplete! Word " + start + "-" + caret + " (not inclusive)");40 39 if( start < caret ) { 41 40 String word = text.substring(start, caret); 42 String complete = word == null ? null : autoComplete(word );41 String complete = word == null ? null : autoComplete(word, start == 0); 43 42 if( complete != null && !complete.equals(word) ) { 44 43 StringBuilder sb = new StringBuilder(); … … 75 74 * @return The whole word. 76 75 */ 77 protected String autoComplete( String word ) {76 protected String autoComplete( String word, boolean atStart ) { 78 77 return word; 79 78 }
Note:
See TracChangeset
for help on using the changeset viewer.