Exemple #1
0
 /** @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);
 }
Exemple #2
0
 @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();
 }
Exemple #3
0
 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;
   }
 }
Exemple #5
0
 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;
 }
Exemple #6
0
 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);
   }
 }
Exemple #7
0
  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;
        }
      }
    }
  }
Exemple #8
0
 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;
 }
Exemple #9
0
 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;
 }
Exemple #10
0
 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();
 }
Exemple #11
0
 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();
 }
Exemple #12
0
 /**
  * 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();
 }
Exemple #13
0
 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);
 }
Exemple #14
0
    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;
    }
Exemple #15
0
 /**
  * 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;
 }
Exemple #16
0
 public Row<T> insertRowBeneath(Row<T> row) {
   return row.insertRowBeneath();
 }
Exemple #17
0
 public Row<T> insertRowAbove(Row<T> row) {
   return row.insertRowAbove();
 }
Exemple #18
0
 public Cell<T> above() {
   return parent.above().get(parent.find(this));
 }
Exemple #19
0
 public Cell<T> beneath() {
   return parent.beneath().get(parent.find(this));
 }
Exemple #20
0
 /**
  * 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;
 }
Exemple #21
0
 private String getGroupParam(Row row) {
   Cell cell = row.getCell(1);
   return cell != null && cell.getCellType() == 1
       ? cell.getStringCellValue().replace("_", "").toUpperCase()
       : "";
 }