KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.*;
24 import java.awt.*;
25 import javax.swing.*;
26 import java.awt.event.*;
27 import java.awt.datatransfer.*;
28
29 /**
30  * AddServerWindow.java
31  *
32  *
33  * Created: Mon Nov 1 19:22:12 1999
34  *
35  */

36
37 public class AddServerWindow
38     extends JFrame
39     implements ActionListener, KeyListener
40 {
41     private ImRModel m_model;
42
43     private JTextField m_name_tf;
44     private JComboBox m_host_box;
45     private JTextField m_command_tf;
46     private Component host_box_tf = null; //fast access for paste
47

48     private JButton m_add_btn;
49     private JButton m_cancel_btn;
50
51     private Clipboard clip_board = null;
52
53     public AddServerWindow(ImRModel model) {
54     super("Add Server");
55
56     m_model = model;
57
58     clip_board = Toolkit.getDefaultToolkit().getSystemClipboard();
59
60         addKeyListener( this );
61         
62     JPanel _panel = new JPanel();
63
64     GridBagLayout _gbl = new GridBagLayout();
65     GridBagConstraints _constraints = new GridBagConstraints();
66     _constraints.fill = GridBagConstraints.HORIZONTAL;
67     
68     JLabel _name_lbl = new JLabel("Servername: ");
69     buildConstraints(_constraints, 0, 0, 1, 1, 1, 1);
70     _gbl.setConstraints(_name_lbl, _constraints);
71     _panel.add(_name_lbl);
72     
73     m_name_tf = new JTextField();
74     m_name_tf.requestFocus();
75     buildConstraints(_constraints, 1, 0, 1, 1, 100, 1);
76     _gbl.setConstraints(m_name_tf, _constraints);
77     _panel.add(m_name_tf);
78
79
80     JLabel _host_lbl = new JLabel("Host: ");
81     buildConstraints(_constraints, 0, 1, 1, 1, 1, 1);
82     _gbl.setConstraints(_host_lbl, _constraints);
83     _panel.add(_host_lbl);
84
85     m_host_box = m_model.getHostSelector();
86     buildConstraints(_constraints, 1, 1, 1, 1, 100, 1);
87     _gbl.setConstraints(m_host_box, _constraints);
88     _panel.add(m_host_box);
89         host_box_tf = m_host_box.getEditor().getEditorComponent();
90
91     JLabel _cmd_lbl = new JLabel("Command: ");
92     buildConstraints(_constraints, 0, 2, 1, 1, 1, 1);
93     _gbl.setConstraints(_cmd_lbl, _constraints);
94     _panel.add(_cmd_lbl);
95
96     m_command_tf = new JTextField(30);
97     buildConstraints(_constraints, 1, 2, 1, 1, 100, 1);
98     _gbl.setConstraints(m_command_tf, _constraints);
99     _panel.add(m_command_tf);
100
101     m_add_btn = new JButton ("Add");
102     m_add_btn.addActionListener(this);
103     buildConstraints(_constraints, 0, 3, 1, 1, 1, 1);
104     _constraints.fill = GridBagConstraints.NONE;
105     _gbl.setConstraints(m_add_btn, _constraints);
106     _panel.add(m_add_btn);
107
108     m_cancel_btn = new JButton ("Cancel");
109     m_cancel_btn.addActionListener(this);
110     buildConstraints(_constraints, 1, 3, 1, 1, 1, 1);
111     _gbl.setConstraints(m_cancel_btn, _constraints);
112     _panel.add(m_cancel_btn);
113
114     _panel.setLayout(_gbl);
115     getContentPane().add(_panel);
116
117     pack();
118     setVisible(true);
119     }
120
121     private void buildConstraints(GridBagConstraints gbc, int gx, int gy,
122                   int gw, int gh, int wx, int wy){
123     gbc.gridx = gx;
124     gbc.gridy = gy;
125     gbc.gridwidth = gw;
126     gbc.gridheight = gh;
127     gbc.weightx = wx;
128     gbc.weighty = wy;
129     }
130
131     // implementation of java.awt.event.ActionListener interface
132
/**
133      *
134      * @param param1 <description>
135      */

136     public void actionPerformed(ActionEvent event) {
137     JButton _source = (JButton) event.getSource();
138     
139     if (_source == m_cancel_btn)
140         dispose();
141     else if (_source == m_add_btn){
142         dispose();
143         m_model.addServer(m_name_tf.getText(), m_command_tf.getText(),
144                   (String JavaDoc) m_host_box.getSelectedItem());
145     }
146     }
147     
148     // implementation of java.awt.event.ActionListener interface
149
public void keyTyped( KeyEvent kevt )
150     {
151         //ignore
152
}
153     
154     public void keyPressed( KeyEvent kevt )
155     {
156         try
157         {
158             if( kevt.getKeyCode() == KeyEvent.VK_PASTE )
159             {
160                 Transferable cb_data = clip_board.getContents( this );
161                     
162                 String JavaDoc text = (String JavaDoc)
163                     cb_data.getTransferData(DataFlavor.stringFlavor);
164
165                 if( m_name_tf.hasFocus() )
166                 {
167                     m_name_tf.setText( text );
168                 }
169                 else if( m_command_tf.hasFocus() )
170                 {
171                     m_command_tf.setText( text );
172                 }
173                 else if(host_box_tf.hasFocus() )
174                 {
175                     MutableComboBoxModel model = (MutableComboBoxModel)
176                         m_host_box.getModel();
177                     
178                     model.addElement( text );
179                     model.setSelectedItem( text );
180                 }
181             }
182         }
183         catch( Exception JavaDoc e)
184         {
185             e.printStackTrace();
186         }
187     }
188
189     public void keyReleased( KeyEvent kevt )
190     {
191         //ignore
192
}
193     
194
195 // public static void main(String[] args) {
196
// new AddServerWindow(new ImRModel());
197
// }
198
} // AddServerWindow
199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
Popular Tags