Changeset 29582 in osm
- Timestamp:
- 2013-05-11T20:59:05+02:00 (12 years ago)
- Location:
- applications/editors/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geochat/src/geochat/ChatPaneManager.java
r29576 r29582 133 133 chatPane.setEditable(false); 134 134 Font font = chatPane.getFont(); 135 chatPane.setFont(font.deriveFont(font.getSize2D() - 2)); 135 float size = -1.0f; // Main.pref.getInteger("geochat.fontsize", -1); <- we don't need this 136 if( size < 8 ) 137 size += font.getSize2D(); 138 chatPane.setFont(font.deriveFont(size)); 136 139 // DefaultCaret caret = (DefaultCaret)chatPane.getCaret(); // does not work 137 140 // caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); -
applications/editors/josm/plugins/geochat/src/geochat/ChatServerConnection.java
r29576 r29582 65 65 */ 66 66 public void checkLogin() { 67 autoLogin(null); 68 } 69 70 /** 71 * Test that userId is still active, if not, tries to login with given user name. 72 * Does not autologin, if userName is null, obviously. 73 */ 74 public void autoLogin( final String userName ) { 67 75 final int uid = Main.pref.getInteger("geochat.lastuid", 0); 68 if( uid <= 0 ) return; 69 String query = "whoami&uid=" + uid; 70 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 71 public void processJson( JSONObject json ) { 72 if( json != null && json.has("name") ) 73 login(uid, json.getString("name")); 74 } 75 }); 76 if( uid <= 0 ) { 77 if( userName != null && userName.length() > 1 ) 78 login(userName); 79 } else { 80 String query = "whoami&uid=" + uid; 81 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 82 public void processJson( JSONObject json ) { 83 if( json != null && json.has("name") ) 84 login(uid, json.getString("name")); 85 else if( userName != null && userName.length() > 1 ) 86 login(userName); 87 } 88 }); 89 } 90 } 91 92 /** 93 * Waits until {@link #getPosition()} is not null, then calls {@link #autoLogin(java.lang.String)}. 94 * If two seconds have passed, stops the waiting. Doesn't wait if userName is empty. 95 */ 96 public void autoLoginWithDelay( final String userName ) { 97 if( userName == null || userName.length() == 0 ) { 98 checkLogin(); 99 return; 100 } 101 new Thread(new Runnable() { 102 public void run() { 103 try { 104 int cnt = 10; 105 while( getPosition() == null && cnt-- > 0 ) 106 Thread.sleep(200); 107 } catch( InterruptedException e ) {} 108 autoLogin(userName); 109 } 110 }).start(); 76 111 } 77 112 -
applications/editors/josm/plugins/geochat/src/geochat/GeoChatPanel.java
r29581 r29582 3 3 import java.awt.*; 4 4 import java.awt.event.*; 5 import java.awt.geom.Rectangle2D;6 5 import java.text.SimpleDateFormat; 7 6 import java.util.*; … … 57 56 }; 58 57 59 loginPanel = createLoginPanel(); 58 String defaultUserName = constructUserName(); 59 loginPanel = createLoginPanel(defaultUserName); 60 60 61 61 gcPanel = new JPanel(new BorderLayout()); … … 67 67 connection = ChatServerConnection.getInstance(); 68 68 connection.addListener(this); 69 connection.checkLogin(); 70 updateTitleAlarm(); 71 } 72 73 private JPanel createLoginPanel() { 74 final JTextField nameField = new JPanelTextField() { 75 @Override 76 protected void processEnter( String text ) { 77 connection.login(text); 78 } 79 }; 80 String userName = Main.pref.get("geochat.username", JosmUserIdentityManager.getInstance().getUserName()); 69 boolean autoLogin = Main.pref.get("geochat.username", null) == null ? false : Main.pref.getBoolean("geochat.autologin", true); 70 connection.autoLoginWithDelay(autoLogin ? defaultUserName : null); 71 updateTitleAlarm(); 72 } 73 74 private String constructUserName() { 75 String userName = Main.pref.get("geochat.username", null); // so the default is null 76 if( userName == null ) 77 userName = JosmUserIdentityManager.getInstance().getUserName(); 81 78 if( userName == null ) 82 79 userName = ""; … … 84 81 userName = userName.substring(0, userName.indexOf('@')); 85 82 userName = userName.replace(' ', '_'); 86 nameField.setText(userName); 83 return userName; 84 } 85 86 private JPanel createLoginPanel( String defaultUserName ) { 87 final JTextField nameField = new JPanelTextField() { 88 @Override 89 protected void processEnter( String text ) { 90 connection.login(text); 91 } 92 }; 93 nameField.setText(defaultUserName); 87 94 88 95 JButton loginButton = new JButton(tr("Login")); … … 94 101 nameField.setPreferredSize(new Dimension(nameField.getPreferredSize().width, loginButton.getPreferredSize().height)); 95 102 103 final JCheckBox autoLoginBox = new JCheckBox(tr("Enable autologin"), Main.pref.getBoolean("geochat.autologin", true)); 104 autoLoginBox.addActionListener(new ActionListener() { 105 public void actionPerformed( ActionEvent e ) { 106 Main.pref.put("geochat.autologin", autoLoginBox.isSelected()); 107 } 108 }); 109 96 110 JPanel panel = new JPanel(new GridBagLayout()); 97 111 panel.add(nameField, GBC.std().fill(GridBagConstraints.HORIZONTAL).insets(15, 0, 5, 0)); 98 panel.add(loginButton, GBC.std().fill(GridBagConstraints.NONE).insets(0, 0, 15, 0)); 112 panel.add(loginButton, GBC.eol().fill(GridBagConstraints.NONE).insets(0, 0, 15, 0)); 113 panel.add(autoLoginBox, GBC.std().insets(15, 0, 15, 0)); 99 114 return panel; 100 115 } … … 143 158 public void paint( Graphics2D g, MapView mv, Bounds bbox ) { 144 159 Graphics2D g2d = (Graphics2D)g.create(); 145 g2d.setColor(Color.yellow); 146 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f)); 147 148 int zoom = ChatServerConnection.getCurrentZoom(); 149 int radius = Math.max(zoom, 1) * 10; 150 if( zoom < 14 ) 151 radius /= 2; 152 153 Font font = g2d.getFont().deriveFont(Font.BOLD, Math.max(zoom * 2, 8)); 160 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 161 Composite ac04 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f); 162 Composite ac10 = g2d.getComposite(); 163 164 Font font = g2d.getFont().deriveFont(Font.BOLD, g2d.getFont().getSize2D() + 2.0f); 154 165 g2d.setFont(font); 155 166 FontMetrics fm = g2d.getFontMetrics(); 156 167 157 168 for( String user : users.keySet() ) { 169 int stringWidth = fm.stringWidth(user); 170 int radius = stringWidth / 2 + 10; 158 171 Point p = mv.getPoint(users.get(user)); 159 g2d.setColor(Color.yellow); 172 173 g2d.setComposite(ac04); 174 g2d.setColor(Color.white); 160 175 g2d.fillOval(p.x - radius, p.y - radius, radius * 2 + 1, radius * 2 + 1); 161 176 177 g2d.setComposite(ac10); 162 178 g2d.setColor(Color.black); 163 Rectangle2D rect = fm.getStringBounds(user, g2d); 164 g2d.drawString(user, p.x - Math.round(rect.getWidth() / 2), p.y); 179 g2d.drawString(user, p.x - stringWidth / 2, p.y + fm.getDescent()); 165 180 } 166 181 } -
applications/editors/josm/plugins/geochat/src/geochat/JPanelTextField.java
r29576 r29582 4 4 import java.awt.event.KeyEvent; 5 5 import java.util.*; 6 import javax.swing.JTextField;6 import org.openstreetmap.josm.gui.widgets.JosmTextField; 7 7 import javax.swing.KeyStroke; 8 8 import org.openstreetmap.josm.Main; … … 14 14 * @author zverik 15 15 */ 16 public class JPanelTextField extends J TextField {16 public class JPanelTextField extends JosmTextField { 17 17 18 18 public JPanelTextField() {
Note:
See TracChangeset
for help on using the changeset viewer.