Search in sources :

Example 1 with ResultBeatmap

use of com.github.mob41.osums.io.beatmap.ResultBeatmap in project osumer by mob41.

the class BeatmapSearchPanel method doSearch.

private void doSearch() {
    if (searchFld.getText().isEmpty()) {
        int option = JOptionPane.showOptionDialog(BeatmapSearchPanel.this, "Please consider not to empty the search field.\nIt might cause a long time to do searching.\nAre you sure to continue?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
        if (option == JOptionPane.NO_OPTION) {
            return;
        }
    }
    boolean useDb = rdbtnUseOfflineIndexed.isSelected();
    lblResultDesc.setText("Searching string \"" + searchFld.getText() + "\"" + (useDb ? " in offline indexed database..." : " online..."));
    tableModel.setRowCount(0);
    SearchingProgressDialog dialog = new SearchingProgressDialog();
    Thread thread = new Thread() {

        public void run() {
            try {
                sleep(250);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            ResultBeatmap[] maps;
            try {
                if (useDb) {
                    maps = osums.searchMaps(searchFld.getText());
                    if (maps == null) {
                        int option = JOptionPane.showOptionDialog(BeatmapSearchPanel.this, "Online beatmap not indexed. Indexing can improve searching speed.\n" + "It can take some minutes to an hour.\n\n" + "Do you want to index now or just do web search?", "Not indexed", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
                        if (option == JOptionPane.YES_OPTION) {
                            dialog.dispose();
                            IndexingProgressDialog idialog = new IndexingProgressDialog();
                            Thread t2 = new Thread() {

                                public void run() {
                                    try {
                                        sleep(1000);
                                    } catch (InterruptedException e) {
                                        e.printStackTrace();
                                    }
                                    try {
                                        mgr.startIndexing(idialog.getHandler());
                                        mgr.write();
                                    } catch (DebuggableException e) {
                                        e.printStackTrace();
                                        idialog.dispose();
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                    idialog.dispose();
                                }
                            };
                            t2.setDaemon(true);
                            t2.start();
                            idialog.setLocationRelativeTo(BeatmapSearchPanel.this);
                            idialog.setModal(true);
                            idialog.setVisible(true);
                            JOptionPane.showMessageDialog(BeatmapSearchPanel.this, "Please make another search again.", "Info", JOptionPane.INFORMATION_MESSAGE);
                            return;
                        } else if (option == JOptionPane.NO_OPTION) {
                            Config config = frame.getConfig();
                            doUiLogin(config);
                            try {
                                maps = osums.getLinksOfBeatmapSearch(dialog.getHandler(), "https://osu.ppy.sh/p/beatmaplist?q=" + searchFld.getText());
                            } catch (DebuggableException e) {
                                e.printStackTrace();
                            }
                        } else {
                            dialog.dispose();
                            return;
                        }
                    }
                } else {
                    Config config = frame.getConfig();
                    if (!osums.isLoggedIn()) {
                        doUiLogin(config);
                    }
                    if (osums.isLoggedIn()) {
                        // TODO: Change to use NEW Parser
                        maps = osums.getLinksOfBeatmapSearch(dialog.getHandler(), "https://old.ppy.sh/p/beatmaplist?q=" + searchFld.getText());
                    } else {
                        dialog.dispose();
                        JOptionPane.showMessageDialog(BeatmapSearchPanel.this, "You must be logged into osu! forum to perform online search.", "Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            } catch (DebuggableException e) {
                e.printStackTrace();
                return;
            }
            if (maps.length == 0) {
                lblResultDesc.setText("No beatmaps match with the search string. Try using another keyword!" + (useDb ? " Or please try a web search with this string." : ""));
            }
            if (maps.length <= 40) {
                lblResultDesc.setText("Only " + maps.length + " beatmaps match with the search string." + (useDb ? " Please try a web search with this string." : ""));
            } else {
                lblResultDesc.setText("Total of " + maps.length + " beatmaps match with the search string.");
            }
            dialog.getLabel().setText("Status: Updating UI...");
            for (int i = 0; i < maps.length; i++) {
                tableModel.addRow(new Object[] { maps[i] });
            }
            dialog.dispose();
        }
    };
    thread.setDaemon(true);
    thread.start();
    dialog.setLocationRelativeTo(BeatmapSearchPanel.this);
    dialog.setModal(true);
    dialog.setVisible(true);
}
Also used : DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) Config(com.github.mob41.osumer.Config) IOException(java.io.IOException) ResultBeatmap(com.github.mob41.osums.io.beatmap.ResultBeatmap)

Aggregations

DebuggableException (com.github.mob41.organdebug.exceptions.DebuggableException)1 Config (com.github.mob41.osumer.Config)1 ResultBeatmap (com.github.mob41.osums.io.beatmap.ResultBeatmap)1 IOException (java.io.IOException)1