/*
 * PiAnoS (Picture Annotation System), A fingerprint examiner training tool
 * Copyright (C) 2011-2012 University of Lausanne, Switzerland
 * https://ips-labs.unil.ch/pianos
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */

/**
 * @constructor
 */
function ImageEditor_Invert( params )
{
    // ------------------------------
    // Constructor
    // ------------------------------
    
    params = params || {};
    if( !params )
        params = new Object();
    if( !params.cssPrefix )
        params.cssPrefix = 'imageeditor_';
    
    // ------------------------------
    // Public methods
    // ------------------------------
    
    this.init = function( editorObj )
    {
        editor = editorObj;
    }

    this.getPanel = function()
    {
        if( !panel )
        {
            buildUI();
        }
        return panel;
    }

    this.getName = function()
    {
        return 'invert';
    }

    this.getLabel = function()
    {
        return 'Invert';
    }

    this.getHelp = function()
    {
        return [
            'Replace each pixel with its complementary color.', 'The red, green, and blue intensities of an image are negated. White becomes black, yellow becomes blue, etc.'
        ];
    }

    this.getFilter = function()
    {
        return {
            grayscale: grayscale,
        };
    }

    this.setFilter = function( filter )
    {
    }

    // ------------------------------
    // Private variables
    // ------------------------------
    
    var self = this;
    var panel = null;
    var editor = null;
    
    var grayscale = false;
    
    // ------------------------------
    // Private functions
    // ------------------------------
    
    var mycss = function( suffix )
    {
        return params.cssPrefix + suffix;
    }

    var buildUI = function()
    {
        assert( !panel );
        
        panel = $( '<div />' ).addClass( mycss( 'tool_panel' ) );
        
        var randomID = 'imageeditor_tool_invert' + ( new Date().getTime() );
        var grayscaleBox = $( '<input type="checkbox" ' + ( grayscale ? 'checked="checked"' : '' ) + ' id="' + randomID + '" />' );
        grayscaleBox.bind( 'click', function()
        {
            grayscale = this.checked;
            editor.onFilterChanged( self );
        } );
        var label = $( '<label for="' + randomID + '" />' ).text( 'Apply to grayscale pixels only' );
        
        panel.append( grayscaleBox ).append( label );
    }
}
