1 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 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 title, boolean modal, Translator resource) { 80 super(frame, title, modal); 81 try { 82 res = resource; 83 jbInit(); 84 pack(); 85 } catch (Exception 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 { 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 () { 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 () { 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 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 |