Example usage for java.awt Color cyan

List of usage examples for java.awt Color cyan

Introduction

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

Prototype

Color cyan

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

Click Source Link

Document

The color cyan.

Usage

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createWaterfallChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createWaterfallChart("Waterfall Chart Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/* w  ww  .j  av a  2s  .c om*/

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    WaterfallBarRenderer renderer = (WaterfallBarRenderer) plot.getRenderer();

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    //        GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    //        renderer.setSeriesPaint(0, gp0);
    //        renderer.setSeriesPaint(1, gp1);
    //        renderer.setSeriesPaint(2, gp2);

    //??
    renderer.setFirstBarPaint(gp0);
    renderer.setLastBarPaint(gp2);
    renderer.setPositiveBarPaint(Color.orange);
    renderer.setNegativeBarPaint(Color.cyan);

    return chart;

}

From source file:edworld.pdfreader4humans.PDFReader.java

private Color groupColor(Color inkColor) {
    return new Color(Color.CYAN.getRGB() ^ inkColor.getRGB());
}

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

public void createGraph(PlotJob job, Map<String, List<Double>> PFTData, Map<String, List<Double>> data,
        List<LogEvent> events, List<SEAction> actions) {
    CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions
    String title = job.name + "_";
    XYSeriesCollection dataSet = new XYSeriesCollection();
    double maxY = 0;
    double minY = Double.MAX_VALUE;
    for (int i = 0; i < job.headers.size(); i++) {
        title = title + job.headers.get(i) + "_";
        XYSeries dataSeries;//from   ww w  .  j  a v  a  2s.  co m
        dataSeries = plotTool.createXYSeries(job.headers.get(i), data.get("Time(s)"),
                data.get(job.headers.get(i)));
        dataSet.addSeries(dataSeries);
        maxY = maxY < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY;
        minY = minY > dataSeries.getMinY() ? dataSeries.getMinY() : minY;
    }

    //Now make a data series for PFT data and check its max and min
    XYSeries dataSeries = plotTool.createXYSeries("PFT Total Lung Volume (mL)", PFTData.get("Time"),
            PFTData.get("Volume"));
    dataSet.addSeries(dataSeries);
    maxY = maxY < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY;
    minY = minY > dataSeries.getMinY() ? dataSeries.getMinY() : minY;

    title = title + "vs_Time";

    //Override the constructed title if desired
    if (job.titleOverride != null && !job.titleOverride.isEmpty()
            && !job.titleOverride.equalsIgnoreCase("None"))
        title = job.titleOverride;

    double rangeLength = maxY - minY;
    if (Math.abs(rangeLength) < 1e-6) {
        rangeLength = .01;
    }

    class AEEntry implements Comparable<AEEntry> {
        public String name;
        public List<Double> times = new ArrayList<Double>();
        public List<Double> YVals = new ArrayList<Double>();
        public String type = "";

        public int compareTo(AEEntry entry) {
            return times.get(0) < entry.times.get(0) ? -1 : times.get(0) > entry.times.get(0) ? 1 : 0;
        }
    }

    List<AEEntry> allActionsAndEvents = new ArrayList<AEEntry>();

    if (!job.skipAllEvents) {
        //Make points for each event
        //Treat each event like two points on the same vertical line
        for (LogEvent event : events) {
            boolean skip = false;

            for (String eventToSkip : job.eventOmissions) {
                if (event.text.contains(eventToSkip))
                    skip = true;
            }
            if (skip)
                continue;
            AEEntry entry = new AEEntry();

            entry.times.add(event.time.getValue());
            if (job.logAxis)
                entry.YVals.add(maxY);
            else if (job.forceZeroYAxisBound && maxY < 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(maxY + 0.15 * rangeLength);

            entry.times.add(event.time.getValue());
            if (job.logAxis)
                entry.YVals.add(minY);
            else if (job.forceZeroYAxisBound && minY > 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(minY - 0.15 * rangeLength);

            entry.name = event.text + "\r\nt=" + event.time.getValue();
            entry.type = "EVENT:";

            allActionsAndEvents.add(entry);
        }
    }

    if (!job.skipAllActions) {
        //Make similar entries for actions
        for (SEAction action : actions) {
            boolean skip = false;

            for (String actionToSkip : job.actionOmissions) {
                if (action.toString().contains(actionToSkip))
                    skip = true;
            }
            if (skip)
                continue;

            if (action.toString().contains("Advance Time"))
                continue;

            AEEntry entry = new AEEntry();

            entry.times.add(action.getScenarioTime().getValue());
            if (job.logAxis)
                entry.YVals.add(maxY);
            else if (job.forceZeroYAxisBound && maxY < 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(maxY + 0.15 * rangeLength);

            entry.times.add(action.getScenarioTime().getValue());
            if (job.logAxis)
                entry.YVals.add(minY);
            else if (job.forceZeroYAxisBound && minY > 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(minY - 0.15 * rangeLength);

            entry.name = action.toString() + "\r\nt=" + action.getScenarioTime().getValue();
            entry.type = "ACTION:";

            allActionsAndEvents.add(entry);
        }
    }

    //Sort the list
    Collections.sort(allActionsAndEvents);

    //Add a series for each entry
    for (AEEntry entry : allActionsAndEvents) {
        dataSet.addSeries(plotTool.createXYSeries(entry.type + entry.name, entry.times, entry.YVals));
    }

    //set labels
    String XAxisLabel = "Time(s)";
    String YAxisLabel = job.headers.get(0);

    JFreeChart chart = ChartFactory.createXYLineChart(
            job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    Log.info("Creating Graph " + title);
    XYPlot plot = (XYPlot) chart.getPlot();

    if (!job.logAxis) {
        // Determine Y range
        double resMax0 = maxY;
        double resMin0 = minY;
        if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
            plot.getDomainAxis().setLabel("Range is NaN");
        if (DoubleUtils.isZero(resMin0))
            resMin0 = -0.000001;
        if (DoubleUtils.isZero(resMax0))
            resMax0 = 0.000001;
        if (job.forceZeroYAxisBound && resMin0 >= 0)
            resMin0 = -.000001;
        if (job.forceZeroYAxisBound && resMax0 <= 0)
            resMax0 = .000001;
        rangeLength = resMax0 - resMin0;
        ValueAxis yAxis = plot.getRangeAxis();
        if (rangeLength != 0)
            yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly           

        //Add another Y axis to the right side for easier reading
        ValueAxis rightYAxis = new NumberAxis();
        rightYAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);
        rightYAxis.setLabel("");

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null) {
                yAxis.setLowerBound(job.Y1LowerBound);
                rightYAxis.setLowerBound(job.Y1LowerBound);
            }
            if (job.Y1UpperBound != null) {
                yAxis.setUpperBound(job.Y1UpperBound);
                rightYAxis.setUpperBound(job.Y1UpperBound);
            }
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }
        plot.setRangeAxis(0, yAxis);
        plot.setRangeAxis(1, rightYAxis);

    } else {
        double resMin = minY;
        double resMax = maxY;
        if (resMin <= 0.0)
            resMin = .00001;
        LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")");
        LogarithmicAxis rightYAxis = new LogarithmicAxis("");
        yAxis.setLowerBound(resMin);
        rightYAxis.setLowerBound(resMin);
        yAxis.setUpperBound(resMax);
        rightYAxis.setUpperBound(resMax);

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null) {
                yAxis.setLowerBound(job.Y1LowerBound);
                rightYAxis.setLowerBound(job.Y1LowerBound);
            }
            if (job.Y1UpperBound != null) {
                yAxis.setUpperBound(job.Y1UpperBound);
                rightYAxis.setUpperBound(job.Y1UpperBound);
            }
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }
        plot.setRangeAxis(0, yAxis);
        plot.setRangeAxis(1, rightYAxis);
    }

    //Override X bounds if desired
    try {
        if (job.X1LowerBound != null)
            plot.getDomainAxis(0).setLowerBound(job.X1LowerBound);
        if (job.X1UpperBound != null)
            plot.getDomainAxis(0).setUpperBound(job.X1UpperBound);
    } catch (Exception e) {
        Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist.");
    }

    //Override labels if desired
    if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN"))
        plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label);
    if (job.Y1Label != null)
        plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label);

    formatRPFTPlot(job, chart);
    plot.setDomainGridlinesVisible(job.showGridLines);
    plot.setRangeGridlinesVisible(job.showGridLines);

    //Changing line widths and colors
    XYItemRenderer r = plot.getRenderer();
    BasicStroke wideLine = new BasicStroke(2.0f);
    Color[] AEcolors = { Color.red, Color.green, Color.black, Color.magenta, Color.orange };
    Color[] dataColors = { Color.blue, Color.cyan, Color.gray, Color.black, Color.red };
    for (int i = 0, cIndex = 0; i < dataSet.getSeriesCount(); i++, cIndex++) {
        r.setSeriesStroke(i, wideLine);
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setBaseShapesVisible(false);
        if (cIndex > 4)
            cIndex = 0;
        if (i < job.headers.size()) //Our actual data
        {
            renderer.setSeriesFillPaint(i, dataColors[cIndex]);
            renderer.setSeriesPaint(i, dataColors[cIndex]);
        } else //actions and events in procession of other colors
        {
            renderer.setSeriesFillPaint(i, AEcolors[cIndex]);
            renderer.setSeriesPaint(i, AEcolors[cIndex]);
        }
    }

    //Split the auto-generated legend into two legends, one for data and one for actions and events
    LegendItemCollection originalLegendCollection = plot.getLegendItems();
    final LegendItemCollection dataLegendCollection = new LegendItemCollection();
    int i;
    for (i = 0; i < job.headers.size() && i < originalLegendCollection.getItemCount(); i++) {
        if (originalLegendCollection.get(i).getLabel().startsWith("ACTION")
                || originalLegendCollection.get(i).getLabel().startsWith("EVENT"))
            break;
        dataLegendCollection.add(originalLegendCollection.get(i));
    }
    final LegendItemCollection remainingLegendCollection = new LegendItemCollection();
    for (; i < originalLegendCollection.getItemCount(); i++) {
        remainingLegendCollection.add(originalLegendCollection.get(i));
    }
    chart.removeLegend();
    LegendItemSource source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(dataLegendCollection);
        }

        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };
    LegendTitle dataLegend = new LegendTitle(source);
    dataLegend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    dataLegend.setBorder(2, 2, 2, 2);
    dataLegend.setBackgroundPaint(Color.white);
    dataLegend.setPosition(RectangleEdge.TOP);
    dataLegend.setItemFont(new Font("SansSerif", Font.PLAIN, 22));
    chart.addLegend(dataLegend);

    source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(remainingLegendCollection);
        }

        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };
    LegendTitle actionEventsLegend = new LegendTitle(source);
    actionEventsLegend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    actionEventsLegend.setBorder(2, 2, 2, 2);
    actionEventsLegend.setBackgroundPaint(Color.white);
    actionEventsLegend.setPosition(RectangleEdge.BOTTOM);
    actionEventsLegend.setItemFont(new Font("SansSerif", Font.PLAIN, 22));
    if (!job.hideAELegend && !job.removeAllLegends)
        chart.addLegend(actionEventsLegend);

    if (job.removeAllLegends)
        chart.removeLegend();

    int verticalPixels = 800 + 170 * (allActionsAndEvents.size() / 5);

    try {
        FileUtils.createDirectory(job.outputDir);
        String filename = job.outputFilename == null
                ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg"
                : job.outputDir + "/" + job.outputFilename;
        if (!filename.endsWith(".jpg"))
            filename = filename + ".jpg";
        File JPGFile = new File(filename);
        if (job.imageHeight != null && job.imageWidth != null)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight);
        else if (!job.hideAELegend && !job.removeAllLegends)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, verticalPixels);
        else
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }
}

From source file:de.tor.tribes.ui.panels.MinimapPanel.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    try {/*from w  w w .  j av  a 2s .c o  m*/
        Graphics2D g2d = (Graphics2D) g;
        g2d.clearRect(0, 0, getWidth(), getHeight());
        g2d.drawImage(mBuffer, 0, 0, null);

        if (iCurrentView == ID_MINIMAP) {
            g2d.setColor(Color.YELLOW);

            int mapWidth = rVisiblePart.width;
            int mapHeight = rVisiblePart.height;

            int w = (int) Math.rint(((double) getWidth() / mapWidth) * (double) iWidth);
            int h = (int) Math.rint(((double) getHeight() / mapHeight) * (double) iHeight);

            double posX = ((double) getWidth() / mapWidth * (double) (iX - rVisiblePart.x)) - w / 2;
            double posY = ((double) getHeight() / mapHeight * (double) (iY - rVisiblePart.y)) - h / 2;

            g2d.drawRect((int) Math.rint(posX), (int) Math.rint(posY), w, h);

            if (iCurrentCursor == ImageManager.CURSOR_SHOT) {
                if (rDrag != null) {
                    g2d.setColor(Color.ORANGE);
                    g2d.drawRect((int) rDrag.getMinX(), (int) rDrag.getMinY(),
                            (int) (rDrag.getWidth() - rDrag.getX()), (int) (rDrag.getHeight() - rDrag.getY()));
                }
            } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) {
                if (rDrag != null) {
                    g2d.setColor(Color.CYAN);
                    g2d.drawRect((int) rDrag.getX(), (int) rDrag.getY(),
                            (int) (rDrag.getWidth() - rDrag.getX()),
                            (int) ((rDrag.getWidth() - rDrag.getX()) * ((double) getHeight()) / getWidth()));
                }
            }
        }

        if (showControls) {
            //g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f));
            Rectangle r = minimapButtons.get(ID_MINIMAP);
            g2d.setColor(Color.WHITE);
            Point menuPos = r.getLocation();
            menuPos.translate(-2, -2);
            //draw border
            g2d.fillRect(menuPos.x, menuPos.y, 88, 30);
            g2d.setColor(Color.BLACK);
            //check if mouse is inside minimap button
            if (getMousePosition() != null && r.contains(getMousePosition())) {
                g2d.setColor(Color.YELLOW);
                g2d.fillRect(r.x, r.y, r.width, r.height);
                g2d.setColor(Color.BLACK);
            }
            g2d.drawImage(minimapIcons.get(ID_MINIMAP), r.x, r.y, null);
            g2d.drawRect(r.x, r.y, r.width, r.height);

            r = minimapButtons.get(ID_ALLY_CHART);
            //check if mouse is inside ally chart button
            if (getMousePosition() != null && r.contains(getMousePosition())) {
                g2d.setColor(Color.YELLOW);
                g2d.fillRect(r.x, r.y, r.width, r.height);
                g2d.setColor(Color.BLACK);
            }
            g2d.drawImage(minimapIcons.get(ID_ALLY_CHART), r.x, r.y, null);
            g2d.drawRect(r.x, r.y, r.width, r.height);

            r = minimapButtons.get(ID_TRIBE_CHART);
            //check if mouse is inside tribe chart button
            if (getMousePosition() != null && r.contains(getMousePosition())) {
                g2d.setColor(Color.YELLOW);
                g2d.fillRect(r.x, r.y, r.width, r.height);
                g2d.setColor(Color.BLACK);

            }
            g2d.drawImage(minimapIcons.get(ID_TRIBE_CHART), r.x, r.y, null);
            g2d.drawRect(r.x, r.y, r.width, r.height);
        }
        g2d.dispose();
    } catch (Exception e) {
        logger.error("Failed painting Minimap", e);
    }
}

From source file:projekt.CustomRenderer.java

public void raport_globalny() throws IOException, ClassNotFoundException, SQLException {
    String zapytanie = "select count(*) as Aktualne from zadania where Status_zadania='Aktualne'";
    String zapytanie1 = "select count(*) as FORTEST from zadania where Status_zadania='FORTEST'";
    String zapytanie2 = "select count(*) as Zakonczone from zadania where Status_zadania='Zakonczone'";

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8",
            "root", "");
    PreparedStatement statment;// w  w w  . jav a 2  s . c  om
    ResultSet result;
    double odp = 0, odp1 = 0, odp2 = 0;
    statment = con.prepareStatement(zapytanie);
    result = statment.executeQuery();
    if (result.next()) {
        odp = result.getDouble("Aktualne");
    }
    statment = con.prepareStatement(zapytanie1);
    result = statment.executeQuery();
    if (result.next()) {
        odp1 = result.getDouble("FORTEST");
    }
    statment = con.prepareStatement(zapytanie2);
    result = statment.executeQuery();
    if (result.next()) {
        odp2 = result.getDouble("Zakonczone");
    }
    loginController login = new loginController();
    statment = con.prepareStatement(
            "SELECT CONCAT(imie, ' ', nazwisko) as osoba from uzytkownicy WHERE idUzytkownika = '"
                    + login.uzytkownikID + "'");
    result = statment.executeQuery();
    String bbc = "";
    if (result.next()) {
        bbc = result.getString(1);
    }

    DefaultCategoryDataset set2 = new DefaultCategoryDataset();
    set2.setValue(odp, "", "Aktualne");
    set2.setValue(odp1, "", "FORTEST");
    set2.setValue(odp2, "", "Zakonczone");
    JFreeChart chart = ChartFactory.createBarChart("Wszystkie zadania w bazie", "Zadania", "Ilosc", set2,
            PlotOrientation.VERTICAL, false, true, false);

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

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");

    renderer.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 45.0);
    renderer.setPositiveItemLabelPosition(p);
    plot.setRenderer(renderer);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsJPEG(out, chart, 450, 600);
    DateFormat dataformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    DateFormat dataformat1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
    Date data = new Date();
    String fileName = "Raport globalny " + dataformat1.format(data) + ".pdf";
    try {
        PDRectangle PAGE_SIZE = PDRectangle.A4;
        PDDocument doc = new PDDocument();
        PDFont font = PDType0Font.load(doc,
                getClass().getResourceAsStream("/fonts/RobotoCondensed-Regular.ttf"));
        PDFont font1 = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Bold.ttf"));
        PDPage page = new PDPage(PAGE_SIZE);
        PDPage page1 = new PDPage(PAGE_SIZE);
        doc.addPage(page);
        PDPageContentStream content = new PDPageContentStream(doc, page);
        //naglowek strona 1
        Naglowek(content, dataformat, data);
        //stopka strona1
        Stopka(content, doc);
        content.beginText();
        content.setFont(font1, 48);
        content.moveTextPositionByAmount(135, 550);
        content.showText("Raport globalny");
        content.endText();

        content.beginText();
        content.setFont(font, 22);
        content.moveTextPositionByAmount(30, 250);
        content.showText("Wersja systemu : 1.0");
        content.newLine();
        content.moveTextPositionByAmount(0, 35);
        content.showText("Autor raportu : " + result.getString("osoba"));
        content.endText();
        content.close();

        PDPageContentStream content1 = new PDPageContentStream(doc, page1);

        PDPage page2 = new PDPage(PAGE_SIZE);
        doc.addPage(page2);
        PDPageContentStream content2 = new PDPageContentStream(doc, page2);
        Naglowek(content2, dataformat, data);
        //stopka strona2
        Stopka(content2, doc);
        content2.beginText();
        content2.setFont(font, 14);
        content2.moveTextPositionByAmount(30, 775);
        content2.showText("Wszystkie projekty z bazy danych:");
        statment = con.prepareStatement("Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty");
        result = statment.executeQuery();
        content2.newLine();
        int liczba = 615;
        content2.moveTextPositionByAmount(0, -15);
        while (result.next()) {
            content2.newLine();
            content2.moveTextPositionByAmount(0, -22);
            liczba += 22;
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));

            content2.showText("Nazwa : " + result.getString("Nazwa") + " Opis: " + result.getString("Opis"));
            content2.newLine();
            content2.moveTextPositionByAmount(0, -17);
            liczba += 22;
            content2.showText("Data rozpoczecia: " + result.getString("Poczatek") + " Data zakonczenia: "
                    + result.getString("Koniec"));

        }
        content2.endText();
        //          content2.setLineWidth(2);
        //        content2.moveTo(10, liczba + 5);
        //        content2.lineTo(10, liczba +5);
        //        content2.closeAndStroke();
        DateFormat dataformat2 = new SimpleDateFormat("yyyy-MM-dd");
        statment = con.prepareStatement("Select count(*) as 'Aktualne' from projekty where Koniec > '"
                + dataformat2.format(data) + "'");
        result = statment.executeQuery();
        int aktualne = 0, zakonczone = 0;
        if (result.next()) {
            aktualne = result.getInt("Aktualne");
        }
        System.out.println("aktualne:" + aktualne);
        statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '"
                + dataformat2.format(data) + "'");
        result = statment.executeQuery();
        if (result.next()) {
            zakonczone = result.getInt("Zakonczone");
        }
        System.out.println("zakonczone:" + zakonczone);
        DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("Aktualne", aktualne);
        pieDataset.setValue("Zakonczone", zakonczone);
        JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projektw", // Title
                pieDataset, // Dataset
                true, // Show legend
                true, // Use tooltips
                false // Configure chart to generate URLs?
        );

        PiePlot plot1 = (PiePlot) chart1.getPlot();
        plot1.setSectionPaint("Aktualne", Color.green);
        plot1.setSectionPaint("Zakonczone", Color.red);
        plot1.setExplodePercent("Aktualne", 0.10);
        plot1.setSimpleLabels(true);

        PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
                new DecimalFormat("0"), new DecimalFormat("0%"));
        plot1.setLabelGenerator(gen);

        ByteArrayOutputStream out1 = new ByteArrayOutputStream();
        ChartUtilities.writeChartAsJPEG(out1, chart1, 450, 600);
        PDImageXObject img1 = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out1.toByteArray()));

        content2.close();
        PDPage page3 = new PDPage(PAGE_SIZE);
        doc.addPage(page3);
        PDPageContentStream content3 = new PDPageContentStream(doc, page3);
        Naglowek(content3, dataformat, data);
        //stopka strona2
        Stopka(content3, doc);
        content3.drawImage(img1, 50, 50);
        content3.close();
        PDPage page4 = new PDPage(PAGE_SIZE);
        doc.addPage(page4);
        PDPageContentStream content4 = new PDPageContentStream(doc, page4);
        Naglowek(content4, dataformat, data);
        //stopka strona2
        Stopka(content4, doc);
        content4.beginText();
        content4.setFont(font, 14);
        content4.moveTextPositionByAmount(30, 780);
        content4.showText("Wszystkie zadania w bazie:");
        statment = con.prepareStatement(
                "SELECT `Nazwa`,`Opis`,`Status_zadania`,`projekt`, CONCAT(x.imie, \" \", x.nazwisko) as \"UZY\" FROM `zadania` , (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) X WHERE zadania.idUzytkownika=x.idUzytkownika limit 12");
        result = statment.executeQuery();
        content4.newLine();
        int nw = 850;
        content4.moveTextPositionByAmount(0, -15);
        nw -= 15;
        while (result.next()) {
            content4.newLine();
            nw -= 22;
            content4.moveTextPositionByAmount(0, -22);
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));
            content4.showText("Nazwa : " + result.getString("Nazwa"));
            content4.newLine();
            nw -= 17;
            content4.moveTextPositionByAmount(0, -17);
            content4.showText(" Opis: " + result.getString("Opis") + " Status zadania: "
                    + result.getString("Status_zadania"));
            content4.newLine();
            nw -= 17;
            content4.moveTextPositionByAmount(0, -17);
            content4.showText(" Projekt: " + result.getString("projekt") + " Przydzielona osoba do zadania: "
                    + result.getString("UZY"));

        }

        content4.endText();
        content4.close();
        statment = con.prepareStatement("SELECT count(*) as 'liczba' FROM `zadania`");
        result = statment.executeQuery();
        if (result.next()) {
        }
        statment = con.prepareStatement(
                "SELECT `Nazwa`,`Opis`,`Status_zadania`,`projekt`, CONCAT(x.imie, \" \", x.nazwisko) as \"UZY\" FROM `zadania` , (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) X WHERE zadania.idUzytkownika=x.idUzytkownika limit 12,"
                        + result.getInt(1) + "");
        result = statment.executeQuery();
        PDPage page5 = new PDPage(PAGE_SIZE);
        doc.addPage(page5);
        PDPageContentStream content5 = new PDPageContentStream(doc, page5);
        Naglowek(content5, dataformat, data);
        //stopka strona2
        Stopka(content5, doc);
        content5.beginText();
        content5.setFont(font, 14);
        content5.moveTextPositionByAmount(30, 700);
        while (result.next()) {
            content5.newLine();
            nw -= 22;
            content5.moveTextPositionByAmount(0, -22);
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));
            content5.showText("Nazwa : " + result.getString("Nazwa"));
            content5.newLine();
            nw -= 17;
            content5.moveTextPositionByAmount(0, -17);
            content5.showText(" Opis: " + result.getString("Opis") + " Status zadania: "
                    + result.getString("Status_zadania"));
            content5.newLine();
            nw -= 17;
            content5.moveTextPositionByAmount(0, -17);
            content5.showText(" Projekt: " + result.getString("projekt") + " Przydzielona osoba do zadania: "
                    + result.getString("UZY"));
        }
        content5.endText();
        content5.close();
        doc.addPage(page1);
        //naglowek strona 2
        Naglowek(content1, dataformat, data);
        //stopka strona2
        Stopka(content1, doc);
        PDImageXObject img = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out.toByteArray()));
        content1.drawImage(img, 50, 50);
        content1.close();
        doc.save(fileName);
        doc.close();

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java

protected void drawOutlineBox(final Graphics2D g2, final RenderBox box) {
    final int nodeType = box.getNodeType();
    if (nodeType == LayoutNodeTypes.TYPE_BOX_PARAGRAPH) {
        g2.setPaint(Color.magenta);
    } else if (nodeType == LayoutNodeTypes.TYPE_BOX_LINEBOX) {
        g2.setPaint(Color.orange);
    } else if ((nodeType & LayoutNodeTypes.MASK_BOX_TABLE) == LayoutNodeTypes.MASK_BOX_TABLE) {
        g2.setPaint(Color.cyan);
    } else {//from   w  w  w.j a  v a  2s.c  o m
        g2.setPaint(Color.lightGray);
    }
    final double x = StrictGeomUtility.toExternalValue(box.getX());
    final double y = StrictGeomUtility.toExternalValue(box.getY());
    final double w = StrictGeomUtility.toExternalValue(box.getWidth());
    final double h = StrictGeomUtility.toExternalValue(box.getHeight());
    boxArea.setFrame(x, y, w, h);
    g2.draw(boxArea);
}

From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java

public static Color getcolor(int i) {
    switch (i) {//from w  w  w .j  a  va2s. c  om
    case 1:
        return Color.red;
    case 2:
        return Color.blue;
    case 3:
        return Color.cyan;
    case 4:
        return Color.gray;
    case 5:
        return Color.green;
    case 6:
        return Color.magenta;
    case 7:
        return Color.orange;
    case 8:
        return Color.yellow;
    case 9:
        return Color.white;
    case 0:
        return Color.pink;
    default:
        return Color.black;
    }
}

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

public void createGraph(PlotJob job, List<List<Double>> timeData, List<List<Double>> data,
        List<LogEvent> events, List<SEAction> actions) {
    CSVPlotTool plotTool = new CSVPlotTool(); //to leverage existing functions
    String title = job.name + "_";
    XYSeriesCollection dataSet = new XYSeriesCollection();
    double maxY = 0;
    double minY = Double.MAX_VALUE;
    for (int i = 0; i < timeData.size(); i++) {
        if (timeData.get(i) == null || data.get(i) == null) {
            job.bgColor = Color.white; //This hits when we have Expected data but NOT computed data
            continue;
        }/*from  ww w.  j av a 2s  .  c om*/

        title = title + job.headers.get(i) + "_";
        XYSeries dataSeries;
        if (job.isComparePlot) {
            if (timeData.size() > 1)
                dataSeries = plotTool.createXYSeries(i == 0 ? "Expected" : "Computed", timeData.get(i),
                        data.get(i));
            else //If we're comparing but only have one data list, expected is missing, so rename to computed
            {
                dataSeries = plotTool.createXYSeries("Computed", timeData.get(i), data.get(i));
            }
        } else
            dataSeries = plotTool.createXYSeries(job.headers.get(i), timeData.get(i), data.get(i));
        dataSet.addSeries(dataSeries);
        maxY = maxY < dataSeries.getMaxY() ? dataSeries.getMaxY() : maxY;
        minY = minY > dataSeries.getMinY() ? dataSeries.getMinY() : minY;
    }
    title = title + "vs_Time_Action_Event_Plot";

    //Override the constructed title if desired (usually for compare plots)
    if (job.titleOverride != null && !job.titleOverride.isEmpty()
            && !job.titleOverride.equalsIgnoreCase("None"))
        title = job.titleOverride;

    double rangeLength = maxY - minY;
    if (Math.abs(rangeLength) < 1e-6) {
        rangeLength = .01;
    }

    class AEEntry implements Comparable<AEEntry> {
        public String name;
        public List<Double> times = new ArrayList<Double>();
        public List<Double> YVals = new ArrayList<Double>();
        public String type = "";

        public int compareTo(AEEntry entry) {
            return times.get(0) < entry.times.get(0) ? -1 : times.get(0) > entry.times.get(0) ? 1 : 0;
        }
    }

    List<AEEntry> allActionsAndEvents = new ArrayList<AEEntry>();

    if (!job.skipAllEvents) {
        //Make points for each event
        //Treat each event like two points on the same vertical line
        for (LogEvent event : events) {
            boolean skip = false;

            for (String eventToSkip : job.eventOmissions) {
                if (event.text.contains(eventToSkip))
                    skip = true;
            }
            if (skip)
                continue;
            AEEntry entry = new AEEntry();

            entry.times.add(event.time.getValue());
            if (job.logAxis)
                entry.YVals.add(maxY);
            else if (job.forceZeroYAxisBound && maxY < 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(maxY + 0.15 * rangeLength);

            entry.times.add(event.time.getValue());
            if (job.logAxis)
                entry.YVals.add(minY);
            else if (job.forceZeroYAxisBound && minY > 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(minY - 0.15 * rangeLength);

            entry.name = event.text + "\r\nt=" + event.time.getValue();
            entry.type = "EVENT:";

            allActionsAndEvents.add(entry);
        }
    }

    if (!job.skipAllActions) {
        //Make similar entries for actions
        for (SEAction action : actions) {
            boolean skip = false;

            for (String actionToSkip : job.actionOmissions) {
                if (action.toString().contains(actionToSkip))
                    skip = true;
            }
            if (skip)
                continue;

            if (action.toString().contains("Advance Time"))
                continue;

            AEEntry entry = new AEEntry();

            entry.times.add(action.getScenarioTime().getValue());
            if (job.logAxis)
                entry.YVals.add(maxY);
            else if (job.forceZeroYAxisBound && maxY < 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(maxY + 0.15 * rangeLength);

            entry.times.add(action.getScenarioTime().getValue());
            if (job.logAxis)
                entry.YVals.add(minY);
            else if (job.forceZeroYAxisBound && minY > 0)
                entry.YVals.add(-.01);
            else
                entry.YVals.add(minY - 0.15 * rangeLength);

            entry.name = action.toString() + "\r\nt=" + action.getScenarioTime().getValue();
            entry.type = "ACTION:";

            allActionsAndEvents.add(entry);
        }
    }

    //Sort the list
    Collections.sort(allActionsAndEvents);

    //Add a series for each entry
    for (AEEntry entry : allActionsAndEvents) {
        dataSet.addSeries(plotTool.createXYSeries(entry.type + entry.name, entry.times, entry.YVals));
    }

    //If we have experimental data, try to load it and create a dataset for it
    XYSeriesCollection expDataSet = new XYSeriesCollection();
    if (job.experimentalData != null && !job.experimentalData.isEmpty()) {
        Map<String, List<Double>> expData = new HashMap<String, List<Double>>();
        List<String> expHeaders = new ArrayList<String>();

        try {
            CSVContents csv = new CSVContents(job.experimentalData);
            csv.abbreviateContents = 0;
            csv.readAll(expData);
            expHeaders = csv.getHeaders();
        } catch (Exception e) {
            Log.error("Unable to read experimental data");
        }

        if (!expData.isEmpty() && !expHeaders.isEmpty()) {
            List<Double> expTimeData = new ArrayList<Double>();
            expTimeData = expData.get("Time(s)");

            for (String h : expHeaders) //Will assume all headers from exp file will be on same Y axis vs time
            {
                if (h.equalsIgnoreCase("Time(s)"))
                    continue;

                expDataSet.addSeries(plotTool.createXYSeries("Experimental " + h, expTimeData, expData.get(h)));
            }
        }
    }

    //set labels
    String XAxisLabel = "Time(s)";
    String YAxisLabel = job.headers.get(0);

    JFreeChart chart = ChartFactory.createXYLineChart(
            job.titleOverride != null && job.titleOverride.equalsIgnoreCase("None") ? "" : title, // chart title
            XAxisLabel, // x axis label
            YAxisLabel, // y axis label
            dataSet, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    Log.info("Creating Graph " + title);
    XYPlot plot = (XYPlot) chart.getPlot();

    if (!job.logAxis) {
        // Determine Y range
        double resMax0 = maxY;
        double resMin0 = minY;
        if (Double.isNaN(resMax0) || Double.isNaN(resMin0))
            plot.getDomainAxis().setLabel("Range is NaN");
        if (DoubleUtils.isZero(resMin0))
            resMin0 = -0.000001;
        if (DoubleUtils.isZero(resMax0))
            resMax0 = 0.000001;
        if (job.forceZeroYAxisBound && resMin0 >= 0)
            resMin0 = -.000001;
        if (job.forceZeroYAxisBound && resMax0 <= 0)
            resMax0 = .000001;
        rangeLength = resMax0 - resMin0;
        ValueAxis yAxis = plot.getRangeAxis();
        if (rangeLength != 0)
            yAxis.setRange(resMin0 - 0.15 * rangeLength, resMax0 + 0.15 * rangeLength);//15% buffer so we can see top and bottom clearly           

        //Add another Y axis to the right side for easier reading
        ValueAxis rightYAxis = new NumberAxis();
        rightYAxis.setRange(yAxis.getRange());
        rightYAxis.setLabel("");

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null) {
                yAxis.setLowerBound(job.Y1LowerBound);
                rightYAxis.setLowerBound(job.Y1LowerBound);
            }
            if (job.Y1UpperBound != null) {
                yAxis.setUpperBound(job.Y1UpperBound);
                rightYAxis.setUpperBound(job.Y1UpperBound);
            }
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }
        plot.setRangeAxis(0, yAxis);
        plot.setRangeAxis(1, rightYAxis);

    } else {
        double resMin = minY;
        double resMax = maxY;
        if (resMin <= 0.0)
            resMin = .00001;
        LogarithmicAxis yAxis = new LogarithmicAxis("Log(" + YAxisLabel + ")");
        LogarithmicAxis rightYAxis = new LogarithmicAxis("");
        yAxis.setLowerBound(resMin);
        rightYAxis.setLowerBound(resMin);
        yAxis.setUpperBound(resMax);
        rightYAxis.setUpperBound(resMax);

        //Override the bounds if desired
        try {
            if (job.Y1LowerBound != null) {
                yAxis.setLowerBound(job.Y1LowerBound);
                rightYAxis.setLowerBound(job.Y1LowerBound);
            }
            if (job.Y1UpperBound != null) {
                yAxis.setUpperBound(job.Y1UpperBound);
                rightYAxis.setUpperBound(job.Y1UpperBound);
            }
        } catch (Exception e) {
            Log.error(
                    "Couldn't set Y bounds. You probably tried to set a bound on an axis that doesn't exist.");
        }
        plot.setRangeAxis(0, yAxis);
        plot.setRangeAxis(1, rightYAxis);
    }

    //Override X bounds if desired
    try {
        if (job.X1LowerBound != null)
            plot.getDomainAxis(0).setLowerBound(job.X1LowerBound);
        if (job.X1UpperBound != null)
            plot.getDomainAxis(0).setUpperBound(job.X1UpperBound);
    } catch (Exception e) {
        Log.error("Couldn't set X bounds. You probably tried to set a bound on an axis that doesn't exist.");
    }

    //Override labels if desired
    if (job.X1Label != null && !plot.getDomainAxis(0).getLabel().contains("NaN"))
        plot.getDomainAxis(0).setLabel(job.X1Label.equalsIgnoreCase("None") ? "" : job.X1Label);
    if (job.Y1Label != null)
        plot.getRangeAxis(0).setLabel(job.Y1Label.equalsIgnoreCase("None") ? "" : job.Y1Label);

    //If we have experimental data, set up the renderer for it and add to plot
    if (expDataSet.getSeriesCount() != 0) {
        XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true); // Shapes only
        renderer1.setSeriesShape(0, ShapeUtilities.createDiamond(8));
        plot.setDataset(1, expDataSet);
        plot.setRenderer(1, renderer1);
        plot.mapDatasetToDomainAxis(1, 0);
        plot.mapDatasetToRangeAxis(1, 0);
    }

    formatAEPlot(job, chart);
    plot.setDomainGridlinesVisible(job.showGridLines);
    plot.setRangeGridlinesVisible(job.showGridLines);

    //Changing line widths and colors
    XYItemRenderer r = plot.getRenderer();
    BasicStroke wideLine = new BasicStroke(2.0f);
    Color[] AEcolors = { Color.red, Color.green, Color.black, Color.magenta, Color.orange };
    Color[] dataColors = { Color.blue, Color.cyan, Color.gray, Color.black, Color.red };
    for (int i = 0, cIndex = 0; i < dataSet.getSeriesCount(); i++, cIndex++) {
        r.setSeriesStroke(i, wideLine);
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setBaseShapesVisible(false);
        if (cIndex > 4)
            cIndex = 0;
        if (i < job.headers.size()) //Our actual data
        {
            renderer.setSeriesFillPaint(i, dataColors[cIndex]);
            renderer.setSeriesPaint(i, dataColors[cIndex]);
        } else //actions and events in procession of other colors
        {
            renderer.setSeriesFillPaint(i, AEcolors[cIndex]);
            renderer.setSeriesPaint(i, AEcolors[cIndex]);
        }
    }
    //Special color and format changes for compare plots
    if (job.isComparePlot) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

        for (int i = 0; i < dataSet.getSeriesCount(); i++) {
            if (dataSet.getSeries(i).getKey().toString().equalsIgnoreCase("Expected")) {
                renderer.setSeriesStroke(//makes a dashed line
                        i, //argument below float[]{I,K} -> alternates between solid and opaque (solid for I, opaque for K)
                        new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                                new float[] { 15.0f, 30.0f }, 0.0f));
                renderer.setDrawSeriesLineAsPath(true);
                renderer.setUseFillPaint(true);
                renderer.setBaseShapesVisible(false);
                renderer.setSeriesFillPaint(i, Color.black);
                renderer.setSeriesPaint(i, Color.black);
            }
            if (dataSet.getSeries(i).getKey().toString().equalsIgnoreCase("Computed")) {
                renderer.setSeriesFillPaint(i, Color.red);
                renderer.setSeriesPaint(i, Color.red);
            }
            if (dataSet.getSeries(i).getKey().toString().startsWith("ACTION")) {
                renderer.setSeriesFillPaint(i, Color.green);
                renderer.setSeriesPaint(i, Color.green);
            }
            if (dataSet.getSeries(i).getKey().toString().startsWith("EVENT")) {
                renderer.setSeriesFillPaint(i, Color.blue);
                renderer.setSeriesPaint(i, Color.blue);
            }
        }
    }

    //Split the auto-generated legend into two legends, one for data and one for actions and events
    LegendItemCollection originalLegendCollection = plot.getLegendItems();
    final LegendItemCollection dataLegendCollection = new LegendItemCollection();
    int i;
    for (i = 0; i < job.headers.size() && i < originalLegendCollection.getItemCount(); i++) {
        if (originalLegendCollection.get(i).getLabel().startsWith("ACTION")
                || originalLegendCollection.get(i).getLabel().startsWith("EVENT"))
            break;
        dataLegendCollection.add(originalLegendCollection.get(i));
    }
    final LegendItemCollection remainingLegendCollection = new LegendItemCollection();
    for (; i < originalLegendCollection.getItemCount(); i++) {
        remainingLegendCollection.add(originalLegendCollection.get(i));
    }
    chart.removeLegend();
    LegendItemSource source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(dataLegendCollection);
        }

        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };
    LegendTitle dataLegend = new LegendTitle(source);
    dataLegend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    dataLegend.setBorder(2, 2, 2, 2);
    dataLegend.setBackgroundPaint(Color.white);
    dataLegend.setPosition(RectangleEdge.TOP);
    dataLegend.setItemFont(new Font("SansSerif", Font.PLAIN, 22));
    chart.addLegend(dataLegend);

    source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(remainingLegendCollection);
        }

        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };
    LegendTitle actionEventsLegend = new LegendTitle(source);
    actionEventsLegend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    actionEventsLegend.setBorder(2, 2, 2, 2);
    actionEventsLegend.setBackgroundPaint(Color.white);
    actionEventsLegend.setPosition(RectangleEdge.BOTTOM);
    actionEventsLegend.setItemFont(new Font("SansSerif", Font.PLAIN, 22));
    if (!job.hideAELegend && !job.removeAllLegends)
        chart.addLegend(actionEventsLegend);

    if (job.removeAllLegends)
        chart.removeLegend();

    int verticalPixels = 800 + 170 * (allActionsAndEvents.size() / 5);

    //This is a little hacky, but if we want only the legend, just extend Plot() and remove the draw functionality so it makes a blank plot
    class legendPlot extends Plot {
        public void draw(Graphics2D arg0, Rectangle2D arg1, Point2D arg2, PlotState arg3,
                PlotRenderingInfo arg4) {

        }

        public String getPlotType() {
            return null;
        }
    }
    //Then add the legend to that and throw away the original plot
    if (job.legendOnly) {
        chart = new JFreeChart("", null, new legendPlot(), false);
        chart.addLegend(actionEventsLegend);
    }

    try {
        FileUtils.createDirectory(job.outputDir);
        String filename = job.outputFilename == null
                ? job.outputDir + "/" + plotTool.MakeFileName(title) + ".jpg"
                : job.outputDir + "/" + job.outputFilename;
        if (!filename.endsWith(".jpg"))
            filename = filename + ".jpg";
        File JPGFile = new File(filename);
        if (job.imageHeight != null && job.imageWidth != null)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, job.imageWidth, job.imageHeight);
        else if (!job.hideAELegend && !job.removeAllLegends)
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, verticalPixels);
        else
            ChartUtilities.saveChartAsJPEG(JPGFile, chart, 1600, 800);
    } catch (IOException e) {
        Log.error(e.getMessage());
    }
}

From source file:com.voterData.graph.Graph.java

public static JFreeChart getRaceDistbn2008(Map<String, Double> dataMap) {
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    for (String key : dataMap.keySet()) {
        if (key.equals("A_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Asian", "REP");
        } else if (key.equals("B_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "REP");
        } else if (key.equals("I_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "REP");
        } else if (key.equals("O_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Other", "REP");
        } else if (key.equals("M_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "REP");
        } else if (key.equals("U_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "REP");
        } else if (key.equals("W_Rep_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "White", "REP");
        } else if (key.equals("A_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Asian", "DEM");
        } else if (key.equals("B_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "DEM");
        } else if (key.equals("I_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "DEM");
        } else if (key.equals("O_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Other", "DEM");
        } else if (key.equals("M_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "DEM");
        } else if (key.equals("U_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "DEM");
        } else if (key.equals("W_Dem_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "White", "DEM");
        } else if (key.equals("A_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Asian", "UNA");
        } else if (key.equals("B_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "African American/Black", "UNA");
        } else if (key.equals("I_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "American Indian/Alaska Native", "UNA");
        } else if (key.equals("O_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Other", "UNA");
        } else if (key.equals("M_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Multiracial", "UNA");
        } else if (key.equals("U_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "Undefined", "UNA");
        } else if (key.equals("W_Una_2008")) {
            defaultcategorydataset.addValue(dataMap.get(key), "White", "UNA");
        }// w w  w .  j a v a 2  s  .c  om
    }

    JFreeChart jfreechart = ChartFactory.createBarChart("Race Distribution - 2008", "Party", "% of votes",
            defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    BarRenderer renderer = (BarRenderer) categoryplot.getRenderer();

    renderer.setDrawBarOutline(false);
    renderer.setSeriesPaint(0, Color.ORANGE);
    renderer.setSeriesPaint(1, Color.MAGENTA);
    renderer.setSeriesPaint(2, Color.PINK);
    renderer.setSeriesPaint(3, Color.YELLOW);
    renderer.setSeriesPaint(4, Color.cyan);
    renderer.setSeriesPaint(5, Color.RED);
    renderer.setSeriesPaint(6, Color.green);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    renderer.setItemLabelsVisible(true);
    categoryplot.setRenderer(renderer);

    return jfreechart;

}

From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileTool.java

public boolean updatePlotPanel() {

    if (isBlockUpdate()) {
        return false;
    }/*from w  w w.  jav  a 2s  . c o  m*/

    if (realTimeImage.isSelected()) {
        previewPanel.setImage(getFlattenedImage());
    }
    // Chack data size of
    int length = getDataLength();

    if (xData.length != length) {
        xData = new float[length];
    }

    if (aScan.length != length) {
        aScan = new float[length];
    }

    // Update X Range
    float[] range = xRange;
    for (int i = 0; i < xData.length; i++) {
        xData[i] = (range[0] + (range[1] - range[0]) * (i / (xData.length - 1.f)));
    }

    xData = PlotingToolkit.getXDataFloat(aScan.length);
    updateAScan();

    int pos = (int) getOffset();
    if (pos < 0) {
        pos = 0;
    }
    XYSeriesCollection datCol1 = PlotingToolkit.getCollection(xData, aScan, "Data");

    XYSeriesCollection datCol2 = PlotingToolkit.getCollection(new float[] { xData[pos] },
            new float[] { aScan[pos] }, "Data");

    dataPlot.getXYPlot().setDataset(0, datCol1);
    dataPlot.getXYPlot().setDataset(1, datCol2);

    XYLineAndShapeRenderer dataRender1 = new XYLineAndShapeRenderer(true, false);
    XYLineAndShapeRenderer dataRender2 = new XYLineAndShapeRenderer(false, true);

    dataRender1.setSeriesPaint(0, Color.CYAN);
    dataRender2.setSeriesPaint(0, Color.RED);

    dataPlot.getXYPlot().setRenderer(0, dataRender1);
    dataPlot.getXYPlot().setRenderer(1, dataRender2);

    // XYSeriesCollection datCol1 = PlotingToolkit
    // .getCollection(xData, aScan, "Data");
    //
    // XYLineAndShapeRenderer dataRender1 = new XYLineAndShapeRenderer(true,
    // false);
    //
    // dataRender1.setSeriesPaint(0, Color.CYAN);
    // dataPlot.getXYPlot().setRenderer(0, dataRender1);
    // dataPlot.getXYPlot().setDataset(0, datCol1);

    dataPanel.repaint();
    return true;
}