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 java.awt.*;
024: import javax.swing.*;
025: import java.awt.event.*;
026: import java.awt.datatransfer.*;
027:
028: /**
029: * AddServerWindow.java
030: *
031: *
032: * Created: Mon Nov 1 19:22:12 1999
033: *
034: */
035:
036: public class AddServerWindow extends JFrame implements ActionListener,
037: KeyListener {
038: private transient ImRModel m_model;
039:
040: private JTextField m_name_tf;
041: private JComboBox m_host_box;
042: private JTextField m_command_tf;
043: private Component host_box_tf = null; //fast access for paste
044:
045: private JButton m_add_btn;
046: private JButton m_cancel_btn;
047:
048: private transient Clipboard clip_board = null;
049:
050: public AddServerWindow(ImRModel model) {
051: super ("Add Server");
052:
053: m_model = model;
054:
055: clip_board = Toolkit.getDefaultToolkit().getSystemClipboard();
056:
057: addKeyListener(this );
058:
059: JPanel _panel = new JPanel();
060:
061: GridBagLayout _gbl = new GridBagLayout();
062: GridBagConstraints _constraints = new GridBagConstraints();
063: _constraints.fill = GridBagConstraints.HORIZONTAL;
064:
065: JLabel _name_lbl = new JLabel("Servername: ");
066: buildConstraints(_constraints, 0, 0, 1, 1, 1, 1);
067: _gbl.setConstraints(_name_lbl, _constraints);
068: _panel.add(_name_lbl);
069:
070: m_name_tf = new JTextField();
071: m_name_tf.requestFocus();
072: buildConstraints(_constraints, 1, 0, 1, 1, 100, 1);
073: _gbl.setConstraints(m_name_tf, _constraints);
074: _panel.add(m_name_tf);
075:
076: JLabel _host_lbl = new JLabel("Host: ");
077: buildConstraints(_constraints, 0, 1, 1, 1, 1, 1);
078: _gbl.setConstraints(_host_lbl, _constraints);
079: _panel.add(_host_lbl);
080:
081: m_host_box = m_model.getHostSelector();
082: buildConstraints(_constraints, 1, 1, 1, 1, 100, 1);
083: _gbl.setConstraints(m_host_box, _constraints);
084: _panel.add(m_host_box);
085: host_box_tf = m_host_box.getEditor().getEditorComponent();
086:
087: JLabel _cmd_lbl = new JLabel("Command: ");
088: buildConstraints(_constraints, 0, 2, 1, 1, 1, 1);
089: _gbl.setConstraints(_cmd_lbl, _constraints);
090: _panel.add(_cmd_lbl);
091:
092: m_command_tf = new JTextField(30);
093: buildConstraints(_constraints, 1, 2, 1, 1, 100, 1);
094: _gbl.setConstraints(m_command_tf, _constraints);
095: _panel.add(m_command_tf);
096:
097: m_add_btn = new JButton("Add");
098: m_add_btn.addActionListener(this );
099: buildConstraints(_constraints, 0, 3, 1, 1, 1, 1);
100: _constraints.fill = GridBagConstraints.NONE;
101: _gbl.setConstraints(m_add_btn, _constraints);
102: _panel.add(m_add_btn);
103:
104: m_cancel_btn = new JButton("Cancel");
105: m_cancel_btn.addActionListener(this );
106: buildConstraints(_constraints, 1, 3, 1, 1, 1, 1);
107: _gbl.setConstraints(m_cancel_btn, _constraints);
108: _panel.add(m_cancel_btn);
109:
110: _panel.setLayout(_gbl);
111: getContentPane().add(_panel);
112:
113: pack();
114: setVisible(true);
115: }
116:
117: private void buildConstraints(GridBagConstraints gbc, int gx,
118: int gy, int gw, int gh, int wx, int wy) {
119: gbc.gridx = gx;
120: gbc.gridy = gy;
121: gbc.gridwidth = gw;
122: gbc.gridheight = gh;
123: gbc.weightx = wx;
124: gbc.weighty = wy;
125: }
126:
127: // implementation of java.awt.event.ActionListener interface
128:
129: public void actionPerformed(ActionEvent event) {
130: JButton _source = (JButton) event.getSource();
131:
132: if (_source == m_cancel_btn)
133: dispose();
134: else if (_source == m_add_btn) {
135: dispose();
136: m_model.addServer(m_name_tf.getText(), m_command_tf
137: .getText(), (String) m_host_box.getSelectedItem());
138: }
139: }
140:
141: // implementation of java.awt.event.ActionListener interface
142: public void keyTyped(KeyEvent kevt) {
143: //ignore
144: }
145:
146: public void keyPressed(KeyEvent kevt) {
147: try {
148: if (kevt.getKeyCode() == KeyEvent.VK_PASTE) {
149: Transferable cb_data = clip_board.getContents(this );
150:
151: String text = (String) cb_data
152: .getTransferData(DataFlavor.stringFlavor);
153:
154: if (m_name_tf.hasFocus()) {
155: m_name_tf.setText(text);
156: } else if (m_command_tf.hasFocus()) {
157: m_command_tf.setText(text);
158: } else if (host_box_tf.hasFocus()) {
159: MutableComboBoxModel model = (MutableComboBoxModel) m_host_box
160: .getModel();
161:
162: model.addElement(text);
163: model.setSelectedItem(text);
164: }
165: }
166: } catch (Exception e) {
167: e.printStackTrace();
168: }
169: }
170:
171: public void keyReleased(KeyEvent kevt) {
172: //ignore
173: }
174:
175: // public static void main(String[] args) {
176: // new AddServerWindow(new ImRModel());
177: // }
178: } // AddServerWindow
|