⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 artists.java

📁 eclise rcp 项目,是非常好的学习源码
💻 JAVA
字号:
/*******************************************************************************
 * Copyright (c) 2007 Siemens AG
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Kai T鰀ter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.model.logical;

import java.util.ArrayList;
import java.util.List;

import com.siemens.ct.mp3m.model.IMP3Info;
import com.siemens.ct.mp3m.model.MP3Infos;

/**
 * This class contains the data model for the ArtistTable
 */
public class Artists {
	private static List<Artist> artists = new ArrayList<Artist>();
	private static List<ILogicalModelListener> modelChangeListeners = new ArrayList<ILogicalModelListener>();

	public static Artist[] getArtists() {
		return artists.toArray(new Artist[] {});
	}

	public static void addMP3Info(IMP3Info mp3Info) {
		try {
			String mp3Artist = mp3Info.getArtist();
			String mp3Album = mp3Info.getAlbum();
			String mp3Title = mp3Info.getTitle();
			String mp3Track = mp3Info.getTrack();
			String mp3Duration = Integer.toString(mp3Info.getDuration());
			Artist newArtist = null;
			for (Artist artist : artists) {
				if (artist.getName().equals(mp3Artist)) {
					newArtist = artist;
					break;
				}
			}
			if (newArtist == null && mp3Artist != null && mp3Artist.length() > 0) {
				newArtist = new Artist(mp3Artist);
				artists.add(newArtist);
			}

			if (newArtist != null && mp3Album != null && mp3Title != null) {
				Album album = newArtist.addAlbum(mp3Album);
				album.addSong(mp3Title, mp3Track, mp3Duration, mp3Info.getMP3File());
			}
		} catch (RuntimeException e) {
			System.err.println("Could not process: " + mp3Info.getMP3File()); //$NON-NLS-1$
		}
	}

	public static void addModelChangeListener(ILogicalModelListener modelListener) {
		modelChangeListeners.add(modelListener);
	}

	public static void removeModelChangeListener(ILogicalModelListener modelListener) {
		modelChangeListeners.remove(modelListener);
	}

	public static void recomputeModel() {
		artists = new ArrayList<Artist>();
		List<IMP3Info> infos = MP3Infos.getMP3Infos();
		for (IMP3Info info : infos) {
			addMP3Info(info);
		}
		for (ILogicalModelListener listener : modelChangeListeners) {
			listener.modelChanged();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -