package jas.hist; import jas.plot.Overlay; import jas.util.ColorConverter; import java.io.Serializable; import java.util.Observable; class JASHist1DHistogramData extends JASHistData { JASHist1DHistogramData(DataManager dm,DataSource ds) { super(dm); dataSource = ds; initTransientData(); JASHistStyle s = null; if (ds instanceof HasStyle) s = ((HasStyle) ds).getStyle(); if (s == null) s = new JASHist1DHistogramStyle(); setStyle(s); String property = System.getProperty("hurry", "false"); hurry = property != null && property.equalsIgnoreCase("true"); } private void initTransientData() { yLimitsValid = false; isBinned = false; } public void setStyle(JASHistStyle style) { if (!(style instanceof JASHist1DHistogramStyle)) throw new IllegalArgumentException("Style is not subclass of JASHist1DHistogramStyle"); if (this.style != null) this.style.deleteObserver(this); this.style = (JASHist1DHistogramStyle) style; this.style.addObserver(this); } public String getTitle() { return dataSource.getTitle(); } String[] getAxisLabels() { return dataSource instanceof Rebinnable1DHistogramData ? ((Rebinnable1DHistogramData) dataSource).getAxisLabels() : null; } Overlay createOverlay() { return new OneDOverlay(this); } void writeAsXML(XMLPrintWriter pw, boolean snapshot) { pw.setAttribute("axis","y"+getYAxis()); pw.openTag("data1d"); String theAxisType = pw.convertAxisTypeToString(getAxisType()); if (snapshot) { if (dataSource instanceof Rebinnable1DHistogramData) { pw.setAttribute("title",getTitle()); pw.openTag("bins1d"); for (int i=0; i < data.length; i++) { pw.print(data[i]); pw.print(","); pw.print(plusError[i]); pw.print(","); pw.print(minusError[i]); pw.println(); } pw.closeTag(); pw.printBinnedDataAxisAttributes( "x", "" + xLow, "" + xHigh, "" + xBins, theAxisType); if (theAxisType.equals("string")) { pw.setAttribute("type","x0"); pw.openTag("axisLabels"); String[] labels = getAxisLabels(); for (int i=0; i < labels.length; i++) { pw.setAttribute("value",labels[i]); pw.printTag("axisLabel"); } pw.closeTag(); } } else { pw.setAttribute("title",getTitle()); pw.openTag("points"); for (int i=0; i < data.length; i++) { pw.print(dataX[i]); pw.print(','); pw.print(data[i]); pw.print(','); pw.print(plusError[i]); pw.print(','); pw.print(minusError[i]); pw.println(); } pw.closeTag(); pw.setAttribute("axis","x"); pw.setAttribute("type",theAxisType); pw.printTag("pointDataAxisAttributes"); } if (dataSource instanceof HasStatistics) { Statistics stats = ((HasStatistics) dataSource).getStatistics(); if (stats != null) { pw.openTag("statistics"); String[] names = stats.getStatisticNames(); for (int i=0; i