Example usage for org.jfree.chart.title LegendTitle setVisible

List of usage examples for org.jfree.chart.title LegendTitle setVisible

Introduction

In this page you can find the example usage for org.jfree.chart.title LegendTitle setVisible.

Prototype

public void setVisible(boolean visible) 

Source Link

Document

Sets a flag that controls whether or not the title should be drawn, and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/**
 * paint this chart as legend/*from w w  w .j av  a2 s. co m*/
 *
 * @param graphics
 *          the graphics
 * @param bounds
 *          the bounds
 */
private final void __paintAsLegend(final Graphics2D graphics, final Rectangle bounds) {
    final LegendTitle legend;
    final _JFCXYItemRenderer render;
    final XYItemRenderer old;
    Rectangle2D r;
    double w, h;

    legend = this.m_chart.getLegend();
    if ((legend == null) || (!(legend.isVisible()))) {
        this.m_chart.draw(graphics, bounds);
        return;
    }

    legend.setVisible(false);
    old = this.m_plot.getRenderer();
    try {
        render = new _JFCXYItemRenderer(old);
        this.m_plot.setRenderer(render);
        this.m_plot.setRenderer(0, render);
        this.paint(graphics, bounds);
        legend.setVisible(true);

        legend.setBackgroundPaint(this.m_plot.getBackgroundPaint());
        w = (render.m_maxX - render.m_minX);
        h = (render.m_maxY - render.m_minY);
        r = new Rectangle2D.Double(//
                render.m_minX + (0.05d * w), //
                render.m_minY + (0.05d * h), //
                w * 0.9d, //
                h * 0.9d);

        _JFCLineChart2D.__paintLegend(legend, graphics, r);
    } finally {
        this.m_plot.setRenderer(old);
    }
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java

private JFreeChart updateBubbleChartChart(Set<QuantDiseaseGroupsComparison> selectedComparisonList) {

    if (userCustomizedComparison != null) {
        return updateBubbleChartChartWithCustUserData(selectedComparisonList);
    }/*from ww  w .j  a va  2 s.co  m*/
    tooltipsProtNumberMap.clear();
    DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset();
    int counter = 0;
    int upper = -1;
    boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly();

    for (QuantDiseaseGroupsComparison qc : selectedComparisonList) {
        if (significantOnly) {
            int upperCounter = 0;
            for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) {
                if (qp == null) {
                    continue;
                }

                if (qp.getSignificantTrindCategory() == 2 || qp.getSignificantTrindCategory() == 5) {
                    continue;
                }

                upperCounter++;
            }
            if (upperCounter > upper) {
                upper = upperCounter;
            }

        } else {
            if (qc.getComparProtsMap() == null) {
                System.out.println("null qc " + qc.getComparisonHeader());

            }
            if (qc.getComparProtsMap().size() > upper) {
                upper = qc.getComparProtsMap().size();
            }
        }

    }

    final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>();
    Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor,
            new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE };

    double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI };
    seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE,
            Color.WHITE, Color.WHITE });
    defaultxyzdataset.addSeries("   ", seriesValuesI);

    for (QuantDiseaseGroupsComparison qc : selectedComparisonList) {

        double[] tempWidthValue = new double[8];
        if (qc.getComparProtsMap() == null) {
            continue;
        }

        for (String key : qc.getComparProtsMap().keySet()) {
            qc.getComparProtsMap().get(key).updateLabelLayout();

            if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2
                    || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) {
                tempWidthValue[3] = 0;
                tempWidthValue[6] = 0;
            } else {
                tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory()
                        + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1]
                                + 1;
            }
        }

        if (tempWidthValue[3] > 0 && tempWidthValue[3] >= 0) {
            stableColor = new Color(1, 141, 244);

        } else {
            stableColor = Color.decode("#b5babb");

        }

        tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6];
        tempWidthValue[6] = 0;
        dataColor[3] = stableColor;

        int length = 0;
        if (upper < 10) {
            upper = 10;
        }

        double[] tooltipNumbess = new double[tempWidthValue.length];
        System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length);
        this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess);
        for (int x = 0; x < tempWidthValue.length; x++) {
            if (tempWidthValue[x] > 0) {
                tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[x] * 1.5 / upper, 0.05);
                length++;
            }

        }
        double[] yAxisValue = new double[length];
        double[] xAxisValue = new double[length];
        double[] widthValue = new double[length];
        Color[] serColorArr = new Color[length];
        length = 0;

        for (int x = 0; x < tempWidthValue.length; x++) {
            if (tempWidthValue[x] > 0) {
                xAxisValue[length] = x;
                yAxisValue[length] = counter + 1;
                widthValue[length] = tempWidthValue[x];
                serColorArr[length] = dataColor[x];
                length++;
            }

        }

        if (length == 1 && selectedComparisonList.size() == 1) {
            widthValue[0] = 1;
        }
        seriousColorMap.put(counter + 1, serColorArr);

        double[][] seriesValues = { yAxisValue, xAxisValue, widthValue };
        defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues);
        counter++;
    }
    double[] yAxisValueII = new double[0];
    double[] xAxisValueII = new double[0];
    double[] widthValueII = new double[0];
    seriousColorMap.put(counter + 1, new Color[] {});
    double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII };
    defaultxyzdataset.addSeries(" ", seriesValuesII);

    final Color[] labelsColor = new Color[] { Color.LIGHT_GRAY, new Color(80, 183, 71), Color.LIGHT_GRAY,
            new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.LIGHT_GRAY };
    Font font = new Font("Verdana", Font.BOLD, 13);
    SymbolAxis yAxis = new SymbolAxis(null,
            new String[] { "  ", "Decreased", " ", "Equal", " ", "Increased", "  " }) {

        int i = 0;

        @Override
        public RectangleInsets getTickLabelInsets() {
            //                System.out.println("at ---- super.getTickLabelInsets() " + super.getTickLabelInsets());
            //                if (i == 0) {
            //                    i++;
            //                    return new RectangleInsets(-5, -5, 0, 0);
            //                }else                   
            //                
            return super.getTickLabelInsets(); //To change body of generated methods, choose Tools | Templates.
        }

        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= labelsColor.length) {
                x = 0;
            }
            return labelsColor[x++];
        }
    };
    yAxis.setAutoRangeStickyZero(true);
    yAxis.setFixedAutoRange(8);
    yAxis.setTickLabelFont(font);
    yAxis.setGridBandsVisible(false);
    yAxis.setAxisLinePaint(Color.LIGHT_GRAY);
    yAxis.setTickMarksVisible(false);
    yAxis.setUpperBound(6);

    String[] xAxisLabels = new String[selectedComparisonList.size() + 2];
    int x = 0;
    xAxisLabels[x] = "";
    int maxLength = -1;
    //init labels color

    final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 2];
    diseaseGroupslabelsColor[x] = Color.WHITE;
    x++;

    for (QuantDiseaseGroupsComparison comp : selectedComparisonList) {
        String header = comp.getComparisonHeader();
        String updatedHeader = header.split(" / ")[0].split("\n")[0] + " / "
                + header.split(" / ")[1].split("\n")[0] + "";

        xAxisLabels[x] = updatedHeader + " (" + comp.getDatasetIndexes().length + ")    ";
        if (xAxisLabels[x].length() > maxLength) {
            maxLength = xAxisLabels[x].length();
        }
        diseaseGroupslabelsColor[x] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]);
        x++;

    }
    xAxisLabels[x] = "";
    diseaseGroupslabelsColor[x] = Color.WHITE;

    SymbolAxis xAxis;
    final boolean finalNum;
    finalNum = maxLength > 30 && selectedComparisonList.size() > 4;

    xAxis = new SymbolAxis(null, xAxisLabels) {

        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= diseaseGroupslabelsColor.length) {
                x = 0;
            }
            return diseaseGroupslabelsColor[x++];
        }

        private final boolean localfinal = finalNum;

        @Override
        protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

            if (localfinal) {
                setVerticalTickLabels(localfinal);
                return super.refreshTicksHorizontal(g2, dataArea, edge);
            }
            List ticks = new java.util.ArrayList();
            Font tickLabelFont = getTickLabelFont();
            g2.setFont(tickLabelFont);
            double size = getTickUnit().getSize();
            int count = calculateVisibleTickCount();
            double lowestTickValue = calculateLowestVisibleTickValue();
            double previousDrawnTickLabelPos = 0.0;
            double previousDrawnTickLabelLength = 0.0;
            if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
                for (int i = 0; i < count; i++) {
                    double currentTickValue = lowestTickValue + (i * size);
                    double xx = valueToJava2D(currentTickValue, dataArea, edge);
                    String tickLabel;
                    NumberFormat formatter = getNumberFormatOverride();
                    if (formatter != null) {
                        tickLabel = formatter.format(currentTickValue) + "  ";
                    } else {
                        tickLabel = valueToString(currentTickValue) + "  ";
                    }
                    // avoid to draw overlapping tick labels
                    Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics());
                    double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth();
                    boolean tickLabelsOverlapping = false;
                    if (i > 0) {
                        double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0;
                        if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) {
                            tickLabelsOverlapping = true;
                        }
                    }
                    if (tickLabelsOverlapping) {
                        setVerticalTickLabels(true);
                    } else {
                        // remember these values for next comparison
                        previousDrawnTickLabelPos = xx;
                        previousDrawnTickLabelLength = tickLabelLength;
                    }
                    TextAnchor anchor;
                    TextAnchor rotationAnchor;
                    double angle = 0.0;
                    if (isVerticalTickLabels()) {
                        anchor = TextAnchor.CENTER_RIGHT;
                        rotationAnchor = TextAnchor.CENTER_RIGHT;
                        if (edge == RectangleEdge.TOP) {
                            angle = 76.5;
                        } else {
                            angle = -76.5;
                        }
                    } else {
                        if (edge == RectangleEdge.TOP) {
                            anchor = TextAnchor.BOTTOM_CENTER;
                            rotationAnchor = TextAnchor.BOTTOM_CENTER;
                        } else {
                            anchor = TextAnchor.TOP_CENTER;
                            rotationAnchor = TextAnchor.TOP_CENTER;
                        }
                    }
                    Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                            angle);

                    ticks.add(tick);
                }
            }
            return ticks;
        }
    };

    //        }
    xAxis.setTickLabelFont(font);
    xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20));
    xAxis.setAutoRangeStickyZero(true);
    xAxis.setTickMarksVisible(false);
    xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1);

    xAxis.setGridBandsVisible(false);
    xAxis.setAxisLinePaint(Color.LIGHT_GRAY);
    int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS;

    XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) {
        private int counter = 0;
        private int localSerious = -1;
        private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap;

        @Override
        public Paint getSeriesPaint(int series) {
            if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) {
                counter = 0;
                isNewImge = false;
            }
            localSerious = series;
            Color c = localSeriousColorMap.get(series)[counter];
            counter++;

            return c;
        }

    };

    XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) {

        @Override
        protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) {
            try {
                if (!ticks.isEmpty()) {
                    ticks.remove(0);
                }
                if (!ticks.isEmpty()) {
                    ticks.remove(ticks.size() - 1);
                }
            } catch (Exception e) {
            }
            super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates.
        }

        //            private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")};
        //
        //            private final Font font = new Font("Verdana", Font.PLAIN, 12);
        //            private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."};
        //
        //            @Override
        //            public LegendItemCollection getLegendItems() {
        //                LegendItemCollection legendItemCollection = new LegendItemCollection();
        //                for (int i = 0; i < labelsColor.length; i++) {
        //                    LegendItem item = new LegendItem(labels[i], labelsColor[i]);
        //                    item.setLabelFont(font);
        //
        //                    legendItemCollection.add(item);
        //
        //                }
        //
        //                return legendItemCollection;//To change body of generated methods, choose Tools | Templates.
        //            }
    };

    JFreeChart generatedChart = new JFreeChart(xyplot) {

    };

    xyplot.setOutlineVisible(false);
    LegendTitle legend = generatedChart.getLegend();

    legend.setVisible(false);
    //        legend.setMargin(20, 0, 0, 0);
    ////        legend.setBorder(1, 1, 1, 1);
    //        legend.setFrame(new BlockBorder(1, 0, 1, 0, Color.LIGHT_GRAY));

    //        generatedChart.removeLegend();
    //        xyplot.setForegroundAlpha(0.65F);
    xyplot.setBackgroundPaint(Color.WHITE);

    generatedChart.setBackgroundPaint(Color.WHITE);

    generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart);
    //        exporter.writeChartToPDFFile(generatedChart, 595, 842, "bublechart.pdf");
    return generatedChart;

}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java

private JFreeChart updateBubbleChartChartWithCustUserData(
        Set<QuantDiseaseGroupsComparison> selectedComparisonList) {

    tooltipsProtNumberMap.clear();//from w w w . j  a  v  a2s  .c  om
    DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset();
    int counter = 0;
    int upper = -1;
    boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly();

    if (userCustomizedComparison.getComparProtsMap().size() > upper) {
        upper = userCustomizedComparison.getComparProtsMap().size();
    }

    for (QuantDiseaseGroupsComparison qc : selectedComparisonList) {
        if (significantOnly) {
            int upperCounter = 0;
            for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) {
                if (qp == null) {
                    continue;
                }

                if (qp.getSignificantTrindCategory() == 2) {
                    continue;
                }

                upperCounter++;
            }
            if (upperCounter > upper) {
                upper = upperCounter;
            }

        } else {
            if (qc.getComparProtsMap() == null) {
                System.out.println("null qc " + qc.getComparisonHeader());

            }
            if (qc.getComparProtsMap().size() > upper) {
                upper = qc.getComparProtsMap().size();
            }
        }

    }

    final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>();
    Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor,
            new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE };
    double[] tempWidthValue = new double[8];

    double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 };
    double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI };
    seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE,
            Color.WHITE, Color.WHITE });
    defaultxyzdataset.addSeries("   ", seriesValuesI);

    for (String key : userCustomizedComparison.getComparProtsMap().keySet()) {
        userCustomizedComparison.getComparProtsMap().get(key).updateLabelLayout();

        {
            tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key).getSignificantTrindCategory()
                    + 1] = tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key)
                            .getSignificantTrindCategory() + 1] + 1;
        }
    }
    int length = 0;
    if (upper < 10) {
        upper = 10;
    }
    double[] tooltipNumbess = new double[tempWidthValue.length];
    System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length);
    this.tooltipsProtNumberMap.put(userCustomizedComparison.getComparisonHeader(), tooltipNumbess);
    for (int z = 0; z < tempWidthValue.length; z++) {
        if (tempWidthValue[z] > 0) {
            tempWidthValue[z] = scaleValues(tempWidthValue[z], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05);
            length++;
        }

    }
    double[] yAxisValue = new double[length];
    double[] xAxisValue = new double[length];
    double[] widthValue = new double[length];
    Color[] serColorArr = new Color[length];
    length = 0;

    for (int z = 0; z < tempWidthValue.length; z++) {
        if (tempWidthValue[z] > 0) {
            xAxisValue[length] = z;
            yAxisValue[length] = counter + 1;
            widthValue[length] = tempWidthValue[z];
            serColorArr[length] = dataColor[z];
            length++;
        }

    }

    if (length == 1 && selectedComparisonList.size() == 1) {
        widthValue[0] = 1;
    }
    seriousColorMap.put(++counter, serColorArr);

    double[][] seriesValues = { yAxisValue, xAxisValue, widthValue };
    defaultxyzdataset.addSeries(userCustomizedComparison.getComparisonHeader(), seriesValues);

    for (QuantDiseaseGroupsComparison qc : selectedComparisonList) {

        tempWidthValue = new double[8];
        if (qc.getComparProtsMap() == null) {
            continue;
        }

        for (String key : qc.getComparProtsMap().keySet()) {
            qc.getComparProtsMap().get(key).updateLabelLayout();

            if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2
                    || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) {
                tempWidthValue[3] = 0;
                tempWidthValue[6] = 0;
            } else {
                tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory()
                        + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1]
                                + 1;
            }
        }
        if (tempWidthValue[3] > 0 && tempWidthValue[6] >= 0) {
            stableColor = new Color(1, 141, 244);

        } else {
            stableColor = Color.decode("#b5babb");
        }
        tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6];
        tempWidthValue[6] = 0;
        dataColor[3] = stableColor;
        length = 0;
        if (upper < 10) {
            upper = 10;
        }
        tooltipNumbess = new double[tempWidthValue.length];
        System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length);
        this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess);
        for (int x = 0; x < tempWidthValue.length; x++) {
            if (tempWidthValue[x] > 0) {
                tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05);
                length++;
            }

        }
        yAxisValue = new double[length];
        xAxisValue = new double[length];
        widthValue = new double[length];
        serColorArr = new Color[length];
        length = 0;

        for (int x = 0; x < tempWidthValue.length; x++) {
            if (tempWidthValue[x] > 0) {
                xAxisValue[length] = x;
                yAxisValue[length] = counter + 1;
                widthValue[length] = tempWidthValue[x];
                serColorArr[length] = dataColor[x];
                length++;
            }

        }

        if (length == 1 && selectedComparisonList.size() == 1) {
            widthValue[0] = 1;
        }
        seriousColorMap.put(counter + 1, serColorArr);

        seriesValues = new double[][] { yAxisValue, xAxisValue, widthValue };
        defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues);

        counter++;
    }

    double[] yAxisValueII = new double[0];
    double[] xAxisValueII = new double[0];
    double[] widthValueII = new double[0];
    seriousColorMap.put(counter + 1, new Color[] {});
    double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII };
    defaultxyzdataset.addSeries(" ", seriesValuesII);

    final Color[] labelsColor = new Color[] { Color.WHITE, new Color(80, 183, 71), Color.LIGHT_GRAY,
            new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.WHITE };
    Font font = new Font("Verdana", Font.BOLD, 13);
    SymbolAxis yAxis = new SymbolAxis(null,
            new String[] { "  ", "Decreased", " ", "Equal", " ", "Increased", "  " }) {
        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= labelsColor.length) {
                x = 0;
            }
            return labelsColor[x++];
        }
    };

    yAxis.setAutoRangeStickyZero(true);
    yAxis.setFixedAutoRange(8);
    yAxis.setTickLabelFont(font);
    yAxis.setGridBandsVisible(false);
    yAxis.setAxisLinePaint(Color.LIGHT_GRAY);
    yAxis.setTickMarksVisible(false);
    yAxis.setUpperBound(6);

    String[] xAxisLabels = new String[selectedComparisonList.size() + 3];
    xAxisLabels[0] = "  ";
    final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 3];
    int x = 0;
    int maxLength = -1;
    //init labels color

    String updatedHeader = userCustomizedComparison.getComparisonHeader().split(" / ")[0].split("\n")[0] + " / "
            + userCustomizedComparison.getComparisonHeader().split(" / ")[1].split("\n")[0] + "";
    diseaseGroupslabelsColor[0] = Color.WHITE;
    diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get("UserData");
    xAxisLabels[x + 1] = updatedHeader + " (" + userCustomizedComparison.getDatasetIndexes().length + ")    ";
    if (xAxisLabels[x + 1].length() > maxLength) {
        maxLength = xAxisLabels[++x].length();
    }

    for (QuantDiseaseGroupsComparison comp : selectedComparisonList) {
        String header = comp.getComparisonHeader();
        updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0]
                + "";

        xAxisLabels[x + 1] = updatedHeader + " (" + comp.getDatasetIndexes().length + ")    ";
        if (xAxisLabels[x + 1].length() > maxLength) {
            maxLength = xAxisLabels[x + 1].length();
        }
        diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]);
        x++;

    }
    xAxisLabels[x + 1] = "   ";

    SymbolAxis xAxis;
    final boolean finalNum;
    finalNum = maxLength > 30 && selectedComparisonList.size() > 4;

    xAxis = new SymbolAxis(null, xAxisLabels) {

        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= diseaseGroupslabelsColor.length) {
                x = 0;
            }
            return diseaseGroupslabelsColor[x++];
        }

        private final boolean localfinal = finalNum;

        @Override
        protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

            if (localfinal) {
                setVerticalTickLabels(localfinal);
                return super.refreshTicksHorizontal(g2, dataArea, edge);
            }
            List ticks = new java.util.ArrayList();
            Font tickLabelFont = getTickLabelFont();
            g2.setFont(tickLabelFont);
            double size = getTickUnit().getSize();
            int count = calculateVisibleTickCount();
            double lowestTickValue = calculateLowestVisibleTickValue();
            double previousDrawnTickLabelPos = 0.0;
            double previousDrawnTickLabelLength = 0.0;
            if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
                for (int i = 0; i < count; i++) {
                    double currentTickValue = lowestTickValue + (i * size);
                    double xx = valueToJava2D(currentTickValue, dataArea, edge);
                    String tickLabel;
                    NumberFormat formatter = getNumberFormatOverride();
                    if (formatter != null) {
                        tickLabel = formatter.format(currentTickValue) + "  ";
                    } else {
                        tickLabel = valueToString(currentTickValue) + "  ";
                    }
                    // avoid to draw overlapping tick labels
                    Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics());
                    double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth();
                    boolean tickLabelsOverlapping = false;
                    if (i > 0) {
                        double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0;
                        if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) {
                            tickLabelsOverlapping = true;
                        }
                    }
                    if (tickLabelsOverlapping) {
                        setVerticalTickLabels(true);
                    } else {
                        // remember these values for next comparison
                        previousDrawnTickLabelPos = xx;
                        previousDrawnTickLabelLength = tickLabelLength;
                    }
                    TextAnchor anchor;
                    TextAnchor rotationAnchor;
                    double angle = 0.0;
                    if (isVerticalTickLabels()) {
                        anchor = TextAnchor.CENTER_RIGHT;
                        rotationAnchor = TextAnchor.CENTER_RIGHT;
                        if (edge == RectangleEdge.TOP) {
                            angle = 76.5;
                        } else {
                            angle = -76.5;
                        }
                    } else {
                        if (edge == RectangleEdge.TOP) {
                            anchor = TextAnchor.BOTTOM_CENTER;
                            rotationAnchor = TextAnchor.BOTTOM_CENTER;
                        } else {
                            anchor = TextAnchor.TOP_CENTER;
                            rotationAnchor = TextAnchor.TOP_CENTER;
                        }
                    }
                    Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                            angle);

                    ticks.add(tick);
                }
            }
            return ticks;
        }
    };

    //        }
    xAxis.setTickLabelFont(font);
    xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20));
    xAxis.setAutoRangeStickyZero(true);
    xAxis.setAutoRangeStickyZero(true);
    xAxis.setTickMarksVisible(false);
    xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1);
    xAxis.setGridBandsVisible(false);
    xAxis.setAxisLinePaint(Color.LIGHT_GRAY);
    int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS;

    XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) {
        private int counter = 0;
        private int localSerious = -1;
        private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap;

        @Override
        public Paint getSeriesPaint(int series) {
            if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) {
                counter = 0;
                isNewImge = false;
            }
            localSerious = series;
            Color c = localSeriousColorMap.get(series)[counter];
            counter++;

            return c;
        }

    };

    XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) {
        @Override
        protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) {
            try {
                if (!ticks.isEmpty()) {
                    ticks.remove(0);
                }
                if (!ticks.isEmpty()) {
                    ticks.remove(ticks.size() - 1);
                }
            } catch (Exception e) {
            }
            super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates.
        }

        //            private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")};
        //
        //            private final Font font = new Font("Verdana", Font.PLAIN, 12);
        //            private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."};
        //
        //            @Override
        //            public LegendItemCollection getLegendItems() {
        //                LegendItemCollection legendItemCollection = new LegendItemCollection();
        //                for (int i = 0; i < labelsColor.length; i++) {
        //                    LegendItem item = new LegendItem(labels[i], labelsColor[i]);
        //                    item.setLabelFont(font);
        //                    legendItemCollection.add(item);
        //
        //                }
        //
        //                return legendItemCollection;//To change body of generated methods, choose Tools | Templates.
        //            }
    };

    JFreeChart generatedChart = new JFreeChart(xyplot) {

    };
    xyplot.setOutlineVisible(false);
    LegendTitle legend = generatedChart.getLegend();
    legend.setVisible(false);
    xyplot.setBackgroundPaint(Color.WHITE);
    generatedChart.setBackgroundPaint(Color.WHITE);
    generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart);
    return generatedChart;

}

From source file:io.github.mzmine.modules.plots.chromatogram.ChromatogramPlotWindowController.java

@FXML
public void initialize() {

    final JFreeChart chart = chartNode.getChart();
    final XYPlot plot = chart.getXYPlot();

    // Do not set colors and strokes dynamically. They are instead provided
    // by the dataset and configured in configureRenderer()
    plot.setDrawingSupplier(null);//from w  ww  .  ja  v a 2  s. c o  m
    plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor));
    plot.setRangeCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    // chart properties
    chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));

    // legend properties
    LegendTitle legend = chart.getLegend();
    // legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the X axis (retention time) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setLabel("Retention time (min)");
    xAxis.setUpperMargin(0.03);
    xAxis.setLowerMargin(0.03);
    xAxis.setRangeType(RangeType.POSITIVE);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel("Intensity");
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    // set the fixed number formats, because otherwise JFreeChart sometimes
    // shows exponent, sometimes it doesn't
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    xAxis.setNumberFormatOverride(mzFormat);
    DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
    yAxis.setNumberFormatOverride(intensityFormat);

    chartTitle = chartNode.getChart().getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);
    chartTitle.setText("Chromatogram");

    chartNode.setCursor(Cursor.CROSSHAIR);

    // Remove the dataset if it is removed from the list
    datasets.addListener((Change<? extends ChromatogramPlotDataSet> c) -> {
        while (c.next()) {
            if (c.wasRemoved()) {
                for (ChromatogramPlotDataSet ds : c.getRemoved()) {
                    int index = plot.indexOf(ds);
                    plot.setDataset(index, null);
                }
            }
        }
    });

    itemLabelsVisible.addListener((prop, oldVal, newVal) -> {
        for (ChromatogramPlotDataSet dataset : datasets) {
            int datasetIndex = plot.indexOf(dataset);
            XYItemRenderer renderer = plot.getRenderer(datasetIndex);
            renderer.setBaseItemLabelsVisible(newVal);
        }
    });

    legendVisible.addListener((prop, oldVal, newVal) -> {
        legend.setVisible(newVal);
    });
}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void initialize() {

    final JFreeChart chart = chartNode.getChart();
    final XYPlot plot = chart.getXYPlot();

    // Do not set colors and strokes dynamically. They are instead provided
    // by the dataset and configured in configureRenderer()
    plot.setDrawingSupplier(null);/*from  ww  w  . j  ava2  s.  c om*/
    plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    // chart properties
    chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));

    // legend properties
    LegendTitle legend = chart.getLegend();
    // legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the X axis (m/z) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setLabel("m/z");
    xAxis.setUpperMargin(0.03);
    xAxis.setLowerMargin(0.03);
    xAxis.setRangeType(RangeType.POSITIVE);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel("Intensity");
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    // set the fixed number formats, because otherwise JFreeChart sometimes
    // shows exponent, sometimes it doesn't
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    xAxis.setNumberFormatOverride(mzFormat);
    DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
    yAxis.setNumberFormatOverride(intensityFormat);

    chartTitle = chartNode.getChart().getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    chartNode.setCursor(Cursor.CROSSHAIR);

    // Remove the dataset if it is removed from the list
    datasets.addListener((Change<? extends MsSpectrumDataSet> c) -> {
        while (c.next()) {
            if (c.wasRemoved()) {
                for (MsSpectrumDataSet ds : c.getRemoved()) {
                    int index = plot.indexOf(ds);
                    plot.setDataset(index, null);
                }
            }
        }
    });

    itemLabelsVisible.addListener((prop, oldVal, newVal) -> {
        for (MsSpectrumDataSet dataset : datasets) {
            int datasetIndex = plot.indexOf(dataset);
            XYItemRenderer renderer = plot.getRenderer(datasetIndex);
            renderer.setBaseItemLabelsVisible(newVal);
        }
    });

    legendVisible.addListener((prop, oldVal, newVal) -> {
        legend.setVisible(newVal);
    });

}