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

nl.cloudfarming.client.util.swing.icon.BadgePosition Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2008-2013 LimeTri. All rights reserved.
 *
 * 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.util.swing.icon;

import java.awt.Dimension;
import java.awt.Point;

/**
 * Enum defining and calculating badge position
 *
 * @author Frantisek Post
 */
public enum BadgePosition {

    NORTH_WEST(0),
    NORTH_EAST(1),
    SOUTH_WEST(2),
    SOUTH_EAST(3),
    NORTH(4),
    EAST(5),
    SOUTH(6),
    WEST(7);
    
    
    private static final int margin = 1;
    private int type;

    private BadgePosition(int type) {
        this.type = type;
    }

    public Point getBadgePosition(Dimension baseDimension, Dimension badgeDimension) {
        Point point = null;
        switch (type) {
            case 0:
                point = new Point(margin, margin);
                break;
            case 1:
                point = new Point(baseDimension.width - badgeDimension.width - margin, margin);
                break;
            case 2:
                point = new Point(margin, baseDimension.height - badgeDimension.height - margin);
                break;
            case 3:
                point = new Point(baseDimension.width - badgeDimension.width - margin, baseDimension.height - badgeDimension.height - margin);
                break;
            case 4:
                point = new Point((baseDimension.width - badgeDimension.width) / 2, margin);
                break;
            case 5:
                point = new Point(baseDimension.width - badgeDimension.width - margin, (baseDimension.height - badgeDimension.height) / 2);
                break;
            case 6:
                point = new Point((baseDimension.width - badgeDimension.width) / 2, baseDimension.height - badgeDimension.height - margin);
                break;
            case 7:
                point = new Point(margin, (baseDimension.height - badgeDimension.height) / 2);
                break;
            default:
                break;
        }

        return point;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy