package org.fissore.cooee2impress.linuxday;

import org.fissore.cooee2impress.utils.GUIUtils;
import org.karora.cooee.app.Alignment;
import org.karora.cooee.app.Button;
import org.karora.cooee.app.Column;
import org.karora.cooee.app.ContentPane;
import org.karora.cooee.app.Extent;
import org.karora.cooee.app.Font;
import org.karora.cooee.app.HttpImageReference;
import org.karora.cooee.app.Insets;
import org.karora.cooee.app.Label;
import org.karora.cooee.app.Row;
import org.karora.cooee.app.SplitPane;
import org.karora.cooee.app.layout.ColumnLayoutData;
import org.karora.cooee.ng.ExtentEx;

public class Intro extends ContentPane {

  private static final long serialVersionUID = 8515820563862255950L;

  private static final HttpImageReference IMG_JUGTORINO = new HttpImageReference(
      "images/jugtorino.jpg");
  private static final HttpImageReference IMG_LINUXDAY = new HttpImageReference(
      "images/linuxdaypng.png");
  private static final HttpImageReference IMG_DUKE = new HttpImageReference(
      "images/duke.png");

  private static final Font FONT_16PT_PLAIN = new Font(Font.SANS_SERIF,
      Font.PLAIN, new Extent(16, Extent.PT));
  static final Font FONT_16PT_BOLD = new Font(Font.SANS_SERIF, Font.BOLD,
      new Extent(16, Extent.PT));
  static final Font FONT_50PT = new Font(Font.SANS_SERIF, Font.BOLD,
      new Extent(50, Extent.PT));

  public Intro() {
    super();

    buildUI();
  }

  private void buildUI() {
    SplitPane sp = new SplitPane(SplitPane.ORIENTATION_HORIZONTAL_RIGHT_LEFT);
    add(sp);

    sp.setSeparatorPosition(new ExtentEx(280));

    ColumnLayoutData columnLayoutData = new ColumnLayoutData();
    columnLayoutData.setAlignment(new Alignment(Alignment.CENTER,
        Alignment.DEFAULT));
    columnLayoutData.setInsets(new Insets(0, 10, 0, 10));
    Column col = new Column();
    sp.add(col);
    col.add(GUIUtils.buildButton(IMG_LINUXDAY, "http://linuxdaytorino.org/",
        columnLayoutData));
    col.add(GUIUtils.buildButton(IMG_JUGTORINO, "http://www.jugtorino.it/",
        columnLayoutData));
    col.add(GUIUtils.buildButton(IMG_DUKE, "https://openjdk.dev.java.net/",
        columnLayoutData));

    Row row = new Row();
    row.setInsets(new Insets(0, 200, 0, 0));
    sp.add(row);

    col = new Column();
    row.add(col);

    col.setCellSpacing(new Extent(10));
    col.add(new Label("Cooee") {
      private static final long serialVersionUID = -5579175397172528019L;
      {
        this.setFont(FONT_50PT);
      }
    });
    col.add(new Label("Webapp più app che web") {
      private static final long serialVersionUID = 6943051704659585702L;
      {
        this.setFont(FONT_16PT_BOLD);
      }
    });
    Column col3 = new Column();
    col.add(col3);
    col3.setInsets(new Insets(0, 30, 0, 0));
    col3.add(GUIUtils.buildLabel("Federico Fissore"));
    col3.add(buildLink("federico@fissore.org", "mailto:federico@fsfe.org"));
    col3.add(buildLink("http://www.fissore.org/blog/",
        "http://www.fissore.org/blog/"));
  }

  private Button buildLink(String text, String url) {
    Button button = GUIUtils.buildButton(text, url);
    button.setFont(FONT_16PT_PLAIN);
    return button;
  }
}
