KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > imr > util > RefreshWindow


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.imr.util;
22
23 import javax.swing.*;
24 import java.awt.event.*;
25 import java.awt.*;
26 /**
27  * This class shows a window which lets the user control
28  * the behaviour of the refresh thread. It allows to change
29  * the refresh interval and stop/restart the thread.
30  *
31  * @author Nicolas Noffke
32  *
33  * $Log: RefreshWindow.java,v $
34  * Revision 1.7 2004/05/06 12:39:59 nicolas
35  * Updated Copyright notice to 2004
36  *
37  * Revision 1.6 2002/12/20 18:29:04 nicolas
38  * Updated Copyright year to 2003
39  *
40  * Revision 1.5 2002/07/01 07:54:16 nicolas
41  * updated or inserted Copyright notice
42  *
43  * Revision 1.4 2002/03/19 09:25:11 nicolas
44  * updated copyright to 2002
45  *
46  * Revision 1.3 2002/03/19 11:08:02 brose
47  * *** empty log message ***
48  *
49  * Revision 1.2 2002/03/17 18:44:02 brose
50  * *** empty log message ***
51  *
52  * Revision 1.3 1999/11/25 16:05:49 brose
53  * cosmetics
54  *
55  * Revision 1.2 1999/11/25 10:02:14 noffke
56  * Wrote small comment.
57  *
58  *
59  */

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     // implementation of java.awt.event.ActionListener interface
128
/**
129      *
130      * @param event a button has been clicked.
131      */

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         //disabled is selected
141
m_model.disableRefresh();
142         else
143         m_model.setRefreshInterval(Integer.parseInt(m_interval_tf.getText()));
144     }
145     }
146 } // RefreshWindow
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
Popular Tags