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

rups.com.lowagie.rups.view.renderer.PageField Maven / Gradle / Ivy

The newest version!
/*
 * $Id: PageField.java 3117 2008-01-31 05:53:22Z xlv $
 *
 * Copyright 2007 Bruno Lowagie.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package com.lowagie.rups.view.renderer;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;

import com.lowagie.rups.view.PageNavigationListener;

/**
 * A field that can be used to fill in a number of a page that has
 * to be rendered.
 */
public class PageField extends JTextField implements ActionListener {

	/** An object that listens to page change events. */
	protected PageNavigationListener listener;

	/**
	 * Creates the page field.
	 * @param	listener	the object that listens to page navigation changes.
	 */
	public PageField(PageNavigationListener listener) {
		super("", 5);
		this.listener = listener;
		setMaximumSize(new Dimension(45, 32));
		addActionListener(this);
	}
	
	/**
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent evt) {
		int pageNumber;
        try {
            pageNumber = Integer.parseInt(getText());
        } catch (NumberFormatException nfe) {
        	pageNumber = -1;
        }
        listener.gotoPage(pageNumber);
	}
	
	/** A Serial Version UID. */
	private static final long serialVersionUID = 8212776141917597892L;

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy