1 21 package org.jacorb.imr.util; 22 23 import java.awt.*; 24 import javax.swing.*; 25 import java.awt.event.ActionListener ; 26 import java.awt.event.ActionEvent ; 27 28 35 36 public class ConnectWindow extends JFrame implements ActionListener { 37 private JTextField m_imr_url_tf; 38 private JButton m_imr_connect_btn; 39 private JButton m_cancel_btn; 40 private ImRModel m_model; 41 42 public ConnectWindow(ImRModel model) { 43 super("Connect to remote repository"); 44 45 m_model = model; 46 47 JPanel _url_panel = new JPanel(); 48 GridBagLayout _url_gbl = new GridBagLayout(); 49 GridBagConstraints _constraints = new GridBagConstraints(); 50 51 JLabel _url_lbl = new JLabel("Enter a URL:"); 52 buildConstraints(_constraints, 0, 0, 1, 1, 1, 1); 53 _constraints.fill = GridBagConstraints.NONE; 54 _url_gbl.setConstraints(_url_lbl, _constraints); 55 _url_panel.add(_url_lbl); 56 57 m_imr_url_tf = new JTextField("http://", 30); 58 buildConstraints(_constraints, 0, 1, 2, 1, 1, 1); 59 _constraints.fill = GridBagConstraints.HORIZONTAL; 60 _url_gbl.setConstraints(m_imr_url_tf, _constraints); 61 _url_panel.add(m_imr_url_tf); 62 63 m_imr_connect_btn = new JButton("Connect"); 64 m_imr_connect_btn.addActionListener(this); 65 buildConstraints(_constraints, 0, 2, 1, 1, 1, 1); 66 _constraints.fill = GridBagConstraints.NONE; 67 _url_gbl.setConstraints(m_imr_connect_btn, _constraints); 68 _url_panel.add(m_imr_connect_btn); 69 70 m_cancel_btn = new JButton("Cancel"); 71 m_cancel_btn.addActionListener(this); 72 buildConstraints(_constraints, 1, 2, 1, 1, 1, 1); 73 _constraints.fill = GridBagConstraints.NONE; 74 _url_gbl.setConstraints(m_cancel_btn, _constraints); 75 _url_panel.add(m_cancel_btn); 76 77 _url_panel.setLayout(_url_gbl); 78 79 getContentPane().add(_url_panel); 80 pack(); 81 setVisible(true); 82 } 83 84 private void buildConstraints(GridBagConstraints gbc, int gx, int gy, 85 int gw, int gh, int wx, int wy){ 86 gbc.gridx = gx; 87 gbc.gridy = gy; 88 gbc.gridwidth = gw; 89 gbc.gridheight = gh; 90 gbc.weightx = wx; 91 gbc.weighty = wy; 92 } 93 94 99 public void actionPerformed(ActionEvent event) { 100 JButton _source = (JButton) event.getSource(); 101 102 if (_source == m_cancel_btn) 103 dispose(); 104 else if (_source == m_imr_connect_btn){ 105 dispose(); 106 m_model.connectTo(m_imr_url_tf.getText()); 107 } 108 } 109 } 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | Popular Tags |