KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > naming > namemanager > ObjectDialog


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-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.naming.namemanager;
22
23 import javax.swing.*;
24 import java.awt.*;
25 import java.awt.event.*;
26
27 /**
28  * A dialog to enter the name and ior for an object binding
29  *
30  * @version $Id: ObjectDialog.java,v 1.3 2004/05/06 12:39:59 nicolas Exp $
31  * @author Gerald Brose, Xtradyne Technologies
32  */

33
34 public class ObjectDialog
35     extends JDialog
36     implements ActionListener, KeyListener
37 {
38     JTextField nameField;
39     JTextField iorField;
40     JCheckBox rebindCheckBox;
41     boolean isOk;
42
43     public ObjectDialog(Frame frame)
44     {
45         super(frame, "Bind Object", true);
46
47         isOk = false;
48         JPanel mainPanel = new JPanel( new BorderLayout());
49
50         JPanel hiPanel = new JPanel();
51         hiPanel.setLayout( new BoxLayout( hiPanel, BoxLayout.Y_AXIS ));
52         JLabel nameLabel = new JLabel("Name:");
53         JLabel objectLabel = new JLabel("IOR:");
54         rebindCheckBox = new JCheckBox("Rebind if name is bound?", false);
55         nameField = new JTextField(40);
56         iorField = new JTextField(40);
57
58         hiPanel.add(nameLabel);
59         hiPanel.add(nameField);
60         hiPanel.add(objectLabel);
61         hiPanel.add(iorField);
62         hiPanel.add(rebindCheckBox);
63
64         JButton ok = new JButton("Ok");
65         JButton cancel = new JButton("Cancel");
66
67         JPanel loPanel = new JPanel();
68         loPanel.add(ok);
69         loPanel.add(cancel);
70
71         ok.addActionListener(this);
72         cancel.addActionListener(this);
73
74         mainPanel.add(hiPanel, BorderLayout.CENTER);
75         mainPanel.add(loPanel, BorderLayout.SOUTH);
76         getContentPane().add(mainPanel);
77
78         pack();
79         show();
80
81     }
82
83     public boolean isRebind()
84     {
85         return rebindCheckBox.isSelected();
86     }
87
88     public String JavaDoc getName()
89     {
90         return nameField.getText();
91     }
92
93     public String JavaDoc getIOR()
94     {
95         return iorField.getText();
96     }
97
98     public void actionPerformed(ActionEvent e)
99     {
100         if (e.getActionCommand().equals("Ok"))
101         {
102             try
103             {
104                 isOk = true;
105                 dispose();
106             }
107             catch (Exception JavaDoc ex)
108             {
109                 JOptionPane.showMessageDialog( this, ex.getMessage(),
110                                                "Input error", JOptionPane.ERROR_MESSAGE);
111             }
112         }
113         else dispose();
114     }
115
116     public void keyPressed(KeyEvent e)
117     {
118         if (e.getKeyCode()==KeyEvent.VK_ENTER)
119             actionPerformed(new ActionEvent(this, 0, "Ok"));
120         else if (e.getKeyCode()==KeyEvent.VK_ESCAPE)
121             actionPerformed(new ActionEvent(this, 0, "Cancel"));
122     }
123
124     public void keyReleased(KeyEvent e) {}
125     public void keyTyped(KeyEvent e) {}
126 }
127
128
129
130
Popular Tags