/* * Copyright (C) 2007-2012 Geometer Plus <contact@geometerplus.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ package org.geometerplus.fbreader.library; import java.util.*; public abstract class AbstractLibrary { private final List<ChangeListener> myListeners = Collections.synchronizedList(new LinkedList<ChangeListener>()); public interface ChangeListener { public enum Code { BookAdded, BookRemoved, StatusChanged, Found, NotFound } void onLibraryChanged(Code code); } public void addChangeListener(ChangeListener listener) { myListeners.add(listener); } public void removeChangeListener(ChangeListener listener) { myListeners.remove(listener); } protected void fireModelChangedEvent(ChangeListener.Code code) { synchronized (myListeners) { for (ChangeListener l : myListeners) { l.onLibraryChanged(code); } } } public abstract boolean isUpToDate(); public static final int REMOVE_DONT_REMOVE = 0x00; public static final int REMOVE_FROM_LIBRARY = 0x01; public static final int REMOVE_FROM_DISK = 0x02; public static final int REMOVE_FROM_LIBRARY_AND_DISK = REMOVE_FROM_LIBRARY | REMOVE_FROM_DISK; public abstract boolean canRemoveBookFile(Book book); public abstract void removeBook(Book book, int removeMode); public abstract Book getRecentBook(); public abstract Book getPreviousBook(); public abstract void addBookToRecentList(Book book); public abstract boolean isBookInFavorites(Book book); public abstract void addBookToFavorites(Book book); public abstract void removeBookFromFavorites(Book book); public abstract void startBookSearch(final String pattern); public abstract List<Bookmark> allBookmarks(); public abstract List<Bookmark> invisibleBookmarks(Book book); }