⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formcheckbox.java

📁 Java生成PDF Java生成PDF Java生成PDF
💻 JAVA
字号:
// $Id: FormCheckbox.java,v 1.4 2003/10/16 15:46:42 mike Exp $package org.faceless.pdf;import java.io.*;import java.util.*;import java.awt.Color;/** * A type of form element representing a Check Box, which can be * either "checked" or "cleared" (on or off), in the same way as * the HTML "checkbox" input type. Unlike Radio Buttons, multiple * checkboxes may be set. * </p><p> * Here's an example showing how to add a set of checkboxes to * the form * </p> * <pre> *   FormCheckbox check1 = new FormCheckbox(page, 100,100,110,110); *   form.addElement("PowerSteering", check1); *   FormCheckbox check2 = new FormCheckbox(page, 100,120,110,130); *   form.addElement("ElectricWindows", check2); *   FormCheckbox check3 = new FormCheckbox(page, 100,140,110,150); *   form.addElement("AirConditioning", check3); * </pre> * <p>and here's how to determine which of those values is checked</p> * <pre> *   Form form = pdf.getForm(); *   FormCheckbox check = (FormCheckbox)form.getElement("PowerSteering"); *   boolean powersteering = check.getValue(); *   check = (FormCheckbox)form.getElement("ElectricWindows"); *   boolean electricwindows = check.getValue(); *   <i>etc.</i> * </pre> * Unlike HTML, each checkbox is a separate entity, and any "grouping" * of checkboxes is up to the programmer to implement. * * @since 1.1.23 */public final class FormCheckbox extends FormElement{    FormCheckbox(org.faceless.pdf2.FormCheckbox b)    {        super(b);    }    /**     * Create a new FormCheckbox element. With this constructor the page annotation     * must be positioned explicitly by calling the {@link PDFAnnotation#setPage}     * and {@link PDFAnnotation#setRectangle} methods.     * @since 1.1.26     */    public FormCheckbox()    {	this(null,0,0,0,0);    }    /**     * Create a new FormCheckbox     * @param page the page to place the box on     * @param x1 the left-most X co-ordinate of the box     * @param y1 the top-most Y co-ordinate of the box     * @param x2 the right-most X co-ordinate of the box     * @param x2 the bottom-most Y co-ordinate of the box     */    public FormCheckbox(PDFPage page, float x1, float y1, float x2, float y2)    {	super(new org.faceless.pdf2.FormCheckbox(page==null ? null : page.page, x1, y1, x2, y2));    }    /**     * <p>     * Set the style of the checkbox. The box can have one of six different     * appearances, and can be drawn in three colors.     * </p><p>     * The first parameter, <code>style</code>, must be one of     * {@link #STYLE_CHECK STYLE_CHECK} (the default), {@link #STYLE_SQUARE STYLE_SQUARE},     * {@link #STYLE_DIAMOND STYLE_DIAMOND}, {@link #STYLE_STAR STYLE_STAR}, {@link #STYLE_CIRCLE STYLE_CIRCLE} or     * {@link #STYLE_CROSS STYLE_CROSS}. The remaining parameters control the color     * of the box:     * </p>     * <ul>     * <li>The <code>centercolor</code> is the color of the marker in the     * middle of the box that indicates it's selected.</li>     * <li>The <code>background</code> parameters FillColor is the color     * of the background of the box. It may be null</li>     * <li>The <code>background</code> parameters LineColor is the color     * of the border of the box. It may be null</li>     * </ul>     * <p>     * Other background style parameters may be set to control the     * {@link PDFStyle#setLineWeighting border thickness} and     * {@link PDFStyle#setFormStyle style} etc.     * </p>     *     * @param style the style to draw the marker in the center of the box     * @param centercolor the color to draw the marker in the center of the box     * @param background the style in which to draw the background of the box     * @see PDFStyle#setFormStyle     */    public void setStyle(int style, Color centercolor, PDFStyle background)    {	char newstyle = org.faceless.pdf2.PDFStyle.FORMRADIOBUTTONSTYLE_CHECK;	org.faceless.pdf2.PDFStyle backstyle = (background==null ? null : background.style);	org.faceless.pdf2.PDFStyle textstyle = new org.faceless.pdf2.PDFStyle();	textstyle.setFillColor(centercolor==null ? backstyle==null ? Color.black : backstyle.getLineColor() : centercolor);	textstyle.setFormCheckboxStyle(newstyle);	textstyle.setFont(new org.faceless.pdf2.StandardFont(org.faceless.pdf2.StandardFont.ZAPFDINGBATS), 0);	for (int i=0;i<element.getAnnotations().size();i++) {	    org.faceless.pdf2.WidgetAnnotation annot = element.getAnnotation(i);	    annot.setTextStyle(textstyle);	    annot.setBackgroundStyle(backstyle);	}    }    /**     * Set the value of the checkbox, which can be <code>true</code> for     * checked or <code>false</code> for clear.     * @param value whether to set or clear the checkbox     */    public void setValue(boolean value)    {	String v = value ? element.getAnnotation(0).getValue() : null;	((org.faceless.pdf2.FormCheckbox)element).setValue(v);    }    /**     * Return the value of the checkbox. The value is <code>true</code> for     * checked or <code>false</code> for clear.     * @return whether the checkbox is checked     */    public boolean getValue()    {	String v = ((org.faceless.pdf2.FormCheckbox)element).getValue();	return v!=null;    }    /**     * Set the default value of the checkbox, which can be <code>true</code> for     * checked or <code>false</code> for clear. The default value is what the     * box is set to when the form is reset.     * @param value the default value of the checkbox     */    public void setDefaultValue(boolean value)    {	String v = value ? element.getAnnotation(0).getValue() : null;	((org.faceless.pdf2.FormCheckbox)element).setDefaultValue(v);    }    /**     * Return the default value of the checkbox. The value is <code>true</code> for     * checked or <code>false</code> for clear.     * @return whether the checkbox is checked when the form is reset     */    public boolean getDefaultValue()    {	String v = ((org.faceless.pdf2.FormCheckbox)element).getDefaultValue();	return v!=null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -