/** 
 * This script loads when ExhibitPLus is loaded and defines additional options 
 */
 
import se.datadosen.component.*;
import se.datadosen.util.*;
import se.datadosen.jalbum.event.*;

// Read localized strings to use in user interface
File f = new File(skinDirectory, "texts");
SmartResourceBundle texts = SmartResourceBundle.getBundle(IO.relativePath(f, programDirectory));

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

ControlPanel ui = new ControlPanel() {

	JCheckBox allowEmptyFolderDescription = new JCheckBox(texts.getString("ui.allowEmptyFolderDescription"));
	JTextField dateFormat = new JTextField("dd.MM.yyyy");
	JComboBox displayEXIF = new JComboBox(new Object[] { "always", "userselect", "never" } );
	JCheckBox displayW3CLogosOnIndex = new JCheckBox(texts.getString("ui.displayW3CLogos"), true);
	JCheckBox displayW3CLogosOnSlide = new JCheckBox(texts.getString("ui.displayW3CLogos"), true);
	JCheckBox fixedFormatIndexPage = new JCheckBox(texts.getString("ui.fixedFormatIndexPage"));
	JCheckBox fixedFormatIndexPageStretching = new JCheckBox(texts.getString("ui.fixedFormatIndexPageStretching"));
	JTextField folderAgeNew = new JTextField("30");
	JCheckBox forceLandscapeSlideLayout = new JCheckBox(texts.getString("ui.forceLandscapeSlideLayout"));
	JCheckBox imageCommentUnderThumbnail = new JCheckBox(texts.getString("ui.imageCommentUnderThumbnail"));
	JCheckBox imageNameUnderThumbnail = new JCheckBox(texts.getString("ui.imageNameUnderThumbnail"));
	JTextField imagePaddingAdjust = new JTextField("100");
	JCheckBox keyboardShortcuts = new JCheckBox(texts.getString("ui.keyboardShortcuts"), true);
	JTextField numberOfMiniThumbs = new JTextField("10");
	JCheckBox polaroidMode = new JCheckBox(texts.getString("ui.polaroidMode"));
	JCheckBox protectIndexImages = new JCheckBox(texts.getString("ui.protectImages"));
	JCheckBox protectSlideImages = new JCheckBox(texts.getString("ui.protectImages"));
	JCheckBox sameSizeFilterIndex = new JCheckBox(texts.getString("ui.sameSizeFilterIndex"));
	JComboBox upButtonAtRootIndexPage = new JComboBox(new Object[] { "normal", "force", "never" } ); 
	JCheckBox useThumbForFolderIcon = new JCheckBox(texts.getString("ui.useThumbForFolderIcon"), true);
	JTextField watermark = new JTextField("");
	JTextField watermarkSize = new JTextField("20");
	JCheckBox shutterfly = new JCheckBox(texts.getString("ui.shutterfly"), true);
	JCheckBox fullScreenButtons = new JCheckBox(texts.getString("ui.fullScreenButtons"), true);
	JCheckBox navigationTop = new JCheckBox(texts.getString("ui.navigationTop"), true);
	JCheckBox navigationBottom = new JCheckBox(texts.getString("ui.navigationBottom"), true);
	JCheckBox jumpDirectFullscreen = new JCheckBox(texts.getString("ui.jumpDirectFullscreen"), false);
	JCheckBox singleFolderMode = new JCheckBox(texts.getString("ui.singleFolderMode"), false);
	JCheckBox commentAboveSlide = new JCheckBox(texts.getString("ui.commentAboveSlide"), false);
	JCheckBox slideShowContinuous = new JCheckBox(texts.getString("ui.slideShowContinuous"), false);
	JTextField slideShowDelay = new JTextField("4");
	JTextField miniThumbAdjust = new JTextField("25");
	JTextField numberIndexColumns = new JTextField("1");
	JComboBox language = new JComboBox();
	JComboBox iconSet = new JComboBox();
	JCheckBox displayFolderDateAdded = new JCheckBox(texts.getString("ui.displayFolderDateAdded"), true); 
	JCheckBox imageDateUnderThumbnail = new JCheckBox(texts.getString("ui.imageDateUnderThumbnail"), false);	
};

public List getSupportedLanguages()
{
	Iterator it = Arrays.asList(skinDirectory.listFiles()).iterator();
	List result = new LinkedList();
	
	while( it.hasNext() )
	{
		String file_name = ((File)it.next()).getName().toLowerCase();
		
		if( !file_name.startsWith("texts_") || !file_name.endsWith(".properties") )
			continue;
		
		int end_index = file_name.indexOf(".properties");
		
		result.add( file_name.substring(6, end_index) );
	}
	return result;
}

public void setItemsForComboBox(JComboBox combo, List items)
{
//	Collections.sort(items);
	combo.removeAllItems();
	
	Iterator it = items.iterator();
	
	while( it.hasNext() )
		combo.addItem( it.next() );
}

public List getIconSets()
{
	Iterator it = Arrays.asList(new File(skinDirectory,"button-sets").listFiles()).iterator();
	List result = new LinkedList();
	
	result.add( "default" );
	while( it.hasNext() )
	{
		File file = (File)it.next();
		
		if( !file.isDirectory() )
			continue;
		
		result.add( file.getName() );
	}
	return result;
}


RiverLayout layout = (RiverLayout)ui.getLayout();
layout.setHgap(0);
ui.add(new JLabel(texts.getString("ui.welcome1") + " 1.3 (01.05.2004)"));
ui.add("br", new JLabel(texts.getString("ui.welcome2") + " "));
JLinkLabel link = new JLinkLabel(texts.getString("ui.welcome3")); 
link.setURL("http://www.fyvie.net/photos/info_exhibitplus.html");
ui.add(link);
ui.add(new JLabel(" " + texts.getString("ui.welcome4"))); 


ControlPanel generalPanel = new ControlPanel(texts.getString("ui.generalOptions"));
RiverLayout layout = (RiverLayout)generalPanel.getLayout();
layout.setHgap(1);
setItemsForComboBox(ui.language, getSupportedLanguages());
generalPanel.add(new JLabel(texts.getString("ui.languageLabel")));
generalPanel.add("tab", ui.language);
setItemsForComboBox(ui.iconSet, getIconSets());

generalPanel.add("br", new JLabel(texts.getString("ui.iconSetLabel")));
generalPanel.add("tab", ui.iconSet);
generalPanel.add("br", ui.keyboardShortcuts);
generalPanel.add("br", new JLabel(texts.getString("ui.dateFormat") + " "));
generalPanel.add(ui.dateFormat);

ControlPanel slidePanel = new ControlPanel(texts.getString("ui.slides"));
RiverLayout layout = (RiverLayout)slidePanel.getLayout();
layout.setHgap(0);
layout.setVgap(0);

ControlPanel upperSlidePanel = new ControlPanel();

RiverLayout layout = (RiverLayout)upperSlidePanel.getLayout();
layout.setHgap(1);

upperSlidePanel.add(ui.navigationTop);
upperSlidePanel.add("tab", ui.forceLandscapeSlideLayout);
upperSlidePanel.add("tab", ui.fullScreenButtons);
upperSlidePanel.add("br", ui.navigationBottom);
upperSlidePanel.add("tab", ui.protectSlideImages);
upperSlidePanel.add("tab", ui.slideShowContinuous);
upperSlidePanel.add("br", ui.commentAboveSlide);
upperSlidePanel.add("tab", ui.polaroidMode);

upperSlidePanel.add("tab", ui.shutterfly);
JLinkLabel link = new JLinkLabel("shutterfly.com");
link.setURL("http://www.shutterfly.com");
upperSlidePanel.add(link);

upperSlidePanel.add("br", ui.displayW3CLogosOnSlide);

slidePanel.add("br hfill", upperSlidePanel);

ControlPanel lowerSlidePanel = new ControlPanel();

lowerSlidePanel.add("br", new JLabel(texts.getString("ui.miniThumbnails") + " "));
lowerSlidePanel.add("tab", ui.numberOfMiniThumbs);
lowerSlidePanel.add("br", new JLabel(texts.getString("ui.miniThumbAdjust") + " "));
lowerSlidePanel.add("tab", ui.miniThumbAdjust);
lowerSlidePanel.add(new JLabel("%"));
lowerSlidePanel.add("br", new JLabel(texts.getString("ui.imageFrameAdjust") + " "));
lowerSlidePanel.add("tab", ui.imagePaddingAdjust);
lowerSlidePanel.add(new JLabel("%"));
lowerSlidePanel.add("br", new JLabel(texts.getString("ui.slideshowDelay") + " "));
lowerSlidePanel.add("tab", ui.slideShowDelay);
lowerSlidePanel.add(new JLabel(" " + texts.getString("ui.seconds")));
lowerSlidePanel.add("br", new JLabel(texts.getString("ui.displayEXIF") + " "));
lowerSlidePanel.add("tab", ui.displayEXIF);
lowerSlidePanel.add("br", new JLabel(texts.getString("ui.watermarkSize") + " "));
lowerSlidePanel.add("tab", ui.watermarkSize);
lowerSlidePanel.add("tab", new JLabel(texts.getString("ui.watermarkText") + " "));
lowerSlidePanel.add("hfill", ui.watermark);

slidePanel.add("p hfill", lowerSlidePanel);

ControlPanel indexPanel = new ControlPanel(texts.getString("ui.thumbnails"));
RiverLayout layout = (RiverLayout)indexPanel.getLayout();
layout.setHgap(1);
indexPanel.add(ui.allowEmptyFolderDescription);
indexPanel.add("tab", ui.displayW3CLogosOnIndex);
indexPanel.add("br", ui.fixedFormatIndexPage);
indexPanel.add("tab", ui.imageCommentUnderThumbnail);
indexPanel.add("br", ui.fixedFormatIndexPageStretching);
indexPanel.add("tab", ui.imageNameUnderThumbnail);
indexPanel.add("br", ui.protectIndexImages);
indexPanel.add("tab", ui.imageDateUnderThumbnail);
indexPanel.add("br", ui.useThumbForFolderIcon);
indexPanel.add("tab", ui.displayFolderDateAdded);
indexPanel.add("br", ui.singleFolderMode);
indexPanel.add("tab", ui.sameSizeFilterIndex);
indexPanel.add("br", ui.jumpDirectFullscreen);

indexPanel.add("br", new JLabel(texts.getString("ui.numberIndexColumns") + " "));
indexPanel.add(ui.numberIndexColumns);

indexPanel.add("br", new JLabel(texts.getString("ui.newFolders") + " "));
indexPanel.add(ui.folderAgeNew);
indexPanel.add(new JLabel(" " + texts.getString("ui.daysOld")));

indexPanel.add("br", new JLabel(texts.getString("ui.upButton") + " "));
indexPanel.add(ui.upButtonAtRootIndexPage);


JTabbedPane tabs = new JTabbedPane();
tabs.add(indexPanel, texts.getString("ui.indexPanel"));
tabs.add(slidePanel, texts.getString("ui.slidePanel"));
tabs.add(generalPanel, texts.getString("ui.generalPanel"));

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

// Configure controls
ui.allowEmptyFolderDescription.setToolTipText(texts.getString("ui.allowEmptyFolderDescriptionToolTip"));
ui.dateFormat.setToolTipText(texts.getString("ui.dateFormat.setToolTipText"));
ui.displayEXIF.setToolTipText(texts.getString("ui.displayEXIF.setToolTipText"));
ui.displayW3CLogosOnIndex.setToolTipText(texts.getString("ui.displayW3CLogosOnIndex.setToolTipText"));
ui.displayW3CLogosOnSlide.setToolTipText(texts.getString("ui.displayW3CLogosOnSlide.setToolTipText"));
ui.fixedFormatIndexPage.setToolTipText(texts.getString("ui.fixedFormatIndexPage.setToolTipText"));
ui.fixedFormatIndexPageStretching.setToolTipText(texts.getString("ui.fixedFormatIndexPageStretching.setToolTipText"));
ui.folderAgeNew.setToolTipText(texts.getString("ui.folderAgeNew.setToolTipText"));
ui.forceLandscapeSlideLayout.setToolTipText(texts.getString("ui.forceLandscapeSlideLayout.setToolTipText"));
ui.imageCommentUnderThumbnail.setToolTipText(texts.getString("ui.imageCommentUnderThumbnail.setToolTipText"));
ui.imageNameUnderThumbnail.setToolTipText(texts.getString("ui.imageNameUnderThumbnail.setToolTipText"));
ui.imagePaddingAdjust.setToolTipText(texts.getString("ui.imagePaddingAdjust.setToolTipText"));
ui.keyboardShortcuts.setToolTipText(texts.getString("ui.keyboardShortcuts.setToolTipText"));
ui.numberOfMiniThumbs.setToolTipText(texts.getString("ui.numberOfMiniThumbs.setToolTipText"));
ui.polaroidMode.setToolTipText(texts.getString("ui.polaroidMode.setToolTipText"));
ui.protectIndexImages.setToolTipText(texts.getString("ui.protectIndexImages.setToolTipText"));
ui.protectSlideImages.setToolTipText(texts.getString("ui.protectSlideImages.setToolTipText"));
ui.sameSizeFilterIndex.setToolTipText(texts.getString("ui.sameSizeFilterIndex.setToolTipText"));
ui.upButtonAtRootIndexPage.setToolTipText(texts.getString("ui.upButtonAtRootIndexPage.setToolTipText"));
ui.useThumbForFolderIcon.setToolTipText(texts.getString("ui.useThumbForFolderIcon.setToolTipText"));
ui.shutterfly.setToolTipText(texts.getString("ui.shutterfly.setToolTipText"));
ui.watermark.setToolTipText(texts.getString("ui.watermark.setToolTipText"));
ui.watermarkSize.setToolTipText(texts.getString("ui.watermarkSize.setToolTipText"));
ui.fullScreenButtons.setToolTipText(texts.getString("ui.fullScreenButtons.setToolTipText"));
ui.navigationTop.setToolTipText(texts.getString("ui.navigationTop.setToolTipText"));
ui.navigationBottom.setToolTipText(texts.getString("ui.navigationBottom.setToolTipText"));
ui.jumpDirectFullscreen.setToolTipText(texts.getString("ui.jumpDirectFullscreen.setToolTipText"));
ui.singleFolderMode.setToolTipText(texts.getString("ui.singleFolderMode.setToolTipText"));
ui.commentAboveSlide.setToolTipText(texts.getString("ui.commentAboveSlide.setToolTipText"));
ui.slideShowContinuous.setToolTipText(texts.getString("ui.slideShowContinuous.setToolTipText"));
ui.miniThumbAdjust.setToolTipText(texts.getString("ui.miniThumbAdjust.setToolTipText"));
ui.language.setToolTipText(texts.getString("ui.language.setToolTipText"));
ui.iconSet.setToolTipText(texts.getString("ui.iconSet.setToolTipText"));
ui.displayFolderDateAdded.setToolTipText(texts.getString("ui.displayFolderDateAdded.setToolTipText"));
ui.imageDateUnderThumbnail.setToolTipText(texts.getString("ui.imageDateUnderThumbnail.setToolTipText"));

// Allow other languages than specified in list
ui.language.setEditable(true);

// Set default language
ui.language.setSelectedItem(System.getProperty("user.language"));

// Set default iconSet
ui.iconSet.setSelectedItem("default");

window.addJAlbumListener(new JAlbumAdapter() {
   public void skinUIDisplayed(JAlbumEvent e) {
   	System.out.println("Displayed");
   }

   public void skinUIHidden(JAlbumEvent e) {
   	System.out.println("Hidden");
   }

   public void styleChanged(JAlbumEvent e) {
   	System.out.println("StyleChange");
	// Set default iconSet
	ui.iconSet.setSelectedItem("default");
   }

   public void skinChanged(JAlbumEvent e) {
   	System.out.println("SkinChange");
   }
   
   public void albumCreationStarted(JAlbumEvent e) {
   	System.out.println("Creation started");
   }
   
   public void albumCreationFinished(JAlbumEvent e) {
   	System.out.println("Creation finished");
   }
   
});

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