Changeset 22812 in osm for applications/editors/josm/plugins/czechaddress/src
- Timestamp:
- 2010-08-27T15:00:44+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/gui/LocationSelector.java
r18897 r22812 33 33 protected ElementWithStreets selectedElement; 34 34 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>(); 35 39 36 40 … … 52 56 setContent(mainPanel); 53 57 setButtonIcons(new String[] {"ok.png", "cancel.png"}); 58 setDefaultButton(1); 54 59 setupDialog(); 55 60 … … 58 63 suburbComboBox.setRenderer(new SuburbRenderer()); 59 64 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); 67 73 } 68 74 69 75 /** 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. 71 78 * 72 * @deprecated73 79 */ 74 @Deprecated 75 private void autodetectLocation() { 80 private void initLocationHints() { 76 81 boolean assertions = false; 77 82 assert assertions = true; … … 79 84 OsmPrimitive bestFit = null; 80 85 double bestLen = 0; 81 82 // TODO: center se počítá jako střed stažené oblasti. Měl by to však83 // být střed obrazovky... Jen vědět, jak získat souřadnici středu84 // obrazovky.85 86 86 87 BoundingXYVisitor visitor = new BoundingXYVisitor(); … … 96 97 97 98 try { 98 center = Main.proj.eastNorth2latlon( visitor.getBounds().getCenter());99 center = Main.proj.eastNorth2latlon(Main.map.mapView.getCenter()); 99 100 } catch (Exception e) { 100 101 System.err.println("AUTO: No bounds to determine autolocation."); … … 143 144 for (ViToCi obec : oblast.getViToCis()) { 144 145 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); 155 152 } 156 153 } else { 157 154 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); 163 159 } 164 160 } … … 167 163 } 168 164 } 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; 169 186 } 170 187 … … 278 295 if (oblast == null) return; 279 296 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)); 281 301 vitociComboBox.setEnabled(vitociComboBox.getModel().getSize() > 1); 282 302 vitociComboBoxItemStateChanged(null); … … 293 313 suburbs[i] = obec.getSuburbs().get(i); 294 314 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)); 296 319 } else 297 320 suburbComboBox.setModel(new DefaultComboBoxModel()); … … 345 368 setText(((AddressElement) value).getName()); 346 369 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 347 376 return c; 348 377 } … … 360 389 // setText(((ViToCi) value).getName() + ", všechny části [experimentální]"); 361 390 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)); 364 395 365 396 return c;
Note:
See TracChangeset
for help on using the changeset viewer.