01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1997-2004 Gerald Brose.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * 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.naming.namemanager;
22:
23: import javax.swing.*;
24: import java.awt.*;
25: import java.awt.event.*;
26:
27: public class NSPrefsDlg extends JDialog implements ActionListener,
28: KeyListener {
29: JTextField editSeconds;
30: boolean isOk;
31: public int updateInterval;
32:
33: public NSPrefsDlg(Frame frame, int updInt) {
34: super (frame, "Preferences", true);
35: isOk = false;
36: JPanel mainPanel = new JPanel(new GridLayout(2, 1));
37: getContentPane().add(mainPanel);
38: JPanel hiPanel = new JPanel(new FlowLayout());
39: JPanel loPanel = new JPanel();
40: mainPanel.add(hiPanel);
41: mainPanel.add(loPanel);
42:
43: JLabel label1 = new JLabel("Update view after ");
44:
45: Integer upd = new Integer(updInt);
46: editSeconds = new JTextField(upd.toString(), 3);
47: JLabel label2 = new JLabel("seconds ");
48: hiPanel.add(label1);
49: hiPanel.add(editSeconds);
50: hiPanel.add(label2);
51:
52: JButton ok = new JButton("Ok");
53: JButton cancel = new JButton("Cancel");
54: loPanel.add(ok);
55: loPanel.add(cancel);
56: ok.addActionListener(this );
57: cancel.addActionListener(this );
58: editSeconds.addKeyListener(this );
59: }
60:
61: public void actionPerformed(ActionEvent e) {
62: if (e.getActionCommand().equals("Ok")) {
63: try {
64: updateInterval = Integer
65: .parseInt(editSeconds.getText());
66: isOk = true;
67: dispose();
68: } catch (Exception ex) {
69: JOptionPane.showMessageDialog(this ,
70: "Wrong number format", "Input error",
71: JOptionPane.ERROR_MESSAGE);
72: editSeconds.grabFocus();
73: editSeconds.selectAll();
74: }
75: } else
76: dispose();
77: }
78:
79: public void keyPressed(KeyEvent e) {
80: if (e.getKeyCode() == KeyEvent.VK_ENTER)
81: actionPerformed(new ActionEvent(this , 0, "Ok"));
82: else if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
83: actionPerformed(new ActionEvent(this , 0, "Cancel"));
84: }
85:
86: public void keyReleased(KeyEvent e) {
87: }
88:
89: public void keyTyped(KeyEvent e) {
90: }
91: }
|