001/**
002 * Copyright (c) 2008-2014 Ardor Labs, Inc.
003 *
004 * This file is part of Ardor3D.
005 *
006 * Ardor3D is free software: you can redistribute it and/or modify it 
007 * under the terms of its license which may be found in the accompanying
008 * LICENSE file or at <http://www.ardor3d.com/LICENSE>.
009 */
010
011package com.ardor3d.example.ui;
012
013import java.util.ArrayList;
014import java.util.List;
015import java.util.logging.Logger;
016
017import com.ardor3d.ui.text.BMFont;
018import com.ardor3d.util.resource.ResourceLocatorTool;
019import com.ardor3d.util.resource.ResourceSource;
020
021/**
022 * Simple hack singleton that loads some font textures and provides easy access.
023 */
024public class BMFontLoader {
025    static Logger logger = Logger.getLogger(BMFontLoader.class.getName());
026
027    static BMFontLoader s_instance = null;
028    final ArrayList<BMFont> _fontList = new ArrayList<>();
029
030    public static List<BMFont> allFonts() {
031        return instance()._fontList;
032    }
033
034    public static BMFont defaultFont() {
035        return instance()._fontList.get(0);
036    }
037
038    private static BMFontLoader instance() {
039        if (s_instance == null) {
040            s_instance = new BMFontLoader();
041        }
042        return s_instance;
043    }
044
045    private BMFontLoader() {
046        final FontLoad[] fontNames = new FontLoad[] { new FontLoad("DejaVuSansCondensed-20-bold-regular", true),
047                new FontLoad("DroidSans-15-bold-regular", false), // --------------------
048                new FontLoad("LiberationMono-15-bold-regular", false), // ---------------
049                new FontLoad("FreebooterScript-60-medium-regular", true), // ------------
050                new FontLoad("Bandy-35-medium-regular", true), // -----------------------
051                new FontLoad("OkasaSansSerif-35-medium-regular", true),// ---------------
052                new FontLoad("Chinyen-30-medium-regular", true), // ---------------------
053                new FontLoad("Computerfont-35-medium-regular", true) };
054
055        for (final FontLoad fl : fontNames) {
056            try {
057                final String file = "fonts/" + fl.fontName + ".fnt";
058                final ResourceSource url = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, file);
059                final BMFont bmFont = new BMFont(url, fl.useMipMaps);
060                _fontList.add(bmFont);
061            } catch (final Throwable t) {
062                logger.warning(t.getMessage());
063            }
064        }
065        logger.info("defaultFont = " + _fontList.get(0).getStyleName());
066    }
067
068    private static class FontLoad {
069        String fontName;
070        boolean useMipMaps;
071
072        FontLoad(final String name, final boolean mipMap) {
073            fontName = name;
074            useMipMaps = mipMap;
075        }
076    }
077
078}