public Object getValueAt(int rowIndex, int columnIndex) {
   switch (columnIndex) {
     case 0:
       return row.getId();
     case 1:
       return row.getVal();
     case 2:
       return row.getExtra();
   }
   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;
   }
 }
示例#3
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();
 }
 private Dimension getLayoutSize(Container parent, boolean isPreferred) {
   // strategy:
   // this.minwidth = max(header.minwidth, (max(label.minwidth) + max(controls.minwidth)))
   // this.minheight = sum foreach row (header,control) (header.minheight or max(label.minheight,
   // control.minheight))
   int n = parent.getComponentCount();
   int w1 = 0, w2 = 0, wh = 0;
   Insets border = parent.getInsets();
   int height = border.top + border.bottom;
   for (int i = 0; i < n; i++) {
     Row r = (Row) rows.get(i);
     height += r.getHeight(isPreferred);
     if (r instanceof HeaderRow) {
       wh = Math.max(wh, ((HeaderRow) r).getWidth(isPreferred));
     } else {
       w1 = Math.max(w1, ((NormalRow) r).getLabelWidth(isPreferred));
       w2 = Math.max(w1, ((NormalRow) r).getControlWidth(isPreferred));
     }
   }
   wh = border.left + border.right + Math.max(wh, EXTRA + w1 + PADDING + w2);
   return new Dimension(wh, height);
 }