/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 *

package familiada;
import java.awt.*;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.ImageIcon;




public class Draw extends JPanel {

  private static Font mainFont = new Font("Tahoma", Font.BOLD, 55);
  private static Font questFont = new Font("Tahoma", Font.BOLD, 45);
  private static Font ansFont = new Font("Tahoma", Font.BOLD, 35);
  private static Font underline = new Font("Tahoma", Font.PLAIN, 25);
  private int width, height;
  private int sheight=200;
  private int swidth=100;
  private Question[] questions;
  private Graphics g;
  public int qw;
  private Main pr;

  private int actualMarginTop = 0;

    int prop = 1;
    int skaluj =0;
  public Draw(Main pr) {


      this.questions = pr.questions;
      this.pr = pr;
  }
  @Override public void paintComponent(Graphics g)
  {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension scrnsize = toolkit.getScreenSize();
    this.g = g;
qw = 0;


    width = getWidth();
    height = getHeight();
    skaluj = width;
    if(actualMarginTop>0 && prop==1)
    {
        prop = width/actualMarginTop;
    }

         if(width>(height*prop))
         {
             skaluj = height*prop;
         }
    mainFont = new Font("Tahoma", Font.BOLD, (50*skaluj)/1024);
         questFont = new Font("Tahoma", Font.BOLD, (30*skaluj)/1024);
         ansFont = new Font("Tahoma", Font.BOLD, (25*skaluj)/1024);
         underline = new Font("Tahoma", Font.PLAIN, (15*skaluj)/1024);

         sheight=((100*skaluj)/1024);
         swidth=((50*skaluj)/1024);

actualMarginTop = 0;
    g.setColor(Color.black);
    g.fillRect(0, 0, width, height);
    mainlogo();
    questions();
    if(pr.ended)
    {
        end();
    }
  }
  public void punkty()
  {
    g.setFont(questFont);
    Integer punktyl = (Integer) pr.pktl;
    FontMetrics  fm = g.getFontMetrics();
    String txt = " "+punktyl.toString()+" ";
    int w = fm.stringWidth(txt);
    int h = fm.getHeight();
    int padding = fm.stringWidth("----");

    g.setColor(Color.WHITE);
    g.fillRect((width/2) - (qw/2) - w - padding, actualMarginTop-h, w, h);
    g.setColor(Color.BLACK);
    g.drawString(txt, (width/2) - (qw/2) - (w) - padding, actualMarginTop-(h/4));

    g.setFont(questFont);
    Integer punktyr = (Integer) pr.pktr;
     txt = " "+punktyr.toString()+" ";
     w = fm.stringWidth(txt);
     h = fm.getHeight();
     padding = fm.stringWidth("----");
    g.setColor(Color.WHITE);
    g.fillRect((width/2) + (qw/2)  + padding, actualMarginTop-h, w, h);
    g.setColor(Color.BLACK);
    g.drawString(txt, (width/2) + (qw/2) + (padding) , actualMarginTop-(h/4));
  }
  public void questions()
  {
    for(Question qs:questions)
    {
        if(qs.isActive())
        {
            
            g.setColor(Color.black);
            g.fillRect(0, 0, width, height);
            g.setColor(Color.YELLOW);
            g.setFont(questFont);
            FontMetrics  fm = g.getFontMetrics();
            int h = fm.getAscent();
            actualMarginTop += fm.getHeight()*2;
            int textmargin = actualMarginTop;
            String[] text = qs.getText().split("\\|");
            for(int i=0; i<text.length; i++)
            {
                String[] result = new Splitter(40).split(text[i]);
                for(String s:result)
                {
                    int fontwidth = fm.stringWidth(s);
                    if(fontwidth>qw) { qw = fontwidth; }
                     g.drawString(s, (width/2) - (fontwidth / 2), textmargin);
                      textmargin += +fm.getHeight();
                }
             
            }
              punkty();
              actualMarginTop += textmargin-fm.getHeight();
            strata(qs);
                answers(qs);

        }
    }
    repaint();
  }
  public void strata(Question qs)
  {
      g.setColor(Color.YELLOW);
      int borderWidth = ((10*skaluj)/1024);
      int margin = ((30*skaluj)/1024);
      int hmargin = ((50*skaluj)/1024);
      for(int st=0; st<qs.straty[0]; st++)
      {
        int x = (width/2) - (qw/2)-hmargin;
        int y = actualMarginTop+((sheight+margin)*st);
        for(int xp=0; xp<borderWidth; xp++)
        {
            g.drawLine(x-swidth+xp, y, x+xp, y+sheight);
            g.drawLine(x+xp, y, x+xp-swidth, y+sheight);
        }
      }
       if(qs.duzastrata[0]) {
              int x = (width/2) - (qw/2)-hmargin;
              int y = actualMarginTop+((sheight+margin)*2);

              g.setColor(Color.black);
              g.fillRect(x-swidth-borderWidth, actualMarginTop, swidth+(2*borderWidth), ((sheight+margin)*3));
              g.setColor(Color.RED);
              for(int xp=0; xp<borderWidth; xp++)
              {
                g.drawLine(x-swidth+xp, actualMarginTop, x+xp, y);
                g.drawLine(x+xp, actualMarginTop, x+xp-swidth, y);
              }
          }

      g.setColor(Color.YELLOW);
      //Prawe X'y
      for(int st=0; st<qs.straty[1]; st++)
      {
          int x = (width/2) + (qw/2)+hmargin;
              int y = actualMarginTop+((sheight+margin)*st);
              for(int xp=0; xp<borderWidth; xp++)
              {
                g.drawLine(x+xp, y, x+xp+swidth, y+sheight);
                g.drawLine(x+swidth+xp, y, x+xp, y+sheight);
              }
      }
      //Duzy czerwony X
        if(qs.duzastrata[1])
        {
              int x = (width/2) + (qw/2)+hmargin;
              int y = actualMarginTop+((sheight+margin)*2);

              g.setColor(Color.black);
              g.fillRect(x-borderWidth, actualMarginTop, swidth+(2*borderWidth), ((sheight+margin)*3));
              g.setColor(Color.RED);
              for(int xp=0; xp<borderWidth; xp++)
              {
                g.drawLine(x+xp, actualMarginTop, x+xp+swidth, y);
                g.drawLine(x+swidth+xp, actualMarginTop, x+xp, y);
              }
        }
  }
  public void answers(Question qs)
  {
      Answer[] ans = qs.getAnswers();
        for(int z=0; z<ans.length; z++)
        {

            String text = ans[z].getText();
            FontMetrics fm = g.getFontMetrics();
            int w = fm.stringWidth(text);
            int h = fm.getHeight();

            g.setFont(underline);
            fm = g.getFontMetrics();
            int kropka =  fm.stringWidth(".");
            int ilekropek = qw/kropka;
            String kropki = "";
            for(int k=0; k<ilekropek; k++)
            {
                kropki +=".";
            }

            g.setColor(Color.WHITE);
            actualMarginTop += h;

            g.drawString(kropki, (width/2) - (qw / 2), actualMarginTop);
            g.setFont(ansFont);
            if(ans[z].isactive())
            {
                fm = g.getFontMetrics();
                int answidth =  fm.stringWidth(text);
                g.setColor(Color.black);
                g.fillRect( (width/2) - (qw / 2), actualMarginTop - fm.getHeight()+fm.getDescent(), answidth, fm.getAscent());

                g.setColor(Color.YELLOW);
                g.drawString(text, (width/2) - (qw / 2), actualMarginTop);


                fm = g.getFontMetrics();
                w = fm.stringWidth(ans[z].getCount());

                g.setColor(Color.black);
                g.fillRect( (width/2) + (qw/2)-w, actualMarginTop - fm.getHeight()+fm.getDescent(), w, fm.getAscent());

                g.setColor(Color.YELLOW);
                g.drawString(ans[z].getCount(), (width/2) + (qw / 2)-w, actualMarginTop);
            }

        }

  }
  public void mainlogo()
  {
    g.setColor(Color.YELLOW);

    g.setFont(mainFont);
    String text = "FAMILIADA";
    FontMetrics  fm = g.getFontMetrics();
    int w = fm.stringWidth(text);
    int h = fm.getAscent();
    g.drawString(text, (width/2) - (w / 2), (height/2) + - h);
    text = "by";
    fm = g.getFontMetrics();
    w = fm.stringWidth(text);
    int h1 = fm.getAscent();
    g.drawString(text, (width/2) - (w / 2), (height/2) );
    g.drawImage(hernasLogo(), (width/2) - (imgwidth/2), (height/2) + h, imgwidth, imgheight, null);

  }
  public void end()
  {

    g.setColor(Color.black);
    g.fillRect(0, 0, width, height);
    
    g.setColor(Color.YELLOW);

    g.setFont(mainFont);
    String text = pr.pktl+" do "+pr.pktr;
    FontMetrics  fm = g.getFontMetrics();
    int w = fm.stringWidth(text);
    int h = fm.getAscent();
    g.drawString(text, (width/2) - (w / 2), (h / 2) +h*2);

    g.setFont(questFont);
    text = "Brawa dla obu drużyn!";
    fm = g.getFontMetrics();
    w = fm.stringWidth(text);
    g.drawString(text, (width/2) - (w / 2), (h/2) + h*3);


    g.drawImage(hernasLogo(), width/2 - imgwidth/2, height-imgheight, imgwidth, imgheight, null);
    repaint();
  }

      int imgwidth = 0;
      int imgheight = 0;
    public Image  hernasLogo()
    {
           java.net.URL imgURL = getClass().getResource("logohernas.png");
           ImageIcon imgicon = new ImageIcon(imgURL);
           
        imgwidth = ((imgicon.getIconWidth()*skaluj)/1024);
        imgheight = ((imgicon.getIconHeight()*skaluj)/1024);

       return imgicon.getImage();
    }


}
 * */
 
