public GridTest() {
super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX));
setStyleName("DefaultResizable");
Column groupContainerColumn = new Column();
groupContainerColumn.setCellSpacing(new Extent(5));
groupContainerColumn.setStyleName("TestControlsColumn");
add(groupContainerColumn);
Column testColumn = new Column();
add(testColumn);
ButtonColumn controlsColumn;
controlsColumn = new ButtonColumn();
controlsColumn.add(new Label("Insert/Delete Cells"));
groupContainerColumn.add(controlsColumn);
final Grid grid = new Grid(4);
grid.setBorder(new Border(new Extent(1), Color.BLUE, Border.STYLE_SOLID));
while (nextCellNumber < 17) {
grid.add(createGridCellButton());
}
testColumn.add(grid);
controlsColumn.addButton("Clear Selection", new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectCellButton(null);
}
});
controlsColumn.addButton("Insert Cell Before Selected", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
grid.add(createGridCellButton(), grid.indexOf(selectedButton));
}
}
});
controlsColumn.addButton("Append New Cell", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Button button = createGridCellButton();
grid.add(button);
selectCellButton(button);
}
});
controlsColumn.addButton("Append 10 New Cells", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Button button = null;
for (int i = 0; i < 10; ++i) {
button = createGridCellButton();
grid.add(button);
}
selectCellButton(button);
}
});
controlsColumn.addButton("Delete Selected Cell", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
int index = grid.indexOf(selectedButton);
grid.remove(selectedButton);
if (grid.getComponentCount() != 0) {
if (index < grid.getComponentCount()) {
selectCellButton((Button) grid.getComponent(index));
} else {
selectCellButton((Button) grid.getComponent(grid.getComponentCount() - 1));
}
} else {
selectCellButton(null);
}
}
}
});
controlsColumn.addButton("Delete All Cells", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.removeAll();
}
});
controlsColumn.addButton("Add Row-Button Cell", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Row row = new Row();
for (int i = 0; i < 3; ++i) {
Button button = new Button("Test (" + i + ") Test");
button.setStyleName("Default");
row.add(button);
}
grid.add(row);
}
});
controlsColumn = new ButtonColumn();
controlsColumn.add(new Label("Configure Grid"));
groupContainerColumn.add(controlsColumn);
controlsColumn.addButton("Swap Orientation", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setOrientation(grid.getOrientation() == Grid.ORIENTATION_VERTICAL
? Grid.ORIENTATION_HORIZONTAL : Grid.ORIENTATION_VERTICAL);
}
});
controlsColumn.addButton("[+] Size", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setSize(grid.getSize() + 1);
}
});
controlsColumn.addButton("[-] Size", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (grid.getSize() > 1) {
grid.setSize(grid.getSize() - 1);
}
}
});
controlsColumn.addButton("Change Foreground", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setForeground(StyleUtil.randomColor());
}
});
controlsColumn.addButton("Change Background", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setBackground(StyleUtil.randomColor());
}
});
controlsColumn.addButton("Change Border (All Attributes)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setBorder(StyleUtil.randomBorder());
}
});
controlsColumn.addButton("Change Border Color", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Border border = grid.getBorder();
grid.setBorder(new Border(border.getSize(), StyleUtil.randomColor(), border.getStyle()));
}
});
controlsColumn.addButton("Change Border Size", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setBorder(StyleUtil.nextBorderSize(grid.getBorder()));
}
});
controlsColumn.addButton("Change Border Style", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setBorder(StyleUtil.nextBorderStyle(grid.getBorder()));
}
});
controlsColumn.addButton("Set Insets 0px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setInsets(new Insets(0));
}
});
controlsColumn.addButton("Set Insets 2px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setInsets(new Insets(2));
}
});
controlsColumn.addButton("Set Insets 10/5px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setInsets(new Insets(10, 5));
}
});
controlsColumn.addButton("Set Insets 10/20/30/40px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setInsets(new Insets(10, 20, 30, 40));
}
});
controlsColumn.addButton("Set Width = null", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setWidth(null);
}
});
controlsColumn.addButton("Set Width = 500px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setWidth(new Extent(500));
}
});
controlsColumn.addButton("Set Width = 100%", new ActionListener() {
public void actionPerformed(ActionEvent e) {
grid.setWidth(new Extent(100, Extent.PERCENT));
}
});
controlsColumn = new ButtonColumn();
controlsColumn.add(new Label("Configure Cell"));
groupContainerColumn.add(controlsColumn);
controlsColumn.addButton("[+] Column Span", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
if (layoutData.getColumnSpan() < 1) {
layoutData.setColumnSpan(1);
} else {
layoutData.setColumnSpan(layoutData.getColumnSpan() + 1);
}
selectedButton.setLayoutData(layoutData);
retitle(selectedButton);
}
}
});
controlsColumn.addButton("[-] Column Span", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
if (layoutData.getColumnSpan() > 1) {
layoutData.setColumnSpan(layoutData.getColumnSpan() - 1);
} else {
layoutData.setColumnSpan(1);
}
selectedButton.setLayoutData(layoutData);
retitle(selectedButton);
}
}
});
controlsColumn.addButton("[+] Row Span", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
if (layoutData.getRowSpan() < 1) {
layoutData.setRowSpan(1);
} else {
layoutData.setRowSpan(layoutData.getRowSpan() + 1);
}
selectedButton.setLayoutData(layoutData);
retitle(selectedButton);
}
}
});
controlsColumn.addButton("[-] Row Span", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
if (layoutData.getRowSpan() > 1) {
layoutData.setRowSpan(layoutData.getRowSpan() - 1);
} else {
layoutData.setRowSpan(1);
}
selectedButton.setLayoutData(layoutData);
retitle(selectedButton);
}
}
});
controlsColumn.addButton("Column Span: FILL", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setColumnSpan(GridLayoutData.SPAN_FILL);
selectedButton.setLayoutData(layoutData);
retitle(selectedButton);
}
}
});
controlsColumn.addButton("Row Span: FILL", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setRowSpan(GridLayoutData.SPAN_FILL);
selectedButton.setLayoutData(layoutData);
retitle(selectedButton);
}
}
});
controlsColumn.addButton("Set Insets 0px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setInsets(new Insets(0));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Insets 2px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setInsets(new Insets(2));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Insets 10/5px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setInsets(new Insets(10, 5));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Insets 10/20/30/40px", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setInsets(new Insets(10, 20, 30, 40));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Alignment = Default", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setAlignment(null);
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Alignment = Leading/Top", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setAlignment(new Alignment(Alignment.LEADING, Alignment.TOP));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Alignment = Trailing/Bottom", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setAlignment(new Alignment(Alignment.TRAILING, Alignment.BOTTOM));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Alignment = Left/Top", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setAlignment(new Alignment(Alignment.LEFT, Alignment.TOP));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Alignment = Right/Bottom", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setAlignment(new Alignment(Alignment.RIGHT, Alignment.BOTTOM));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Alignment = Center/Center", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setAlignment(new Alignment(Alignment.CENTER, Alignment.CENTER));
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Background Image", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Background Image (5px)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE_5_PX_REPEAT);
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Set Background Image (1%)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE_1_PERCENT_REPEAT);
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn.addButton("Clear BackgroundImage", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedButton != null) {
GridLayoutData layoutData = (GridLayoutData) selectedButton.getLayoutData();
layoutData.setBackgroundImage(null);
selectedButton.setLayoutData(layoutData);
}
}
});
controlsColumn = new ButtonColumn();
controlsColumn.add(new Label("Configure Rows/Columns"));
groupContainerColumn.add(controlsColumn);
controlsColumn.addButton("Clear Widths of First 16 Columns", new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < 16; ++i) {
grid.setColumnWidth(i, null);
}
}
});
controlsColumn.addButton("Set First 16 Columns to 100px Width", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Extent width = new Extent(100);
for (int i = 0; i < 16; ++i) {
grid.setColumnWidth(i, width);
}
}
});
controlsColumn.addButton("Set First 16 Columns to Random Width", new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < 16; ++i) {
grid.setColumnWidth(i, new Extent( ((int) (Math.random() * 100)) + 50));
}
}
});
controlsColumn.addButton("Clear Heights of First 16 Rows", new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < 16; ++i) {
grid.setRowHeight(i, null);
}
}
});
controlsColumn.addButton("Set First 16 Rows to 100px Height", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Extent height = new Extent(100);
for (int i = 0; i < 16; ++i) {
grid.setRowHeight(i, height);
}
}
});
controlsColumn.addButton("Set First 16 Rows to Random Height", new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < 16; ++i) {
grid.setRowHeight(i, new Extent( ((int) (Math.random() * 100)) + 50));
}
}
});
controlsColumn = new ButtonColumn();
controlsColumn.add(new Label("Additional Tests"));
groupContainerColumn.add(controlsColumn);
controlsColumn.addButton("Grid/Column/Grid FillImage Test", new ActionListener() {
public void actionPerformed(ActionEvent e) {
WindowPane windowPane = new WindowPane();
windowPane.setTitle("Grid/Column/Grid FillImage Test");
windowPane.setInsets(new Insets(10));
windowPane.setStyleName("Default");
windowPane.setDefaultCloseOperation(WindowPane.DISPOSE_ON_CLOSE);
InteractiveApp.getApp().getDefaultWindow().getContent().add(windowPane);
GridLayoutData gld;
ColumnLayoutData cld;
Grid grid0 = new Grid();
grid0.setInsets(new Insets(5));
grid0.add(new Label("Grid 0 Label"));
grid0.add(new Label("Grid 0 Label"));
grid0.add(new Label("Grid 0 Label"));
Column column = new Column();
column.setInsets(new Insets(5));
grid0.add(column);
column.add(new Label("Column Label"));
column.add(new Label("Column Label"));
column.add(new Label("Column Label"));
gld = new GridLayoutData();
gld.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE_50_PX_REPEAT);
column.setLayoutData(gld);
grid0.add(column);
Grid grid1 = new Grid();
grid1.setInsets(new Insets(5));
cld = new ColumnLayoutData();
cld.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE_5_PX_REPEAT);
grid1.setLayoutData(cld);
column.add(grid1);
grid1.add(new Label("Grid 1 Label"));
grid1.add(new Label("Grid 1 Label"));
grid1.add(new Label("Grid 1 Label"));