com.objectwave.uiWidget
Class PieChart

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.objectwave.uiWidget.JGraph
                          |
                          +--com.objectwave.uiWidget.PieChart
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable

public class PieChart
extends JGraph

See Also:
Serialized Form

Field Summary
 int arcX
           
 int arcY
           
 java.awt.Point center
           
 int size
           
 
Fields inherited from class com.objectwave.uiWidget.JGraph
blue, bottom, currColor, focusedItemValue, graphItems, green, itemListeners, left, padding, recalc, red, right, selectedItem, shadeSelection, top
 
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
PieChart()
           
PieChart(java.lang.String title)
           
 
Method Summary
 void addItem(java.lang.Object object, int value, java.awt.Color col)
          Pass an object instead of a name so that it can be accessed later.
 void addItem(java.lang.String name, int value)
           
 void addItem(java.lang.String name, int value, java.awt.Color col)
           
 void clear()
           
protected  void displayLabel(javax.swing.JLabel label, int degrees, int adjustedValue, int size)
           
protected  void displayLabelOld(GraphItem item, int degrees, int adjustedValue, int size, java.awt.Graphics g)
           
protected  int getPieWedgeCount()
          The number of visible pie wedges.
 GraphItem getSelectedItem(java.awt.Point p)
           
protected  int getTotalValue(int count)
           
 boolean isDisplayLabels()
           
 GraphItem itemAtPoint(java.awt.Point p)
           
 void paint(java.awt.Graphics g)
          As in the Graph class, we collect the font metrics for measuring and the current color for resetting.
 GraphItem pieSliceAtPoint(java.awt.Point p)
           
 java.lang.String pieSliceLabelAtPoint(java.awt.Point p)
           
 boolean pointInPie(java.awt.Point p)
           
 double pointToDegrees(java.awt.Point p)
          90 Translate a point to be relative to the pie's | center, then figure it's degrees using the reverse, 180 --+-- 0/360 rotated coordinate system used by Java, as described | on the left.
 void removeItem(java.lang.String name)
           
 void setBounds(int x, int y, int width, int height)
           
 void setBounds(java.awt.Rectangle r)
           
 void setCenter(java.awt.Rectangle r)
           
 void setDisplayLabels(boolean value)
           
 void setLabelPositions()
           
 void setTitle(java.lang.String t)
           
 void setWedgeLimit(int value)
          Limit the number wedges the specified value.
 void setWedgeLimitPercentage(double d)
           
 
Methods inherited from class com.objectwave.uiWidget.JGraph
addItemListener, fireSelectionEvent, getMouseListener, getMouseMotionListener, getPreferredSize, getSelectedItem, getSelectedItemLabel, getSelectedObjects, pickColor, removeItemListener, setDimensions, setSelectedItem, setSelectedItem, setShadeSelection, updateFocusedItemLabel, updateItemLabel
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, 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
 

Field Detail

arcX

public int arcX

arcY

public int arcY

size

public int size

center

public java.awt.Point center
Constructor Detail

PieChart

public PieChart()

PieChart

public PieChart(java.lang.String title)
Method Detail

addItem

public void addItem(java.lang.Object object,
                    int value,
                    java.awt.Color col)
Pass an object instead of a name so that it can be accessed later. the object's name will be object.toString().

Overrides:
addItem in class JGraph

addItem

public void addItem(java.lang.String name,
                    int value)
Overrides:
addItem in class JGraph

addItem

public void addItem(java.lang.String name,
                    int value,
                    java.awt.Color col)
Overrides:
addItem in class JGraph

clear

public void clear()
Overrides:
clear in class JGraph

displayLabel

protected void displayLabel(javax.swing.JLabel label,
                            int degrees,
                            int adjustedValue,
                            int size)

displayLabelOld

protected void displayLabelOld(GraphItem item,
                               int degrees,
                               int adjustedValue,
                               int size,
                               java.awt.Graphics g)

getPieWedgeCount

protected int getPieWedgeCount()
The number of visible pie wedges.


getSelectedItem

public GraphItem getSelectedItem(java.awt.Point p)
Overrides:
getSelectedItem in class JGraph

getTotalValue

protected int getTotalValue(int count)
Returns:
The sum of the first graphItems.

isDisplayLabels

public boolean isDisplayLabels()

itemAtPoint

public GraphItem itemAtPoint(java.awt.Point p)
Specified by:
itemAtPoint in class JGraph

paint

public void paint(java.awt.Graphics g)
As in the Graph class, we collect the font metrics for measuring and the current color for resetting. The graph title is drawn centered at the top. To draw the pie chart, we use the fillArc method of the Graphicsclass. This method draws an arc based on a circle contained within a rectangle. We use the size variable for the width and height of this rectangle. The arcX and arcY variables represent the x and y values of the top-left corner of the rectangle. When we draw the arcs representing the item values, we need only to know a start angle and an arc angle because the size, arcX, and arcY values remain constant. The for loop sifts through all the graphItems in the vector, setting the color, drawing the arc, resetting the color to the original, and drawing the item label. The values of the graphItems are adjusted for the percentage of the whole pie (360 degrees) they represent. This process takes place in the assignment of adjustedValue. The sumTot variable is added in this assignment to give the correct start angle. After filling the arc, we draw the item label. This process requires a little more thought and measurement. We know the center point of the arc circle because we know the size of the rectangle. We also know the formula for finding a point on a circle given an angle, and this gives us enough data to find the point on the circle in the middle of each filled arc.

Overrides:
paint in class JGraph

pieSliceAtPoint

public GraphItem pieSliceAtPoint(java.awt.Point p)

pieSliceLabelAtPoint

public java.lang.String pieSliceLabelAtPoint(java.awt.Point p)

pointInPie

public boolean pointInPie(java.awt.Point p)

pointToDegrees

public double pointToDegrees(java.awt.Point p)
90 Translate a point to be relative to the pie's | center, then figure it's degrees using the reverse, 180 --+-- 0/360 rotated coordinate system used by Java, as described | on the left. 270


removeItem

public void removeItem(java.lang.String name)
Overrides:
removeItem in class JGraph

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Overrides:
setBounds in class JGraph

setBounds

public void setBounds(java.awt.Rectangle r)
Overrides:
setBounds in class JGraph

setCenter

public void setCenter(java.awt.Rectangle r)

setDisplayLabels

public void setDisplayLabels(boolean value)

setLabelPositions

public void setLabelPositions()

setTitle

public void setTitle(java.lang.String t)

setWedgeLimit

public void setWedgeLimit(int value)
Limit the number wedges the specified value.


setWedgeLimitPercentage

public void setWedgeLimitPercentage(double d)