import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentConnector;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VCaption;
import com.vaadin.terminal.gwt.client.communication.RpcProxy;
import com.vaadin.terminal.gwt.client.communication.ServerRpc;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.ui.VGridLayout.Cell;
import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot;
import com.vaadin.ui.GridLayout;
public class GridLayoutConnector extends AbstractComponentContainerConnector
implements DirectionalManagedLayout {
+ public static class GridLayoutState extends ComponentState {
+ private boolean spacing = false;
+ private int rows = 0;
+ private int columns = 0;
+
+ public boolean isSpacing() {
+ return spacing;
+ }
+
+ public void setSpacing(boolean spacing) {
+ this.spacing = spacing;
+ }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public void setRows(int rows) {
+ this.rows = rows;
+ }
+
+ public int getColumns() {
+ return columns;
+ }
+
+ public void setColumns(int cols) {
+ columns = cols;
+ }
+
+ }
+
private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
this) {
getWidget().spacingMeasureElement);
}
+ @Override
+ public GridLayoutState getState() {
+ return (GridLayoutState) super.getState();
+ }
+
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+
+ clickEventHandler.handleEventHandlerRegistration();
+
+ }
+
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
VGridLayout layout = getWidget();
if (!isRealUpdate(uidl)) {
return;
}
- clickEventHandler.handleEventHandlerRegistration();
- int cols = uidl.getIntAttribute("w");
- int rows = uidl.getIntAttribute("h");
+ int cols = getState().getColumns();
+ int rows = getState().getRows();
layout.columnWidths = new int[cols];
layout.rowHeights = new int[rows];
int bitMask = uidl.getIntAttribute("margins");
layout.updateMarginStyleNames(new VMarginInfo(bitMask));
- layout.updateSpacingStyleName(uidl.getBooleanAttribute("spacing"));
+ layout.updateSpacingStyleName(getState().isSpacing());
getLayoutManager().setNeedsUpdate(this);
}
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.GridLayoutConnector;
import com.vaadin.terminal.gwt.client.ui.GridLayoutConnector.GridLayoutServerRPC;
+import com.vaadin.terminal.gwt.client.ui.GridLayoutConnector.GridLayoutState;
import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler;
/**
}
};
- /**
- * Initial grid columns.
- */
- private int cols = 0;
-
- /**
- * Initial grid rows.
- */
- private int rows = 0;
-
/**
* Cursor X position: this is where the next component with unspecified x,y
* is inserted
this(1, 1);
}
+ @Override
+ public GridLayoutState getState() {
+ return (GridLayoutState) super.getState();
+ }
+
/**
* <p>
* Adds a component to the grid in the specified area. The area is defined
throw new IllegalArgumentException(
"Illegal coordinates for the component");
}
- if (column1 < 0 || row1 < 0 || column2 >= cols || row2 >= rows) {
+ if (column1 < 0 || row1 < 0 || column2 >= getColumns()
+ || row2 >= getRows()) {
throw new OutOfBoundsException(area);
}
&& cursorY <= row2) {
// cursor within area
cursorX = column2 + 1; // one right of area
- if (cursorX >= cols) {
+ if (cursorX >= getColumns()) {
// overflowed columns
cursorX = 0; // first col
// move one row down, or one row under the area
*/
public void space() {
cursorX++;
- if (cursorX >= cols) {
+ if (cursorX >= getColumns()) {
cursorX = 0;
cursorY++;
}
}
// Extends the grid if needed
- cols = cursorX >= cols ? cursorX + 1 : cols;
- rows = cursorY >= rows ? cursorY + 1 : rows;
+ if (cursorX >= getColumns()) {
+ setColumns(cursorX + 1);
+ }
+ if (cursorY >= getRows()) {
+ setRows(cursorY + 1);
+ }
addComponent(component, cursorX, cursorY);
}
super.paintContent(target);
// TODO refactor attribute names in future release.
- target.addAttribute("h", rows);
- target.addAttribute("w", cols);
-
target.addAttribute("structuralChange", structuralChange);
structuralChange = false;
- if (spacing) {
- target.addAttribute("spacing", spacing);
- }
-
// Area iterator
final Iterator<Area> areaiterator = areas.iterator();
int emptyCells = 0;
final String[] alignmentsArray = new String[components.size()];
- final Integer[] columnExpandRatioArray = new Integer[cols];
- final Integer[] rowExpandRatioArray = new Integer[rows];
+ final Integer[] columnExpandRatioArray = new Integer[getColumns()];
+ final Integer[] rowExpandRatioArray = new Integer[getColumns()];
int realColExpandRatioSum = 0;
float colSum = getExpandRatioSum(columnExpandRatio);
if (colSum == 0) {
// no columns has been expanded, all cols have same expand
// rate
- float equalSize = 1 / (float) cols;
+ float equalSize = 1 / (float) getColumns();
int myRatio = Math.round(equalSize * 1000);
- for (int i = 0; i < cols; i++) {
+ for (int i = 0; i < getColumns(); i++) {
columnExpandRatioArray[i] = myRatio;
}
- realColExpandRatioSum = myRatio * cols;
+ realColExpandRatioSum = myRatio * getColumns();
} else {
- for (int i = 0; i < cols; i++) {
+ for (int i = 0; i < getColumns(); i++) {
int myRatio = Math
.round((getColumnExpandRatio(i) / colSum) * 1000);
columnExpandRatioArray[i] = myRatio;
if (rowSum == 0) {
// no rows have been expanded
equallyDividedRows = true;
- float equalSize = 1 / (float) rows;
+ float equalSize = 1 / (float) getRows();
int myRatio = Math.round(equalSize * 1000);
- for (int i = 0; i < rows; i++) {
+ for (int i = 0; i < getRows(); i++) {
rowExpandRatioArray[i] = myRatio;
}
- realRowExpandRatioSum = myRatio * rows;
+ realRowExpandRatioSum = myRatio * getRows();
}
int index = 0;
// Iterates every applicable row
- for (int cury = 0; cury < rows; cury++) {
+ for (int cury = 0; cury < getRows(); cury++) {
target.startTag("gr");
if (!equallyDividedRows) {
}
// Iterates every applicable column
- for (int curx = 0; curx < cols; curx++) {
+ for (int curx = 0; curx < getColumns(); curx++) {
// Checks if current item is located at curx,cury
if (area != null && (area.row1 == cury)
// Checks if empty cell needs to be rendered
if (emptyCells > 0) {
target.startTag("gc");
- target.addAttribute("x", cols - emptyCells);
+ target.addAttribute("x", getColumns() - emptyCells);
target.addAttribute("y", cury);
if (emptyCells > 1) {
target.addAttribute("w", emptyCells);
}
// In case of no change
- if (cols == columns) {
+ if (getColumns() == columns) {
return;
}
// Checks for overlaps
- if (cols > columns) {
+ if (getColumns() > columns) {
for (final Iterator<Area> i = areas.iterator(); i.hasNext();) {
final Area area = i.next();
if (area.column2 >= columns) {
}
}
- cols = columns;
+ getState().setColumns(columns);
requestRepaint();
}
* @return the number of columns in the grid.
*/
public int getColumns() {
- return cols;
+ return getState().getColumns();
}
/**
}
// In case of no change
- if (this.rows == rows) {
+ if (getRows() == rows) {
return;
}
// Checks for overlaps
- if (this.rows > rows) {
+ if (getRows() > rows) {
for (final Iterator<Area> i = areas.iterator(); i.hasNext();) {
final Area area = i.next();
if (area.row2 >= rows) {
}
}
- this.rows = rows;
+ getState().setRows(rows);
requestRepaint();
}
* @return the number of rows in the grid.
*/
public int getRows() {
- return rows;
+ return getState().getRows();
}
/**
* The leftmost row has index 0.
*/
public void insertRow(int row) {
- if (row > rows) {
+ if (row > getRows()) {
throw new IllegalArgumentException("Cannot insert row at " + row
- + " in a gridlayout with height " + rows);
+ + " in a gridlayout with height " + getRows());
}
for (Iterator<Area> i = areas.iterator(); i.hasNext();) {
cursorY++;
}
- setRows(rows + 1);
+ setRows(getRows() + 1);
structuralChange = true;
requestRepaint();
}
* Index of the row to remove. The leftmost row has index 0.
*/
public void removeRow(int row) {
- if (row >= rows) {
+ if (row >= getRows()) {
throw new IllegalArgumentException("Cannot delete row " + row
- + " from a gridlayout with height " + rows);
+ + " from a gridlayout with height " + getRows());
}
// Remove all components in row
}
}
- if (rows == 1) {
+ if (getRows() == 1) {
/*
* Removing the last row means that the dimensions of the Grid
* layout will be truncated to 1 empty row and the cursor is moved
cursorX = 0;
cursorY = 0;
} else {
- setRows(rows - 1);
+ setRows(getRows() - 1);
if (cursorY > row) {
cursorY--;
}