1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }