01: /*
02: * GNetWatch
03: * Copyright 2006, 2007 Alexandre Fenyo
04: * gnetwatch@fenyo.net
05: *
06: * This file is part of GNetWatch.
07: *
08: * GNetWatch is free software; you can redistribute it and/or modify
09: * it under the terms of the GNU General Public License as published by
10: * the Free Software Foundation; either version 2 of the License, or
11: * (at your option) any later version.
12: *
13: * GNetWatch is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with GNetWatch; if not, write to the Free Software
20: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21: */
22:
23: package net.fenyo.gnetwatch.GUI;
24:
25: import java.io.*;
26: import java.util.Date;
27: import java.awt.*;
28: import java.awt.event.WindowEvent;
29: import java.awt.font.*;
30: import java.awt.geom.*;
31: import java.awt.image.*;
32: import javax.swing.*;
33: import javax.imageio.*;
34:
35: import net.fenyo.gnetwatch.data.*;
36: import net.fenyo.gnetwatch.targets.*;
37:
38: import org.apache.commons.logging.Log;
39: import org.apache.commons.logging.LogFactory;
40:
41: /**
42: * This class implements a component that can display EventBytesSent events.
43: * @author Alexandre Fenyo
44: * @version $Id: BytesSentComponent.java,v 1.5 2007/03/03 00:38:19 fenyo Exp $
45: */
46:
47: public class BytesSentComponent extends BasicComponent {
48: private static Log log = LogFactory
49: .getLog(BytesSentComponent.class);
50:
51: /**
52: * Constructor.
53: * @param target target this graphic component works on.
54: */
55: // GUI thread
56: public BytesSentComponent(final Target target) {
57: super (target);
58: }
59:
60: /**
61: * Returns the horizontal scale.
62: * @param none.
63: * @return long horizontal scale.
64: */
65: public long getDelayPerInterval() {
66: return 60000;
67: }
68:
69: /**
70: * Called when the window is closing.
71: * @param e event.
72: * @return void.
73: */
74: // AWT thread
75: public void windowClosing(final WindowEvent e) {
76: getTarget().unregisterComponent(this , EventBytesSent.class);
77: }
78:
79: /**
80: * Fetches events that can be displayed.
81: * @param none.
82: * @return void.
83: */
84: // AWT thread
85: // AWT thread << sync_value_per_vinterval << sync_update << registered_components
86: protected void updateValues() {
87: synchronized (getSyncUpdate()) {
88: getTarget().registerComponent(this , EventBytesSent.class);
89: final long end = System.currentTimeMillis();
90: final long begin = end
91: - getDelayPerInterval()
92: * (getDimension().width - axis_margin_left - axis_margin_right)
93: / pixels_per_interval;
94: setEvents(getTarget().getEvents(new Date(begin),
95: new Date(end), EventBytesSent.class));
96: updateVerticalScale();
97: }
98: }
99: }
|