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

📄 formradiobutton.java

📁 Java生成PDF Java生成PDF Java生成PDF
💻 JAVA
字号:
// $Id: FormRadioButton.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;import org.faceless.util.OrderedMap;/** * <p> * A type of form element representing a group of Radio buttons. Unlike * the other <code>FormElements</code>, a Radio Button usually has several * visible annotations on the page - one for each value. These are set * with the {@link #setButton setButton} method. * </p><p> * This example creates a group of four buttons and adds them to the form: * </p> * <pre> *   FormRadioButton buttons = new FormRadioButton(); *   buttons.setButton("Visa", currentpage, 30,100,40,110); *   buttons.setButton("Mastercard", currentpage, 30,120,40,130); *   buttons.setButton("Amex", currentpage, 30,140,40,150); *   buttons.setButton("Diners", currentpage, 30,160,40,170); *   pdf.getForm().add("CreditCard", buttons); * </pre> * <p> * This example shows how to set the value of an existing form: * </p> * <pre> *   Form form = pdf.getForm(); *   FormRadioButton buttons = (FormRadioButtons)form.getElement("CreditCard"); *   buttons.setValue("Mastercard"); * </pre> * @since 1.1.23 */public final class FormRadioButton extends FormElement{    FormRadioButton(org.faceless.pdf2.FormRadioButton b)    {        super(b);    }    /**     * Create a new Radio Button set. The newly created field doesn't     * have an appearance on the page until the {@link #setButton}     * method is called.     */    public FormRadioButton()    {	super(new org.faceless.pdf2.FormRadioButton());    }    /**     * Add a new value for this radio button at the specified position.     * If the value already exists, it's overwritten.     * @param value the value for this radio button     * @param page the page to place the button on     * @param x1 the left-most X co-ordinate of the button     * @param y1 the top-most Y co-ordinate of the button     * @param x2 the right-most X co-ordinate of the button     * @param x2 the bottom-most Y co-ordinate of the button     * @return the annotation created by this method (since 1.2.1 - prior to this it returned void)     */    public PDFAnnotation setButton(String value, PDFPage page, float x1, float y1, float x2, float y2)    {        return (PDFAnnotation)PeeredObject.getPeer(((org.faceless.pdf2.FormRadioButton)element).addAnnotation(value, page==null ? null : page.page, x1, y1, x2, y2));    }    /**     * <p>     * Set the background style of the buttons. The button 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_CIRCLE STYLE_CIRCLE} (the default), {@link #STYLE_SQUARE STYLE_SQUARE},     * {@link #STYLE_DIAMOND STYLE_DIAMOND}, {@link #STYLE_STAR}, {@link #STYLE_CHECK STYLE_CHECK} or     * {@link #STYLE_CROSS STYLE_CROSS}. The remaining parameters control the color     * of the button:     * </p>     * <ul>     * <li>The <code>centercolor</code> is the color of the marker in the     * middle of the button that indicates it's selected.</li>     * <li>The <code>background</code> parameters FillColor is the color     * of the background of the button. It may be null</li>     * <li>The <code>background</code> parameters LineColor is the color     * of the border of the button. It may be null</li>     * </ul>     * <p>     * Other background style parameters may also be set to further     * control the appearance of the button.     * </p>     *     * @param style the style to draw the marker in the center of the button     * @param centercolor the color to draw the marker in the center of the button     * @param background the style in which to draw the background of the button     * @see PDFStyle#setFormStyle     * @see Form#setBackgroundStyle     */    public void setStyle(int style, Color centercolor, PDFStyle background)    {	char newstyle = org.faceless.pdf2.PDFStyle.FORMRADIOBUTTONSTYLE_CIRCLE;	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.setFormRadioButtonStyle(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);	}    }    /**     * Return a Map containing all the values for this RadioButton.     * The key of each map is a {@link java.lang.String} which is the     * value of the button, and the value is a {@link PDFAnnotation}     * which has information on the page and location of that button.     * The returned map is unmodifiable - changes to the Map are not     * allowed.     * @return an unmodifiable <code>Map</code> containing all the annotations     * for this RadioButton     */    public Map getOptions()    {	Map m = new OrderedMap();	List l = element.getAnnotations();	for (int i=0;i<l.size();i++) {	    org.faceless.pdf2.WidgetAnnotation annot = element.getAnnotation(i);	    m.put(annot.getValue(), PeeredObject.getPeer(annot));	}	return Collections.unmodifiableMap(m);    }    /**     * Set the value of this set of Radio buttons. The button with the     * specified value is selected. If no button exists with the specified     * value, an <code>IllegalArgumentException</code> is thrown.     * @param value the button to select     * @throws IllegalArgumentException if no such button exists     */    public void setValue(String value)    {	((org.faceless.pdf2.FormRadioButton)element).setValue(value);    }    /**      * Get the value of this set of Radio buttons. The value is whichever     * button is selected, or <code>null</code> if no buttons are selected     * @return the value of this set of buttons, or <code>null</code> if no value is set     */    public String getValue()    {	return ((org.faceless.pdf2.FormRadioButton)element).getValue();    }    /**     * Set the defualt value of this set of Radio buttons. The button with the     * specified value is selected when the form is reset. If no button exists     * with the specified value, an <code>IllegalArgumentException</code> is thrown.     * @param value the button to select     * @throws IllegalArgumentException if no such button exists     */    public void setDefaultValue(boolean value)    {	String v = value ? element.getAnnotation(0).getValue() : null;	((org.faceless.pdf2.FormRadioButton)element).setDefaultValue(v);    }    /**      * Get the default value of this set of Radio buttons. The value is whichever     * button is selected, or <code>null</code> if no buttons are selected     * @return the value of this set of buttons, or <code>null</code> if no value is set     */    public String getDefaultValue()    {	return ((org.faceless.pdf2.FormRadioButton)element).getDefaultValue();    }}

⌨️ 快捷键说明

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