001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.imaging;
018
019import org.apache.commons.imaging.common.BufferedImageFactory;
020
021/**
022 * Imaging parameters.
023 *
024 * <p>
025 * Contains parameters that are common to all formats. Implementations must include the specific parameters for each image format.
026 * </p>
027 *
028 * @param <E> This type
029 * @since 1.0-alpha3
030 */
031public class ImagingParameters<E extends ImagingParameters<E>> {
032
033    /**
034     * Whether to throw an exception when any issue occurs during reading or writing a file format. Default is {@code false}.
035     */
036    private boolean strict;
037
038    /**
039     * An optional file name, used for the description of input streams where a file name would be hard (or not possible) to be identified. Default is
040     * {@code null}.
041     */
042    private String fileName;
043
044    /**
045     * Factory to create {@code BufferedImage}s. Default is {@code null}.
046     */
047    private BufferedImageFactory bufferedImageFactory;
048
049    /**
050     * <p>
051     * Parameter key. Used in write operations to indicate the desired pixel density (DPI), and/or aspect ratio.
052     * </p>
053     */
054    private PixelDensity pixelDensity;
055
056    // getters and setters
057
058    @SuppressWarnings("unchecked")
059    public E asThis() {
060        return (E) this;
061    }
062
063    public BufferedImageFactory getBufferedImageFactory() {
064        return bufferedImageFactory;
065    }
066
067    public String getFileName() {
068        return fileName;
069    }
070
071    public PixelDensity getPixelDensity() {
072        return pixelDensity;
073    }
074
075    public boolean isStrict() {
076        return strict;
077    }
078
079    public E setBufferedImageFactory(final BufferedImageFactory bufferedImageFactory) {
080        this.bufferedImageFactory = bufferedImageFactory;
081        return asThis();
082    }
083
084    public E setFileName(final String fileName) {
085        this.fileName = fileName;
086        return asThis();
087    }
088
089    public E setPixelDensity(final PixelDensity pixelDensity) {
090        this.pixelDensity = pixelDensity;
091        return asThis();
092    }
093
094    public E setStrict(final boolean strict) {
095        this.strict = strict;
096        return asThis();
097    }
098}