001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ade.galleries.client.preview;
029
030/**
031 * Free image format restriction. To be used within the image format tab of the image preview.<p>
032 *
033 * @since 8.0.0
034 */
035public class CmsFreeFormatRestriction implements I_CmsFormatRestriction {
036
037    /** The format label. */
038    private String m_label;
039
040    /** The format name. */
041    private String m_name;
042
043    /**
044     * Constructor.<p>
045     *
046     * @param name the format name
047     * @param label the format label
048     */
049    public CmsFreeFormatRestriction(String name, String label) {
050
051        m_label = label;
052        m_name = name;
053    }
054
055    /**
056     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#adjustCroppingParam(org.opencms.ade.galleries.client.preview.CmsCroppingParamBean)
057     */
058    public void adjustCroppingParam(CmsCroppingParamBean croppingParam) {
059
060        if (!croppingParam.isCropped()) {
061            croppingParam.setTargetHeight(I_CmsFormatRestriction.DIMENSION_NOT_SET);
062            croppingParam.setTargetWidth(I_CmsFormatRestriction.DIMENSION_NOT_SET);
063        }
064        croppingParam.setFormatName(getName());
065    }
066
067    /**
068     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#getHeight(int, int)
069     */
070    public int getHeight(int orgHeight, int orgWidth) {
071
072        return orgHeight;
073    }
074
075    /**
076     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#getLabel()
077     */
078    public String getLabel() {
079
080        return m_label;
081    }
082
083    /**
084     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#getName()
085     */
086    public String getName() {
087
088        return m_name;
089    }
090
091    /**
092     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#getWidth(int, int)
093     */
094    public int getWidth(int orgHeight, int orgWidth) {
095
096        return orgWidth;
097    }
098
099    /**
100     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#isCroppingEnabled()
101     */
102    public boolean isCroppingEnabled() {
103
104        return true;
105    }
106
107    /**
108     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#isFixedRatio()
109     */
110    public boolean isFixedRatio() {
111
112        return false;
113    }
114
115    /**
116     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#isHeightEditable()
117     */
118    public boolean isHeightEditable() {
119
120        return false;
121    }
122
123    /**
124     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#isWidthEditable()
125     */
126    public boolean isWidthEditable() {
127
128        return false;
129    }
130
131    /**
132     * @see org.opencms.ade.galleries.client.preview.I_CmsFormatRestriction#matchesCroppingParam(org.opencms.ade.galleries.client.preview.CmsCroppingParamBean)
133     */
134    public boolean matchesCroppingParam(CmsCroppingParamBean croppingParam) {
135
136        return ((croppingParam.getCropX() != I_CmsFormatRestriction.DIMENSION_NOT_SET)
137            && (croppingParam.getTargetHeight() == croppingParam.getCropHeight()))
138            && (croppingParam.getTargetWidth() == croppingParam.getCropWidth());
139    }
140
141}