ikayaki.gui
Class MagnetometerStatusPanel

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 ikayaki.gui.MagnetometerStatusPanel
All Implemented Interfaces:
MeasurementListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class MagnetometerStatusPanel
extends JPanel
implements MeasurementListener

Picture of current magnetometer status, with sample holder position and rotation. Status is updated according to MeasurementEvents received by MeasurementControlsPanel. And, manual controls in ManualControlsPanel inner class. Now that I got over myself and painfully merged the two classes.

Author:
Samuli Kaipiainen
See Also:
Serialized Form

Nested Class Summary
private  class MagnetometerStatusPanel.MagnetometerStatusAnimator
          Deprecated. replaced by a simple Timer in constructor
 class MagnetometerStatusPanel.ManualControlsPanel
          Magnetometer manual controls.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  boolean demagnetizing
           
static Color DEMAGNETIZING_COLOR
           
static Color IDLE_COLOR
           
(package private)  MagnetometerStatusPanel.ManualControlsPanel manualControlsPanel
          ManualControlsPanel whose move-radiobuttons to show.
private  int maxposition
           
private  int maxrotation
           
private  boolean measuring
           
static Color MEASURING_COLOR
           
private  TreeMap<Integer,JComponent> moveButtons
          Sorted map for move-radiobuttons' positions.
private  boolean moving
           
static Color MOVING_COLOR
           
private  int posBG
           
private  int posDemagY
           
private  int posDemagZ
           
private  int posHome
           
private  int position
           
private  int posLeft
           
private  int posMeasure
           
private  int posMove
           
private  int posRight
           
private  boolean rotating
           
private  int rotation
           
private  Squid squid
          Squid to read the device's state and command the handler to move and rotateto.
 
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
MagnetometerStatusPanel()
          Sets magnetometer status to current position.
 
Method Summary
private  void drawArrow(Graphics2D g2, int x, int y, int length, int rotation)
          Draws the rotation arrow.
private  void drawFillOval(Graphics2D g2, Color fill, int x, int y, int width, int height)
          Draws a filled oval with line.
private  void drawFillSideRect(Graphics2D g2, Color fill, int x, int y, int width, int height)
          Draws a filled rectangle with lines on left and right side.
 void measurementUpdated(MeasurementEvent e)
          Updates magnetometer status picture; called by MeasurementControlsPanel when it receives MeasurementEvent.
protected  void paintComponent(Graphics g)
          Paints the magnetometer status picture.
 void setSquid(Squid squid)
          Sets our Squid to command; called by MainViewPanel.
private  void updateButtonPositions()
          Updates moveButtons' positions.
private  void updatePositions()
          Reads handler positions from Settings, posLeft and posRight are hard-coded.
 void updateStatus()
          Updates magnetometer status picture.
 
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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getWidth, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, 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, checkImage, checkImage, 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, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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
 

Field Detail

DEMAGNETIZING_COLOR

public static final Color DEMAGNETIZING_COLOR

MEASURING_COLOR

public static final Color MEASURING_COLOR

MOVING_COLOR

public static final Color MOVING_COLOR

IDLE_COLOR

public static final Color IDLE_COLOR

manualControlsPanel

final MagnetometerStatusPanel.ManualControlsPanel manualControlsPanel
ManualControlsPanel whose move-radiobuttons to show.


squid

private Squid squid
Squid to read the device's state and command the handler to move and rotateto. Is null if the current project does not have access to the Squid.


position

private int position

rotation

private int rotation

moving

private boolean moving

rotating

private boolean rotating

demagnetizing

private boolean demagnetizing

measuring

private boolean measuring

maxposition

private int maxposition

maxrotation

private int maxrotation

posMove

private int posMove

posLeft

private int posLeft

posHome

private int posHome

posDemagZ

private int posDemagZ

posDemagY

private int posDemagY

posBG

private int posBG

posMeasure

private int posMeasure

posRight

private int posRight

moveButtons

private TreeMap<Integer,JComponent> moveButtons
Sorted map for move-radiobuttons' positions.

Constructor Detail

MagnetometerStatusPanel

public MagnetometerStatusPanel()
Sets magnetometer status to current position.

Method Detail

setSquid

public void setSquid(Squid squid)
Sets our Squid to command; called by MainViewPanel. Uses the sample handler to read positions and command with move/rotate commands. Degausser and magnetometer are used for displaying their status.


updatePositions

private void updatePositions()
Reads handler positions from Settings, posLeft and posRight are hard-coded. Updates maxposition and position->radiobutton -treemap.


updateButtonPositions

private void updateButtonPositions()
Updates moveButtons' positions. Stacks 'em up nicely so that noone is on top of another or out of screen.


updateStatus

public void updateStatus()
Updates magnetometer status picture. Reads current Squid status from Handler, Magnetometer and Degausser.


measurementUpdated

public void measurementUpdated(MeasurementEvent e)
Updates magnetometer status picture; called by MeasurementControlsPanel when it receives MeasurementEvent.

Specified by:
measurementUpdated in interface MeasurementListener
Parameters:
e - the event that happened.

paintComponent

protected void paintComponent(Graphics g)
Paints the magnetometer status picture.

Overrides:
paintComponent in class JComponent
Parameters:
g - mursu.

drawFillOval

private void drawFillOval(Graphics2D g2,
                          Color fill,
                          int x,
                          int y,
                          int width,
                          int height)
Draws a filled oval with line.


drawFillSideRect

private void drawFillSideRect(Graphics2D g2,
                              Color fill,
                              int x,
                              int y,
                              int width,
                              int height)
Draws a filled rectangle with lines on left and right side.


drawArrow

private void drawArrow(Graphics2D g2,
                       int x,
                       int y,
                       int length,
                       int rotation)
Draws the rotation arrow.

Parameters:
g2 - marsu.
x - x-center.
y - y-center.
length - arrow length; arrow pointing lines' length will be length/4.
rotation - rotation angle as 0..maxrotation (meaning 0..360 degrees).