/** @param value the value to set */ public void setValue(T value) { if (this.value != null) { parent.getParent().removeCellOfItem(value); } this.value = value; parent.getParent().setCellOfItem(value, this); }
@Override public String toString() { StringBuilder sb = new StringBuilder("{"); sb.append(super.toString()); sb.append("\n"); for (Row<T> row : this) { sb.append("\t"); sb.append(row.toString()); sb.append("\n"); } sb.append("}"); return sb.toString(); }
public Point find(Cell<T> target) { if (target == null) { return null; } int i = 0; for (Row<T> row : this) { if (row == target.getParent()) { return new Point(row.find(target), i); } i++; } return null; }
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if (rowIndex >= getRowCount()) { return; } final Row row = myData.get(rowIndex); switch (columnIndex) { case NAME_TABLE_COLUMN: row.name = (String) aValue; break; case EXPRESSION_TABLE_COLUMN: row.value = (TextWithImports) aValue; break; } }
public boolean isInterleaveableWith(Row<T> other) { if (other == null || other == this) { return false; } else if (other.getNextRow() != this && other.getPrevRow() != this) { return false; } Iterator<Cell<T>> oIt = other.iterator(); for (Cell<T> c : this) { if (oIt.next().isUnpackable() && c.isUnpackable()) { return false; } } return true; }
public void insertColumnBefore(int col) { if (col < 0 || col > width) { throw new IllegalArgumentException("Column #" + col + " does not exist"); } if (col == width) { for (Row<T> row : this) { row.lastCell._insertCellAfter(); } } else { for (Row<T> row : this) { row.get(col)._insertCellBefore(); } } width++; if (parent != null) { parent._insertColumnBefore(col, width); } }
private void processRow(Row row) { int fc = row.getFirstCellNum(); if (fc == 0) { Cell cell = row.getCell(0); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { columnCount = columnCount < row.getLastCellNum() ? row.getLastCellNum() : columnCount; String rowType = cell.getStringCellValue().toUpperCase(); switch (rowType) { case "TITLE": { title.add(row); } break; case "GROUPH": { String fName = getGroupParam(row); if (!fName.isEmpty()) { detail.addGroup(true, row, fName); } } break; case "DETAIL1": { detail.add(row); } break; case "GROUPF": { String fName = getGroupParam(row); if (!fName.isEmpty()) { detail.addGroup(false, row, fName); } } break; case "SUMMARY": { summary.add(row); } break; } } } }
private Cell<T> _insertCellAfter() { Cell<T> newCell = new Cell<T>(parent, this, nextCell); if (nextCell == null) { parent.lastCell = newCell; } else { nextCell.prevCell = newCell; } nextCell = newCell; return newCell; }
private Cell<T> _insertCellBefore() { Cell<T> newCell = new Cell<T>(parent, prevCell, this); if (prevCell == null) { parent.firstCell = newCell; } else { prevCell.nextCell = newCell; } prevCell = newCell; return newCell; }
public Cell<T> insertCellAfter() { // Make sure last cell is empty if (parent.lastCell.isFilled()) { parent.parent.addLastColumn(); } _insertCellAfter(); // Trim end of row parent.lastCell.getPrevCell().nextCell = null; parent.lastCell = parent.lastCell.getPrevCell(); return getNextCell(); }
public Cell<T> insertCellBefore() { // Make sure first cell is empty if (parent.firstCell.isFilled()) { parent.parent.addFirstColumn(); } _insertCellBefore(); // Trim beginning of row parent.firstCell.getNextCell().prevCell = null; parent.firstCell = parent.firstCell.getNextCell(); return getPrevCell(); }
/** * This function re-computes the total number of hours for the selected period. It is ran every * time the user edits a text field specifying the number of hours for a particular top-level * project. Percentage labels are also updated. */ private void recomputeTotal() { double total = 0; for (Row row : rows.values()) { try { row.hours = Double.parseDouble(row.hoursTF.getText()); total += row.hours; row.hoursTF.setForeground(normalColour); } catch (NumberFormatException e) { row.hoursTF.setForeground(errorColour); totalLabel.setText("ERROR"); totalLabel.setForeground(errorColour); return; } } totalLabel.setText(decimalFormat.format(total)); totalLabel.setForeground(normalColour); for (Row row : rows.values()) { String percentS = decimalFormat.format(total == 0 ? 0 : 100 * row.hours / total); row.percentL.setText("(" + percentS + "%)"); } pack(); }
public void pack() { boolean changed; do { changed = false; for (Row<T> r : this) { changed |= r.tryInterleaveWith(r.getPrevRow()); } // System.out.println(); for (Row<T> r : this) { changed |= r.tryInterleaveWith(r.getNextRow()); } // System.out.println(); } while (changed); }
public boolean tryInterleaveWith(Row<T> other) { // System.out.println("Try to interleave " + this); // System.out.print(" with " + other); if (!isInterleaveableWith(other)) { // System.out.println(": failed"); return false; } Iterator<Cell<T>> oIt = other.iterator(); for (Cell<T> c : this) { Cell<T> oC = oIt.next(); if (c.isFilled()) { if (oC.prevCell == null) { oC.parent.firstCell = c; } else { oC.prevCell.nextCell = c; } if (oC.nextCell == null) { oC.parent.lastCell = c; } else { oC.nextCell.prevCell = c; } c.prevCell = oC.prevCell; c.nextCell = oC.nextCell; c.parent = oC.parent; oC.nextCell = null; oC.prevCell = null; oC.parent = null; } else if (c.isUnpackable()) { oC.setPackable(false); } } this._remove(); // System.out.println(": done"); return true; }
/** * will create a new column before <code>this</code> * * @param value the value of the new cell * @return the new cell before <code>this</code> */ public Cell<T> insertColumnBefore() { int i = parent.find(this); parent.parent.insertColumnBefore(i); return prevCell; }
public Row<T> insertRowBeneath(Row<T> row) { return row.insertRowBeneath(); }
public Row<T> insertRowAbove(Row<T> row) { return row.insertRowAbove(); }
public Cell<T> above() { return parent.above().get(parent.find(this)); }
public Cell<T> beneath() { return parent.beneath().get(parent.find(this)); }
/** * will create a new column after <code>this</code> * * @return the new cell after <code>this</code> */ public Cell<T> insertColumnAfter() { int i = parent.find(this); parent.parent.insertColumnAfter(i); return nextCell; }
private String getGroupParam(Row row) { Cell cell = row.getCell(1); return cell != null && cell.getCellType() == 1 ? cell.getStringCellValue().replace("_", "").toUpperCase() : ""; }