Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/voytechs/jnetanalyzer/message/swing/JMessage.java


1   /*
2    * File: JMessage.java
3    * Auth: Mark Bednarczyk
4    * Date: DATE
5    *   Id: $Id: JMessage.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: JMessage.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.message.swing;
29  
30  import java.lang.*;
31  import java.util.*;
32  
33  import java.awt.*;
34  import java.awt.event.*;
35  import javax.swing.*;
36  import javax.swing.border.*;
37  
38  /**
39   *  JMessage is a rectangular representation of a network message.
40   * The message is made up of many segmenets. As segments are added they
41   * are displayed within the message box. Appropriate colors and labels can be
42   * assigned to each segements and entire message. 
43   * Message contains scrollbars if it doesn't fit on the screen.
44   */
45  public class JMessage 
46    extends JPanel {
47  
48    /* Internal attributes */
49    private static final boolean debug = false;
50  
51    private JMessageControlBox controlBox = new JMessageControlBox();
52  
53    /**
54     *
55     * @param
56     * @exception
57     */
58    public JMessage() {
59      setLayout(new FlowLayout());
60  
61      Action cancelTimersAction = new AbstractAction("Stop All Timers") {
62        
63        public void actionPerformed(ActionEvent event) {
64          
65          JMessage m = (JMessage)getValue("message");
66          m.cancelAllTimeoutTimers();
67  
68  //        ((JButton)event.getSource()).setVisible(false);
69        }
70        
71      };
72  
73      cancelTimersAction.putValue("message", this);
74  
75      Action addSegmentAction = new AbstractAction("Add") {
76        
77        public void actionPerformed(ActionEvent event) {
78          
79          JMessage m = (JMessage)getValue("message");
80          m.add(new JMessageSegment());
81          m.validate();
82        }
83        
84      };
85  
86      addSegmentAction.putValue("message", this);
87  
88      Action hideAction = new AbstractAction("Hide") {
89        
90        public void actionPerformed(ActionEvent event) {
91          
92          JMessage m = (JMessage)getValue("message");
93          m.setVisible(false);
94        }
95        
96      };
97  
98      hideAction.putValue("message", this);
99  
100     JButton button;
101 //    add(button = new JButton(cancelTimersAction));
102 //    add(button = new JButton(addSegmentAction));
103     add(button = new JButton(hideAction));
104 
105     add(controlBox);
106 
107 
108     setBorder(new BevelBorder(BevelBorder.RAISED));
109 
110   }
111 
112 
113 
114 
115   /**
116    * Cancel all timers for all of the segments.
117    */
118   public void cancelAllTimeoutTimers() {
119     
120     Component[] components = getComponents();
121 
122     for(int i = 0; i < components.length; i ++) {
123       if(components[i] instanceof JMessageSegment) {
124         ((JMessageSegment)components[i]).cancelTimeoutTimer();
125       }
126     }
127   }
128 
129 
130 
131 
132   /**
133    * Returns the control box.
134    */
135   public JMessageControlBox getControlBox() {
136     return(controlBox);
137   }
138 
139 
140   /**
141    * Test function for JMessage
142    * @param args command line arguments
143    */
144   public static void main(String [] args) {
145 
146     JFrame  frame = new JFrame("Message Panel Test");
147 
148     JMessage m = new JMessage();
149 
150     m.getControlBox().setLabel1("SRC: 192.168.1.1 > 23");
151     m.getControlBox().setLabel2("DST: 192.168.1.2 < 1551");
152     m.getControlBox().setLabel3("Wed 2003-07-28 5:39:06.05 pm created");
153     m.getControlBox().setTitle("192.168.1.1 -> 192.168.1.2");
154 
155     for(int i = 0; i < 0; i ++) {
156       m.add(new JMessageSegment());
157     }
158 
159     frame.setContentPane(m);
160 
161     frame.getContentPane().setSize(200, 200);
162     frame.pack();
163 
164     frame.setVisible(true);
165   }
166 
167 
168 } /* END OF: JMessage */