if(userInput.equals("ListLayout")) { CustomLayout layout = new ListLayout(); } else if (userInput.equals("GridLayout")) { CustomLayout layout = new GridLayout(); }
/** * Adjust the number of logical rows and columns and how elements are wrapped * into those cells. */ private void setElementRowsAndColumns(int elementRows, int elementColumns) { int logicalRowCountBefore = logicalRowCount(); int logicalColumnCountBefore = logicalColumnCount(); this.elementRows = elementRows; this.elementColumns = elementColumns; fixCellCount(logicalRowCountBefore, logicalColumnCountBefore); }
private void insertLogicalColumn(int index) { int baseColumn = logicalToLayoutColumn(index); // insert the gap for all columns but the first if(index != 0 && gapColumn != null) { insertColumn(baseColumn, gapColumn); baseColumn += 1; } // insert the element columns for(int c = 0; c < columnSpecs.length; c++) { insertColumn(baseColumn + c, columnSpecs[c]); } } private void removeLogicalRow(int index) {
private void insertLogicalRow(int index) { int baseRow = logicalToLayoutRow(index); // insert the gap for all rows but the first if(index != 0 && gapRow != null) { insertRow(baseRow, gapRow); baseRow += 1; } // insert the element rows for(int r = 0; r < rowSpecs.length; r++) { insertRow(baseRow + r, rowSpecs[r]); } } private void insertLogicalColumn(int index) {
/** * We can improve this method by replacing the before counts as parameters * by figuring out what the counts are by examining the layout. */ private void fixCellCount(int logicalRowCountBefore, int logicalColumnCountBefore) { int logicalColumnCountAfter = logicalColumnCount(); int logicalRowCountAfter = logicalRowCount(); // make sure we have enough cells for(int r = logicalRowCountBefore; r < logicalRowCountAfter; r++) { insertLogicalRow(r); } for(int c = logicalColumnCountBefore; c < logicalColumnCountAfter; c++) { insertLogicalColumn(c); } // we have too many cells in one dimension, the perfect time to // reassign constraints safely reassignConstraints(); // make sure we don't have too many cells for(int r = logicalRowCountBefore - 1; r >= logicalRowCountAfter; r--) { removeLogicalRow(r); } for(int c = logicalColumnCountBefore - 1; c >= logicalColumnCountAfter; c--) { removeLogicalColumn(c); } }
private void reassignConstraints() { formLayout.invalidateLayout(container); for(int i = 0; i < gridComponents.size(); i++) { CellComponents cellComponents = gridComponents.get(i); for(int j = 0; j < cellComponents.components.size(); j++) { Component component = cellComponents.components.get(j); Constraints constraints = cellComponents.constraints.get(j); formLayout.addLayoutComponent(component, deriveCellConstraints(constraints.getFormConstraints(), logicalColumn(i), logicalRow(i))); } } }
/** * We can improve this method by replacing the before counts as parameters * by figuring out what the counts are by examining the layout. */ private void fixCellCount(int logicalRowCountBefore, int logicalColumnCountBefore) { int logicalColumnCountAfter = logicalColumnCount(); int logicalRowCountAfter = logicalRowCount(); // make sure we have enough cells for(int r = logicalRowCountBefore; r < logicalRowCountAfter; r++) { insertLogicalRow(r); } for(int c = logicalColumnCountBefore; c < logicalColumnCountAfter; c++) { insertLogicalColumn(c); } // we have too many cells in one dimension, the perfect time to // reassign constraints safely reassignConstraints(); // make sure we don't have too many cells for(int r = logicalRowCountBefore - 1; r >= logicalRowCountAfter; r--) { removeLogicalRow(r); } for(int c = logicalColumnCountBefore - 1; c >= logicalColumnCountAfter; c--) { removeLogicalColumn(c); } }
/** {@inheritDoc} */ @Override public void addLayoutComponent(Component component, Object constraints) { Constraints listLayoutConstraints = (Constraints)constraints; int index = listLayoutConstraints.getIndex(); int formConstraints = listLayoutConstraints.getFormConstraints(); CellComponents cellComponents = gridComponents.get(index); cellComponents.components.add(component); cellComponents.constraints.add(listLayoutConstraints); CellConstraints cellConstraints = deriveCellConstraints(formConstraints, logicalColumn(index), logicalRow(index)); super.addLayoutComponent(component, cellConstraints); }
private void insertLogicalRow(int index) { int baseRow = logicalToLayoutRow(index); // insert the gap for all rows but the first if(index != 0 && gapRow != null) { insertRow(baseRow, gapRow); baseRow += 1; } // insert the element rows for(int r = 0; r < rowSpecs.length; r++) { insertRow(baseRow + r, rowSpecs[r]); } } private void insertLogicalColumn(int index) {
/** * We can improve this method by replacing the before counts as parameters * by figuring out what the counts are by examining the layout. */ private void fixCellCount(int logicalRowCountBefore, int logicalColumnCountBefore) { int logicalColumnCountAfter = logicalColumnCount(); int logicalRowCountAfter = logicalRowCount(); // make sure we have enough cells for(int r = logicalRowCountBefore; r < logicalRowCountAfter; r++) { insertLogicalRow(r); } for(int c = logicalColumnCountBefore; c < logicalColumnCountAfter; c++) { insertLogicalColumn(c); } // we have too many cells in one dimension, the perfect time to // reassign constraints safely reassignConstraints(); // make sure we don't have too many cells for(int r = logicalRowCountBefore - 1; r >= logicalRowCountAfter; r--) { removeLogicalRow(r); } for(int c = logicalColumnCountBefore - 1; c >= logicalColumnCountAfter; c--) { removeLogicalColumn(c); } }
/** * Adjust the number of logical rows and columns and how elements are wrapped * into those cells. */ private void setElementRowsAndColumns(int elementRows, int elementColumns) { int logicalRowCountBefore = logicalRowCount(); int logicalColumnCountBefore = logicalColumnCount(); this.elementRows = elementRows; this.elementColumns = elementColumns; fixCellCount(logicalRowCountBefore, logicalColumnCountBefore); }
/** {@inheritDoc} */ @Override public void addLayoutComponent(Component component, Object constraints) { Constraints listLayoutConstraints = (Constraints)constraints; int index = listLayoutConstraints.getIndex(); int formConstraints = listLayoutConstraints.getFormConstraints(); CellComponents cellComponents = gridComponents.get(index); cellComponents.components.add(component); cellComponents.constraints.add(listLayoutConstraints); CellConstraints cellConstraints = deriveCellConstraints(formConstraints, logicalColumn(index), logicalRow(index)); super.addLayoutComponent(component, cellConstraints); }
if ("ListLayout".equals(userInput)) { return new ListLayout(); }
private void insertLogicalRow(int index) { int baseRow = logicalToLayoutRow(index); // insert the gap for all rows but the first if(index != 0 && gapRow != null) { insertRow(baseRow, gapRow); baseRow += 1; } // insert the element rows for(int r = 0; r < rowSpecs.length; r++) { insertRow(baseRow + r, rowSpecs[r]); } } private void insertLogicalColumn(int index) {
private void insertLogicalColumn(int index) { int baseColumn = logicalToLayoutColumn(index); // insert the gap for all columns but the first if(index != 0 && gapColumn != null) { insertColumn(baseColumn, gapColumn); baseColumn += 1; } // insert the element columns for(int c = 0; c < columnSpecs.length; c++) { insertColumn(baseColumn + c, columnSpecs[c]); } } private void removeLogicalRow(int index) {
/** * Adjust the number of logical rows and columns and how elements are wrapped * into those cells. */ private void setElementRowsAndColumns(int elementRows, int elementColumns) { int logicalRowCountBefore = logicalRowCount(); int logicalColumnCountBefore = logicalColumnCount(); this.elementRows = elementRows; this.elementColumns = elementColumns; fixCellCount(logicalRowCountBefore, logicalColumnCountBefore); }
private void reassignConstraints() { formLayout.invalidateLayout(container); for(int i = 0; i < gridComponents.size(); i++) { CellComponents cellComponents = gridComponents.get(i); for(int j = 0; j < cellComponents.components.size(); j++) { Component component = cellComponents.components.get(j); Constraints constraints = cellComponents.constraints.get(j); formLayout.addLayoutComponent(component, deriveCellConstraints(constraints.getFormConstraints(), logicalColumn(i), logicalRow(i))); } } }
public class CustomLayoutFactory { public CustomLayout createInstance(String layoutName) { if("ListLayout".equals(layoutName) { return new ListLayout(); } else if("GridLayout".equals(layoutName) { return new GridLayout(); } return null; } }
private void insertLogicalColumn(int index) { int baseColumn = logicalToLayoutColumn(index); // insert the gap for all columns but the first if(index != 0 && gapColumn != null) { insertColumn(baseColumn, gapColumn); baseColumn += 1; } // insert the element columns for(int c = 0; c < columnSpecs.length; c++) { insertColumn(baseColumn + c, columnSpecs[c]); } } private void removeLogicalRow(int index) {
/** * Handle a list element being removed by adjusting the layout. */ public void removeIndex(int index) { int logicalColumnCountBefore = logicalColumnCount(); int logicalRowCountBefore = logicalRowCount(); gridComponents.remove(index); fixCellCount(logicalRowCountBefore, logicalColumnCountBefore); }