net.fenyo.gnetwatch.GUI
Class BasicComponent

java.lang.Object
  extended by java.awt.Component
      extended by net.fenyo.gnetwatch.GUI.BasicComponent
All Implemented Interfaces:
java.awt.event.ComponentListener, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener
Direct Known Subclasses:
BytesReceivedComponent, BytesSentComponent, ChartComponent, FloodComponent, GenericProcessComponent, GenericSrcComponent, HTTPComponent, HTTPPagesComponent, MapComponent

public abstract class BasicComponent
extends java.awt.Component
implements java.awt.event.ComponentListener, java.awt.event.WindowListener, java.awt.event.KeyListener, java.awt.event.MouseMotionListener, java.awt.event.MouseListener

This class implements an AWT component capable of drawing time series with the Java2D API.

Version:
$Id: BasicComponent.java,v 1.37 2008/04/27 21:13:02 fenyo Exp $
Author:
Alexandre Fenyo
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private static int axis_margin_bottom
           
protected  int axis_margin_left
           
protected static int axis_margin_right
           
private static int axis_margin_top
           
private  java.awt.Graphics2D backing_g
           
private  java.awt.Image backing_store
           
private  java.text.DateFormat date_format
           
private  java.awt.Dimension dimension
           
private  long drag_now_start
           
private  int drag_x_start
           
private  java.util.List<EventGeneric> events
           
private  int fps
           
private  int last_fps_100ms
           
private  long last_paint
           
private  long last_paint_100ms
           
private  int lastPixelsOffsetValue
           
private static Log log
           
private  long manual_delay_per_interval
           
private  boolean manual_mode
           
private  long manual_now
           
protected  int pixels_per_interval
           
private  int pixels_per_vinterval
           
private static int std_margin
           
private static int std_separator
           
private static java.lang.Object sync_update
           
private  java.lang.Object sync_value_per_vinterval
           
private  Target target
           
private  int value_per_vinterval
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
BasicComponent(Target target)
          Constructor.
 
Method Summary
private  long _getDelayPerInterval()
           
 void componentHidden(java.awt.event.ComponentEvent e)
          Called when the component is hidden.
 void componentMoved(java.awt.event.ComponentEvent e)
          Called when the component is moved.
 void componentResized(java.awt.event.ComponentEvent e)
          When the component is resized, creates a new backing store, reset margins and fetch events that can be displayed.
 void componentShown(java.awt.event.ComponentEvent e)
          Called when the component appears first.
private  java.lang.String formatDate(long time)
           
private  java.lang.String formatTime(long time)
          Formats a time string to be displayed.
 long getDelayPerInterval()
          Returns the horizontal scale.
protected  java.awt.Dimension getDimension()
          Returns the dimensions of this component.
protected abstract  java.lang.Class getEventClass()
           
protected  Target getTarget()
          Returns the associated target.
 void init()
          Initialize the component and ask AWT to receive events.
 boolean isManualMode()
           
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
private  void newBackingElts()
          Creates a backing store.
 void paint(java.awt.Graphics g)
          Repaints the component using the backing store.
private  long paintAxis()
          Paints axis.
 void paintChart(long now)
          Paints the chart.
private  void paintFPS(int fps)
          Displays the number of frames per second.
 boolean pixelsOffsetChanged()
           
private  void removeOldEvents()
          Removes events that can not be displayed.
protected  void setEvents(java.util.List<EventGeneric> events)
          Sets the list of events to display.
private  void setMargin()
          Computes new margins.
private  void updateFPS()
          Computes the "frames per second" indicator.
protected  void updateValues()
          Fetches events that can be displayed.
 void updateValues(EventGeneric event)
          Takes a new event into account.
protected  void updateVerticalScale()
          Updates the vertical scale.
 void windowActivated(java.awt.event.WindowEvent e)
          Called whenthe window is activated.
 void windowClosed(java.awt.event.WindowEvent e)
          Called whenthe window is closed.
abstract  void windowClosing(java.awt.event.WindowEvent e)
          Called when the window is closing.
 void windowDeactivated(java.awt.event.WindowEvent e)
          Called whenthe window is deactivated.
 void windowDeiconified(java.awt.event.WindowEvent e)
          Called whenthe window is deiconified.
 void windowIconified(java.awt.event.WindowEvent e)
          Called whenthe window is iconified.
 void windowOpened(java.awt.event.WindowEvent e)
          Called whenthe window is opened.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static Log log

manual_mode

private boolean manual_mode

manual_now

private long manual_now

manual_delay_per_interval

private long manual_delay_per_interval

lastPixelsOffsetValue

private int lastPixelsOffsetValue

target

private final Target target

sync_update

private static java.lang.Object sync_update

events

private java.util.List<EventGeneric> events

backing_store

private java.awt.Image backing_store

backing_g

private java.awt.Graphics2D backing_g

dimension

private java.awt.Dimension dimension

date_format

private final java.text.DateFormat date_format

fps

private int fps

last_paint

private long last_paint

last_paint_100ms

private long last_paint_100ms

last_fps_100ms

private int last_fps_100ms

pixels_per_interval

protected final int pixels_per_interval
See Also:
Constant Field Values

value_per_vinterval

private int value_per_vinterval

sync_value_per_vinterval

private final java.lang.Object sync_value_per_vinterval

pixels_per_vinterval

private final int pixels_per_vinterval
See Also:
Constant Field Values

std_margin

private static final int std_margin
See Also:
Constant Field Values

std_separator

private static final int std_separator
See Also:
Constant Field Values

axis_margin_bottom

private static final int axis_margin_bottom
See Also:
Constant Field Values

axis_margin_top

private static final int axis_margin_top
See Also:
Constant Field Values

axis_margin_left

protected int axis_margin_left

axis_margin_right

protected static final int axis_margin_right
See Also:
Constant Field Values

drag_x_start

private int drag_x_start

drag_now_start

private long drag_now_start
Constructor Detail

BasicComponent

public BasicComponent(Target target)
Constructor.

Parameters:
target - target this graphic component works on.
Method Detail

isManualMode

public boolean isManualMode()

getDelayPerInterval

public long getDelayPerInterval()
Returns the horizontal scale.

Parameters:
none. -
Returns:
long horizontal scale.

_getDelayPerInterval

private long _getDelayPerInterval()

setEvents

protected void setEvents(java.util.List<EventGeneric> events)
Sets the list of events to display.

Parameters:
events - events to display.

getDimension

protected java.awt.Dimension getDimension()
Returns the dimensions of this component.

Parameters:
none. -
Returns:
Dimension dimensions.

getTarget

protected Target getTarget()
Returns the associated target.

Parameters:
none. -
Returns:
Target target.

init

public void init()
Initialize the component and ask AWT to receive events.


componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Called when the component is hidden.

Specified by:
componentHidden in interface java.awt.event.ComponentListener
Parameters:
e - event.

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Called when the component is moved.

Specified by:
componentMoved in interface java.awt.event.ComponentListener
Parameters:
e - event.

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
When the component is resized, creates a new backing store, reset margins and fetch events that can be displayed.

Specified by:
componentResized in interface java.awt.event.ComponentListener
Parameters:
e - event.

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Called when the component appears first.

Specified by:
componentShown in interface java.awt.event.ComponentListener
Parameters:
e - event.

windowActivated

public void windowActivated(java.awt.event.WindowEvent e)
Called whenthe window is activated.

Specified by:
windowActivated in interface java.awt.event.WindowListener
Parameters:
e - event.

windowClosed

public void windowClosed(java.awt.event.WindowEvent e)
Called whenthe window is closed.

Specified by:
windowClosed in interface java.awt.event.WindowListener
Parameters:
e - event.

windowClosing

public abstract void windowClosing(java.awt.event.WindowEvent e)
Called when the window is closing.

Specified by:
windowClosing in interface java.awt.event.WindowListener
Parameters:
e - event.

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent e)
Called whenthe window is deactivated.

Specified by:
windowDeactivated in interface java.awt.event.WindowListener
Parameters:
e - event.

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent e)
Called whenthe window is deiconified.

Specified by:
windowDeiconified in interface java.awt.event.WindowListener
Parameters:
e - event.

windowIconified

public void windowIconified(java.awt.event.WindowEvent e)
Called whenthe window is iconified.

Specified by:
windowIconified in interface java.awt.event.WindowListener
Parameters:
e - event.

windowOpened

public void windowOpened(java.awt.event.WindowEvent e)
Called whenthe window is opened.

Specified by:
windowOpened in interface java.awt.event.WindowListener
Parameters:
e - event.

setMargin

private void setMargin()
Computes new margins.

Parameters:
none. -

newBackingElts

private void newBackingElts()
Creates a backing store.

Parameters:
none. -

removeOldEvents

private void removeOldEvents()
Removes events that can not be displayed.

Parameters:
none. -

updateVerticalScale

protected void updateVerticalScale()
Updates the vertical scale.

Parameters:
none. -

updateValues

public void updateValues(EventGeneric event)
Takes a new event into account.

Parameters:
event - new event.

getEventClass

protected abstract java.lang.Class getEventClass()

updateValues

protected void updateValues()
Fetches events that can be displayed.

Parameters:
none. -

updateFPS

private void updateFPS()
Computes the "frames per second" indicator.

Parameters:
none. -

paintFPS

private void paintFPS(int fps)
Displays the number of frames per second.

Parameters:
fps - frames per second to display.

formatTime

private java.lang.String formatTime(long time)
Formats a time string to be displayed.

Parameters:
time - time.
Returns:
String time to be displayed.

formatDate

private java.lang.String formatDate(long time)

pixelsOffsetChanged

public boolean pixelsOffsetChanged()

paintAxis

private long paintAxis()
Paints axis.

Parameters:
none. -
Returns:
long current time displayed at the axis bottom.

paintChart

public void paintChart(long now)
Paints the chart.

Parameters:
now - current time.

paint

public void paint(java.awt.Graphics g)
Repaints the component using the backing store.

Overrides:
paint in class java.awt.Component
Parameters:
g - graphics context.

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener