us.ihmc.simulationconstructionset.gui.BookmarkedVariablesHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simulation-construction-set
Show all versions of simulation-construction-set
Simulation Construction Set
package us.ihmc.simulationconstructionset.gui;
import java.util.ArrayList;
import us.ihmc.yoVariables.variable.YoVariable;
public class BookmarkedVariablesHolder
{
private ArrayList bookmarkedVariables = new ArrayList<>(0);
private ArrayList listeners = new ArrayList<>(0);
private ArrayList removedListeners = new ArrayList<>(0);
public ArrayList getBookMarkedVariables()
{
return new ArrayList<>(bookmarkedVariables);
}
public void addBookmark(YoVariable variable)
{
if (!bookmarkedVariables.contains(variable))
{
bookmarkedVariables.add(variable);
notifyBookmarkedVariableAddedListeners();
}
}
public void removeBookmark(YoVariable variable)
{
if (bookmarkedVariables.remove(variable))
{
notifyBookmarkedVariableRemovedListeners(variable);
}
}
public void addBookmarkedVariableAddedListener(BookmarkedVariableAddedListener listener)
{
listeners.add(listener);
}
public void addBookmarkedVariableRemovedListener(BookmarkedVariableRemovedListener listener)
{
removedListeners.add(listener);
}
private void notifyBookmarkedVariableRemovedListeners(YoVariable variable)
{
for (BookmarkedVariableRemovedListener removedListener : removedListeners)
{
removedListener.bookmarkRemoved(variable);
}
}
private void notifyBookmarkedVariableAddedListeners()
{
for (BookmarkedVariableAddedListener listener : listeners)
{
listener.bookmarkAdded(bookmarkedVariables.get(bookmarkedVariables.size() - 1));
}
}
}