Search in sources :

Example 1 with SearchSettings

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();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) Point(java.awt.Point) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) LatLon(net.osmand.data.LatLon) ActionListener(java.awt.event.ActionListener) SearchSettings(net.osmand.search.core.SearchSettings) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) FocusListener(java.awt.event.FocusListener)

Example 2 with SearchSettings

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();
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) ActionEvent(java.awt.event.ActionEvent) SearchResult(net.osmand.search.core.SearchResult) Point(java.awt.Point) Point(java.awt.Point) LatLon(net.osmand.data.LatLon) ActionListener(java.awt.event.ActionListener) SearchSettings(net.osmand.search.core.SearchSettings) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) Street(net.osmand.data.Street) JMenuItem(javax.swing.JMenuItem)

Example 3 with SearchSettings

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);
}
Also used : SearchSettings(net.osmand.search.core.SearchSettings)

Example 4 with SearchSettings

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;
    }
}
Also used : LatLon(net.osmand.data.LatLon) SearchSettings(net.osmand.search.core.SearchSettings)

Example 5 with SearchSettings

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);
}
Also used : SearchSettings(net.osmand.search.core.SearchSettings)

Aggregations

SearchSettings (net.osmand.search.core.SearchSettings)24 LatLon (net.osmand.data.LatLon)11 SearchResult (net.osmand.search.core.SearchResult)7 SearchResultCollection (net.osmand.search.SearchUICore.SearchResultCollection)6 SearchPhrase (net.osmand.search.core.SearchPhrase)6 ArrayList (java.util.ArrayList)4 SpannableString (android.text.SpannableString)3 SearchWord (net.osmand.search.core.SearchWord)3 SuppressLint (android.annotation.SuppressLint)2 Bundle (android.os.Bundle)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Point (java.awt.Point)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Test (org.junit.Test)2