it.tidalwave.bluebill.mobile.observation.KMLReportGenerator Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* 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.
*
***********************************************************************************************************************
*
* $Id: KMLReportGenerator.java,v 3e7ea5dbefcb 2010/05/17 15:10:54 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.observation;
import javax.annotation.Nonnull;
import it.tidalwave.util.AsException;
import it.tidalwave.geo.Coordinate;
import it.tidalwave.geo.Range;
import it.tidalwave.bluebill.observation.Cardinality;
import it.tidalwave.bluebill.observation.Location;
import it.tidalwave.bluebill.observation.Observation;
import it.tidalwave.bluebill.observation.ObservationItem;
import it.tidalwave.bluebill.taxonomy.Taxon;
import it.tidalwave.bluebill.mobile.GeneralPreferences;
import static it.tidalwave.bluebill.taxonomy.Taxon.Taxon;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonomyPreferences;
import org.openide.util.Lookup;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class KMLReportGenerator implements ObservationSetVisitor.Listener
{
private static final Class Range = Range.class; // FIXME: move to Range
@Nonnull
private final Lookup lookup = Lookup.getDefault();
private TaxonomyPreferences taxonomyPreferences;
private final StringBuilder buffer = new StringBuilder();
@Nonnull
private final GeneralPreferences generalPreferences = Lookup.getDefault().lookup(GeneralPreferences.class);
private boolean ignore = false;
private StringBuilder name = new StringBuilder();
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void begin()
{
taxonomyPreferences = lookup.lookup(TaxonomyPreferences.class);
buffer.append("\n"
+ "");
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void end()
{
buffer.append(" ");
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void beginVisit (final @Nonnull Observation observation)
{
try
{
// final LocationPreferences locationPreferences = lookup.lookup(LocationPreferences.class);
final Location location = observation.getLocation();
final Range range = location.as(Range);
final Coordinate coordinate = range.getCoordinate();
buffer.append(" ");
buffer.append(" ");
buffer.append(String.format("%f,%f,%f ",
coordinate.getLatitude(), coordinate.getLongitude(), coordinate.getAltitude()));
buffer.append(" ");
name = new StringBuilder();
name.append(generalPreferences.formatDateAndTime(observation.getDate()));
name.append("\n");
ignore = false;
}
catch (AsException e)
{
// Range not available, can't place on a map
ignore = true;
}
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void visit (final @Nonnull ObservationItem item)
{
if (!ignore)
{
}
final Taxon taxon = item.getObservable().as(Taxon);
final Cardinality cardinality = item.getCardinality();
name.append("* ").append(taxonomyPreferences.format(taxon));
if (!cardinality.equals(Cardinality.UNDEFINED))
{
name.append(" ").append(cardinality.toString());
}
buffer.append(String.format(" %s ", name.toString()));
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void endVisit (final @Nonnull Observation observation)
{
buffer.append(" ");
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
protected String getMessage()
{
return buffer.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy