001: /*
002: * GNetWatch
003: * Copyright 2006, 2007 Alexandre Fenyo
004: * gnetwatch@fenyo.net
005: *
006: * This file is part of GNetWatch.
007: *
008: * GNetWatch is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License as published by
010: * the Free Software Foundation; either version 2 of the License, or
011: * (at your option) any later version.
012: *
013: * GNetWatch is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with GNetWatch; if not, write to the Free Software
020: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
021: */
022:
023: package net.fenyo.gnetwatch.GUI;
024:
025: import java.io.*;
026: import java.util.Date;
027: import java.awt.*;
028: import java.awt.event.WindowEvent;
029: import java.awt.font.*;
030: import java.awt.geom.*;
031: import java.awt.image.*;
032: import javax.swing.*;
033: import javax.imageio.*;
034:
035: import net.fenyo.gnetwatch.data.*;
036: import net.fenyo.gnetwatch.targets.*;
037:
038: import org.apache.commons.logging.Log;
039: import org.apache.commons.logging.LogFactory;
040:
041: /**
042: * This class implements a component that can display EventBytesReceived events.
043: * @author Alexandre Fenyo
044: * @version $Id: BytesReceivedComponent.java,v 1.5 2007/03/03 00:38:19 fenyo Exp $
045: */
046:
047: public class BytesReceivedComponent extends BasicComponent {
048: private static Log log = LogFactory
049: .getLog(BytesReceivedComponent.class);
050:
051: /**
052: * Constructor.
053: * @param target target this graphic component works on.
054: */
055: // GUI thread
056: public BytesReceivedComponent(final Target target) {
057: super (target);
058: }
059:
060: /**
061: * Returns the horizontal scale.
062: * @param none.
063: * @return long horizontal scale.
064: */
065: public long getDelayPerInterval() {
066: return 60000;
067: }
068:
069: /**
070: * Called when the window is closing.
071: * @param e event.
072: * @return void.
073: */
074: // AWT thread
075: public void windowClosing(final WindowEvent e) {
076: getTarget().unregisterComponent(this , EventBytesReceived.class);
077: }
078:
079: /**
080: * Fetches events that can be displayed.
081: * @param none.
082: * @return void.
083: */
084: // AWT thread
085: // AWT thread << sync_value_per_vinterval << sync_update << registered_components
086: protected void updateValues() {
087: synchronized (getSyncUpdate()) {
088: getTarget().registerComponent(this ,
089: EventBytesReceived.class);
090: final long end = System.currentTimeMillis();
091: final long begin = end
092: - getDelayPerInterval()
093: * (getDimension().width - axis_margin_left - axis_margin_right)
094: / pixels_per_interval;
095: setEvents(getTarget().getEvents(new Date(begin),
096: new Date(end), EventBytesReceived.class));
097: updateVerticalScale();
098: }
099: }
100: }
|