/** A class to render numbers in scientific format. */
  class ScientificRenderer extends JLabel implements TableCellRenderer {
    NumberFormat format = NumberFormat.getInstance();

    public ScientificRenderer(int sigfigs) {
      sigfigs = Math.min(sigfigs, 6);
      if (format instanceof DecimalFormat) {
        String pattern = "0.0"; // $NON-NLS-1$
        for (int i = 0; i < sigfigs - 1; i++) {
          pattern += "0"; // $NON-NLS-1$
        }
        pattern += "E0"; // $NON-NLS-1$
        ((DecimalFormat) format).applyPattern(pattern);
      }
    }

    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      setFont(
          getDefaultRenderer(String.class)
              .getTableCellRendererComponent(DatasetStatisticsTable.this, "a", false, false, 0, 0)
              .getFont()); //$NON-NLS-1$
      setText(format.format(value));
      setHorizontalAlignment(SwingConstants.TRAILING);
      return this;
    }
  }
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   setFont(
       getDefaultRenderer(String.class)
           .getTableCellRendererComponent(DatasetStatisticsTable.this, "a", false, false, 0, 0)
           .getFont()); //$NON-NLS-1$
   setText(format.format(value));
   setHorizontalAlignment(SwingConstants.TRAILING);
   return this;
 }
Exemplo n.º 3
0
 public synchronized Object getValueAt(int row, int col) {
   Chef entry = (Chef) (_entries.elementAt(row));
   if (col == NAME) return entry.getName();
   else if (col == POSITION) return new Double(entry.getPosition()._angle);
   else if (col == TIME) return _timeFormat.format(entry.getTime());
   else if (col == STATE) return Chef.stateStrings[entry.getModelingState()];
   else if (col == SERVING) {
     if (entry.getServing() == null) return "";
     else return entry.getServing()._name;
   } else if (col == BOAT) {
     if (entry.getBoat() != null) return entry.getBoat().getName();
     else return "";
   } else return null;
 }
 private static Object formatBigDecimal(Object number, Locale locale) {
   NumberFormat nf = NumberFormat.getNumberInstance(locale);
   nf.setMinimumFractionDigits(2);
   return nf.format(number);
 }
Exemplo n.º 5
0
 public ChefTable() {
   _timeFormat = NumberFormat.getInstance(java.util.Locale.US);
   _timeFormat.setGroupingUsed(false);
   _timeFormat.setMinimumFractionDigits(4);
   _timeFormat.setMaximumFractionDigits(4);
 }