Example usage for java.awt Color PINK

List of usage examples for java.awt Color PINK

Introduction

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

Prototype

Color PINK

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

Click Source Link

Document

The color pink.

Usage

From source file:Paints.java

/** Draw the example */
public void paint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    // Paint the entire background using a GradientPaint.
    // The background color varies diagonally from deep red to pale blue
    g.setPaint(new GradientPaint(0, 0, new Color(150, 0, 0), WIDTH, HEIGHT, new Color(200, 200, 255)));
    g.fillRect(0, 0, WIDTH, HEIGHT); // fill the background

    // Use a different GradientPaint to draw a box.
    // This one alternates between deep opaque green and transparent green.
    // Note: the 4th arg to Color() constructor specifies color opacity
    g.setPaint(new GradientPaint(0, 0, new Color(0, 150, 0), 20, 20, new Color(0, 150, 0, 0), true));
    g.setStroke(new BasicStroke(15)); // use wide lines
    g.drawRect(25, 25, WIDTH - 50, HEIGHT - 50); // draw the box

    // The glyphs of fonts can be used as Shape objects, which enables
    // us to use Java2D techniques with letters Just as we would with
    // any other shape. Here we get some letter shapes to draw.
    Font font = new Font("Serif", Font.BOLD, 10); // a basic font
    Font bigfont = // a scaled up version
            font.deriveFont(AffineTransform.getScaleInstance(30.0, 30.0));
    GlyphVector gv = bigfont.createGlyphVector(g.getFontRenderContext(), "JAV");
    Shape jshape = gv.getGlyphOutline(0); // Shape of letter J
    Shape ashape = gv.getGlyphOutline(1); // Shape of letter A
    Shape vshape = gv.getGlyphOutline(2); // Shape of letter V

    // We're going to outline the letters with a 5-pixel wide line
    g.setStroke(new BasicStroke(5.0f));

    // We're going to fake shadows for the letters using the
    // following Paint and AffineTransform objects
    Paint shadowPaint = new Color(0, 0, 0, 100); // Translucent black
    AffineTransform shadowTransform = AffineTransform.getShearInstance(-1.0, 0.0); // Shear to the right
    shadowTransform.scale(1.0, 0.5); // Scale height by 1/2

    // Move to the baseline of our first letter
    g.translate(65, 270);// w ww .ja  v a2 s  .c  o m

    // Draw the shadow of the J shape
    g.setPaint(shadowPaint);
    g.translate(15, 20); // Compensate for the descender of the J
    // transform the J into the shape of its shadow, and fill it
    g.fill(shadowTransform.createTransformedShape(jshape));
    g.translate(-15, -20); // Undo the translation above

    // Now fill the J shape with a solid (and opaque) color
    g.setPaint(Color.blue); // Fill with solid, opaque blue
    g.fill(jshape); // Fill the shape
    g.setPaint(Color.black); // Switch to solid black
    g.draw(jshape); // And draw the outline of the J

    // Now draw the A shadow
    g.translate(75, 0); // Move to the right
    g.setPaint(shadowPaint); // Set shadow color
    g.fill(shadowTransform.createTransformedShape(ashape)); // draw shadow

    // Draw the A shape using a solid transparent color
    g.setPaint(new Color(0, 255, 0, 125)); // Transparent green as paint
    g.fill(ashape); // Fill the shape
    g.setPaint(Color.black); // Switch to solid back
    g.draw(ashape); // Draw the outline

    // Move to the right and draw the shadow of the letter V
    g.translate(175, 0);
    g.setPaint(shadowPaint);
    g.fill(shadowTransform.createTransformedShape(vshape));

    // We're going to fill the next letter using a TexturePaint, which
    // repeatedly tiles an image. The first step is to obtain the image.
    // We could load it from an image file, but here we create it
    // ourselves by drawing a into an off-screen image. Note that we use
    // a GradientPaint to fill the off-screen image, so the fill pattern
    // combines features of both Paint classes.
    BufferedImage tile = // Create an image
            new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
    Graphics2D tg = tile.createGraphics(); // Get its Graphics for drawing
    tg.setColor(Color.pink);
    tg.fillRect(0, 0, 50, 50); // Fill tile background with pink
    tg.setPaint(new GradientPaint(40, 0, Color.green, // diagonal gradient
            0, 40, Color.gray)); // green to gray
    tg.fillOval(5, 5, 40, 40); // Draw a circle with this gradient

    // Use this new tile to create a TexturePaint and fill the letter V
    g.setPaint(new TexturePaint(tile, new Rectangle(0, 0, 50, 50)));
    g.fill(vshape); // Fill letter shape
    g.setPaint(Color.black); // Switch to solid black
    g.draw(vshape); // Draw outline of letter

    // Move to the right and draw the shadow of the final A
    g.translate(160, 0);
    g.setPaint(shadowPaint);
    g.fill(shadowTransform.createTransformedShape(ashape));

    g.fill(ashape); // Fill letter A
    g.setPaint(Color.black); // Revert to solid black
    g.draw(ashape); // Draw the outline of the A
}

From source file:eu.planets_project.tb.impl.chart.ExperimentExecutionCharts.java

public JFreeChart createXYChart(String expId) {
    ExperimentPersistencyRemote edao = ExperimentPersistencyImpl.getInstance();
    long eid = Long.parseLong(expId);
    log.info("Building experiment chart for eid = " + eid);
    Experiment exp = edao.findExperiment(eid);

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    final String expName = exp.getExperimentSetup().getBasicProperties().getExperimentName();
    List<Boolean> success = new ArrayList<Boolean>();

    for (BatchExecutionRecordImpl batch : exp.getExperimentExecutable().getBatchExecutionRecords()) {
        int i = 1;
        for (ExecutionRecordImpl exr : batch.getRuns()) {
            //log.info("Found Record... "+exr+" stages: "+exr.getStages());
            if (exr != null && exr.getStages() != null) {
                // Look up the object, so we can get the name.
                DigitalObjectRefBean dh = new DataHandlerImpl().get(exr.getDigitalObjectReferenceCopy());
                String dobName = "Object " + i;
                if (dh != null)
                    dobName = dh.getName();

                for (ExecutionStageRecordImpl exsr : exr.getStages()) {
                    Double time = exsr.getDoubleMeasurement(TecRegMockup.PROP_SERVICE_TIME);
                    // Look for timing:
                    if (time != null) {
                        dataset.addValue(time, expName, dobName);
                        if (exsr.isMarkedAsSuccessful()) {
                            success.add(Boolean.TRUE);
                        } else {
                            success.add(Boolean.FALSE);
                        }/*from  ww  w .ja v a 2  s . c  o m*/
                    }
                }
            }
            // Increment, for the next run.
            i++;
        }
    }

    // Create the chart.
    JFreeChart chart = ChartFactory.createBarChart(null, "Digital Object", "Time [s]", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

    Paint[] customColours = new Paint[success.size()];
    for (int i = 0; i < success.size(); i++) {
        Boolean b = success.get(i);
        if (Boolean.TRUE.equals(b)) {
            customColours[i] = Color.GREEN;
        } else {
            customColours[i] = Color.RED;
        }
    }
    CategoryItemRenderer renderer = new CustomRenderer(customColours);

    // disable bar outlines...
    //final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    //renderer.setDrawBarOutline(false);
    plot.setRenderer(renderer);

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

    // Set the tooltips...
    renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp", "series", "section"));
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));

    return chart;
}

From source file:org.samjoey.graphing.GraphUtility.java

public static void createGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (Game game : games) {
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }// w  w  w  . j  a va2s .c om
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }

    for (String key : datasets.keySet()) {
        JFrame f = new JFrame();
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        f.setContentPane(chartPanel);
        f.pack();
        RefineryUtilities.centerFrameOnScreen(f);
        f.setVisible(true);
    }
}

From source file:projekt.CustomRenderer.java

public void raport_lokalny() throws IOException, ClassNotFoundException, SQLException {

    loginController login = new loginController();
    String zapytanie = "select count(*) as Aktualne from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Aktualne' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";
    String zapytanie1 = "select count(*) as FORTEST from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'FORTEST' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";
    String zapytanie2 = "select count(*) as Zakonczone from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Zakonczone' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8",
            "root", "");
    PreparedStatement statment;/*from   ww w .j a  v a2s  .  c o  m*/
    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");
    }
    //tu tez zmienic na id
    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 z projektow za ktore odpowiada " + result.getString(1), "Zadania", "Ilosc", set2,
            PlotOrientation.VERTICAL, false, true, false);

    final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.blue, Color.pink, Color.cyan,
            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 lokalny " + 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
        Naglowek1(content, dataformat, data);
        //stopka strona1
        Stopka(content, doc);
        content.beginText();
        content.setFont(font1, 48);
        content.moveTextPositionByAmount(135, 550);
        content.showText("Raport lokalny");
        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);
        Naglowek1(content2, dataformat, data);
        //stopka strona2
        Stopka(content2, doc);
        content2.beginText();
        content2.setFont(font, 14);
        content2.moveTextPositionByAmount(30, 775);
        content2.showText("Wszystkie projekty za ktre odpowiada: " + result.getString(1));
        statment = con.prepareStatement(
                "Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty where idUzytkownika='"
                        + login.uzytkownikID + "'");
        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(1));
            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) + "' and idUzytkownika='" + login.uzytkownikID + "'");
        result = statment.executeQuery();
        int aktualne = 0, zakonczone = 0;
        if (result.next()) {
            aktualne = result.getInt("Aktualne");
        }
        statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '"
                + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'");
        result = statment.executeQuery();
        if (result.next()) {
            zakonczone = result.getInt("Zakonczone");
        }

        DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("Aktualne", aktualne);
        pieDataset.setValue("Zakonczone", zakonczone);
        JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projekt za ktore odpowiada" + bbc, // Title
                pieDataset, // Dataset
                true, // Show legend
                true, // Use tooltips
                false // Configure chart to generate URLs?
        );

        PiePlot plot1 = (PiePlot) chart1.getPlot();
        plot1.setSectionPaint("Aktualne", Color.blue);
        plot1.setSectionPaint("Zakonczone", Color.yellow);
        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);
        Naglowek1(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);
        Naglowek1(content4, dataformat, data);
        //stopka strona2
        Stopka(content4, doc);
        content4.beginText();
        content4.setFont(font, 14);
        content4.moveTextPositionByAmount(30, 780);
        content4.showText("Wszystkie zadania w projektach za ktore odpowiada:" + bbc);
        statment = con.prepareStatement(
                "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, ' ' , y.nazwisko) as 'UZY' FROM zadania , (select Nazwa from projekty where idUzytkownika = '"
                        + login.uzytkownikID
                        + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '"
                        + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12"); //poprawic
        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("zadania.Nazwa"));
            content4.newLine();
            nw -= 17;
            content4.moveTextPositionByAmount(0, -17);
            content4.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: "
                    + result.getString("zadania.Status_zadania"));
            content4.newLine();
            nw -= 17;
            content4.moveTextPositionByAmount(0, -17);
            content4.showText(" Projekt: " + result.getString("zadania.projekt")
                    + " Przydzielona osoba do zadania: " + result.getString("UZY"));

        }

        content4.endText();
        content4.close();
        statment = con.prepareStatement(
                "SELECT count(*) as 'liczba' FROM `zadania` where idUzytkownika='" + login.uzytkownikID + "'"); //poprawic
        result = statment.executeQuery();
        if (result.next()) {
        }
        statment = con.prepareStatement(
                "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, \" \", y.nazwisko) as \"UZY\" FROM zadania , (select Nazwa from projekty where idUzytkownika = '"
                        + login.uzytkownikID
                        + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '"
                        + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12,"
                        + result.getInt(1) + "");
        result = statment.executeQuery();
        PDPage page5 = new PDPage(PAGE_SIZE);
        doc.addPage(page5);
        PDPageContentStream content5 = new PDPageContentStream(doc, page5);
        Naglowek1(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("zadania.Nazwa"));
            content5.newLine();
            nw -= 17;
            content5.moveTextPositionByAmount(0, -17);
            content5.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: "
                    + result.getString("zadania.Status_zadania"));
            content5.newLine();
            nw -= 17;
            content5.moveTextPositionByAmount(0, -17);
            content5.showText(" Projekt: " + result.getString("zadania.projekt")
                    + " Przydzielona osoba do zadania: " + result.getString("UZY"));
        }
        content5.endText();
        content5.close();
        doc.addPage(page1);
        //naglowek strona 2
        Naglowek1(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:umontreal.ssj.charts.SSJCategorySeriesCollection.java

/**
 * Converts a java Color object into a friendly and readable LaTeX/xcolor string.
 *
 * @param   color    in color./*from w  w  w .  j  av a  2s.c  om*/
 * @return           friendly color with string format as possible, null otherwise.
 */
protected static String detectXColorClassic(Color color) {
    String retour = null;

    int red = color.getRed();
    int green = color.getGreen();
    int blue = color.getBlue();

    // On utilise pas la method Color.equals(Color ) car on ne veut pas tester le parametre de transparence : Alpha
    if (red == Color.GREEN.getRed() && blue == Color.GREEN.getBlue() && green == Color.GREEN.getGreen())
        return "green";
    else if (red == Color.RED.getRed() && blue == Color.RED.getBlue() && green == Color.RED.getGreen())
        return "red";
    else if (red == Color.WHITE.getRed() && blue == Color.WHITE.getBlue() && green == Color.WHITE.getGreen())
        return "white";
    else if (red == Color.GRAY.getRed() && blue == Color.GRAY.getBlue() && green == Color.GRAY.getGreen())
        return "gray";
    else if (red == Color.BLACK.getRed() && blue == Color.BLACK.getBlue() && green == Color.BLACK.getGreen())
        return "black";
    else if (red == Color.YELLOW.getRed() && blue == Color.YELLOW.getBlue() && green == Color.YELLOW.getGreen())
        return "yellow";
    else if (red == Color.MAGENTA.getRed() && blue == Color.MAGENTA.getBlue()
            && green == Color.MAGENTA.getGreen())
        return "magenta";
    else if (red == Color.CYAN.getRed() && blue == Color.CYAN.getBlue() && green == Color.CYAN.getGreen())
        return "cyan";
    else if (red == Color.BLUE.getRed() && blue == Color.BLUE.getBlue() && green == Color.BLUE.getGreen())
        return "blue";
    else if (red == Color.DARK_GRAY.getRed() && blue == Color.DARK_GRAY.getBlue()
            && green == Color.DARK_GRAY.getGreen())
        return "darkgray";
    else if (red == Color.LIGHT_GRAY.getRed() && blue == Color.LIGHT_GRAY.getBlue()
            && green == Color.LIGHT_GRAY.getGreen())
        return "lightgray";
    else if (red == Color.ORANGE.getRed() && blue == Color.ORANGE.getBlue() && green == Color.ORANGE.getGreen())
        return "orange";
    else if (red == Color.PINK.getRed() && blue == Color.PINK.getBlue() && green == Color.PINK.getGreen())
        return "pink";

    if (red == 192 && blue == 128 && green == 64)
        return "brown";
    else if (red == 128 && blue == 128 && green == 0)
        return "olive";
    else if (red == 128 && blue == 0 && green == 128)
        return "violet";
    else if (red == 192 && blue == 0 && green == 64)
        return "purple";
    else
        return null;
}

From source file:org.deeplearning4j.ui.TestRendering.java

@Ignore
@Test//from  ww w.j a  va 2  s  .  c om
public void test() throws Exception {

    List<Component> list = new ArrayList<>();

    //Common style for all of the charts
    StyleChart s = new StyleChart.Builder().width(640, LengthUnit.Px).height(480, LengthUnit.Px)
            .margin(LengthUnit.Px, 100, 40, 40, 20).strokeWidth(2).pointSize(4)
            .seriesColors(Color.GREEN, Color.MAGENTA).titleStyle(new StyleText.Builder().font("courier")
                    .fontSize(16).underline(true).color(Color.GRAY).build())
            .build();

    //Line chart with vertical grid
    Component c1 = new ChartLine.Builder("Line Chart!", s)
            .addSeries("series0", new double[] { 0, 1, 2, 3 }, new double[] { 0, 2, 1, 4 })
            .addSeries("series1", new double[] { 0, 1, 2, 3 }, new double[] { 0, 1, 0.5, 2.5 })
            .setGridWidth(1.0, null) //Vertical grid lines, no horizontal grid
            .build();
    list.add(c1);

    //Scatter chart
    Component c2 = new ChartScatter.Builder("Scatter!", s)
            .addSeries("series0", new double[] { 0, 1, 2, 3 }, new double[] { 0, 2, 1, 4 }).showLegend(true)
            .setGridWidth(0, 0).build();
    list.add(c2);

    //Histogram with variable sized bins
    Component c3 = new ChartHistogram.Builder("Histogram!", s).addBin(-1, -0.5, 0.2).addBin(-0.5, 0, 0.5)
            .addBin(0, 1, 2.5).addBin(1, 2, 0.5).build();
    list.add(c3);

    //Stacked area chart
    Component c4 = new ChartStackedArea.Builder("Area Chart!", s).setXValues(new double[] { 0, 1, 2, 3, 4, 5 })
            .addSeries("series0", new double[] { 0, 1, 0, 2, 0, 1 })
            .addSeries("series1", new double[] { 2, 1, 2, 0.5, 2, 1 }).build();
    list.add(c4);

    //Table
    StyleTable ts = new StyleTable.Builder().backgroundColor(Color.LIGHT_GRAY).headerColor(Color.ORANGE)
            .borderWidth(1).columnWidths(LengthUnit.Percent, 20, 40, 40).width(500, LengthUnit.Px)
            .height(200, LengthUnit.Px).build();

    Component c5 = new ComponentTable.Builder(ts).header("H1", "H2", "H3").content(
            new String[][] { { "row0col0", "row0col1", "row0col2" }, { "row1col0", "row1col1", "row1col2" } })
            .build();
    list.add(c5);

    //Accordion decorator, with the same chart
    StyleAccordion ac = new StyleAccordion.Builder().height(480, LengthUnit.Px).width(640, LengthUnit.Px)
            .build();

    Component c6 = new DecoratorAccordion.Builder(ac).title("Accordion - Collapsed By Default!")
            .setDefaultCollapsed(true).addComponents(c5).build();
    list.add(c6);

    //Text with styling
    Component c7 = new ComponentText.Builder("Here's some blue text in a green div!",
            new StyleText.Builder().font("courier").fontSize(30).underline(true).color(Color.BLUE).build())
                    .build();

    //Div, with a chart inside
    Style divStyle = new StyleDiv.Builder().width(30, LengthUnit.Percent).height(200, LengthUnit.Px)
            .backgroundColor(Color.GREEN).floatValue(StyleDiv.FloatValue.right).build();
    Component c8 = new ComponentDiv(divStyle, c7,
            new ComponentText("(Also: it's float right, 30% width, 200 px high )", null));
    list.add(c8);

    //Timeline chart:
    List<ChartTimeline.TimelineEntry> entries = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        entries.add(new ChartTimeline.TimelineEntry("e0-" + i, 10 * i, 10 * i + 5, Color.BLUE));
    }
    List<ChartTimeline.TimelineEntry> entries2 = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        entries2.add(new ChartTimeline.TimelineEntry("e1-" + i, (int) (5 * i + 0.2 * i * i),
                (int) (5 * i + 0.2 * i * i) + 3, Color.ORANGE));
    }
    List<ChartTimeline.TimelineEntry> entries3 = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        entries3.add(new ChartTimeline.TimelineEntry("e2-" + i, (int) (2 * i + 0.6 * i * i + 3),
                (int) (2 * i + 0.6 * i * i + 3) + 2 * i + 1));
    }
    Color[] c = new Color[] { Color.CYAN, Color.YELLOW, Color.GREEN, Color.PINK };
    List<ChartTimeline.TimelineEntry> entries4 = new ArrayList<>();
    Random r = new Random(12345);
    for (int i = 0; i < 10; i++) {
        entries4.add(new ChartTimeline.TimelineEntry("e3-" + i, (int) (2 * i + 0.6 * i * i + 3),
                (int) (2 * i + 0.6 * i * i + 3) + i + 1, c[r.nextInt(c.length)]));
    }
    Component c9 = new ChartTimeline.Builder("Title", s).addLane("Lane 0", entries).addLane("Lane 1", entries2)
            .addLane("Lane 2", entries3).addLane("Lane 3", entries4).build();
    list.add(c9);

    //Generate HTML
    StringBuilder sb = new StringBuilder();
    sb.append("<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + "<head>\n" + "    <meta charset=\"UTF-8\">\n"
            + "    <title>Title</title>\n" + "</head>\n" + "<body>\n" + "\n" + "    <div id=\"maindiv\">\n"
            + "\n" + "    </div>\n" + "\n" + "\n"
            + "    <script src=\"//code.jquery.com/jquery-1.10.2.js\"></script>\n"
            + "    <script src=\"https://code.jquery.com/ui/1.11.4/jquery-ui.min.js\"></script>\n"
            + "    <link rel=\"stylesheet\" href=\"//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css\">\n"
            + "    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js\"></script>\n"
            + "    <script src=\"src/main/resources/assets/dl4j-ui.js\"></script>\n" + "\n" + "    <script>\n");

    ObjectMapper om = new ObjectMapper();
    for (int i = 0; i < list.size(); i++) {
        Component component = list.get(i);
        sb.append("        ").append("var str").append(i).append(" = '")
                .append(om.writeValueAsString(component).replaceAll("'", "\\\\'")).append("';\n");

        sb.append("        ").append("var obj").append(i).append(" = Component.getComponent(str").append(i)
                .append(");\n");
        sb.append("        ").append("obj").append(i).append(".render($('#maindiv'));\n");
        sb.append("\n\n");
    }

    sb.append("    </script>\n" + "\n" + "</body>\n" + "</html>");

    FileUtils.writeStringToFile(new File("TestRendering.html"), sb.toString());
}

From source file:fitmon.WorkoutChart.java

/**
 * Creates a sample chart./*from  w  w  w . ja  v  a2  s.c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
public JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("weekly workout", // chart title
            "Date", // domain axis label
            "Performance", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(25, 200);

    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

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

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:umontreal.iro.lecuyer.charts.SSJCategorySeriesCollection.java

protected static String detectXColorClassic(Color color) {
    String retour = null;/*from w  w w .ja  v  a2 s.c o  m*/

    int red = color.getRed();
    int green = color.getGreen();
    int blue = color.getBlue();

    // On utilise pas la method Color.equals(Color ) car on ne veut pas tester le parametre de transparence : Alpha
    if (red == Color.GREEN.getRed() && blue == Color.GREEN.getBlue() && green == Color.GREEN.getGreen())
        return "green";
    else if (red == Color.RED.getRed() && blue == Color.RED.getBlue() && green == Color.RED.getGreen())
        return "red";
    else if (red == Color.WHITE.getRed() && blue == Color.WHITE.getBlue() && green == Color.WHITE.getGreen())
        return "white";
    else if (red == Color.GRAY.getRed() && blue == Color.GRAY.getBlue() && green == Color.GRAY.getGreen())
        return "gray";
    else if (red == Color.BLACK.getRed() && blue == Color.BLACK.getBlue() && green == Color.BLACK.getGreen())
        return "black";
    else if (red == Color.YELLOW.getRed() && blue == Color.YELLOW.getBlue() && green == Color.YELLOW.getGreen())
        return "yellow";
    else if (red == Color.MAGENTA.getRed() && blue == Color.MAGENTA.getBlue()
            && green == Color.MAGENTA.getGreen())
        return "magenta";
    else if (red == Color.CYAN.getRed() && blue == Color.CYAN.getBlue() && green == Color.CYAN.getGreen())
        return "cyan";
    else if (red == Color.BLUE.getRed() && blue == Color.BLUE.getBlue() && green == Color.BLUE.getGreen())
        return "blue";
    else if (red == Color.DARK_GRAY.getRed() && blue == Color.DARK_GRAY.getBlue()
            && green == Color.DARK_GRAY.getGreen())
        return "darkgray";
    else if (red == Color.LIGHT_GRAY.getRed() && blue == Color.LIGHT_GRAY.getBlue()
            && green == Color.LIGHT_GRAY.getGreen())
        return "lightgray";
    else if (red == Color.ORANGE.getRed() && blue == Color.ORANGE.getBlue() && green == Color.ORANGE.getGreen())
        return "orange";
    else if (red == Color.PINK.getRed() && blue == Color.PINK.getBlue() && green == Color.PINK.getGreen())
        return "pink";

    if (red == 192 && blue == 128 && green == 64)
        return "brown";
    else if (red == 128 && blue == 128 && green == 0)
        return "olive";
    else if (red == 128 && blue == 0 && green == 128)
        return "violet";
    else if (red == 192 && blue == 0 && green == 64)
        return "purple";
    else
        return null;
}

From source file:com.joey.software.plottingToolkit.PlotingToolkit.java

public static Color getPlotColor(int number) {
    switch (number) {
    case 0:/*from   w  w w . jav a2  s .  c o  m*/
        return Color.RED;
    case 1:
        return Color.GREEN;
    case 2:
        return Color.BLUE;
    case 3:
        return Color.CYAN;
    case 4:
        return Color.PINK;
    case 5:
        return Color.magenta;
    default:
        return ImageOperations.getRandomColor();
    }
}

From source file:it.cnr.istc.iloc.gui.StateVariableVisualizer.java

@Override
public Collection<XYPlot> getPlots(Type type) {
    Collection<IItem> instances = type.getInstances();
    Collection<XYPlot> plots = new ArrayList<>(instances.size());
    Map<IItem, Collection<Atom>> sv_atoms = new IdentityHashMap<>(instances.size());
    for (IItem i : type.getInstances()) {
        sv_atoms.put(i, new ArrayList<>());
    }//w w  w  .  j  ava  2  s. c o  m
    for (Atom atom : ((StateVariable) type).getDefinedPredicates().stream()
            .flatMap(p -> p.getInstances().stream()).map(a -> (Atom) a)
            .filter(a -> a.state.evaluate().isSingleton() && a.state.evaluate().contains(AtomState.Active))
            .collect(Collectors.toList())) {
        for (IItem i : ((IEnumItem) atom.get(SCOPE)).getEnumVar().evaluate().getAllowedValues()) {
            if (sv_atoms.containsKey(i)) {
                sv_atoms.get(i).add(atom);
            }
        }
    }

    for (IItem sv : instances) {
        Collection<Atom> atoms = sv_atoms.get(sv);
        // For each pulse the atoms starting at that pulse
        Map<Double, Collection<Atom>> starting_atoms = new HashMap<>(atoms.size());
        // For each pulse the atoms ending at that pulse
        Map<Double, Collection<Atom>> ending_atoms = new HashMap<>(atoms.size());

        // The pulses of the timeline
        Set<Double> c_pulses = new HashSet<>(atoms.size() * 2);

        for (Atom atom : atoms) {
            double start = sv.getCore().evaluate(((IArithItem) atom.get("start")).getArithVar());
            double end = sv.getCore().evaluate(((IArithItem) atom.get("end")).getArithVar());

            if (!starting_atoms.containsKey(start)) {
                starting_atoms.put(start, new ArrayList<>());
            }
            starting_atoms.get(start).add(atom);

            if (!ending_atoms.containsKey(end)) {
                ending_atoms.put(end, new ArrayList<>());
            }
            ending_atoms.get(end).add(atom);

            c_pulses.add(start);
            c_pulses.add(end);
        }

        // we sort current pulses..
        Double[] c_pulses_array = c_pulses.toArray(new Double[c_pulses.size()]);
        Arrays.sort(c_pulses_array);

        XYIntervalSeriesCollection collection = new XYIntervalSeriesCollection();

        ValueXYIntervalSeries undefined = new ValueXYIntervalSeries("Undefined");
        ValueXYIntervalSeries sv_values = new ValueXYIntervalSeries("Values");
        ValueXYIntervalSeries conflicts = new ValueXYIntervalSeries("Conflicts");

        List<Atom> overlapping_atoms = new ArrayList<>();
        for (int i = 0; i < c_pulses_array.length - 1; i++) {
            if (starting_atoms.containsKey(c_pulses_array[i])) {
                overlapping_atoms.addAll(starting_atoms.get(c_pulses_array[i]));
            }
            if (ending_atoms.containsKey(c_pulses_array[i])) {
                overlapping_atoms.removeAll(ending_atoms.get(c_pulses_array[i]));
            }
            switch (overlapping_atoms.size()) {
            case 0:
                undefined.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1,
                        new Atom[0]);
                break;
            case 1:
                sv_values.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1,
                        overlapping_atoms.toArray(new Atom[overlapping_atoms.size()]));
                break;
            default:
                conflicts.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1,
                        overlapping_atoms.toArray(new Atom[overlapping_atoms.size()]));
                break;
            }
        }

        collection.addSeries(undefined);
        collection.addSeries(sv_values);
        collection.addSeries(conflicts);

        XYBarRenderer renderer = new XYBarRenderer();
        renderer.setSeriesPaint(0, Color.lightGray);
        renderer.setSeriesPaint(1, new Color(100, 250, 100));
        renderer.setSeriesPaint(2, Color.pink);
        renderer.setBarPainter(new ReverseGradientXYBarPainter());
        renderer.setDrawBarOutline(true);
        renderer.setShadowXOffset(2);
        renderer.setShadowYOffset(2);
        renderer.setUseYInterval(true);

        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelPaint(Color.black);
        Font font = new Font("SansSerif", Font.PLAIN, 9);
        renderer.setBaseItemLabelFont(font);
        XYItemLabelGenerator generator = (XYDataset dataset, int series,
                int item) -> toString(((ValueXYIntervalDataItem) ((XYIntervalSeriesCollection) dataset)
                        .getSeries(series).getDataItem(item)).atoms);
        ItemLabelPosition itLabPos = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER);
        renderer.setBasePositiveItemLabelPosition(itLabPos);
        for (int i = 0; i < collection.getSeriesCount(); i++) {
            renderer.setSeriesItemLabelGenerator(i, generator);
            renderer.setSeriesItemLabelsVisible(i, true);
            renderer.setSeriesItemLabelPaint(i, Color.black);
            renderer.setSeriesItemLabelFont(i, font);
            renderer.setSeriesPositiveItemLabelPosition(i, itLabPos);
            renderer.setSeriesToolTipGenerator(i,
                    (XYDataset dataset, int series, int item) -> toString(
                            ((ValueXYIntervalDataItem) ((XYIntervalSeriesCollection) dataset).getSeries(series)
                                    .getDataItem(item)).atoms));
        }

        XYPlot plot = new XYPlot(collection, null, new NumberAxis(""), renderer);
        plot.getRangeAxis().setVisible(false);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        plots.add(plot);
    }

    return plots;
}