1 package org.prevayler.demos.demo2.gui; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Color ; 5 import java.awt.Component ; 6 import java.awt.Container ; 7 import java.text.DecimalFormat ; 8 import java.text.ParseException ; 9 10 import javax.swing.Box ; 11 import javax.swing.JInternalFrame ; 12 import javax.swing.JLabel ; 13 import javax.swing.JPanel ; 14 import javax.swing.JTextField ; 15 16 import org.prevayler.Prevayler; 17 18 19 abstract class AccountFrame extends JInternalFrame { 20 21 protected final Prevayler _prevayler; 22 protected final JTextField holderField = new JTextField (); 23 24 protected String holderText() { 25 return holderField.getText(); 26 } 27 28 AccountFrame(String title, Prevayler prevayler, Container container) { 29 super(title, false, true); _prevayler = prevayler; 31 32 container.add(this); 33 this.setBackground(new Color (204, 204, 204)); 34 35 getContentPane().add(Box.createVerticalStrut(4), BorderLayout.NORTH); 36 getContentPane().add(Box.createHorizontalStrut(4), BorderLayout.EAST); 37 getContentPane().add(Box.createHorizontalStrut(4), BorderLayout.WEST); 38 getContentPane().add(fieldBox(), BorderLayout.CENTER); 39 getContentPane().add(buttonPanel(), BorderLayout.SOUTH); 40 41 show(); 42 holderField.requestFocus(); 43 } 44 45 private Box fieldBox() { 46 Box fieldBox = Box.createVerticalBox(); 47 addFields(fieldBox); 48 return fieldBox; 49 } 50 51 protected void addFields(Box fieldBox) { 52 fieldBox.add(labelContainer("Holder")); 53 fieldBox.add(holderField); 54 }; 55 56 private JPanel buttonPanel() { 57 JPanel buttonPanel = new JPanel (); 58 addButtons(buttonPanel); 59 return buttonPanel; 60 } 61 62 abstract protected void addButtons(JPanel buttonPanel); 63 64 protected Container labelContainer(String text) { 65 Box box = Box.createHorizontalBox(); 66 JLabel label = new JLabel (text); 67 box.add(label); 68 box.add(Box.createHorizontalGlue()); 69 return box; 70 } 71 72 protected Component gap() { 73 return Box.createVerticalStrut(3); 74 } 75 76 protected long parse(String numericString) throws ParseException { 77 return new DecimalFormat ("#").parse(numericString).longValue(); } 79 80 } 81 | Popular Tags |