1 21 package org.jacorb.imr.util; 22 23 import javax.swing.*; 24 import java.awt.event.*; 25 import java.awt.*; 26 60 61 public class RefreshWindow extends JFrame implements ActionListener{ 62 private JTextField m_interval_tf; 63 private JButton m_ok_btn; 64 private JButton m_cancel_btn; 65 private Checkbox m_disable_box; 66 private ImRModel m_model; 67 68 public RefreshWindow(ImRModel model) { 69 super("Refresh Interval Settings"); 70 71 m_model = model; 72 73 JPanel _interval_panel = new JPanel(); 74 GridBagLayout _interval_gbl = new GridBagLayout(); 75 GridBagConstraints _constraints = new GridBagConstraints(); 76 77 JLabel _interval_lbl = new JLabel("Enter an Interval (in ms):"); 78 buildConstraints(_constraints, 0, 0, 1, 1, 1, 1); 79 _constraints.fill = GridBagConstraints.NONE; 80 _interval_gbl.setConstraints(_interval_lbl, _constraints); 81 _interval_panel.add(_interval_lbl); 82 83 m_interval_tf = new JTextField("" + m_model.m_current_refresh_interval, 10); 84 buildConstraints(_constraints, 0, 1, 2, 1, 1, 1); 85 _constraints.fill = GridBagConstraints.HORIZONTAL; 86 _interval_gbl.setConstraints(m_interval_tf, _constraints); 87 _interval_panel.add(m_interval_tf); 88 89 m_disable_box = new Checkbox("Disable automatic refresh"); 90 m_disable_box.setState(m_model.m_refresh_disabled); 91 buildConstraints(_constraints, 0, 2, 2, 1, 1, 1); 92 _constraints.fill = GridBagConstraints.HORIZONTAL; 93 _interval_gbl.setConstraints(m_disable_box, _constraints); 94 _interval_panel.add(m_disable_box); 95 96 m_ok_btn = new JButton("OK"); 97 m_ok_btn.addActionListener(this); 98 buildConstraints(_constraints, 0, 3, 1, 1, 1, 1); 99 _constraints.fill = GridBagConstraints.NONE; 100 _interval_gbl.setConstraints(m_ok_btn, _constraints); 101 _interval_panel.add(m_ok_btn); 102 103 m_cancel_btn = new JButton("Cancel"); 104 m_cancel_btn.addActionListener(this); 105 buildConstraints(_constraints, 1, 3, 1, 1, 1, 1); 106 _constraints.fill = GridBagConstraints.NONE; 107 _interval_gbl.setConstraints(m_cancel_btn, _constraints); 108 _interval_panel.add(m_cancel_btn); 109 110 _interval_panel.setLayout(_interval_gbl); 111 112 getContentPane().add(_interval_panel); 113 pack(); 114 setVisible(true); 115 } 116 117 private void buildConstraints(GridBagConstraints gbc, int gx, int gy, 118 int gw, int gh, int wx, int wy){ 119 gbc.gridx = gx; 120 gbc.gridy = gy; 121 gbc.gridwidth = gw; 122 gbc.gridheight = gh; 123 gbc.weightx = wx; 124 gbc.weighty = wy; 125 } 126 127 132 public void actionPerformed(ActionEvent event) { 133 JButton _source = (JButton) event.getSource(); 134 135 if (_source == m_cancel_btn) 136 dispose(); 137 else if (_source == m_ok_btn){ 138 dispose(); 139 if (m_disable_box.getState()) 140 m_model.disableRefresh(); 142 else 143 m_model.setRefreshInterval(Integer.parseInt(m_interval_tf.getText())); 144 } 145 } 146 } 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | Popular Tags |