use of net.osmand.search.core.SearchSettings in project OsmAnd-tools by osmandapp.
the class OsmExtractionUI method updateStatusField.
private void updateStatusField(final JTextField statusField) {
popup = new JScrollPopupMenu();
popup.setMaximumVisibleRows(25);
popup.setFocusable(false);
searchUICore.setOnResultsComplete(new Runnable() {
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateSearchResult(statusField, searchUICore.getCurrentSearchResult(), true);
}
});
}
});
statusField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
// if(e.getOppositeComponent() != popup) {
// popup.setVisible(false);
// }
}
@Override
public void focusGained(FocusEvent e) {
popup.setFocusable(false);
SearchSettings settings = searchUICore.getPhrase().getSettings().setOriginalLocation(new LatLon(mapPanel.getLatitude(), mapPanel.getLongitude()));
settings = settings.setLang(DataExtractionSettings.getSettings().getSearchLocale(), false);
searchUICore.updateSettings(settings);
}
});
statusField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
mapPanel.setStatusField(null);
if (e.getKeyCode() == KeyEvent.VK_DOWN && popup.getComponentCount() > 0) {
popup.setVisible(false);
popup.setFocusable(true);
Point p = statusField.getLocation();
popup.show(e.getComponent(), p.x, p.y - 4);
// popup.show();
popup.requestFocus();
return;
}
}
@Override
public void keyTyped(KeyEvent e) {
mapPanel.setStatusField(null);
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
return;
}
String text = statusField.getText();
int ps = statusField.getCaretPosition();
if (e.getKeyChar() == '\b') {
// nothing
} else if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
if (ps >= text.length()) {
text += e.getKeyChar();
} else {
text = text.substring(0, ps) + e.getKeyChar() + text.substring(ps);
}
}
SearchSettings settings = searchUICore.getPhrase().getSettings();
if (settings.getRadiusLevel() != 1) {
searchUICore.updateSettings(settings.setRadiusLevel(1));
}
SearchResultCollection c = null;
if (!text.contains("#map")) {
c = searchUICore.search(text, true, null);
}
if (c != null) {
updateSearchResult(statusField, c, false);
}
}
});
statusField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
mapPanel.setStatusField(statusField);
String txt = statusField.getText();
int i = txt.indexOf("#map=");
if (i != -1) {
String[] vs = txt.substring(i + "#map=".length()).split("/");
mapPanel.setLatLon(Float.parseFloat(vs[1]), Float.parseFloat(vs[2]));
mapPanel.setZoom(Integer.parseInt(vs[0]));
}
mapPanel.refresh();
}
});
}
use of net.osmand.search.core.SearchSettings in project OsmAnd-tools by osmandapp.
the class OsmExtractionUI method updateSearchResult.
private void updateSearchResult(final JTextField statusField, SearchResultCollection res, boolean addMore) {
popup.setVisible(false);
popup.removeAll();
if (res.getCurrentSearchResults().size() > 0 || addMore) {
int count = 30;
if (addMore) {
JMenuItem mi = new JMenuItem();
mi.setText("Results " + res.getCurrentSearchResults().size() + ", radius " + res.getPhrase().getRadiusLevel() + " (show more...)");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SearchSettings settings = searchUICore.getPhrase().getSettings();
searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
SearchResultCollection collection = searchUICore.search(statusField.getText(), true, null);
updateSearchResult(statusField, collection, false);
}
});
popup.add(mi);
}
for (final SearchResult sr : res.getCurrentSearchResults()) {
count--;
if (count == 0) {
// break;
}
JMenuItem mi = new JMenuItem();
LatLon location = res.getPhrase().getLastTokenLocation();
String locationString = "";
if (sr.location != null) {
locationString = ((int) MapUtils.getDistance(location, sr.location)) / 1000.f + " km";
}
if (!Algorithms.isEmpty(sr.localeRelatedObjectName)) {
locationString += " " + sr.localeRelatedObjectName;
if (sr.distRelatedObjectName != 0) {
locationString += " " + (int) (sr.distRelatedObjectName / 1000.f) + " km";
}
}
if (sr.objectType == ObjectType.HOUSE) {
if (sr.relatedObject instanceof Street) {
locationString += " " + ((Street) sr.relatedObject).getCity().getName();
}
}
if (sr.objectType == ObjectType.LOCATION) {
locationString += " " + osmandRegions.getCountryName(sr.location);
}
if (sr.object instanceof Amenity) {
locationString += " " + ((Amenity) sr.object).getSubType();
if (((Amenity) sr.object).isClosed()) {
locationString += " (CLOSED)";
}
}
mi.setText(sr.localeName + " [" + sr.getFoundWordCount() + ", " + sr.objectType + "] " + locationString);
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mapPanel.setStatusField(null);
if (sr.location != null) {
mapPanel.setLatLon(sr.location.getLatitude(), sr.location.getLongitude());
mapPanel.setZoom(sr.preferredZoom);
}
searchUICore.selectSearchResult(sr);
String txt = searchUICore.getPhrase().getText(true);
statusField.setText(txt);
searchUICore.search(txt, false, null);
statusField.requestFocus();
// statusField.setCaretPosition(statusField.getText().length());
}
});
popup.add(mi);
}
// .getCaret().getMagicCaretPosition();
Point p = statusField.getLocation();
if (popup.isVisible()) {
popup.setVisible(true);
} else {
popup.show(statusField.getParent(), p.x, p.y + statusField.getHeight() + 4);
// popup.show();
}
}
}
use of net.osmand.search.core.SearchSettings in project Osmand by osmandapp.
the class QuickSearchDialogFragment method startAddressSearch.
private void startAddressSearch() {
SearchSettings settings = searchUICore.getSearchSettings().setEmptyQueryAllowed(true).setSortByName(false).setSearchTypes(ObjectType.CITY, ObjectType.VILLAGE, ObjectType.POSTCODE, ObjectType.HOUSE, ObjectType.STREET_INTERSECTION, ObjectType.STREET, ObjectType.LOCATION, ObjectType.PARTIAL_LOCATION).setRadiusLevel(1);
searchUICore.updateSettings(settings);
}
use of net.osmand.search.core.SearchSettings in project Osmand by osmandapp.
the class QuickSearchDialogFragment method show.
public void show() {
if (useMapCenter) {
LatLon mapCenter = getMapActivity().getMapView().getCurrentRotatedTileBox().getCenterLatLon();
SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation(new LatLon(mapCenter.getLatitude(), mapCenter.getLongitude()));
searchUICore.updateSettings(ss);
updateUseMapCenterUI();
updateLocationUI(mapCenter, null);
}
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
getDialog().show();
paused = false;
hidden = false;
if (interruptedSearch) {
addMoreButton(true);
interruptedSearch = false;
}
}
use of net.osmand.search.core.SearchSettings in project Osmand by osmandapp.
the class QuickSearchDialogFragment method startPostcodeSearch.
private void startPostcodeSearch() {
SearchSettings settings = searchUICore.getSearchSettings().setSearchTypes(ObjectType.POSTCODE).setEmptyQueryAllowed(false).setSortByName(true).setRadiusLevel(1);
searchUICore.updateSettings(settings);
}
Aggregations