Changeset 2499 in josm


Ignore:
Timestamp:
Nov 22, 2009 2:55:15 PM (4 years ago)
Author:
stoecker
Message:

see #3989 - subprojection fixes

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/ProjectionSubPrefs.java

    r2491 r2499  
    2323     * @return 
    2424     */ 
    25     public JPanel getPreferencePanel(); 
     25    public void setupPreferencePanel(JPanel p); 
    2626 
    2727    /** 
    2828     * Will be called if the preference dialog is dismissed. 
    2929     */ 
    30     public Collection<String> getPreferences(); 
     30    public Collection<String> getPreferences(JPanel p); 
    3131 
    3232    /** 
     
    4040     */ 
    4141    public void setPreferences(Collection<String> args); 
    42  
    43     /** 
    44      * Resets all variables related to the projection preferences so they may 
    45      * update the next time getPreferencePanel is called. 
    46      */ 
    47     public void destroyCachedPanel(); 
    4842} 
  • trunk/src/org/openstreetmap/josm/data/projection/UTM.java

    r2496 r2499  
    377377    } 
    378378 
    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(); 
    386381        for(int i = 1; i <= 60; i++) { 
    387382            prefcb.addItem(i); 
     
    389384 
    390385        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)) 
    401397            return null; 
    402         int zone = prefcb.getSelectedIndex() + 1; 
     398        int zone = ((JComboBox)prefcb).getSelectedIndex() + 1; 
    403399        return Collections.singleton(Integer.toString(zone)); 
    404     } 
    405  
    406     public void destroyCachedPanel() { 
    407         prefpanel = null; 
    408         prefcb = null; 
    409400    } 
    410401 
  • trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java

    r2496 r2499  
    6666 
    6767    public void addGui(PreferenceDialog gui) { 
    68         clearSubProjPrefs(); 
    6968        setupProjectionCombo(); 
    7069 
     
    112111        Collection<String> prefs = null; 
    113112        if(projHasPrefs(proj)) 
    114             prefs = ((ProjectionSubPrefs) proj).getPreferences(); 
     113            prefs = ((ProjectionSubPrefs) proj).getPreferences(projSubPrefPanel); 
    115114 
    116115        Main.pref.put("projection", projname); 
     
    121120            CoordinateFormat.setCoordinateFormat((CoordinateFormat)coordinatesCombo.getSelectedItem()); 
    122121        } 
    123  
    124         // We get the change to remove these panels on closing the preferences 
    125         // dialog, so take it. TODO: Make this work always, even when canceling 
    126         // the dialog 
    127         clearSubProjPrefs(); 
    128122 
    129123        return false; 
     
    182176    } 
    183177 
     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 
    184195    /** 
    185196     * Handles all the work related to update the projection-specific 
     
    192203        } else { 
    193204            ProjectionSubPrefs projPref = (ProjectionSubPrefs) proj; 
    194             projSubPrefPanel = projPref.getPreferencePanel(); 
     205            projSubPrefPanel = new SBPanel(proj); 
     206            projPref.setupPreferencePanel(projSubPrefPanel); 
    195207        } 
    196208 
     
    233245        }); 
    234246    } 
    235  
    236     /** 
    237      * Method to clean up the preference panels made by each projection. This 
    238      * 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 the 
    240      * outside 
    241      */ 
    242     static private void clearSubProjPrefs() { 
    243         for(Projection proj : Projection.allProjections) { 
    244             if(projHasPrefs(proj)) { 
    245                 ((ProjectionSubPrefs) proj).destroyCachedPanel(); 
    246             } 
    247         } 
    248     } 
    249247} 
Note: See TracChangeset for help on using the changeset viewer.