use of javax.swing.ButtonModel in project vcell by virtualcell.
the class CartoonTool method updateButtonGroup.
public final void updateButtonGroup(ButtonGroup buttonGroup, String actionCommand) {
if (buttonGroup == null) {
return;
}
// if selected button does not have this action command, select the
// first button we find with appropriate action command
String currSelectedString = (buttonGroup.getSelection() != null ? buttonGroup.getSelection().getActionCommand() : null);
if (currSelectedString != null) {
if (currSelectedString.equals(actionCommand)) {
return;
}
}
Enumeration<AbstractButton> buttons = buttonGroup.getElements();
while (buttons.hasMoreElements()) {
ButtonModel button = buttons.nextElement().getModel();
if (button.getActionCommand().equals(actionCommand)) {
button.setSelected(true);
return;
}
}
System.out.println("ERROR: button with actionCommand " + actionCommand + " not found");
return;
}
use of javax.swing.ButtonModel in project aerospike-client-java by aerospike.
the class GuiDisplay method run_selected_examples.
/**
* Run the user selected examples
*/
private void run_selected_examples() {
ButtonModel selected = buttonGroup.getSelection();
if (selected == null) {
console.error("Please select an example and then press Run");
return;
}
try {
String example = selected.getActionCommand();
final String[] examples = new String[1];
examples[0] = example;
params.host = seedHostTextField.getText().trim();
params.port = Integer.parseInt(portTextField.getText().trim());
params.user = usernameTextField.getText().trim();
params.password = new String(passwordTextField.getPassword()).trim();
params.namespace = namespaceTextField.getText().trim();
params.set = txtSetTextfield.getText().trim();
new Thread() {
public void run() {
try {
Main.runExamples(console, params, examples);
} catch (Exception ex) {
console.error(ex.toString());
}
}
}.start();
} catch (Exception ex) {
console.error(ex.toString());
}
}
use of javax.swing.ButtonModel in project airavata by apache.
the class BasicLinkButtonUI method paintText.
protected void paintText(Graphics g, JComponent com, Rectangle rect, String s) {
XBayaLinkButton bn = (XBayaLinkButton) com;
ButtonModel bnModel = bn.getModel();
if (bnModel.isEnabled()) {
if (bnModel.isPressed())
bn.setForeground(bn.getActiveLinkColor());
else if (bn.isLinkVisited())
bn.setForeground(bn.getVisitedLinkColor());
else
bn.setForeground(bn.getLinkColor());
} else {
if (bn.getDisabledLinkColor() != null)
bn.setForeground(bn.getDisabledLinkColor());
}
super.paintText(g, com, rect, s);
int behaviour = bn.getLinkBehavior();
boolean drawLine = false;
if (behaviour == XBayaLinkButton.HOVER_UNDERLINE) {
if (bnModel.isRollover())
drawLine = true;
} else if (behaviour == XBayaLinkButton.ALWAYS_UNDERLINE || behaviour == XBayaLinkButton.SYSTEM_DEFAULT)
drawLine = true;
if (!drawLine)
return;
FontMetrics fm = g.getFontMetrics();
int x = rect.x + getTextShiftOffset();
int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1;
if (bnModel.isEnabled()) {
g.setColor(bn.getForeground());
g.drawLine(x, y, (x + rect.width) - 1, y);
} else {
g.setColor(bn.getBackground().brighter());
g.drawLine(x, y, (x + rect.width) - 1, y);
}
}
use of javax.swing.ButtonModel in project mudmap2 by Neop.
the class EditWorldDialog method save.
/**
* Saves the changes
*/
private void save() throws Exception {
String name = textfield_name.getText();
// if textfield is not empty
if (!name.isEmpty()) {
world.setName(name);
}
// modify risk levels
for (Map.Entry<RiskLevel, Pair<JTextField, ColorChooserButton>> rl_color : risklevel_colors.entrySet()) {
String description = rl_color.getValue().first.getText();
if (description.isEmpty())
world.removeRiskLevel(rl_color.getKey());
else {
rl_color.getKey().setDescription(description);
rl_color.getKey().setColor(rl_color.getValue().second.getColor());
}
}
world.setTileCenterColor(tile_center_color.getColor());
// add new risk level, if name not empty
String name_new = risklevel_new_name.getText();
if (!name_new.isEmpty()) {
world.addRiskLevel(new RiskLevel(name_new, risklevel_new_color.getColor()));
}
ButtonModel selection = buttongroup_place_id.getSelection();
if (selection == radiobutton_place_id_none.getModel())
world.setShowPlaceID(World.ShowPlaceID.NONE);
else if (selection == radiobutton_place_id_all.getModel())
world.setShowPlaceID(World.ShowPlaceID.ALL);
else
world.setShowPlaceID(World.ShowPlaceID.UNIQUE);
getParent().repaint();
}
use of javax.swing.ButtonModel in project ChatGameFontificator by GlitchCog.
the class CharacterPicker method build.
private void build() {
setLayout(new GridLayout(12, 8));
setTitle("Character Picker");
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JToggleButton tb = (JToggleButton) e.getSource();
setSelectedChar(tb.getText().charAt(0));
setVisible(false);
}
};
buttonGroup = new ButtonGroup() {
private static final long serialVersionUID = 1L;
@Override
public void setSelected(ButtonModel model, boolean selected) {
if (selected) {
super.setSelected(model, selected);
} else {
clearSelection();
}
}
};
charButtons = new JToggleButton[96];
for (int i = 0; i < charButtons.length; i++) {
charButtons[i] = new JToggleButton(Character.toString((char) (i + 32)));
charButtons[i].addActionListener(al);
buttonGroup.add(charButtons[i]);
add(charButtons[i]);
}
pack();
setResizable(false);
}
Aggregations