ButtonColumn controlsColumn = new ButtonColumn();
controlsColumn.setStyleName("TestControlsColumn");
add(controlsColumn);
final Row testRow = new Row();
testRow.setBorder(new Border(new Extent(1), Color.BLUE, Border.STYLE_SOLID));
testRow.setLayoutData(insetLayoutData);
add(testRow);
controlsColumn.addButton("Add Item (at beginning)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.add(new Label("Added item [" + nextValue++ + "]"), 0);
}
});
controlsColumn.addButton("Add Item (at end)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.add(new Label("Added item [" + nextValue++ + "]"));
}
});
controlsColumn.addButton("Add-Remove-Add Item (at end)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Label label = new Label("Added item [" + nextValue++ + "]");
testRow.add(label);
testRow.remove(label);
testRow.add(label);
}
});
controlsColumn.addButton("Remove Last Item", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (testRow.getComponentCount() > 0) {
testRow.remove(testRow.getComponentCount() - 1);
}
}
});
controlsColumn.addButton("Add Some Items, Remove Some Items", new ActionListener() {
public void actionPerformed(ActionEvent e) {
int count = 1 + ((int) (Math.random() * 10));
for (int i = 0; i < count; ++i) {
int componentCount = testRow.getComponentCount();
if (componentCount > 0 && ((int) (Math.random() * 2)) == 0) {
// Perform remove.
int position = (int) (Math.random() * componentCount);
testRow.remove(position);
} else {
// Perform add.
int position = (int) (Math.random() * (componentCount + 1));
testRow.add(new Label("Added item [" + nextValue++ + "]"), position);
}
}
}
});
controlsColumn.addButton("Randomly Remove and Re-insert Item", new ActionListener() {
public void actionPerformed(ActionEvent e) {
int itemCount = testRow.getComponentCount();
if (itemCount == 0) {
return;
}
Component item = testRow.getComponent((int) (Math.random() * itemCount));
testRow.remove(item);
testRow.add(item, (int) (Math.random() * (itemCount - 1)));
}
});
controlsColumn.addButton("Set Foreground", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setForeground(StyleUtil.randomColor());
}
});
controlsColumn.addButton("Clear Foreground", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setForeground(null);
}
});
controlsColumn.addButton("Set Background", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setBackground(StyleUtil.randomColor());
}
});
controlsColumn.addButton("Clear Background", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setBackground(null);
}
});
controlsColumn.addButton("Set Border (All Attributes)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setBorder(StyleUtil.randomBorder());
}
});
controlsColumn.addButton("Set Border Color", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Border border = testRow.getBorder();
if (border == null) {
border = new Border(new Extent(1), Color.BLUE, Border.STYLE_SOLID);
}
testRow.setBorder(new Border(border.getSize(), StyleUtil.randomColor(), border.getStyle()));
}
});
controlsColumn.addButton("Set Border Size", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setBorder(StyleUtil.nextBorderSize(testRow.getBorder()));
}
});
controlsColumn.addButton("Set Border Style", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setBorder(StyleUtil.nextBorderStyle(testRow.getBorder()));
}
});
controlsColumn.addButton("Remove Border", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setBorder(null);
}
});
controlsColumn.addButton("Cell Spacing -> 0px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setCellSpacing(new Extent(0, Extent.PX));
}
});
controlsColumn.addButton("Cell Spacing -> 2px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setCellSpacing(new Extent(2, Extent.PX));
}
});
controlsColumn.addButton("Cell Spacing -> 20px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setCellSpacing(new Extent(20, Extent.PX));
}
});
controlsColumn.addButton("Insets -> null", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setInsets(null);
}
});
controlsColumn.addButton("Insets -> 0px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setInsets(new Insets(0));
}
});
controlsColumn.addButton("Insets -> 5px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setInsets(new Insets(5));
}
});
controlsColumn.addButton("Insets -> 10/20/30/40px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.setInsets(new Insets(10, 20, 30, 40));
}
});
controlsColumn.addButton("Alignment -> Leading", new ActionListener(){
public void actionPerformed(ActionEvent e) {
testRow.setAlignment(new Alignment(Alignment.LEADING, Alignment.DEFAULT));
}
});
controlsColumn.addButton("Alignment -> Trailing", new ActionListener(){
public void actionPerformed(ActionEvent e) {
testRow.setAlignment(new Alignment(Alignment.TRAILING, Alignment.DEFAULT));
}
});
controlsColumn.addButton("Alignment -> Left", new ActionListener(){
public void actionPerformed(ActionEvent e) {
testRow.setAlignment(new Alignment(Alignment.LEFT, Alignment.DEFAULT));
}
});
controlsColumn.addButton("Alignment -> Center", new ActionListener(){
public void actionPerformed(ActionEvent e) {
testRow.setAlignment(new Alignment(Alignment.CENTER, Alignment.DEFAULT));
}
});
controlsColumn.addButton("Alignment -> Right", new ActionListener(){
public void actionPerformed(ActionEvent e) {
testRow.setAlignment(new Alignment(Alignment.RIGHT, Alignment.DEFAULT));
}
});
controlsColumn.addButton("Alignment -> Default", new ActionListener(){
public void actionPerformed(ActionEvent e) {
testRow.setAlignment(new Alignment(Alignment.DEFAULT, Alignment.DEFAULT));
}
});
controlsColumn.addButton("Clear All LayoutData", new ActionListener() {
public void actionPerformed(ActionEvent e) {
int componentCount = testRow.getComponentCount();
for (int i = 0; i < componentCount; ++i) {
testRow.getComponent(i).setLayoutData(null);
}
}
});
controlsColumn.addButton("Set Layout Data of All Items to 100%/count Width", new ActionListener() {
public void actionPerformed(ActionEvent e) {
int componentCount = testRow.getComponentCount();
for (int i = 0; i < componentCount; ++i) {
RowLayoutData rowLayoutData = new RowLayoutData();
rowLayoutData.setWidth(new Extent(100 / componentCount, Extent.PERCENT));
rowLayoutData.setBackground(StyleUtil.randomBrightColor());
testRow.getComponent(i).setLayoutData(rowLayoutData);
}
}
});
controlsColumn.addButton("Set Layout Data (of random item)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
int componentCount = testRow.getComponentCount();
if (componentCount == 0) {
return;
}
Component component = testRow.getComponent((int) (Math.random() * componentCount));
RowLayoutData rowLayoutData = new RowLayoutData();
rowLayoutData.setAlignment(StyleUtil.randomAlignmentHV());
rowLayoutData.setBackground(StyleUtil.randomBrightColor());
rowLayoutData.setInsets(new Insets((int) (Math.random() * 30)));
switch((int) (Math.random() * 7)) {
case 0:
rowLayoutData.setBackgroundImage(Styles.BG_SHADOW_DARK_BLUE);
break;
case 1:
rowLayoutData.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
break;
default:
rowLayoutData.setBackgroundImage(null);
}
component.setLayoutData(rowLayoutData);
}
});
controlsColumn.addButton("Add Item, Randomize Column Insets", new ActionListener() {
public void actionPerformed(ActionEvent e) {
testRow.add(new Label("Added item [" + nextValue++ + "]"));
testRow.setInsets(new Insets((int) (Math.random() * 50)));
}
});
controlsColumn.addButton("Toggle Test Inset", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (testRow.getLayoutData() == null) {
testRow.setLayoutData(insetLayoutData);
} else {
testRow.setLayoutData(null);
}
}
});
}