KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > fenyo > gnetwatch > data > Views


1
2 /*
3  * GNetWatch
4  * Copyright 2006, 2007 Alexandre Fenyo
5  * gnetwatch@fenyo.net
6  *
7  * This file is part of GNetWatch.
8  *
9  * GNetWatch is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * GNetWatch 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 GNetWatch; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  */

23
24 package net.fenyo.gnetwatch.data;
25
26 import net.fenyo.gnetwatch.*;
27 import net.fenyo.gnetwatch.GUI.*;
28 import net.fenyo.gnetwatch.targets.*;
29
30 import java.util.*;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 /**
36  * This class creates and manages views, depending on the events that are created.
37  * @author Alexandre Fenyo
38  * @version $Id: Views.java,v 1.17 2007/03/09 22:44:20 fenyo Exp $
39  */

40
41 public class Views {
42   private static Log log = LogFactory.getLog(Views.class);
43
44   private final GUI gui;
45
46   /**
47    * Constructor.
48    * @param gui GUI instance.
49    */

50   // main thread
51
public Views(final GUI gui) {
52     this.gui = gui;
53   }
54
55   /**
56    * Each time a target gets a new event type, this method creates the associated view.
57    * @param target new target.
58    * @return void.
59    */

60   // add data views to this target if needed
61
// GUI thread
62
public void refreshDataViews(final Target target) {
63     synchronized (gui.sync_tree) {
64       for (final Class JavaDoc event_type : target.getEventTypesInUse()) {
65         if (event_type == EventGeneric.class) {
66           // nothing to do : no view can handle generic events
67
}
68
69         // manage events handled by ReachableView
70
if (event_type == EventReachable.class /* || event_type == A_CLASS_ReachableView_CAN_HANDLE */) {
71           ReachableView reachable_view = null;
72           // look for an instance of ReachableView
73
for (final VisualElement child : target.getChildren())
74             if (child instanceof ReachableView) {
75               reachable_view = (ReachableView) child;
76               break;
77             }
78           if (reachable_view == null) new ReachableView(gui, target);
79         }
80
81         // manage events handled by FloodView
82
if (event_type == EventFlood.class) {
83           FloodView flood_view = null;
84           // look for an instance of ReachableView
85
for (final VisualElement child : target.getChildren())
86             if (child instanceof FloodView) {
87               flood_view = (FloodView) child;
88               break;
89             }
90           if (flood_view == null) new FloodView(gui, target);
91         }
92
93         // manage events handled by HTTPView
94
if (event_type == EventHTTP.class) {
95           HTTPView http_view = null;
96           // look for an instance of HTTPView
97
for (final VisualElement child : target.getChildren())
98             if (child instanceof HTTPView) {
99               http_view = (HTTPView) child;
100               break;
101             }
102           if (http_view == null) new HTTPView(gui, target);
103         }
104
105         // manage events handled by HTTPPagesView
106
if (event_type == EventHTTPPages.class) {
107           HTTPPagesView http_pages_view = null;
108           // look for an instance of HTTPView
109
for (final VisualElement child : target.getChildren())
110             if (child instanceof HTTPPagesView) {
111               http_pages_view = (HTTPPagesView) child;
112               break;
113             }
114           if (http_pages_view == null) new HTTPPagesView(gui, target);
115         }
116
117         // manage events handled by NmapView
118
if (event_type == EventNmap.class) {
119           NmapView nmap_view = null;
120           // look for an instance of NmapView
121
for (final VisualElement child : target.getChildren())
122             if (child instanceof NmapView) {
123               nmap_view = (NmapView) child;
124               break;
125             }
126           if (nmap_view == null) new NmapView(gui, target);
127         }
128
129         // manage events handled by BytesReceivedView
130
if (event_type == EventBytesReceived.class) {
131           BytesReceivedView bytes_received_view = null;
132           // look for an instance of BytesReceivedView
133
for (final VisualElement child : target.getChildren())
134             if (child instanceof BytesReceivedView) {
135               bytes_received_view = (BytesReceivedView) child;
136               break;
137             }
138           if (bytes_received_view == null) new BytesReceivedView(gui, target);
139         }
140
141         // manage events handled by BytesSentView
142
if (event_type == EventBytesSent.class) {
143           BytesSentView bytes_sent_view = null;
144           // look for an instance of BytesSentView
145
for (final VisualElement child : target.getChildren())
146             if (child instanceof BytesSentView) {
147               bytes_sent_view = (BytesSentView) child;
148               break;
149             }
150           if (bytes_sent_view == null) new BytesSentView(gui, target);
151         }
152       }
153     }
154   }
155
156   /**
157    * Checks that the parameter can be a child of this visual element.
158    * @param visual_element visual element.
159    * @return boolean true is the parameter can be a child of this visual element.
160    */

161   public boolean canManageThisChild(final VisualElement visual_element) {
162     return false;
163   }
164 }
165
Popular Tags