Ejemplo n.º 1
0
  /**
   * Invoked when an action occurs.
   *
   * @param evt
   */
  @Override
  public void perform(ActionEvent evt) {

    boolean b = Conf.getBoolean(Const.CONF_STATE_REPEAT);

    UtilGUI.setRepeatSingleGui(!b);
    QueueModel.setRepeatModeToAll(false);

    if (!b) { // enabled button
      // if FIFO is not void, repeat over current item
      StackItem item = QueueModel.getCurrentItem();
      if (item != null) {
        item.setRepeat(true);
      }
    } else { // disable repeat mode
      if (Conf.getBoolean(Const.CONF_DROP_PLAYED_TRACKS_FROM_QUEUE)) {
        // remove tracks before current position
        QueueModel.remove(0, QueueModel.getIndex() - 1);
        QueueModel.setIndex(0); // select first track
      }
    }
    // computes planned tracks
    QueueModel.computesPlanned(false);
    // Refresh Queue View
    ObservationManager.notify(new JajukEvent(JajukEvents.QUEUE_NEED_REFRESH));
  }
 /** Test method for {@link org.jajuk.ui.views.TracksTreeView#populateTree()}. */
 public final void testPopulateTree() {
   TracksTreeView view = new TracksTreeView();
   tryInitUI(view);
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
   // try with different settings
   Conf.setProperty(Const.CONF_LOGICAL_TREE_SORT_ORDER, "0");
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
   Conf.setProperty(Const.CONF_LOGICAL_TREE_SORT_ORDER, "1");
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
   Conf.setProperty(Const.CONF_LOGICAL_TREE_SORT_ORDER, "2");
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
   Conf.setProperty(Const.CONF_LOGICAL_TREE_SORT_ORDER, "3");
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
   Conf.setProperty(Const.CONF_LOGICAL_TREE_SORT_ORDER, "4");
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
   Conf.setProperty(Const.CONF_LOGICAL_TREE_SORT_ORDER, "5");
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
   Conf.setProperty(Const.CONF_LOGICAL_TREE_SORT_ORDER, "6");
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
   Conf.setProperty(Const.CONF_LOGICAL_TREE_SORT_ORDER, "7");
   try {
     view.populateTree();
   } catch (NullPointerException e) {
     // reported on headless settings
   }
 }
Ejemplo n.º 3
0
 /** Test method for {@link org.jajuk.services.dj.AmbienceManager#commit()}. */
 public final void testCommit() {
   // this creates the 14 default ambiences
   AmbienceManager.getInstance().createDefaultAmbiences();
   // set one ambience prefix to have it removed before
   Conf.setProperty(Const.AMBIENCE_PREFIX + "12/ambience", "testvalue");
   AmbienceManager.getInstance().commit();
 }
Ejemplo n.º 4
0
 /**
  * Test method for.
  *
  * <p>{@link org.jajuk.services.dj.AmbienceManager#getSelectedAmbience()}.
  */
 public final void testGetSelectedAmbience() {
   // first with no ambience and no default set
   assertNull(AmbienceManager.getInstance().getSelectedAmbience());
   // this creates the 14 default ambiences
   AmbienceManager.getInstance().createDefaultAmbiences();
   Conf.setProperty(Const.CONF_DEFAULT_AMBIENCE, "2"); // by ID
   // now we should find one
   assertNotNull(AmbienceManager.getInstance().getSelectedAmbience());
 }
 /**
  * Scan directories to cleanup removed files and playlists.
  *
  * @param dirsToRefresh list of the directory to refresh, null if all of them
  * @return whether some items have been removed
  */
 public boolean cleanRemovedFiles(List<Directory> dirsToRefresh) {
   long l = System.currentTimeMillis();
   // directories cleanup
   boolean bChanges = cleanDirectories(dirsToRefresh);
   // files cleanup
   bChanges = bChanges | cleanFiles(dirsToRefresh);
   // Playlist cleanup
   bChanges = bChanges | cleanPlaylist(dirsToRefresh);
   // clear history to remove old files referenced in it
   if (Conf.getString(Const.CONF_HISTORY) != null) {
     History.getInstance().clear(Integer.parseInt(Conf.getString(Const.CONF_HISTORY)));
   }
   // delete old history items
   l = System.currentTimeMillis() - l;
   Log.debug(
       "{{"
           + getName()
           + "}} Old file references cleaned in: "
           + ((l < 1000) ? l + " ms" : l / 1000 + " s, changes: " + bChanges));
   return bChanges;
 }
Ejemplo n.º 6
0
 /** Perform required operations before exit */
 public void commit() {
   // first, remove all ambiences from configuration
   Properties properties = Conf.getProperties();
   Iterator<Object> it = properties.keySet().iterator();
   while (it.hasNext()) {
     String sKey = (String) it.next();
     if (sKey.startsWith(Const.AMBIENCE_PREFIX)) {
       it.remove();
     }
   }
   // now create and set each ambience
   for (Ambience ambience : ambiences.values()) {
     if (ambience.getStyles().size() > 0) {
       String styles = "";
       for (Style style : ambience.getStyles()) {
         styles += style.getID() + ',';
       }
       styles = styles.substring(0, styles.length() - 1);
       Conf.setProperty(
           Const.AMBIENCE_PREFIX + ambience.getID() + '/' + ambience.getName(), styles);
     }
   }
 }
Ejemplo n.º 7
0
 /** Load properties from in file Format: jajuk.ambience.<ID>/<name>=style1,style2,... */
 public void load() {
   // if first startup, define default ambiences
   if (UpgradeManager.isFirstSesion()) {
     createDefaultAmbiences();
     return;
   }
   Properties properties = Conf.getProperties();
   Enumeration<Object> e = properties.keys();
   while (e.hasMoreElements()) {
     String sKey = (String) e.nextElement();
     if (sKey.matches(Const.AMBIENCE_PREFIX + ".*")) {
       Set<Style> styles = new HashSet<Style>(10);
       StringTokenizer st = new StringTokenizer((String) properties.get(sKey), ",");
       while (st.hasMoreTokens()) {
         Style style = StyleManager.getInstance().getStyleByID(st.nextToken());
         if (style != null) {
           styles.add(style);
         }
       }
       String ambienceDesc = sKey.substring(Const.AMBIENCE_PREFIX.length());
       int index = ambienceDesc.indexOf('/');
       if (index == -1) {
         continue;
       }
       String ambienceID = ambienceDesc.substring(0, index);
       String ambienceName = ambienceDesc.substring(index + 1);
       Ambience ambience = new Ambience(ambienceID, ambienceName, styles);
       ambiences.put(ambienceID, ambience);
     }
   }
   // If none ambience, means ambience can have been reset after a style
   // hashcode computation change, reset to defaults
   if (ambiences.size() == 0) {
     createDefaultAmbiences();
   }
 }
Ejemplo n.º 8
0
 /** @return currently selected ambience or null if "all" ambience selected */
 public Ambience getSelectedAmbience() {
   String sDefault = Conf.getString(Const.CONF_DEFAULT_AMBIENCE);
   return getAmbience(sDefault);
 }
  /** Refresh last fm collection tabs. */
  private void refreshLastFMCollectionTabs() {
    String newArtist = null;
    File current = QueueModel.getPlayingFile();
    if (current != null) {
      newArtist = current.getTrack().getArtist().getName2();
    }
    // if none track playing
    if (current == null
        // Last.FM infos is disable
        || !Conf.getBoolean(Const.CONF_LASTFM_INFO)
        // None internet access option is set
        || Conf.getBoolean(Const.CONF_NETWORK_NONE_INTERNET_ACCESS)
        // If unknown artist
        || (newArtist == null || newArtist.equals(Messages.getString(UNKNOWN_ARTIST)))) {
      // Set empty panels
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              stopAllBusyLabels();
              tabs.setComponentAt(3, new JLabel(Messages.getString("SuggestionView.7")));
              tabs.setComponentAt(4, new JLabel(Messages.getString("SuggestionView.7")));
            }
          });
      return;
    }
    // Check if artist changed, otherwise, just leave
    if (newArtist.equals(this.artist)) {
      return;
    }
    // Save current artist
    artist = newArtist;
    // Display a busy panel in the mean-time
    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            JXBusyLabel busy1 = new JXBusyLabel();
            busy1.setBusy(true);
            JXBusyLabel busy2 = new JXBusyLabel();
            busy2.setBusy(true);
            // stop all existing busy labels before we add the new ones...
            stopAllBusyLabels();
            tabs.setComponentAt(3, UtilGUI.getCentredPanel(busy1));
            tabs.setComponentAt(4, UtilGUI.getCentredPanel(busy2));
          }
        });
    // Use a swing worker as construct takes a lot of time
    SwingWorker<Void, Void> sw =
        new SwingWorker<Void, Void>() {
          JScrollPane jsp1;
          JScrollPane jsp2;

          @Override
          public Void doInBackground() {
            try {
              // Fetch last.fm calls and downloads covers
              preFetchOthersAlbum();
              preFetchSimilarArtists();
            } catch (Exception e) {
              Log.error(e);
            }
            return null;
          }

          @Override
          public void done() {
            jsp1 = getLastFMSuggestionsPanel(SuggestionType.OTHERS_ALBUMS, false);
            jsp2 = getLastFMSuggestionsPanel(SuggestionType.SIMILAR_ARTISTS, false);
            stopAllBusyLabels();
            tabs.setComponentAt(3, (jsp1 == null) ? new JPanel() : jsp1);
            tabs.setComponentAt(4, (jsp2 == null) ? new JPanel() : jsp2);
          }
        };
    sw.execute();
  }
  /*
   * (non-Javadoc)
   *
   * @see org.jajuk.ui.views.IView#populate()
   */
  @Override
  public void initUI() {
    tabs = new JTabbedPane();
    // Remove tab border, see
    // http://forum.java.sun.com/thread.jspa?threadID=260746&messageID=980405
    class MyTabbedPaneUI extends javax.swing.plaf.basic.BasicTabbedPaneUI {
      @Override
      protected Insets getContentBorderInsets(int tabPlacement) {
        return new Insets(0, 0, 0, 0);
      }

      @Override
      protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {
        // nothing to do here...
      }
    }
    // Now use the new TabbedPaneUI
    tabs.setUI(new MyTabbedPaneUI());
    // Fill tabs with empty tabs
    tabs.addTab(
        Messages.getString("SuggestionView.1"),
        UtilGUI.getCentredPanel(new JLabel(Messages.getString("WikipediaView.3"))));
    tabs.addTab(
        Messages.getString("SuggestionView.2"),
        UtilGUI.getCentredPanel(new JLabel(Messages.getString("WikipediaView.3"))));
    tabs.addTab(
        Messages.getString("SuggestionView.5"),
        UtilGUI.getCentredPanel(new JLabel(Messages.getString("WikipediaView.3"))));
    tabs.addTab(
        Messages.getString("SuggestionView.3"), new JLabel(Messages.getString("SuggestionView.7")));
    tabs.addTab(
        Messages.getString("SuggestionView.4"), new JLabel(Messages.getString("SuggestionView.7")));
    // Refresh tabs on demand only, add changelisterner after tab creation to
    // avoid that the stored tab is overwrited at startup
    tabs.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent arg0) {
            refreshLastFMCollectionTabs();
            // store the selected tab
            Conf.setProperty(
                getClass().getName()
                    + "_"
                    + ((getPerspective() == null) ? "solo" : getPerspective().getID()),
                Integer.toString(tabs.getSelectedIndex()).toString());
          }
        });
    if (Conf.containsProperty(
        getClass().getName()
            + "_"
            + ((getPerspective() == null) ? "solo" : getPerspective().getID()))) {
      int index =
          Conf.getInt(
              getClass().getName()
                  + "_"
                  + ((getPerspective() == null) ? "solo" : getPerspective().getID()));
      if (index > 0 && index < tabs.getTabCount()) {
        tabs.setSelectedIndex(index);
      }
    }
    // Add panels
    refreshLocalCollectionTabs();
    // Add tabs
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    add(tabs);
    // Look for events
    ObservationManager.register(this);
  }
Ejemplo n.º 11
0
 /**
  * Test method for {@link org.jajuk.services.dj.AmbienceManager#load()}.
  *
  * @throws Exception the exception
  */
 public final void testLoad() throws Exception {
   // make sure "UpgradeManager.bFirstSession" is not set
   {
     Class<?> c = UpgradeManager.class;
     Field f = c.getDeclaredField("firstSession");
     f.setAccessible(true);
     f.setBoolean(null, Boolean.FALSE);
   }
   assertFalse(UpgradeManager.isFirstSession());
   assertEquals(0, AmbienceManager.getInstance().getAmbiences().size());
   // first without any key
   AmbienceManager.getInstance().load();
   // creates the 14 default ambiences
   assertEquals(14, AmbienceManager.getInstance().getAmbiences().size());
   // clean out all leftover ambiences from other testing
   for (Ambience amb : AmbienceManager.getInstance().getAmbiences()) {
     AmbienceManager.getInstance().removeAmbience(amb.getID());
   }
   assertEquals(0, AmbienceManager.getInstance().getAmbiences().size());
   { // remove all leftover properties
     Properties properties = Conf.getProperties();
     Enumeration<Object> e = properties.keys();
     while (e.hasMoreElements()) {
       String sKey = (String) e.nextElement();
       if (sKey.matches(Const.AMBIENCE_PREFIX + ".*")) {
         properties.remove(sKey);
       }
     }
   }
   // then add set some Ambience-items
   Genre genre1 = GenreManager.getInstance().registerGenre("genre1");
   Genre genre2 = GenreManager.getInstance().registerGenre("genre2");
   Conf.setProperty(
       Const.AMBIENCE_PREFIX + "12/myambience", genre1.getID() + "," + genre2.getID());
   assertEquals(0, AmbienceManager.getInstance().getAmbiences().size());
   { // check all the conditions to find out why it fails in Hudson
     assertFalse(UpgradeManager.isFirstSession());
     Properties properties = Conf.getProperties();
     Enumeration<Object> e = properties.keys();
     int nMatch = 0;
     while (e.hasMoreElements()) {
       String sKey = (String) e.nextElement();
       if (sKey.matches(Const.AMBIENCE_PREFIX + ".*")) {
         if (sKey.substring(Const.AMBIENCE_PREFIX.length()).indexOf('/') == -1) {
           continue;
         }
         nMatch++;
       }
     }
     assertEquals(properties.toString(), 1, nMatch);
   }
   AmbienceManager.getInstance().load();
   assertEquals(1, AmbienceManager.getInstance().getAmbiences().size());
   assertNotNull(AmbienceManager.getInstance().getAmbience("12"));
   // now test with an ambience with invalid format, i.e. only "12", not
   // "12/name"
   for (Ambience amb : AmbienceManager.getInstance().getAmbiences()) {
     AmbienceManager.getInstance().removeAmbience(amb.getID());
   }
   assertEquals(0, AmbienceManager.getInstance().getAmbiences().size());
   Conf.setProperty(Const.AMBIENCE_PREFIX + "12", genre1.getID() + "," + genre2.getID());
   Conf.removeProperty(Const.AMBIENCE_PREFIX + "12/myambience");
   AmbienceManager.getInstance().load();
   // now 14 as this could not be loaded and thus the default ones were
   // loaded...
   assertEquals(14, AmbienceManager.getInstance().getAmbiences().size());
   UpgradeManager.setFirstSession();
   AmbienceManager.getInstance().load();
 }