/** Perform a search when user stop to type in the search combo for 2 sec or pressed enter */ private void search() { try { bNeedSearch = false; setEnabled(false); // no typing during search if (sTyped.length() >= MIN_CRITERIA_LENGTH) { // second test to get sure user didn't // typed before entering this method TreeSet<SearchResult> tsResu = TrackManager.getInstance().search(sTyped.toString()); // Add web radio names tsResu.addAll(WebRadioManager.getInstance().search(sTyped.toString())); if (tsResu.size() > 0) { DefaultListModel model = new DefaultListModel(); alResults = new ArrayList<SearchResult>(); alResults.addAll(tsResu); for (SearchResult sr : tsResu) { model.addElement(sr); } jlist = new JList(model); jlist.setLayoutOrientation(JList.VERTICAL); jlist.setCellRenderer(new SearchListRenderer()); PopupFactory factory = PopupFactory.getSharedInstance(); JScrollPane jsp = new JScrollPane(jlist); int width = (int) ((float) Toolkit.getDefaultToolkit().getScreenSize().getWidth() * 0.7f); jsp.setMinimumSize(new Dimension(width, 250)); jsp.setPreferredSize(new Dimension(width, 250)); jsp.setMaximumSize(new Dimension(width, 250)); jlist.setSelectionMode(0); jlist.addListSelectionListener(lsl); jsp.setBorder(BorderFactory.createLineBorder(Color.BLACK)); if (popup != null) { popup.hide(); } // take upper-left point relative to the // textfield Point point = new Point(0, 0); // take absolute coordonates in the screen (popups works // only on absolute coordonates in opposition to swing // widgets) SwingUtilities.convertPointToScreen(point, this); popup = factory.getPopup( this, jsp, (int) point.getX() + 500 - (width), (int) point.getY() - 250); popup.show(); } else { if (popup != null) { popup.hide(); } } } requestFocusInWindow(); } catch (Exception e) { Log.error(e); } finally { // make sure to enable search box in all cases setEnabled(true); } }
public void perform(ActionEvent evt) { // check modifiers to see if it is a movement inside track, between // tracks or between albums if (evt != null // evt == null when using hotkeys && (evt.getModifiers() & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK) { ActionManager.getAction(JajukAction.NEXT_ALBUM).actionPerformed(evt); } else { // if playing a radio, launch next radio station if (FIFO.getInstance().isPlayingRadio()) { final ArrayList<WebRadio> radios = new ArrayList<WebRadio>(WebRadioManager.getInstance().getWebRadios()); int index = radios.indexOf(FIFO.getInstance().getCurrentRadio()); if (index == radios.size() - 1) { index = 0; } else { index++; } final int i = index; new Thread() { public void run() { FIFO.getInstance().launchRadio(radios.get(i)); } }.start(); } else { // Playing a track synchronized (MUTEX) { new Thread() { public void run() { try { FIFO.getInstance().playNext(); } catch (Exception e) { Log.error(e); } } }.start(); // Player was paused, reset pause button when changing of // track if (Player.isPaused()) { Player.setPaused(false); ObservationManager.notify(new Event(EventSubject.EVENT_PLAYER_RESUME)); } } } } }