Changeset 29571 in osm for applications/editors/josm/plugins/geochat
- Timestamp:
- 2013-05-09T21:00:19+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/geochat
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geochat/build.xml
r29540 r29571 22 22 <property name="plugin.class" value="geochat.GeoChatPlugin"/> 23 23 <property name="plugin.description" value="Talk with users editing the map nearby, be notified when someone comes close."/> 24 <property name="plugin.icon" value="images/ geochat.png"/>25 <property name="plugin.link" value="http://wiki.openstreetmap.org/wiki/ GeoChat"/>24 <property name="plugin.icon" value="images/dialogs/geochat.png"/> 25 <property name="plugin.link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/GeoChat"/> 26 26 27 27 <target name="additional-manifest"> … … 29 29 <attribute name="ru_Author" value="Илья Зверев"/> 30 30 <attribute name="ru_Plugin-Description" value="Панель для общения с редактирующими карту поблизости, а также способ узнать, когда кто-то собирается править окрестности."/> 31 <attribute name="ru_Plugin_Link" value="http://wiki.openstreetmap.org/wiki/RU:JOSM/Plugins/GeoChat"/> 31 32 </manifest> 32 33 </target> -
applications/editors/josm/plugins/geochat/src/geochat/ChatPaneManager.java
r29568 r29571 7 7 import javax.swing.event.ChangeEvent; 8 8 import javax.swing.event.ChangeListener; 9 import javax.swing.text.BadLocationException; 10 import javax.swing.text.DefaultCaret; 11 import javax.swing.text.Document; 9 import javax.swing.text.*; 12 10 import static org.openstreetmap.josm.tools.I18n.tr; 13 11 … … 53 51 int alarm = 0; 54 52 for( ChatPane entry : chatPanes.values() ) { 55 if( entry.notify ) { 56 if( entry.isPublic && alarm < 1 ) 57 alarm = 1; 58 else if( !entry.isPublic ) 59 alarm = 2; 60 } 53 if( entry.notify > alarm ) 54 alarm = entry.notify; 61 55 } 62 56 return alarm; … … 68 62 } 69 63 70 public void notify( String user, boolean really ) { 71 // if( user == null && !really && !collapsed ) 72 // return; 73 if( !hasUser(user) ) 64 public void notify( String user, int alarmLevel ) { 65 if( alarmLevel <= 0 || !hasUser(user) ) 74 66 return; 75 67 ChatPane entry = chatPanes.get(user == null ? PUBLIC_PANE : user); 76 System.out.println("Notifying " + user); 77 entry.notify = true; 68 entry.notify = alarmLevel; 78 69 int idx = tabs.indexOfComponent(entry.component); 79 70 if( idx >= 0 ) … … 82 73 83 74 public void addLineToChatPane( String userName, String line ) { 75 if( line.length() == 0 ) 76 return; 84 77 if( !chatPanes.containsKey(userName) ) 85 78 createChatPane(userName); … … 98 91 } 99 92 93 /** 94 * Special case: the line contains username, so it must be highlighted. 95 */ 96 public void addLineToPublicEm( String line ) { 97 if( !line.startsWith("\n") ) 98 line = "\n" + line; 99 Document doc = chatPanes.get(PUBLIC_PANE).pane.getDocument(); 100 try { 101 SimpleAttributeSet attrs = new SimpleAttributeSet(); 102 StyleConstants.setItalic(attrs, true); 103 doc.insertString(doc.getLength(), line, attrs); 104 } catch( BadLocationException ex ) { 105 // whatever 106 } 107 } 108 100 109 public void clearPublicChatPane() { 101 110 chatPanes.get(PUBLIC_PANE).pane.setText(""); … … 139 148 entry.pane = chatPane; 140 149 entry.component = scrollPane; 141 entry.notify = false;150 entry.notify = 0; 142 151 entry.userName = userName; 143 152 entry.isPublic = userName == null; … … 207 216 boldFont = getFont().deriveFont(Font.BOLD); 208 217 } 209 System.out.println("clauses: collapsed=" + collapsed + ", tabs:" + tabs.getSelectedIndex() + "=" + tabs.indexOfComponent(entry.component)); 210 if( entry.notify && !collapsed && tabs.getSelectedIndex() == tabs.indexOfComponent(entry.component) ) 211 entry.notify = false; 212 setFont(entry.notify ? boldFont : normalFont); 218 if( entry.notify > 0 && !collapsed && tabs.getSelectedIndex() == tabs.indexOfComponent(entry.component) ) 219 entry.notify = 0; 220 setFont(entry.notify > 0 ? boldFont : normalFont); 213 221 panel.updateTitleAlarm(); 214 222 } … … 220 228 public JTextPane pane; 221 229 public JScrollPane component; 222 public booleannotify;230 public int notify; 223 231 224 232 } -
applications/editors/josm/plugins/geochat/src/geochat/GeoChatPanel.java
r29568 r29571 104 104 105 105 private String autoCompleteUser( String word ) { 106 return word; // todo: write autocomplete 106 String result = null; 107 for( String user : users.keySet() ) { 108 if( user.startsWith(word) ) { 109 if( result == null ) 110 result = user; 111 else { 112 int i = word.length(); 113 while( i < result.length() && i < user.length() && result.charAt(i) == user.charAt(i) ) 114 i++; 115 if( i < result.length() ) 116 result = result.substring(0, i); 117 } 118 } 119 } 120 return result; 107 121 } 108 122 … … 245 259 StringBuilder sb = new StringBuilder(); 246 260 for( ChatMessage msg : messages ) { 247 formatMessage(sb, msg); 248 if( msg.isIncoming() ) { 249 // todo: alarm=2 for private messages 250 alarm = 1; 261 boolean important = msg.isIncoming() && containsName(msg.getMessage()); 262 if( msg.isIncoming() && alarm < 2 ) { 263 alarm = important ? 2 : 1; 251 264 } 265 if( important ) { 266 // add buffer, then add current line with italic, then clear buffer 267 chatPanes.addLineToPublic(sb.toString()); 268 sb.setLength(0); 269 formatMessage(sb, msg); 270 chatPanes.addLineToPublicEm(sb.toString()); 271 sb.setLength(0); 272 } else 273 formatMessage(sb, msg); 252 274 } 253 275 chatPanes.addLineToPublic(sb.toString()); 254 276 if( alarm > 0 ) 255 chatPanes.notify(null, alarm > 1); 256 } 277 chatPanes.notify(null, alarm); 278 } 279 } 280 281 private boolean containsName( String message ) { 282 String userName = connection.getUserName(); 283 int length = userName.length(); 284 int i = message.indexOf(userName); 285 while( i >= 0 ) { 286 if( (i == 0 || !Character.isJavaIdentifierPart(message.charAt(i - 1))) 287 && (i + length >= message.length() || !Character.isJavaIdentifierPart(message.charAt(i + length))) ) 288 return true; 289 i = message.indexOf(userName, i + 1); 290 } 291 return false; 257 292 } 258 293 … … 265 300 chatPanes.addLineToChatPane(msg.isIncoming() ? msg.getAuthor() : msg.getRecipient(), sb.toString()); 266 301 if( msg.isIncoming() ) 267 chatPanes.notify(msg.getAuthor(), true);302 chatPanes.notify(msg.getAuthor(), 2); 268 303 } 269 304 } -
applications/editors/josm/plugins/geochat/src/geochat/JPanelTextField.java
r29568 r29571 1 1 package geochat; 2 2 3 import java.awt.KeyboardFocusManager; 3 4 import java.awt.event.KeyEvent; 5 import java.util.*; 4 6 import javax.swing.JTextField; 7 import javax.swing.KeyStroke; 5 8 import org.openstreetmap.josm.Main; 6 9 … … 12 15 */ 13 16 public class JPanelTextField extends JTextField { 17 18 public JPanelTextField() { 19 setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, new HashSet<KeyStroke>()); 20 } 14 21 15 22 @Override … … 24 31 } 25 32 } else if( code == KeyEvent.VK_TAB ) { 26 String word = ""; // todo: get the word 27 String complete = word == null ? null : autoComplete(word); 28 if( complete != null && !complete.equals(word) ) { 29 // todo: replace the word 33 String text = getText(); 34 int caret = getCaretPosition(); 35 int start = caret - 1; 36 while( start >= 0 && Character.isJavaIdentifierPart(text.charAt(start)) ) 37 start--; 38 start++; 39 System.out.println("Autocomplete! Word " + start + "-" + caret + " (not inclusive)"); 40 if( start < caret ) { 41 String word = text.substring(start, caret); 42 String complete = word == null ? null : autoComplete(word); 43 if( complete != null && !complete.equals(word) ) { 44 StringBuilder sb = new StringBuilder(); 45 if( start > 0 ) 46 sb.append(text.substring(0, start)); 47 sb.append(complete); 48 if( caret < text.length() ) 49 sb.append(text.substring(caret)); 50 setText(sb.toString()); 51 setCaretPosition(start + complete.length()); 52 } 30 53 } 31 54 } else if( code == KeyEvent.VK_ESCAPE ) {
Note:
See TracChangeset
for help on using the changeset viewer.