001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.imr.util;
022:
023: import javax.swing.*;
024: import java.awt.event.*;
025: import java.awt.*;
026:
027: /**
028: * This class shows a window which lets the user control
029: * the behaviour of the refresh thread. It allows to change
030: * the refresh interval and stop/restart the thread.
031: *
032: * @author Nicolas Noffke
033: *
034: * $Log: RefreshWindow.java,v $
035: * Revision 1.7 2004/05/06 12:39:59 nicolas
036: * Updated Copyright notice to 2004
037: *
038: * Revision 1.6 2002/12/20 18:29:04 nicolas
039: * Updated Copyright year to 2003
040: *
041: * Revision 1.5 2002/07/01 07:54:16 nicolas
042: * updated or inserted Copyright notice
043: *
044: * Revision 1.4 2002/03/19 09:25:11 nicolas
045: * updated copyright to 2002
046: *
047: * Revision 1.3 2002/03/19 11:08:02 brose
048: * *** empty log message ***
049: *
050: * Revision 1.2 2002/03/17 18:44:02 brose
051: * *** empty log message ***
052: *
053: * Revision 1.3 1999/11/25 16:05:49 brose
054: * cosmetics
055: *
056: * Revision 1.2 1999/11/25 10:02:14 noffke
057: * Wrote small comment.
058: *
059: *
060: */
061:
062: public class RefreshWindow extends JFrame implements ActionListener {
063: private JTextField m_interval_tf;
064: private JButton m_ok_btn;
065: private JButton m_cancel_btn;
066: private Checkbox m_disable_box;
067: private ImRModel m_model;
068:
069: public RefreshWindow(ImRModel model) {
070: super ("Refresh Interval Settings");
071:
072: m_model = model;
073:
074: JPanel _interval_panel = new JPanel();
075: GridBagLayout _interval_gbl = new GridBagLayout();
076: GridBagConstraints _constraints = new GridBagConstraints();
077:
078: JLabel _interval_lbl = new JLabel("Enter an Interval (in ms):");
079: buildConstraints(_constraints, 0, 0, 1, 1, 1, 1);
080: _constraints.fill = GridBagConstraints.NONE;
081: _interval_gbl.setConstraints(_interval_lbl, _constraints);
082: _interval_panel.add(_interval_lbl);
083:
084: m_interval_tf = new JTextField(""
085: + m_model.m_current_refresh_interval, 10);
086: buildConstraints(_constraints, 0, 1, 2, 1, 1, 1);
087: _constraints.fill = GridBagConstraints.HORIZONTAL;
088: _interval_gbl.setConstraints(m_interval_tf, _constraints);
089: _interval_panel.add(m_interval_tf);
090:
091: m_disable_box = new Checkbox("Disable automatic refresh");
092: m_disable_box.setState(m_model.m_refresh_disabled);
093: buildConstraints(_constraints, 0, 2, 2, 1, 1, 1);
094: _constraints.fill = GridBagConstraints.HORIZONTAL;
095: _interval_gbl.setConstraints(m_disable_box, _constraints);
096: _interval_panel.add(m_disable_box);
097:
098: m_ok_btn = new JButton("OK");
099: m_ok_btn.addActionListener(this );
100: buildConstraints(_constraints, 0, 3, 1, 1, 1, 1);
101: _constraints.fill = GridBagConstraints.NONE;
102: _interval_gbl.setConstraints(m_ok_btn, _constraints);
103: _interval_panel.add(m_ok_btn);
104:
105: m_cancel_btn = new JButton("Cancel");
106: m_cancel_btn.addActionListener(this );
107: buildConstraints(_constraints, 1, 3, 1, 1, 1, 1);
108: _constraints.fill = GridBagConstraints.NONE;
109: _interval_gbl.setConstraints(m_cancel_btn, _constraints);
110: _interval_panel.add(m_cancel_btn);
111:
112: _interval_panel.setLayout(_interval_gbl);
113:
114: getContentPane().add(_interval_panel);
115: pack();
116: setVisible(true);
117: }
118:
119: private void buildConstraints(GridBagConstraints gbc, int gx,
120: int gy, int gw, int gh, int wx, int wy) {
121: gbc.gridx = gx;
122: gbc.gridy = gy;
123: gbc.gridwidth = gw;
124: gbc.gridheight = gh;
125: gbc.weightx = wx;
126: gbc.weighty = wy;
127: }
128:
129: // implementation of java.awt.event.ActionListener interface
130: /**
131: *
132: * @param event a button has been clicked.
133: */
134: public void actionPerformed(ActionEvent event) {
135: JButton _source = (JButton) event.getSource();
136:
137: if (_source == m_cancel_btn)
138: dispose();
139: else if (_source == m_ok_btn) {
140: dispose();
141: if (m_disable_box.getState())
142: //disabled is selected
143: m_model.disableRefresh();
144: else
145: m_model.setRefreshInterval(Integer
146: .parseInt(m_interval_tf.getText()));
147: }
148: }
149: } // RefreshWindow
|