001: /* Copyright 2004 Inderjeet Singh. All rights reserved. You may not modify,
002: * use, reproduce or distribute this software except in compliance with the
003: * terms of the license at http://tcpmon.dev.java.net/
004: * $Id: MainWindow.java,v 1.9 2004/11/14 19:28:54 inder Exp $ */
005:
006: package tcpmon;
007:
008: import java.io.*;
009:
010: /**
011: *
012: * @author Inderjeet Singh
013: */
014: public class MainWindow extends javax.swing.JFrame {
015:
016: /** Creates new form MainWindow */
017: public MainWindow() {
018: initComponents();
019: java.net.URL helpURL = MainWindow.class
020: .getResource("/readme.html");
021: if (helpURL != null) {
022: try {
023: tpInfo.setPage(helpURL);
024: } catch (IOException e) {
025: System.err.println("Attempted to read a bad URL: "
026: + helpURL);
027: }
028: } else {
029: System.err.println("Couldn't find file: readme.html");
030: }
031: }
032:
033: /** This method is called from within the constructor to
034: * initialize the form.
035: * WARNING: Do NOT modify this code. The content of this method is
036: * always regenerated by the Form Editor.
037: */
038: private void initComponents() {//GEN-BEGIN:initComponents
039: java.awt.GridBagConstraints gridBagConstraints;
040:
041: tabbedPane = new javax.swing.JTabbedPane();
042: adminPanel = new javax.swing.JPanel();
043: pConnection = new javax.swing.JPanel();
044: jLabel1 = new javax.swing.JLabel();
045: pConnectionInfo = new javax.swing.JPanel();
046: lLocalPort = new javax.swing.JLabel();
047: tfLocalPort = new javax.swing.JTextField();
048: lRemoteHost = new javax.swing.JLabel();
049: tfRemoteHost = new javax.swing.JTextField();
050: lRemotePort = new javax.swing.JLabel();
051: tfRemotePort = new javax.swing.JTextField();
052: bAddMonitor = new javax.swing.JButton();
053: pInfo = new javax.swing.JPanel();
054: spInfo = new javax.swing.JScrollPane();
055: tpInfo = new javax.swing.JTextPane();
056:
057: getContentPane().setLayout(new java.awt.BorderLayout(5, 5));
058:
059: setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
060: tabbedPane.setMinimumSize(new java.awt.Dimension(640, 480));
061: tabbedPane.setPreferredSize(new java.awt.Dimension(640, 480));
062: adminPanel.setLayout(new java.awt.BorderLayout());
063:
064: adminPanel.setMinimumSize(new java.awt.Dimension(400, 400));
065: adminPanel.setPreferredSize(new java.awt.Dimension(400, 400));
066: pConnection.setLayout(new java.awt.GridBagLayout());
067:
068: jLabel1.setText("Create a New TCP Monitor Connection: ");
069: gridBagConstraints = new java.awt.GridBagConstraints();
070: gridBagConstraints.gridx = 0;
071: gridBagConstraints.gridy = 0;
072: gridBagConstraints.gridwidth = 2;
073: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
074: gridBagConstraints.insets = new java.awt.Insets(20, 20, 0, 0);
075: pConnection.add(jLabel1, gridBagConstraints);
076:
077: pConnectionInfo.setLayout(new java.awt.GridBagLayout());
078:
079: pConnectionInfo.setMinimumSize(new java.awt.Dimension(150, 70));
080: pConnectionInfo
081: .setPreferredSize(new java.awt.Dimension(150, 80));
082: lLocalPort.setText("Local Port: ");
083: gridBagConstraints = new java.awt.GridBagConstraints();
084: gridBagConstraints.gridx = 0;
085: gridBagConstraints.gridy = 0;
086: gridBagConstraints.ipadx = 16;
087: gridBagConstraints.ipady = 9;
088: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
089: pConnectionInfo.add(lLocalPort, gridBagConstraints);
090:
091: tfLocalPort.setText("8080");
092: gridBagConstraints = new java.awt.GridBagConstraints();
093: gridBagConstraints.gridx = 1;
094: gridBagConstraints.gridy = 0;
095: gridBagConstraints.ipadx = 119;
096: gridBagConstraints.ipady = 4;
097: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
098: gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
099: pConnectionInfo.add(tfLocalPort, gridBagConstraints);
100:
101: lRemoteHost.setText("Server Name: ");
102: gridBagConstraints = new java.awt.GridBagConstraints();
103: gridBagConstraints.gridx = 0;
104: gridBagConstraints.gridy = 1;
105: gridBagConstraints.ipadx = 3;
106: gridBagConstraints.ipady = 9;
107: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
108: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
109: pConnectionInfo.add(lRemoteHost, gridBagConstraints);
110:
111: tfRemoteHost.setText("127.0.0.1");
112: gridBagConstraints = new java.awt.GridBagConstraints();
113: gridBagConstraints.gridx = 1;
114: gridBagConstraints.gridy = 1;
115: gridBagConstraints.gridheight = 2;
116: gridBagConstraints.ipadx = 119;
117: gridBagConstraints.ipady = 4;
118: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
119: gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 0);
120: pConnectionInfo.add(tfRemoteHost, gridBagConstraints);
121:
122: lRemotePort.setText("Server Port: ");
123: gridBagConstraints = new java.awt.GridBagConstraints();
124: gridBagConstraints.gridx = 0;
125: gridBagConstraints.gridy = 3;
126: gridBagConstraints.ipadx = 6;
127: gridBagConstraints.ipady = 9;
128: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
129: gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
130: pConnectionInfo.add(lRemotePort, gridBagConstraints);
131:
132: tfRemotePort.setText("80");
133: gridBagConstraints = new java.awt.GridBagConstraints();
134: gridBagConstraints.gridx = 1;
135: gridBagConstraints.gridy = 3;
136: gridBagConstraints.gridheight = 2;
137: gridBagConstraints.ipadx = 119;
138: gridBagConstraints.ipady = 4;
139: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
140: gridBagConstraints.insets = new java.awt.Insets(6, 10, 16, 0);
141: pConnectionInfo.add(tfRemotePort, gridBagConstraints);
142:
143: gridBagConstraints = new java.awt.GridBagConstraints();
144: gridBagConstraints.gridx = 0;
145: gridBagConstraints.gridy = 1;
146: gridBagConstraints.gridwidth = 3;
147: gridBagConstraints.ipadx = 90;
148: gridBagConstraints.ipady = 40;
149: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
150: gridBagConstraints.insets = new java.awt.Insets(15, 30, 0, 0);
151: pConnection.add(pConnectionInfo, gridBagConstraints);
152:
153: bAddMonitor.setText("Add Monitor");
154: bAddMonitor
155: .addActionListener(new java.awt.event.ActionListener() {
156: public void actionPerformed(
157: java.awt.event.ActionEvent evt) {
158: bAddMonitorActionPerformed(evt);
159: }
160: });
161:
162: gridBagConstraints = new java.awt.GridBagConstraints();
163: gridBagConstraints.gridx = 0;
164: gridBagConstraints.gridy = 2;
165: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
166: gridBagConstraints.insets = new java.awt.Insets(0, 90, 278, 0);
167: pConnection.add(bAddMonitor, gridBagConstraints);
168:
169: adminPanel.add(pConnection, java.awt.BorderLayout.WEST);
170:
171: pInfo.setLayout(new java.awt.BorderLayout());
172:
173: tpInfo.setEditable(false);
174: spInfo.setViewportView(tpInfo);
175:
176: pInfo.add(spInfo, java.awt.BorderLayout.CENTER);
177:
178: adminPanel.add(pInfo, java.awt.BorderLayout.CENTER);
179:
180: tabbedPane.addTab("Admin", adminPanel);
181:
182: getContentPane().add(tabbedPane, java.awt.BorderLayout.CENTER);
183:
184: pack();
185: }//GEN-END:initComponents
186:
187: private void bAddMonitorActionPerformed(
188: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAddMonitorActionPerformed
189: MonitorPanel p = new MonitorPanel();
190: TunnelConfig tc = new TunnelConfig(tfRemoteHost.getText(),
191: tfRemotePort.getText(), tfLocalPort.getText(), true);
192: p.start(tc);
193: tabbedPane.addTab("Port " + tc.localPort, p);
194: // Select the tab that just got created.
195: tabbedPane.setSelectedIndex(tabbedPane.indexOfComponent(p));
196: }//GEN-LAST:event_bAddMonitorActionPerformed
197:
198: public static void main(String args[]) {
199: java.awt.EventQueue.invokeLater(new Runnable() {
200: public void run() {
201: new MainWindow().setVisible(true);
202: }
203: });
204: }
205:
206: // Variables declaration - do not modify//GEN-BEGIN:variables
207: private javax.swing.JPanel adminPanel;
208: private javax.swing.JButton bAddMonitor;
209: private javax.swing.JLabel jLabel1;
210: private javax.swing.JLabel lLocalPort;
211: private javax.swing.JLabel lRemoteHost;
212: private javax.swing.JLabel lRemotePort;
213: private javax.swing.JPanel pConnection;
214: private javax.swing.JPanel pConnectionInfo;
215: private javax.swing.JPanel pInfo;
216: private javax.swing.JScrollPane spInfo;
217: private javax.swing.JTabbedPane tabbedPane;
218: private javax.swing.JTextField tfLocalPort;
219: private javax.swing.JTextField tfRemoteHost;
220: private javax.swing.JTextField tfRemotePort;
221: private javax.swing.JTextPane tpInfo;
222: // End of variables declaration//GEN-END:variables
223:
224: }
|