Example usage for java.awt Color orange

List of usage examples for java.awt Color orange

Introduction

In this page you can find the example usage for java.awt Color orange.

Prototype

Color orange

To view the source code for java.awt Color orange.

Click Source Link

Document

The color orange.

Usage

From source file:de.codesourcery.jasm16.utils.ASTInspector.java

public ASTInspector() {
    defaultStyle = new SimpleAttributeSet();
    errorStyle = createStyle(Color.RED);
    registerStyle = createStyle(Color.ORANGE);
    commentStyle = createStyle(Color.DARK_GRAY);
    instructionStyle = createStyle(Color.BLUE);
    labelStyle = createStyle(Color.GREEN);
    preProcessorStyle = createStyle(new Color(200, 200, 200));
}

From source file:mil.tatrc.physiology.utilities.csv.plots.MultiPlotter.java

protected void formatMultiPlot(PlotJob job, JFreeChart chart, XYSeriesCollection dataSet1,
        XYSeriesCollection dataSet2) {/*from   w  w w  .j a va  2 s  .co  m*/
    Color[] blueColors = { Color.blue, Color.cyan, new Color(0, 160, 255), new Color(0, 100, 255),
            new Color(0, 160, 255), new Color(14, 0, 145), new Color(70, 105, 150) };
    Color[] redColors = { Color.red, Color.magenta, new Color(255, 0, 100), new Color(255, 0, 160), Color.pink,
            new Color(145, 0, 0), new Color(132, 58, 58) };
    Color[] variedColors = { Color.red, Color.blue, Color.green, Color.orange, Color.magenta, Color.cyan,
            Color.gray, new Color(255, 165, 0), new Color(42, 183, 136), new Color(87, 158, 186) };
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) plot.getRenderer();
    BasicStroke wideLine = new BasicStroke(2.0f);

    //For Scientific notation
    NumberFormat formatter = new DecimalFormat("0.######E0");

    for (int i = 0; i < plot.getDomainAxisCount(); i++) {
        plot.getDomainAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
        plot.getDomainAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15));
        plot.getDomainAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black);
        plot.getDomainAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black);
    }
    for (int i = 0; i < plot.getRangeAxisCount(); i++) {
        plot.getRangeAxis(i).setLabelFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
        plot.getRangeAxis(i).setTickLabelFont(new Font("SansSerif", Font.PLAIN, 15));
        plot.getRangeAxis(i).setLabelPaint(job.bgColor == Color.red ? Color.white : Color.black);
        plot.getRangeAxis(i).setTickLabelPaint(job.bgColor == Color.red ? Color.white : Color.black);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(i);
        rangeAxis.setNumberFormatOverride(formatter);
    }

    //White background outside of plottable area
    chart.setBackgroundPaint(job.bgColor);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    chart.getLegend().setItemFont(new Font("SansSerif", Font.PLAIN, 15));
    chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, job.fontSize));
    chart.getTitle().setPaint(job.bgColor == Color.red ? Color.white : Color.black);

    //If there is only one Y axis, we just need to color the data series differently
    if (job.Y2headers == null || job.Y2headers.isEmpty()) {
        for (int i = 0, cIndex = 0; i < dataSet1.getSeriesCount(); i++, cIndex++) {
            renderer1.setSeriesStroke(i, wideLine);
            renderer1.setBaseShapesVisible(false);
            if (cIndex > 9)
                cIndex = 0;
            renderer1.setSeriesFillPaint(i, variedColors[cIndex]);
            renderer1.setSeriesPaint(i, variedColors[cIndex]);
        }
    }
    //If there are 2 Y axes, we should color the axes to correspond with the data so it isn't (as) confusing
    else {
        StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
        plot.setRenderer(1, renderer2);

        for (int i = 0, cIndex = 0; i < dataSet1.getSeriesCount(); i++, cIndex++) {
            renderer1.setSeriesStroke(i, wideLine);
            renderer1.setBaseShapesVisible(false);
            if (cIndex > 6)
                cIndex = 0;
            renderer1.setSeriesFillPaint(i, redColors[cIndex]);
            renderer1.setSeriesPaint(i, redColors[cIndex]);
        }
        for (int i = 0, cIndex = 0; i < dataSet2.getSeriesCount(); i++, cIndex++) {
            renderer2.setSeriesStroke(i, wideLine);
            renderer2.setBaseShapesVisible(false);
            if (cIndex > 6)
                cIndex = 0;
            renderer2.setSeriesFillPaint(i, blueColors[cIndex]);
            renderer2.setSeriesPaint(i, blueColors[cIndex]);
        }
        plot.getRangeAxis(0).setLabelPaint(redColors[0]);
        plot.getRangeAxis(0).setTickLabelPaint(redColors[0]);
        plot.getRangeAxis(1).setLabelPaint(blueColors[0]);
        plot.getRangeAxis(1).setTickLabelPaint(blueColors[0]);
    }
}

From source file:org.fhcrc.cpl.viewer.quant.gui.PanelWithSpectrumChart.java

License:asdf

/**
 *  Generate all the charts/*from   w  ww  .j  ava  2s .c om*/
 */
public void generateCharts() {
    int minScanIndex = Math.abs(run.getIndexForScanNum(minScan));
    int maxScanIndex = Math.abs(run.getIndexForScanNum(maxScan));
    int numScans = maxScanIndex - minScanIndex + 1;
    int numMzBins = (int) ((float) resolution * (maxMz - minMz)) + 1;
    double[] scanValues = new double[numScans];

    double[] mzValues = new double[numMzBins];

    for (int i = 0; i < numScans; i++)
        scanValues[i] = run.getScanNumForIndex(minScanIndex + i);
    for (int i = 0; i < numMzBins; i++)
        mzValues[i] = minMz + (i / (float) resolution);

    //Resampling adds some slop on each end
    float minMzForRange = (int) minMz;
    if (minMzForRange > minMz)
        minMzForRange--;
    float maxMzForRange = (int) maxMz;
    if (maxMzForRange < maxMz)
        maxMzForRange++;

    FloatRange mzWindowForResample = new FloatRange(minMzForRange, maxMzForRange);
    double[][] intensityValues = new double[numScans][numMzBins];
    _log.debug("Loading spectrum in range....");

    double[] sumIntensitiesInQuantRange = new double[numMzBins];
    //carry just the intensities used in quantitation
    double[] sumPeakIntensitiesInQuantRange = new double[numMzBins];
    if (numSafePeaks < 0)
        numSafePeaks = Math.min(Math.round((heavyMz - lightMz) * charge), MAX_Q3_PEAKS);
    if (heavyMz < lightMz)
        numSafePeaks = 4;
    if (peakMzs != null)
        numSafePeaks = Math.min(numSafePeaks, peakMzs.length);

    List<Float> peakMzsToQuantitate = new ArrayList<Float>();
    List<Float> nonMonoisotopicPeakMzList = new ArrayList<Float>();

    for (int i = 0; i < numSafePeaks; i++) {
        float lightPeakMz = lightMz + (peakSeparationMass / charge) * i;
        float heavyPeakMz = heavyMz + (peakSeparationMass / charge) * i;
        if (peakMzs != null) {
            lightPeakMz = peakMzs[i];
            heavyPeakMz = heavyMz + (lightPeakMz - lightMz);
        }
        peakMzsToQuantitate.add(lightPeakMz);
        peakMzsToQuantitate.add(heavyPeakMz);
        nonMonoisotopicPeakMzList.add(lightPeakMz);
        if (heavyPeakMz > lightMz)
            nonMonoisotopicPeakMzList.add(heavyPeakMz);
    }
    int heavyMonoisotopicPeakIndex = numSafePeaks;

    float[] nonMonoisotopicPeakMzs = new float[nonMonoisotopicPeakMzList.size()];
    for (int i = 0; i < nonMonoisotopicPeakMzs.length; i++) {
        nonMonoisotopicPeakMzs[i] = nonMonoisotopicPeakMzList.get(i);
    }
    Collections.sort(peakMzsToQuantitate);

    //dhmay adding 20090723
    //For calculating single-peak ratio based on theoretical highest peak
    int maxIdealPeakIndex = Spectrum.calcMaxIdealPeakIndex(lightMz - Spectrum.HYDROGEN_ION_MASS) * charge;
    float lightMaxIdealPeakIntensitySum = 0f;
    float heavyMaxIdealPeakIntensitySum = 0f;

    for (int scanArrayIndex = 0; scanArrayIndex < numScans; scanArrayIndex++) {
        int scanIndex = minScanIndex + scanArrayIndex;
        MSRun.MSScan scan = run.getScan(scanIndex);
        if (scan.getNum() == idEventScan)
            specifiedScanFoundMS1 = true;
        float[] signalFromResample = Spectrum.Resample(scan.getSpectrum(), mzWindowForResample, resolution);
        int firstIndexToKeep = -1;

        for (int i = 0; i < signalFromResample.length; i++) {
            float mzValueThisIndex = minMzForRange + (i / (float) resolution);
            if (mzValueThisIndex >= minMz && firstIndexToKeep == -1) {
                firstIndexToKeep = i;
                break;
            }
        }

        //this is horrible.  arraycopy would be better, but need to convert float to double
        double[] signal = new double[numMzBins];
        for (int i = 0; i < numMzBins; i++) {
            signal[i] = signalFromResample[firstIndexToKeep + i];

        }

        if (shouldGenerateLineCharts) {
            double[] signalPeaks = new double[numMzBins];
            int currentPeakIndex = -1;
            float minMzCurrentPeak = -1;
            float maxMzCurrentPeak = -1;
            for (int i = 0; i < numMzBins; i++) {
                double mz = mzValues[i];
                if (mz > maxMzCurrentPeak && currentPeakIndex < peakMzsToQuantitate.size() - 1) {
                    currentPeakIndex++;
                    float currentPeakMz = peakMzsToQuantitate.get(currentPeakIndex);
                    float currentPeakMass = (currentPeakMz - Spectrum.HYDROGEN_ION_MASS) * charge;
                    float deltaMz = (peakTolerancePPM * currentPeakMass / 1000000f) / charge;
                    minMzCurrentPeak = currentPeakMz - deltaMz;
                    maxMzCurrentPeak = currentPeakMz + deltaMz;
                }
                if (mz >= minMzCurrentPeak && mz <= maxMzCurrentPeak) {
                    signalPeaks[i] += signal[i];
                }
            }
            upperZBoundNearPeak = Math.max(upperZBoundNearPeak, BasicStatistics.max(signalPeaks));

            PanelWithLineChart lineChart = new PanelWithPeakChart(mzValues, signalPeaks,
                    "Scan " + (int) scanValues[scanArrayIndex], PanelWithLineChart.defaultShape, Color.BLUE);
            lineChart.addData(mzValues, signal, "all", PanelWithLineChart.defaultShape, Color.GRAY);

            lineChart.setAxisLabels("m/z", "intensity");
            scanLineChartMap.put((int) scanValues[scanArrayIndex], lineChart);
        }

        intensityValues[scanArrayIndex] = signal;

        upperZBound = Math.max(upperZBound, BasicStatistics.max(signal));

        if (scan.getNum() >= lightFirstScanLine && scan.getNum() >= heavyFirstScanLine
                && scan.getNum() <= lightLastScanLine && scan.getNum() <= heavyLastScanLine) {
            int currentPeakIndex = -1;
            float minMzCurrentPeak = -1;
            float maxMzCurrentPeak = -1;
            for (int i = 0; i < sumIntensitiesInQuantRange.length; i++) {
                sumIntensitiesInQuantRange[i] += signal[i];
                float mz = (float) mzValues[i];

                if (mz > maxMzCurrentPeak && currentPeakIndex < peakMzsToQuantitate.size() - 1) {
                    currentPeakIndex++;
                    float currentPeakMz = peakMzsToQuantitate.get(currentPeakIndex);
                    float currentPeakMass = (currentPeakMz - Spectrum.HYDROGEN_ION_MASS) * charge;
                    float deltaMz = (peakTolerancePPM * currentPeakMass / 1000000f) / charge;
                    minMzCurrentPeak = currentPeakMz - deltaMz;
                    maxMzCurrentPeak = currentPeakMz + deltaMz;
                }

                if (mz >= minMzCurrentPeak && mz <= maxMzCurrentPeak) {
                    sumPeakIntensitiesInQuantRange[i] += signal[i];
                    //dhmay adding 20090723 for single-peak quantitation
                    if (currentPeakIndex == maxIdealPeakIndex)
                        lightMaxIdealPeakIntensitySum += signal[i];
                    else if (currentPeakIndex == heavyMonoisotopicPeakIndex + maxIdealPeakIndex)
                        heavyMaxIdealPeakIntensitySum += signal[i];
                }
            }
        }
    }

    ratioOnePeak = lightMaxIdealPeakIntensitySum / Math.max(heavyMaxIdealPeakIntensitySum, 0.001f);

    double maxIntensityOnSumChart = BasicStatistics.max(sumIntensitiesInQuantRange);
    double maxPeakIntensity = BasicStatistics.max(sumPeakIntensitiesInQuantRange);
    if (maxIntensityOnSumChart < 1)
        maxIntensityOnSumChart = maxPeakIntensity;

    float[] monoisotopicMzs = new float[] { lightMz, heavyMz };

    double intensityForSumChartHeight = maxIntensityOnSumChart * 1.5;
    float[] monoisotopicIntensitiesSumChart = new float[] { (float) intensityForSumChartHeight,
            (float) intensityForSumChartHeight };
    intensitySumChart = new PanelWithPeakChart(mzValues, sumPeakIntensitiesInQuantRange, "Peak Intensities");

    intensitySumChart.addData(mzValues, sumIntensitiesInQuantRange, "Intensity Sum",
            PanelWithLineChart.defaultShape, Color.LIGHT_GRAY);
    if (heavyMz > 0)
        intensitySumChart.addDataFloat(monoisotopicMzs, monoisotopicIntensitiesSumChart,
                "Monoisotopic light and heavy", PanelWithLineChart.defaultShape, Color.GREEN);
    else
        intensitySumChart.addDataFloat(new float[] { lightMz },
                new float[] { (float) intensityForSumChartHeight }, "Monoisotopic light and heavy",
                PanelWithLineChart.defaultShape, Color.GREEN);
    if (nonMonoisotopicPeakMzs.length > 0) {
        //for (float mz : nonMonoisotopicPeakMzs) System.err.println("***" + mz);
        float[] nonmonoisotopicIntensitiesSumChart = new float[nonMonoisotopicPeakMzs.length];
        Arrays.fill(nonmonoisotopicIntensitiesSumChart, (float) intensityForSumChartHeight);
        //System.err.println("ADDING LINES, peakMzs null ? " + (peakMzs == null));            
        if (peakMzs != null) {
            intensitySumChart.addDataFloat(nonMonoisotopicPeakMzs, nonmonoisotopicIntensitiesSumChart,
                    "Nonmonoisotopic light and heavy (exact)", PanelWithLineChart.defaultShape, Color.RED);
        } else {
            intensitySumChart.addDataFloat(nonMonoisotopicPeakMzs, nonmonoisotopicIntensitiesSumChart,
                    "Nonmonoisotopic light and heavy (approx)", PanelWithLineChart.defaultShape, Color.ORANGE);

        }
    }
    intensitySumChart.getChart().removeLegend();
    intensitySumChart.setAxisLabels("m/z", "Intensity (Sum)");
    if (maxPeakIntensity > 1)
        ((XYPlot) intensitySumChart.getPlot()).getRangeAxis().setRange(0, maxPeakIntensity * 1.25);
    intensitySumChart.setSize(getWidth(), getHeight());

    if (shouldGenerateLineCharts) {
        float rangeMax = (float) upperZBoundNearPeak * 1.25f;
        for (PanelWithLineChart lineChart : scanLineChartMap.values()) {
            ((XYPlot) lineChart.getPlot()).getRangeAxis().setRange(0, rangeMax);
            float[] monoisotopicIntensities = new float[] { (float) rangeMax, rangeMax };
            lineChart.addDataFloat(monoisotopicMzs, monoisotopicIntensities, "Monoisotopic light and heavy",
                    PanelWithLineChart.defaultShape, Color.GREEN);
            if (nonMonoisotopicPeakMzs.length > 0) {
                float[] nonMonoisotopicIntensities = new float[nonMonoisotopicPeakMzs.length];
                Arrays.fill(nonMonoisotopicIntensities, rangeMax);
                lineChart.addDataFloat(nonMonoisotopicPeakMzs, nonMonoisotopicIntensities,
                        "Nonmonoisotopic light and heavy", PanelWithLineChart.defaultShape, Color.ORANGE);
            }
            lineChart.getChart().removeLegend();
        }
    }

    int lightFirstScanLineIndex = -1;
    int lightLastScanLineIndex = -1;
    int heavyFirstScanLineIndex = -1;
    int heavyLastScanLineIndex = -1;

    int numScansPadded = maxScan - minScan + 1;
    double[] scanValuesPadded;
    double[][] intensityValuesPadded;
    setPaintScale(createHeatMapPaintScale());

    if (numScansPadded == numScans) {
        scanValuesPadded = scanValues;
        intensityValuesPadded = intensityValues;

        if (lightFirstScanLine > 0) {
            for (int i = 0; i < scanValues.length; i++) {
                if (scanValues[i] < lightFirstScanLine)
                    lightFirstScanLineIndex = i;
                else
                    break;
            }
        }
        if (lightLastScanLine > 0) {
            for (int i = 0; i < scanValues.length; i++) {
                if (scanValues[i] <= lightLastScanLine + 1)
                    lightLastScanLineIndex = i;
                else
                    break;
            }
        }
        if (heavyFirstScanLine > 0) {
            for (int i = 0; i < scanValues.length; i++) {
                if (scanValues[i] < heavyFirstScanLine)
                    heavyFirstScanLineIndex = i;
                else
                    break;
            }
        }
        if (heavyLastScanLine > 0) {
            for (int i = 0; i < scanValues.length; i++) {
                if (scanValues[i] <= heavyLastScanLine + 1)
                    heavyLastScanLineIndex = i;
                else
                    break;
            }
        }
    } else {
        _log.debug("Padding! unpadded: " + numScans + ", padded: " + numScansPadded);

        scanValuesPadded = new double[numScansPadded];
        intensityValuesPadded = new double[numScansPadded][numMzBins];

        int unPaddedIndex = 0;

        for (int i = 0; i < scanValuesPadded.length; i++) {
            int scanValue = minScan + i;
            scanValuesPadded[i] = scanValue;

            if (unPaddedIndex < scanValues.length - 1 && scanValue >= scanValues[unPaddedIndex + 1])
                unPaddedIndex++;

            System.arraycopy(intensityValues[unPaddedIndex], 0, intensityValuesPadded[i], 0,
                    intensityValues[unPaddedIndex].length);
        }

        //add the lines for the scanlines, just outside the specified boundaries
        if (lightFirstScanLine > 0) {
            lightFirstScanLineIndex = 0;
            for (int i = 0; i < scanValuesPadded.length; i++) {
                if (scanValuesPadded[i] < lightFirstScanLine) {
                    lightFirstScanLineIndex = i;
                } else
                    break;
            }
        }
        if (lightLastScanLine > 0) {
            lightLastScanLineIndex = 0;
            int nextScanAfterLine2 = 0;
            for (int i = 0; i < scanValues.length; i++)
                if (scanValues[i] > lightLastScanLine) {
                    nextScanAfterLine2 = (int) scanValues[i];
                    break;
                }
            if (nextScanAfterLine2 == 0)
                lightLastScanLineIndex = 0;
            else {
                for (int i = 0; i < scanValuesPadded.length; i++) {
                    if (scanValuesPadded[i] >= nextScanAfterLine2) {
                        lightLastScanLineIndex = i;
                        break;
                    }
                }
            }
        }
        if (heavyFirstScanLine > 0) {
            heavyFirstScanLineIndex = 0;
            for (int i = 0; i < scanValuesPadded.length; i++) {
                if (scanValuesPadded[i] < heavyFirstScanLine) {
                    heavyFirstScanLineIndex = i;
                } else
                    break;
            }
        }
        if (heavyLastScanLine > 0) {
            heavyLastScanLineIndex = 0;
            int nextScanAfterLine2 = 0;
            for (int i = 0; i < scanValues.length; i++)
                if (scanValues[i] > heavyLastScanLine) {
                    nextScanAfterLine2 = (int) scanValues[i];
                    break;
                }
            if (nextScanAfterLine2 == 0)
                heavyLastScanLineIndex = 0;
            else {
                for (int i = 0; i < scanValuesPadded.length; i++) {
                    if (scanValuesPadded[i] >= nextScanAfterLine2) {
                        heavyLastScanLineIndex = i;
                        break;
                    }
                }
            }
        }
    }

    int lightMzIndex = 0;
    for (lightMzIndex = 0; lightMzIndex < intensityValuesPadded[0].length; lightMzIndex++)
        if (mzValues[lightMzIndex] > lightMz)
            break;
    int heavyMzIndex = 0;
    for (heavyMzIndex = 0; heavyMzIndex < intensityValuesPadded[0].length; heavyMzIndex++)
        if (mzValues[heavyMzIndex] > heavyMz)
            break;

    if (lightFirstScanLineIndex > 0)
        shadeArea(intensityValuesPadded, 0, 0, lightFirstScanLineIndex, lightMzIndex);

    if (lightLastScanLineIndex > 0)
        shadeArea(intensityValuesPadded, lightLastScanLineIndex, 0, intensityValuesPadded.length - 1,
                lightMzIndex);

    if (heavyFirstScanLineIndex > 0)
        shadeArea(intensityValuesPadded, 0, heavyMzIndex, heavyFirstScanLineIndex,
                intensityValuesPadded[0].length - 1);

    if (lightLastScanLineIndex > 0)
        shadeArea(intensityValuesPadded, heavyLastScanLineIndex, heavyMzIndex, intensityValuesPadded.length - 1,
                intensityValuesPadded[0].length - 1);

    //if light and heavy first scan are same, shade the remaining area on the left.  Same with last scan
    if (lightFirstScanLineIndex > 0 && heavyFirstScanLineIndex == lightFirstScanLineIndex)
        shadeArea(intensityValuesPadded, 0, lightMzIndex + 1, lightFirstScanLineIndex, heavyMzIndex - 1);
    if (lightLastScanLineIndex > 0 && heavyLastScanLineIndex == lightLastScanLineIndex)
        shadeArea(intensityValuesPadded, lightLastScanLineIndex, lightMzIndex + 1,
                intensityValuesPadded.length - 1, heavyMzIndex - 1);

    //special value for tick intensity
    float intensityForTickMark = -2f;
    float intensityForIdCross = -2f;

    //cross for ID event
    if (idEventScan > 0 && idEventMz > 0) {
        drawHeatmapCrossForEvent(scanValuesPadded, mzValues, intensityValuesPadded, idEventScan, idEventMz,
                intensityForIdCross);
    }

    if (otherEventScans != null && !otherEventScans.isEmpty()) {
        for (int i = 0; i < otherEventScans.size(); i++)
            drawHeatmapCrossForEvent(scanValuesPadded, mzValues, intensityValuesPadded, otherEventScans.get(i),
                    otherEventMZs.get(i), intensityForIdCross);
    }

    //tick marks for specified m/z's
    if (lightMz > 0) {
        placeHeatmapTick(mzValues, intensityValuesPadded, lightMz, intensityForTickMark);
    }
    if (heavyMz > 0) {
        placeHeatmapTick(mzValues, intensityValuesPadded, heavyMz, intensityForTickMark);
    }

    if (peakMzs != null) {
        for (float mz : nonMonoisotopicPeakMzs)
            placeHeatmapTick(mzValues, intensityValuesPadded, mz, intensityForTickMark);
    }

    if (shouldGenerate3DChart)
        generate3DPlot(scanValuesPadded, mzValues, intensityValuesPadded);

    _log.debug("Done loading spectrum in range.");

    setData(scanValuesPadded, mzValues, intensityValuesPadded);
    getChart().removeLegend();
    //try {contourPlot.saveAllImagesToFiles(new File("/home/dhmay/temp/charts"));} catch(IOException e) {}
    ((XYPlot) _plot).getDomainAxis().setRange(minScan, maxScan);
    ((XYPlot) _plot).getRangeAxis().setRange(minMz, maxMz);
}

From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java

public OpenBSTGUI() {
    instance = this;
    UIManager.put("OptionPane.errorIcon", new ImageIcon(Icons.getImage("Cancel", 48)));
    UIManager.put("OptionPane.informationIcon", new ImageIcon(Icons.getImage("About", 48)));
    UIManager.put("OptionPane.questionIcon", new ImageIcon(Icons.getImage("Rename", 48)));
    UIManager.put("OptionPane.warningIcon", new ImageIcon(Icons.getImage("Error", 48)));

    BorderLayout borderLayout = new BorderLayout();
    borderLayout.setVgap(4);/*from  ww w  .j av a  2s. c o  m*/
    getContentPane().setLayout(borderLayout);
    setIconImage(Icons.getImage("Logo", 48));
    setTitle("OpenBST " + OpenBST.VERSION);
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            boolean cancelled = false;
            int i = 0;
            for (Component c : container.getComponents()) {
                if (c instanceof StoryPanel) {
                    i++;
                } else if (c instanceof StoryEditor) {
                    container.setSelectedComponent(c);
                    if (((StoryEditor) c).askClose()) {
                        continue;
                    } else {
                        cancelled = true;
                        break;
                    }
                }
            }
            if (!cancelled) {
                if (i > 0) {
                    int j = Messagers.showConfirm(OpenBSTGUI.this,
                            "You are about to close " + i + " file(s). Are you sure you wish to exit OpenBST?",
                            Messagers.OPTIONS_YES_NO, Messagers.TYPE_WARNING, "Closing OpenBST");
                    if (j != Messagers.OPTION_YES)
                        cancelled = true;
                }
                if (!cancelled)
                    System.exit(0);
            }
        }

    });

    JMenuBar jmb = new JMenuBar();
    jmb.setBackground(OPENBST_BLUE);
    jmb.add(Box.createHorizontalGlue());
    jmb.add(createShortMenu());
    jmb.add(Box.createHorizontalGlue());
    this.setJMenuBar(jmb);

    addDarkModeCallback(b -> {
        jmb.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE);
    });

    container = new JTabbedPane();
    container.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    container.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (SwingUtilities.isMiddleMouseButton(e)) {
                final int i = container.indexAtLocation(e.getX(), e.getY());
                System.out.println(i);
                if (i > -1) {
                    Component c = container.getComponentAt(i);
                    if (c instanceof StoryPanel) {
                        container.setSelectedComponent(c);
                        ((StoryPanel) c).askClose();
                    } else if (c instanceof StoryEditor) {
                        container.setSelectedComponent(c);
                        ((StoryEditor) c).askClose();
                    }
                }
            }
        }
    });
    getContentPane().add(container, BorderLayout.CENTER);

    final JBackgroundPanel welcomeContentPanel = new JBackgroundPanel(Icons.getRandomBackground(),
            Image.SCALE_FAST);
    background = welcomeContentPanel;

    welcomeContentPanel.setLayout(new MigLayout("hidemode 2", "[grow,center]", "[][grow][]"));
    container.add(welcomeContentPanel);
    container.setTitleAt(0, Lang.get("welcome"));

    bannersPanel = new JPanel(new MigLayout("hidemode 2, gap 0px, fill, wrap 1, ins 0"));
    bannersPanel.setBackground(new Color(0, 0, 0, 0));
    welcomeContentPanel.add(bannersPanel, "cell 0 0,grow");

    if (OpenBST.VERSION.endsWith("u")) {
        JButton btnReportBugs = new JButton(Lang.get("welcome.reportbugs"));
        btnReportBugs.addActionListener(e -> {
            VisualsUtils.browse("https://github.com/utybo/BST/issues");
        });
        bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Experiment", 32)), Color.YELLOW,
                Lang.get("welcome.ontheedge"), btnReportBugs, false), "grow");
    } else if (OpenBST.VERSION.contains("SNAPSHOT")) {
        bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Experiment", 32)), Color.ORANGE,
                Lang.get("welcome.snapshot"), null, false), "grow");
    }

    if (System.getProperty("java.specification.version").equals("9")) {
        bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Attention", 32)),
                new Color(255, 50, 50), Lang.get("welcome.java9warning"), null, false), "grow");
    }
    if (System.getProperty("java.specification.version").equals("10")) {
        bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Attention", 32)),
                new Color(255, 50, 50), Lang.get("welcome.java10warning"), null, false), "grow");
    }

    JButton btnJoinDiscord = new JButton(Lang.get("openbst.discordjoin"));
    btnJoinDiscord.addActionListener(e -> {
        VisualsUtils.browse("https://discord.gg/6SVDCMM");
    });
    bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Discord", 48)), DISCORD_COLOR,
            Lang.get("openbst.discord"), btnJoinDiscord, true), "grow");

    JPanel panel = new JPanel();
    panel.setBackground(new Color(0, 0, 0, 0));
    welcomeContentPanel.add(panel, "flowx,cell 0 1,growx,aligny center");
    panel.setLayout(new MigLayout("", "[40%][][][][60%,growprio 50]", "[][grow]"));

    final JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogo", 48)));
    addDarkModeCallback(b -> lblOpenbst
            .setIcon(new ImageIcon(b ? Icons.getImage("FullLogoWhite", 48) : Icons.getImage("FullLogo", 48))));
    panel.add(lblOpenbst, "flowx,cell 0 0 1 2,alignx trailing,aligny center");

    JSeparator separator = new JSeparator();
    separator.setOrientation(SwingConstants.VERTICAL);
    panel.add(separator, "cell 2 0 1 2,growy");

    final JLabel lblWelcomeToOpenbst = new JLabel("<html>" + Lang.get("welcome.intro"));
    lblWelcomeToOpenbst.setMaximumSize(new Dimension(350, 999999));
    panel.add(lblWelcomeToOpenbst, "cell 4 0");

    Component horizontalStrut = Box.createHorizontalStrut(10);
    panel.add(horizontalStrut, "cell 1 1");

    Component horizontalStrut_1 = Box.createHorizontalStrut(10);
    panel.add(horizontalStrut_1, "cell 3 1");

    final JButton btnOpenAFile = new JButton(Lang.get("welcome.open"));
    panel.add(btnOpenAFile, "flowx,cell 4 1");
    btnOpenAFile.setIcon(new ImageIcon(Icons.getImage("Open", 40)));
    btnOpenAFile.addActionListener(e -> {
        openStory(VisualsUtils.askForFile(this, Lang.get("file.title")));
    });

    final JButton btnOpenEditor = new JButton(Lang.get("welcome.openeditor"));
    panel.add(btnOpenEditor, "cell 4 1");
    btnOpenEditor.setIcon(new ImageIcon(Icons.getImage("Edit Property", 40)));
    btnOpenEditor.addActionListener(e -> {
        openEditor(VisualsUtils.askForFile(this, Lang.get("file.title")));
    });

    JButton btnChangeBackground = new JButton(Lang.get("welcome.changebackground"),
            new ImageIcon(Icons.getImage("Change Theme", 16)));
    btnChangeBackground.addActionListener(e -> {
        BufferedImage prev = background.getImage();
        BufferedImage next;
        do {
            next = Icons.getRandomBackground();
        } while (prev == next);
        background.setImage(next);
    });
    welcomeContentPanel.add(btnChangeBackground, "flowx,cell 0 2,alignx left");

    JButton btnWelcomepixabay = new JButton(Lang.get("welcome.pixabay"),
            new ImageIcon(Icons.getImage("External Link", 16)));
    btnWelcomepixabay.addActionListener(e -> {
        VisualsUtils.browse("https://pixabay.com");

    });
    welcomeContentPanel.add(btnWelcomepixabay, "cell 0 2");

    JLabel creds = new JLabel(Lang.get("welcome.credits"));
    creds.setEnabled(false);
    welcomeContentPanel.add(creds, "cell 0 2, gapbefore 10px");

    setSize((int) (830 * Icons.getScale()), (int) (480 * Icons.getScale()));
    setLocationRelativeTo(null);
}

From source file:hr.restart.util.chart.ChartXY.java

/**
 * Creates a BAR CHART/*from  w ww . ja va 2  s .c o  m*/
 * @param dataset The org.jfree.data.CategoryDataset
 * @param title The title
 * @return org.jfree.chart.JFreeChart
 */
private JFreeChart createBarChart(final CategoryDataset dataset, String title, PlotOrientation orientation) {

    final JFreeChart chart = ChartFactory.createBarChart(title, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            orientation, // the plot orientation
            false, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    // the subtitle from the combobox        
    if (jcb != null)
        chart.addSubtitle(new TextTitle(jcb.getSelectedItem().toString()));

    //subtitles setted by the user.
    if (getSubtitles() != null)
        for (int i = 0; i < getSubtitles().size(); i++) {
            chart.addSubtitle(new TextTitle(getSubtitles().get(i).toString()));
        }

    final Plot plot = chart.getPlot();

    // get a reference to the plot for further customisation...
    final CategoryPlot categoryPlot = (CategoryPlot) plot;

    categoryPlot.setNoDataMessage("NO DATA!");

    categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.red, Color.blue, Color.green,
            Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue });
    categoryPlot.setRenderer(renderer);

    renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    renderer.setItemLabelsVisible(true);

    // inside
    //renderer.setBaseItemLabelPaint(Color.white);
    Font font = new Font("SansSerif", Font.PLAIN, 7);
    Font derive = font.deriveFont(Font.BOLD);
    renderer.setBaseItemLabelFont(derive);

    // margin
    final CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    //domainAxis.setBottomCategoryLabelPosition(new CategoryLabelPosition(RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER));
    domainAxis.setCategoryLabelPositions(new CategoryLabelPositions(
            new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_CENTER), // TOP
            new CategoryLabelPosition(RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER), // BOTTOM
            new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
                    CategoryLabelWidthType.RANGE, 0.30f), // LEFT
            new CategoryLabelPosition(RectangleAnchor.RIGHT, TextBlockAnchor.CENTER_RIGHT,
                    CategoryLabelWidthType.RANGE, 0.30f) // RIGHT) 
    ));

    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 0.0);
    renderer.setPositiveItemLabelPosition(p);

    if (comboBoxOrientation != null) {
        if (comboBoxOrientation.getSelectedItem() == "Vertikalni") {

            domainAxis.setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));
        }
    }

    return chart;

}

From source file:jboost.visualization.HistogramFrame.java

private JFreeChart createHistogramChart() {

    XYBarRenderer renderer1 = new XYBarRenderer();
    renderer1.setSeriesPaint(0, Color.cyan);
    renderer1.setSeriesPaint(1, Color.pink);

    XYPlot histPlot = new XYPlot(histogramDataset, null, new NumberAxis("count"), renderer1);

    XYBarRenderer renderer2 = new XYBarRenderer();
    renderer2.setSeriesPaint(0, Color.green);
    renderer2.setSeriesPaint(1, Color.orange);
    renderer2.setUseYInterval(true);//ww w .  j ava2  s.  c o m

    // weight and potential
    if (infoParser.isRobustBoost || infoParser.isAdaBoost || infoParser.isLogLossBoost) {
        StandardXYItemRenderer renderer3 = new StandardXYItemRenderer();
        renderer3.setSeriesPaint(0, Color.blue);
        renderer3.setSeriesPaint(1, Color.red);
        renderer3.setBaseStroke(new BasicStroke(2));

        StandardXYItemRenderer renderer4 = new StandardXYItemRenderer();
        renderer4.setSeriesPaint(0, Color.blue);
        renderer4.setSeriesPaint(1, Color.red);
        renderer4.setBaseStroke(
                new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2, new float[] { 2 }, 0));

        histPlot.setDataset(1, weightDataset);
        histPlot.setRenderer(1, renderer3);

        histPlot.setDataset(2, potentialDataset);
        histPlot.setRenderer(2, renderer4);

        histPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    XYPlot fluctPlot = new XYPlot(fluctDataset, null, new NumberAxis("bin"), renderer2);

    double initialLocation = (upper_limit + lower_limit) / 2.0;
    histMarker = new IntervalMarker(initialLocation, initialLocation);
    histPlot.addDomainMarker(histMarker, Layer.BACKGROUND);
    fluctPlot.addDomainMarker(histMarker, Layer.BACKGROUND);

    // plot.setBackgroundPaint(Color.lightGray);
    // plot.setDomainGridlinePaint(Color.white);
    // plot.setRangeGridlinePaint(Color.white);

    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(new NumberAxis("score"));
    combinedPlot.setGap(10.0);

    // add the subplots...
    ValueAxis axis = new NumberAxis();
    axis.setRange(rawData.getMinRange(iter), rawData.getMaxRange(iter));
    combinedPlot.add(histPlot, 3);
    combinedPlot.add(fluctPlot, 1);
    combinedPlot.setOrientation(PlotOrientation.VERTICAL);
    combinedPlot.setDomainAxis(axis);

    JFreeChart chart = new JFreeChart("Histogram", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, false // legend
    );

    return chart;
}

From source file:com.lfv.lanzius.server.WorkspaceView.java

@Override
protected void paintComponent(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    Document doc = server.getDocument();

    Color storedCol = g.getColor();
    Font storedFont = g.getFont();

    // Fill workspace area
    g.setColor(getBackground());/*w  w w  . ja va  2  s.c o  m*/
    g.fillRect(0, 0, w, h);

    // Should the cached version be updated?
    int updateDocumentVersion = server.getDocumentVersion();
    boolean update = (documentVersion != updateDocumentVersion);

    // Check if we have cached the latest document version, otherwise cache the terminals
    if (update) {
        log.debug("Updating view to version " + updateDocumentVersion);
        terminalMap.clear();
        groupList.clear();
        if (doc != null) {
            synchronized (doc) {

                // Clear the visible attribute on all groups
                // except the started or paused ones
                Element egd = doc.getRootElement().getChild("GroupDefs");
                Iterator iter = egd.getChildren().iterator();
                while (iter.hasNext()) {
                    Element eg = (Element) iter.next();
                    boolean isVisible = !DomTools.getAttributeString(eg, "state", "stopped", false)
                            .equals("stopped");
                    eg.setAttribute("visible", String.valueOf(isVisible));
                }

                // Gather information about terminals and cache it
                Element etd = doc.getRootElement().getChild("TerminalDefs");
                iter = etd.getChildren().iterator();
                while (iter.hasNext()) {
                    Element et = (Element) iter.next();
                    int tid = DomTools.getAttributeInt(et, "id", 0, false);
                    if (tid > 0) {
                        // Create terminal and add it to list
                        Terminal t = new Terminal(tid, DomTools.getAttributeInt(et, "x", 0, false),
                                DomTools.getAttributeInt(et, "y", 0, false),
                                DomTools.getChildText(et, "Name", "T/" + tid, false),
                                DomTools.getAttributeBoolean(et, "online", false, false),
                                DomTools.getAttributeBoolean(et, "selected", false, false));
                        terminalMap.put(tid, t);

                        // Is the terminal monitored?
                        t.isMonitored = DomTools.getAttributeBoolean(et, "monitored", false, false);

                        // Examine the Player element under PlayerSetup
                        t.groupColor = null;
                        Element ep = DomTools.getElementFromSection(doc, "PlayerSetup", "terminalid",
                                String.valueOf(tid));

                        // Has linked player for this terminal
                        if (ep != null) {
                            StringBuffer sb = new StringBuffer();

                            // Append player name
                            sb.append(DomTools.getChildText(ep, "Name", "P/?", true));
                            sb.append(" (");

                            // Append role list
                            boolean hasRoles = false;
                            Element ers = ep.getChild("RoleSetup");
                            if (ers != null) {
                                Iterator iterr = ers.getChildren().iterator();

                                while (iterr.hasNext()) {
                                    Element er = (Element) iterr.next();
                                    String id = er.getAttributeValue("id");
                                    er = DomTools.getElementFromSection(doc, "RoleDefs", "id", id);
                                    if (er != null) {
                                        sb.append(DomTools.getChildText(er, "Name", "R/" + id, false));
                                        sb.append(", ");
                                        hasRoles = true;
                                    }
                                }
                                if (hasRoles) {
                                    // Trim last comma
                                    int len = sb.length();
                                    sb.setLength(Math.max(len - 2, 0));
                                }
                                sb.append(")");
                            }
                            t.roles = sb.toString();

                            // Is the player relocated?
                            t.isRelocated = DomTools.getAttributeBoolean(ep, "relocated", false, false);

                            // Get group name and color
                            Element eg = DomTools.getElementFromSection(doc, "GroupDefs", "id",
                                    DomTools.getAttributeString(ep, "groupid", "0", true));
                            t.groupColor = Color.lightGray;
                            if (eg != null) {
                                String sc = DomTools.getChildText(eg, "Color", null, false);
                                if (sc != null) {
                                    try {
                                        t.groupColor = Color.decode(sc);
                                    } catch (NumberFormatException ex) {
                                        log.warn("Invalid color attribute on Group node, defaulting to grey");
                                    }
                                }
                                //t.name += "  "+DomTools.getChildText(eg, "Name", "G/"+eg.getAttributeValue("id"), false);
                                t.groupName = DomTools.getChildText(eg, "Name",
                                        "G/" + eg.getAttributeValue("id"), false);

                                // This group should now be visible
                                eg.setAttribute("visible", "true");
                            } else
                                log.warn("Invalid groupid attribute on Player node, defaulting to grey");
                        }
                    } else
                        log.error("Invalid id attribute on Terminal node, skipping");
                }

                // Gather information about groups and cache it
                iter = egd.getChildren().iterator();
                while (iter.hasNext()) {
                    Element eg = (Element) iter.next();
                    if (DomTools.getAttributeBoolean(eg, "visible", false, false)) {
                        int gid = DomTools.getAttributeInt(eg, "id", 0, true);
                        if (gid > 0) {
                            Group grp = new Group(gid, DomTools.getChildText(eg, "Name", "G/" + gid, false),
                                    DomTools.getAttributeBoolean(eg, "selected", false, false));
                            groupList.add(grp);

                            // group color
                            String sc = DomTools.getChildText(eg, "Color", null, false);
                            if (sc != null) {
                                try {
                                    grp.color = Color.decode(sc);
                                } catch (NumberFormatException ex) {
                                    log.warn("Invalid color attribute on Group node, defaulting to grey");
                                }
                            }

                            // state color
                            grp.stateColor = Color.red;
                            String state = DomTools.getAttributeString(eg, "state", "stopped", false);
                            if (state.equals("started"))
                                grp.stateColor = Color.green;
                            else if (state.equals("paused"))
                                grp.stateColor = Color.orange;
                        }
                    }
                }
            }
        }
    }

    if (doc == null) {
        g.setColor(Color.black);
        String text = "No configuration loaded. Select 'Load configuration...' from the file menu.";
        g.drawString(text, (w - SwingUtilities.computeStringWidth(g.getFontMetrics(), text)) / 2, h * 5 / 12);
    } else {
        g.setFont(new Font("Dialog", Font.BOLD, 13));

        Iterator<Terminal> itert = terminalMap.values().iterator();
        while (itert.hasNext()) {
            Terminal t = itert.next();

            // Draw box
            int b = t.isSelected ? SERVERVIEW_SELECTION_BORDER : 1;
            g.setColor(Color.black);
            g.fillRect(t.x + SERVERVIEW_SELECTION_BORDER - b, t.y + SERVERVIEW_SELECTION_BORDER - b,
                    SERVERVIEW_TERMINAL_WIDTH + 2 * b, SERVERVIEW_TERMINAL_HEIGHT + 2 * b);
            g.setColor(t.groupColor == null ? Color.white : t.groupColor);
            g.fillRect(t.x + SERVERVIEW_SELECTION_BORDER, t.y + SERVERVIEW_SELECTION_BORDER,
                    SERVERVIEW_TERMINAL_WIDTH, SERVERVIEW_TERMINAL_HEIGHT);

            // Inner areas
            Rectangle r = new Rectangle(t.x + SERVERVIEW_SELECTION_BORDER + SERVERVIEW_TERMINAL_BORDER,
                    t.y + SERVERVIEW_SELECTION_BORDER + SERVERVIEW_TERMINAL_BORDER,
                    SERVERVIEW_TERMINAL_WIDTH - 2 * SERVERVIEW_TERMINAL_BORDER,
                    g.getFontMetrics().getHeight() + 4);

            g.setColor(Color.white);
            g.fillRect(r.x, r.y, r.width, r.height);
            g.fillRect(r.x, r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 2, r.width,
                    SERVERVIEW_TERMINAL_HEIGHT - 3 * SERVERVIEW_TERMINAL_BORDER - r.height - 2);
            g.setColor(Color.black);
            g.drawRect(r.x, r.y, r.width, r.height);
            g.drawRect(r.x, r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 2, r.width,
                    SERVERVIEW_TERMINAL_HEIGHT - 3 * SERVERVIEW_TERMINAL_BORDER - r.height - 2);

            // Name of terminal and group
            if (server.isaClient(t.tid)) {
                g.drawImage(indicatorIsa.getImage(), r.x + r.width - 20, r.y + SERVERVIEW_TERMINAL_HEIGHT - 26,
                        null);
            }
            g.drawString(t.name + " " + t.groupName, r.x + 4, r.y + r.height - 4);

            double px = r.x + 4;
            double py = r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 5;

            // Draw monitored indicator
            if (t.isMonitored) {
                g.drawImage(indicatorMonitored.getImage(), r.x + r.width - 9, r.y + 3, null);
            }

            // Draw relocated indicator
            if (t.isRelocated) {
                g.drawImage(indicatorRelocated.getImage(), r.x + r.width - 9, r.y + 13, null);
            }

            // Draw online indicator
            r.setBounds(r.x, r.y + r.height, r.width, 3);
            g.setColor(t.isOnline ? Color.green : Color.red);
            g.fillRect(r.x, r.y, r.width, r.height);
            g.setColor(Color.black);
            g.drawRect(r.x, r.y, r.width, r.height);

            // Roles
            if (t.roles.length() > 0) {
                LineBreakMeasurer lbm = new LineBreakMeasurer(new AttributedString(t.roles).getIterator(),
                        new FontRenderContext(null, false, true));

                TextLayout layout;
                while ((layout = lbm
                        .nextLayout(SERVERVIEW_TERMINAL_WIDTH - 2 * SERVERVIEW_TERMINAL_BORDER)) != null) {
                    if (py < t.y + SERVERVIEW_TERMINAL_HEIGHT) {
                        py += layout.getAscent();
                        layout.draw((Graphics2D) g, (int) px, (int) py);
                        py += layout.getDescent() + layout.getLeading();
                    }
                }
            }
        }

        // Draw group indicators
        int nbrGroupsInRow = w
                / (2 * Constants.SERVERVIEW_SELECTION_BORDER + 2 + Constants.SERVERVIEW_GROUP_WIDTH);
        if (nbrGroupsInRow < 1)
            nbrGroupsInRow = 1;
        int nbrGroupRows = (groupList.size() + nbrGroupsInRow - 1) / nbrGroupsInRow;

        int innerWidth = Constants.SERVERVIEW_GROUP_WIDTH;
        int innerHeight = g.getFontMetrics().getHeight() + 5;

        int outerWidth = innerWidth + 2 * Constants.SERVERVIEW_SELECTION_BORDER + 2;
        int outerHeight = innerHeight + 2 * Constants.SERVERVIEW_SELECTION_BORDER + 2;

        int x = 0;
        int y = h - outerHeight * nbrGroupRows;

        g.setColor(Color.white);
        g.fillRect(0, y, w, h - y);
        g.setColor(Color.black);
        g.drawLine(0, y - 1, w - 1, y - 1);

        Iterator<Group> iterg = groupList.iterator();
        while (iterg.hasNext()) {
            Group grp = iterg.next();

            // Group box
            grp.boundingRect.setBounds(x, y, outerWidth, outerHeight);
            int b = grp.isSelected ? Constants.SERVERVIEW_SELECTION_BORDER : 1;
            g.setColor(Color.black);
            g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER - b + 1,
                    y + Constants.SERVERVIEW_SELECTION_BORDER - b + 1, innerWidth + 2 * b, innerHeight + 2 * b);
            g.setColor(grp.color);
            g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER + 1,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + 1, innerWidth, innerHeight);

            g.setColor(Color.black);
            g.drawString(grp.name, x + Constants.SERVERVIEW_SELECTION_BORDER + 4,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + innerHeight - 4 + 1);

            // Draw started indicator
            g.setColor(grp.stateColor);
            g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER + 1,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + 1, innerWidth, 2);
            g.setColor(Color.black);
            g.drawLine(x + Constants.SERVERVIEW_SELECTION_BORDER + 1,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + 3,
                    x + Constants.SERVERVIEW_SELECTION_BORDER + 1 + innerWidth,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + 3);

            x += outerWidth;
            if ((x + outerWidth) > w) {
                x = 0;
                y += outerHeight;
            }
        }
    }

    // Store cached version
    documentVersion = updateDocumentVersion;

    g.setColor(storedCol);
    g.setFont(storedFont);
}

From source file:edu.fullerton.ldvservlet.SrcList.java

private PageItem makePlots(ArrayList<ChanSourceData> csdList, String name, Database db, Page vpage,
        ViewUser vuser, String contextPath) throws WebUtilException, LdvTableException {
    PageItemList ret = new PageItemList();
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Date/Time (UTC)"));
    plot.setGap(10.0);/*from   ww  w.  j  av a 2 s. c o m*/

    String baseName = "";
    StringBuilder errors = new StringBuilder();
    int plotNum = 0;
    Color[] colors = { Color.RED, Color.BLUE, Color.MAGENTA, Color.ORANGE, Color.DARK_GRAY, Color.GREEN };
    boolean gotData = false;
    TimeInterval timeRange = null;
    for (ChanSourceData csd : csdList) {
        TimeInterval ti = csd.getTimeRange();
        if (ti != null) {
            if (timeRange == null) {
                timeRange = ti;
            } else if (timeRange.overlaps(ti)) {
                timeRange = timeRange.mergeIntervals(ti);
            } else if (ti.getStartGps() < timeRange.getStartGps()) {
                timeRange.setStartGps(ti.getStartGps());
            } else if (ti.getStopGps() > timeRange.getStopGps()) {
                timeRange.setStopGps(ti.getStopGps());
            }
        }
    }
    if (timeRange != null) {
        for (ChanSourceData csd : csdList) {
            baseName = csd.getChanInfo().getBaseName();
            TimeSeriesCollection mtds = new TimeSeriesCollection();
            String server = csd.getChanInfo().getServer().replace(".caltech.edu", "");
            String legend = String.format("Type: %1$s at %2$s", csd.getChanInfo().getcType(), server);
            TimeSeries ts;
            double[][] data = csd.getGraphData();
            if (data == null) {
                data = new double[2][2];
                data[0][0] = timeRange.getStartGps();
                data[1][0] = timeRange.getStopGps();
                data[0][1] = data[1][1] = 0;
                errors.append("Error getting data for: ").append(legend).append("<br>");
            } else {
                gotData = true;
            }
            for (double[] d : data) {
                d[1] = d[1] <= 1 ? 1 : d[1];
            }
            ts = getTimeSeries(data, legend);

            mtds.addSeries(ts);
            XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA);

            BasicStroke str = new BasicStroke(2);
            int colorIdx = plotNum % colors.length;
            Color color = colors[colorIdx];
            NumberAxis yAxis = new NumberAxis("% Avail");
            yAxis.setRange(0, 100);
            renderer.setBaseFillPaint(color);
            renderer.setSeriesFillPaint(0, Color.WHITE);
            renderer.setBaseStroke(str);
            renderer.setUseFillPaint(true);
            XYPlot subplot = new XYPlot(mtds, null, yAxis, renderer);
            plot.add(subplot);

            plotNum++;
        }

        ChartPanel cpnl;
        JFreeChart chart;
        String gtitle = String.format("Available data for %1$s ", baseName);
        String subTitleTxt = String.format("From %1$s to %2$s",
                TimeAndDate.gpsAsUtcString(timeRange.getStartGps()),
                TimeAndDate.gpsAsUtcString(timeRange.getStopGps()));

        plot.setOrientation(PlotOrientation.VERTICAL);

        chart = new JFreeChart(gtitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

        chart.addSubtitle(new TextTitle(subTitleTxt));
        cpnl = new ChartPanel(chart, false, false, false, false, false);

        PluginSupport psupport = new PluginSupport();
        psupport.setup(db, vpage, vuser);
        int imgId;
        PageItemImage img = null;
        try {
            psupport.setSize(800, 600);
            imgId = psupport.saveImageAsPNG(cpnl);
            String url = String.format("%1$s/view?act=getImg&amp;imgId=%2$d", contextPath, imgId);

            img = new PageItemImage(url, "availability", baseName);

        } catch (SQLException | IOException | NoSuchAlgorithmException ex) {
            String ermsg = String.format("Error creating or saving image: %1$s - $2$s",
                    ex.getClass().getSimpleName(), ex.getLocalizedMessage());
            errors.append(ermsg);

        }
        if (errors.length() > 0) {
            ret.add(errors.toString());
        }
        if (img != null) {
            ret.add(img);
        }
    } else {
        ret.add("No data to plot.");
    }
    return ret;
}

From source file:no.met.jtimeseries.MeteogramWrapper.java

/**
 * Reset bound when both air temperature and dew point temperature are shown
 * @param model// ww  w. j  a v  a  2 s.  c  om
 * @param plotter
 */
private void resetBoundForTemperature(GenericDataModel model, ChartPlotter plotter) {
    NumberPhenomenon temperature = model.getNumberPhenomenon(PhenomenonName.AirTemperature.toString());
    NumberPhenomenon dewtemperature = model.getNumberPhenomenon(PhenomenonName.dewPointTemperature.toString());
    double minValue = temperature.getMinValue() <= dewtemperature.getMinValue() ? temperature.getMinValue()
            : dewtemperature.getMinValue();
    double maxValue = temperature.getMaxValue() >= dewtemperature.getMaxValue() ? temperature.getMaxValue()
            : dewtemperature.getMaxValue();

    NumberAxis numberAxis1 = (NumberAxis) plotter.getPlot().getRangeAxis(plotter.getPlotIndex() - 2);
    numberAxis1.setLabel(messages.getString("parameter.temperature"));
    ChartPlotter.setAxisBound(numberAxis1, maxValue, minValue, 8, BACKGROUND_LINES);

    NumberAxis numberAxis2 = (NumberAxis) plotter.getPlot().getRangeAxis(plotter.getPlotIndex() - 1);
    numberAxis2.setLabel(messages.getString("parameter.temperature"));
    numberAxis2.setUpperBound(numberAxis1.getUpperBound());
    numberAxis2.setLowerBound(numberAxis1.getLowerBound());
    numberAxis2.setTickUnit(numberAxis1.getTickUnit());
    numberAxis2.setVisible(false);

    //Add labels on the curves
    NumberValueItem airItem = (NumberValueItem) temperature.getItems().get(0);
    NumberValueItem dewpointItem = (NumberValueItem) dewtemperature.getItems().get(0);

    plotter.getPlot().getRenderer()
            .addAnnotation(ChartPlotter.createTextAnnotation(messages.getString("label.air"),
                    temperature.getStartTime().getTime(), airItem.getValue() + 0.1d, TextAnchor.BOTTOM_LEFT,
                    Color.RED), Layer.BACKGROUND);
    plotter.getPlot().getRenderer()
            .addAnnotation(ChartPlotter.createTextAnnotation(messages.getString("label.dewpoint"),
                    dewtemperature.getStartTime().getTime(), dewpointItem.getValue() + 0.1d,
                    TextAnchor.BOTTOM_LEFT, Color.ORANGE), Layer.BACKGROUND);
}

From source file:blue.automation.AutomationManager.java

private JMenu buildChannelMenu(Channel channel, SoundLayer soundLayer) {

    JMenu retVal = new JMenu();

    retVal.setText(channel.getName());/*www  .j  a v  a2s  . c o  m*/

    ParameterIdList paramIdList = soundLayer.getAutomationParameters();

    // pre effects
    EffectsChain preEffects = channel.getPreEffects();

    if (preEffects.size() > 0) {
        JMenu preMenu = new JMenu("Pre-Effects");
        retVal.add(preMenu);

        for (int i = 0; i < preEffects.size(); i++) {
            Automatable automatable = (Automatable) preEffects.getElementAt(i);

            ParameterList params = automatable.getParameterList();

            if (params.size() > 0) {
                JMenu effectMenu = new JMenu();

                if (automatable instanceof Effect) {
                    effectMenu.setText(((Effect) automatable).getName());
                } else if (automatable instanceof Send) {
                    effectMenu.setText("Send: " + ((Send) automatable).getSendChannel());
                } else {
                    effectMenu.setText("ERROR");
                }

                preMenu.add(effectMenu);

                for (int j = 0; j < params.size(); j++) {
                    Parameter param = params.getParameter(j);
                    JMenuItem paramItem = new JMenuItem();
                    paramItem.setText(param.getName());
                    paramItem.addActionListener(parameterActionListener);

                    if (param.isAutomationEnabled()) {
                        if (paramIdList.contains(param.getUniqueId())) {
                            paramItem.setForeground(Color.GREEN);
                        } else {
                            paramItem.setForeground(Color.ORANGE);
                        }

                    }

                    paramItem.putClientProperty("param", param);

                    effectMenu.add(paramItem);
                }
            }
        }
    }

    // volume
    JMenuItem volItem = new JMenuItem("Volume");
    Parameter volParam = channel.getLevelParameter();
    volItem.putClientProperty("param", volParam);
    volItem.addActionListener(parameterActionListener);

    if (volParam.isAutomationEnabled()) {
        if (paramIdList.contains(volParam.getUniqueId())) {
            volItem.setForeground(Color.GREEN);
        } else {
            volItem.setForeground(Color.ORANGE);
        }

    }

    retVal.add(volItem);

    // post effects
    EffectsChain postEffects = channel.getPostEffects();

    if (postEffects.size() > 0) {
        JMenu postMenu = new JMenu("Post-Effects");
        retVal.add(postMenu);

        for (int i = 0; i < postEffects.size(); i++) {
            Automatable automatable = (Automatable) postEffects.getElementAt(i);

            ParameterList params = automatable.getParameterList();

            if (params.size() > 0) {
                JMenu effectMenu = new JMenu();

                if (automatable instanceof Effect) {
                    effectMenu.setText(((Effect) automatable).getName());
                } else if (automatable instanceof Send) {
                    effectMenu.setText("Send: " + ((Send) automatable).getSendChannel());
                } else {
                    effectMenu.setText("ERROR");
                }

                postMenu.add(effectMenu);

                for (int j = 0; j < params.size(); j++) {
                    Parameter param = params.getParameter(j);
                    JMenuItem paramItem = new JMenuItem();
                    paramItem.setText(param.getName());
                    paramItem.addActionListener(parameterActionListener);

                    if (param.isAutomationEnabled()) {
                        if (paramIdList.contains(param.getUniqueId())) {
                            paramItem.setForeground(Color.GREEN);
                        } else {
                            paramItem.setForeground(Color.ORANGE);
                        }

                    }

                    paramItem.putClientProperty("param", param);

                    effectMenu.add(paramItem);
                }
            }
        }
    }

    return retVal;
}