eu.beesoft.gantt.chart
Class ChartComponent

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by eu.beesoft.gantt.chart.ChartComponent
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class ChartComponent
extends javax.swing.JPanel

A ChartComponent is one of the most meaningful sub-components of JGantt.

It is painted on the right side of JGantt (there is an instance of JTreeTable on the left).

It co-ordinates painting with registered instances of the Layer class and dispatches events to them.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
ChartComponent(JGantt ganttComponent)
          Create and initializes a new instance of ChartComponent.
 
Method Summary
 void addLayer(Layer layer)
          Adds given layer to the end of registered layers.
 void addLayer(Layer layer, int index)
          Inserts given layer at the specified index in the registered layers list.
 JGantt getGantt()
          Return instance of JGantt which created this ChartComponent.
 java.util.List<Layer> getLayers()
          Returns list of all registered layers.
 java.awt.Dimension getMinimumSize()
          Returns preferred size of chart component.
protected  java.util.List<GanttNode> getPaintedNodes()
          Returns list of GanttNodes to paint.
protected  int getPosition(java.util.Date date)
          Returns x-coordinate for given date.
 java.awt.Dimension getPreferredSize()
          Returns preferred size of chart component.
 java.awt.Dimension getSize()
          Returns preferred size of chart component.
protected  TimeSpan getTimeSpan(java.util.Date date)
          Returns TimeSpan for given date or null, if no such TimeSpan exists.
 java.util.List<TimeSpan> getTimeSpans()
          Returns list of all TimeSpan instances in this chart.
 TimeUnit getTimeSpanUnit()
          Returns TimeUnit used for TimeSpan instances.
 int getTimeSpanWidth()
          Returns width (in pixels) of TimeSpan instances.
 int getZoomIndex()
          Returns current step (index) in ZoomPolicy.
 ZoomPolicy getZoomPolicy()
          Returns current instance of ZoomPolicy.
protected  void mouseClicked(java.awt.event.MouseEvent e)
          Invoked when the mouse has been clicked on a component.
protected  void mouseDragged(java.awt.event.MouseEvent e)
          Invoked when a mouse button is pressed on a component and then dragged.
protected  void mouseEntered(java.awt.event.MouseEvent e)
          Invoked when the mouse enters a component.
protected  void mouseExited(java.awt.event.MouseEvent e)
          Invoked when the mouse exits a component.
protected  void mouseMoved(java.awt.event.MouseEvent e)
          Invoked when the mouse button has been moved on a component (with no buttons no down).
protected  void mousePressed(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been pressed on a component.
protected  void mouseReleased(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been released on a component.
 void paintComponent(java.awt.Graphics g)
          Paints chart component.
 void removeLayer(Layer layer)
          Removes given layer from the registered layers list.
 void setTimeSpanUnit(TimeUnit timeSpanUnit)
          Sets TimeUnit for use with TimeSpan instances.
 void setZoomIndex(int zoomIndex)
          Sets new value for step (index) in ZoomPolicy.
 void setZoomPolicy(ZoomPolicy zoomPolicy)
          Sets new instance of ZoomPolicy for zooming control.
 void updateChart()
          The key method of ChartComponent, responsible for chart updating.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printComponent, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, checkImage, checkImage, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChartComponent

public ChartComponent(JGantt ganttComponent)
Create and initializes a new instance of ChartComponent.

Parameters:
ganttComponent - - instance of JGantt which creates this ChartComponent
Method Detail

getGantt

public JGantt getGantt()
Return instance of JGantt which created this ChartComponent.

Returns:
instance of JGantt which created this ChartComponent

updateChart

public void updateChart()
The key method of ChartComponent, responsible for chart updating. Checks if something was changed and if so, re-calculates chart painting parameters and repaints chart.


getTimeSpan

protected TimeSpan getTimeSpan(java.util.Date date)
Returns TimeSpan for given date or null, if no such TimeSpan exists.

Returns:
instance of TimeSpan for required Date

getTimeSpans

public java.util.List<TimeSpan> getTimeSpans()
Returns list of all TimeSpan instances in this chart.

Returns:
list of TimeSpan instances

getTimeSpanUnit

public TimeUnit getTimeSpanUnit()
Returns TimeUnit used for TimeSpan instances.

Returns:
TimeUnit of TimeSpan instances

setTimeSpanUnit

public void setTimeSpanUnit(TimeUnit timeSpanUnit)
Sets TimeUnit for use with TimeSpan instances. This TimeUnit should be equal or less than TimeUnit for minor step (see ZoomPolicy).

Parameters:
timeSpanUnit - - a constant of TimeUnit for TimeSpan instances to set

getTimeSpanWidth

public int getTimeSpanWidth()
Returns width (in pixels) of TimeSpan instances. In this implementation simply redirects to the ZoomPolicy method.

Returns:
width (in pixels) of TimeSpan instances

addLayer

public void addLayer(Layer layer)
Adds given layer to the end of registered layers.

Parameters:
layer - - layer to add

addLayer

public void addLayer(Layer layer,
                     int index)
Inserts given layer at the specified index in the registered layers list.

Parameters:
layer - - layer to add
index - - position in layers list where to insert

removeLayer

public void removeLayer(Layer layer)
Removes given layer from the registered layers list.

Parameters:
layer - - layer to remove

getLayers

public java.util.List<Layer> getLayers()
Returns list of all registered layers.

Returns:
list of registered layers

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints chart component.

In the first step it finds all gantt nodes that should be painted (visible on the screen). These nodes can be later obtained via getPaintedNodes() method.

Then it iterates over registered layers and if layer is visible (e.g. method Layer.isVisible() returns true) it calls method Layer.paint(Graphics) on it.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - - the graphics context to use for painting

getPaintedNodes

protected java.util.List<GanttNode> getPaintedNodes()
Returns list of GanttNodes to paint.

Returns:
list of GanttNodes to paint

getPosition

protected int getPosition(java.util.Date date)
Returns x-coordinate for given date. This method obtains the coordinate from an appropriate TimeSpan instance. If no such is found, returns 0.

Returns:
x-coordinate for given date

getSize

public java.awt.Dimension getSize()
Returns preferred size of chart component.

Overrides:
getSize in class java.awt.Component
Returns:
preferred size of chart component

getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns preferred size of chart component.

Overrides:
getMinimumSize in class javax.swing.JComponent
Returns:
preferred size of chart component

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns preferred size of chart component. The preferred size is calculated this way:

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
preferred size of chart component

getZoomPolicy

public ZoomPolicy getZoomPolicy()
Returns current instance of ZoomPolicy.

Returns:
instance of ZoomPolicy

setZoomPolicy

public void setZoomPolicy(ZoomPolicy zoomPolicy)
Sets new instance of ZoomPolicy for zooming control.

Parameters:
zoomPolicy - - instance of ZoomPolicy to set

getZoomIndex

public int getZoomIndex()
Returns current step (index) in ZoomPolicy.

Returns:
current step in ZoomPolicy

setZoomIndex

public void setZoomIndex(int zoomIndex)
Sets new value for step (index) in ZoomPolicy.

Parameters:
zoomIndex - - a new ZoomPolicy step to set

mouseClicked

protected void mouseClicked(java.awt.event.MouseEvent e)
Invoked when the mouse has been clicked on a component. This method invokes method Layer.mouseClicked(MouseEvent) on each visible Layer instance.

Parameters:
e - - mouse event

mouseEntered

protected void mouseEntered(java.awt.event.MouseEvent e)
Invoked when the mouse enters a component. This method invokes method Layer.mouseEntered(MouseEvent) on each visible Layer instance.

Parameters:
e - - mouse event

mouseExited

protected void mouseExited(java.awt.event.MouseEvent e)
Invoked when the mouse exits a component. This method invokes method Layer.mouseExited(MouseEvent) on each visible Layer instance.

Parameters:
e - - mouse event

mousePressed

protected void mousePressed(java.awt.event.MouseEvent e)
Invoked when a mouse button has been pressed on a component. This method invokes method Layer.mousePressed(MouseEvent) on each visible Layer instance.

Parameters:
e - - mouse event

mouseReleased

protected void mouseReleased(java.awt.event.MouseEvent e)
Invoked when a mouse button has been released on a component. This method invokes method Layer.mouseReleased(MouseEvent) on each visible Layer instance.

Parameters:
e - - mouse event

mouseDragged

protected void mouseDragged(java.awt.event.MouseEvent e)
Invoked when a mouse button is pressed on a component and then dragged. This method invokes method Layer.mouseDragged(MouseEvent) on each visible Layer instance.

Parameters:
e - - mouse event

mouseMoved

protected void mouseMoved(java.awt.event.MouseEvent e)
Invoked when the mouse button has been moved on a component (with no buttons no down). This method invokes method Layer.mouseMoved(MouseEvent) on each visible Layer instance.

Parameters:
e - - mouse event