<MyMathCalcPlugin Project>/src/org/myorg/mymathcalcplugin/ComputeSumAction.java |
package org.myorg.mymathcalcplugin;
import java.text.MessageFormat;
import org.openide.util.NbBundle;
public class ComputeSumAction extends AbstractComputationAction {
private static final MessageFormat RESULT_FORMAT = new MessageFormat(
NbBundle.getMessage(ComputeSumAction.class, "MSG_SumResult"));
public ComputeSumAction() {
super(new AverageComputer());
}
@Override
public String getName() {
return NbBundle.getMessage(ComputeSumAction.class, "NAME_Sum");
}
private static class AverageComputer extends AbstractComputationPerformer {
private double sum = 0;
@Override
public void reset() {
super.reset();
sum = 0;
}
@Override
public void addValue(Object value) {
super.addValue(value);
Number n = (Number) value;
sum += n.doubleValue();
}
@Override
public String getResultDisplayMessage() {
return RESULT_FORMAT.format(new Object[] { getCount(), getResult() } );
}
@Override
public Object getResult() {
return sum;
}
@Override
public String getProgressName() {
return NbBundle.getMessage(ComputeSumAction.class, "MSG_ProgressComputingSum");
}
}
}