📄 chartserviceimpl.java
字号:
org.gridsphere.services.core.secdir.FileInfo resourceLists[] = secureDirectoryService.getFileList(secureDirectoryService.createFileLocationID(userID, CHART_SERVICE_DIRECTORY, appName + "/" + path)); int count = 0; if (resourceLists == null) return null; for (int i = 0; i < resourceLists.length; ++i) { if (!resourceLists[i].isDirectory()) ++count; } String chartList[] = new String[count]; count = 0; for (int i = 0; i < resourceLists.length; ++i) { if (!resourceLists[i].isDirectory()) { String resource = resourceLists[i].getResource(); resource = util.substitute("s/\\.xml$//", resource); chartList[count++] = resource; } } return chartList; } public File getChartImageFile(FileLocationID fileLocationID) throws IOException, Exception { String userID = fileLocationID.getUserID(); String appName = fileLocationID.getCategory(); String resource = fileLocationID.getFilePath(); refreshChart(fileLocationID); ChartDescriptor chartDescriptor = readChartDescriptor(userID, appName, resource); Image imageInfo = chartDescriptor.getFileInfo().getImage(); return secureDirectoryService.getFile(secureDirectoryService.createFileLocationID(userID, imageInfo.getAppName(), imageInfo.getFilename() + (imageInfo.getType().equals("JPEG") ? ".jpeg" : ".png"))); } public File getChartDataFile(FileLocationID fileLocationID) throws IOException, Exception { String userID = fileLocationID.getUserID(); String appName = fileLocationID.getCategory(); String resource = fileLocationID.getFilePath(); ChartDescriptor chartDescriptor = readChartDescriptor(userID, appName, resource); Dataset datasetInfo = chartDescriptor.getFileInfo().getDataset(); return secureDirectoryService.getFile(secureDirectoryService.createFileLocationID(userID, datasetInfo.getAppName(), datasetInfo.getFilename() + ".xml")); } public boolean deleteChart(FileLocationID fileLocationID) throws IOException, Exception { return deleteChart(fileLocationID, false); } public boolean deleteChart(FileLocationID fileLocationID, boolean deleteDataset) throws IOException, Exception { String userID = fileLocationID.getUserID(); String appName = fileLocationID.getCategory(); String resource = fileLocationID.getFilePath(); ChartDescriptor chartDescriptor = readChartDescriptor(userID, appName, resource); Image imageInfo = chartDescriptor.getFileInfo().getImage(); secureDirectoryService.deleteFile(secureDirectoryService.createFileLocationID(userID, imageInfo.getAppName(), imageInfo.getFilename() + (imageInfo.getType().equals("JPEG") ? ".jpeg" : ".png")), true, true); if (deleteDataset) { Dataset dataset = chartDescriptor.getFileInfo().getDataset(); secureDirectoryService.deleteFile(secureDirectoryService.createFileLocationID(userID, dataset.getAppName(), dataset.getFilename() + ".xml"), true, true); } return secureDirectoryService.deleteFile(secureDirectoryService.createFileLocationID(userID, CHART_SERVICE_DIRECTORY, appName + "/" + resource + ".xml"), true, true); } public FileLocationID createChartLocationID(String userID, String category, String fileName) { return new FileLocationID(userID, category, fileName); } public boolean chartExists(FileLocationID fileLocationID) { File file = secureDirectoryService.getFile(secureDirectoryService.createFileLocationID(fileLocationID.getUserID(), CHART_SERVICE_DIRECTORY, fileLocationID.getCategory() + "/" + fileLocationID.getFilePath() + ".xml")); return file.exists(); } private boolean refreshChart(FileLocationID fileLocationID) throws IOException, MarshalException, ValidationException, Exception { String userID = fileLocationID.getUserID(); String appName = fileLocationID.getCategory(); String resource = fileLocationID.getFilePath(); ChartDescriptor chartDescriptor = readChartDescriptor(userID, appName, resource); if (chartDescriptor.getChartInfo().getRefresh() == false) { Image imageInfo = chartDescriptor.getFileInfo().getImage();// File imageFile = getChartImageFile(userID, appName, resource); Dataset datasetInfo = chartDescriptor.getFileInfo().getDataset(); File datasetFile = getChartDataFile(fileLocationID); if ((imageInfo.getTimestamp() > datasetInfo.getTimestamp()) && (imageInfo.getTimestamp() >= datasetFile.lastModified())) return false; } org.jfree.data.Dataset dataset = readDataset(userID, chartDescriptor.getFileInfo().getDataset().getAppName(), resource, chartDescriptor.getFileInfo().getDataset().getType()); org.jfree.chart.JFreeChart chart = null; ChartInfo chartInfo = chartDescriptor.getChartInfo(); try { if (chartInfo.getType().equals("Pie")) { chart = org.jfree.chart.ChartFactory.createPieChart(chartInfo.getTitle(), (org.jfree.data.DefaultPieDataset) dataset, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("Pie3D")) { chart = org.jfree.chart.ChartFactory.createPieChart3D(chartInfo.getTitle(), (org.jfree.data.DefaultPieDataset) dataset, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("Bar")) { chart = org.jfree.chart.ChartFactory.createBarChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.DefaultCategoryDataset) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("Bar3D")) { chart = org.jfree.chart.ChartFactory.createBarChart3D(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.DefaultCategoryDataset) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("StackedBar")) { chart = org.jfree.chart.ChartFactory.createStackedBarChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.DefaultCategoryDataset) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("StackedBar3D")) { chart = org.jfree.chart.ChartFactory.createStackedBarChart3D(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.DefaultCategoryDataset) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("BarXY")) { if (dataset instanceof org.jfree.data.XYSeriesCollection) chart = org.jfree.chart.ChartFactory.createXYBarChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), false, chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.XYSeriesCollection) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); else chart = org.jfree.chart.ChartFactory.createXYBarChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), true, chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.time.TimeSeriesCollection) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("Area")) { chart = org.jfree.chart.ChartFactory.createAreaChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.DefaultCategoryDataset) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("StackedArea")) { chart = org.jfree.chart.ChartFactory.createStackedAreaChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.DefaultCategoryDataset) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("AreaXY")) { chart = org.jfree.chart.ChartFactory.createXYAreaChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.XYSeriesCollection) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("Gantt")) { chart = org.jfree.chart.ChartFactory.createGanttChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.gantt.TaskSeriesCollection) dataset, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("Line")) { chart = org.jfree.chart.ChartFactory.createLineChart(chartInfo.getTitle(), chartInfo.getPlot().getSettings().getCategory().getDomainAxisLabel(), chartInfo.getPlot().getSettings().getCategory().getRangeAxisLabel(), (org.jfree.data.DefaultCategoryDataset) dataset, chartInfo.getPlot().getSettings().getCategory().getPlotOrientation().equals("PlotOrientation.HORIZONTAL") ? org.jfree.chart.plot.PlotOrientation.HORIZONTAL : org.jfree.chart.plot.PlotOrientation.VERTICAL, chartInfo.getLegend(), false, false); } else if (chartInfo.getType().equals("LineXY")) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -