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: * JRemoveVMDialog.java
023: *
024: * Created on January 3, 2003, 2:41 PM
025: */
026:
027: package ch.ethz.prose.tools;
028:
029: import java.util.Map;
030: import java.util.Vector;
031:
032: import javax.swing.DefaultComboBoxModel;
033: import javax.swing.JComboBox;
034: import javax.swing.JOptionPane;
035:
036: /**
037: *
038: * @author pschoch
039: */
040: public class JRemoveVMDialog extends javax.swing.JDialog {
041:
042: private static final long serialVersionUID = 3257285812134491960L;
043: private Map vmMap;
044: private String nameVM = null;
045: private String urlVM = null;
046:
047: /** Creates new form JRemoveVMDialog */
048: public JRemoveVMDialog(java.awt.Frame parent, boolean modal) {
049: super (parent, modal);
050: initComponents();
051: this .setLocationRelativeTo(this .getParent());
052: }
053:
054: /** This method is called from within the constructor to
055: * initialize the form.
056: * WARNING: Do NOT modify this code. The content of this method is
057: * always regenerated by the Form Editor.
058: */
059: private void initComponents() {//GEN-BEGIN:initComponents
060: jPanel1 = new javax.swing.JPanel();
061: comboBoxPanel = new javax.swing.JPanel();
062: jLabel1 = new javax.swing.JLabel();
063: jComboBox1 = new javax.swing.JComboBox();
064: viewPanel = new javax.swing.JPanel();
065: urlLabel = new javax.swing.JLabel();
066: urlTextField = new javax.swing.JTextField();
067: buttons = new javax.swing.JPanel();
068: removeButton = new javax.swing.JButton();
069: cancelButton = new javax.swing.JButton();
070:
071: setTitle("Remove Virtual Machine");
072: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
073: setName("removeVMDialog");
074: addWindowListener(new java.awt.event.WindowAdapter() {
075: public void windowClosing(java.awt.event.WindowEvent evt) {
076: closeDialog(evt);
077: }
078: });
079:
080: jPanel1.setLayout(new java.awt.BorderLayout());
081:
082: jPanel1.setPreferredSize(new java.awt.Dimension(380, 138));
083: jPanel1.setMinimumSize(new java.awt.Dimension(380, 138));
084: comboBoxPanel.setBorder(new javax.swing.border.CompoundBorder(
085: new javax.swing.border.CompoundBorder(
086: new javax.swing.border.EmptyBorder(
087: new java.awt.Insets(1, 10, 1, 10)),
088: new javax.swing.border.EtchedBorder()),
089: new javax.swing.border.EmptyBorder(new java.awt.Insets(
090: 5, 1, 5, 1))));
091: comboBoxPanel.setPreferredSize(new java.awt.Dimension(350, 80));
092: comboBoxPanel.setMinimumSize(new java.awt.Dimension(350, 80));
093: comboBoxPanel.setMaximumSize(new java.awt.Dimension(350, 80));
094: jLabel1.setText("Name:");
095: jLabel1.setPreferredSize(new java.awt.Dimension(60, 29));
096: jLabel1.setBorder(new javax.swing.border.EmptyBorder(
097: new java.awt.Insets(1, 1, 1, 10)));
098: jLabel1.setMinimumSize(new java.awt.Dimension(100, 29));
099: jLabel1.setMaximumSize(new java.awt.Dimension(100, 29));
100: comboBoxPanel.add(jLabel1);
101:
102: java.util.List l = ((JMultipleProseClient) getOwner())
103: .getModel().getAllVM();
104: java.util.Iterator i = l.iterator();
105: vmMap = new java.util.HashMap();
106: while (i.hasNext()) {
107: WorksheetSingleClientModel crtM = (WorksheetSingleClientModel) i
108: .next();
109: vmMap.put(crtM.getName(), crtM);
110: }
111: jComboBox1.setModel(new DefaultComboBoxModel(new Vector(vmMap
112: .keySet())));
113: nameVM = (String) jComboBox1.getSelectedItem();
114: urlVM = ((WorksheetSingleClientModel) vmMap.get(nameVM))
115: .getAddress();
116: jComboBox1.setPreferredSize(new java.awt.Dimension(280, 50));
117: jComboBox1.setBorder(new javax.swing.border.EmptyBorder(
118: new java.awt.Insets(10, 10, 10, 10)));
119: jComboBox1.setMinimumSize(new java.awt.Dimension(280, 50));
120: jComboBox1.setMaximumSize(new java.awt.Dimension(280, 50));
121: jComboBox1
122: .addActionListener(new java.awt.event.ActionListener() {
123: public void actionPerformed(
124: java.awt.event.ActionEvent evt) {
125: jComboBoxActionPerformed(evt);
126: }
127: });
128:
129: comboBoxPanel.add(jComboBox1);
130:
131: jPanel1.add(comboBoxPanel, java.awt.BorderLayout.NORTH);
132:
133: viewPanel.setBorder(new javax.swing.border.CompoundBorder(
134: new javax.swing.border.CompoundBorder(
135: new javax.swing.border.EmptyBorder(
136: new java.awt.Insets(1, 10, 1, 10)),
137: new javax.swing.border.EtchedBorder()),
138: new javax.swing.border.EmptyBorder(new java.awt.Insets(
139: 5, 1, 5, 1))));
140: viewPanel.setPreferredSize(new java.awt.Dimension(370, 58));
141: viewPanel.setMinimumSize(new java.awt.Dimension(350, 58));
142: viewPanel.setMaximumSize(new java.awt.Dimension(400, 58));
143: urlLabel.setText("URL:");
144: urlLabel
145: .setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
146: urlLabel.setPreferredSize(new java.awt.Dimension(50, 29));
147: urlLabel.setBorder(new javax.swing.border.EmptyBorder(
148: new java.awt.Insets(1, 1, 1, 10)));
149: urlLabel.setMinimumSize(new java.awt.Dimension(100, 29));
150: urlLabel.setMaximumSize(new java.awt.Dimension(100, 29));
151: viewPanel.add(urlLabel);
152:
153: urlTextField.setToolTipText(urlVM);
154: urlTextField.setEditable(false);
155: urlTextField.setFont(new java.awt.Font("Dialog", 1, 12));
156: urlTextField.setText(urlVM);
157: urlTextField.setPreferredSize(new java.awt.Dimension(280, 29));
158: urlTextField.setMaximumSize(new java.awt.Dimension(280, 29));
159: urlTextField.setMinimumSize(new java.awt.Dimension(280, 29));
160: viewPanel.add(urlTextField);
161:
162: jPanel1.add(viewPanel, java.awt.BorderLayout.SOUTH);
163:
164: getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
165:
166: buttons.setLayout(new java.awt.FlowLayout(
167: java.awt.FlowLayout.CENTER, 20, 15));
168:
169: buttons.setPreferredSize(new java.awt.Dimension(300, 59));
170: buttons.setMinimumSize(new java.awt.Dimension(300, 59));
171: removeButton.setMnemonic('R');
172: removeButton.setText("Remove");
173: removeButton.setPreferredSize(new java.awt.Dimension(91, 29));
174: removeButton.setMaximumSize(new java.awt.Dimension(91, 29));
175: removeButton.setMinimumSize(new java.awt.Dimension(91, 29));
176: removeButton
177: .addActionListener(new java.awt.event.ActionListener() {
178: public void actionPerformed(
179: java.awt.event.ActionEvent evt) {
180: removeButtonActionPerformed(evt);
181: }
182: });
183:
184: buttons.add(removeButton);
185:
186: cancelButton.setMnemonic('C');
187: cancelButton.setText("Cancel");
188: cancelButton.setPreferredSize(new java.awt.Dimension(91, 29));
189: cancelButton.setMaximumSize(new java.awt.Dimension(91, 29));
190: cancelButton.setMinimumSize(new java.awt.Dimension(91, 29));
191: cancelButton
192: .addActionListener(new java.awt.event.ActionListener() {
193: public void actionPerformed(
194: java.awt.event.ActionEvent evt) {
195: cancelButtonActionPerformed(evt);
196: }
197: });
198:
199: buttons.add(cancelButton);
200:
201: getContentPane().add(buttons, java.awt.BorderLayout.SOUTH);
202:
203: pack();
204: }//GEN-END:initComponents
205:
206: private void jComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxActionPerformed
207: nameVM = (String) ((JComboBox) evt.getSource())
208: .getSelectedItem();
209: urlVM = ((WorksheetSingleClientModel) vmMap.get(nameVM))
210: .getAddress();
211: urlTextField.setText(urlVM);
212: urlTextField.setToolTipText(urlVM);
213: }//GEN-LAST:event_jComboBoxActionPerformed
214:
215: private void removeButtonActionPerformed(
216: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
217: int n = JOptionPane.showConfirmDialog(this ,
218: "Are you sure you want to remove VM " + nameVM + "?",
219: "Remove VM Confirmation", JOptionPane.YES_NO_OPTION);
220: if (n == JOptionPane.NO_OPTION)
221: return;
222: else if (n == JOptionPane.YES_OPTION) {
223: ((JMultipleProseClient) getOwner()).removeTab(nameVM);
224: setVisible(false);
225: dispose();
226: }
227: }//GEN-LAST:event_removeButtonActionPerformed
228:
229: private void cancelButtonActionPerformed(
230: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
231: setVisible(false);
232: dispose();
233: }//GEN-LAST:event_cancelButtonActionPerformed
234:
235: /** Closes the dialog */
236: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
237: setVisible(false);
238: dispose();
239: }//GEN-LAST:event_closeDialog
240:
241: /**
242: * @param args the command line arguments
243: */
244: public static void main(String args[]) {
245: // new JRemoveVMDialog(new javax.swing.JFrame(), true).show(); // deprecated since JDK 1.5
246: new JRemoveVMDialog(new javax.swing.JFrame(), true)
247: .setVisible(true); // replaces show()
248: }
249:
250: // Variables declaration - do not modify//GEN-BEGIN:variables
251: private javax.swing.JTextField urlTextField;
252: private javax.swing.JPanel comboBoxPanel;
253: private javax.swing.JComboBox jComboBox1;
254: private javax.swing.JPanel buttons;
255: private javax.swing.JButton cancelButton;
256: private javax.swing.JLabel urlLabel;
257: private javax.swing.JLabel jLabel1;
258: private javax.swing.JPanel jPanel1;
259: private javax.swing.JPanel viewPanel;
260: private javax.swing.JButton removeButton;
261: // End of variables declaration//GEN-END:variables
262:
263: }
|