Source code: com/voytechs/jnetanalyzer/tcp/swing/JTCPStream.java
1 /*
2 * File: JTCPStream.java
3 * Auth: Mark Bednarczyk
4 * Date: DATE
5 * Id: $Id: JTCPStream.java,v 1.1.1.1 2003/09/22 16:32:06 voytechs Exp $
6 ********************************************
7 Copyright (C) 2003 Mark Bednarczyk
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 ********************************************
23 * $Log: JTCPStream.java,v $
24 * Revision 1.1.1.1 2003/09/22 16:32:06 voytechs
25 * Initial import.
26 *
27 */
28 package com.voytechs.jnetanalyzer.tcp.swing;
29
30 import com.voytechs.jnetstream.protocol.layer4.*;
31 import com.voytechs.jnetstream.protocol.*;
32 import com.voytechs.jnetanalyzer.tcp.*;
33 import com.voytechs.jnetanalyzer.message.*;
34 import com.voytechs.jnetanalyzer.message.swing.*;
35
36
37 import java.lang.*;
38 import java.util.*;
39
40 import java.awt.*;
41
42 /**
43 *
44 */
45 public class JTCPStream
46 extends JMessage {
47
48 /* Internal attributes */
49 private static final boolean debug = false;
50
51 private ArrayList segments = new ArrayList();
52
53 private TCPStream stream;
54
55 /**
56 *
57 * @param
58 * @exception
59 */
60 public JTCPStream(TCPStream stream) {
61
62 this.stream = stream;
63
64 getControlBox().setTitle(stream.getName() + ": " + stream.getAddress().toString());
65 }
66
67 /**
68 * Find the segment out of all that have been added.
69 */
70 protected JTCPSegment getSegment(long seq) {
71 for(int i = 0; i < segments.size(); i ++) {
72 JTCPSegment seg = (JTCPSegment)segments.get(i);
73
74 if(seq >= seg.getSeq() && seq <= (seg.getSeq() + seg.getLength())) {
75 return(seg);
76 }
77 }
78
79 return(null);
80 }
81
82 /**
83 * Adds a new segment.
84 */
85 public void add(JTCPSegment seg) {
86 super.add(seg);
87
88 segments.add(seg);
89 }
90
91 /**
92 * Handle an event from analyzer. This event is specific to a segment in our stream.
93 */
94 public void handleAnalyzerEvent(MessageSegment seg, MessageEvent event) {
95 TCPSegment tcpSegment = (TCPSegment)seg;
96
97 if(event.getType().equals(TCPEvent.EVENT_ACKNOWLEDGMENT)) {
98 JTCPSegment segment = getSegment(tcpSegment.getAck());
99 if(segment == null)
100 return;
101
102 segment.setBackground(Color.yellow);
103 segment.cancelTimeoutTimer();
104 }
105 }
106
107 /**
108 * Test function for JTCPStream
109 * @param args command line arguments
110 */
111 public static void main(String [] args) {
112 }
113
114 } /* END OF: JTCPStream */