debuglevel="lines,vars,source"
target="1.6"
source="1.6"
- />
+ >
+ <compilerarg value="-Xlint:deprecation" />
+ </javac>
</target>
<target name="jar" depends="compile">
// ------------------------------------------------------------------------
/**
- * RadioButton state, true means selected.
+ * RadioButton state, true means selected. Note package private access.
*/
- private boolean selected = false;
+ boolean selected = false;
/**
* The shortcut and radio button label.
/**
* ID for this radio button. Buttons start counting at 1 in the
- * RadioGroup.
+ * RadioGroup. Note package private access.
*/
- private int id;
+ int id;
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
// ------------------------------------------------------------------------
/**
- * Public constructor.
+ * Package private constructor.
*
* @param parent parent widget
* @param x column relative to parent
* @param label label to display next to (right of) the radiobutton
* @param id ID for this radio button
*/
- public TRadioButton(final TRadioGroup parent, final int x, final int y,
+ TRadioButton(final TRadioGroup parent, final int x, final int y,
final String label, final int id) {
// Set parent and window
setCursorVisible(true);
setCursorX(1);
+
+ parent.addRadioButton(this);
}
// ------------------------------------------------------------------------
public void onMouseDown(final TMouseEvent mouse) {
if ((mouseOnRadioButton(mouse)) && (mouse.isMouse1())) {
// Switch state
- selected = true;
- ((TRadioGroup) getParent()).setSelected(this);
+ ((TRadioGroup) getParent()).setSelected(id);
}
}
public void onKeypress(final TKeypressEvent keypress) {
if (keypress.equals(kbSpace)) {
- selected = true;
- ((TRadioGroup) getParent()).setSelected(this);
+ ((TRadioGroup) getParent()).setSelected(id);
return;
}
}
/**
- * Set RadioButton state, true means selected. Note package private
- * access.
+ * Set RadioButton state, true means selected.
*
* @param selected if true then this is the one button in the group that
* is selected
*/
- void setSelected(final boolean selected) {
- this.selected = selected;
+ public void setSelected(final boolean selected) {
+ if (selected == true) {
+ ((TRadioGroup) getParent()).setSelected(id);
+ } else {
+ ((TRadioGroup) getParent()).setSelected(0);
+ }
}
/**
* If true, one of the children MUST be selected. Note package private
* access.
*/
- boolean requiresSelection = true;
+ boolean requiresSelection = false;
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
return selectedButton.getId();
}
- /**
- * Set the new selected radio button. Note package private access.
- *
- * @param button new button that became selected
- */
- void setSelected(final TRadioButton button) {
- assert (button.isSelected());
- if ((selectedButton != null) && (selectedButton != button)) {
- selectedButton.setSelected(false);
- }
- selectedButton = button;
- }
-
/**
* Set the new selected radio button. 1-based.
*
return;
}
+ for (TWidget widget: getChildren()) {
+ ((TRadioButton) widget).selected = false;
+ }
if (id == 0) {
- for (TWidget widget: getChildren()) {
- ((TRadioButton) widget).setSelected(false);
- }
selectedButton = null;
return;
}
assert ((id > 0) && (id <= getChildren().size()));
TRadioButton button = (TRadioButton) (getChildren().get(id - 1));
- button.setSelected(true);
+ button.selected = true;
selectedButton = button;
}
+ /**
+ * Get the radio button that was selected.
+ *
+ * @return the selected button, or null if no button is selected
+ */
+ public TRadioButton getSelectedButton() {
+ return selectedButton;
+ }
+
+ /**
+ * Convenience function to add a radio button to this group.
+ *
+ * @param label label to display next to (right of) the radiobutton
+ * @param selected if true, this will be the selected radiobutton
+ * @return the new radio button
+ */
+ public TRadioButton addRadioButton(final String label,
+ final boolean selected) {
+
+ TRadioButton button = addRadioButton(label);
+ setSelected(button.id);
+ return button;
+ }
+
/**
* Convenience function to add a radio button to this group.
*
* @return the new radio button
*/
public TRadioButton addRadioButton(final String label) {
- int buttonX = 1;
- int buttonY = getChildren().size() + 1;
+ return new TRadioButton(this, 0, 0, label, 0);
+ }
+
+ /**
+ * Package private method for RadioButton to add itself to a RadioGroup
+ * container.
+ *
+ * @param button the button to add
+ */
+ void addRadioButton(final TRadioButton button) {
+ super.setHeight(getChildren().size() + 2);
+ button.setX(1);
+ button.setY(getChildren().size());
+ button.id = getChildren().size();
+ String label = button.getMnemonic().getRawLabel();
+
if (StringUtils.width(label) + 4 > getWidth()) {
super.setWidth(StringUtils.width(label) + 7);
}
- super.setHeight(getChildren().size() + 3);
- TRadioButton button = new TRadioButton(this, buttonX, buttonY, label,
- getChildren().size() + 1);
if (getParent().getLayoutManager() != null) {
getParent().getLayoutManager().resetSize(this);
// Default to the first item on the list.
activate(getChildren().get(0));
+ }
- return button;
+ /**
+ * Get the requires selection flag.
+ *
+ * @return true if this radiogroup requires that one of the buttons be
+ * selected
+ */
+ public boolean getRequiresSelection() {
+ return requiresSelection;
+ }
+
+ /**
+ * Set the requires selection flag.
+ *
+ * @param requiresSelection if true, then this radiogroup requires that
+ * one of the buttons be selected
+ */
+ public void setRequiresSelection(final boolean requiresSelection) {
+ this.requiresSelection = requiresSelection;
+ if (requiresSelection) {
+ if (getChildren().size() > 0) {
+ setSelected(1);
+ }
+ }
}
}
TRadioGroup group = addRadioGroup(1, row,
i18n.getString("radioGroupTitle"));
group.addRadioButton(i18n.getString("radioOption1"));
- group.addRadioButton(i18n.getString("radioOption2"));
+ group.addRadioButton(i18n.getString("radioOption2"), true);
group.addRadioButton(i18n.getString("radioOption3"));
List<String> comboValues = new ArrayList<String>();
// If at the beginning of a word already, push past it.
if ((getChar() != -1)
&& (getRawLine().length() > 0)
- && !Character.isSpace((char) getChar())
+ && !Character.isWhitespace((char) getChar())
) {
left();
}
// int line = lineNumber;
while ((getChar() == -1)
|| (getRawLine().length() == 0)
- || Character.isSpace((char) getChar())
+ || Character.isWhitespace((char) getChar())
) {
if (left() == false) {
return;
assert (getChar() != -1);
- if (!Character.isSpace((char) getChar())
+ if (!Character.isWhitespace((char) getChar())
&& (getRawLine().length() > 0)
) {
// Advance until at the beginning of the document or a whitespace
// is encountered.
- while (!Character.isSpace((char) getChar())) {
+ while (!Character.isWhitespace((char) getChar())) {
int line = lineNumber;
if (left() == false) {
// End of document, bail out.
}
if (lineNumber != line) {
// We wrapped a line. Here that counts as whitespace.
- if (!Character.isSpace((char) getChar())) {
+ if (!Character.isWhitespace((char) getChar())) {
// We found a character immediately after the line.
// Done!
return;
}
assert (getChar() != -1);
- if (!Character.isSpace((char) getChar())
+ if (!Character.isWhitespace((char) getChar())
&& (getRawLine().length() > 0)
) {
// Advance until at the end of the document or a whitespace is
// encountered.
- while (!Character.isSpace((char) getChar())) {
+ while (!Character.isWhitespace((char) getChar())) {
line = lineNumber;
if (right() == false) {
// End of document, bail out.
}
if (lineNumber != line) {
// We wrapped a line. Here that counts as whitespace.
- if (!Character.isSpace((char) getChar())
+ if (!Character.isWhitespace((char) getChar())
&& (getRawLine().length() > 0)
) {
// We found a character immediately after the line.
}
if (lineNumber != line) {
// We wrapped a line. Here that counts as whitespace.
- if (!Character.isSpace((char) getChar())) {
+ if (!Character.isWhitespace((char) getChar())) {
// We found a character immediately after the line.
// Done!
return;
}
assert (getChar() != -1);
- if (Character.isSpace((char) getChar())) {
+ if (Character.isWhitespace((char) getChar())) {
// Advance until at the end of the document or a non-whitespace
// is encountered.
- while (Character.isSpace((char) getChar())) {
+ while (Character.isWhitespace((char) getChar())) {
if (right() == false) {
// End of document, bail out.
return;