Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
blueBill Core - 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 SCM: https://java.net/hg/bluebill~core-src /
 
 package it.tidalwave.mobile.util;
 
 import  javax.annotation.Nonnegative;
 import  javax.annotation.Nonnull;
 import java.util.Map;
 import java.io.File;
 import  it.tidalwave.role.Displayable;
 import  it.tidalwave.role.Removable;

Author(s):
Fabrizio Giudici
Version:
$Id$ /
 
 public abstract class Downloadable implements Removable
   {
     private final static long serialVersionUID = 876756656347568673L;
     
     private static final Logger log = LoggerFactory.getLogger(Downloadable.class);

    
/
 
     public static enum Status implements Displayable
       {
         NOT_DOWNLOADED(false),
         QUEUED(false),
         DOWNLOADING(false),
         DOWNLOADED(true),
         OBSOLETE(false),
         BROKEN(true);
 
         private static final String BUNDLE_NAME = Status.class.getPackage().getName().replace('.''/') + "/Bundle";
 
         /* package */ static final Comparator<LocaleLOCALE_COMPARATOR = new Comparator<Locale>()
           {
             public int compare (final @Nonnull Locale l1final @Nonnull Locale l2)
               {
                 return l1.getLanguage().compareTo(l2.getLanguage());
               }
           };
         
         private final boolean final_;
 
         @Nonnull
         public String getDisplayName()
           {
             return getDisplayName(Locale.getDefault());
           }
 
         @Nonnull
         public String getDisplayName (final @Nonnull Locale locale)
           {
     //        final ResourceBundle bundle = NbBundle.getBundle(BUNDLE_NAME, locale);  FIXME: crashes Android 1.5
             final ResourceBundle bundle = ResourceBundle.getBundle(locale);
             return bundle.getString("status_" + toString());
           }
 
         @Nonnull
         public Map<LocaleStringgetDisplayNames()
           {
            final Map<LocaleStringresult = new HashMap<LocaleString>();
            for (final Locale locale : getLocales())
              {
                result.put(localegetDisplayName(locale));
              }
            return result;
          }
        @Nonnull
        public SortedSet<LocalegetLocales()
          {
            final TreeSet<LocaletreeSet = new TreeSet<Locale>();
            treeSet.addAll(Arrays.asList(new Locale("en"), new Locale("it"), new Locale("fr")));
            return treeSet;
          }
        public boolean isFinal() 
          {
            return ;
          }
      }
    public static final Class<DownloadableDownloadable = Downloadable.class;
    public static final String PROP_DOWNLOAD_PROGRESS = "downloadProgress";
    public static final String PROP_STATUS = "status";
    public static final String PROP_CACHED = "cached";
    @Nonnegative
    protected float downloadProgress = 0f;
    @Nonnull
    protected Status status = .;
    protected boolean cached = false;
    private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    
/
    @Nonnegative
    public float getDownloadProgress()
      {
        return ;
      }

    
/
    @Nonnull
    public Status getStatus()
      {
        return ;
      }

    
/
    @Nonnull
    public abstract File getFile();

    
/
    public boolean isCached()
      {
        return ;
      }

    
/
    public void addPropertyChangeListener (final @Nonnull PropertyChangeListener listener)
      {
      }

    
/
    public void removePropertyChangeListener (final @Nonnull PropertyChangeListener listener)
      {
      }

    
/
    public abstract void download();

    
/
    public abstract void refresh();

    
/
    public synchronized void waitUntilDownloadingCompleted()
      throws InterruptedException
      {
        while (getStatus() == .)
          {
            wait();
          }
      }

    
/
    protected void setDownloadProgress (final @Nonnull float downloadProgress)
      {
        final float oldDownloadProgress = this.;
        this. = downloadProgress;
        .firePropertyChange(oldDownloadProgressdownloadProgress);
      }

    
/
    protected void setStatus (final @Nonnull Status status)
      {
        .debug("setStatus({})"status);
        final Status oldStatus = this.;
        this. = status;
        synchronized (this)
          {
            notifyAll();
          }
        .firePropertyChange(oldStatusstatus);
      }

    
/
    protected void setCached (final boolean cached)
      {
        final boolean oldCached = this.;
        this. = cached;
        .firePropertyChange(oldCachedcached);
      }
  }
New to GrepCode? Check out our FAQ X