grid.add(selectField2);
listBox2 = new ListBox(NUMBERS);
grid.add(listBox2);
controlsColumn.add(new Label("Global"));
controlsColumn.addButton("Add ActionListener", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.addActionListener(actionListener);
}
});
}
});
controlsColumn.addButton("Remove ActionListener", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.removeActionListener(actionListener);
}
});
}
});
controlsColumn.addButton("Add ChangeListener", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.getSelectionModel().addChangeListener(changeListener);
}
});
}
});
controlsColumn.addButton("Remove ChangeListener", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.getSelectionModel().removeChangeListener(changeListener);
}
});
}
});
controlsColumn.addButton("Add ListDataListener", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.getModel().addListDataListener(listDataListener);
}
});
}
});
controlsColumn.addButton("Remove ListDataListener", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.getModel().removeListDataListener(listDataListener);
}
});
}
});
controlsColumn.addButton("Toggle Enabled State", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setEnabled(!listComponent.isEnabled());
}
});
}
});
controlsColumn.addButton("Set ListCellRenderer", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setCellRenderer(evenOddListCellRenderer);
}
});
}
});
controlsColumn.addButton("Clear ListCellRenderer", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setCellRenderer(AbstractListComponent.DEFAULT_LIST_CELL_RENDERER);
}
});
}
});
controlsColumn.addButton("Set Border", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Border border = StyleUtil.randomBorder();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setBorder(border);
}
});
}
});
controlsColumn.addButton("Clear Border", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setBorder(null);
}
});
}
});
controlsColumn.addButton("Set Foreground", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Color color = StyleUtil.randomColor();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setForeground(color);
}
});
}
});
controlsColumn.addButton("Set Background", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Color color = StyleUtil.randomColor();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setBackground(color);
}
});
}
});
controlsColumn.addButton("Set Font", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Font font = StyleUtil.randomFont();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setFont(font);
}
});
}
});
controlsColumn.addButton("Clear Font", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setFont(null);
}
});
}
});
controlsColumn.addButton("Set Disabled Border", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Border border = StyleUtil.randomBorder();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setDisabledBorder(border);
}
});
}
});
controlsColumn.addButton("Clear Disabled Border", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setDisabledBorder(null);
}
});
}
});
controlsColumn.addButton("Set Disabled Foreground", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Color color = StyleUtil.randomColor();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setDisabledForeground(color);
}
});
}
});
controlsColumn.addButton("Set Disabled Background", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Color color = StyleUtil.randomColor();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setDisabledBackground(color);
}
});
}
});
controlsColumn.addButton("Set Disabled Font", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Font font = StyleUtil.randomFont();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setDisabledFont(font);
}
});
}
});
controlsColumn.addButton("Clear Disabled Font", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setDisabledFont(null);
}
});
}
});
controlsColumn.addButton("Toggle ToolTip Text", new ActionListener(){
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
if (listComponent.getToolTipText() == null) {
listComponent.setToolTipText("This is a tool tip.");
} else {
listComponent.setToolTipText(null);
}
}
});
}
});
controlsColumn.addButton("Enable Rollover Effects", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setRolloverEnabled(true);
}
});
}
});
controlsColumn.addButton("Disable Rollover Effects", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setRolloverEnabled(false);
}
});
}
});
controlsColumn.addButton("Set Rollover Foreground", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Color color = StyleUtil.randomColor();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setRolloverForeground(color);
}
});
}
});
controlsColumn.addButton("Set Rollover Background", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Color color = StyleUtil.randomColor();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setRolloverBackground(color);
}
});
}
});
controlsColumn.addButton("Set Rollover Font", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Font font = StyleUtil.randomFont();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setRolloverFont(font);
}
});
}
});
controlsColumn.addButton("Increase Width (15 px)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Extent width = listBox1.getWidth() == null ? new Extent(75) : listBox1.getWidth();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setWidth(Extent.add(width, new Extent(15)));
}
});
}
});
controlsColumn.addButton("Decrease Width (15 px)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Extent width = listBox1.getWidth() == null ? new Extent(75) : listBox1.getWidth();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setWidth(Extent.add(width, new Extent(-15)));
}
});
}
});
controlsColumn.addButton("Increase Height (15 px)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Extent height = listBox1.getHeight() == null ? new Extent(75) : listBox1.getHeight();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setHeight(Extent.add(height, new Extent(15)));
}
});
}
});
controlsColumn.addButton("Decrease Height (15 px)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Extent height = listBox1.getHeight() == null ? new Extent(75) : listBox1.getHeight();
apply(new Applicator() {
public void apply(AbstractListComponent listComponent) {
listComponent.setHeight(Extent.add(height, new Extent(-15)));
}
});
}
});
controlsColumn.addButton("Select Index 0", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator(){
public void apply(AbstractListComponent listComponent) {
if (listComponent instanceof ListBox) {
((ListBox) listComponent).setSelectedIndices(new int[] {0});
} else if (listComponent instanceof SelectField) {
((SelectField) listComponent).setSelectedIndex(0);
}
}
});
}
});
controlsColumn.addButton("Select Index 2", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator(){
public void apply(AbstractListComponent listComponent) {
if (listComponent instanceof ListBox) {
((ListBox) listComponent).setSelectedIndices(new int[] {2});
} else if (listComponent instanceof SelectField) {
((SelectField) listComponent).setSelectedIndex(2);
}
}
});
}
});
controlsColumn.addButton("Select Index 1502", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator(){
public void apply(AbstractListComponent listComponent) {
if (listComponent instanceof ListBox) {
((ListBox) listComponent).setSelectedIndices(new int[] {1502});
} else if (listComponent instanceof SelectField) {
((SelectField) listComponent).setSelectedIndex(1502);
}
}
});
}
});
controlsColumn.addButton("Clear Selections", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator(){
public void apply(AbstractListComponent listComponent) {
if (listComponent instanceof ListBox) {
((ListBox) listComponent).setSelectedIndices(new int[] {});
} else if (listComponent instanceof SelectField) {
((SelectField) listComponent).setSelectedIndex(-1);
}
}
});
}
});
controlsColumn.addButton("Empty ListModel", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator(){
public void apply(AbstractListComponent listComponent) {
listComponent.setModel(new DefaultListModel());
}
});
}
});
controlsColumn.addButton("Set ListModel = Numbers", new ActionListener() {
public void actionPerformed(ActionEvent e) {
apply(new Applicator(){
public void apply(AbstractListComponent listComponent) {
listComponent.setModel(new DefaultListModel(NUMBERS));
}
});
}
});
controlsColumn.addButton("Focus SelectField1", new ActionListener() {
public void actionPerformed(ActionEvent e) {
getApplicationInstance().setFocusedComponent(selectField1);
}
});
controlsColumn.addButton("Focus SelectField2", new ActionListener() {
public void actionPerformed(ActionEvent e) {
getApplicationInstance().setFocusedComponent(selectField2);
}
});
controlsColumn.add(new Label("ListBox-specific"));
controlsColumn.addButton("Toggle Multiple Select", new ActionListener() {
public void actionPerformed(ActionEvent e) {
final int mode = ListSelectionModel.MULTIPLE_SELECTION == listBox1.getSelectionMode()
? ListSelectionModel.SINGLE_SELECTION : ListSelectionModel.MULTIPLE_SELECTION;