1 17 18 19 20 package org.apache.fop.render.awt.viewer; 21 22 import java.awt.Dimension ; 23 import java.awt.Frame ; 24 import java.awt.GridBagConstraints ; 25 import java.awt.GridBagLayout ; 26 import java.awt.Insets ; 27 28 import javax.swing.JButton ; 29 import javax.swing.JDialog ; 30 import javax.swing.JLabel ; 31 import javax.swing.JPanel ; 32 import javax.swing.JTextField ; 33 34 import java.awt.event.ActionEvent ; 35 import java.awt.event.ActionListener ; 36 37 44 public class GoToPageDialog extends JDialog { 45 46 private JTextField pageNumberField; 47 private int pageNumber = -1; 48 49 55 public GoToPageDialog(Frame frame, String title, Translator translator) { 56 super(frame, title, true); 57 jbInit(translator); 58 pack(); 59 } 60 61 private void jbInit(Translator translator) { 62 JPanel panel1 = new JPanel (); 63 GridBagLayout gridBagLayout1 = new GridBagLayout (); 64 JLabel pgNbLabel = new JLabel (); 65 pageNumberField = new JTextField (); 66 JButton okButton = new JButton (); 67 JButton cancelButton = new JButton (); 68 panel1.setLayout(gridBagLayout1); 69 pgNbLabel.setText(translator.getString("Label.Page.number")); 70 okButton.setText(translator.getString("Button.Ok")); 71 okButton.addActionListener(new ActionListener () { 72 public void actionPerformed(ActionEvent e) { 73 okButtonActionPerformed(e); 74 } 75 }); 76 cancelButton.setText(translator.getString("Button.Cancel")); 77 cancelButton.addActionListener(new java.awt.event.ActionListener () { 78 public void actionPerformed(ActionEvent e) { 79 cancelButtonActionPerformed(e); 80 } 81 }); 82 panel1.setMinimumSize(new Dimension (250, 78)); 83 getContentPane().add(panel1); 84 panel1.add(pgNbLabel, 85 new GridBagConstraints (0, 0, 1, 1, 0.0, 0.0, 86 GridBagConstraints.WEST, 87 GridBagConstraints.NONE, 88 new Insets (10, 10, 10, 5), 0, 0)); 89 panel1.add(pageNumberField, 90 new GridBagConstraints (1, 0, 1, 1, 1.0, 0.0, 91 GridBagConstraints.WEST, 92 GridBagConstraints.BOTH, 93 new Insets (10, 5, 10, 10), 0, 0)); 94 panel1.add(okButton, 95 new GridBagConstraints (0, 1, 1, 1, 0.0, 0.0, 96 GridBagConstraints.EAST, 97 GridBagConstraints.NONE, 98 new Insets (0, 0, 10, 5), 0, 0)); 99 panel1.add(cancelButton, 100 new GridBagConstraints (1, 1, 1, 1, 0.0, 0.0, 101 GridBagConstraints.WEST, 102 GridBagConstraints.NONE, 103 new Insets (0, 10, 10, 10), 0, 0)); 104 } 105 106 private void okButtonActionPerformed(ActionEvent e) { 107 try { 108 pageNumber = Integer.parseInt(pageNumberField.getText()); 109 dispose(); 110 } catch (NumberFormatException nfe) { 111 pageNumberField.setText("???"); 112 } 113 114 } 115 116 private void cancelButtonActionPerformed(ActionEvent e) { 117 pageNumber = -1; 118 dispose(); 119 } 120 121 125 public int getPageNumber() { 126 return pageNumber; 127 } 128 } 129 130 | Popular Tags |