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

nl.cloudfarming.client.sensor.SensorPalette Maven / Gradle / Ivy

There is a newer version: 13.03-beta
Show newest version
/**
 * Copyright (C) 2008-2012 AgroSense Foundation.
 *
 * AgroSense is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
 * this software, see the FLOSS License Exception
 * .
 *
 * AgroSense 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with AgroSense.  If not, see .
 */
package nl.cloudfarming.client.sensor;

import java.awt.Color;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import nl.cloudfarming.client.geoviewer.Palette;
import nl.cloudfarming.client.geoviewer.ValueRange;
import org.netbeans.api.visual.model.ObjectState;
import org.openide.util.lookup.ServiceProvider;

/**
 * SensorPalette. The sensor palette contains different colors for different
 * sensor reading values. The sensor palette is interchangeable. It contains a
 * static list with palettes for different value ranges.
 *
 *
 * @author Timon Veenstra
 */
@ServiceProvider(service = Palette.class)
public class SensorPalette extends Palette implements ValueRange, Serializable {

    private double rangeFrom;
    private double rangeTo;
    private int nrOfColors = 20;
    public static final int SENSOR_DATA_MULTIPLIER = 1000;
    private static final List> choiceList = new ArrayList<>();
    public static final SensorPalette PALLET01_04 = new SensorPalette(0.1, 0.4);
    public static final SensorPalette PALLET01_06 = new SensorPalette(0.1, 0.6);
    public static final SensorPalette PALLET01_08 = new SensorPalette(0.1, 0.8);
    public static final SensorPalette PALLET02_04 = new SensorPalette(0.2, 0.4);
    public static final SensorPalette PALLET02_06 = new SensorPalette(0.2, 0.6);
    public static final SensorPalette PALLET02_08 = new SensorPalette(0.2, 0.8);
    public static final SensorPalette PALLET00_10 = new SensorPalette(0.1, 1.0);

    static {
        choiceList.add(PALLET01_04);
        choiceList.add(PALLET01_06);
        choiceList.add(PALLET01_08);
        choiceList.add(PALLET02_04);
        choiceList.add(PALLET02_06);
        choiceList.add(PALLET02_08);
        choiceList.add(PALLET00_10);
    }

    public SensorPalette() {
        super(Color.BLACK);
    }
    
    

    private SensorPalette(double rangeFrom, double rangeTo) {
        super(Color.BLACK);
        this.rangeFrom = rangeFrom;
        this.rangeTo = rangeTo;

    }

    public double getRangeFrom() {
        return rangeFrom;
    }

    public double getRangeTo() {
        return rangeTo;
    }

    @Override
    public String toString() {
        return "SensorDataPallet " + rangeFrom + " -> " + rangeTo;
    }

    @Override
    public Double getMinValue() {
        return rangeFrom * SENSOR_DATA_MULTIPLIER;
    }

    @Override
    public Double getMaxValue() {
        return rangeTo * SENSOR_DATA_MULTIPLIER;
    }

    @Override
    public int getSteps() {
        return nrOfColors;
    }

    @Override
    public boolean supports(Class clazz) {
        return (SensorDataObject.class.isAssignableFrom(clazz));
    }

    @Override
    public Color getColorForValue(Number value) {
        double dvalue = value.doubleValue();
        double step = (getRangeTo() - getRangeFrom()) / ((getSteps() - 1));

        if (dvalue < 0d) {
            return Color.BLACK;
        } else if (dvalue <= getRangeFrom() * SENSOR_DATA_MULTIPLIER) {
            return new Color(0x8F050C);
        } else if (dvalue <= (getRangeFrom() + (1 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xB60A06);
        } else if (dvalue <= (getRangeFrom() + (2 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xDB0F01);
        } else if (dvalue <= (getRangeFrom() + (3 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xE32600);
        } else if (dvalue <= (getRangeFrom() + (4 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xE24000);
        } else if (dvalue <= (getRangeFrom() + (5 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xE65E00);
        } else if (dvalue <= (getRangeFrom() + (6 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xF17F00);
        } else if (dvalue <= (getRangeFrom() + (7 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xFC9F00);
        } else if (dvalue <= (getRangeFrom() + (8 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xFDB703);
        } else if (dvalue <= (getRangeFrom() + (9 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xFAD007);
        } else if (dvalue <= (getRangeFrom() + (10 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xF7E80B);
        } else if (dvalue <= (getRangeFrom() + (11 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xDCF40A);
        } else if (dvalue <= (getRangeFrom() + (12 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0xB7F805);
        } else if (dvalue <= (getRangeFrom() + (13 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0x92FC00);
        } else if (dvalue <= (getRangeFrom() + (14 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0x69E003);
        } else if (dvalue <= (getRangeFrom() + (15 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0x41C405);
        } else if (dvalue <= (getRangeFrom() + (16 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0x16A508);
        } else if (dvalue <= (getRangeFrom() + (17 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0x048608);
        } else if (dvalue <= (getRangeFrom() + (18 * step)) * SENSOR_DATA_MULTIPLIER) {
            return new Color(0x046707);
        } else if (dvalue <= getRangeTo()) {
            return new Color(0x044606);
        }
        return Color.GRAY;
    }

    @Override
    public Color getColorForState(ObjectState state) {
        return Color.BLACK;
    }

    @Override
    public boolean isInterchangeable() {
        return true;
    }

    @Override
    public List> getInterchangeablePalettes() {
        return Collections.unmodifiableList(choiceList);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy