Changeset 29541 in osm
- Timestamp:
- 2013-04-28T22:52:00+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/ChatServerConnection.java
r29540 r29541 32 32 requestThread = new LogRequest(); 33 33 new Thread(requestThread).start(); 34 checkLogin();35 34 } 36 35 … … 65 64 */ 66 65 public void checkLogin() { 67 final int uid = Main.pref.getInteger("geocha r.lastuid", 0);66 final int uid = Main.pref.getInteger("geochat.lastuid", 0); 68 67 if( uid <= 0 ) return; 69 68 String query = "whoami&uid=" + uid; 70 69 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 71 70 public void processJson( JSONObject json ) { 72 if( json != null && json.has("name") ) {71 if( json != null && json.has("name") ) 73 72 login(uid, json.getString("name")); 74 }75 73 } 76 74 }); … … 243 241 244 242 public void run() { 245 int interval = Main.pref.getInteger("geochat.interval", 3);243 int interval = Main.pref.getInteger("geochat.interval", 2); 246 244 while( !stopping ) { 247 245 process(); … … 329 327 String author = msg.getString("author"); 330 328 String message = msg.getString("message"); 331 ChatMessage cm = new ChatMessage(id, new LatLon(lat, lon), author, message, new Date(timeStamp ));329 ChatMessage cm = new ChatMessage(id, new LatLon(lat, lon), author, message, new Date(timeStamp * 1000)); 332 330 cm.setPrivate(priv); 333 331 result.add(cm); -
applications/editors/josm/plugins/geochat/src/geochat/GeoChatPanel.java
r29540 r29541 2 2 3 3 import java.awt.BorderLayout; 4 import java.awt.Font; 4 5 import java.awt.event.ActionEvent; 5 6 import java.awt.event.ActionListener; 7 import java.awt.event.KeyEvent; 6 8 import java.text.SimpleDateFormat; 7 9 import java.util.*; … … 25 27 private JTextField input; 26 28 private JTabbedPane tabs; 27 private JPanel chatPanel;28 29 private JComponent noData; 29 30 private JPanel loginPanel; … … 36 37 chatPane = new JTextPane(); 37 38 chatPane.setEditable(false); 39 Font font = chatPane.getFont(); 40 chatPane.setFont(font.deriveFont(font.getSize2D() - 2)); 38 41 39 42 noData = new JLabel(tr("Zoom in to see messages"), SwingConstants.CENTER); 40 43 41 44 tabs = new JTabbedPane(); 42 tabs.addTab(tr("Public"), noData);45 tabs.addTab(tr("Public"), chatPane); 43 46 44 input = new JTextField(); 47 input = new JTextField() { 48 @Override 49 protected void processKeyEvent( KeyEvent e ) { 50 if( e.getID() == KeyEvent.KEY_PRESSED ) { 51 int code = e.getKeyCode(); 52 if( code == KeyEvent.VK_ENTER ) { 53 String text = input.getText(); 54 if( text.length() > 0 ) { 55 connection.postMessage(text); 56 input.setText(""); 57 } 58 } else if( code == KeyEvent.VK_TAB ) { 59 // todo: autocomplete name 60 } else if( code == KeyEvent.VK_ESCAPE ) { 61 if( Main.map != null && Main.map.mapView != null ) 62 Main.map.mapView.requestFocus(); 63 } 64 // Do not pass other events to JOSM 65 if( code != KeyEvent.VK_LEFT && code != KeyEvent.VK_HOME && code != KeyEvent.VK_RIGHT 66 && code != KeyEvent.VK_END && code != KeyEvent.VK_BACK_SPACE && code != KeyEvent.VK_DELETE ) 67 e.consume(); 68 } 69 super.processKeyEvent(e); 70 } 45 71 46 gcPanel = new JPanel(new BorderLayout()); 47 gcPanel.add(tabs, BorderLayout.CENTER); 48 gcPanel.add(input, BorderLayout.SOUTH); 72 }; 49 73 50 loginPanel = new JPanel(new BorderLayout());51 74 final JTextField nameField = new JTextField(); 52 75 String userName = JosmUserIdentityManager.getInstance().getUserName(); … … 55 78 if( userName.contains("@") ) 56 79 userName = userName.substring(0, userName.indexOf('@')); 57 nameField.setText( name);80 nameField.setText(userName); 58 81 59 82 JButton loginButton = new JButton(tr("Login")); … … 64 87 }); 65 88 89 loginPanel = new JPanel(new BorderLayout()); 66 90 loginPanel.add(nameField, BorderLayout.CENTER); 67 91 loginPanel.add(loginButton, BorderLayout.EAST); 92 loginPanel.add(Box.createVerticalGlue(), BorderLayout.NORTH); 93 loginPanel.add(Box.createVerticalGlue(), BorderLayout.SOUTH); 68 94 69 95 gcPanel = new JPanel(new BorderLayout()); … … 73 99 // Start threads 74 100 connection = ChatServerConnection.getInstance(); 101 connection.addListener(this); 102 connection.checkLogin(); 75 103 } 76 104 77 105 public void loggedIn( String userName ) { 78 gcPanel.remove(0); 79 gcPanel.add(tabs, 0); 106 if( gcPanel.getComponentCount() == 1 ) { 107 gcPanel.remove(0); 108 gcPanel.add(tabs, BorderLayout.CENTER); 109 gcPanel.add(input, BorderLayout.SOUTH); 110 } 80 111 } 81 112 … … 89 120 public void statusChanged( boolean active ) { 90 121 tabs.setComponentAt(0, active ? chatPane : noData); 122 repaint(); 91 123 } 92 124 … … 99 131 chatPane.setText(""); 100 132 } 101 StringBu ffer sb = new StringBuffer();133 StringBuilder sb = new StringBuilder(); 102 134 for( ChatMessage msg : messages ) { 103 135 sb.append('\n'); -
applications/editors/josm/plugins/geochat/src/geochat/JsonQueryUtil.java
r29540 r29541 29 29 String serverURL = Main.pref.get("geochat.server", "http://zverik.dev.openstreetmap.org/osmochat.php?action="); 30 30 URL url = new URL(serverURL + query); 31 // System.out.println("GeoChat URL = " + url.toString()); 31 32 HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 32 33 connection.connect();
Note:
See TracChangeset
for help on using the changeset viewer.