KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > fenyo > gnetwatch > GUI > ChartComponent


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.GUI;
25
26 import java.io.*;
27 import java.util.Date JavaDoc;
28 import java.awt.*;
29 import java.awt.event.WindowEvent JavaDoc;
30 import java.awt.font.*;
31 import java.awt.geom.*;
32 import java.awt.image.*;
33 import javax.swing.*;
34 import javax.imageio.*;
35
36 import net.fenyo.gnetwatch.data.EventReachable;
37 import net.fenyo.gnetwatch.targets.*;
38
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41
42 /**
43  * This class implements a component that can display EventReachable events.
44  * @author Alexandre Fenyo
45  * @version $Id: ChartComponent.java,v 1.9 2007/03/03 00:38:19 fenyo Exp $
46  */

47
48 public class ChartComponent extends BasicComponent {
49   private static Log log = LogFactory.getLog(ChartComponent.class);
50
51   /**
52    * Constructor.
53    * @param target target this graphic component works on.
54    */

55   // GUI thread
56
public ChartComponent(final Target target) {
57     super(target);
58   }
59
60   /**
61    * Called when the window is closing.
62    * @param e event.
63    * @return void.
64    */

65   // AWT thread
66
public void windowClosing(final WindowEvent JavaDoc e) {
67     getTarget().unregisterComponent(this, EventReachable.class);
68   }
69
70   /**
71    * Fetches events that can be displayed.
72    * @param none.
73    * @return void.
74    */

75   // AWT thread
76
// AWT thread << sync_value_per_vinterval << sync_update << registered_components
77
protected void updateValues() {
78     synchronized (getSyncUpdate()) {
79       getTarget().registerComponent(this, EventReachable.class);
80       final long end = System.currentTimeMillis();
81       final long begin = end - getDelayPerInterval() *
82       (getDimension().width - axis_margin_left - axis_margin_right) / pixels_per_interval;
83       setEvents(getTarget().getEvents(new Date JavaDoc(begin), new Date JavaDoc(end), EventReachable.class));
84       updateVerticalScale();
85     }
86   }
87 }
88
Popular Tags