package etf;

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped;
import javax.faces.bean.RequestScoped;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

@ManagedBean(name="srbija")
@RequestScoped
public class Srbija {
    private String izlaz = null;
    private Rectangle okrug1 = new Rectangle(116,160,176,220);
    private Rectangle okrug2 = new Rectangle(200,180,260,240);
    private Rectangle okrug3 = new Rectangle(40,180,90,230);
    private Rectangle okrug4 = new Rectangle(134,253,235,285);
    private Rectangle okrug5 = new Rectangle(63,282,117,365);
    
    public void uhvatiKlik(ActionEvent dogadjaj){
        FacesContext context = FacesContext.getCurrentInstance();
        String klijent = dogadjaj.getComponent().getClientId(context);
        Map<String, String> parametri =
                context.getExternalContext().getRequestParameterMap();
        int x = new Integer((String) parametri.get(klijent + ".x")).intValue();
        int y = new Integer((String) parametri.get(klijent + ".y")).intValue();
        
        izlaz = null;
        
        if(okrug1.contains(new Point(x, y)))
            izlaz = "beograd";
        
        if(okrug2.contains(new Point(x, y)))
            izlaz = "smederevo";
        
        if(okrug3.contains(new Point(x, y)))
            izlaz = "valjevo";
        
        if(okrug4.contains(new Point(x, y)))
            izlaz = "kragujevac";
        
        if(okrug5.contains(new Point(x, y)))
            izlaz = "uzice";
    }

    public String navigacija(){
        return izlaz;
    }   
}