/*------------------------------------------------------------------------------
 src/lib/djWidget/imageOpLutWidget.cxx
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "djImageOpColorWidget.h"
#include <djFileNameWidget.h>

namespace dj {

ImageOpLutWidget::ImageOpLutWidget()
{
  _widget = new FileNameWidget;
  
  VLayout * layout = new VLayout(this);
  layout->add(_widget);
  layout->stretchAdd();
  
  widgetUpdate();
  
  _widget->sig().set(this, widgetCallback);
}

void ImageOpLutWidget::set(ImageOp * in)
{
  ImageOpWidget::set(in);
  widgetUpdate();
}

void ImageOpLutWidget::widgetUpdate()
{
  Str fileName;
  if (_op) {
    StrList data = _op->attr(imageOpLutAttrStr()[ImageOpLut::ATTR_FILE_NAME]);
    inflateStr(data, &fileName);
  }
  _widget->set(fileName);
}

void ImageOpLutWidget::widgetCallback(const Str & in)
{
  if (! _op) return;
  _op->attr(imageOpLutAttrStr()[ImageOpLut::ATTR_FILE_NAME], deflateStr(in));
  sig().emit(true);
  widgetUpdate();
}

}
