KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: GoToPageDialog.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.render.awt.viewer;
21
22 import java.awt.Dimension JavaDoc;
23 import java.awt.Frame JavaDoc;
24 import java.awt.GridBagConstraints JavaDoc;
25 import java.awt.GridBagLayout JavaDoc;
26 import java.awt.Insets JavaDoc;
27
28 import javax.swing.JButton JavaDoc;
29 import javax.swing.JDialog JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32 import javax.swing.JTextField JavaDoc;
33
34 import java.awt.event.ActionEvent JavaDoc;
35 import java.awt.event.ActionListener JavaDoc;
36
37 /**
38  * Go to Page Dialog.
39  * Originally contributed by:
40  * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com,
41  * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com,
42  * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com
43  */

44 public class GoToPageDialog extends JDialog JavaDoc {
45     
46     private JTextField JavaDoc pageNumberField;
47     private int pageNumber = -1;
48
49     /**
50      * Creates modal dialog with a given title, attached to a given frame.
51      * @param frame Frame to attach to
52      * @param title dialog title
53      * @param translator translator for localization
54      */

55     public GoToPageDialog(Frame JavaDoc frame, String JavaDoc title, Translator translator) {
56         super(frame, title, true);
57         jbInit(translator);
58         pack();
59     }
60
61     private void jbInit(Translator translator) {
62         JPanel JavaDoc panel1 = new JPanel JavaDoc();
63         GridBagLayout JavaDoc gridBagLayout1 = new GridBagLayout JavaDoc();
64         JLabel JavaDoc pgNbLabel = new JLabel JavaDoc();
65         pageNumberField = new JTextField JavaDoc();
66         JButton JavaDoc okButton = new JButton JavaDoc();
67         JButton JavaDoc cancelButton = new JButton JavaDoc();
68         panel1.setLayout(gridBagLayout1);
69         pgNbLabel.setText(translator.getString("Label.Page.number"));
70         okButton.setText(translator.getString("Button.Ok"));
71         okButton.addActionListener(new ActionListener JavaDoc() {
72             public void actionPerformed(ActionEvent JavaDoc e) {
73                 okButtonActionPerformed(e);
74             }
75         });
76         cancelButton.setText(translator.getString("Button.Cancel"));
77         cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
78             public void actionPerformed(ActionEvent JavaDoc e) {
79                 cancelButtonActionPerformed(e);
80             }
81         });
82         panel1.setMinimumSize(new Dimension JavaDoc(250, 78));
83         getContentPane().add(panel1);
84         panel1.add(pgNbLabel,
85                    new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.0, 0.0,
86                                           GridBagConstraints.WEST,
87                                           GridBagConstraints.NONE,
88                                           new Insets JavaDoc(10, 10, 10, 5), 0, 0));
89         panel1.add(pageNumberField,
90                    new GridBagConstraints JavaDoc(1, 0, 1, 1, 1.0, 0.0,
91                                           GridBagConstraints.WEST,
92                                           GridBagConstraints.BOTH,
93                                           new Insets JavaDoc(10, 5, 10, 10), 0, 0));
94         panel1.add(okButton,
95                    new GridBagConstraints JavaDoc(0, 1, 1, 1, 0.0, 0.0,
96                                           GridBagConstraints.EAST,
97                                           GridBagConstraints.NONE,
98                                           new Insets JavaDoc(0, 0, 10, 5), 0, 0));
99         panel1.add(cancelButton,
100                    new GridBagConstraints JavaDoc(1, 1, 1, 1, 0.0, 0.0,
101                                           GridBagConstraints.WEST,
102                                           GridBagConstraints.NONE,
103                                           new Insets JavaDoc(0, 10, 10, 10), 0, 0));
104     }
105
106     private void okButtonActionPerformed(ActionEvent JavaDoc e) {
107         try {
108             pageNumber = Integer.parseInt(pageNumberField.getText());
109             dispose();
110         } catch (NumberFormatException JavaDoc nfe) {
111             pageNumberField.setText("???");
112         }
113
114     }
115
116     private void cancelButtonActionPerformed(ActionEvent JavaDoc e) {
117         pageNumber = -1;
118         dispose();
119     }
120
121     /**
122      * Returns page number, entered by user.
123      * @return the page number
124      */

125     public int getPageNumber() {
126         return pageNumber;
127     }
128 }
129
130
Popular Tags