All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.vision.pdf.PdfField Maven / Gradle / Ivy

/*
 * Copyright (C) 2018 FormKiQ Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.formkiq.vision.pdf;

import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;

import com.formkiq.vision.document.DocumentField;

/**
 * Pdf Field Holder.
 *
 */
public class PdfField implements DocumentField {

    /** {@link PDField}. */
    private PDField field;

    /** {@link String}. */
    private String fieldName;

	/** {@link PDAnnotationWidget}. */
    private PDAnnotationWidget widget;

    /**
     * constructor.
     *
     * @param pdfield {@link PDField}
     * @param pdWidget {@link PDAnnotationWidget}
     */
    public PdfField(final PDField pdfield, final PDAnnotationWidget pdWidget) {
        this.field = pdfield;
        this.widget = pdWidget;
        this.fieldName = pdfield.getFullyQualifiedName();
    }

    /**
     * @return {@link PDField}
     */
    public PDField getField() {
        return this.field;
    }

    /**
     * @return {@link PDAnnotationWidget}
     */
    @Deprecated
    public PDAnnotationWidget getWidget() {
        return this.widget;
    }

//    @Override
//    public PDRectangle getRectangle() {
//        return this.widget.getRectangle();
//    }

    @Override
    public String toString() {
        return "field=" + this.field + ",rectangle="
                + this.widget.getRectangle();
    }

    /**
     * @return {@link String}
     */
    public String getFieldName() {
		return this.fieldName;
	}

    /**
     * @param name {@link String}
     */
	public void setFieldName(final String name) {
		this.fieldName = name;
	}

    @Override
    public float getLowerLeftX() {
        return this.widget.getRectangle().getLowerLeftX();
    }

    @Override
    public float getLowerLeftY() {
        return this.widget.getRectangle().getLowerLeftY();
    }

    @Override
    public float getUpperRightX() {
        return this.widget.getRectangle().getUpperRightX();
    }

    @Override
    public float getUpperRightY() {
        return this.widget.getRectangle().getUpperRightY();
    }

//    @Override
//    public boolean isSignatureField() {
//        return this.getField() instanceof PDSignatureField;
//    }
//
//    @Override
//    public DocumentBlockRectangle getBlockRectangle() {
//        return this;
//    }
//
//    @Override
//    public boolean isCheckbox() {
//        return this.getField() instanceof PDCheckBox;
//    }
//
//    @Override
//    public List getOptions() {
//
//        if (this.field instanceof PDComboBox) {
//            PDComboBox box = (PDComboBox) this.field;
//            return box.getOptions();
//        }
//
//        if (this.field instanceof PDCheckBox) {
//            PDCheckBox c = (PDCheckBox) this.field;
//            return new ArrayList<>(c.getOnValues());
//        }
//
//        return null;
//    }

//    @Override
//    public List getValues() {
//
//        if (this.field instanceof PDChoice) {
//            return ((PDChoice) this.field).getValue();
//        }
//        return Arrays.asList(this.field.getValueAsString());
//    }

//    @Override
//    public boolean isMultiSelect() {
//
//        if (this.field instanceof PDChoice) {
//            return ((PDChoice) this.field).isMultiSelect();
//        }
//
//        return false;
//    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy