List of usage examples for org.jfree.data.xy XYDataItem getX
public Number getX()
From source file:com.jbombardier.console.charts.XYTimeChartPanel.java
@SuppressWarnings("unchecked") public void removeOldDataPoints() { List<XYSeries> series = xyseriescollection.getSeries(); for (XYSeries xySeries : series) { while (xySeries.getItemCount() > 0) { XYDataItem xyDataItem = xySeries.getDataItem(0); long itemTime = xyDataItem.getX().longValue(); if (mostRecentTimeValue - timePeriod > itemTime) { xySeries.remove(0);//from ww w . j av a 2s.co m } else { // Fast exit, the items will be in time order break; } } } }
From source file:org.owasp.benchmark.score.report.ScatterHome.java
private JFreeChart display(String title, int height, Set<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //averages/*w w w . jav a 2 s. co m*/ ArrayList<Double> averageCommercialFalseRates = new ArrayList<Double>(); ArrayList<Double> averageCommercialTrueRates = new ArrayList<Double>(); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (Report toolReport : toolResults) { if (!toolReport.isCommercial()) { OverallResults overallResults = toolReport.getOverallResults(); series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100); if (toolReport.isCommercial()) { averageCommercialFalseRates.add(overallResults.getFalsePositiveRate()); averageCommercialTrueRates.add(overallResults.getTruePositiveRate()); } } } int commercialToolCount = 0; for (Report toolReport : toolResults) { if (toolReport.isCommercial()) { commercialToolCount++; OverallResults overallResults = toolReport.getOverallResults(); if (!BenchmarkScore.showAveOnlyMode) { series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100); } if (toolReport.isCommercial()) { averageCommercialFalseRates.add(overallResults.getFalsePositiveRate()); averageCommercialTrueRates.add(overallResults.getTruePositiveRate()); } } } for (double d : averageCommercialFalseRates) { afr += d; } afr = afr / averageCommercialFalseRates.size(); for (double d : averageCommercialTrueRates) { atr += d; } atr = atr / averageCommercialTrueRates.size(); if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) { series.add(afr * 100, atr * 100); } dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); initializePlot(xyplot); makeDataLabels(toolResults, xyplot); makeLegend(toolResults, 103, 100.5, dataset, xyplot); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } ChartPanel cp = new ChartPanel(chart, height, height, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:gda.plots.TurboXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself./*w ww.j ava 2 s . c o m*/ * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information etc). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param crosshairState * crosshair information for the plot ( <code>null</code> permitted). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int _item, CrosshairState crosshairState, int pass) { if (_item > 0) return; SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); try { int x0 = -1; // the x position in pixels of the previous point int y0 = -1; // the y position in pixels of the previous point int x1 = -1; // the x position in pixels of the current point int y1 = -1; // the y position in pixels of the current point int xmin = (int) dataArea.getMinX(); int xmax = (int) dataArea.getMaxX(); int ymin = (int) dataArea.getMinY(); int ymax = (int) dataArea.getMaxY(); GeneralPath path = null; /* * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear * maths */ double xl = 0., mx = Double.NaN, cx = 0.; if (domainAxis instanceof SimpleNumberAxis) { xl = domainAxis.getRange().getLowerBound(); mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl); cx = xmin; } double yl = 0., my = Double.NaN, cy = 0.; if (rangeAxis instanceof SimpleNumberAxis) { yl = rangeAxis.getRange().getLowerBound(); my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl); cy = ymax; } List<XYDataItem> list = sxys.getData(); boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my); Paint paint = sxys.getPaint(); Stroke stroke = sxys.getStroke(); Paint paint_symbol = sxys.getSymbolPaint(); Stroke stroke_symbol = new BasicStroke(); drawLines = sxys.isDrawLines(); boolean filled = sxys.getFilled(); Shape shape = sxys.getSymbol(); boolean drawMarkers = sxys.isDrawMarkers() & shape != null; int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */ if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) { Rectangle shapeBoundingBox = shape.getBounds(); tooltipThresholdCounts = (int) dataArea.getWidth() / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold); } java.util.Vector<ddouble> markerPositions = null; Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } boolean prevLineAdded = false; // In case the iterator does not work then use the TODO comment iterator use and why not always // comment variables synchronized (list) { Iterator<XYDataItem> iter = list.iterator(); /* * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The * variable addThis determines if the current point is to be added to the path If previous line was * added that the current must be even if off the screen - but in this case the flag prevLineAdded is * set false so that the next does not have to be added. */ for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) { XYDataItem dataitem = iter.next(); double x = dataitem.getX().doubleValue(); double y = dataitem.getY().doubleValue(); x = xValueTransformer.transformValue(x); x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation) : (int) ((x - xl) * mx + cx); y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) : (int) ((y - yl) * my + cy); boolean addThis = true; if (item == 0) { x0 = x1; y0 = y1; if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) { addThis = false; } } else { if (x1 == x0 && y1 == y0) { addThis = false; } if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin) || (y1 > ymax && y0 > ymax)) { if (prevLineAdded) { path = addPointToLine(path, orientation, x1, y1); } addThis = false; } } if (addThis) { /* * If the current point is to be added then ensure previous one is as well to prevent lines * not crossing the edge of the screen */ if (!prevLineAdded) { path = addPointToLine(path, orientation, x0, y0); } path = addPointToLine(path, orientation, x1, y1); prevLineAdded = true; } prevLineAdded = addThis; if (addThis && drawMarkers) { if (markerPositions == null) { markerPositions = new java.util.Vector<ddouble>(); } markerPositions.add(new ddouble(item, x1, y1)); if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) { drawMarkers = false; markerPositions = null; } } } if (path != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(path); } if (markerPositions != null) { if (drawMarkers) { g2.setPaint(paint_symbol); g2.setStroke(stroke_symbol); for (ddouble dd : markerPositions) { Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y); if (filled) { g2.fill(shape_item); } else { g2.draw(shape_item); } entityArea = shape_item; // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y); } } g2.setPaint(paint); g2.setStroke(stroke); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.owasp.benchmark.score.report.ScatterScores.java
private JFreeChart display(String title, int height, int width, List<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (int i = 0; i < toolResults.size(); i++) { Report toolReport = toolResults.get(i); OverallResults overallResults = toolReport.getOverallResults(); series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100); }//from w w w.j a va2 s .c om dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Arial"; DecimalFormat pctFormat = new DecimalFormat("0'%'"); theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 16)); theme.setSmallFont(new Font(fontName, Font.PLAIN, 12)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); xyplot.setOutlineVisible(true); rangeAxis.setRange(-5, 109.99); rangeAxis.setNumberFormatOverride(pctFormat); rangeAxis.setTickLabelPaint(Color.decode("#666666")); rangeAxis.setMinorTickCount(5); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setAxisLineVisible(true); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setTickMarksVisible(true); rangeAxis.setLowerMargin(10); rangeAxis.setUpperMargin(10); xyplot.setRangeGridlineStroke(new BasicStroke()); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setRangeMinorGridlinesVisible(true); domainAxis.setRange(-5, 105); domainAxis.setNumberFormatOverride(pctFormat); domainAxis.setTickLabelPaint(Color.decode("#666666")); domainAxis.setMinorTickCount(5); domainAxis.setTickUnit(new NumberTickUnit(10)); domainAxis.setAxisLineVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setMinorTickMarksVisible(true); domainAxis.setLowerMargin(10); domainAxis.setUpperMargin(10); xyplot.setDomainGridlineStroke(new BasicStroke()); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setDomainMinorGridlinesVisible(true); chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.removeLegend(); chart.setPadding(new RectangleInsets(20, 20, 20, 20)); xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7")); // // setup item labels // XYItemRenderer renderer = xyplot.getRenderer(); // Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f); // for ( int i = 0; i < dataset.getSeriesCount(); i++ ) { // renderer.setSeriesShape(i, circle); // renderer.setSeriesPaint(i, Color.blue); // String label = ""+((String)dataset.getSeries(i).getKey()); // int idx = label.indexOf( ':'); // label = label.substring( 0, idx ); // StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label); // renderer.setSeriesItemLabelGenerator(i, generator); // renderer.setSeriesItemLabelsVisible(i, true); // ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER ); // renderer.setSeriesPositiveItemLabelPosition(i, position); // } makeDataLabels(toolResults, xyplot); makeLegend(toolResults, 57, 48, dataset, xyplot); Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 }, 0); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } // // put legend inside plot // LegendTitle lt = new LegendTitle(xyplot); // lt.setItemFont(theme.getSmallFont()); // lt.setPosition(RectangleEdge.RIGHT); // lt.setItemFont(theme.getSmallFont()); // XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT); // ta.setMaxWidth(0.48); // xyplot.addAnnotation(ta); // draw guessing line XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red); xyplot.addAnnotation(guessing); XYPointerAnnotation worse = makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90); xyplot.addAnnotation(worse); XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270); xyplot.addAnnotation(better); XYTextAnnotation stroketext = new XYTextAnnotation(" Random Guess", 88, 107); stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.red); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red); xyplot.setBackgroundPaint(Color.white); xyplot.addAnnotation(strokekey); ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:org.owasp.benchmark.score.report.ScatterVulns.java
private JFreeChart display(String title, int height, String category, Set<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // averages/*w w w .j a v a 2 s. com*/ ArrayList<Double> averageFalseRates = new ArrayList<Double>(); ArrayList<Double> averageTrueRates = new ArrayList<Double>(); int commercialToolCount = 0; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (Report toolReport : toolResults) { if (!toolReport.isCommercial()) { OverallResult overallResult = toolReport.getOverallResults().getResults(category); series.add(overallResult.falsePositiveRate * 100, overallResult.truePositiveRate * 100); } } for (Report toolReport : toolResults) { if (toolReport.isCommercial()) { OverallResult overallResult = toolReport.getOverallResults().getResults(category); if (!BenchmarkScore.showAveOnlyMode) { series.add(overallResult.falsePositiveRate * 100, overallResult.truePositiveRate * 100); } commercialToolCount++; averageFalseRates.add(overallResult.falsePositiveRate); averageTrueRates.add(overallResult.truePositiveRate); } } for (double d : averageFalseRates) { afr += d; } afr = afr / averageFalseRates.size(); for (double d : averageTrueRates) { atr += d; } atr = atr / averageTrueRates.size(); if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) { series.add(afr * 100, atr * 100); } dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); initializePlot(xyplot); makeDataLabels(category, toolResults, xyplot); makeLegend(category, toolResults, 103, 100.5, dataset, xyplot); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } ChartPanel cp = new ChartPanel(chart, height, height, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:org.jfree.data.xy.XYSeries.java
/** * Returns the index of the item with the specified x-value, or a * negative index if the series does not contain an item with that * x-value. Be aware that for an unsorted series, the index is * found by iterating through all items in the series. * * @param x the x-value (<code>null</code> not permitted). * * @return The index./*from ww w . j a v a 2 s .c om*/ */ public int indexOf(Number x) { if (this.autoSort) { return Collections.binarySearch(this.data, new XYDataItem(x, null)); } else { for (int i = 0; i < this.data.size(); i++) { XYDataItem item = (XYDataItem) this.data.get(i); if (item.getX().equals(x)) { return i; } } return -1; } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java
protected TableXYDataset convertToTable(final XYSeriesCollection xyDataset) { final ExtCategoryTableXYDataset tableXYDataset = new ExtCategoryTableXYDataset(); final int count = xyDataset.getSeriesCount(); for (int i = 0; i < count; i++) { final XYSeries timeSeries = xyDataset.getSeries(i); final Comparable key = timeSeries.getKey(); final int itemCount = timeSeries.getItemCount(); for (int ic = 0; ic < itemCount; ic++) { final XYDataItem seriesDataItem = timeSeries.getDataItem(ic); tableXYDataset.add(seriesDataItem.getX(), seriesDataItem.getY(), key, false); }//from w w w .j a v a2 s. c o m } return tableXYDataset; }
From source file:it.illinois.adsc.ema.softgrid.monitoring.ui.SPMainFrame.java
private void refresh() { if (!chartPanelVisible) { return;//from ww w . j av a2 s . c om } try { File file = new File(ConfigUtil.LIMIT_VIOLATION_RECORD_FILE); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { JOptionPane.showMessageDialog(this, "Invalid Limit Violation Path\n" + file.getAbsolutePath()); // System.exit(0); } } BufferedReader bufferedReader; String line = ""; for (MonitorConfig monitorConfig : monitorConfigs) { monitorConfig.setXySeries(new XYSeries(monitorConfig.toString())); } long lineCount = -1; long racordCount = 0; String type = ""; boolean found = false; for (int j = 0; j < 2; j++) { File logFile = new File(ConfigUtil.LOG_FILE); if (!logFile.exists()) { logFile = new File(ConfigUtil.LOG_FILE + "." + j); if (!logFile.exists()) { System.out.println("Invalid IED log file path.\n" + logFile.getAbsolutePath()); break; } } else { j = 2; } bufferedReader = new BufferedReader(new FileReader(logFile)); while ((line = bufferedReader.readLine()) != null) { lineCount++; String[] data = line.split(":"); if (data.length >= 4 && data[0].equals("Data")) { double timeinMilis = (Double.parseDouble(data[1]) - startTime) * 100.00 / 100000.00; if (timeinMilis < 0) startTime -= 10; // Day day = new Day(Long.parseLong(data[1])); type = data[3]; // select the type ArrayList<MonitorConfig> newMonitors = new ArrayList<MonitorConfig>(); ArrayList<MonitorConfig> removableQueries = new ArrayList<MonitorConfig>(); for (MonitorConfig monitorConfig : monitorConfigs) { if (monitorConfig.getDeviceType().equalsIgnoreCase(type)) { if (monitorConfig.getKeyValueMap().isEmpty()) { found = true; } else { for (String key : monitorConfig.getKeyValueMap().keySet()) { found = false; for (int i = 4; i < data.length; i++) { if (data[i].equalsIgnoreCase(key) && data.length >= i + 1) { if (data[i + 1].trim().equalsIgnoreCase( monitorConfig.getKeyValueMap().get(key))) { found = true; break; } } } } } if (found) { for (int i = 4; i < data.length; i++) { if (monitorConfig.getXySeries() != null && data[i].equalsIgnoreCase(monitorConfig.getVariable())) { double value = 0; try { if (data[i + 1].equals("Closed")) { value = 0; } else if (data[i + 1].equals("Open")) { value = 1; } else { value = Double.parseDouble(data[i + 1]); } if (this.isVisible() && timeinMilis > 0 && value < 0.5 && monitorConfig.getVariable().contains("BusKVVolt")) { JOptionPane.showMessageDialog(this, "Blackout occurred...!"); try { Thread.sleep(7000); } catch (InterruptedException e) { e.printStackTrace(); } stopIEDServers(); } } catch (NumberFormatException e) { System.out.println("data[2] = " + data[2]); e.printStackTrace(); return; } monitorConfig.getXySeries().add(timeinMilis, value); maxTimeRange = (long) timeinMilis; if (maxTimeRange > 0 && dataFileWriter != null) { dataFileWriter .write(maxTimeRange + " , " + monitorConfig.getVariable() + " , " + String.valueOf(value) + "\n"); dataFileWriter.flush(); } if (racordCount >= 100000) { XYDataItem xyDataItem = monitorConfig.getXySeries().remove(0); minTimeRange = xyDataItem.getX().longValue(); } } } } } } if (monitorConfigs.size() < 10) { monitorConfigs.addAll(newMonitors); } if (racordCount < 50000) { racordCount++; } } } bufferedReader.close(); } SMAlert smAlert = lastAlert; while (smAlert != null && smAlert.getPreviouseAlert() != null) { smAlert = smAlert.getPreviouseAlert(); long addedTime = alertTimeMap.get(smAlert); if ((System.currentTimeMillis() - addedTime) > ALERT_STORE_DURATION) { removeAlert(smAlert); } } FileReader fileReader = null; BufferedReader violationReader = null; try { fileReader = new FileReader(file); violationReader = new BufferedReader(fileReader); while ((line = violationReader.readLine()) != null) { String[] vlData = line.split(","); try { long addedTime = Long.parseLong(vlData[0]); if ((System.currentTimeMillis() - addedTime) <= ALERT_STORE_DURATION) { addAlert(addedTime, new SMAlert(vlData[3], vlData[2], vlData[1])); } } catch (NumberFormatException e) { e.printStackTrace(); } } } catch (IOException e) { e.printStackTrace(); } finally { try { violationReader.close(); } catch (IOException e) { e.printStackTrace(); } try { fileReader.close(); } catch (IOException e) { e.printStackTrace(); } } lastLine = lineCount; dataset.removeAllSeries(); for (MonitorConfig monitorConfig : monitorConfigs) { if (monitorConfig.getXySeries() != null) { dataset.addSeries(monitorConfig.getXySeries()); } } ChartPanel tempNewPanel = getChartPanel(); if (tempNewPanel != null) { JPanel tempPanel = chartPanel; chartPanel = tempNewPanel; chartPanel.updateUI(); Component component = resultTabbedPane.getSelectedComponent(); resultTabbedPane.remove(tempPanel); resultTabbedPane.add(chartPanel, "Chart Panel"); resultTabbedPane.setSelectedComponent(component == tempPanel ? chartPanel : component); // this.getContentPane().add(chartPanel, new GridBagConstraints(0, 2, 1, 1, 0.75, 0.75, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 0, 12, 0), 0, 0)); // if (tempPanel != null) { // this.getContentPane().remove(tempPanel); // } chartPanel.updateUI(); } } catch (Exception e) { e.printStackTrace(); } this.getContentPane().repaint(); }
From source file:org.jfree.data.xy.XYSeries.java
/** * Adds or updates an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the data item (<code>null</code> not permitted). * * @return A copy of the overwritten data item, or <code>null</code> if no * item was overwritten./*ww w. jav a 2s .c o m*/ * * @since 1.0.14 */ public XYDataItem addOrUpdate(XYDataItem item) { ParamChecks.nullNotPermitted(item, "item"); if (this.allowDuplicateXValues) { add(item); return null; } // if we get to here, we know that duplicate X values are not permitted XYDataItem overwritten = null; int index = indexOf(item.getX()); if (index >= 0) { XYDataItem existing = (XYDataItem) this.data.get(index); overwritten = (XYDataItem) existing.clone(); // figure out if we need to iterate through all the y-values boolean iterate = false; double oldY = existing.getYValue(); if (!Double.isNaN(oldY)) { iterate = oldY <= this.minY || oldY >= this.maxY; } existing.setY(item.getY()); if (iterate) { findBoundsByIteration(); } else if (item.getY() != null) { double yy = item.getY().doubleValue(); this.minY = minIgnoreNaN(this.minY, yy); this.maxY = maxIgnoreNaN(this.maxY, yy); } } else { // if the series is sorted, the negative index is a result from // Collections.binarySearch() and tells us where to insert the // new item...otherwise it will be just -1 and we should just // append the value to the list... item = (XYDataItem) item.clone(); if (this.autoSort) { this.data.add(-index - 1, item); } else { this.data.add(item); } updateBoundsForAddedItem(item); // check if this addition will exceed the maximum item count... if (getItemCount() > this.maximumItemCount) { XYDataItem removed = (XYDataItem) this.data.remove(0); updateBoundsForRemovedItem(removed); } } fireSeriesChanged(); return overwritten; }
From source file:org.jfree.data.xy.XYSeries.java
/** * Adds a data item to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the (x, y) item (<code>null</code> not permitted). * @param notify a flag that controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners./*from ww w . j av a 2 s. co m*/ */ public void add(XYDataItem item, boolean notify) { if (item == null) { throw new IllegalArgumentException("Null 'item' argument."); } if (this.autoSort) { int index = Collections.binarySearch(this.data, item); if (index < 0) { this.data.add(-index - 1, item); } else { if (this.allowDuplicateXValues) { // need to make sure we are adding *after* any duplicates int size = this.data.size(); while (index < size && item.compareTo(this.data.get(index)) == 0) { index++; } if (index < this.data.size()) { this.data.add(index, item); } else { this.data.add(item); } } else { throw new SeriesException("X-value already exists."); } } } else { if (!this.allowDuplicateXValues) { // can't allow duplicate values, so we need to check whether // there is an item with the given x-value already int index = indexOf(item.getX()); if (index >= 0) { throw new SeriesException("X-value already exists."); } } this.data.add(item); } if (getItemCount() > this.maximumItemCount) { this.data.remove(0); } if (notify) { fireSeriesChanged(); } }