1 31 package org.objectweb.proactive.ic2d.gui.dialog; 32 33 import java.awt.BorderLayout ; 34 import java.awt.Container ; 35 import java.awt.GridBagConstraints ; 36 import java.awt.GridBagLayout ; 37 import java.awt.Insets ; 38 import java.awt.event.ActionEvent ; 39 import java.awt.event.ActionListener ; 40 import java.awt.event.MouseAdapter ; 41 import java.awt.event.MouseEvent ; 42 import java.net.InetAddress ; 43 44 import javax.swing.JButton ; 45 import javax.swing.JDialog ; 46 import javax.swing.JLabel ; 47 import javax.swing.JPanel ; 48 import javax.swing.JTextField ; 49 50 public class NewGlobusHostDialog extends JDialog implements ActionListener { 51 52 public boolean success = true; 53 public String host; 54 public int port; 55 private JButton btOk; 56 private JButton btCancel; 57 private JTextField tfHost; 58 private JTextField tfPort; 59 60 61 public void actionPerformed(ActionEvent e) { 62 if (tfHost.getText().length() != 0) { 63 host = tfHost.getText(); 64 if (tfPort.getText() == null) 66 port = 754; 67 else 68 port = Integer.parseInt(tfPort.getText()); 69 } 70 closeDialog(true); 71 } 72 73 74 80 public NewGlobusHostDialog(java.awt.Frame parent, boolean modal) { 81 super(parent, modal); 82 initComponents(); 83 pack(); 84 } 85 86 87 92 private void initComponents() { 93 setTitle("GLOBUS host to ic2d"); 94 setName("Acquire GLOBUS Host Dialog"); 95 96 addWindowListener(new java.awt.event.WindowAdapter () { 97 98 public void windowClosing(java.awt.event.WindowEvent evt) { 99 closeDialog(false); 100 } 101 }); 102 103 Container content = getContentPane(); 104 GridBagLayout gb = new GridBagLayout (); 105 GridBagConstraints c = new GridBagConstraints (); 106 107 content.setLayout(gb); 108 109 c.gridx = 0; 111 c.gridy = 0; 112 c.insets = new Insets (5, 10, 5, 10); 113 JLabel label = new JLabel ("Url"); 114 gb.setConstraints(label, c); 115 content.add(label); 116 117 try { 120 tfHost = new JTextField (InetAddress.getLocalHost().getCanonicalHostName()); 121 } catch (Exception e) { 122 tfHost = new JTextField ("localhost"); 123 } 124 tfHost.addActionListener(this); 125 c.gridx = 1; 126 c.fill = GridBagConstraints.HORIZONTAL; 127 gb.setConstraints(tfHost, c); 128 content.add(tfHost); 129 130 tfPort = new JTextField ("754"); 131 tfPort.addActionListener(this); 132 c.gridx = 2; 133 c.fill = GridBagConstraints.HORIZONTAL; 134 gb.setConstraints(tfPort, c); 135 content.add(tfPort); 136 137 138 JPanel p = new JPanel (); 140 p.setLayout(new BorderLayout ()); 141 btOk = new JButton ("OK"); 143 btOk.addMouseListener(new MouseAdapter () { 144 145 public void mouseReleased(MouseEvent evt) { 146 if (tfHost.getText().length() != 0) { 147 host = tfHost.getText(); 148 } 149 closeDialog(true); 150 } 151 }); 152 p.add(btOk, BorderLayout.EAST); 153 154 btCancel = new JButton ("Cancel"); 156 btCancel.addMouseListener(new MouseAdapter () { 157 158 public void mouseReleased(MouseEvent e) { 159 closeDialog(false); 160 } 161 }); 162 p.add(btCancel, BorderLayout.WEST); 163 164 c.gridx = 0; 165 c.gridy = 1; 166 c.gridwidth = 2; 167 gb.setConstraints(p, c); 168 content.add(p); 169 p = null; 170 } 171 172 173 private void closeDialog(boolean val) { 174 success = val; 175 setVisible(false); 176 dispose(); 177 } 178 } 179 | Popular Tags |