001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developer of the Original Code is Andrei Popovici. Portions
017: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: /*
022: * AddVMDialog.java
023: *
024: * Created on December 30, 2002, 4:18 PM
025: */
026:
027: package ch.ethz.prose.tools;
028:
029: import javax.swing.event.DocumentEvent;
030: import javax.swing.event.DocumentListener;
031: import javax.swing.text.BadLocationException;
032: import javax.swing.text.Document;
033:
034: /**
035: *
036: * @author pschoch
037: */
038: public class AddVMDialog extends javax.swing.JDialog {
039:
040: private static final long serialVersionUID = 3256728398360556336L;
041: private String nameVM = null;
042: private String ip = "";
043: private String port = "5000";
044:
045: /** Creates new form AddVMDialog */
046: public AddVMDialog(java.awt.Frame parent, boolean modal) {
047: super (parent, modal);
048: initComponents();
049: customizeComponents();
050: }
051:
052: protected class MyDocumentListener implements DocumentListener {
053: private String which;
054:
055: public MyDocumentListener(String which) {
056: this .which = which;
057: }
058:
059: public void insertUpdate(DocumentEvent e) {
060: displayEditInfo(e);
061: }
062:
063: public void removeUpdate(DocumentEvent e) {
064: displayEditInfo(e);
065: }
066:
067: public void changedUpdate(DocumentEvent e) {
068: // Plain Text components don't fire this events.
069: }
070:
071: private void displayEditInfo(DocumentEvent e) {
072: String text = null;
073: Document doc = (Document) e.getDocument();
074: try {
075: text = doc.getText(0, doc.getLength());
076: } catch (BadLocationException es) {
077: throw new Error("bad location in AddVMDialog");
078: }
079: if (which.equals("name"))
080: nameVM = text;
081: else if (which.equals("ip"))
082: ip = text;
083: else if (which.equals("port"))
084: port = text;
085: else
086: throw new RuntimeException("wrong label: " + which);
087: }
088: }
089:
090: /** This method is called from within the constructor to
091: * initialize the form.
092: * WARNING: Do NOT modify this code. The content of this method is
093: * always regenerated by the Form Editor.
094: */
095: private void initComponents() {//GEN-BEGIN:initComponents
096: input = new javax.swing.JPanel();
097: namePane = new javax.swing.JPanel();
098: nameLabel = new javax.swing.JLabel();
099: nameTextField = new javax.swing.JTextField();
100: ipPane = new javax.swing.JPanel();
101: ipLabel = new javax.swing.JLabel();
102: ipTextField = new javax.swing.JTextField();
103: portPane = new javax.swing.JPanel();
104: portLabel = new javax.swing.JLabel();
105: portTextField = new javax.swing.JTextField();
106: buttons = new javax.swing.JPanel();
107: addButton = new javax.swing.JButton();
108: cancelButton = new javax.swing.JButton();
109:
110: setTitle("Add new Virtual Machine");
111: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
112: setName("addVMDialog");
113: addWindowListener(new java.awt.event.WindowAdapter() {
114: public void windowClosing(java.awt.event.WindowEvent evt) {
115: closeDialog(evt);
116: }
117: });
118:
119: input.setLayout(new javax.swing.BoxLayout(input,
120: javax.swing.BoxLayout.Y_AXIS));
121:
122: input.setPreferredSize(new java.awt.Dimension(300, 200));
123: input.setMinimumSize(new java.awt.Dimension(300, 200));
124: namePane.setLayout(new javax.swing.BoxLayout(namePane,
125: javax.swing.BoxLayout.X_AXIS));
126:
127: namePane.setBorder(new javax.swing.border.EmptyBorder(
128: new java.awt.Insets(5, 10, 5, 10)));
129: namePane.setAlignmentX(0.0F);
130: namePane.setMaximumSize(new java.awt.Dimension(300, 58));
131: nameLabel.setText("Name:");
132: nameLabel
133: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
134: nameLabel.setPreferredSize(new java.awt.Dimension(80, 29));
135: nameLabel.setBorder(new javax.swing.border.EmptyBorder(
136: new java.awt.Insets(1, 1, 1, 10)));
137: nameLabel.setMinimumSize(new java.awt.Dimension(100, 29));
138: nameLabel.setMaximumSize(new java.awt.Dimension(100, 29));
139: namePane.add(nameLabel);
140:
141: nameTextField.setToolTipText("name of the VM");
142: nameTextField.setAlignmentX(1.0F);
143: nameTextField.setPreferredSize(new java.awt.Dimension(200, 29));
144: nameTextField.setMaximumSize(new java.awt.Dimension(200, 29));
145: nameTextField.setMinimumSize(new java.awt.Dimension(200, 29));
146: namePane.add(nameTextField);
147:
148: input.add(namePane);
149:
150: ipPane.setLayout(new javax.swing.BoxLayout(ipPane,
151: javax.swing.BoxLayout.X_AXIS));
152:
153: ipPane.setBorder(new javax.swing.border.EmptyBorder(
154: new java.awt.Insets(5, 10, 5, 10)));
155: ipPane.setAlignmentX(0.0F);
156: ipPane.setMaximumSize(new java.awt.Dimension(300, 58));
157: ipLabel.setText("IP:");
158: ipLabel
159: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
160: ipLabel.setPreferredSize(new java.awt.Dimension(80, 29));
161: ipLabel.setBorder(new javax.swing.border.EmptyBorder(
162: new java.awt.Insets(1, 1, 1, 10)));
163: ipLabel.setMinimumSize(new java.awt.Dimension(100, 29));
164: ipLabel.setMaximumSize(new java.awt.Dimension(100, 29));
165: ipPane.add(ipLabel);
166:
167: ipTextField
168: .setToolTipText("IP-Address OR www-Address OR Hostname");
169: ipTextField.setAlignmentX(1.0F);
170: ipTextField.setPreferredSize(new java.awt.Dimension(200, 29));
171: ipTextField.setMaximumSize(new java.awt.Dimension(200, 29));
172: ipTextField.setMinimumSize(new java.awt.Dimension(200, 29));
173: ipPane.add(ipTextField);
174:
175: input.add(ipPane);
176:
177: portPane.setLayout(new javax.swing.BoxLayout(portPane,
178: javax.swing.BoxLayout.X_AXIS));
179:
180: portPane.setBorder(new javax.swing.border.EmptyBorder(
181: new java.awt.Insets(5, 10, 5, 10)));
182: portPane.setPreferredSize(new java.awt.Dimension(222, 29));
183: portPane.setMinimumSize(new java.awt.Dimension(222, 29));
184: portPane.setAlignmentX(0.0F);
185: portPane.setMaximumSize(new java.awt.Dimension(300, 58));
186: portLabel.setText("Port:");
187: portLabel
188: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
189: portLabel.setPreferredSize(new java.awt.Dimension(60, 29));
190: portLabel.setBorder(new javax.swing.border.EmptyBorder(
191: new java.awt.Insets(1, 1, 1, 10)));
192: portLabel.setMinimumSize(new java.awt.Dimension(100, 29));
193: portLabel.setMaximumSize(new java.awt.Dimension(100, 29));
194: portPane.add(portLabel);
195:
196: portTextField.setToolTipText("Portnumber");
197: portTextField.setText("5000");
198: portTextField.setPreferredSize(new java.awt.Dimension(200, 29));
199: portTextField.setMaximumSize(new java.awt.Dimension(200, 29));
200: portTextField.setMinimumSize(new java.awt.Dimension(200, 29));
201: portPane.add(portTextField);
202:
203: input.add(portPane);
204:
205: getContentPane().add(input, java.awt.BorderLayout.CENTER);
206:
207: buttons.setLayout(new java.awt.FlowLayout(
208: java.awt.FlowLayout.CENTER, 20, 15));
209:
210: addButton.setMnemonic('A');
211: addButton.setText("Add");
212: addButton.setPreferredSize(new java.awt.Dimension(81, 29));
213: addButton.setMaximumSize(new java.awt.Dimension(81, 29));
214: addButton.setMinimumSize(new java.awt.Dimension(81, 29));
215: addButton
216: .addActionListener(new java.awt.event.ActionListener() {
217: public void actionPerformed(
218: java.awt.event.ActionEvent evt) {
219: addButtonActionPerformed(evt);
220: }
221: });
222:
223: addButton.addKeyListener(new java.awt.event.KeyAdapter() {
224: public void keyPressed(java.awt.event.KeyEvent evt) {
225: addButtonKeyPressed(evt);
226: }
227: });
228:
229: buttons.add(addButton);
230:
231: cancelButton.setMnemonic('C');
232: cancelButton.setText("Cancel");
233: cancelButton
234: .addActionListener(new java.awt.event.ActionListener() {
235: public void actionPerformed(
236: java.awt.event.ActionEvent evt) {
237: cancelButtonActionPerformed(evt);
238: }
239: });
240:
241: buttons.add(cancelButton);
242: getContentPane().add(buttons, java.awt.BorderLayout.SOUTH);
243: pack();
244: }//GEN-END:initComponents
245:
246: private void addButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_addButtonKeyPressed
247: if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER)
248: addButtonAction();
249: }//GEN-LAST:event_addButtonKeyPressed
250:
251: private void cancelButtonActionPerformed(
252: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
253: setVisible(false);
254: dispose();
255: }//GEN-LAST:event_cancelButtonActionPerformed
256:
257: private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
258: addButtonAction();
259: }//GEN-LAST:event_addButtonActionPerformed
260:
261: /** Closes the dialog */
262: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
263: setVisible(false);
264: dispose();
265: }//GEN-LAST:event_closeDialog
266:
267: private void addButtonAction() {
268: try {
269: ((JMultipleProseClient) getOwner()).addTab(nameVM, ip,
270: port, true);
271: setVisible(false);
272: dispose();
273: } catch (Exception e) {
274: JMultipleProseClient.showException(this , e);
275: if (e instanceof java.rmi.RemoteException) {
276: setVisible(false);
277: dispose();
278: }
279: }
280: }
281:
282: private void customizeComponents() {
283: nameTextField.getDocument().addDocumentListener(
284: new MyDocumentListener("name"));
285: portTextField.getDocument().addDocumentListener(
286: new MyDocumentListener("port"));
287: ipTextField.getDocument().addDocumentListener(
288: new MyDocumentListener("ip"));
289: this .setLocationRelativeTo(this .getParent());
290: }
291:
292: // Variables declaration - do not modify//GEN-BEGIN:variables
293: private javax.swing.JLabel nameLabel;
294: private javax.swing.JPanel portPane;
295: private javax.swing.JLabel ipLabel;
296: private javax.swing.JPanel input;
297: private javax.swing.JTextField ipTextField;
298: private javax.swing.JButton addButton;
299: private javax.swing.JPanel buttons;
300: private javax.swing.JButton cancelButton;
301: private javax.swing.JTextField portTextField;
302: private javax.swing.JPanel ipPane;
303: private javax.swing.JLabel protocolLabel;
304: private javax.swing.JLabel portLabel;
305: private javax.swing.JPanel namePane;
306: private javax.swing.JTextField nameTextField;
307: private javax.swing.JPanel protocolPane;
308: private javax.swing.JTextField protocolTextField;
309: // End of variables declaration//GEN-END:variables
310:
311: }
|