KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > viewer > GoToPageDialog


1 /*
2  * $Id: GoToPageDialog.java,v 1.2.2.2 2003/02/25 15:25:15 jeremias Exp $
3  * ============================================================================
4  * The Apache Software License, Version 1.1
5  * ============================================================================
6  *
7  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  * ============================================================================
45  *
46  * This software consists of voluntary contributions made by many individuals
47  * on behalf of the Apache Software Foundation and was originally created by
48  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
49  * Software Foundation, please see <http://www.apache.org/>.
50  */

51 package org.apache.fop.viewer;
52
53 import java.awt.*;
54 import javax.swing.*;
55 import java.awt.event.*;
56
57 import org.apache.fop.messaging.MessageHandler;
58
59 /*
60  * originally contributed by
61  * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com,
62  * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com,
63  * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com
64  */

65
66
67 public class GoToPageDialog extends JDialog {
68     private Translator res;
69
70     JPanel panel1 = new JPanel();
71     GridBagLayout gridBagLayout1 = new GridBagLayout();
72     JLabel pgNbLabel = new JLabel();
73     JTextField pgNbField = new JTextField();
74     JButton okButton = new JButton();
75     JButton cancelButton = new JButton();
76
77     int pageNumber = -1;
78
79     public GoToPageDialog(Frame frame, String JavaDoc title, boolean modal, Translator resource) {
80         super(frame, title, modal);
81         try {
82             res = resource;
83             jbInit();
84             pack();
85         } catch (Exception JavaDoc ex) {
86             MessageHandler.errorln("GoToPageDialog: Konstruktor: "
87                                    + ex.getMessage());
88         }
89     }
90
91     public GoToPageDialog() {
92         this(null, "", false, null);
93     }
94
95     void jbInit() throws Exception JavaDoc {
96         panel1.setLayout(gridBagLayout1);
97         pgNbLabel.setText(res.getString("Page number"));
98         okButton.setText(res.getString("Ok"));
99         okButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
100
101             public void actionPerformed(ActionEvent e) {
102                 okButton_actionPerformed(e);
103             }
104
105         });
106         cancelButton.setText(res.getString("Cancel"));
107         cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
108
109             public void actionPerformed(ActionEvent e) {
110                 cancelButton_actionPerformed(e);
111             }
112
113         });
114         panel1.setMinimumSize(new Dimension(250, 78));
115         getContentPane().add(panel1);
116         panel1.add(pgNbLabel,
117                    new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
118                                           GridBagConstraints.WEST,
119                                           GridBagConstraints.NONE,
120                                           new Insets(10, 10, 10, 5), 0, 0));
121         panel1.add(pgNbField,
122                    new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
123                                           GridBagConstraints.WEST,
124                                           GridBagConstraints.BOTH,
125                                           new Insets(10, 5, 10, 10), 0, 0));
126         panel1.add(okButton,
127                    new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
128                                           GridBagConstraints.EAST,
129                                           GridBagConstraints.NONE,
130                                           new Insets(0, 0, 10, 5), 0, 0));
131         panel1.add(cancelButton,
132                    new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
133                                           GridBagConstraints.WEST,
134                                           GridBagConstraints.NONE,
135                                           new Insets(0, 10, 10, 10), 0, 0));
136     }
137
138     void okButton_actionPerformed(ActionEvent e) {
139         try {
140             pageNumber = Integer.parseInt(pgNbField.getText());
141             dispose();
142         } catch (Exception JavaDoc ex) {
143             pgNbField.setText("???");
144         }
145
146     }
147
148     void cancelButton_actionPerformed(ActionEvent e) {
149         pageNumber = -1;
150         dispose();
151     }
152
153     public int getPageNumber() {
154         return pageNumber;
155     }
156
157 }
158
Popular Tags