📄 formbutton.java
字号:
// $Id: FormButton.java,v 1.3 2003/10/06 12:40:06 mike Exp $package org.faceless.pdf;import java.io.*;import java.util.*;import java.awt.Color;/** * <p> * A type of form element representing a push Button, of the kind used to * trigger an action like submitting or resetting a form. * </p><p> * A buttons value doesn't change when clicked, and it's not included in the * list of fields submitted by the form. Here's an example showing how to add * a pushbutton which submits the form. * </p> * <pre> * Form form = pdf.getForm(); * FormButton button = new FormButton(pdf.getLastPage(), 100,100,200,120); * button.setValue("Submit"); * button.setAction(PDFAction.formSubmit("/servlet/Submit", PDFAction.METHOD_HTTP_POST)); * form.addElement("SubmitButton", button); * </pre> * @since 1.1.23 */public final class FormButton extends FormElement{ FormButton(org.faceless.pdf2.FormButton b) { super(b); } /** * Create a new FormButton 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 FormButton() { this(null,0,0,0,0); } /** * Create a new FormButton. * @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 */ public FormButton(PDFPage page, float x1, float y1, float x2, float y2) { super(new org.faceless.pdf2.FormButton(page==null ? null : page.page, x1, y1, x2, y2)); } /** * <p> * Set the style of the button. The two parameters control both the * style of the text (or "value") of the button and the background * style of the button. The text style, if not null, must * define a font and a fill color. The background style may specify * a line and/or fill color, as well has having other fields like the * {@link PDFStyle#setLineWeighting} or * {@link PDFStyle#setFormStyle} set. * </p><p> * If an image is also set using the {@link #setImage setImage} method, the * text will be overlaid above the image, unless the text style * {@link PDFStyle#setTextAlign alignment} is set to left or right. * </p> * @param text the style to draw the text of the button in, or <code>null</code>. * @param background the style to draw the background of the button in, or * <code>null</code> * @see #setImage * @see #setValue * @see PDFStyle#setFormStyle */ public void setStyle(PDFStyle text, PDFStyle background) { List l = element.getAnnotations(); for (int i=0;i<l.size();i++) { org.faceless.pdf2.WidgetAnnotation annot = element.getAnnotation(i); annot.setTextStyle(text==null ? null : text.style); annot.setBackgroundStyle(background==null ? null : background.style); } } /** * <p> * Set the image for the button. This is optional, but if set will draw * the specified image in the button on top of whatever background style * has been set by the {@link #setStyle setStyle} method. The image will be * stretched to fill the button, unless the alignment of the text style is * set to left or right. * </p> * @param image the background image to draw on the button, or * <tt>null</tt> to remove the current background image * @see #setStyle */ public void setImage(PDFImage image) { List l = element.getAnnotations(); for (int i=0;i<l.size();i++) { org.faceless.pdf2.WidgetAnnotation annot = element.getAnnotation(i); annot.setButtonImage(image==null ? null : image.image); } } /** * <p> * Set the "value" of the button - the text which is displayed in the * button. This is optional, but if specified the <tt>text style</tt> * passed to the {@link #setStyle setStyle} method must define a font * and a fill color. * </p><p> * The label is positioned in the left, center or right of the button * (depending on the alignment of the text style), and is drawn on a * single line - it must not contain any newlines (<tt>\n</tt>). * </p> * @param label the label to print on the button, or <tt>null</tt> for no label * @throws IllegalArgumentException if the label contains newlines */ public void setValue(String label) { List l = element.getAnnotations(); for (int i=0;i<l.size();i++) { org.faceless.pdf2.WidgetAnnotation annot = element.getAnnotation(i); annot.setValue(label); } } /** * Return the value of the button - the text which is displayed in * the button. * @return the label of the button */ public String getValue() { if (element.getAnnotations().size()>0) { org.faceless.pdf2.WidgetAnnotation annot = element.getAnnotation(0); return annot.getValue(); } else { return null; } } /** * Set the action when the button is clicked. Shorthand for * <code>getAnnotations()[0].setEventAction(PDFAnnotation.EVENT_ONCLICK)</code> * @param action the action to perform when the button is clicked, * or <code>null</code> to remove the current action * @see PDFAnnotation#setEventAction * @see #getAnnotations */ public void setAction(PDFAction action) { List l = element.getAnnotations(); for (int i=0;i<l.size();i++) { org.faceless.pdf2.WidgetAnnotation annot = element.getAnnotation(i); annot.setAction(org.faceless.pdf2.Event.CLICK, action==null ? null : action.action); } } /** * Return the action performed when the button is clicked. Shorthand for * <code>getAnnotations()[0].getEventAction(PDFAnnotation.EVENT_ONCLICK)</code> * @return the action when the button is clicked, or <code>null</code> to remove the * current action * @see PDFAnnotation#getEventAction * @see #getAnnotations */ public PDFAction getAction() { if (element.getAnnotations().size()>0) { org.faceless.pdf2.WidgetAnnotation annot = element.getAnnotation(0); return (PDFAction)PeeredObject.getPeer(annot.getAction(org.faceless.pdf2.Event.CLICK)); } else { return null; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -