Changeset 22812 in osm for applications


Ignore:
Timestamp:
2010-08-27T15:00:44+02:00 (14 years ago)
Author:
rcernoch
Message:

CzechAddress: LocationSelector uses better method for selecting the desired region. THX to Libor!

Location:
applications/editors/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/czechaddress/build.xml

    r22015 r22812  
    9292            <jvmarg value="-Xdebug"/>
    9393            <jvmarg value="-ea"/>
     94            <jvmarg value="-Djava.net.useSystemProxies=true"/>
    9495            <classpath>
    9596                <pathelement location="${plugin.build.dir}"/>
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/LocationSelector.java

    r18897 r22812  
    3333    protected ElementWithStreets selectedElement;
    3434    protected ArrayList<ItemListener> listeners = new ArrayList<ItemListener>();
     35    int regionHlIndex, vitociHlIndex, suburbHlIndex;
     36    protected ArrayList<AddressElement> hlRegions = new ArrayList<AddressElement>();
     37    protected ArrayList<AddressElement> hlViToCis = new ArrayList<AddressElement>();
     38    protected ArrayList<AddressElement> hlSuburbs = new ArrayList<AddressElement>();
    3539
    3640
     
    5256        setContent(mainPanel);
    5357        setButtonIcons(new String[] {"ok.png", "cancel.png"});
     58        setDefaultButton(1);
    5459        setupDialog();
    5560
     
    5863        suburbComboBox.setRenderer(new SuburbRenderer());
    5964
    60         oblastComboBox.setModel(new DefaultComboBoxModel(
    61                 Database.getInstance().regions.toArray()));
    62 
    63         try {
    64             autodetectLocation();
    65         } catch (Exception e) {}
    66         //oblastComboBoxItemStateChanged(null);
     65        initLocationHints();
     66
     67        DefaultComboBoxModel regions = new DefaultComboBoxModel(Database.getInstance().regions.toArray());
     68        regionHlIndex = reshuffleListItems(regions, hlRegions);
     69        oblastComboBox.setModel(regions);
     70        oblastComboBox.setSelectedItem(regions.getElementAt(0));
     71
     72        oblastComboBoxItemStateChanged(null);
    6773    }
    6874
    6975    /**
    70      * Hardly ever working method for autodetecting the current location.
     76     * Guess location name from the map and put all matches to the top of the
     77     * list.
    7178     *
    72      * @deprecated
    7379     */
    74     @Deprecated
    75         private void autodetectLocation() {
     80        private void initLocationHints() {
    7681        boolean assertions = false;
    7782        assert  assertions = true;
     
    7984        OsmPrimitive bestFit = null;
    8085        double bestLen = 0;
    81 
    82         // TODO: center se počítá jako střed stažené oblasti. Měl by to však
    83         // být střed obrazovky... Jen vědět, jak získat souřadnici středu
    84         // obrazovky.
    8586
    8687        BoundingXYVisitor visitor = new BoundingXYVisitor();
     
    9697
    9798        try {
    98             center = Main.proj.eastNorth2latlon(visitor.getBounds().getCenter());
     99            center = Main.proj.eastNorth2latlon(Main.map.mapView.getCenter());
    99100        } catch (Exception e) {
    100101            System.err.println("AUTO: No bounds to determine autolocation.");
     
    143144                for (ViToCi obec : oblast.getViToCis()) {
    144145                    if (!bestFit.get("place").equals("suburb")) {
    145                         if (obec.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) {
    146                             oblastComboBox.setSelectedItem(oblast);
    147                             vitociComboBox.setSelectedItem(obec);
    148                             for (Suburb castObce : obec.getSuburbs()) {
    149                                 if (castObce.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) {
    150                                     suburbComboBox.setSelectedItem(castObce);
    151                                     break;
    152                                 }
    153                             }
    154                             break;
     146                        if (obec.getName().equalsIgnoreCase(bestFit.get("name"))) {
     147                            hlRegions.add(oblast);
     148                            hlViToCis.add(obec);
     149                            for (Suburb castObce : obec.getSuburbs())
     150                                if (castObce.getName().equalsIgnoreCase(bestFit.get("name")))
     151                                    hlSuburbs.add(castObce);
    155152                        }
    156153                    } else {
    157154                        for (Suburb castObce : obec.getSuburbs()) {
    158                             if (castObce.getName().toUpperCase().equals(bestFit.get("name").toUpperCase())) {
    159                                 oblastComboBox.setSelectedItem(oblast);
    160                                 vitociComboBox.setSelectedItem(obec);
    161                                 suburbComboBox.setSelectedItem(castObce);
    162                                 break;
     155                            if (castObce.getName().equalsIgnoreCase(bestFit.get("name"))) {
     156                                hlRegions.add(oblast);
     157                                hlViToCis.add(obec);
     158                                hlSuburbs.add(castObce);
    163159                            }
    164160                        }
     
    167163            }
    168164        }
     165    }
     166
     167    /**
     168    * Reshuffle items in combo box list, put those in hlList to the
     169    * beginning, return number of moved items.
     170    */
     171
     172    private int reshuffleListItems(DefaultComboBoxModel list, final ArrayList<AddressElement> hlList) {
     173        int curHlIndex = 0;
     174
     175        for (int i = 0; i < list.getSize(); i++)
     176            for (int j = 0; j < hlList.size(); j++) {
     177                Object t = list.getElementAt(i);
     178                if (t == hlList.get(j)) {
     179                    list.removeElementAt(i);
     180                    list.insertElementAt(t, curHlIndex++);
     181                    break;
     182                }
     183            }
     184
     185        return curHlIndex;
    169186    }
    170187
     
    278295        if (oblast == null) return;
    279296
    280         vitociComboBox.setModel(new DefaultComboBoxModel(oblast.getViToCis().toArray()));
     297        DefaultComboBoxModel vitocis = new DefaultComboBoxModel(oblast.getViToCis().toArray());
     298        vitociHlIndex = reshuffleListItems(vitocis, hlViToCis);
     299        vitociComboBox.setModel(vitocis);
     300        vitociComboBox.setSelectedItem(vitocis.getElementAt(0));
    281301        vitociComboBox.setEnabled(vitociComboBox.getModel().getSize() > 1);
    282302        vitociComboBoxItemStateChanged(null);
     
    293313                suburbs[i] = obec.getSuburbs().get(i);
    294314            suburbs[obec.getSuburbs().size()] = obec;
    295             suburbComboBox.setModel(new DefaultComboBoxModel(suburbs));
     315            DefaultComboBoxModel suburbsList = new DefaultComboBoxModel(suburbs);
     316            suburbHlIndex = reshuffleListItems(suburbsList, hlSuburbs);
     317            suburbComboBox.setModel(suburbsList);
     318            suburbComboBox.setSelectedItem(suburbsList.getElementAt(0));
    296319        } else
    297320            suburbComboBox.setModel(new DefaultComboBoxModel());
     
    345368                setText(((AddressElement) value).getName());
    346369
     370            if ((value instanceof Region && index < regionHlIndex) ||
     371                (value instanceof ViToCi && index < vitociHlIndex))
     372                setFont(getFont().deriveFont(Font.BOLD));
     373            else
     374                setFont(getFont().deriveFont(Font.PLAIN));
     375
    347376            return c;
    348377        }
     
    360389//                setText(((ViToCi) value).getName() + ", všechny části [experimentální]");
    361390                setText("všechny části obce [experimentální]");
    362             } else
    363                 setFont(getFont().deriveFont(Font.PLAIN));
     391            } else if (index < suburbHlIndex)
     392                    setFont(getFont().deriveFont(Font.BOLD));
     393                else
     394                    setFont(getFont().deriveFont(Font.PLAIN));
    364395
    365396            return c;
Note: See TracChangeset for help on using the changeset viewer.