001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.sequence; 020 021import java.util.ArrayList; 022import java.util.List; 023 024/** 025 * @author Stephane 026 */ 027public abstract class AbstractSequenceModel implements SequenceModel 028{ 029 private final List<SequenceModelListener> listeners; 030 031 public AbstractSequenceModel() 032 { 033 super(); 034 035 listeners = new ArrayList<SequenceModelListener>(); 036 } 037 038 /** 039 * fire model image changed event 040 */ 041 @Override 042 public void fireModelImageChangedEvent() 043 { 044 for (SequenceModelListener listener : new ArrayList<SequenceModelListener>(listeners)) 045 listener.imageChanged(); 046 } 047 048 /** 049 * fire model dimension changed event 050 */ 051 @Override 052 public void fireModelDimensionChangedEvent() 053 { 054 for (SequenceModelListener listener : new ArrayList<SequenceModelListener>(listeners)) 055 listener.dimensionChanged(); 056 } 057 058 @Override 059 public void addSequenceModelListener(SequenceModelListener listener) 060 { 061 synchronized (listeners) 062 { 063 listeners.add(listener); 064 } 065 } 066 067 @Override 068 public void removeSequenceModelListener(SequenceModelListener listener) 069 { 070 synchronized (listeners) 071 { 072 listeners.remove(listener); 073 } 074 } 075}