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

it.tidalwave.bluebill.mobile.taxonomy.factsheet.impl.sound.SoundActionProvider Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * blueBill Mobile - Android - open source birding
 * Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://bluebill.tidalwave.it/mobile
 * SCM: https://java.net/hg/bluebill-mobile~android-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.taxonomy.factsheet.impl.sound;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collection;
import javax.swing.Action;
import it.tidalwave.role.ui.spi.ActionProviderSupport;
import it.tidalwave.observation.Observation;
import it.tidalwave.mobile.media.Media;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.ui.sound.DefaultTaxonSoundFactSheetViewController;
import it.tidalwave.bluebill.mobile.taxonomy.factsheet.ui.sound.TaxonSoundFactSheetView;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
public class SoundActionProvider extends ActionProviderSupport
  {
    @Nonnull
    private final PlayController playController;
    
    @Nonnull
    private final Media media;

    /* package */ final Action doNothingAction = new DoNothingAction();
    /* package */ final Action downloadAction;
    /* package */ final Action refreshAction;
    /* package */ final Action playAction;
    /* package */ final Action stopAction;
    /* package */ final Action deleteAction;
    /* package */ final Action openWebPageAction;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public SoundActionProvider (final @Nonnull DefaultTaxonSoundFactSheetViewController controller, 
                                final @Nonnull TaxonSoundFactSheetView view, 
                                final @Nonnull PlayController playController,
                                final @Nonnull Media media, 
                                final @Nonnull Observation observation)
      {
        this.playController = playController;
        this.media = media;
        downloadAction = new DownloadAction(media, controller, view);
        refreshAction = new RefreshAction(media, controller, view);
        playAction = new PlayAction(media, playController, view);
        stopAction = new StopAction(media, playController, view);
        deleteAction = new DeleteAction(media, controller, view);
        openWebPageAction = new OpenWebPageAction(observation, view);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override @Nonnull
    public Collection getActions()
      {
        return Arrays.asList(playAction, downloadAction, refreshAction, deleteAction, openWebPageAction);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override @Nonnull
    public Action getDefaultAction()
      {
        if (playController.isPlaying(media))
          {
            return stopAction;
          }
        else if (playAction.isEnabled())
          {
            return playAction;
          }
        else if (downloadAction.isEnabled())
          {
            return downloadAction;
          }
        else
          {
            return doNothingAction;
          }
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy