import se.datadosen.component.*;
import se.datadosen.jalbum.event.*;


window.addJAlbumListener(new JAlbumAdapter() {
	String originalIndexPageName;
	String originalPageExtension;

  public void albumCreationStarted(JAlbumEvent e) {
	System.out.println("Setting xml again");
	originalIndexPageName = engine.getIndexPageName();
	originalPageExtension = engine.getPageExtension();
	engine.setIndexPageName("BananAlbum");
	engine.setPageExtension(".xml");
	engine.setRows(1200);  
  }

  public void albumCreationFinished(JAlbumEvent e) {
  	System.out.println("Creation finished");
    engine.setIndexPageName(originalIndexPageName);
    engine.setPageExtension(originalPageExtension);
  }
});


// Controls that are to be imported into JAlbum as variables

ControlPanel ui = new ControlPanel() {
	
	JCheckBox txt = new JCheckBox("show comments", true);
	JCheckBox showlabels = new JCheckBox("show labels", true);
	JCheckBox download = new JCheckBox("enable download");
	JCheckBox rightmouseDownload = new JCheckBox("download using right mouse button");
	JCheckBox downloadPHP = new JCheckBox("[php]");
	JComboBox chooseDownload = new JComboBox(new Object[] { "open image in pop-up", "make button say 'supersize'", "just open image in new window", "enable direct download (php required)"} ); 
	JCheckBox supersize = new JCheckBox("enable supersize");
	JCheckBox hidethumbs = new JCheckBox("hide thumbnails");

JComboBox thumbStyle = new JComboBox(new Object[] { "default", "grid"} ); 
JComboBox activeThumb = new JComboBox(new Object[] { "default", "bar"} ); 

JCheckBox centerthumbs = new JCheckBox("center", true);
JCheckBox scrollbar = new JCheckBox("show scrollbar", true);
	JCheckBox exifinfo = new JCheckBox("add exif info");
	JCheckBox dateaslabel = new JCheckBox("date as label");
	JCheckBox slideshow = new JCheckBox("slideshow");
	JCheckBox fullscreen = new JCheckBox("enable full screen", true);
JComboBox imgTransition = new JComboBox(new Object[] { "default", "classic", "none"} ); 


	JCheckBox outline = new JCheckBox("image outline", true);
	
	JColorSelector bgcolor = new JColorSelector("background color");
	JColorSelector txtcolor = new JColorSelector("color of labels, comments and the BananaTree");
	JColorSelector imgcolor = new JColorSelector("image color");
	JColorSelector linecolor = new JColorSelector("color of all lines");
	JColorSelector activecolor = new JColorSelector("color of active BananaBranch");
	
	JCheckBox autoScale = new JCheckBox("autoscale image", true);
	JCheckBox preload = new JCheckBox("preload images", true);
	JCheckBox cropThumbs = new JCheckBox("crop thumbnails", false);
	JTextField margin = new JTextField("14", 4);
	JTextField topMargin = new JTextField("16", 4);
	JTextField thumbSpacing = new JTextField("5", 4);
	JTextField banaPrefix = new JTextField("[", 3);
	JTextField banaSuffix = new JTextField("]", 3);
	JTextField slideshowInterval = new JTextField("4", 5);

	JTextField slideshowX = new JTextField(5);
	JTextField slideshowY = new JTextField(5);
	JCheckBox slideshowBig = new JCheckBox("big icon", false);
	JCheckBox slideshowAuto = new JCheckBox("autostart", false);

	JCheckBox externalComments = new JCheckBox("get comments from external textfiles", false);

	JCheckBox treeactive = new JCheckBox("activate BananaTree", true);

JCheckBox nobg = new JCheckBox("transparent background", false);

	JTextField customType = new JTextField("");
	JTextField customTree = new JTextField("");
	JTextField bg = new JTextField("", 9);
	JTextField treeY = new JTextField("", 5);

	JTextField txtx = new JTextField(5);
	JTextField txty = new JTextField(5);
	JTextField txtw = new JTextField(5);
	JTextField txth = new JTextField(5);

	JTextField labelx = new JTextField(5);
	JTextField labely = new JTextField(5);

	JTextField imgx = new JTextField(5);
	JTextField imgminx = new JTextField(5);
	JTextField imgy = new JTextField(5);
	JTextField imgw = new JTextField(5);
	JTextField imgh = new JTextField(5);

	JTextField thumbw = new JTextField("68", 5);
	JTextField thumbh = new JTextField("68", 5);

JTextField slideshowtxt = new JTextField("play slideshow, pause slideshow", 18);

	JCheckBox imgFade = new JCheckBox("fade image", true);

JCheckBox tile = new JCheckBox("tile", false);

	JComboBox labeltype = new JComboBox(new Object[] { "default", "monaco", "rudinpx", "chicago", "arial", "custom1", "custom2"} ); 
	JComboBox txttype = new JComboBox(new Object[] { "default", "monaco", "rudinpx", "chicago", "arial", "custom1", "custom2"} ); 

JComboBox chooseTree = new JComboBox(new Object[] { "default", "no-icon", "monaco-tree", "rudinpx-tree", "chicago-tree", "arial-tree", "arial-no-icon", "custom-tree"} ); 
JComboBox chooseThumbPos = new JComboBox(new Object[] { "top", "bottom", "left", "right", "disable"} ); 

};

RiverLayout layout = (RiverLayout)ui.getLayout();
layout.setHgap(0);

ControlPanel generalPanel = new ControlPanel("General");

ControlPanel cc = new ControlPanel("Colors");
cc.add(new JLabel("background"));
cc.add("tab", ui.bgcolor);
cc.add("br", new JLabel("line"));
cc.add("tab", ui.linecolor);
cc.add("br", new JLabel("image"));
cc.add("tab", ui.imgcolor);
cc.add("br", new JLabel("text"));
cc.add("tab", ui.txtcolor);
cc.add("br", new JLabel("active branch"));
cc.add("tab", ui.activecolor);
generalPanel.add("vtop", cc);


ControlPanel imgPanel = new ControlPanel("Images");
imgPanel.add(ui.outline);
imgPanel.add("br", ui.slideshow);
// imgPanel.add("br", ui.download);
// imgPanel.add("tab", ui.downloadPHP);
// imgPanel.add("br", ui.supersize);
generalPanel.add(imgPanel);

ControlPanel thumbPanel = new ControlPanel("Thumbnails");
thumbPanel.add("br", new JLabel("width: "));
thumbPanel.add("", ui.thumbw);
thumbPanel.add("", new JLabel("height: "));
thumbPanel.add("", ui.thumbh);
thumbPanel.add("br", new JLabel("thumbnail position:"));
thumbPanel.add(ui.chooseThumbPos);
thumbPanel.add("br", ui.hidethumbs);
thumbPanel.add("p",new JLabel("Please Note:"));
// // thumbPanel.add("br",new JLabel("Thumbs will only autohide when set to 'top'."));
thumbPanel.add("br",new JLabel("BananaTree won't appear when set to 'left'."));
generalPanel.add("hfill", thumbPanel);


ControlPanel txtPanel = new ControlPanel("Text");
txtPanel.add(ui.txt);
txtPanel.add("br", new JLabel("typeface for comments:"));
txtPanel.add(ui.txttype);
txtPanel.add("br", ui.showlabels);
txtPanel.add("br", new JLabel("typeface for labels:"));
txtPanel.add(ui.labeltype);
txtPanel.add("br", ui.exifinfo);
txtPanel.add("br", ui.dateaslabel);
// // JLinkLabel typeExample = new JLinkLabel("Examples"); 
// // typeExample.setURL("http://www.BananAlbum.net/examples/typeface");
// txtPanel.add(typeExample);
generalPanel.add("br hfill", txtPanel);

ControlPanel treePanel = new ControlPanel("BananaTree");
treePanel.add("", ui.treeactive);
treePanel.add("br", new JLabel("BananaTree:"));
treePanel.add(ui.chooseTree);
// // JLinkLabel treeExample = new JLinkLabel("Examples"); 
// // treeExample.setURL("http://www.BananAlbum.net/examples/bananatree");
// treePanel.add("br", treeExample);
generalPanel.add(treePanel);

JLinkLabel BananAlbumLink = new JLinkLabel("BananAlbum.net"); 
BananAlbumLink.setURL("http://www.BananAlbum.net");
generalPanel.add("br",BananAlbumLink);

ControlPanel expertPanel = new ControlPanel("Expert");

expertPanel.add("", ui.download);
expertPanel.add("", ui.chooseDownload);
expertPanel.add("", ui.rightmouseDownload);
expertPanel.add("br", ui.preload);
// expertPanel.add("", ui.autoScale);
expertPanel.add("", ui.imgFade);
expertPanel.add("", ui.fullscreen);
expertPanel.add("", new JLabel("transition: "));
expertPanel.add("", ui.imgTransition);
expertPanel.add("br", ui.cropThumbs);

expertPanel.add("", ui.centerthumbs);
expertPanel.add("", new JLabel("style: "));
expertPanel.add("", ui.thumbStyle);
expertPanel.add("", new JLabel("active thumb: "));
expertPanel.add("", ui.activeThumb);
expertPanel.add("", ui.scrollbar);
expertPanel.add("br", ui.externalComments);
// expertPanel.add("", ui.nobg);

expertPanel.add("br", new JLabel("  "));

expertPanel.add("br", new JLabel("border: "));
expertPanel.add("", ui.margin);
expertPanel.add("", new JLabel("thumbmargin: "));
expertPanel.add("", ui.topMargin);
expertPanel.add("", new JLabel("thumbspacing: "));
expertPanel.add("", ui.thumbSpacing);
expertPanel.add("br", new JLabel("BananaTree prefix: "));
expertPanel.add("", ui.banaPrefix);
expertPanel.add("", new JLabel("suffix: "));
expertPanel.add("", ui.banaSuffix);
expertPanel.add("br", new JLabel("background image: "));
expertPanel.add("", ui.bg);
expertPanel.add("", ui.tile);
expertPanel.add("br", new JLabel("slideshow interval: "));
expertPanel.add("", ui.slideshowInterval);
expertPanel.add("", ui.slideshowBig);
expertPanel.add("", ui.slideshowAuto);
expertPanel.add("", ui.slideshowtxt);
// // expertPanel.add("br", new JLabel("use custom typeface: "));
// // expertPanel.add("hfill", ui.customType);
// // expertPanel.add("br", new JLabel("use custom BananaTree: "));
// // expertPanel.add("hfill", ui.customTree);

expertPanel.add("br", new JLabel("  "));
expertPanel.add("br", new JLabel("Define size and/or position.. "));

JLinkLabel calcExample = new JLinkLabel("You can do calculations!"); 
calcExample.setURL("http://www.BananAlbum.com/examples/calculate");
expertPanel.add("", calcExample);

expertPanel.add("br", new JLabel("image "));
expertPanel.add("tab", new JLabel("x: "));
expertPanel.add("", ui.imgx);
expertPanel.add("", new JLabel("min x: "));
expertPanel.add("", ui.imgminx);
expertPanel.add("", new JLabel("y: "));
expertPanel.add("", ui.imgy);
expertPanel.add("", new JLabel("w: "));
expertPanel.add("", ui.imgw);
expertPanel.add("", new JLabel("h: "));
expertPanel.add("", ui.imgh);

expertPanel.add("br", new JLabel("labels "));
expertPanel.add("tab", new JLabel("x: "));
expertPanel.add("", ui.labelx);
expertPanel.add("", new JLabel("y: "));
expertPanel.add("", ui.labely);

expertPanel.add("br", new JLabel("comments "));
expertPanel.add("tab", new JLabel("x: "));
expertPanel.add("", ui.txtx);
expertPanel.add("", new JLabel("y: "));
expertPanel.add("", ui.txty);
expertPanel.add("", new JLabel("w: "));
expertPanel.add("", ui.txtw);
expertPanel.add("", new JLabel("h: "));
expertPanel.add("", ui.txth);

expertPanel.add("br", new JLabel("BananaTree "));
expertPanel.add("tab", new JLabel("y: "));
expertPanel.add("tab", ui.treeY);

expertPanel.add("br", new JLabel("slideshow "));
expertPanel.add("tab", new JLabel("x: "));
expertPanel.add("", ui.slideshowX);
expertPanel.add("", new JLabel("y: "));
expertPanel.add("", ui.slideshowY);

// settings like thumbspacing, margin, topmargin, delbreaks, bananatree y, prefix, suffix, imgx, imgy, back txt en link, collapse bananatree, bgimg, slideshow interval...

Color getMatchingColor(Color c) {
	float brightness = ((float)(3*c.getRed()+4*c.getGreen()+c.getBlue()))/2040;
	if (brightness < 0.3) c = c.brighter();
	if (brightness < 0.5) c = c.brighter();
	else c = c.darker();
	return c;
}

// Configure controls
ui.bgcolor.setColor("#EEEEEE");
ui.linecolor.setColor("#000000");
ui.imgcolor.setColor("#FFFFFF");
ui.txtcolor.setColor("#000000");
ui.activecolor.setColor("#444444");

JTabbedPane tabs = new JTabbedPane();
tabs.add(generalPanel, "General");
tabs.add(expertPanel, "Expert");

ui.add("vtop hfill vfill", tabs);

// Finally install components into JAlbum
window.setSkinUI(ui);
window.pack();
