/******************************************************************************************************************* * * ******************************************************************************************************************/ @Override public void writeExternal (final @Nonnull ObjectOutput oo) throws IOException { oo.writeObject(taxon.getId()); }
@Override public void run() { log.info("renderTaxon({})", taxon); taxon.as(TextViewRenderable).renderTo(tvTaxon); } });
public CommonNamesPresentationModel (final @Nonnull Taxon taxon, final @Nonnull Locale locale) throws NotFoundException { super(new Object[] { taxon }); language = getMessage(_, "lang_" + locale.getLanguage()); name = taxon.getDisplayName(locale); scientificName = taxon.getScientificName(); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public static Intent intentFor (final @Nonnull Taxon taxon) throws NotFoundException { // FIXME: you should really use the Uri, but it fails to find the Intent // FIXME: probably it needs a further declaration in the Android manifest // return new Intent(ACTION_TAXON, Uri.parse(taxon.getId().stringValue())); final Intent intent = new Intent(getActionPackage() + taxon.getRank().getNarrower().name()); intent.putExtra(TAXON_ID, taxon.getId().stringValue()); return intent; }
public int compare (final @Nonnull Taxon taxon1, final @Nonnull Taxon taxon2) { return collator.compare(taxon1.getScientificName(), taxon2.getScientificName()); } };
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull protected URI getUriFor (final @Nonnull Taxon taxon) throws NotFoundException, URISyntaxException { final String displayName = taxon.getDisplayName(Locale.UK); final StringBuilder buffer = new StringBuilder(BBC_CONTEXT + "nature/species/"); String separator = ""; for (final String s : displayName.split(" ")) { buffer.append(separator).append(capitalized(s)); separator = "_"; } buffer.append(".rdf"); return new URI(buffer.toString()); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull protected List<Taxon> getPath() { final List<Taxon> path = new ArrayList<Taxon>(); try { Taxon parent = taxon.getParent().getParent(); // Skip Genus, it's already rendered as part of the name for (;;) { path.add(parent); parent = parent.getParent(); } } catch (NotFoundException e) { // ok, done } Collections.reverse(path); return path; } }
/******************************************************************************************************************* * * Loads the taxa. If a {@link Taxon} is contained in the {@link Intent}, the sub taxa will be loaded and the cache * disabled since there are no taxa with a number of sub taxa so large to create performance problems while sorting. * If no {@code Taxon} is contained in the {@code Intent}, all the taxa with the {@link Rank} bound to this * controller will be loaded; and the cache enabled if the rank is {@code SPECIES} since there can be so many * items to create performance problems when sorting. The latter behaviour also happens if the {@code Intent} * contains a {@code Taxon}, but it's not from the current taxonomy. * * TODO: This management of cache is cumbersome. Using Finders with sorting capabilities could be a solution, * moving all the caching logics to the Finder themselves (and eventually could opaquely implement sorting * based on OpenSesame query that could be fast enough to avoid caching). * ******************************************************************************************************************/ @Nonnull private void loadTaxa (final @Nonnull Intent intent) { taxa.clear(); cacheEnabled = false; try { taxa.addAll(TaxonIntentHelper.getTaxon(intent).findSubTaxa().results()); } catch (NotFoundException e) // no Taxon in the Intent { taxa.addAll(taxonomyPreferences.get().getTaxonomy().findTaxa().withRank(rank).results()); cacheEnabled = rank == Rank.SPECIES; } ensureTaxaAreSorted(); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ private boolean matchesScientificName (final @Nonnull Taxon taxon, final @Nonnull CharSequence match, final @Nonnull NameMatcher nameMatcher) { return nameMatcher.matches(taxon.getScientificName(), match, Locale.ENGLISH); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ private boolean matchesLocalizedNames (final @Nonnull Taxon taxon, final @Nonnull CharSequence match, final @Nonnull NameMatcher nameMatcher) { for (final Locale locale : preferences.get().getTaxonomyLocales()) { try { if (nameMatcher.matches(taxon.getDisplayName(locale), match, locale)) { return true; } } catch (NotFoundException e) { // never mind } } return false; }
@Nonnull private String getDisplayName (final @Nonnull Taxon taxon) { try { return taxon.getDisplayName(primaryTaxonLocale); } catch (NotFoundException e) { // We prepend some zeds to scientific names, so if they are compared against common names, // they go to the bottom of the list. // FIXME: in some locales, Z is not the last letter! return "ZZZZZZZ" + taxon.getScientificName(); } } };
@Nonnull public String getLocalizedName (final @Nonnull Taxon taxon) throws NotFoundException { // FIXME: string concatenation here kills the performance - make it "No name for %s", taxon); // return NotFoundException.throwWhenNull(map.get(taxon.getId()), "No name for " + taxon); return NotFoundException.throwWhenNull(map.get(taxon.getId()), "No name for taxon"); }
public void renderTo (final @Nonnull TextView textView, final @Nonnull Object ... args) { textView.setText(Html.fromHtml(taxon.as(HtmlRenderable).render(args))); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull private String renderHierarchy() { final StringBuilder buffer = new StringBuilder(); for (final Taxon taxon : getPath()) { buffer.append(String.format("%s<br>", taxon.getScientificName())); } return buffer.toString(); }
final String displayName = taxon.getDisplayName(locale); buffer.append(separator + size1 + style1 + displayName + style2 + size2); style1 = style2 = ""; buffer.append(String.format("<small><i>%s</i></small>", taxon.getScientificName()));
/******************************************************************************************************************* * * ******************************************************************************************************************/ public void addToTaxonHistory (final @Nonnull Taxon taxon) { final Id id = taxon.getId(); taxonIdHistory.remove(id); taxonIdHistory.add(0, id); while (taxonIdHistory.size() > maxHistorySize) { taxonIdHistory.remove(maxHistorySize); } save(); }
public void renderTo (final @Nonnull View view, final @Nonnull Object ... args) { final TextView textView = (TextView)view.findViewById(R.id.text); textView.setText(Html.fromHtml(taxon.as(HtmlRenderable).render(args))); } }
@Nonnull public String render (final @Nonnull Object... args) { final StringBuilder buffer = new StringBuilder(); String separator = ""; final List<Locale> taxonLocales = preferences.get().getTaxonomyLocales(); for (final Locale locale : taxonLocales) { try { buffer.append(separator).append(taxon.getDisplayName(locale)); separator = ", "; } catch (NotFoundException e) { // a localized name not available, just ignore it } } if (preferences.get().isScientificNamesRenderingEnabled()) { buffer.append(" (").append(taxon.getScientificName()).append(")"); } return buffer.toString(); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void addDisplayName (final @Nonnull JSONObject jsonObject, final @Nonnull Taxon taxon, final @Nonnull Locale locale) { final String languageCode = "lang_" + locale.getLanguage(); final String displayName = jsonObject.optString(languageCode); if ((displayName != null) && !displayName.equals("")) { final String language = locale.getLanguage(); Map<Id, String> nameBag = nameBagsByLanguage.get(language); if (nameBag == null) { nameBag = new HashMap<Id, String>(); nameBagsByLanguage.put(language, nameBag); } nameBag.put(taxon.getId(), displayName); } }
public void run() { log.info("renderTaxon({})", taxon); taxon.as(TextViewRenderable).renderTo(tvTaxon, TaxonRenderingOptions.PRIMARY_AND_SCIENTIFIC_NAME); } });