Package com.tulskiy.musique.plugins.discogs.model

Source Code of com.tulskiy.musique.plugins.discogs.model.DiscogsTrackListModel

/*
* Copyright (c) 2008, 2009, 2010, 2011 Denis Tulskiy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this work.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.tulskiy.musique.plugins.discogs.model;

import org.discogs.model.Track;

import com.tulskiy.musique.plugins.discogs.util.DiscogsModelUtil;
import com.tulskiy.musique.util.Util;

/**
* @author mliauchuk
*/
public class DiscogsTrackListModel extends DiscogsDefaultListModel {
 
  private StringBuilder sb = new StringBuilder();
 
  private boolean useAnv;
 
  public void setUseAnv(boolean useAnv) {
    this.useAnv = useAnv;
  }

  public Track getEx(int index) {
    Object item = super.get(index);
    if (item instanceof Track) {
      return (Track) item;
    }
   
    return null;
  }

  @Override
  public Object get(int index) {
    Track track = getEx(index);
    return track == null ? null : getTrackDescription(track);
  }

  @Override
  public void addElement(Object obj) {
    if (obj instanceof Track && Util.isEmpty(((Track) obj).getPositionRaw())) {
      return;
    }
    super.addElement(obj);
  }

  private String getTrackDescription(Track track) {
    sb.setLength(0);
    sb.trimToSize();

    String artistName = DiscogsModelUtil.getReleaseArtistDescription(track.getArtists(), useAnv, true);

    sb.append(track.getPositionRaw());
    if (!Util.isEmpty(artistName)) {
      sb.append(" - ").append(artistName);
    }
    sb.append(" - ").append(DiscogsModelUtil.getTrackTitleCleared(track.getTitle()));
    if (track.getDuration() != null) {
      sb.append(" (").append(track.getDuration()).append(')');
    }
   
    return sb.toString();
  }

}
TOP

Related Classes of com.tulskiy.musique.plugins.discogs.model.DiscogsTrackListModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.