All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.ihmc.simulationconstructionset.gui.BookmarkedVariablesHolder Maven / Gradle / Ivy

There is a newer version: 0.25.2
Show newest version
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));
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy