List of usage examples for java.text DecimalFormatSymbols getInstance
public static final DecimalFormatSymbols getInstance(Locale locale)
From source file:net.sf.jasperreports.charts.util.ChartUtil.java
public TickUnitSource createStandardTickUnits(Locale locale) { DecimalFormatSymbols formatSymbols = DecimalFormatSymbols.getInstance(locale); //copied from NumberAxis.createStandardTickUnits() to preserve backward behaviour TickUnits units = new TickUnits(); DecimalFormat df0 = new DecimalFormat("0.00000000", formatSymbols); DecimalFormat df1 = new DecimalFormat("0.0000000", formatSymbols); DecimalFormat df2 = new DecimalFormat("0.000000", formatSymbols); DecimalFormat df3 = new DecimalFormat("0.00000", formatSymbols); DecimalFormat df4 = new DecimalFormat("0.0000", formatSymbols); DecimalFormat df5 = new DecimalFormat("0.000", formatSymbols); DecimalFormat df6 = new DecimalFormat("0.00", formatSymbols); DecimalFormat df7 = new DecimalFormat("0.0", formatSymbols); DecimalFormat df8 = new DecimalFormat("#,##0", formatSymbols); //these two are probably not needed DecimalFormat df9 = new DecimalFormat("#,###,##0", formatSymbols); DecimalFormat df10 = new DecimalFormat("#,###,###,##0", formatSymbols); // we can add the units in any order, the TickUnits collection will // sort them... units.add(new NumberTickUnit(0.0000001, df1)); units.add(new NumberTickUnit(0.000001, df2)); units.add(new NumberTickUnit(0.00001, df3)); units.add(new NumberTickUnit(0.0001, df4)); units.add(new NumberTickUnit(0.001, df5)); units.add(new NumberTickUnit(0.01, df6)); units.add(new NumberTickUnit(0.1, df7)); units.add(new NumberTickUnit(1, df8)); units.add(new NumberTickUnit(10, df8)); units.add(new NumberTickUnit(100, df8)); units.add(new NumberTickUnit(1000, df8)); units.add(new NumberTickUnit(10000, df8)); units.add(new NumberTickUnit(100000, df8)); units.add(new NumberTickUnit(1000000, df9)); units.add(new NumberTickUnit(10000000, df9)); units.add(new NumberTickUnit(100000000, df9)); units.add(new NumberTickUnit(1000000000, df10)); units.add(new NumberTickUnit(10000000000.0, df10)); units.add(new NumberTickUnit(100000000000.0, df10)); units.add(new NumberTickUnit(0.00000025, df0)); units.add(new NumberTickUnit(0.0000025, df1)); units.add(new NumberTickUnit(0.000025, df2)); units.add(new NumberTickUnit(0.00025, df3)); units.add(new NumberTickUnit(0.0025, df4)); units.add(new NumberTickUnit(0.025, df5)); units.add(new NumberTickUnit(0.25, df6)); units.add(new NumberTickUnit(2.5, df7)); units.add(new NumberTickUnit(25, df8)); units.add(new NumberTickUnit(250, df8)); units.add(new NumberTickUnit(2500, df8)); units.add(new NumberTickUnit(25000, df8)); units.add(new NumberTickUnit(250000, df8)); units.add(new NumberTickUnit(2500000, df9)); units.add(new NumberTickUnit(25000000, df9)); units.add(new NumberTickUnit(250000000, df9)); units.add(new NumberTickUnit(2500000000.0, df10)); units.add(new NumberTickUnit(25000000000.0, df10)); units.add(new NumberTickUnit(250000000000.0, df10)); units.add(new NumberTickUnit(0.0000005, df1)); units.add(new NumberTickUnit(0.000005, df2)); units.add(new NumberTickUnit(0.00005, df3)); units.add(new NumberTickUnit(0.0005, df4)); units.add(new NumberTickUnit(0.005, df5)); units.add(new NumberTickUnit(0.05, df6)); units.add(new NumberTickUnit(0.5, df7)); units.add(new NumberTickUnit(5L, df8)); units.add(new NumberTickUnit(50L, df8)); units.add(new NumberTickUnit(500L, df8)); units.add(new NumberTickUnit(5000L, df8)); units.add(new NumberTickUnit(50000L, df8)); units.add(new NumberTickUnit(500000L, df8)); units.add(new NumberTickUnit(5000000L, df9)); units.add(new NumberTickUnit(50000000L, df9)); units.add(new NumberTickUnit(500000000L, df9)); units.add(new NumberTickUnit(5000000000L, df10)); units.add(new NumberTickUnit(50000000000L, df10)); units.add(new NumberTickUnit(500000000000L, df10)); // adding further values by default because 5E11 is not enough for some people units.add(new NumberTickUnit(1000000000000L, df8)); units.add(new NumberTickUnit(2500000000000L, df8)); units.add(new NumberTickUnit(5000000000000L, df8)); units.add(new NumberTickUnit(10000000000000L, df8)); units.add(new NumberTickUnit(25000000000000L, df8)); units.add(new NumberTickUnit(50000000000000L, df8)); units.add(new NumberTickUnit(100000000000000L, df8)); units.add(new NumberTickUnit(250000000000000L, df8)); units.add(new NumberTickUnit(500000000000000L, df8)); units.add(new NumberTickUnit(1000000000000000L, df8)); units.add(new NumberTickUnit(2500000000000000L, df8)); units.add(new NumberTickUnit(5000000000000000L, df8)); units.add(new NumberTickUnit(10000000000000000L, df8)); units.add(new NumberTickUnit(25000000000000000L, df8)); units.add(new NumberTickUnit(50000000000000000L, df8)); units.add(new NumberTickUnit(100000000000000000L, df8)); units.add(new NumberTickUnit(250000000000000000L, df8)); units.add(new NumberTickUnit(500000000000000000L, df8)); units.add(new NumberTickUnit(1000000000000000000L, df8)); units.add(new NumberTickUnit(2500000000000000000L, df8)); units.add(new NumberTickUnit(5000000000000000000L, df8)); return units; }
From source file:com.openbravo.pos.util.JRViewer400.java
/** * *///from ww w . ja v a 2 s.c om protected void initResources(Locale locale, ResourceBundle resBundle) { //FIXME in theory, the setLocale method could be called after current Component was created, in which case all below should be reloaded if (locale != null) { setLocale(locale); } else { setLocale(Locale.getDefault()); } if (resBundle == null) { this.resourceBundle = ResourceBundle.getBundle("net/sf/jasperreports/view/viewer", getLocale()); } else { this.resourceBundle = resBundle; } zoomDecimalFormat = new DecimalFormat("#.##", DecimalFormatSymbols.getInstance(getLocale())); }
From source file:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java
@Override protected JFreeChart createMeterChart() throws JRException { // Start by creating the plot that will hold the meter MeterPlot chartPlot = new MeterPlot((ValueDataset) getDataset()); JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // Set the shape MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.DIAL : jrPlot.getShapeValue(); switch (shape) { case CHORD:/* w w w .ja v a 2 s.c o m*/ chartPlot.setDialShape(DialShape.CHORD); break; case PIE: chartPlot.setDialShape(DialShape.PIE); break; case CIRCLE: chartPlot.setDialShape(DialShape.CIRCLE); break; case DIAL: default: return createDialChart(); } chartPlot.setDialOutlinePaint(Color.BLACK); int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger(); // Set the size of the meter chartPlot.setMeterAngle(meterAngle); // Set the spacing between ticks. I hate the name "tickSize" since to me it // implies I am changing the size of the tick, not the spacing between them. double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble(); chartPlot.setTickSize(tickInterval); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); chartPlot.setTickLabelFont(themeTickLabelFont); // localizing the default format, can be overridden by display.getMask() chartPlot.setTickLabelFormat(NumberFormat.getInstance(getLocale())); Color tickColor = jrPlot.getTickColor() == null ? Color.BLACK : jrPlot.getTickColor(); chartPlot.setTickPaint(tickColor); int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { // Set the meter's range chartPlot.setRange(range); double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); if ((range.getLowerBound() == (int) range.getLowerBound() && range.getUpperBound() == (int) range.getUpperBound() && tickInterval == (int) tickInterval) || dialUnitScale > 1) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale == 1) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0.0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale <= 0) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(getLocale()))); } } chartPlot.setTickLabelsVisible(true); // Set all the colors we support Paint backgroundPaint = jrPlot.getOwnBackcolor() == null ? ChartThemesConstants.TRANSPARENT_PAINT : jrPlot.getOwnBackcolor(); chartPlot.setBackgroundPaint(backgroundPaint); GradientPaint gp = new GradientPaint(new Point(), Color.LIGHT_GRAY, new Point(), Color.BLACK, false); if (jrPlot.getMeterBackgroundColor() != null) { chartPlot.setDialBackgroundPaint(jrPlot.getMeterBackgroundColor()); } else { chartPlot.setDialBackgroundPaint(gp); } //chartPlot.setForegroundAlpha(1f); Paint needlePaint = jrPlot.getNeedleColor() == null ? new Color(191, 48, 0) : jrPlot.getNeedleColor(); chartPlot.setNeedlePaint(needlePaint); JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { Color valueColor = display.getColor() == null ? Color.BLACK : display.getColor(); chartPlot.setValuePaint(valueColor); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) chartPlot.setTickLabelFormat( new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); JRFont displayFont = display.getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); if (themeDisplayFont != null) { chartPlot.setValueFont(themeDisplayFont); } } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); } // Set the units - this is just a string that will be shown next to the // value String units = jrPlot.getUnits() == null ? label : jrPlot.getUnits(); if (units != null && units.length() > 0) chartPlot.setUnits(units); chartPlot.setTickPaint(Color.BLACK); // Now define all of the intervals, setting their range and color List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); interval.setBackgroundColor(color); interval.setAlpha(1.0d); chartPlot.addInterval(convertInterval(interval)); } } // Actually create the chart around the plot JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:org.aludratest.testcase.data.impl.xml.XmlBasedTestDataProvider.java
private Object format(Object object, String formatPattern, Locale locale) { if (locale == null) { locale = Locale.US;/*from w w w . java 2 s. c o m*/ } if (object instanceof Date) { if (formatPattern == null) { formatPattern = "yyyy-MM-dd"; } SimpleDateFormat sdf = new SimpleDateFormat(formatPattern, locale); return sdf.format(object); } if (object instanceof Number) { if (formatPattern == null) { formatPattern = "#.#"; } DecimalFormat df = new DecimalFormat(formatPattern, DecimalFormatSymbols.getInstance(locale)); return df.format(object); } return object; }
From source file:org.structr.web.maintenance.DeployCommand.java
private void doImport(final Map<String, Object> attributes) throws FrameworkException { missingPrincipals.clear();// w ww .j a v a2 s . c o m final long startTime = System.currentTimeMillis(); customHeaders.put("start", new Date(startTime).toString()); final String path = (String) attributes.get("source"); final SecurityContext ctx = SecurityContext.getSuperUserInstance(); final App app = StructrApp.getInstance(ctx); ctx.setDoTransactionNotifications(false); ctx.disableEnsureCardinality(); ctx.disableModificationOfAccessTime(); final Map<String, Object> componentsConf = new HashMap<>(); final Map<String, Object> templatesConf = new HashMap<>(); final Map<String, Object> pagesConf = new HashMap<>(); final Map<String, Object> filesConf = new HashMap<>(); if (StringUtils.isBlank(path)) { throw new FrameworkException(422, "Please provide 'source' attribute for deployment source directory path."); } final Path source = Paths.get(path); if (!Files.exists(source)) { throw new FrameworkException(422, "Source path " + path + " does not exist."); } if (!Files.isDirectory(source)) { throw new FrameworkException(422, "Source path " + path + " is not a directory."); } final Map<String, Object> broadcastData = new HashMap(); broadcastData.put("type", DEPLOYMENT_IMPORT_STATUS); broadcastData.put("subtype", DEPLOYMENT_STATUS_BEGIN); broadcastData.put("start", startTime); broadcastData.put("source", source); TransactionCommand.simpleBroadcastGenericMessage(broadcastData); // apply configuration final Path preDeployConf = source.resolve("pre-deploy.conf"); if (Files.exists(preDeployConf)) { try (final Tx tx = app.tx()) { final String confSource = new String(Files.readAllBytes(preDeployConf), Charset.forName("utf-8")) .trim(); if (confSource.length() > 0) { info("Applying pre-deployment configuration from {}", preDeployConf); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Applying pre-deployment configuration"); Scripting.evaluate(new ActionContext(ctx), null, confSource, "pre-deploy.conf"); } else { info("Ignoring empty pre-deployment configuration {}", preDeployConf); } tx.success(); } catch (Throwable t) { logger.warn("", t); publishDeploymentWarningMessage("Exception caught while importing pre-deploy.conf", t.toString()); } } // backup previous value of change log setting // temporary disable creation of change log final boolean changeLogEnabled = Settings.ChangelogEnabled.getValue(); Settings.ChangelogEnabled.setValue(false); // read grants.json publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing resource access grants"); final Path grantsConf = source.resolve("security/grants.json"); if (Files.exists(grantsConf)) { info("Reading {}", grantsConf); importListData(ResourceAccess.class, readConfigList(grantsConf)); } // read schema-methods.json final Path schemaMethodsConf = source.resolve("schema-methods.json"); if (Files.exists(schemaMethodsConf)) { info("Reading {}", schemaMethodsConf); final String title = "Deprecation warning"; final String text = "Found file 'schema-methods.json'. Newer versions store global schema methods in the schema snapshot file. Recreate the export with the current version to avoid compatibility issues. Support for importing this file will be dropped in future versions."; info(title + ": " + text); publishDeploymentWarningMessage(title, text); importListData(SchemaMethod.class, readConfigList(schemaMethodsConf)); } // read mail-templates.json final Path mailTemplatesConf = source.resolve("mail-templates.json"); if (Files.exists(mailTemplatesConf)) { info("Reading {}", mailTemplatesConf); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing mail templates"); importListData(MailTemplate.class, readConfigList(mailTemplatesConf)); } // read widgets.json final Path widgetsConf = source.resolve("widgets.json"); if (Files.exists(widgetsConf)) { info("Reading {}", widgetsConf); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing widgets"); importListData(Widget.class, readConfigList(widgetsConf)); } // read localizations.json final Path localizationsConf = source.resolve("localizations.json"); if (Files.exists(localizationsConf)) { final PropertyMap additionalData = new PropertyMap(); // Question: shouldn't this be true? No, 'imported' is a flag for legacy-localization which // have been imported from a legacy-system which was replaced by structr. // it is a way to differentiate between new and old localization strings additionalData.put(StructrApp.key(Localization.class, "imported"), false); info("Reading {}", localizationsConf); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing localizations"); importListData(Localization.class, readConfigList(localizationsConf), additionalData); } // read files.conf final Path filesConfFile = source.resolve("files.json"); if (Files.exists(filesConfFile)) { info("Reading {}", filesConfFile); filesConf.putAll(readConfigMap(filesConfFile)); } // read pages.conf final Path pagesConfFile = source.resolve("pages.json"); if (Files.exists(pagesConfFile)) { info("Reading {}", pagesConfFile); pagesConf.putAll(readConfigMap(pagesConfFile)); } // read components.conf final Path componentsConfFile = source.resolve("components.json"); if (Files.exists(componentsConfFile)) { info("Reading {}", componentsConfFile); componentsConf.putAll(readConfigMap(componentsConfFile)); } // read templates.conf final Path templatesConfFile = source.resolve("templates.json"); if (Files.exists(templatesConfFile)) { info("Reading {}", templatesConfFile); templatesConf.putAll(readConfigMap(templatesConfFile)); } // import schema final Path schema = source.resolve("schema"); if (Files.exists(schema)) { try { info("Importing data from schema/ directory"); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing schema"); Files.walkFileTree(schema, new SchemaImportVisitor(schema)); } catch (IOException ioex) { logger.warn("Exception while importing schema", ioex); } } // import files final Path files = source.resolve("files"); if (Files.exists(files)) { try { info("Importing files (unchanged files will be skipped)"); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing files"); FileImportVisitor fiv = new FileImportVisitor(files, filesConf); Files.walkFileTree(files, fiv); fiv.handleDeferredFiles(); } catch (IOException ioex) { logger.warn("Exception while importing files", ioex); } } for (StructrModule module : StructrApp.getConfiguration().getModules().values()) { if (module.hasDeploymentData()) { info("Importing deployment data for module {}", module.getName()); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing deployment data for module " + module.getName()); final Path moduleFolder = source.resolve("modules/" + module.getName() + "/"); module.importDeploymentData(moduleFolder, getGson()); } } // construct paths final Path templates = source.resolve("templates"); final Path components = source.resolve("components"); final Path pages = source.resolve("pages"); final Path sitesConfFile = source.resolve("sites.json"); // remove all DOMNodes from the database (clean webapp for import, but only // if the actual import directories exist, don't delete web components if // an empty directory was specified accidentially). if (Files.exists(templates) && Files.exists(components) && Files.exists(pages)) { try (final Tx tx = app.tx()) { final String tenantIdentifier = app.getDatabaseService().getTenantIdentifier(); final String optionalTenantLabel = (tenantIdentifier != null) ? ":" + tenantIdentifier : ""; info("Removing pages, templates and components"); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Removing pages, templates and components"); app.cypher("MATCH (n" + optionalTenantLabel + ":DOMNode) DETACH DELETE n", null); if (Files.exists(sitesConfFile)) { info("Removing sites"); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Removing sites"); app.cypher("MATCH (n" + optionalTenantLabel + ":Site) DETACH DELETE n", null); } FlushCachesCommand.flushAll(); tx.success(); } } else { logger.info( "Import directory does not seem to contain pages, templates or components, NOT removing any data."); } // import templates, must be done before pages so the templates exist if (Files.exists(templates)) { try { info("Importing templates"); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing templates"); Files.walkFileTree(templates, new TemplateImportVisitor(templatesConf)); } catch (IOException ioex) { logger.warn("Exception while importing templates", ioex); } } // import components, must be done before pages so the shared components exist if (Files.exists(components)) { try { info("Importing shared components"); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing shared components"); Files.walkFileTree(components, new ComponentImportVisitor(componentsConf)); } catch (IOException ioex) { logger.warn("Exception while importing shared components", ioex); } } // import pages if (Files.exists(pages)) { try { info("Importing pages"); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing pages"); Files.walkFileTree(pages, new PageImportVisitor(pages, pagesConf)); } catch (IOException ioex) { logger.warn("Exception while importing pages", ioex); } } // import sites if (Files.exists(sitesConfFile)) { info("Importing sites"); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Importing sites"); importSites(readConfigList(sitesConfFile)); } try (final Tx tx = app.tx()) { deferredPageLinks.forEach((String linkableUUID, String pagePath) -> { try { final DOMNode page = StructrApp.getInstance().get(DOMNode.class, linkableUUID); final Linkable linkedPage = StructrApp.getInstance().nodeQuery(Linkable.class) .and(StructrApp.key(Page.class, "path"), pagePath).or(Page.name, pagePath).getFirst(); ((LinkSource) page).setLinkable(linkedPage); } catch (FrameworkException ex) { } }); deferredPageLinks.clear(); tx.success(); } // apply configuration final Path postDeployConf = source.resolve("post-deploy.conf"); if (Files.exists(postDeployConf)) { try (final Tx tx = app.tx()) { final String confSource = new String(Files.readAllBytes(postDeployConf), Charset.forName("utf-8")) .trim(); if (confSource.length() > 0) { info("Applying post-deployment configuration from {}", postDeployConf); publishDeploymentProgressMessage(DEPLOYMENT_IMPORT_STATUS, "Applying post-deployment configuration"); Scripting.evaluate(new ActionContext(ctx), null, confSource, "post-deploy.conf"); } else { info("Ignoring empty post-deployment configuration {}", postDeployConf); } tx.success(); } catch (Throwable t) { logger.warn("", t); publishDeploymentWarningMessage("Exception caught while importing post-deploy.conf", t.toString()); } } if (!missingPrincipals.isEmpty()) { final String title = "Missing Principal(s)"; final String text = "The following user(s) and/or group(s) are missing for grants or node ownership during deployment.<br>" + "Because of these missing grants/ownerships, the functionality is not identical to the export you just imported!<br><br>" + String.join(", ", missingPrincipals) + "<br><br>Consider adding these principals to your <a href=\"https://support.structr.com/article/428#pre-deployconf-javascript\">pre-deploy.conf</a> and re-importing."; info("\n###############################################################################\n" + "\tWarning: " + title + "!\n" + "\tThe following user(s) and/or group(s) are missing for grants or node ownership during deployment.\n" + "\tBecause of these missing grants/ownerships, the functionality is not identical to the export you just imported!\n\n" + "\t" + String.join(", ", missingPrincipals) + "\n\n\tConsider adding these principals to your 'pre-deploy.conf' (see https://support.structr.com/article/428#pre-deployconf-javascript) and re-importing.\n" + "###############################################################################"); publishDeploymentWarningMessage(title, text); } // restore saved value Settings.ChangelogEnabled.setValue(changeLogEnabled); final long endTime = System.currentTimeMillis(); DecimalFormat decimalFormat = new DecimalFormat("0.00", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); final String duration = decimalFormat.format(((endTime - startTime) / 1000.0)) + "s"; customHeaders.put("end", new Date(endTime).toString()); customHeaders.put("duration", duration); info("Import from {} done. (Took {})", source.toString(), duration); broadcastData.put("subtype", DEPLOYMENT_STATUS_END); broadcastData.put("end", endTime); broadcastData.put("duration", duration); TransactionCommand.simpleBroadcastGenericMessage(broadcastData); }
From source file:net.sf.jasperreports.chartthemes.spring.AegeanChartTheme.java
@Override protected JFreeChart createThermometerChart() throws JRException { JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot(); // Create the plot that will hold the thermometer. ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset()); ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext()); // setting localized range axis formatters chartPlot.getRangeAxis().setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale())); // Build a chart around this plot JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false);//w ww . j a v a 2 s. c o m Range range = convertRange(jrPlot.getDataRange()); if (range != null) { // Set the boundary of the thermomoter chartPlot.setLowerBound(range.getLowerBound()); chartPlot.setUpperBound(range.getUpperBound()); } chartPlot.setGap(0); // Units can only be Fahrenheit, Celsius or none, so turn off for now. chartPlot.setUnits(ThermometerPlot.UNITS_NONE); // Set the color of the mercury. Only used when the value is outside of // any defined ranges. @SuppressWarnings("unchecked") List<Paint> seriesPaints = (List<Paint>) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SERIES_COLORS); Paint paint = jrPlot.getMercuryColor(); if (paint != null) { chartPlot.setUseSubrangePaint(false); } else { //it has no effect, but is kept for backward compatibility reasons paint = seriesPaints.get(0); } chartPlot.setMercuryPaint(paint); chartPlot.setThermometerPaint(THERMOMETER_COLOR); chartPlot.setThermometerStroke(new BasicStroke(2f)); chartPlot.setOutlineVisible(false); chartPlot.setValueFont(chartPlot.getValueFont().deriveFont(Font.BOLD)); // localizing the default format, can be overridden by display.getMask() chartPlot.setValueFormat(NumberFormat.getNumberInstance(getLocale())); // Set the formatting of the value display JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { if (display.getColor() != null) { chartPlot.setValuePaint(display.getColor()); } if (display.getMask() != null) { chartPlot.setValueFormat( new DecimalFormat(display.getMask(), DecimalFormatSymbols.getInstance(getLocale()))); } if (display.getFont() != null) { // chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont()).deriveFont(Font.BOLD)); } } // Set the location of where the value is displayed // Set the location of where the value is displayed ValueLocationEnum valueLocation = jrPlot.getValueLocationValue(); switch (valueLocation) { case NONE: chartPlot.setValueLocation(ThermometerPlot.NONE); break; case LEFT: chartPlot.setValueLocation(ThermometerPlot.LEFT); break; case RIGHT: chartPlot.setValueLocation(ThermometerPlot.RIGHT); break; case BULB: default: chartPlot.setValueLocation(ThermometerPlot.BULB); break; } // Define the three ranges range = convertRange(jrPlot.getLowRange()); if (range != null) { chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound()); } range = convertRange(jrPlot.getMediumRange()); if (range != null) { chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound()); } range = convertRange(jrPlot.getHighRange()); if (range != null) { chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound()); } return jfreeChart; }
From source file:de.andreas_rueckert.trade.site.btc_e.client.BtcEClient.java
/** * Format an amount btc-e compliant./* w w w . j ava 2 s. co m*/ * * @param amount The amount to format. */ private final String formatAmount(BigDecimal amount) { // The amount has always 8 fraction digits for now. DecimalFormat amountFormat = new DecimalFormat("#####.########", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return amountFormat.format(amount); }
From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java
@Override protected JFreeChart createMeterChart() throws JRException { // Start by creating the plot that will hold the meter MeterPlot chartPlot = new MeterPlot((ValueDataset) getDataset()); JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // Set the shape MeterShapeEnum shape = jrPlot.getShapeValue() == null ? MeterShapeEnum.DIAL : jrPlot.getShapeValue(); switch (shape) { case CHORD:/* w ww . j av a 2 s . c om*/ chartPlot.setDialShape(DialShape.CHORD); break; case PIE: chartPlot.setDialShape(DialShape.PIE); break; case CIRCLE: chartPlot.setDialShape(DialShape.CIRCLE); break; case DIAL: default: return createDialChart(); } chartPlot.setDialOutlinePaint(Color.BLACK); int meterAngle = jrPlot.getMeterAngleInteger() == null ? 180 : jrPlot.getMeterAngleInteger(); // Set the size of the meter chartPlot.setMeterAngle(meterAngle); // Set the spacing between ticks. I hate the name "tickSize" since to me it // implies I am changing the size of the tick, not the spacing between them. double tickInterval = jrPlot.getTickIntervalDouble() == null ? 10.0 : jrPlot.getTickIntervalDouble(); chartPlot.setTickSize(tickInterval); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); chartPlot.setTickLabelFont(themeTickLabelFont); // localizing the default format, can be overridden by display.getMask() chartPlot.setTickLabelFormat(NumberFormat.getInstance(getLocale())); Color tickColor = jrPlot.getTickColor() == null ? Color.BLACK : jrPlot.getTickColor(); chartPlot.setTickPaint(tickColor); int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); // Set the meter's range if (range != null) { chartPlot.setRange(range); double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); if ((range.getLowerBound() == (int) range.getLowerBound() && range.getUpperBound() == (int) range.getUpperBound() && tickInterval == (int) tickInterval) || dialUnitScale > 1) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale == 1) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0.0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale <= 0) { chartPlot.setTickLabelFormat( new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(getLocale()))); } } chartPlot.setTickLabelsVisible(true); // Set all the colors we support Paint backgroundPaint = jrPlot.getOwnBackcolor() == null ? ChartThemesConstants.TRANSPARENT_PAINT : jrPlot.getOwnBackcolor(); chartPlot.setBackgroundPaint(backgroundPaint); GradientPaint gp = new GradientPaint(new Point(), Color.LIGHT_GRAY, new Point(), Color.BLACK, false); if (jrPlot.getMeterBackgroundColor() != null) { chartPlot.setDialBackgroundPaint(jrPlot.getMeterBackgroundColor()); } else { chartPlot.setDialBackgroundPaint(gp); } //chartPlot.setForegroundAlpha(1f); Paint needlePaint = jrPlot.getNeedleColor() == null ? new Color(191, 48, 0) : jrPlot.getNeedleColor(); chartPlot.setNeedlePaint(needlePaint); JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { Color valueColor = display.getColor() == null ? Color.BLACK : display.getColor(); chartPlot.setValuePaint(valueColor); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) chartPlot.setTickLabelFormat( new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); JRFont displayFont = display.getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); if (themeDisplayFont != null) { chartPlot.setValueFont(themeDisplayFont); } } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); } // Set the units - this is just a string that will be shown next to the // value String units = jrPlot.getUnits() == null ? label : jrPlot.getUnits(); if (units != null && units.length() > 0) chartPlot.setUnits(units); chartPlot.setTickPaint(Color.BLACK); // Now define all of the intervals, setting their range and color List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); interval.setBackgroundColor(color); interval.setAlpha(1.0d); chartPlot.addInterval(convertInterval(interval)); } } // Actually create the chart around the plot JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, chartPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:de.andreas_rueckert.trade.site.btc_e.client.BtcEClient.java
/** * Format the price for a given currency pair. * * @param price The price to format./*w w w . j a v a 2 s .c om*/ * @param currencyPair The currency pair to trade. */ private final String formatPrice(BigDecimal price, CurrencyPair currencyPair) { if (currencyPair.getCurrency().equals(CurrencyImpl.BTC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.USD)) { // btc has only 3 fraction digits for usd. DecimalFormat btcDecimalFormat = new DecimalFormat("#####.###", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return btcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.BTC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.RUR)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.BTC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.EUR)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.LTC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.BTC)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.LTC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.USD)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.LTC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.RUR)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.LTC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.EUR)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.###", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.NMC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.BTC)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.NMC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.USD)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.###", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.NVC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.BTC)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.NVC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.USD)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.###", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.USD) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.RUR)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.EUR) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.USD)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.TRC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.BTC)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.PPC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.BTC)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.PPC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.USD)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.###", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.FTC) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.BTC)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else if (currencyPair.getCurrency().equals(CurrencyImpl.XPM) && currencyPair.getPaymentCurrency().equals(CurrencyImpl.BTC)) { DecimalFormat nmcDecimalFormat = new DecimalFormat("#####.#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return nmcDecimalFormat.format(price); } else { throw new CurrencyNotSupportedException( "The currency pair " + currencyPair.getName() + " is not supported in formatPrice()"); } }
From source file:org.structr.core.graph.SyncCommand.java
private static void importDatabase(final GraphDatabaseService graphDb, final SecurityContext securityContext, final ZipInputStream zis, boolean doValidation, final Long batchSize) throws FrameworkException, IOException { final App app = StructrApp.getInstance(); final DataInputStream dis = new DataInputStream(new BufferedInputStream(zis)); final RelationshipFactory relFactory = new RelationshipFactory(securityContext); final long internalBatchSize = batchSize != null ? batchSize : 200; final NodeFactory nodeFactory = new NodeFactory(securityContext); final String uuidPropertyName = GraphObject.id.dbName(); final Map<String, Node> uuidMap = new LinkedHashMap<>(); final Set<Long> deletedNodes = new HashSet<>(); final Set<Long> deletedRels = new HashSet<>(); final SuperUser superUser = new SuperUser(); double t0 = System.nanoTime(); PropertyContainer currentObject = null; String currentKey = null;/*from ww w.jav a 2 s . c o m*/ boolean finished = false; long totalNodeCount = 0; long totalRelCount = 0; do { try (final Tx tx = app.tx(doValidation)) { final List<Relationship> rels = new LinkedList<>(); final List<Node> nodes = new LinkedList<>(); long nodeCount = 0; long relCount = 0; do { try { // store current position dis.mark(4); // read one byte byte objectType = dis.readByte(); // skip newlines if (objectType == '\n') { continue; } if (objectType == 'N') { // break loop after 200 objects, commit and restart afterwards if (nodeCount + relCount >= internalBatchSize) { dis.reset(); break; } currentObject = graphDb.createNode(); nodeCount++; // store for later use nodes.add((Node) currentObject); } else if (objectType == 'R') { // break look after 200 objects, commit and restart afterwards if (nodeCount + relCount >= internalBatchSize) { dis.reset(); break; } String startId = (String) deserialize(dis); String endId = (String) deserialize(dis); String relTypeName = (String) deserialize(dis); Node endNode = uuidMap.get(endId); Node startNode = uuidMap.get(startId); if (startNode != null && endNode != null) { if (deletedNodes.contains(startNode.getId()) || deletedNodes.contains(endNode.getId())) { System.out.println("NOT creating relationship between deleted nodes.."); } else { RelationshipType relType = DynamicRelationshipType.withName(relTypeName); currentObject = startNode.createRelationshipTo(endNode, relType); // store for later use rels.add((Relationship) currentObject); relCount++; } } else { System.out.println("NOT creating relationship of type " + relTypeName + ", start: " + startId + ", end: " + endId); } } else { // reset if not at the beginning of a line dis.reset(); if (currentKey == null) { currentKey = (String) deserialize(dis); } else { if (currentObject != null) { Object obj = deserialize(dis); if (uuidPropertyName.equals(currentKey) && currentObject instanceof Node) { String uuid = (String) obj; uuidMap.put(uuid, (Node) currentObject); } if (currentKey.length() != 0) { // store object in DB currentObject.setProperty(currentKey, obj); // set type label if (currentObject instanceof Node && NodeInterface.type.dbName().equals(currentKey)) { ((Node) currentObject).addLabel(DynamicLabel.label((String) obj)); } } else { logger.log(Level.SEVERE, "Invalid property key for value {0}, ignoring", obj); } currentKey = null; } else { logger.log(Level.WARNING, "No current object to store property in."); } } } } catch (EOFException eofex) { finished = true; } } while (!finished); totalNodeCount += nodeCount; totalRelCount += relCount; for (Node node : nodes) { if (!deletedNodes.contains(node.getId())) { NodeInterface entity = nodeFactory.instantiate(node); // check for existing schema node and merge if (entity instanceof AbstractSchemaNode) { checkAndMerge(entity, deletedNodes, deletedRels); } if (!deletedNodes.contains(node.getId())) { TransactionCommand.nodeCreated(superUser, entity); entity.addToIndex(); } } } for (Relationship rel : rels) { if (!deletedRels.contains(rel.getId())) { RelationshipInterface entity = relFactory.instantiate(rel); TransactionCommand.relationshipCreated(superUser, entity); entity.addToIndex(); } } logger.log(Level.INFO, "Imported {0} nodes and {1} rels, committing transaction..", new Object[] { totalNodeCount, totalRelCount }); tx.success(); } } while (!finished); double t1 = System.nanoTime(); double time = ((t1 - t0) / 1000000000.0); DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); logger.log(Level.INFO, "Import done in {0} s", decimalFormat.format(time)); }