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

org.oscim.renderer.bucket.TextItem Maven / Gradle / Ivy

Go to download

OpenGL vector map library written in Java - running on Android, iOS, Desktop and within the browser.

There is a newer version: 0.21.0
Show newest version
/*
 * Copyright 2012 Hannes Janetzek
 * Copyright 2017 Luca Osten
 *
 * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
 *
 * This program is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * this program. If not, see .
 */
package org.oscim.renderer.bucket;

import org.oscim.theme.styles.TextStyle;
import org.oscim.utils.pool.Inlist;
import org.oscim.utils.pool.SyncPool;

public class TextItem extends Inlist {
    //static final Logger log = LoggerFactory.getLogger(TextItem.class);
    private static final int MAX_POOL = 250;

    public static final SyncPool pool = new SyncPool(MAX_POOL) {

        @Override
        protected TextItem createItem() {
            return new TextItem();
        }

        @Override
        protected boolean clearItem(TextItem ti) {
            // drop references
            ti.label = null;
            ti.text = null;
            //ti.n1 = null;
            //ti.n2 = null;
            return true;
        }
    };

    public static TextItem copy(TextItem orig) {

        TextItem ti = pool.get();

        ti.x = orig.x;
        ti.y = orig.y;

        ti.x1 = orig.x1;
        ti.y1 = orig.y1;
        ti.x2 = orig.x2;
        ti.y2 = orig.y2;

        return ti;
    }

    public TextItem set(float x, float y, String label, TextStyle text) {
        this.x = x;
        this.y = y;
        this.label = label;
        this.text = text;
        this.x1 = 0;
        this.y1 = 0;
        this.x2 = 1;
        this.y2 = 0;
        this.width = text.paint.measureText(label);
        return this;
    }

    // center
    public float x, y;

    // label text
    public String label;

    // text style
    public TextStyle text;

    // label width
    public float width;

    // left and right corner of segment
    public float x1, y1, x2, y2;

    // segment length
    public short length;

    // link to next/prev label of the way
    //public TextItem n1;
    //public TextItem n2;

    public byte edges;

    @Override
    public String toString() {
        return x + " " + y + " " + label;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy