List of usage examples for java.text NumberFormat getIntegerInstance
public static final NumberFormat getIntegerInstance()
From source file:org.kuali.rice.krad.util.KRADUtils.java
/** * Convert the given money amount into an integer string. * * <p>/*from w w w .j av a 2 s. c o m*/ * Since the return string cannot have decimal point, multiplies the amount by 100 so the decimal places * are not lost, for example, 320.15 is converted into 32015. * </p> * * @param decimalNumber decimal number to be converted * @return an integer string of the given money amount through multiplying by 100 and removing the fraction * portion. */ public final static String convertDecimalIntoInteger(KualiDecimal decimalNumber) { KualiDecimal decimalAmount = decimalNumber.multiply(ONE_HUNDRED); NumberFormat formatter = NumberFormat.getIntegerInstance(); String formattedAmount = formatter.format(decimalAmount); return StringUtils.replace(formattedAmount, ",", ""); }
From source file:savant.chromatogram.ChromatogramPlugin.java
/** * The start field has changed or a chromatogram has been loaded. Update the end field appropriately. *//*from w ww.j a v a2 s. c om*/ private void updateEndField() { try { NumberFormat numberParser = NumberFormat.getIntegerInstance(); int startBase = numberParser.parse(startField.getText()).intValue(); if (chromatogram != null) { endField.setText(String.valueOf(startBase + chromatogram.getSequenceLength())); if (canvas != null) { canvas.updatePos(startBase); } } } catch (ParseException x) { Toolkit.getDefaultToolkit().beep(); } }
From source file:com.smedic.tubtub.YouTubeSearch.java
/** * Search videos for a specific query/*from w ww . j a v a 2 s. c o m*/ * * @param keywords - query */ public void searchVideos(final String keywords) { new Thread() { public void run() { try { youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { } }).setApplicationName(appName).build(); YouTube.Search.List searchList; YouTube.Videos.List videosList; searchList = youtube.search().list("id,snippet"); searchList.setKey(Config.YOUTUBE_API_KEY); searchList.setType("video"); //TODO ADD PLAYLISTS SEARCH searchList.setMaxResults(Config.NUMBER_OF_VIDEOS_RETURNED); searchList.setFields("items(id/videoId,snippet/title,snippet/thumbnails/default/url)"); videosList = youtube.videos().list("id,contentDetails,statistics"); videosList.setKey(Config.YOUTUBE_API_KEY); videosList.setFields("items(contentDetails/duration,statistics/viewCount)"); //search searchList.setQ(keywords); SearchListResponse searchListResponse = searchList.execute(); List<SearchResult> searchResults = searchListResponse.getItems(); //save all ids from searchList list in order to find video list StringBuilder contentDetails = new StringBuilder(); int ii = 0; for (SearchResult result : searchResults) { contentDetails.append(result.getId().getVideoId()); if (ii < 49) contentDetails.append(","); ii++; } //find video list videosList.setId(contentDetails.toString()); VideoListResponse resp = videosList.execute(); List<Video> videoResults = resp.getItems(); //make items for displaying in listView ArrayList<YouTubeVideo> items = new ArrayList<>(); for (int i = 0; i < searchResults.size(); i++) { YouTubeVideo item = new YouTubeVideo(); //searchList list info item.setTitle(searchResults.get(i).getSnippet().getTitle()); item.setThumbnailURL( searchResults.get(i).getSnippet().getThumbnails().getDefault().getUrl()); item.setId(searchResults.get(i).getId().getVideoId()); //video info if (videoResults.get(i) != null) { BigInteger viewsNumber = videoResults.get(i).getStatistics().getViewCount(); String viewsFormatted = NumberFormat.getIntegerInstance().format(viewsNumber) + " views"; item.setViewCount(viewsFormatted); String isoTime = videoResults.get(i).getContentDetails().getDuration(); String time = Utils.convertISO8601DurationToNormalTime(isoTime); item.setDuration(time); } else { item.setDuration("NA"); } //add to the list items.add(item); } youTubeVideosReceiver.onVideosReceived(items); } catch (IOException e) { Log.e(TAG, "Could not initialize: " + e); e.printStackTrace(); return; } } }.start(); }
From source file:scrum.server.common.BurndownChart.java
private static JFreeChart createSprintBurndownChart(List<BurndownSnapshot> snapshots, Date firstDay, Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int dateMarkTickUnit, float widthPerDay) { DefaultXYDataset data = createSprintBurndownChartDataset(snapshots, firstDay, lastDay, originallyLastDay, freeDays);/*from w w w . j a v a 2 s . c om*/ double tick = 1.0; double max = BurndownChart.getMaximum(data); while (max / tick > 25) { tick *= 2; if (max / tick <= 25) break; tick *= 2.5; if (max / tick <= 25) break; tick *= 2; } double valueLabelTickUnit = tick; double upperBoundary = Math.min(max * 1.1f, max + 3); if (!Sys.isHeadless()) LOG.warn("GraphicsEnvironment is not headless"); JFreeChart chart = ChartFactory.createXYLineChart("", "", "", data, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = chart.getXYPlot(); // plot.setInsets(new RectangleInsets(0, 0, 0, 0)); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); // plot.setOutlineVisible(false); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainGridlinePaint(Color.lightGray); // plot.setRangeCrosshairPaint(Color.lightGray); // plot.setRangeMinorGridlinePaint(Color.lightGray); // plot.setDomainCrosshairPaint(Color.blue); // plot.setDomainMinorGridlinePaint(Color.green); // plot.setDomainTickBandPaint(Color.green); XYItemRenderer renderer = plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2f)); renderer.setSeriesPaint(0, COLOR_PAST_LINE); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer.setSeriesPaint(1, COLOR_PROJECTION_LINE); renderer.setSeriesStroke(1, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 3f }, 0)); renderer.setSeriesPaint(2, COLOR_OPTIMUM_LINE); renderer.setSeriesStroke(2, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); DateAxis domainAxis1 = new DateAxis(); String dateFormat = "d."; widthPerDay -= 5; if (widthPerDay > 40) { dateFormat = "EE " + dateFormat; } if (widthPerDay > 10) { float spaces = widthPerDay / 2.7f; dateFormat = Str.multiply(" ", (int) spaces) + dateFormat; } domainAxis1.setDateFormatOverride(new SimpleDateFormat(dateFormat, Locale.US)); domainAxis1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, dateMarkTickUnit)); domainAxis1.setAxisLineVisible(false); Range range = new Range(firstDay.toMillis(), lastDay.nextDay().toMillis()); domainAxis1.setRange(range); DateAxis domainAxis2 = new DateAxis(); domainAxis2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1)); domainAxis2.setTickMarksVisible(false); domainAxis2.setTickLabelsVisible(false); domainAxis2.setRange(range); plot.setDomainAxis(0, domainAxis2); plot.setDomainAxis(1, domainAxis1); plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance()); rangeAxis.setTickUnit(new NumberTickUnit(valueLabelTickUnit)); rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(upperBoundary); plot.setRangeAxis(rangeAxis); return chart; }
From source file:pcgen.gui2.tabs.SummaryInfoTab.java
SummaryInfoTab() { this.tabTitle = new TabTitle(Tab.SUMMARY); this.basicsPanel = new JPanel(); this.todoPanel = new JPanel(); this.scoresPanel = new JPanel(); this.racePanel = new JPanel(); this.classPanel = new JPanel(); this.characterNameField = new JTextField(); this.characterTypeComboBox = new JComboBox<>(); this.random = new JButton(); FontManipulation.xsmall(random);/*from w w w.j av a 2 s . co m*/ this.playerNameField = new JTextField(); this.expField = new JFormattedTextField(NumberFormat.getIntegerInstance()); this.nextlevelField = new JFormattedTextField(NumberFormat.getIntegerInstance()); this.xpTableComboBox = new JComboBox<>(); this.expmodField = new JFormattedTextField(NumberFormat.getIntegerInstance()); this.addLevelsField = new JFormattedTextField(NumberFormat.getIntegerInstance()); this.removeLevelsField = new JFormattedTextField(NumberFormat.getIntegerInstance()); this.statsTable = new JTable(); this.classLevelTable = new JTable(); this.languageTable = new JTable(); this.genderComboBox = new JComboBox<>(); this.handsComboBox = new JComboBox<>(); this.alignmentComboBox = new JComboBox<>(); this.deityComboBox = new JComboBox<>(); this.raceComboBox = new JComboBox<>(); this.ageComboBox = new JComboBox<>(); this.classComboBox = new JComboBox<>(); this.tabLabelField = new JTextField(); this.ageField = new JFormattedTextField(NumberFormat.getIntegerInstance()); this.generateRollsButton = new JButton(); this.rollMethodButton = new JButton(); this.createMonsterButton = new JButton(); this.addLevelsButton = new JButton(); this.removeLevelsButton = new JButton(); this.expaddButton = new JButton(); this.expsubtractButton = new JButton(); this.hpButton = new JButton(); this.totalHPLabel = new JLabel(); this.infoPane = new JEditorPane(); this.statTotalLabel = new JLabel(); this.statTotal = new JLabel(); this.modTotalLabel = new JLabel(); this.modTotal = new JLabel(); this.todoPane = new JEditorPane(); this.infoBoxRenderer = new InfoBoxRenderer(); this.classBoxRenderer = new ClassBoxRenderer(); initComponents(); }
From source file:android.support.v7.app.NotificationCompatImplBase.java
private static RemoteViews applyStandardTemplate(Context context, CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, int resId, boolean fitIn1U) { RemoteViews contentView = new RemoteViews(context.getPackageName(), resId); boolean showLine3 = false; boolean showLine2 = false; // On versions before Jellybean, the large icon was shown by SystemUI, so we need to hide // it here./*from w w w. j av a2 s.c o m*/ if (largeIcon != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { contentView.setViewVisibility(R.id.icon, View.VISIBLE); contentView.setImageViewBitmap(R.id.icon, largeIcon); } else { contentView.setViewVisibility(R.id.icon, View.GONE); } if (contentTitle != null) { contentView.setTextViewText(R.id.title, contentTitle); } if (contentText != null) { contentView.setTextViewText(R.id.text, contentText); showLine3 = true; } if (contentInfo != null) { contentView.setTextViewText(R.id.info, contentInfo); contentView.setViewVisibility(R.id.info, View.VISIBLE); showLine3 = true; } else if (number > 0) { final int tooBig = context.getResources().getInteger(R.integer.status_bar_notification_info_maxnum); if (number > tooBig) { contentView.setTextViewText(R.id.info, context.getResources().getString(R.string.status_bar_notification_info_overflow)); } else { NumberFormat f = NumberFormat.getIntegerInstance(); contentView.setTextViewText(R.id.info, f.format(number)); } contentView.setViewVisibility(R.id.info, View.VISIBLE); showLine3 = true; } else { contentView.setViewVisibility(R.id.info, View.GONE); } // Need to show three lines? Only allow on Jellybean+ if (subText != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { contentView.setTextViewText(R.id.text, subText); if (contentText != null) { contentView.setTextViewText(R.id.text2, contentText); contentView.setViewVisibility(R.id.text2, View.VISIBLE); showLine2 = true; } else { contentView.setViewVisibility(R.id.text2, View.GONE); } } // RemoteViews.setViewPadding and RemoteViews.setTextViewTextSize is not available on ICS- if (showLine2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (fitIn1U) { // need to shrink all the type to make sure everything fits final Resources res = context.getResources(); final float subTextSize = res.getDimensionPixelSize(R.dimen.notification_subtext_size); contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); } // vertical centering contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); } if (when != 0) { if (useChronometer) { contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); contentView.setLong(R.id.chronometer, "setBase", when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); contentView.setBoolean(R.id.chronometer, "setStarted", true); } else { contentView.setViewVisibility(R.id.time, View.VISIBLE); contentView.setLong(R.id.time, "setTime", when); } } contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); return contentView; }
From source file:com.intuit.tank.notification.NotificationContextBuilder.java
private String formatInt(int i) { return NumberFormat.getIntegerInstance().format(i); }
From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java
public static void updateImageFont(JSONParcelable imageData, TextView imageScore) { try {//from w ww . j a v a 2 s. co m if (!imageData.getJSONObject().has("vote")) { imageScore.setVisibility(View.GONE); return; } if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("up")) imageScore.setText(Html.fromHtml("<font color=#89c624>" + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score")) + " points </font> (<font color=#89c624>" + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups")) + "</font>/<font color=#ee4444>" + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("downs")) + "</font>)")); else if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("down")) imageScore.setText(Html.fromHtml("<font color=#ee4444>" + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score")) + " points </font> (<font color=#89c624>" + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups")) + "</font>/<font color=#ee4444>" + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("downs")) + "</font>)")); else imageScore.setText(Html.fromHtml( NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score")) + " points (<font color=#89c624>" + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups")) + "</font>/<font color=#ee4444>" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt("downs")) + "</font>)")); } catch (JSONException e) { Log.e("Error font!", e.toString()); } }
From source file:com.newatlanta.appengine.servlet.GaeVfsServlet.java
/** * Return the directory listing for the specified GaeVFS folder. Copied from: * /*from w w w . j a va 2 s. c o m*/ * http://www.docjar.com/html/api/org/mortbay/util/Resource.java.html * * Modified to support GAE virtual file system. */ private String getListHTML(Path path) throws IOException { String title = "Directory: " + path.toString(); StringBuffer buf = new StringBuffer(4096); buf.append("<HTML><HEAD><TITLE>"); buf.append(title); buf.append("</TITLE></HEAD><BODY>\n<H1>"); buf.append(title); buf.append("</H1><TABLE BORDER='0' cellpadding='3'>"); if (path.getParent() != null) { buf.append("<TR><TD><A HREF='"); String parentPath = path.getParent().toString(); buf.append(parentPath); if (!parentPath.endsWith("/")) { buf.append("/"); } buf.append("'>Parent Directory</A></TD><TD></TD><TD></TD></TR>\n"); } Iterator<Path> children = path.newDirectoryStream().iterator(); if (!children.hasNext()) { buf.append("<TR><TD>[empty directory]</TD></TR>\n"); } else { NumberFormat nfmt = NumberFormat.getIntegerInstance(); buf.append("<tr><th align='left'>Name</th><th>Size</th>" + "<th aligh='left'>Type</th><th align='left'>Date modified</th></tr>"); while (children.hasNext()) { Path child = children.next(); buf.append("<TR><TD><A HREF=\"").append(child).append("\">"); buf.append(escapeHtml(child.getName().toString())); BasicFileAttributes childAttrs = readBasicFileAttributes(child); if (childAttrs.isDirectory()) { buf.append('/'); } buf.append("</TD><TD ALIGN=right>"); if (childAttrs.isRegularFile()) { buf.append(nfmt.format(childAttrs.size())).append(" bytes"); } buf.append("</TD><TD>"); buf.append(childAttrs.isDirectory() ? "directory" : "file"); buf.append("</TD><TD>"); buf.append(childAttrs.lastModifiedTime()); buf.append("</TD></TR>\n"); } } buf.append("</TABLE>\n"); buf.append("</BODY></HTML>\n"); return buf.toString(); }
From source file:de.cismet.cids.custom.utils.berechtigungspruefung.BerechtigungspruefungHandler.java
/** * DOCUMENT ME!/*from w ww. ja v a 2 s. c o m*/ * * @param user DOCUMENT ME! * @param downloadInfo DOCUMENT ME! * * @return DOCUMENT ME! */ public String createNewSchluessel(final User user, final BerechtigungspruefungDownloadInfo downloadInfo) { synchronized (this) { final String type; if (BerechtigungspruefungBescheinigungDownloadInfo.PRODUKT_TYP.equals(downloadInfo.getProduktTyp())) { type = "BlaB"; } else if (BerechtigungspruefungAlkisDownloadInfo.PRODUKT_TYP.equals(downloadInfo.getProduktTyp())) { type = "LB"; } else { type = "?"; } final int year = Calendar.getInstance().get(Calendar.YEAR); final CidsBean lastAnfrageBean = loadLastAnfrageBeanByTypeAndYear(user, type, year); final String lastAnfrageSchluessel = (lastAnfrageBean != null) ? (String) lastAnfrageBean.getProperty("schluessel") : null; final int lastNumber; if (lastAnfrageSchluessel != null) { final Pattern pattern = Pattern.compile("^" + type + "-" + year + "-(\\d{5})$"); final Matcher matcher = pattern.matcher(lastAnfrageSchluessel); if (matcher.matches()) { final String group = matcher.group(1); lastNumber = (group != null) ? Integer.parseInt(group) : 0; } else { lastNumber = 0; } } else { lastNumber = 0; } final int newNumber = lastNumber + 1; final NumberFormat format = NumberFormat.getIntegerInstance(); format.setMinimumIntegerDigits(5); format.setGroupingUsed(false); final String newAnfrageSchluessel = type + "-" + Integer.toString(year) + "-" + format.format(newNumber); return newAnfrageSchluessel; } }