/*
 * 	Copyright (c) 2010, Java Swing Components
 * 	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 Java Swing Components nor the
 *        names of its contributors may be used to endorse or promote products
 *        derived from this software without specific prior written permission.
 *      * Redistributions must also adhere to the terms and conditions of the 
 *        specific distribution licenses purchased from Java Swing Components. 
 * 	      (be it developer, enterprise or source code). 
 * 
 *  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 JAVA SWING COMPONENTS 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.
 * 
 * Additional Terms And Conditions.
 *
 * 1. Conditions
 * The purchase of a license for a component from Java Swing Components entitles you to the following: 
 *   1.1. You may use the component on as many projects as you desire. There are no restrictions regarding the number of deployments, and you may bundle the component as part of your software, be it commercial or personal.
 *   1.2. Once you have purchased a component, there is no limit on how many times you may download the Java archive or its supporting documentation.
 *   1.3. 3 months free email support for the purchased component. Additional support will require the purchase of an extended support contract.
 *   1.4. Receive bug fixes and updates for the version of the component purchased. Note that this only includes increments of the component's minor version. To illustrate this, if you purchase version 1.0 of a specific component, you are entitled to all future minor updates (i.e. 1.1, 1.2 ... 1.n).
 *   1.5. In the event that a major version is released within 3 months of you purchasing the previous version, you will be automatically entitled to the new version. To illustrate this, if you purchase version 1.0 of a specific component, you are entitled to version 2.0 for free, if version 2.0 is released within 3 months of your purchase of version 1.0.
 *
 * 2. Restrictions
 * Restrictions apply to all types of licenses:
 *   2.1. You may not directly resell licensed component to other individuals or entities. To illustrate this, you may not sell the Java archive to third parties. Please note that this does not restrict you from including the component in commercial software; it prevents you directly selling the archive to other third parties.
 *   2.2. If the deployment of your software directly exposes the API of the component to third party developers, there may be an additional deployment fee. To illustrate this, if you sell a product whose primary target is developers, they will gain access to the licensed component and be able to use it in their own software. Please note that this does not restrict you from including the component in commercial software; it is intended to prevent other third party developers from making use of components that they have not purchased.
 *   2.3. A license may not be automatically transferred. An enterprise license is granted to a named enterprise and may not be transferred to another enterprise. A developer license is granted to a named developer and may not be transferred to another developer. Java Swing Components does not support a floating license. Please contact us directly if you need to transfer a license.
 *
 * 3. License Types
 * At present there are 3 types of licenses available: developer, enterprise and source code.
 *   3.1. A developer license entitles a single named developer to make use of the licensed components.
 *   3.2. An enterprise license entitles all developers within the enterprise to make use of the licensed components.
 *   3.3. A source code license is available and applies on an enterprise scale; please contact us for more details.
 *
 * If you have additional questions regarding the licensing, please feel free to contact us directly.
 */
package com.javaswingcomponents.demo;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import com.javaswingcomponents.framework.painters.configurationbound.ImagePainter;
import com.javaswingcomponents.framework.painters.configurationbound.SolidColorPainter;
import com.javaswingcomponents.rater.JSCRater;
import com.javaswingcomponents.rater.model.DefaultRaterModel;
import com.javaswingcomponents.rater.model.DefaultRaterModel.Selection;


public class Demo {
	private static JFrame frame;
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
					frame = new JFrame("Rater Skinning Demo");
					
					JPanel mainPanel = new JPanel(new GridLayout(2,1));
					mainPanel.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
					mainPanel.add(createDefaultRater());
					mainPanel.add(createCustomRater());
					frame.getContentPane().add(mainPanel);
					frame.pack();
					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setSize(396, 340);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	protected static Component createDefaultRater() {
		JSCRater rater = new JSCRater();
		rater.setBorder(BorderFactory.createTitledBorder("Standard"));
		return rater;
	}

	private static Component createCustomRater() {
		//creates a new instance of JSCRater
		JSCRater rater = new JSCRater();
		
		//creates a new model with 5 shapes that allows the user
		//to select half shapes
		DefaultRaterModel raterModel = new DefaultRaterModel();
		raterModel.setSelection(Selection.HALVES);
		raterModel.setNumShapes(5);
		rater.setRaterModel(raterModel);
		
		//creates a new CowShape and assigns it to the rater.
		CowShape cowShape = new CowShape();
		rater.setShapeProvider(cowShape);
		
		//creates a new unselected painter which will
		//fill the empty areas of the shape blue.
		Color tuCowsBlue = new Color(43,176,245);
		SolidColorPainter unselectedPainter = new SolidColorPainter(tuCowsBlue);
		rater.setUnselectedPainter(unselectedPainter);
		
		//creates a new selected painter which will
		//tile the filled areas of the shape with cowPrint.
		ImagePainter selectedPainter = new ImagePainter(Thread.currentThread().getContextClassLoader().getResourceAsStream("cows.png"));
		selectedPainter.setTile(true);
		rater.setSelectedPainter(selectedPainter);

		//sets the mouse over border color to light gray.
		rater.setMouseOverBorderColor(Color.LIGHT_GRAY);
		//sets the standard border to black.
		rater.setBorderColor(Color.BLACK);
		//sets the rater to draw a drop shadow. this is expensive on large raters.
		rater.setDrawShadow(true);
		
		rater.setBorder(BorderFactory.createTitledBorder("Custom"));
		return rater;
	}
	
}

