1 16 package org.apache.log4j.lf5.viewer; 17 18 import javax.swing.*; 19 import java.awt.*; 20 import java.awt.event.ActionEvent ; 21 import java.awt.event.ActionListener ; 22 import java.awt.event.KeyAdapter ; 23 import java.awt.event.KeyEvent ; 24 25 34 35 37 public class LogFactor5InputDialog extends LogFactor5Dialog { 38 public static final int SIZE = 30; 42 46 private JTextField _textField; 50 54 60 public LogFactor5InputDialog(JFrame jframe, String title, String label) { 61 this(jframe, title, label, SIZE); 62 } 63 64 71 public LogFactor5InputDialog(JFrame jframe, String title, String label, 72 int size) { 73 super(jframe, title, true); 74 75 JPanel bottom = new JPanel(); 76 bottom.setLayout(new FlowLayout()); 77 78 JPanel main = new JPanel(); 79 main.setLayout(new FlowLayout()); 80 main.add(new JLabel(label)); 81 _textField = new JTextField(size); 82 main.add(_textField); 83 84 addKeyListener(new KeyAdapter () { 85 public void keyPressed(KeyEvent e) { 86 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 87 hide(); 88 } 89 } 90 }); 91 92 JButton ok = new JButton("Ok"); 93 ok.addActionListener(new ActionListener () { 94 public void actionPerformed(ActionEvent e) { 95 hide(); 96 } 97 }); 98 99 JButton cancel = new JButton("Cancel"); 100 cancel.addActionListener(new ActionListener () { 101 public void actionPerformed(ActionEvent e) { 102 hide(); 103 _textField.setText(""); 107 } 108 }); 109 110 bottom.add(ok); 111 bottom.add(cancel); 112 getContentPane().add(main, BorderLayout.CENTER); 113 getContentPane().add(bottom, BorderLayout.SOUTH); 114 pack(); 115 centerWindow(this); 116 show(); 117 } 118 119 public String getText() { 123 String s = _textField.getText(); 124 125 if (s != null && s.trim().length() == 0) { 126 return null; 127 } 128 129 return s; 130 131 } 132 133 137 141 } | Popular Tags |