1 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 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; 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 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 ) m_host_box.getSelectedItem()); 145 } 146 } 147 148 public void keyTyped( KeyEvent kevt ) 150 { 151 } 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 text = (String ) 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 e) 184 { 185 e.printStackTrace(); 186 } 187 } 188 189 public void keyReleased( KeyEvent kevt ) 190 { 191 } 193 194 195 } 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | Popular Tags |