package mars.venus; import mars.*; import mars.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; /* Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar Developed by Pete Sanderson (psanderson@otterbein.edu) and Kenneth Vollmar (kenvollmar@missouristate.edu) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (MIT license, http://www.opensource.org/licenses/mit-license.html) */ /** * 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. */ public class NumberDisplayBaseChooser extends JCheckBox { public static final int DECIMAL = 10; public static final int HEXADECIMAL = 16; public static final int ASCII = 0; private int base; private JCheckBoxMenuItem settingMenuItem; /** * constructor. It assumes the text will be worded * so that a checked box means hexadecimal! * @param text Text to accompany the check box. * @param defaultBase Currently either DECIMAL or HEXADECIMAL */ public NumberDisplayBaseChooser(String text, boolean displayInHex) { super(text, displayInHex); base = getBase(displayInHex); addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ie) { NumberDisplayBaseChooser choose = (NumberDisplayBaseChooser)ie.getItem(); if (ie.getStateChange() == ItemEvent.SELECTED) { choose.setBase(NumberDisplayBaseChooser.HEXADECIMAL); } else { choose.setBase(NumberDisplayBaseChooser.DECIMAL); } // Better to use notify, but I am tired... if (settingMenuItem!=null) { settingMenuItem.setSelected(choose.isSelected()); ActionListener[] listeners = settingMenuItem.getActionListeners(); ActionEvent event = new ActionEvent(settingMenuItem, 0, "chooser"); for (int i=0; i