
org.opencms.ade.galleries.client.preview.CmsImagePreviewHandler Maven / Gradle / Ivy
Show all versions of opencms-gwt Show documentation
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.ade.galleries.client.preview;
import org.opencms.ade.galleries.client.preview.ui.CmsImagePreviewDialog;
import org.opencms.ade.galleries.shared.CmsImageInfoBean;
import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.gwt.client.util.I_CmsSimpleCallback;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
/**
* Image preview dialog controller handler.
*
* Delegates the actions of the preview controller to the preview dialog.
*
* @since 8.0.0
*/
public class CmsImagePreviewHandler extends A_CmsPreviewHandler
implements ValueChangeHandler {
/** Enumeration of image tag attribute names. */
public enum Attribute {
/** Image align attribute. */
align,
/** Image alt attribute. */
alt,
/** Image class attribute. */
clazz,
/** Image copyright info. */
copyright,
/** Image direction attribute. */
dir,
/** No image selected if this attribute is present. */
emptySelection,
/** The image hash. */
hash,
/** Image height attribute. */
height,
/** Image hspace attribute. */
hspace,
/** Image id attribute. */
id,
/** Image copyright flag. */
insertCopyright,
/** Image link original flag. */
insertLinkOrig,
/** Image spacing flag. */
insertSpacing,
/** Image subtitle flag. */
insertSubtitle,
/** Image language attribute. */
lang,
/** Image link path. */
linkPath,
/** Image link target. */
linkTarget,
/** Image longDesc attribute. */
longDesc,
/** Image style attribute. */
style,
/** Image title attribute. */
title,
/** Image vspace attribute. */
vspace,
/** Image width attribute. */
width
}
/** List of handlers for cropping changes. */
private List m_croppingHandlers = new ArrayList<>();
/** The cropping parameter. */
private CmsCroppingParamBean m_croppingParam;
/** The image format handler. */
private CmsImageFormatHandler m_formatHandler;
/** List of handlers for focal point changes. */
private List m_imagePointHandlers = new ArrayList<>();
/** The focal point controller. */
private CmsFocalPointController m_pointController;
/** The preview dialog. */
private CmsImagePreviewDialog m_previewDialog;
/** The image container width. */
private int m_containerWidth;
/** The image container height. */
private int m_containerHeight;
/**
* Constructor.
*
* @param resourcePreview the resource preview instance
*/
public CmsImagePreviewHandler(CmsImageResourcePreview resourcePreview) {
super(resourcePreview);
m_previewDialog = resourcePreview.getPreviewDialog();
m_pointController = new CmsFocalPointController(
() -> m_croppingParam,
this::getImageInfo,
this::onImagePointChanged);
}
/**
* Adds a handler for cropping changes.
*
* @param action the handler to add
*/
public void addCroppingChangeHandler(Runnable action) {
m_croppingHandlers.add(action);
}
/**
* Adds a handler for focal point changes.
*
* @param onImagePointChanged the handler to add
*/
public void addImagePointChangeHandler(Runnable onImagePointChanged) {
m_imagePointHandlers.add(onImagePointChanged);
}
/**
* Returns the image cropping parameter bean.
*
* @return the image cropping parameter bean
*/
public CmsCroppingParamBean getCroppingParam() {
return m_croppingParam;
}
/**
* Gets the focal point controller.
*
* @return the focal point controller
*/
public CmsFocalPointController getFocalPointController() {
return m_pointController;
}
/**
* Gets the format handler.
*
* @return the format handler
*/
public CmsImageFormatHandler getFormatHandler() {
return m_formatHandler;
}
/**
* Returns the name of the currently selected image format.
*
* @return the format name
*/
public String getFormatName() {
String result = "";
if ((m_formatHandler != null) && (m_formatHandler.getCurrentFormat() != null)) {
result = m_formatHandler.getCurrentFormat().getName();
}
return result;
}
/**
* Returns image tag attributes to set for editor plugins.
*
* @param callback the callback to execute
*/
public void getImageAttributes(I_CmsSimpleCallback