List of usage examples for java.text NumberFormat getInstance
public static final NumberFormat getInstance()
From source file:com.pikai.jdbc.testcase.PoolTest.java
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception { final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch endLatch = new CountDownLatch(threadCount); final CountDownLatch dumpLatch = new CountDownLatch(1); Thread[] threads = new Thread[threadCount]; for (int i = 0; i < threadCount; ++i) { Thread thread = new Thread() { public void run() { try { startLatch.await();/*from w w w. j a va2 s . c o m*/ for (int i = 0; i < LOOP_COUNT; ++i) { Connection conn = dataSource.getConnection(); conn.close(); } } catch (Exception ex) { ex.printStackTrace(); } endLatch.countDown(); try { dumpLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } } }; threads[i] = thread; thread.start(); } long startMillis = System.currentTimeMillis(); long startYGC = TestUtil.getYoungGC(); long startFullGC = TestUtil.getFullGC(); startLatch.countDown(); endLatch.await(); long[] threadIdArray = new long[threads.length]; for (int i = 0; i < threads.length; ++i) { threadIdArray[i] = threads[i].getId(); } ThreadInfo[] threadInfoArray = ManagementFactory.getThreadMXBean().getThreadInfo(threadIdArray); dumpLatch.countDown(); long blockedCount = 0; long waitedCount = 0; for (int i = 0; i < threadInfoArray.length; ++i) { ThreadInfo threadInfo = threadInfoArray[i]; blockedCount += threadInfo.getBlockedCount(); waitedCount += threadInfo.getWaitedCount(); } long millis = System.currentTimeMillis() - startMillis; long ygc = TestUtil.getYoungGC() - startYGC; long fullGC = TestUtil.getFullGC() - startFullGC; System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + "; YGC " + ygc + " FGC " + fullGC + " blocked " + NumberFormat.getInstance().format(blockedCount) // + " waited " + NumberFormat.getInstance().format(waitedCount) + " physicalConn " + physicalConnStat.get()); }
From source file:canreg.client.analysis.CasesByAgeGroupChartTableBuilder.java
@Override public LinkedList<String> buildTable(String tableHeader, String reportFileName, int startYear, int endYear, Object[][] incidenceData, PopulationDataset[] populations, // can be null PopulationDataset[] standardPopulations, LinkedList<ConfigFields> configList, String[] engineParameters, FileTypes fileType) throws NotCompatibleDataException { // String footerString = java.util.ResourceBundle.getBundle("canreg/client/analysis/resources/AgeSpecificCasesPerHundredThousandTableBuilder").getString("TABLE BUILT ") + new Date() + java.util.ResourceBundle.getBundle("canreg/client/analysis/resources/AgeSpecificCasesPerHundredThousandTableBuilder").getString(" BY CANREG5."); LinkedList<String> generatedFiles = new LinkedList<String>(); if (Arrays.asList(engineParameters).contains("barchart")) { chartType = ChartType.BAR;/* w w w .jav a 2 s. c o m*/ } else { chartType = ChartType.PIE; } if (Arrays.asList(engineParameters).contains("legend")) { legendOn = true; } if (Arrays.asList(engineParameters).contains("r")) { useR = true; } localSettings = CanRegClientApp.getApplication().getLocalSettings(); rpath = localSettings.getProperty(LocalSettings.R_PATH); // does R exist? if (rpath == null || rpath.isEmpty() || !new File(rpath).exists()) { useR = false; // force false if R is not installed } icd10GroupDescriptions = ConfigFieldsReader.findConfig("ICD10_groups", configList); cancerGroupsLocal = EditorialTableTools.generateICD10Groups(icd10GroupDescriptions); // indexes keyGroupsMap = new EnumMap<KeyCancerGroupsEnum, Integer>(KeyCancerGroupsEnum.class); keyGroupsMap.put(KeyCancerGroupsEnum.allCancerGroupsIndex, EditorialTableTools.getICD10index("ALL", icd10GroupDescriptions)); keyGroupsMap.put(KeyCancerGroupsEnum.skinCancerGroupIndex, EditorialTableTools.getICD10index("C44", icd10GroupDescriptions)); keyGroupsMap.put(KeyCancerGroupsEnum.otherCancerGroupsIndex, EditorialTableTools.getICD10index("O&U", icd10GroupDescriptions)); keyGroupsMap.put(KeyCancerGroupsEnum.allCancerGroupsButSkinIndex, EditorialTableTools.getICD10index("ALLbC44", icd10GroupDescriptions)); skinCancerGroupIndex = keyGroupsMap.get(KeyCancerGroupsEnum.skinCancerGroupIndex); allCancerGroupsIndex = keyGroupsMap.get(KeyCancerGroupsEnum.allCancerGroupsIndex); allCancerGroupsButSkinIndex = keyGroupsMap.get(KeyCancerGroupsEnum.allCancerGroupsButSkinIndex); otherCancerGroupsIndex = keyGroupsMap.get(KeyCancerGroupsEnum.otherCancerGroupsIndex); numberOfCancerGroups = cancerGroupsLocal.length; int columnToCount = allCancerGroupsIndex; List<AgeGroup> ageGroups = new LinkedList<AgeGroup>(); // TODO: Make these dynamic? ageGroups.add(new AgeGroup(0, 14)); ageGroups.add(new AgeGroup(15, 29)); ageGroups.add(new AgeGroup(30, 49)); ageGroups.add(new AgeGroup(50, 69)); ageGroups.add(new AgeGroup(70, null)); double[] casesLine; if (incidenceData != null) { String sexString, icdString; String morphologyString; double casesArray[][][] = new double[numberOfSexes][ageGroups.size()][numberOfCancerGroups]; double cum64Array[][][] = new double[numberOfSexes][ageGroups.size()][numberOfCancerGroups]; double cum74Array[][][] = new double[numberOfSexes][ageGroups.size()][numberOfCancerGroups]; double asrArray[][][] = new double[numberOfSexes][ageGroups.size()][numberOfCancerGroups]; int sex, icdIndex, cases, age; List<Integer> dontCount = new LinkedList<Integer>(); // all sites but skin? if (Arrays.asList(engineParameters).contains("noC44")) { dontCount.add(skinCancerGroupIndex); tableHeader += ", excluding C44"; columnToCount = allCancerGroupsButSkinIndex; } for (Object[] dataLine : incidenceData) { // Set default icdIndex = -1; cases = 0; age = 0; // Extract data sexString = (String) dataLine[SEX_COLUMN]; sex = Integer.parseInt(sexString.trim()); // sex = 3 is unknown sex if (sex > 2) { sex = 3; } else { sex -= 1; // sex 1 male maps to column 0... } morphologyString = (String) dataLine[MORPHOLOGY_COLUMN]; icdString = (String) dataLine[ICD10_COLUMN]; icdIndex = Tools.assignICDGroupIndex(keyGroupsMap, icdString, morphologyString, cancerGroupsLocal); if (!dontCount.contains(icdIndex) && icdIndex != DONT_COUNT) { // Extract cases cases = (Integer) dataLine[CASES_COLUMN]; age = (Integer) dataLine[AGE_COLUMN]; for (int group = 0; group < ageGroups.size(); group++) { if (ageGroups.get(group).fitsInAgeGroup(age)) { if (sex <= numberOfSexes && icdIndex >= 0) { casesArray[sex][group][icdIndex] += cases; } else { if (otherCancerGroupsIndex >= 0) { casesArray[sex][group][otherCancerGroupsIndex] += cases; } } if (allCancerGroupsIndex >= 0) { casesArray[sex][group][allCancerGroupsIndex] += cases; } if (allCancerGroupsButSkinIndex >= 0 && skinCancerGroupIndex >= 0 && icdIndex != skinCancerGroupIndex) { casesArray[sex][group][allCancerGroupsButSkinIndex] += cases; } } } } else { // System.out.println("Not counted: " + icdString + "/" + morphologyString); } } //if (populations != null && populations.length > 0) { // // calculate pops // for (PopulationDataset pop : populations) { // for (AgeGroup ag : ageGroups) { // try { // addPopulationDataSetToAgeGroup(pop, ag); // } catch (IncompatiblePopulationDataSetException ex) { // Logger.getLogger(CasesByAgeGroupChartTableBuilder.class.getName()).log(Level.SEVERE, null, ex); // } // } // } // } format = NumberFormat.getInstance(); format.setMaximumFractionDigits(1); for (int sexNumber : new int[] { 0, 1 }) { String fileName = reportFileName + "-" + sexLabel[sexNumber] + "." + fileType.toString(); File file = new File(fileName); List<CancerCasesCount> casesCounts = new LinkedList<CancerCasesCount>(); Double total = 0.0; for (int group = 0; group < ageGroups.size(); group++) { CancerCasesCount thisElement = new CancerCasesCount(null, ageGroups.get(group).toString(), 0.0, group); casesLine = casesArray[sexNumber][group]; thisElement.setCount(thisElement.getCount() + casesLine[columnToCount]); total += casesLine[columnToCount]; casesCounts.add(thisElement); } if (useR && !fileType.equals(FileTypes.jchart) && !fileType.equals(FileTypes.csv)) { String header = tableHeader + ", \n" + TableBuilderInterface.sexLabel[sexNumber]; generatedFiles.addAll(Tools.generateRChart(casesCounts, fileName, header, fileType, chartType, false, 0.0, rpath, false, "Age Group")); } else { Color color; if (sexNumber == 0) { color = Color.BLUE; } else { color = Color.RED; } String header = tableHeader + ", " + TableBuilderInterface.sexLabel[sexNumber]; charts[sexNumber] = Tools.generateJChart(casesCounts, fileName, header, fileType, chartType, false, legendOn, 0.0, total, color, "Age Group"); try { generatedFiles.add(Tools.writeJChartToFile(charts[sexNumber], file, fileType)); } catch (IOException ex) { Logger.getLogger(TopNChartTableBuilder.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(TopNChartTableBuilder.class.getName()).log(Level.SEVERE, null, ex); } } } } return generatedFiles; }
From source file:ImageBouncer.java
public AnimationFrame(ImageBouncer ac) { super();//from ww w . j a v a 2 s. co m setLayout(new BorderLayout()); add(ac, BorderLayout.CENTER); add(mStatusLabel = new Label(), BorderLayout.SOUTH); // Create a number formatter. mFormat = NumberFormat.getInstance(); mFormat.setMaximumFractionDigits(1); // Listen for the frame rate changes. ac.setRateListener(this); // Kick off the animation. Thread t = new Thread(ac); t.start(); }
From source file:javacommon.excel.ExcelReader.java
/** * ???/* w w w .j a va 2 s . c o m*/ * * @param c ? * @return */ private String getCellStringFormatValue(Cell c) { if (c == null) { return ""; } String value = null; NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(12); switch (c.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(c.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(c)) { return DateFormatUtils.ISO_DATE_FORMAT.format(c.getDateCellValue()); } else if ("@".equals(c.getCellStyle().getDataFormatString())) { value = nf.format(c.getNumericCellValue()); } else if ("General".equals(c.getCellStyle().getDataFormatString())) { value = nf.format(c.getNumericCellValue()); } else if (ArrayUtils.contains(ExcelConstants.DATE_PATTERNS, c.getCellStyle().getDataFormatString())) { value = DateFormatUtils.format(HSSFDateUtil.getJavaDate(c.getNumericCellValue()), c.getCellStyle().getDataFormatString()); } else { value = nf.format(c.getNumericCellValue()); } break; case Cell.CELL_TYPE_STRING: value = c.getStringCellValue(); break; case Cell.CELL_TYPE_FORMULA: return c.getCellFormula(); } return value == null ? "" : value.trim(); }
From source file:org.davidmendoza.esu.web.admin.ArticuloController.java
private void inicializaPublicacion(Model model, Publicacion publicacion) { List<Integer> anios = new ArrayList<>(); for (int i = (publicacion.getAnio() + 1); i >= 2011; i--) { anios.add(i);//from w ww .j av a 2 s . c o m } model.addAttribute("anios", anios); List<String> trimestres = new ArrayList<>(); trimestres.add("t1"); trimestres.add("t2"); trimestres.add("t3"); trimestres.add("t4"); model.addAttribute("trimestres", trimestres); NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumIntegerDigits(2); List<String> lecciones = new ArrayList<>(); for (int i = 1; i < 15; i++) { lecciones.add("l" + nf.format(i)); } model.addAttribute("lecciones", lecciones); List<String> temas = new ArrayList<>(); temas.add("tema1"); temas.add("tema2"); temas.add("tema3"); temas.add("tema4"); temas.add("tema5"); model.addAttribute("temas", temas); List<String> tipos = new ArrayList<>(); tipos.add("comunica"); tipos.add("dialoga"); tipos.add("leccion"); tipos.add("versiculo"); tipos.add("video"); tipos.add("imagen"); tipos.add("jovenes"); tipos.add("podcast"); model.addAttribute("tipos", tipos); List<String> dias = new ArrayList<>(); dias.add("domingo"); dias.add("lunes"); dias.add("martes"); dias.add("miercoles"); dias.add("jueves"); dias.add("viernes"); dias.add("sabado"); model.addAttribute("dias", dias); List<String> estados = new ArrayList<>(); estados.add("PUBLICADO"); estados.add("PENDIENTE"); estados.add("RECHAZADO"); model.addAttribute("estados", estados); }
From source file:chibi.gemmaanalysis.OutlierDetectionTestCli.java
/*** Write results to the output file; file name must be given as argument ***/ private void writeResultsToFileCombined(BufferedWriter bw, ExpressionExperiment ee, OutlierDetectionTestDetails testDetails) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(4);/*www . ja va 2s . co m*/ try { // Get information about the experiment: ee = this.eeService.thawLite(ee); System.out.println("Writing results to file for " + ee.getShortName()); bw.write(ee.getShortName()); bw.write("\t" + getPlatforms(ee)); bw.write("\t" + testDetails.getNumExpFactors()); if (useRegression) { bw.write("\t" + testDetails.getNumSigFactors()); } bw.write("\t" + ee.getBioAssays().size()); bw.write("\t" + testDetails.getNumRemoved()); bw.write("\t" + testDetails.getNumOutliersBasicAlgorithm()); bw.write("\t" + testDetails.getNumOutliersByMedian()); bw.write("\t" + testDetails.getNumOutliers()); // Get information about each of the outliers for (OutlierDetails outlier : testDetails.getOutliers()) { bw.write("\t" + outlier.getBioAssay().getName()); } if (useRegression) { for (ExperimentalFactor factor : testDetails.getSignificantFactors()) { bw.write("\t" + factor.getName()); } } bw.newLine(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.cebitec.readXplorer.util.GeneralUtils.java
/** * format a number to show it to the user * @param number/*from w w w . ja va 2 s. c om*/ * @return a good readable string representation of the given number */ public static String formatNumber(Number number) { return NumberFormat.getInstance().format(number); }
From source file:au.org.theark.lims.web.component.biospecimen.batchcreate.form.AutoGenBatchCreateBiospecimenForm.java
/** * /* w w w. j ava 2 s . com*/ * @return the listEditor of BatchBiospecimen(s) */ public AbstractListEditor<BatchBiospecimenVO> buildListEditor() { listEditor = new AbstractListEditor<BatchBiospecimenVO>("batchBiospecimenList", new PropertyModel(this, "batchBiospecimenList")) { private static final long serialVersionUID = 1L; @SuppressWarnings("serial") @Override protected void onPopulateItem(final ListItem<BatchBiospecimenVO> item) { item.setOutputMarkupId(true); item.getModelObject().getBiospecimen() .setLinkSubjectStudy(cpModel.getObject().getLinkSubjectStudy()); item.getModelObject().getBiospecimen() .setStudy(cpModel.getObject().getLinkSubjectStudy().getStudy()); numberToCreateTxtFld = new TextField<Number>("numberToCreate", new PropertyModel(item.getModelObject(), "numberToCreate")); initBioCollectionDdc(item); initSampleTypeDdc(item); sampleDateTxtFld = new DateTextField("biospecimen.sampleDate", new PropertyModel(item.getModelObject(), "biospecimen.sampleDate"), au.org.theark.core.Constants.DD_MM_YYYY); ArkDatePicker sampleDatePicker = new ArkDatePicker(); sampleDatePicker.bind(sampleDateTxtFld); sampleDateTxtFld.add(sampleDatePicker); quantityTxtFld = new TextField<Double>("biospecimen.quantity", new PropertyModel(item.getModelObject(), "biospecimen.quantity")) { private static final long serialVersionUID = 1L; @Override public <C> IConverter<C> getConverter(Class<C> type) { DoubleConverter doubleConverter = new DoubleConverter(); NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMinimumFractionDigits(1); doubleConverter.setNumberFormat(getLocale(), numberFormat); return (IConverter<C>) doubleConverter; } }; initUnitDdc(item); initTreatmentTypeDdc(item); concentrationTxtFld = new TextField<Number>("biospecimen.concentration", new PropertyModel(item.getModelObject(), "biospecimen.concentration")); // Added onchange events to ensure model updated when any change made item.add(numberToCreateTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(bioCollectionDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(sampleTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(sampleDateTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(quantityTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(unitDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(treatmentTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(concentrationTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); // Copy button allows entire row details to be copied item.add(new AjaxEditorButton(Constants.COPY) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { BatchBiospecimenVO batchBiospecimenVo = new BatchBiospecimenVO(); try { batchBiospecimenVo.setNumberToCreate(item.getModelObject().getNumberToCreate()); PropertyUtils.copyProperties(batchBiospecimenVo.getBiospecimen(), item.getModelObject().getBiospecimen()); listEditor.addItem(batchBiospecimenVo); target.add(form); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } }.setDefaultFormProcessing(false)); item.add(new AjaxEditorButton(Constants.DELETE) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { listEditor.removeItem(item); target.add(form); } }.setDefaultFormProcessing(false).setVisible(item.getIndex() > 0)); item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() { private static final long serialVersionUID = 1L; @Override public String getObject() { return (item.getIndex() % 2 == 1) ? Constants.EVEN : Constants.ODD; } })); } }; return listEditor; }
From source file:au.org.theark.lims.web.component.biospecimen.batchcreate.form.ManualBatchCreateBiospecimenForm.java
/** * /*from ww w . ja v a 2 s . co m*/ * @return the listEditor of BatchBiospecimen(s) */ public AbstractListEditor<BatchBiospecimenVO> buildListEditor() { listEditor = new AbstractListEditor<BatchBiospecimenVO>("batchBiospecimenList", new PropertyModel(this, "batchBiospecimenList")) { private static final long serialVersionUID = 1L; @SuppressWarnings("serial") @Override protected void onPopulateItem(final ListItem<BatchBiospecimenVO> item) { item.setOutputMarkupId(true); item.getModelObject().getBiospecimen() .setLinkSubjectStudy(cpModel.getObject().getLinkSubjectStudy()); item.getModelObject().getBiospecimen() .setStudy(cpModel.getObject().getLinkSubjectStudy().getStudy()); biospecimenUidTxtFld = new TextField<String>("biospecimen.biospecimenUid", new PropertyModel(item.getModelObject(), "biospecimen.biospecimenUid")); initBioCollectionDdc(item); initSampleTypeDdc(item); sampleDateTxtFld = new DateTextField("biospecimen.sampleDate", new PropertyModel(item.getModelObject(), "biospecimen.sampleDate"), au.org.theark.core.Constants.DD_MM_YYYY); ArkDatePicker sampleDatePicker = new ArkDatePicker(); sampleDatePicker.bind(sampleDateTxtFld); sampleDateTxtFld.add(sampleDatePicker); quantityTxtFld = new TextField<Double>("biospecimen.quantity", new PropertyModel(item.getModelObject(), "biospecimen.quantity")) { private static final long serialVersionUID = 1L; @Override public <C> IConverter<C> getConverter(Class<C> type) { DoubleConverter doubleConverter = new DoubleConverter(); NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMinimumFractionDigits(1); doubleConverter.setNumberFormat(getLocale(), numberFormat); return (IConverter<C>) doubleConverter; } }; initUnitDdc(item); initTreatmentTypeDdc(item); concentrationTxtFld = new TextField<Number>("biospecimen.concentration", new PropertyModel(item.getModelObject(), "biospecimen.concentration")); // Added onchange events to ensure model updated when any change made item.add(biospecimenUidTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { // Check BiospecimenUID is unique String biospecimenUid = (getComponent().getDefaultModelObject().toString() != null ? getComponent().getDefaultModelObject().toString() : new String()); Biospecimen biospecimen = iLimsService.getBiospecimenByUid(biospecimenUid, item.getModelObject().getBiospecimen().getStudy()); if (biospecimen != null && biospecimen.getId() != null) { ManualBatchCreateBiospecimenForm.this .error("Biospecimen UID must be unique. Please try again."); target.focusComponent(getComponent()); } target.add(feedbackPanel); } })); item.add(bioCollectionDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(sampleTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(sampleDateTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(quantityTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(unitDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(treatmentTypeDdc.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); item.add(concentrationTxtFld.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } })); // Copy button allows entire row details to be copied item.add(new AjaxEditorButton(Constants.COPY) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { BatchBiospecimenVO batchBiospecimenVo = new BatchBiospecimenVO(); try { PropertyUtils.copyProperties(batchBiospecimenVo.getBiospecimen(), item.getModelObject().getBiospecimen()); batchBiospecimenVo.getBiospecimen().setBiospecimenUid(new String()); listEditor.addItem(batchBiospecimenVo); target.add(form); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } }.setDefaultFormProcessing(false)); item.add(new AjaxEditorButton(Constants.DELETE) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { listEditor.removeItem(item); target.add(form); } }.setDefaultFormProcessing(false).setVisible(item.getIndex() > 0)); item.add(new AttributeModifier(Constants.CLASS, new AbstractReadOnlyModel() { private static final long serialVersionUID = 1L; @Override public String getObject() { return (item.getIndex() % 2 == 1) ? Constants.EVEN : Constants.ODD; } })); } }; return listEditor; }
From source file:com.fa.mastodon.activity.AccountActivity.java
private void onObtainAccountSuccess(Account account) { loadedAccount = account;/*from w ww.ja v a 2s . co m*/ TextView username = (TextView) findViewById(R.id.account_username); TextView displayName = (TextView) findViewById(R.id.account_display_name); TextView note = (TextView) findViewById(R.id.account_note); String usernameFormatted = String.format(getString(R.string.status_username_format), account.username); username.setText(usernameFormatted); displayName.setText(account.getDisplayName()); boolean useCustomTabs = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("customTabs", true); LinkHelper.setClickableText(note, account.note, null, useCustomTabs, new LinkListener() { @Override public void onViewTag(String tag) { Intent intent = new Intent(AccountActivity.this, ViewTagActivity.class); intent.putExtra("hashtag", tag); startActivity(intent); } @Override public void onViewAccount(String id) { Intent intent = new Intent(AccountActivity.this, AccountActivity.class); intent.putExtra("id", id); startActivity(intent); } }); if (account.locked) { accountLockedView.setVisibility(View.VISIBLE); } else { accountLockedView.setVisibility(View.GONE); } Picasso.with(this).load(account.avatar).placeholder(R.drawable.avatar_default) .error(R.drawable.avatar_error).into(avatar); Picasso.with(this).load(account.header).placeholder(R.drawable.account_header_default).into(header); NumberFormat nf = NumberFormat.getInstance(); // Add counts to the tabs in the TabLayout. String[] counts = { nf.format(Integer.parseInt(account.statusesCount)), nf.format(Integer.parseInt(account.followingCount)), nf.format(Integer.parseInt(account.followersCount)), }; for (int i = 0; i < tabLayout.getTabCount(); i++) { TabLayout.Tab tab = tabLayout.getTabAt(i); if (tab != null) { View view = tab.getCustomView(); if (view != null) { TextView total = (TextView) view.findViewById(R.id.total); total.setText(counts[i]); } } } }