View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  package zeus.generator.util;
25  
26  import java.util.*;
27  import java.awt.*;
28  import java.awt.event.*;
29  import javax.swing.*;
30  import javax.swing.border.*;
31  
32  public class ParameterDialog extends JDialog 
33    implements ActionListener {
34  
35    protected static final String  CANCEL     = "Cancel";
36    protected static final String  OK         = "Ok";
37  
38    protected JButton okButton;
39    protected JButton cancelButton;
40  
41  
42    protected ParameterChooser caller = null;
43    protected HashtableModel model;
44  
45    public ParameterDialog(Frame parent, String title) {
46      super(parent,title,true);
47  
48      JPanel pane = (JPanel)getContentPane();
49      pane.setLayout( new BorderLayout() );
50  
51      
52      JPanel p1 = new JPanel();
53      p1.setLayout(new GridLayout(1,2,10,10));
54      okButton = new JButton(OK);
55      cancelButton = new JButton(CANCEL);
56      p1.add(okButton);
57      p1.add(cancelButton);
58      
59      GridBagLayout gb = new GridBagLayout();
60      GridBagConstraints gbc = new GridBagConstraints();
61      gbc.insets = new Insets(10,0,10,0);
62      gbc.anchor = GridBagConstraints.NORTHWEST;
63      gbc.fill = GridBagConstraints.HORIZONTAL;
64      gbc.gridwidth = GridBagConstraints.REMAINDER;
65      gbc.weightx = 1;
66      
67      JPanel p0 = new JPanel();
68      JSeparator s1 = new JSeparator();
69      p0.setLayout(gb);
70      gb.setConstraints(s1,gbc);
71      p0.add(s1);
72      
73      gbc.anchor = GridBagConstraints.CENTER;
74      gbc.fill = GridBagConstraints.NONE;
75      gbc.insets = new Insets(0,0,10,0);
76      gb.setConstraints(p1,gbc);
77      p0.add(p1);
78  
79      model = new HashtableModel();
80      JPanel panel = new HashtablePanel(model);
81      panel.setBackground(Color.lightGray);
82  
83      pane.add("South",p0);
84      pane.add("Center",panel);
85      
86      // Event handling
87      okButton.addActionListener(this);
88      cancelButton.addActionListener(this);
89  
90      this.addWindowListener(
91         new WindowAdapter() {
92            public void windowClosing(WindowEvent evt) { setVisible(false); }
93         }
94      );
95      this.pack();
96    }
97    
98    public void actionPerformed(ActionEvent evt) {
99      Object source = evt.getSource();
100     if ( source == okButton ) {
101        this.setVisible(false);
102        if ( caller != null && model.hasChanged() ){
103           caller.parametersChanged(model.getData());
104           repaint();}
105     }
106     else if ( source == cancelButton ) {
107        this.setVisible(false);
108     }
109   }
110 
111   public void display(ParameterChooser caller, Hashtable input) {
112      this.caller = caller;
113      model.reset(input);
114      setVisible(true);
115      pack();
116   }
117 
118 }