import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.Vector; import java.beans.PropertyVetoException; public class LetterGeneratorBrowser extends JInternalFrame { private CustomerCollection cCollection; private LetterTemplateCollection ltCollection; private JList list; private JButton generateButton, cancelButton; private Container container, windowContainer; private JPanel westPanel, eastPanel, northPanel, southPanel, centerPanel; private String [] custNames; private JComboBox jtemplates; private Container window; private Mailer mailer; private TagsCollection tagCollection; public LetterGeneratorBrowser( CustomerCollection cc, LetterTemplateCollection ltc, TagsCollection tc, Mailer m, Container c ) { cCollection = cc; ltCollection = ltc; tagCollection = tc; window = c; mailer = m; // Draw the frame! setTitle( "Letter Generator Browser" ); custNames = new String[ cCollection.size() ]; westPanel = new JPanel(); eastPanel = new JPanel(); northPanel = new JPanel(); southPanel = new JPanel(); centerPanel = new JPanel(); JPanel centerRightPanel = new JPanel(); JPanel jcomboPanel = new JPanel(); centerRightPanel.setLayout( new BorderLayout() ); centerPanel.setLayout( new GridLayout( 1, 2 ) ); cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { try { setClosed(true); }catch(PropertyVetoException pve) {} } } ); generateButton = new JButton("Create Letter(s)"); generateButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { int [] indices = list.getSelectedIndices(); Vector v = new Vector(); for ( int i = 0; i < indices.length; i++ ) { v.addElement( cCollection.getRecord( indices[i] ) ); } LetterTemplate lt = (LetterTemplate) ltCollection.getRecord( jtemplates.getSelectedIndex() ); LetterGenerator lg = new LetterGenerator( tagCollection ); Vector vl = lg.generate( lt, v ); LetterBrowser lb = new LetterBrowser( vl, mailer, window ); window.add( lb ); lb.show(); } } ); jtemplates = new JComboBox(); jtemplates.setBounds( 10, 10, 100, 20 ); jtemplates.setSize( 100, 20 ); jtemplates.setPreferredSize( new Dimension( 200, 24 ) ); for ( int i = 0; i < cCollection.size(); i++ ) { custNames[i] = new String( ((Customer) cCollection.getRecord( i )).getName() ); } for ( int i = 0; i < ltCollection.size(); i++ ) { jtemplates.addItem(( (LetterTemplate) ltCollection.getRecord( i )).getName() ); } setBounds( 10, 10, 500, 300 ); windowContainer = getContentPane(); windowContainer.setBounds( 10, 10, 500, 300 ); windowContainer.setLayout( new BorderLayout() ); southPanel.setLayout( new FlowLayout() ); southPanel.add( generateButton ); southPanel.add( cancelButton ); list = new JList( custNames ); //list.setPreferredSize( new Dimension( 190, 210 ) ); //list.setSize( 190, 210 ); JScrollPane scrollpane = new JScrollPane( list ); scrollpane.setPreferredSize( new Dimension( 200, 220 ) ); //scrollpane.setSize( 200, 220 ); centerRightPanel.add( jtemplates, BorderLayout.NORTH ); //centerRightPanel.add( generateButton, BorderLayout.SOUTH ); centerPanel.add( scrollpane ); centerPanel.add( centerRightPanel ); northPanel.setLayout( new GridLayout( 1, 2 ) ); JPanel northLeftPanel = new JPanel(); northLeftPanel.setLayout( new BorderLayout() ); northLeftPanel.add( westPanel, BorderLayout.WEST ); northLeftPanel.add( new JLabel( " Customers" ), BorderLayout.CENTER ); JPanel northRightPanel = new JPanel(); northRightPanel.setLayout( new BorderLayout() ); northRightPanel.add( new JLabel( "Templates" ), BorderLayout.WEST ); northPanel.add( northLeftPanel ); northPanel.add( northRightPanel ); windowContainer.add( centerPanel, BorderLayout.CENTER ); windowContainer.add( eastPanel, BorderLayout.EAST ); windowContainer.add( southPanel, BorderLayout.SOUTH ); windowContainer.add( westPanel, BorderLayout.WEST ); windowContainer.add( northPanel, BorderLayout.NORTH ); windowContainer.setVisible( true ); setResizable( false ); show(); } }