Package 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:
ImageObserver
,ItemSelectable
,MenuContainer
,Serializable
,Accessible
,SwingConstants
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JCheckBox
JCheckBox.AccessibleJCheckBox
Nested classes/interfaces inherited from class javax.swing.JToggleButton
JToggleButton.AccessibleJToggleButton, JToggleButton.ToggleButtonModel
Nested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
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
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
accessibleContext, 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
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatDoubleNumber
(long value, int base) Produces a string form of a double given a long containing the 64 bit pattern and the numerical base to use (10 or 16).static String
formatFloatNumber
(int value, int base) Produces a string form of a float given an integer containing the 32 bit pattern and the numerical base to use (10 or 16).static 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 String
formatNumber
(float value, int base) Produces a string form of a float given the value and the numerical base to convert it to.formatNumber
(int value) Produces a string form of a number given the value.static String
formatNumber
(int value, int base) Produces a string form of an integer given the value and the numerical base to convert it to.formatUnsignedInteger
(int value) Produces a string form of an unsigned integer given the value.static 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
(JCheckBoxMenuItem setter) Set the menu item from Settings menu that corresponds to this chooser.Methods inherited from class javax.swing.JCheckBox
getAccessibleContext, getUIClassID, isBorderPaintedFlat, paramString, setBorderPaintedFlat, updateUI
Methods inherited from class javax.swing.JToggleButton
requestFocus, requestFocusInWindow
Methods inherited from class javax.swing.AbstractButton
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, 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, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
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, getBaseline, getBaselineResizeBehavior, 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, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
DECIMAL
public static final int DECIMAL- See Also:
-
HEXADECIMAL
public static final int HEXADECIMAL- See Also:
-
ASCII
public static final int ASCII- See Also:
-
-
Constructor Details
-
NumberDisplayBaseChooser
Constructor. It assumes the text will be worded so that a checked box means hexadecimal!- Parameters:
text
- Text to accompany the check box.displayInHex
- Whether to display in hexadecimal or decimal.
-
-
Method Details
-
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
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 convertedbase
- the numerical base to use (currently 10 or 16)- Returns:
- a String equivalent of the value rendered appropriately.
-
formatNumber
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 convertedbase
- the numerical base to use (currently 10 or 16)- Returns:
- a String equivalent of the value rendered appropriately.
-
formatNumber
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 convertedbase
- the numerical base to use (currently 10 or 16)- Returns:
- a String equivalent of the value rendered appropriately.
-
formatNumber
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 convertedbase
- the numerical base to use (currently 10 or 16)- Returns:
- a String equivalent of the value rendered appropriately.
-
formatNumber
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
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.
-
formatFloatNumber
Produces a string form of a float given an integer containing the 32 bit pattern and the numerical base to use (10 or 16). If the base is 16, the string will be built from the 32 bits. If the base is 10, the int bits will be converted to float and the string constructed from that. Seems an odd distinction to make, except that contents of floating point registers are stored internally as int bits. If the int bits represent a NaN value (of which there are many!), converting them to float then calling formatNumber(float, int) above, causes the float value to become the canonical NaN value 0x7fc00000. It does not preserve the bit pattern! Then converting it to hex string yields the canonical NaN. Not an issue if display base is 10 since result string will be NaN no matter what the internal NaN value is.- Parameters:
value
- the int bits to be converted to string of corresponding float.base
- the numerical base to use (currently 10 or 16)- Returns:
- a String equivalent of the value rendered appropriately.
-
formatDoubleNumber
Produces a string form of a double given a long containing the 64 bit pattern and the numerical base to use (10 or 16). If the base is 16, the string will be built from the 64 bits. If the base is 10, the long bits will be converted to double and the string constructed from that. Seems an odd distinction to make, except that contents of floating point registers are stored internally as int bits. If the int bits represent a NaN value (of which there are many!), converting them to double then calling formatNumber(double, int) above, causes the double value to become the canonical NaN value. It does not preserve the bit pattern! Then converting it to hex string yields the canonical NaN. Not an issue if display base is 10 since result string will be NaN no matter what the internal NaN value is.- Parameters:
value
- the long bits to be converted to string of corresponding double.base
- the numerical base to use (currently 10 or 16)- Returns:
- a String equivalent of the value rendered appropriately.
-
setSettingsMenuItem
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.
-