Changeset 2499 in josm
- Timestamp:
- 2009-11-22T14:55:15+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/projection/ProjectionSubPrefs.java
r2491 r2499 23 23 * @return 24 24 */ 25 public JPanel getPreferencePanel();25 public void setupPreferencePanel(JPanel p); 26 26 27 27 /** 28 28 * Will be called if the preference dialog is dismissed. 29 29 */ 30 public Collection<String> getPreferences( );30 public Collection<String> getPreferences(JPanel p); 31 31 32 32 /** … … 40 40 */ 41 41 public void setPreferences(Collection<String> args); 42 43 /**44 * Resets all variables related to the projection preferences so they may45 * update the next time getPreferencePanel is called.46 */47 public void destroyCachedPanel();48 42 } -
trunk/src/org/openstreetmap/josm/data/projection/UTM.java
r2496 r2499 377 377 } 378 378 379 private JPanel prefpanel = null; 380 private JComboBox prefcb = null; 381 public JPanel getPreferencePanel() { 382 if(prefpanel != null) 383 return prefpanel; 384 385 prefcb = new JComboBox(); 379 public void setupPreferencePanel(JPanel p) { 380 JComboBox prefcb = new JComboBox(); 386 381 for(int i = 1; i <= 60; i++) { 387 382 prefcb.addItem(i); … … 389 384 390 385 prefcb.setSelectedIndex(zone - 1); 391 prefpanel = new JPanel(new GridBagLayout()); 392 prefpanel.add(new JLabel(tr("UTM Zone")), GBC.std().insets(5,5,0,5)); 393 prefpanel.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 394 prefpanel.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL)); 395 prefpanel.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 396 return prefpanel; 397 } 398 399 public Collection<String> getPreferences() { 400 if(prefcb == null) 386 p.setLayout(new GridBagLayout()); 387 p.add(new JLabel(tr("UTM Zone")), GBC.std().insets(5,5,0,5)); 388 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 389 /* Note: we use component position 2 below to find this again */ 390 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL)); 391 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 392 } 393 394 public Collection<String> getPreferences(JPanel p) { 395 Object prefcb = p.getComponent(2); 396 if(!(prefcb instanceof JComboBox)) 401 397 return null; 402 int zone = prefcb.getSelectedIndex() + 1;398 int zone = ((JComboBox)prefcb).getSelectedIndex() + 1; 403 399 return Collections.singleton(Integer.toString(zone)); 404 }405 406 public void destroyCachedPanel() {407 prefpanel = null;408 prefcb = null;409 400 } 410 401 -
trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java
r2496 r2499 66 66 67 67 public void addGui(PreferenceDialog gui) { 68 clearSubProjPrefs();69 68 setupProjectionCombo(); 70 69 … … 112 111 Collection<String> prefs = null; 113 112 if(projHasPrefs(proj)) 114 prefs = ((ProjectionSubPrefs) proj).getPreferences( );113 prefs = ((ProjectionSubPrefs) proj).getPreferences(projSubPrefPanel); 115 114 116 115 Main.pref.put("projection", projname); … … 121 120 CoordinateFormat.setCoordinateFormat((CoordinateFormat)coordinatesCombo.getSelectedItem()); 122 121 } 123 124 // We get the change to remove these panels on closing the preferences125 // dialog, so take it. TODO: Make this work always, even when canceling126 // the dialog127 clearSubProjPrefs();128 122 129 123 return false; … … 182 176 } 183 177 178 private class SBPanel extends JPanel 179 { 180 private Projection p; 181 public SBPanel(Projection pr) 182 { 183 super(); 184 p = pr; 185 } 186 @Override 187 public void paint(java.awt.Graphics g) 188 { 189 super.paint(g); 190 ((ProjectionSubPrefs) p).setPreferences(((ProjectionSubPrefs) p).getPreferences(this)); 191 updateMeta(p); 192 } 193 }; 194 184 195 /** 185 196 * Handles all the work related to update the projection-specific … … 192 203 } else { 193 204 ProjectionSubPrefs projPref = (ProjectionSubPrefs) proj; 194 projSubPrefPanel = projPref.getPreferencePanel(); 205 projSubPrefPanel = new SBPanel(proj); 206 projPref.setupPreferencePanel(projSubPrefPanel); 195 207 } 196 208 … … 233 245 }); 234 246 } 235 236 /**237 * Method to clean up the preference panels made by each projection. This238 * requires them to be regenerated when the prefs dialog is opened again,239 * but this also makes them react to changes to their preferences from the240 * outside241 */242 static private void clearSubProjPrefs() {243 for(Projection proj : Projection.allProjections) {244 if(projHasPrefs(proj)) {245 ((ProjectionSubPrefs) proj).destroyCachedPanel();246 }247 }248 }249 247 }
Note:
See TracChangeset
for help on using the changeset viewer.