Example usage for java.math BigDecimal setScale

List of usage examples for java.math BigDecimal setScale

Introduction

In this page you can find the example usage for java.math BigDecimal setScale.

Prototype

@Deprecated(since = "9")
public BigDecimal setScale(int newScale, int roundingMode) 

Source Link

Document

Returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value.

Usage

From source file:org.egov.egf.web.actions.voucher.VoucherSearchAction.java

@ValidationErrorPage(value = SEARCH)
@Action(value = "/voucher/voucherSearch-search")
public String search() throws ApplicationException, ParseException {
    if (parameters.get(SHOW_MODE) != null)
        showMode = parameters.get(SHOW_MODE)[0];
    if (voucherHeader.getModuleId() != null && voucherHeader.getModuleId() == -1)
        voucherHeader.setModuleId(null);
    // validate if mode is edit and financial year is not active
    if (showMode != null && showMode.equalsIgnoreCase("edit")) {
        final boolean validateFinancialYearForPosting = voucherSearchUtil
                .validateFinancialYearForPosting(fromDate, toDate);
        if (!validateFinancialYearForPosting)
            throw new ValidationException(Arrays.asList(new ValidationError(
                    "Financial Year  Not active for Posting(either year or date within selected date range)",
                    "Financial Year  Not active for Posting(either year or date within selected date range)")));
    }/*from  w ww  .j  a v  a2  s  . co m*/

    List<CVoucherHeader> list;
    List<Query> qryObj;
    boolean ismodifyJv = false;
    voucherList = new ArrayList<>();
    // for view voucher implementing paginated result
    if (isBlank(showMode)) {
        qryObj = voucherSearchUtil.voucherSearchQuery(voucherHeader, fromDate, toDate, showMode);
        final Query qry = qryObj.get(0);
        final Long count = (Long) persistenceService.find(qryObj.get(1).getQueryString());
        final Page resPage = new Page(qry, page, pageSize);
        pagedResults = new EgovPaginatedList(resPage, count.intValue());
        list = pagedResults.getList();
    } else if (showMode.equalsIgnoreCase("nonbillPayment"))
        list = voucherSearchUtil.searchNonBillVouchers(voucherHeader, fromDate, toDate, showMode);
    else
        list = voucherSearchUtil.search(voucherHeader, fromDate, toDate, showMode);
    Map<String, Object> voucherMap;
    if (isBlank(showMode)) {
        for (final CVoucherHeader voucherheader : list) {
            voucherMap = new HashMap<>();
            final BigDecimal amt = voucherheader.getTotalAmount();
            voucherMap.put("id", voucherheader.getId());
            voucherMap.put("vouchernumber", voucherheader.getVoucherNumber());
            voucherMap.put(TYPE, voucherheader.getType());
            voucherMap.put("name", voucherheader.getName());
            voucherMap.put("deptName", voucherheader.getVouchermis().getDepartmentid().getName());
            voucherMap.put("voucherdate", voucherheader.getVoucherDate());
            voucherMap.put("fundname", voucherheader.getFundId().getName());
            if (voucherheader.getModuleId() == null)
                voucherMap.put(SOURCE, INTERNAL);
            else
                voucherMap.put(SOURCE, sourceMap.get(voucherheader.getModuleId()));

            voucherMap.put("amount", amt.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString());
            voucherMap.put("status", getVoucherStatus(voucherheader.getStatus()));
            voucherList.add(voucherMap);
        }
        pagedResults.setList(voucherList);
    } else
        for (final CVoucherHeader voucherheader : list) {
            if (voucherheader.getState() != null) {
                final EgBillregistermis billMis = (EgBillregistermis) persistenceService
                        .find("from EgBillregistermis where voucherHeader.id=?", voucherheader.getId());
                if (billMis != null) {
                    /*
                     * bill state will be null if created from create JV screen and voucher is in end state
                     */
                    if (billMis.getEgBillregister().getState() == null
                            && voucherheader.getState().getValue().contains("END"))
                        ismodifyJv = true;
                    else
                        ismodifyJv = false;
                } else if (voucherheader.getName()
                        .equalsIgnoreCase(FinancialConstants.JOURNALVOUCHER_NAME_GENERAL)
                        && voucherheader.getState().getValue().contains("END"))
                    ismodifyJv = true;
            } else
                ismodifyJv = true;
            if (ismodifyJv) {
                voucherMap = new HashMap<>();
                voucherMap.put("id", voucherheader.getId());
                voucherMap.put("vouchernumber", voucherheader.getVoucherNumber());
                voucherMap.put(TYPE, voucherheader.getType());
                voucherMap.put("name", voucherheader.getName());
                voucherMap.put("deptName", voucherheader.getVouchermis().getDepartmentid().getName());
                voucherMap.put("voucherdate", voucherheader.getVoucherDate());
                voucherMap.put("fundname", voucherheader.getFundId().getName());
                if (voucherheader.getModuleId() == null)
                    voucherMap.put(SOURCE, INTERNAL);
                else
                    voucherMap.put(SOURCE, sourceMap.get(voucherheader.getModuleId()));
                voucherMap.put("amount",
                        voucherheader.getTotalAmount().setScale(2, BigDecimal.ROUND_HALF_EVEN).toString());
                voucherMap.put("status", getVoucherStatus(voucherheader.getStatus()));
                voucherList.add(voucherMap);
            }
        }
    return SEARCH;
}

From source file:org.egov.tl.service.TradeLicenseService.java

public void recalculateDemand(final List<FeeMatrixDetail> feeList, TradeLicense license) {
    final LicenseDemand licenseDemand = license.getCurrentDemand();
    // Recalculating current demand detail according to fee matrix
    for (final EgDemandDetails dmd : licenseDemand.getEgDemandDetails())
        for (final FeeMatrixDetail fm : feeList)
            if (licenseDemand.getEgInstallmentMaster().equals(dmd.getEgDemandReason().getEgInstallmentMaster())
                    && dmd.getEgDemandReason().getEgDemandReasonMaster().getCode()
                            .equalsIgnoreCase(fm.getFeeMatrix().getFeeType().getName())) {
                BigDecimal tradeAmt = calculateAmountByRateType(license, fm);
                dmd.setAmount(tradeAmt.setScale(0, RoundingMode.HALF_UP));
            }/*from   w  w  w  .ja  v  a 2s. co m*/
    calcPenaltyDemandDetails(license, licenseDemand);
    licenseDemand.recalculateBaseDemand();
}

From source file:org.egov.ptis.service.es.PropertyTaxElasticSearchIndexService.java

/**
 * Populates the consolidated demand information in CollectionIndexDetails
 *
 * @param collectionDetailsRequest/*w  w w  .ja v a  2s . c om*/
 * @param collectionIndexDetails
 */
public void getConsolidatedDemandInfo(final CollectionDetailsRequest collectionDetailsRequest,
        final CollectionDetails collectionIndexDetails) {
    Date fromDate;
    Date toDate;
    final CFinancialYear currFinYear = cFinancialYearService.getFinancialYearByDate(new Date());

    /**
     * For fetching total demand between the date ranges if dates are sent in the request, consider fromDate and toDate+1 ,
     * else calculate from current year start date till current date+1 day
     */
    if (StringUtils.isNotBlank(collectionDetailsRequest.getFromDate())
            && StringUtils.isNotBlank(collectionDetailsRequest.getToDate())) {
        fromDate = DateUtils.getDate(collectionDetailsRequest.getFromDate(), "yyyy-MM-dd");
        toDate = DateUtils.getDate(collectionDetailsRequest.getToDate(), "yyyy-MM-dd");
    } else {
        fromDate = DateUtils.startOfDay(currFinYear.getStartingDate());
        toDate = new Date();
    }
    final BigDecimal totalDemand = getTotalDemandBasedOnInputFilters(collectionDetailsRequest);
    final int noOfMonths = DateUtils.noOfMonthsBetween(fromDate, toDate) + 1;
    collectionIndexDetails.setTotalDmd(totalDemand);

    // Proportional Demand = (totalDemand/12)*noOfmonths
    final BigDecimal proportionalDemand = totalDemand.divide(BigDecimal.valueOf(12), BigDecimal.ROUND_HALF_UP)
            .multiply(BigDecimal.valueOf(noOfMonths));
    collectionIndexDetails.setCytdDmd(proportionalDemand.setScale(0, BigDecimal.ROUND_HALF_UP));

    collectionIndexDetails.setTotalAssessments(
            collectionIndexElasticSearchService.getTotalAssessmentsCount(collectionDetailsRequest));

    if (proportionalDemand.compareTo(BigDecimal.ZERO) > 0)
        // performance = (current year tilldate collection * 100)/(proportional demand)
        collectionIndexDetails.setPerformance(
                collectionIndexDetails.getCytdColl().multiply(PropertyTaxConstants.BIGDECIMAL_100)
                        .divide(proportionalDemand, 1, BigDecimal.ROUND_HALF_UP));
    // variance = ((currentYearCollection - lastYearCollection)*100)/lastYearCollection
    BigDecimal variation;
    if (collectionIndexDetails.getLytdColl().compareTo(BigDecimal.ZERO) == 0)
        variation = BIGDECIMAL_100;
    else
        variation = collectionIndexDetails.getCytdColl().subtract(collectionIndexDetails.getLytdColl())
                .multiply(BIGDECIMAL_100)
                .divide(collectionIndexDetails.getLytdColl(), 1, BigDecimal.ROUND_HALF_UP);
    collectionIndexDetails.setLyVar(variation);
}

From source file:org.cirdles.geoapp.LatLongToUTM.java

public static UTM convert(BigDecimal latitude, BigDecimal longitude, String datumName) {

    DatumEnum datumEnum = DatumEnum.valueOf(datumName);
    BigDecimal flattening3D = new BigDecimal(datumEnum.getFlattening3D());
    BigDecimal meridianRadius = new BigDecimal(datumEnum.getMeridianRadius());
    BigDecimal eccentricity = new BigDecimal(datumEnum.getEccentricity());

    BigDecimal latitudeRadians = latitude.abs().multiply(new BigDecimal(Math.PI)).divide(new BigDecimal(180.0),
            precision, RoundingMode.HALF_UP);

    //System.out.println("Latitude Radians: " + latitudeRadians);

    int zoneNumber = calcZoneNumber(longitude);

    BigDecimal zoneCentralMeridian = calcZoneCentralMeridian(zoneNumber);

    BigDecimal changeInLongitudeDegree = (longitude.subtract(zoneCentralMeridian)).abs().setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Change in Long Degree: " + changeInLongitudeDegree);

    BigDecimal changeInLongitudeRadians = (changeInLongitudeDegree.multiply(new BigDecimal(Math.PI)))
            .divide(new BigDecimal(180), precision, RoundingMode.HALF_UP);
    //System.out.println("Change In Longitude Radians: " + changeInLongitudeRadians);

    BigDecimal conformalLatitude = calcConformalLatitude(eccentricity, latitudeRadians).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Conformal Latitude: " + conformalLatitude);

    BigDecimal tauPrime = (new BigDecimal(Math.tan(conformalLatitude.doubleValue()))).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Tau Prime: " + tauPrime);

    BigDecimal xiPrimeNorth = calcXiPrimeNorth(changeInLongitudeRadians, tauPrime).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("xi Prime North: " + xiPrimeNorth);

    BigDecimal etaPrimeEast = calcEtaPrimeEast(changeInLongitudeRadians, tauPrime).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Eta Prime East: " + etaPrimeEast);

    BigDecimal[] alphaSeries = { KrugerSeries.alpha1(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha2(flattening3D.setScale(precision, RoundingMode.HALF_UP)),
            KrugerSeries.alpha3(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha4(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha5(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha6(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha7(flattening3D).setScale(precision, RoundingMode.HALF_UP) };

    BigDecimal xiNorth = calcXiNorth(xiPrimeNorth, etaPrimeEast, alphaSeries).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("xi North: " + xiNorth);

    BigDecimal etaEast = calcEtaEast(xiPrimeNorth, etaPrimeEast, alphaSeries).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Eta East: " + etaEast);

    BigDecimal easting = calcEasting(meridianRadius, etaEast, longitude, zoneCentralMeridian)
            .setScale(precision, RoundingMode.HALF_UP);
    BigDecimal northing = calcNorthing(meridianRadius, xiNorth, latitude).setScale(precision,
            RoundingMode.HALF_UP);

    char zoneLetter = calcZoneLetter(latitude);
    char hemisphere = calcHemisphere(latitude);

    return new UTM(easting, northing, hemisphere, zoneNumber, zoneLetter);

}

From source file:org.libreplan.web.planner.order.OrderPlanningModel.java

private String getLabelTextEarnedValueType(OrderEarnedValueChartFiller earnedValueChartFiller,
        EarnedValueType type, LocalDate date) {

    BigDecimal value = earnedValueChartFiller.getIndicator(type, date);
    String units = _("h");
    if (type.equals(EarnedValueType.CPI) || type.equals(EarnedValueType.SPI)) {
        value = value.multiply(new BigDecimal(100));
        units = "%";
    }/*w w  w . j  a va 2s  .c  o  m*/
    return value.setScale(0, RoundingMode.HALF_UP) + " " + units;
}

From source file:org.kuali.ole.select.businessobject.OleInvoiceItem.java

public BigDecimal calculateItemExtendedPrice() {
    BigDecimal extendedPrice = BigDecimal.ZERO;
    BigDecimal itemUnitPrice = getItemUnitPrice();
    if (ObjectUtils.isNotNull(itemUnitPrice)) {
        if (this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
            // SERVICE ITEM: return unit price as extended price
            extendedPrice = itemUnitPrice;
        } else if (ObjectUtils.isNotNull(this.getItemQuantity())) {
            BigDecimal calcExtendedPrice = itemUnitPrice.multiply(this.getItemQuantity().bigDecimalValue());
            // ITEM TYPE (qty driven): return (unitPrice x qty)
            extendedPrice = calcExtendedPrice.setScale(4, KualiDecimal.ROUND_BEHAVIOR);
        }/* w  w w  .  j  av a2  s  . co  m*/
    }
    return extendedPrice;
}

From source file:coffeshop.PaymentPage.java

private void btnScanBTCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnScanBTCActionPerformed
    timeStop = false;//w ww .  j  a  v  a 2 s.c  om
    btnScanBTC.setEnabled(false);
    btcTimer();
    String btcPay = txtPayAmt.getText();
    BigDecimal USD = new BigDecimal(btcPay);
    BigDecimal USDtoBTC = btcPriceIndex();
    BigDecimal BTCDue = USD.divide(USDtoBTC, 5, BigDecimal.ROUND_HALF_UP);
    USDtoBTC = USDtoBTC.setScale(2, BigDecimal.ROUND_HALF_UP);
    lblUSDtoBTC.setText("USD/BTC = " + USDtoBTC);
    lblBTCDue.setText("BTC Due: " + BTCDue);
    try {
        generateQR(btcPay);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Error generating QR Code");
        ex.printStackTrace();
    }
    try {
        BufferedImage image = ImageIO.read(new File("src/ImageRes/QR.jpg"));
        ImageIcon icon = new ImageIcon(image);
        icon.getImage().flush();
        lblQRC.setIcon(icon);
    } catch (IOException ex) {
        System.out.println(ex.getMessage());
    }

    if (lblQRC.getIcon() == null) {
        lblQRC.setIcon(defaultQR);
        JOptionPane.showMessageDialog(null, "Wrong QR Code. Please try again.", "Wrong QR Code",
                JOptionPane.PLAIN_MESSAGE);
    }
}

From source file:org.kuali.ole.select.businessobject.OleInvoiceItem.java

public KualiDecimal calculateForeignExtendedPrice() {
    KualiDecimal extendedPrice = KualiDecimal.ZERO;
    if (this.getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)) {
        if (ObjectUtils.isNotNull(itemForeignUnitCost)) {
            if (this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
                extendedPrice = new KualiDecimal(this.itemForeignUnitCost.toString());
            } else if (ObjectUtils.isNotNull(this.getItemQuantity())) {
                BigDecimal calcExtendedPrice = this.itemForeignUnitCost.bigDecimalValue()
                        .multiply(this.getItemQuantity().bigDecimalValue());
                extendedPrice = new KualiDecimal(
                        calcExtendedPrice.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR));
            }/*w w w.  j  a va2s .  c  o  m*/
        }
    }
    return extendedPrice;
}

From source file:la2launcher.MainFrame.java

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed

    Thread th = new Thread() {
        @Override//from ww  w.  ja  v a2 s. c o  m
        public void run() {
            try {
                jTextArea2.setText(" ");
                File patch = File.createTempFile("patch", ".zip");
                patch.deleteOnExit();
                CloseableHttpClient httpclient = HttpClients.createDefault();
                HttpGet httpGet = new HttpGet(patchPath);
                CloseableHttpResponse response1 = httpclient.execute(httpGet);

                FileOutputStream fos = new FileOutputStream(patch);
                HttpEntity entity1 = response1.getEntity();
                copyStream(entity1.getContent(), fos, new CopyListener() {
                    @Override
                    public void transfered(int n) {
                        bytesRecieved += n;
                        bytesRecievedTotal += n;
                    }
                });
                response1.close();
                fos.close();
                jTextArea2.setText(jTextArea2.getText() + "\r\n ");

                try {
                    new DirDeltaPatcher().patch(new File(gamePath + "\\system"), patch);
                } catch (Exception e) {
                    jTextArea2.setText(jTextArea2.getText() + "\r\n" + e);
                    return;
                }
                jTextArea2.setText(jTextArea2.getText() + "\r\n? ");

            } catch (IOException ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    };

    th.start();

    jButton5.setEnabled(false);
    jButton6.setEnabled(false);
    jButton7.setEnabled(false);
    jButton8.setEnabled(false);
    jButton10.setEnabled(false);
    jProgressBar1.setIndeterminate(true);
    new Thread() {
        @Override
        public void run() {
            do {
                long millis = new Date().getTime();
                try {
                    sleep(300);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                millis = new Date().getTime() - millis;
                BigDecimal totBig = new BigDecimal(bytesRecievedTotal / (1024 * 1024.0));
                totBig = totBig.setScale(2, BigDecimal.ROUND_CEILING);
                jLabel5.setText("?: " + (bytesRecieved / millis) + "KB/s. : "
                        + totBig + " MB");
                bytesRecieved = 0;
            } while (th.isAlive());

            jButton5.setEnabled(true);
            jButton6.setEnabled(true);
            jButton7.setEnabled(true);
            jButton8.setEnabled(true);
            jButton10.setEnabled(true);
            jProgressBar1.setIndeterminate(false);
        }
    }.start();

}

From source file:la2launcher.MainFrame.java

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
    final long initTime = new Date().getTime();
    ReentrantLock lock = new ReentrantLock();
    final String patcherUrl = "http://" + updateHost + "/hf//updater.lst.la2";//new ArrayBlockingQueue<Runnable>(10000)
    final ThreadPoolExecutor tpe = new ThreadPoolExecutor(5, 5, 1, TimeUnit.HOURS,
            new ArrayBlockingQueue<Runnable>(10000));
    filesProcessed = 0;//from   w  w w .j  ava 2s.c o  m
    tpe.execute(new Runnable() {
        @Override
        public void run() {
            jTextArea2.setText("");
            DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
            jProgressBar1.setMinimum(0);
            jProgressBar1.setMaximum(model.getRowCount());
            jProgressBar1.setValue(0);
            jLabel4.setText("0/" + model.getRowCount());
            for (int i = 0; i < model.getRowCount(); i++) {
                boolean checked = (Boolean) model.getValueAt(i, 1);
                String fileName = (String) model.getValueAt(i, 0);
                if (checked) {
                    tpe.execute(new Runnable() {
                        @Override
                        public void run() {

                            final String fileUrl = "http://" + updateHost + "/hf/" + fileName.replace("\\", "/")
                                    + ".la2";
                            try {
                                printMsg("  " + fileUrl);
                                File file = new File(gamePath + fileName + ".rar");
                                File fileExt = new File(gamePath + fileName);

                                file.getParentFile().mkdirs();
                                FileOutputStream fos = new FileOutputStream(file);
                                CloseableHttpClient httpclient = HttpClients.createDefault();
                                HttpGet httpGet = new HttpGet(fileUrl);
                                CloseableHttpResponse response1 = httpclient.execute(httpGet);

                                HttpEntity entity1 = response1.getEntity();
                                copyStream(entity1.getContent(), fos, new CopyListener() {
                                    @Override
                                    public void transfered(int n) {
                                        bytesRecieved += n;
                                        bytesRecievedTotal += n;
                                    }
                                });
                                response1.close();
                                fos.close();

                                printMsg("?? : " + fileName);

                                lock.lock();
                                //fixBzip2File(file);
                                //printMsg(" ?");

                                extractArchive(file.getAbsolutePath());

                                //BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new FileInputStream(file));
                                //OutputStream pout = new FileOutputStream(fileExt);
                                //copyStream(archStream, pout, null);
                                //pout.close();
                                //archStream.close();
                                //jTextArea2.setText(jTextArea2.getText() + "\r\n? : " + fileName);
                                printMsg("? : " + fileName);
                                //file.delete();

                                //                                    File tgt = new File(gamePath + fileName);
                                //                                    if (tgt.exists()) {
                                //                                        tgt.delete();
                                //                                    }
                                //tgt.getParentFile().mkdirs();
                                //Files.move(fileExt.toPath(), new File(gamePath + fileName).toPath());
                                //jTextArea2.setText(jTextArea2.getText() + "\r\n ??: " + fileName);
                                printMsg(" ??: " + fileName);
                                jProgressBar1.setIndeterminate(false);
                                jLabel4.setText((++filesProcessed) + "/" + model.getRowCount());
                                jProgressBar1.setValue((int) filesProcessed);
                                lock.unlock();
                            } catch (IOException ex) {
                                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (Exception ex) {
                                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    });
                }
            }
        }
    });

    jButton5.setEnabled(false);
    jButton6.setEnabled(false);
    jButton7.setEnabled(false);
    jButton8.setEnabled(false);
    jButton9.setEnabled(false);
    jButton10.setEnabled(false);
    jProgressBar1.setIndeterminate(true);
    new Thread() {
        @Override
        public void run() {
            do {
                long millis = new Date().getTime();
                try {
                    sleep(300);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                millis = new Date().getTime() - millis;
                BigDecimal totBig = new BigDecimal(bytesRecievedTotal / (1024 * 1024.0));
                totBig = totBig.setScale(2, BigDecimal.ROUND_CEILING);
                jLabel5.setText("?: " + (bytesRecieved / millis) + "KB/s. : "
                        + totBig + " MB");
                bytesRecieved = 0;
            } while (tpe.getActiveCount() > 0);
            tpe.shutdown();
            jButton5.setEnabled(true);
            jButton6.setEnabled(true);
            jButton7.setEnabled(true);
            jButton8.setEnabled(true);
            jButton9.setEnabled(true);
            jButton10.setEnabled(true);
            jProgressBar1.setIndeterminate(false);
            printMsg("  " + (new Date().getTime() - initTime)
                    + " ?.");
        }
    }.start();
}