/** @return ItemManager associated with selected element in combo box */
 ItemManager getItemManager() {
   ItemManager im = null;
   switch (jcbItemChoice.getSelectedIndex()) {
     case 0:
       im = TrackManager.getInstance();
       break;
     case 1:
       im = FileManager.getInstance();
       break;
     case 2:
       im = StyleManager.getInstance();
       break;
     case 3:
       im = AuthorManager.getInstance();
       break;
     case 4:
       im = AlbumManager.getInstance();
       break;
     case 5:
       im = DeviceManager.getInstance();
       break;
     case 6:
       im = DirectoryManager.getInstance();
       break;
     case 7:
       im = PlaylistFileManager.getInstance();
       break;
     case 8:
       im = YearManager.getInstance();
       break;
   }
   return im;
 }
Esempio n. 2
0
 /** 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 tsResu = FileManager.getInstance().search(sTyped.toString());
       if (tsResu.size() > 0) {
         DefaultListModel model = new DefaultListModel();
         alResults = new ArrayList();
         alResults.addAll(tsResu);
         Iterator it = tsResu.iterator();
         while (it.hasNext()) {
           model.addElement(((SearchResult) it.next()).getResu());
         }
         jlist = new JList(model);
         PopupFactory factory = PopupFactory.getSharedInstance();
         JScrollPane jsp = new JScrollPane(jlist);
         jlist.setSelectionMode(0);
         jlist.addListSelectionListener(lsl);
         jsp.setBorder(BorderFactory.createLineBorder(Color.BLACK));
         if (popup != null) {
           popup.hide();
         }
         Point point = new Point(0, 0); // take upper-left point relative to the textfield
         SwingUtilities.convertPointToScreen(
             point,
             this); // take absolute coordonates in the screen ( popups works only on absolute
                    // coordonates in oposition to swing widgets)
         popup = factory.getPopup(this, jsp, (int) point.getX(), (int) point.getY() + 25);
         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);
   }
 }
  /** Called when draging */
  protected Transferable createTransferable(JComponent c) {
    // make sure to remove others selected rows (can occur during the drag)
    jtable.getSelectionModel().setSelectionInterval(iSelectedRow, iSelectedRow);
    if (jtable instanceof JajukTable) { // sorting only for jajuk table
      iSelectedRow = ((JajukTable) jtable).convertRowIndexToModel(iSelectedRow); // selected row
      // in model
    }
    Object o = ((JajukTableModel) jtable.getModel()).getItemAt(iSelectedRow);
    if (o == null) { // no? try to find a file for this id
      o =
          FileManager.getInstance()
              .getFileByID(jtable.getModel().getValueAt(iSelectedRow, 0).toString());
    }
    if (o != null) {
      return new TransferableTableRow(o);
    }

    return null;
  }
 /*
  * (non-Javadoc)
  *
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(final ActionEvent ae) {
   // do not run this in a separate thread because Player actions would die
   // with the thread
   try {
     if (ae.getSource() == jcbHistory) {
       HistoryItem hi;
       hi = History.getInstance().getHistoryItem(jcbHistory.getSelectedIndex());
       if (hi != null) {
         org.jajuk.base.File file = FileManager.getInstance().getFileByID(hi.getFileId());
         if (file != null) {
           try {
             FIFO.getInstance()
                 .push(
                     new StackItem(file, ConfigurationManager.getBoolean(CONF_STATE_REPEAT), true),
                     ConfigurationManager.getBoolean(CONF_OPTIONS_DEFAULT_ACTION_CLICK));
           } catch (JajukException je) {
             // can be thrown if file is null
           }
         } else {
           Messages.showErrorMessage(120);
           jcbHistory.setSelectedItem(null);
         }
       }
     } else if (ae.getSource().equals(jmiNoveltiesModeSong)) {
       ConfigurationManager.setProperty(CONF_NOVELTIES_MODE, MODE_TRACK);
     } else if (ae.getSource().equals(jmiNoveltiesModeAlbum)) {
       ConfigurationManager.setProperty(CONF_NOVELTIES_MODE, MODE_ALBUM);
     } else if (ae.getSource().equals(jmiShuffleModeSong)) {
       ConfigurationManager.setProperty(CONF_GLOBAL_RANDOM_MODE, MODE_TRACK);
     } else if (ae.getSource().equals(jmiShuffleModeAlbum)) {
       ConfigurationManager.setProperty(CONF_GLOBAL_RANDOM_MODE, MODE_ALBUM);
     } else if (ae.getSource().equals(jmiShuffleModeAlbum2)) {
       ConfigurationManager.setProperty(CONF_GLOBAL_RANDOM_MODE, MODE_ALBUM2);
     } else if (ae.getSource().equals(jmiShuffleModeAlbum2)) {
       ConfigurationManager.setProperty(CONF_GLOBAL_RANDOM_MODE, MODE_ALBUM2);
     }
   } catch (Exception e) {
     Log.error(e);
   } finally {
     ObservationManager.notify(new Event(EventSubject.EVENT_PLAYLIST_REFRESH));
   }
 }
  /* (non-Javadoc)
   * @see org.jajuk.services.dj.DigitalDJ#generatePlaylist()
   */
  @Override
  public List<File> generatePlaylist() {
    List<File> out = new ArrayList<File>(500);

    // get a global shuffle selection
    List<File> global = FileManager.getInstance().getGlobalShufflePlaylist();
    // Select by rate if needed
    filterFilesByRate(global);
    // None element, leave
    if (global.size() == 0) {
      return out;
    }
    // Build a ambience -> files map
    Map<Ambience, List<File>> hmAmbienceFiles = getAmbienceFilesList(global);
    // compute number of items to add
    int items = Math.min(global.size(), Const.NB_TRACKS_ON_ACTION);
    if (!bUnicity && items < Const.MIN_TRACKS_NUMBER_WITHOUT_UNICITY) {
      // under a limit, if collection is too small and no unicity, use
      // several times the same files
      items = Const.MIN_TRACKS_NUMBER_WITHOUT_UNICITY;
    }

    // Get first track
    for (File file : global) {
      if (transitions.get(0).getFrom().getGenres().contains(file.getTrack().getGenre())) {
        out.add(file);
        // Unicity in selection, remove it from this ambience
        if (bUnicity) {
          List<File> files = hmAmbienceFiles.get(getAmbience(file.getTrack().getGenre()));
          files.remove(file);
        }
        items--;
        break;
      }
    }
    // none matching track? return
    if (out.size() == 0) {
      return out;
    }

    // initialize current ambience with first track ambience (can be null for
    // unsorted tracks)
    Ambience currentAmbience = getAmbience(out.get(0).getTrack().getGenre());
    // start transition applying
    while (items > 0) {
      // A genre can be in only one transition
      Transition currentTransition = getTransition(currentAmbience);
      List<File> files = hmAmbienceFiles.get(currentAmbience);
      int nbTracks = 2;
      if (currentTransition != null) {
        nbTracks = currentTransition.getNbTracks();
      }
      // We remove one item as it has already been added through the first track
      if (out.size() == 1) {
        nbTracks--;
      }
      if (files != null && files.size() >= nbTracks) {
        for (int i = 0; i < nbTracks && files.size() > 0; i++) {
          File file = (File) UtilFeatures.getShuffleItem(files);
          out.add(file);
          items--;
          // Unicity in selection, remove it from this ambience
          if (bUnicity) {
            files.remove(file);
          }
        }
      } else { // no more tracks for this ambience ? leave
        // finally ensure that we don't select more than the max number of tracks
        filterFilesByMaxTrack(out);

        return out;
      }
      if (currentTransition != null) {
        currentAmbience = currentTransition.getTo();
      } else {
        break;
      }
    }

    // finally ensure that we don't select more than the max number of tracks
    filterFilesByMaxTrack(out);

    return out;
  }