001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 2005-2006 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.tcpmon.integration;
021:
022: import javax.swing.ListSelectionModel;
023: import javax.swing.event.ListSelectionEvent;
024: import javax.swing.event.ListSelectionListener;
025: import javax.swing.table.AbstractTableModel;
026: import tcpmon.CallBack;
027: import tcpmon.RequestSender;
028: import tcpmon.RequestsTableModel;
029: import tcpmon.Tunnel;
030: import tcpmon.TunnelConfig;
031: import tcpmon.Utils;
032:
033: /**
034: *
035: * @author Inderjeet Singh
036: * @author Lukas Jungmann
037: */
038: public class MonitorPanel extends javax.swing.JPanel implements
039: CallBack, ListSelectionListener {
040:
041: /** Creates new form MonitorPanel */
042: public MonitorPanel() {
043: initComponents();
044: }
045:
046: /** This method is called from within the constructor to
047: * initialize the form.
048: * WARNING: Do NOT modify this code. The content of this method is
049: * always regenerated by the Form Editor.
050: */
051: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
052: private void initComponents() {
053: jSplitPane1 = new javax.swing.JSplitPane();
054: tablePanel = new javax.swing.JPanel();
055: bDeleteRow = new javax.swing.JButton();
056: bDeleteAllRows = new javax.swing.JButton();
057: bSubmitToServer = new javax.swing.JButton();
058: spRequestsTable = new javax.swing.JScrollPane();
059: tRequests = new javax.swing.JTable();
060: tRequests.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
061: tRequests.getSelectionModel().addListSelectionListener(this );
062: bStop = new javax.swing.JButton();
063: bCloseTab = new javax.swing.JButton();
064: splitPane = new javax.swing.JSplitPane();
065: spForward = new javax.swing.JScrollPane();
066: tpForward = new javax.swing.JTextPane();
067: spReverse = new javax.swing.JScrollPane();
068: tpReverse = new javax.swing.JTextPane();
069:
070: setLayout(new java.awt.BorderLayout(5, 5));
071:
072: jSplitPane1
073: .setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
074: jSplitPane1.setOneTouchExpandable(true);
075: bDeleteRow.setText(org.openide.util.NbBundle.getMessage(
076: MonitorPanel.class, "BTN_Delete_Row"));
077: bDeleteRow.setEnabled(false);
078: bDeleteRow
079: .addActionListener(new java.awt.event.ActionListener() {
080: public void actionPerformed(
081: java.awt.event.ActionEvent evt) {
082: bDeleteRowActionPerformed(evt);
083: }
084: });
085:
086: bDeleteAllRows.setText(org.openide.util.NbBundle.getMessage(
087: MonitorPanel.class, "BTN_Delete_All_Rows"));
088: bDeleteAllRows
089: .addActionListener(new java.awt.event.ActionListener() {
090: public void actionPerformed(
091: java.awt.event.ActionEvent evt) {
092: bDeleteAllRowsActionPerformed(evt);
093: }
094: });
095:
096: bSubmitToServer.setText(org.openide.util.NbBundle.getMessage(
097: MonitorPanel.class, "BTN_Submit_to_Server"));
098: bSubmitToServer
099: .addActionListener(new java.awt.event.ActionListener() {
100: public void actionPerformed(
101: java.awt.event.ActionEvent evt) {
102: bSubmitToServerActionPerformed(evt);
103: }
104: });
105:
106: spRequestsTable
107: .setPreferredSize(new java.awt.Dimension(452, 52));
108: tRequests
109: .setBorder(javax.swing.BorderFactory
110: .createBevelBorder(javax.swing.border.BevelBorder.RAISED));
111: tRequests.setModel(getTableModel());
112: spRequestsTable.setViewportView(tRequests);
113:
114: bStop.setText(org.openide.util.NbBundle.getMessage(
115: MonitorPanel.class, "BTN_Stop_Monitor"));
116: bStop.addActionListener(new java.awt.event.ActionListener() {
117: public void actionPerformed(java.awt.event.ActionEvent evt) {
118: bStopActionPerformed(evt);
119: }
120: });
121:
122: bCloseTab.setText(org.openide.util.NbBundle.getMessage(
123: MonitorPanel.class, "BTN_Close_Tab"));
124: bCloseTab
125: .addActionListener(new java.awt.event.ActionListener() {
126: public void actionPerformed(
127: java.awt.event.ActionEvent evt) {
128: bCloseTabActionPerformed(evt);
129: }
130: });
131:
132: org.jdesktop.layout.GroupLayout tablePanelLayout = new org.jdesktop.layout.GroupLayout(
133: tablePanel);
134: tablePanel.setLayout(tablePanelLayout);
135: tablePanelLayout
136: .setHorizontalGroup(tablePanelLayout
137: .createParallelGroup(
138: org.jdesktop.layout.GroupLayout.LEADING)
139: .add(
140: org.jdesktop.layout.GroupLayout.TRAILING,
141: tablePanelLayout
142: .createSequentialGroup()
143: .add(
144: tablePanelLayout
145: .createParallelGroup(
146: org.jdesktop.layout.GroupLayout.LEADING,
147: false)
148: .add(
149: bCloseTab,
150: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
151: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
152: Short.MAX_VALUE)
153: .add(
154: bStop,
155: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
156: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
157: Short.MAX_VALUE))
158: .addPreferredGap(
159: org.jdesktop.layout.LayoutStyle.RELATED)
160: .add(
161: spRequestsTable,
162: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
163: 368, Short.MAX_VALUE)
164: .addPreferredGap(
165: org.jdesktop.layout.LayoutStyle.RELATED)
166: .add(
167: tablePanelLayout
168: .createParallelGroup(
169: org.jdesktop.layout.GroupLayout.LEADING,
170: false)
171: .add(
172: org.jdesktop.layout.GroupLayout.TRAILING,
173: bSubmitToServer,
174: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
175: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
176: Short.MAX_VALUE)
177: .add(
178: org.jdesktop.layout.GroupLayout.TRAILING,
179: bDeleteRow,
180: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
181: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
182: Short.MAX_VALUE)
183: .add(
184: org.jdesktop.layout.GroupLayout.TRAILING,
185: bDeleteAllRows,
186: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
187: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
188: Short.MAX_VALUE))));
189: tablePanelLayout
190: .setVerticalGroup(tablePanelLayout
191: .createParallelGroup(
192: org.jdesktop.layout.GroupLayout.LEADING)
193: .add(
194: tablePanelLayout
195: .createSequentialGroup()
196: .add(bDeleteRow)
197: .addPreferredGap(
198: org.jdesktop.layout.LayoutStyle.RELATED)
199: .add(bDeleteAllRows)
200: .addPreferredGap(
201: org.jdesktop.layout.LayoutStyle.RELATED)
202: .add(bSubmitToServer))
203: .add(
204: tablePanelLayout
205: .createSequentialGroup()
206: .add(bStop)
207: .addPreferredGap(
208: org.jdesktop.layout.LayoutStyle.RELATED)
209: .add(bCloseTab).add(31, 31, 31))
210: .add(
211: spRequestsTable,
212: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
213: 87, Short.MAX_VALUE));
214: jSplitPane1.setTopComponent(tablePanel);
215:
216: splitPane.setResizeWeight(0.5);
217: splitPane.setLastDividerLocation(-5);
218: splitPane.setOneTouchExpandable(true);
219: spForward.setViewportView(tpForward);
220:
221: splitPane.setLeftComponent(spForward);
222:
223: spReverse.setViewportView(tpReverse);
224:
225: splitPane.setBottomComponent(spReverse);
226:
227: jSplitPane1.setRightComponent(splitPane);
228:
229: add(jSplitPane1, java.awt.BorderLayout.CENTER);
230:
231: }// </editor-fold>//GEN-END:initComponents
232:
233: private void bCloseTabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCloseTabActionPerformed
234: // Close this tab and send
235: bCloseTab.setEnabled(false);
236: tableModel.deleteAllRows();
237: tunnel.stopNow();
238: getParent().remove(this );
239: }//GEN-LAST:event_bCloseTabActionPerformed
240:
241: private void bSubmitToServerActionPerformed(
242: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSubmitToServerActionPerformed
243: String requestData = tpForward.getText();
244: RequestSender sender = new RequestSender(requestData, tc, this );
245: }//GEN-LAST:event_bSubmitToServerActionPerformed
246:
247: private void bDeleteAllRowsActionPerformed(
248: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDeleteAllRowsActionPerformed
249: tableModel.deleteAllRows();
250: }//GEN-LAST:event_bDeleteAllRowsActionPerformed
251:
252: private void bDeleteRowActionPerformed(
253: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDeleteRowActionPerformed
254: tableModel.deleteRow(tRequests.getSelectedRow());
255: }//GEN-LAST:event_bDeleteRowActionPerformed
256:
257: private void bStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bStopActionPerformed
258: tunnel.stopNow();
259: bStop.setEnabled(false);
260: }//GEN-LAST:event_bStopActionPerformed
261:
262: private RequestsTableModel tableModel = new RequestsTableModel();
263:
264: public AbstractTableModel getTableModel() {
265: return tableModel;
266: }
267:
268: public String getForwardData() {
269: int selectedRow = tRequests.getSelectedRow();
270: return tableModel.getForwardData(selectedRow);
271: }
272:
273: public void valueChanged(ListSelectionEvent e) {
274: //Ignore extra messages.
275: if (e.getValueIsAdjusting())
276: return;
277:
278: ListSelectionModel lsm = (ListSelectionModel) e.getSource();
279: bDeleteRow.setEnabled(!lsm.isSelectionEmpty());
280: if (lsm.isSelectionEmpty()) {
281: // no rows are selected
282: } else {
283: int selectedRow = lsm.getMinSelectionIndex();
284: tpForward.setText(tableModel.getForwardData(selectedRow));
285: tpReverse.setText(tableModel.getReverseData(selectedRow));
286: }
287: }
288:
289: public void connectionFinished(CallBack.CallBackData data) {
290: String fdata = data.getForwardData();
291: tpForward.setText(fdata);
292: tpReverse.setText(data.getReverseData());
293: // System.err.println("data1: " + fdata);
294: // System.err.println("data2: " + data.getReverseData());
295: int len = fdata.length();
296: if (len > 10) {
297: len = 10;
298: }
299: String requestHead = fdata.substring(0, len) + "...";
300: tableModel.addEntry(data.getState(), data.getTime(), data
301: .getSourceHost(), tc.serverName, requestHead, fdata,
302: data.getReverseData());
303: }
304:
305: public void start(TunnelConfig tc) {
306: try {
307: this .tc = tc;
308: // tfLocalPort.setText(String.valueOf(tc.localPort));
309: // tfRemotePort.setText(String.valueOf(tc.serverPort));
310: // tfRemoteHost.setText(tc.serverName);
311: tunnel = new Tunnel(tc, this );
312: } catch (Exception e) {
313: String stackTrace = Utils.extractStackTrace(e);
314: tpForward.setText(stackTrace);
315: }
316: }
317:
318: TunnelConfig tc;
319: Tunnel tunnel;
320:
321: // Variables declaration - do not modify//GEN-BEGIN:variables
322: private javax.swing.JButton bCloseTab;
323: private javax.swing.JButton bDeleteAllRows;
324: private javax.swing.JButton bDeleteRow;
325: private javax.swing.JButton bStop;
326: private javax.swing.JButton bSubmitToServer;
327: private javax.swing.JSplitPane jSplitPane1;
328: private javax.swing.JScrollPane spForward;
329: private javax.swing.JScrollPane spRequestsTable;
330: private javax.swing.JScrollPane spReverse;
331: private javax.swing.JSplitPane splitPane;
332: private javax.swing.JTable tRequests;
333: private javax.swing.JPanel tablePanel;
334: private javax.swing.JTextPane tpForward;
335: private javax.swing.JTextPane tpReverse;
336: // End of variables declaration//GEN-END:variables
337:
338: }
|