/**
 * Copyright (c) 2011, Martin Foster <martin@ethereal-realms.org>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice, 
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright 
 *       notice, this list of conditions and the following disclaimer in the 
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Ethereal-Realms.org nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.lyra.Interface.Menu;

import java.util.Map;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSlider;
import javax.swing.SwingConstants;

import org.lyra.Lyra;


/**
 * These elements can be used in various circumstances to control volume
 * or the crossfade capability.  In order to provide generality the capability
 * of extracting an instance of JMenu or JPopupMenu is available.
 * <p>
 * @author Martin Foster
 * @version 1.0.4, %Revision, 147%, %LastChangedDate, 06/11/11 4:57PM%
 */
public class CrossfadeMenu extends JSlider {
	
	// Serial Requirements
	private static final long serialVersionUID = 1L;
	
	/*
	 * USER INTERFACE ELEMENT
	 */
	private JMenu menuCrossfade = null;
	private JPopupMenu popupCrossfade = null;
	private JPanel panelCrossfade = null;
	
	
	/*
	 * PACKAGE ELEMENTS
	 */
	private Map<String,String> Lang;
	

	/**
	 * Base constructor for class.  There is no visual editor class due to
	 * the simplicity of the elements.
	 * <p>
	 * @param lang Language map for language independence.
	 */
	public CrossfadeMenu(Map<String,String> lang) {
		
		// Create instance with established minimum and maximums
		super(0, 15);
		
		// Pass up
		Lang = lang;
		
		// Adjust Alignment
		this.setOrientation(
				SwingConstants.VERTICAL);
		
		//Turn on labels at major tick marks.
		this.setMajorTickSpacing(5);
		this.setMinorTickSpacing(1);
		this.setPaintTicks(true);
		this.setPaintLabels(true);
		
		// Identifier
		this.setName("CONTROL.CROSSFADE");
	}
	// End of Constructor Method
	
	
	/**
	 * This method initialises controlCrossfade.  Displays the volume control
	 * widget for display.
	 * <p>
	 * @return javax.swing.JMenu	
	 */
	public JMenu getMenuCrossfade() {
		
		// Check for Existence
		if (menuCrossfade == null) {
			
			// Create Instance
			menuCrossfade = new JMenu();
			
			// Language Element
			menuCrossfade.setText(Lang.get("Organizer.Menu.Options.Crossfade"));
						
			// Add in Slider
			menuCrossfade.add(this);
			
			// Add in Embellishments
			menuCrossfade.addSeparator();
			menuCrossfade.add(getPanelCrossfade());
		}
		
		// Return Instance
		return menuCrossfade;
	}
	// End of getMenuCrossfade Method
	
	
	/**
	 * This method initialises controlCrossfade.  Displays the volume control
	 * widget for display.
	 * <p>
	 * @return javax.swing.JPopupMenu	
	 */
	public JPopupMenu getPopupCrossfade() {
		
		// Check for Existence
		if (popupCrossfade == null) {
			
			// Create Instance
			popupCrossfade = new JPopupMenu();
			
			// Identifier
			popupCrossfade.setName("CONTROL.CROSSFADE");
			
			// Add in Slider
			popupCrossfade.add(this);
			
			// Add in Embellishments
			popupCrossfade.addSeparator();
			popupCrossfade.add(getPanelCrossfade());
		}
		
		// Return Instance
		return popupCrossfade;
	}
	// End of getControlCrossfade Method
	
	
	/**
	 * This method initialises checkCrossfade.  Provides a clean method for
	 * having the icon centred at the bottom as would be expected.
	 * <p>
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelCrossfade() {
		
		// Check for Existence
		if (panelCrossfade == null) {
			
			// Create Instance
			panelCrossfade = new JPanel();
			
			// Establish layout
			panelCrossfade.setLayout(new BoxLayout(panelCrossfade, BoxLayout.X_AXIS));
			
			/*
			 * This should create a centred look which will force the icon
			 * directly to the centre which rarely happens otherwise.
			 */
			
			// Spacer
			panelCrossfade.add(Box.createHorizontalGlue());

			// Embellishment
			panelCrossfade.add(new JLabel((new ImageIcon(
					getClass().getResource(
							Lyra.getIconByMap("Prompt-Crossfade"))))));
			
			// Spacer
			panelCrossfade.add(Box.createHorizontalGlue());
		}
		
		// Return instance
		return panelCrossfade;
	}
	// End of getPanelCrossfade Method

	
	/**
	 * Sets the value of the slider to a desired position.
	 * <p>
	 * @param value Integer containing position in slider.
	 */
	public void setState(int value) {
		
		// Adjust the slider value
		this.setValue(value);
	}
	// End of setState Method
	
	
	/**
	 * Gets the value of the slider at its current position.
	 * <p>
	 * @return Integer containing position in slider.
	 */
	public int getState() {
		
		// Pass-through method
		return this.getValue();
	}
	// End of getState Method
	
}
