/** 
 * This script is being run when a skin is selected
 * The script produces a custom user interface with a lot of goodies.
 * Please look at the "Camera Geek" skin for a smaller example.
 * Author David Ekholm
 */
 
import se.datadosen.component.*;
engine.processBeanShellFile(new File(programDirectory, "includes/printing.bsh"));

// Controls that are to be imported into JAlbum as variables
ControlPanel ui = new ControlPanel() {

	JTextField copyright = new JTextField("");
	JComboBox thumbnailText = new JComboBox(new Object[]
	 { "Nothing", "Number", "Label", "File name", "Comment", "Date" }
	);
	JTextField fontSize = new JTextField("11");
	JComboBox printing = getPrintingComboBox();
	JCheckBox fixedShape = new JCheckBox("Crop to fixed shape");
	JCheckBox grayscale = new JCheckBox("Make grayscale");
	JCheckBox zoomThumbs = new JCheckBox("Zoom");
	JTextField zoomPercent = new JTextField("30");
	
	JCheckBox showLabels = new JCheckBox("Show labels");
	JCheckBox showDates = new JCheckBox("Show dates", true);
	JCheckBox showImageNum = new JCheckBox("Show image numbers", true);
	JTextField watermark = new JTextField("");
	JTextField watermarkSize = new JTextField("36");
	
	JColorSelector bgcolor = new JColorSelector("Background color");
	JColorSelector color = new JColorSelector("Text color");
	JColorSelector bordercolor = new JColorSelector("Link color");
};

// Layout controls easily similar to how text is added in a word processor
ui.add(new JLabel("JAlbum skins may now have custom user interfaces! This is an example"));
ui.add("br", new JLabel("Skin developers, look at the \"onload.bsh\" script to see how this page is made!")); 

ui.add("p", new JLabel("Copyright"));
ui.add("tab hfill", ui.copyright);

ControlPanel orderPrints = new ControlPanel("On-line print ordering");
orderPrints.add(new JLabel("Printing service linking"));
orderPrints.add(ui.printing);
ui.add("p hfill", orderPrints);


ControlPanel cc = new ControlPanel("Colors (for custom style)");
cc.add(new JLabel("Background color"));
cc.add("tab", ui.bgcolor);
cc.add("br", new JLabel("Border color"));
cc.add("tab", ui.bordercolor);
cc.add("br", new JLabel("Text color"));
cc.add("tab", ui.color);
ui.add("p vtop", cc);

ControlPanel indexPanel = new ControlPanel("Thumbnails");
indexPanel.add(new JLabel("Text"));
indexPanel.add(ui.thumbnailText);
indexPanel.add(ui.fontSize);
indexPanel.add("br", ui.fixedShape);
indexPanel.add("br", ui.grayscale);
indexPanel.add("br", ui.zoomThumbs);
indexPanel.add(ui.zoomPercent);
indexPanel.add(new JLabel("%"));
ui.add(indexPanel);

ControlPanel slidePanel = new ControlPanel("Slides");
slidePanel.add(ui.showLabels);
slidePanel.add("br", ui.showDates);
slidePanel.add("br", ui.showImageNum);
slidePanel.add("br", new JLabel("Watermark text and size"));
slidePanel.add("br hfill", ui.watermark);
slidePanel.add(ui.watermarkSize);

ui.add("hfill", slidePanel);

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;
}

// Make the border color similar to the background color
ui.bgcolor.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
		ui.bordercolor.setColor(getMatchingColor(ui.bgcolor.getColor()));
	}
});


// Configure controls
ui.bgcolor.setColor("#ccccff");
ui.fontSize.setToolTipText("Text size in pixels");
ui.fixedShape.setToolTipText("Crop images to 'image bounds' dimension. Press 'Rebuild all' to apply");
ui.grayscale.setToolTipText("Make images grayscale. Press 'Rebuild all' to apply");
ui.zoomThumbs.setToolTipText("Make thumbnails easier to see by enlarging focus area. Press 'Rebuild all' to apply");
ui.watermark.setToolTipText("Add watermark text onto each image. Press 'Rebuild all' to apply");
String text = "Each slide may contain a link that puts that image into a shopping cart for printing and delivery";
orderPrints.setToolTipText(text);
ui.printing.setToolTipText(text);


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