mars.venus
Class NumberDisplayBaseChooser

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.AbstractButton
                          |
                          +--javax.swing.JToggleButton
                                |
                                +--javax.swing.JCheckBox
                                      |
                                      +--mars.venus.NumberDisplayBaseChooser
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, javax.swing.SwingConstants

public class NumberDisplayBaseChooser
extends javax.swing.JCheckBox

Use to select base for displaying numbers. Initially the choices are only 10 (decimal) and 16 (hex), so I'm using a check box where checked means hex. If base 8 (octal) is added later, the Component will need to change.

See Also:
Serialized Form

Field Summary
static int DECIMAL
           
static int HEXADECIMAL
           
 
Fields inherited from class javax.swing.JCheckBox
BORDER_PAINTED_FLAT_CHANGED_PROPERTY
 
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
NumberDisplayBaseChooser(java.lang.String text, boolean displayInHex)
          constructor.
 
Method Summary
static java.lang.String formatNumber(double value, int base)
          Produces a string form of a double given the value and the numerical base to convert it to.
static java.lang.String formatNumber(float value, int base)
          Produces a string form of a float given the value and the numerical base to convert it to.
 java.lang.String formatNumber(int value)
          Produces a string form of a number given the value.
static java.lang.String formatNumber(int value, int base)
          Produces a string form of an integer given the value and the numerical base to convert it to.
 java.lang.String formatUnsignedInteger(int value)
          Produces a string form of an unsigned integer given the value.
static java.lang.String formatUnsignedInteger(int value, int base)
          Produces a string form of an unsigned given the value and the numerical base to convert it to.
 int getBase()
          Retrieve the current number base.
static int getBase(boolean setting)
          Return the number base corresponding to the specified setting.
 void setBase(int newBase)
          Set the current number base.
 void setSettingsMenuItem(javax.swing.JCheckBoxMenuItem setter)
          Set the menu item from Settings menu that corresponds to this chooser.
 
Methods inherited from class javax.swing.JCheckBox
configurePropertiesFromAction, createActionPropertyChangeListener, getAccessibleContext, getUIClassID, isBorderPaintedFlat, paramString, setBorderPaintedFlat, updateUI
 
Methods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
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, 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, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setFont, setForeground, 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, 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, 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, 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

DECIMAL

public static final int DECIMAL
See Also:
Constant Field Values

HEXADECIMAL

public static final int HEXADECIMAL
See Also:
Constant Field Values
Constructor Detail

NumberDisplayBaseChooser

public NumberDisplayBaseChooser(java.lang.String text,
                                boolean displayInHex)
constructor. It assumes the text will be worded so that a checked box means hexidecimal!

Parameters:
text - Text to accompany the check box.
Method Detail

getBase

public int getBase()
Retrieve the current number base.

Returns:
current number base, currently DECIMAL or HEXADECIMAL

setBase

public void setBase(int newBase)
Set the current number base.

Parameters:
newBase - The new number base. Currently, if it is neither DECIMAL nor HEXADECIMAL, the base will not be changed.

formatUnsignedInteger

public static java.lang.String formatUnsignedInteger(int value,
                                                     int base)
Produces a string form of an unsigned given the value and the numerical base to convert it to. This class method can be used by anyone anytime. If base is 16, result is same as for formatNumber(). If base is 10, will produce string version of unsigned value. E.g. 0xffffffff will produce "4294967295" instead of "-1".

Parameters:
value - the number to be converted
base - the numerical base to use (currently 10 or 16)
Returns:
a String equivalent of the value rendered appropriately.

formatNumber

public static java.lang.String formatNumber(int value,
                                            int base)
Produces a string form of an integer given the value and the numerical base to convert it to. There is an instance method that uses the internally stored base. This class method can be used by anyone anytime.

Parameters:
value - the number to be converted
base - the numerical base to use (currently 10 or 16)
Returns:
a String equivalent of the value rendered appropriately.

formatNumber

public static java.lang.String formatNumber(float value,
                                            int base)
Produces a string form of a float given the value and the numerical base to convert it to. There is an instance method that uses the internally stored base. This class method can be used by anyone anytime.

Parameters:
value - the number to be converted
base - the numerical base to use (currently 10 or 16)
Returns:
a String equivalent of the value rendered appropriately.

formatNumber

public static java.lang.String formatNumber(double value,
                                            int base)
Produces a string form of a double given the value and the numerical base to convert it to. There is an instance method that uses the internally stored base. This class method can be used by anyone anytime.

Parameters:
value - the number to be converted
base - the numerical base to use (currently 10 or 16)
Returns:
a String equivalent of the value rendered appropriately.

formatNumber

public java.lang.String formatNumber(int value)
Produces a string form of a number given the value. There is also an class (static method) that uses a specified base.

Parameters:
value - the number to be converted
Returns:
a String equivalent of the value rendered appropriately.

formatUnsignedInteger

public java.lang.String formatUnsignedInteger(int value)
Produces a string form of an unsigned integer given the value. There is also an class (static method) that uses a specified base. If the current base is 16, this produces the same result as formatNumber().

Parameters:
value - the number to be converted
Returns:
a String equivalent of the value rendered appropriately.

setSettingsMenuItem

public void setSettingsMenuItem(javax.swing.JCheckBoxMenuItem setter)
Set the menu item from Settings menu that corresponds to this chooser. It is the responsibility of that item to register here, because this one is created first (before the menu item). They need to communicate with each other so that whenever one changes, so does the other. They cannot be the same object (one is JCheckBox, the other is JCheckBoxMenuItem).


getBase

public static int getBase(boolean setting)
Return the number base corresponding to the specified setting.

Returns:
HEXADECIMAL if setting is true, DECIMAL otherwise.