Example usage for java.awt Color getGreen

List of usage examples for java.awt Color getGreen

Introduction

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

Prototype

public int getGreen() 

Source Link

Document

Returns the green component in the range 0-255 in the default sRGB space.

Usage

From source file:com.dlya.facturews.DlyaPdfExporter2.java

/**
 *
 *//*from   ww  w.j av a  2 s .c  om*/
private static void preparePen(PdfContentByte pdfContentByte, JRPen pen, int lineCap) {
    float lineWidth = pen.getLineWidth().floatValue();

    if (lineWidth <= 0) {
        return;
    }

    pdfContentByte.setLineWidth(lineWidth);
    pdfContentByte.setLineCap(lineCap);

    Color color = pen.getLineColor();
    pdfContentByte.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());

    switch (pen.getLineStyleValue()) {
    case DOUBLE: {
        pdfContentByte.setLineWidth(lineWidth / 3);
        pdfContentByte.setLineDash(0f);
        break;
    }
    case DOTTED: {
        switch (lineCap) {
        case PdfContentByte.LINE_CAP_BUTT: {
            pdfContentByte.setLineDash(lineWidth, lineWidth, 0f);
            break;
        }
        case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: {
            pdfContentByte.setLineDash(0, 2 * lineWidth, 0f);
            break;
        }
        }
        break;
    }
    case DASHED: {
        switch (lineCap) {
        case PdfContentByte.LINE_CAP_BUTT: {
            pdfContentByte.setLineDash(5 * lineWidth, 3 * lineWidth, 0f);
            break;
        }
        case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: {
            pdfContentByte.setLineDash(4 * lineWidth, 4 * lineWidth, 0f);
            break;
        }
        }
        break;
    }
    case SOLID:
    default: {
        pdfContentByte.setLineDash(0f);
        break;
    }
    }
}

From source file:net.sf.jasperreports.engine.export.JExcelApiExporter.java

protected static int rgbDistance(Color awtColor, RGB rgb) {
    return Math.abs(rgb.getRed() - awtColor.getRed()) + Math.abs(rgb.getGreen() - awtColor.getGreen())
            + Math.abs(rgb.getBlue() - awtColor.getBlue());
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static BufferedImage transparentColor(BufferedImage src, Color trColor) {
    int w = src.getWidth();
    int h = src.getHeight();
    BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    if (src.getRaster().getNumBands() < 3) {
        for (int i = 0; i < 3; i++) {
            dst.getRaster().setSamples(0, 0, w, h, i, src.getRaster().getSamples(0, 0, w, h, 0, (int[]) null));
        }/* w w w. j  a v  a 2  s . c  o  m*/
    } else if (src.getRaster().getNumBands() >= 3) {
        for (int i = 0; i < 3; i++) {
            dst.getRaster().setSamples(0, 0, w, h, i, src.getRaster().getSamples(0, 0, w, h, i, (int[]) null));
        }
    }

    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            if (dst.getRaster().getSample(x, y, 0) == trColor.getRed()
                    && dst.getRaster().getSample(x, y, 1) == trColor.getGreen()
                    && dst.getRaster().getSample(x, y, 2) == trColor.getBlue()) {
                dst.getRaster().setSample(x, y, 3, 0);
            } else {
                dst.getRaster().setSample(x, y, 3, 255);
            }
        }
    }
    return dst;
}

From source file:com.chart.SwingChart.java

/**
 * /*from ww w.  java2 s.  c o  m*/
 * @param color JavaFX color
 * @return AWT Color
 */
final java.awt.Color scene2awtColor(javafx.scene.paint.Color color) {
    return new java.awt.Color((float) color.getRed(), (float) color.getGreen(), (float) color.getBlue());
}

From source file:savant.view.tracks.BAMTrackRenderer.java

private Color makeTransparent(Color c) {
    return new Color(c.getRed(), c.getGreen(), c.getBlue(), 90);
}

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

public String toLatex(double XScale, double YScale, double XShift, double YShift, double xmin, double xmax,
        double ymin, double ymax) {

    // Calcule les bornes reelles du graphique, en prenant en compte la position des axes
    xmin = Math.min(XShift, xmin);
    xmax = Math.max(XShift, xmax);
    ymin = Math.min(YShift, ymin);
    ymax = Math.max(YShift, ymax);

    Formatter formatter = new Formatter(Locale.US);
    XYSeriesCollection tempSeriesCollection = (XYSeriesCollection) seriesCollection;
    double XEPSILON = (1.0E-4 / XScale) + XShift;
    double YEPSILON = (1.0E-4 / YScale) + YShift;
    boolean outOfBounds = false;
    MathFunction[] spline = null;//from w ww  . jav  a 2  s  . c  o m
    double[] xBounds = getRangeBounds();
    double[] yBounds = getDomainBounds();
    double x, y;
    // Smoothing splines, consulter  ref: QA278.2 G74, QA278.2 T35, QA278.2 E87

    //       if(xBounds[0] < xmin || xBounds[1] > xmax || yBounds[0] < ymin || yBounds[1] > ymax) {
    //          // on sait qu'il y a des points qui vont sortir du chart
    //          // initialisation d'une spline pour chaque courbe
    //          spline = new SmoothingCubicSpline[seriesCollection.getSeriesCount()];
    //          for(int i = 0; i<seriesCollection.getSeriesCount(); i++)
    //             spline[i] = new SmoothingCubicSpline(  (seriesCollection.getSeries(i).toArray())[0],
    //                                                    (seriesCollection.getSeries(i).toArray())[1], 0.5);
    //       }

    // on sait qu'il y a des points qui vont sortir du chart
    // initialisation d'une spline pour chaque courbe
    if (true) {
        spline = new SmoothingCubicSpline[tempSeriesCollection.getSeriesCount()];
        for (int i = 0; i < tempSeriesCollection.getSeriesCount(); i++)
            spline[i] = new SmoothingCubicSpline((tempSeriesCollection.getSeries(i).toArray())[0],
                    (tempSeriesCollection.getSeries(i).toArray())[1], 1);
    } else {
        spline = new AffineFit[tempSeriesCollection.getSeriesCount()];
        for (int i = 0; i < tempSeriesCollection.getSeriesCount(); i++)
            spline[i] = new AffineFit((tempSeriesCollection.getSeries(i).toArray())[0],
                    (tempSeriesCollection.getSeries(i).toArray())[1]);
    }

    for (int i = tempSeriesCollection.getSeriesCount() - 1; i >= 0; i--) {
        XYSeries temp = tempSeriesCollection.getSeries(i);

        if (temp.getItemCount() < 2)
            throw new IllegalArgumentException(
                    "Unable to plot series " + i + ": this series must have two points at least");

        Color color = (Color) renderer.getSeriesPaint(i);
        String colorString = detectXColorClassic(color);
        if (colorString == null) {
            colorString = "color" + i;
            formatter.format("\\definecolor{%s}{rgb}{%.2f, %.2f, %.2f}%n", colorString, color.getRed() / 255.0,
                    color.getGreen() / 255.0, color.getBlue() / 255.0);
        }

        // Cas particulier pour le premier point, on doit savoir si il est dans le chart ou pas
        if (temp.getX(0).doubleValue() >= xmin && temp.getX(0).doubleValue() <= xmax
                && temp.getY(0).doubleValue() >= ymin && temp.getY(0).doubleValue() <= ymax) {
            outOfBounds = false;
            formatter.format("\\draw [%s, color=%s, mark=%s, style=%s] plot coordinates {%%%n", plotStyle[i],
                    colorString, marksType[i], dashPattern[i]);
        } else {
            outOfBounds = true;
            formatter.format("%% ");
        }
        formatter.format("(%.2f,%.4f)", (temp.getX(0).doubleValue() - XShift) * XScale,
                (temp.getY(0).doubleValue() - YShift) * YScale);
        formatter.format(" %%   (%f,  %f)%n", temp.getX(0).doubleValue(), temp.getY(0).doubleValue());

        // Cas general
        for (int j = 1; j < temp.getItemCount(); j++) {
            double[] result;
            if (!outOfBounds) { //on est dans le chart
                result = evalLimitValues(xmin, xmax, ymin, ymax, XEPSILON, YEPSILON, spline[i], temp, j, false);
                // on regarde si on ne sort pas du chart, si c'est le cas on evalue le point en limite
                if (result != null) { // le point courant n'est pas dans le chart, on sort donc du chart
                    outOfBounds = true;
                    if (autoCompletion)
                        formatter.format("(%.2f,%.4f) %%%n", (result[0] - XShift) * XScale,
                                (result[1] - YShift) * YScale);
                    formatter.format("}%%%n%% ");
                }
            } else { // le point precedent etait hors du chart
                if (temp.getX(j).doubleValue() >= xmin && temp.getX(j).doubleValue() <= xmax
                        && temp.getY(j).doubleValue() >= ymin && temp.getY(j).doubleValue() <= ymax) {
                    // on rentre dans le chart, il faut evaluer le point en limite
                    j = j - 1;
                    result = evalLimitValues(xmin, xmax, ymin, ymax, XEPSILON, YEPSILON, spline[i], temp, j,
                            true);
                    // ici result ne peut pas etre null
                    formatter.format(";%%%n\\draw [%s, color=%s, mark=%s, style=%s] plot coordinates {%%%n",
                            plotStyle[i], colorString, marksType[i], dashPattern[i]);
                    if (autoCompletion)
                        formatter.format("(%.2f,%.4f) %%%n ", (result[0] - XShift) * XScale,
                                (result[1] - YShift) * YScale);
                    formatter.format("%% ");
                    outOfBounds = false;
                } else {
                    formatter.format("%% ");
                    // on les donnees sont toujours hors du chart
                }
            }
            /* on affiche les coordonnees du point quoiqu'il arrive,
            si celui ci est hors du chart alors la balise de commentaire a ete deja place */
            formatter.format("(%.2f,%.4f)", (temp.getX(j).doubleValue() - XShift) * XScale,
                    (temp.getY(j).doubleValue() - YShift) * YScale);
            if (j == temp.getItemCount() - 1)
                formatter.format("}");
            formatter.format(" %%   (%f,  %f)%n", temp.getX(j).doubleValue(), temp.getY(j).doubleValue());
            //            formatter.format(" %%%n");
        }
        formatter.format(" node[right] {%s};%n", (String) temp.getKey());
    }
    return formatter.toString();
}

From source file:org.n52.server.sos.render.DiagramRenderer.java

/**
 * Builds up a DesignDescriptionList which stores the information
 * about the style of each timeseries.//from   w ww .ja v  a  2s  . c  om
 * 
 * @param options
 *            the options
 * @return the design description list
 */
private DesignDescriptionList buildUpDesignDescriptionList(DesignOptions options) {

    String domainAxisLabel;
    if (options.getLanguage() != null && options.getLanguage().equals("de")) {
        domainAxisLabel = "Zeit";
    } else { // default => "en"
        domainAxisLabel = "Time";
    }
    if (this.isOverview) {
        domainAxisLabel = null;
    }

    DesignDescriptionList designDescriptions = new DesignDescriptionList(domainAxisLabel);
    String observedPropertyWithGrid = options.getProperties().get(0).getPhenomenon();

    for (TimeseriesProperties tsProperties : options.getProperties()) {
        Color c = JavaHelper.transformToColor(tsProperties.getHexColor());
        String phenomenonId = tsProperties.getPhenomenon();
        String procedureId = tsProperties.getProcedure();
        String featureId = tsProperties.getFeature();
        boolean drawGrid = observedPropertyWithGrid.equals(phenomenonId);

        TimeseriesParametersLookup lookup = getParameterLookup(tsProperties);
        Feature feature = lookup.getFeature(featureId);
        Procedure procedure = lookup.getProcedure(procedureId);
        Phenomenon phenomenon = lookup.getPhenomenon(phenomenonId);

        designDescriptions.add(phenomenon, procedure, feature, tsProperties,
                new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) tsProperties.getOpacity() * 255 / 100),
                tsProperties.getLineStyle(), tsProperties.getLineWidth(), drawGrid);
    }
    return designDescriptions;
}

From source file:LightTest.java

protected void OnColor() {
    Color rgb = m_ColorChooser.showDialog(m_Panel, "Set Light Color", null);

    if (rgb != null) {
        m_Light.setColor(new Color3f((float) rgb.getRed() / 255f, (float) rgb.getGreen() / 255f,
                (float) rgb.getBlue() / 255f));
    }/*from w  w  w.j  a v a2 s  . com*/
}

From source file:at.tuwien.ifs.somtoolbox.apps.viewer.fileutils.ExportUtils.java

public void saveImageMap(GrowingLayer layer, int unitWidth, String fullPath, String baseFileName,
        String[][] visualisations, boolean isAudioSOM, SOMLibClassInformation classInfo, Color[] colors,
        Properties cleanDataNamesMapping, String inputDataFilesPrefix, String outputDataFilesPrefix,
        String htmlTemplatesDir, String imageMapTitle, boolean generateRhythmPatterns,
        boolean forceLinkGeneration) throws SOMToolboxException {

    String XHTML_FRAMESET = "";
    String XHTML_FRAMESET_INDEXFRAME = "";
    String XHTML_FRAMESET_UNITDETAILS = "";
    String IMAGE_MAP_PAGE = "";
    String UNIT_DETAIL_PAGE = "";
    String VISNAV_PAGE = "";

    String absolutePath = new File((fullPath + "x").substring(0, (fullPath + "x").lastIndexOf(File.separator)))
            .getAbsolutePath();/*from  ww w. jav a  2  s .com*/

    String detailsDir = fullPath + "_details/";
    String detailsDirRelative = baseFileName + "_details/";
    new File(detailsDir).mkdirs();

    String playlistDir = fullPath + "_playlist/";
    String playlistDirRelative = baseFileName + "_playlist/";
    if (isAudioSOM) {
        new File(playlistDir).mkdir();
    }

    String imageMapDir = fullPath + "_map/";
    String imageMapBaseName = baseFileName + "_map/";
    new File(imageMapDir).mkdir();

    String imageDir = fullPath + "_map/"; // if changed here, must be changed in ExportDialog.java as well
    String imageDirRelative = "../" + baseFileName + "_map/";
    new File(imageDir).mkdir();

    // We currently don't use fileTpye icons for generic files
    // (may be later introduced for images, videos, etc.)
    String iconFileType = ""; // = "file.png";
    String unitDetailsTarget = "unitDetails";
    if (isAudioSOM) {
        iconFileType = "note.png";
        unitDetailsTarget = "unitDetailsIndex";
    }

    // copy icons
    // copyResource(imageDir, RESOURCE_PATH_ICONS, iconFileType);
    if (isAudioSOM) {
        FileUtils.copyResource(imageDir, RESOURCE_PATH_ICONS, "play.png");
        FileUtils.copyResource(imageDir, RESOURCE_PATH_ICONS, "download.gif");
        FileUtils.copyResource(detailsDir, RESOURCE_PATH_ICONS, "rp_horizontal_scale.gif");
        FileUtils.copyResource(detailsDir, RESOURCE_PATH_ICONS, "rp_vertical_scale.gif");
    }

    // copy HTML style sheets & templates
    if (htmlTemplatesDir == null) {
        htmlTemplatesDir = ExportUtils.class.getResource(RESOURCE_PATH_CSS).getFile();// + RESOURCE_PATH_CSS;
    }
    if (!htmlTemplatesDir.endsWith(File.separator)) {
        htmlTemplatesDir += File.separator;
    }
    FileUtils.copyFileSafe(imageMapDir + "style.css", htmlTemplatesDir + "style.css");
    FileUtils.copyFileSafe(detailsDir + "styleUnitDetails.css", htmlTemplatesDir + "styleUnitDetails.css");
    FileUtils.copyResource(detailsDir, RESOURCE_PATH_XHTML, "UnitDetails_empty.html");

    try {
        XHTML_FRAMESET = FileUtils.readFromFile(RESOURCE_PATH_XHTML, "Frameset.html");
        XHTML_FRAMESET_INDEXFRAME = FileUtils.readFromFile(RESOURCE_PATH_XHTML, "IndexFrame.html");
        XHTML_FRAMESET_UNITDETAILS = FileUtils.readFromFile(RESOURCE_PATH_XHTML,
                "UnitDetailsContentFrame.html");
        IMAGE_MAP_PAGE = FileUtils.readFromFile(RESOURCE_PATH_XHTML, "ImageMap.html");
        VISNAV_PAGE = FileUtils.readFromFile(RESOURCE_PATH_XHTML, "VisualisationSelection.html");
        if (isAudioSOM && generateRhythmPatterns) {
            UNIT_DETAIL_PAGE = FileUtils.readFromFile(RESOURCE_PATH_XHTML, "UnitDetailsRhythmPattern.html");
        } else {
            UNIT_DETAIL_PAGE = FileUtils.readFromFile(RESOURCE_PATH_XHTML, "UnitDetails.html");
        }

        StringBuffer classLegend = new StringBuffer();
        if (classInfo != null) {
            classLegend.append("      <h3>Class Legend</h3>");
            classLegend.append("      <table>\n");
            String[] classNames = classInfo.classNames();
            for (int i = 0; i < classNames.length; i++) {
                if (i % 2 == 0) {
                    classLegend.append("        <tr>\n");
                }
                classLegend.append("          <td class=\"classLegend\" width=\"50%\">\n");
                classLegend.append("            <span style=\"background-color: rgb(" + colors[i].getRed() + ","
                        + colors[i].getGreen() + "," + colors[i].getBlue()
                        + ")\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;"
                        + StringUtils.beautifyForHTML(classNames[i]) + "\n");
                classLegend.append("          </td>\n");
                if (i % 2 == 1 || i + 1 == classNames.length) {
                    classLegend.append("        </tr>\n");
                }
            }
            classLegend.append("      </table>\n");
        }

        XHTML_FRAMESET_INDEXFRAME = XHTML_FRAMESET_INDEXFRAME
                .replaceAll("PLACEHOLDER_MAPINDEX", imageMapBaseName + "mapIndex.html")
                .replaceAll("PLACEHOLDER_TITLE", imageMapTitle);
        if (!isAudioSOM) { // we have a content frame on the right side
            XHTML_FRAMESET_INDEXFRAME = XHTML_FRAMESET_INDEXFRAME.replaceAll("PLACEHOLDER_DETAIL_FILE",
                    imageMapBaseName + "unitDetailsContentFrame.html");
        }

        // the visualisation links
        if (visualisations != null && visualisations.length > 0) {
            ArrayList<String[]> realVis = new ArrayList<String[]>();
            StringBuffer mapNavigation = new StringBuffer();
            for (String[] visualisation : visualisations) {
                if (visualisation[0].equals("SPACER")) {
                    mapNavigation.append("  " + visualisation[1] + "\n");
                } else {
                    mapNavigation.append("  <a href=\"" + visualisation[0] + ".html"
                            + "\" target=\"map\" class=\"visualisationLink\" id=\"" + visualisation[0]
                            + "\" name=\"visLink\" onclick=\"javascript:selectVis('" + visualisation[0]
                            + "')\">" + visualisation[1] + "</a>\n");
                    realVis.add(visualisation);
                }
            }
            visualisations = new String[realVis.size()][2];
            for (int i = 0; i < visualisations.length; i++) {
                visualisations[i] = realVis.get(i);
            }
            FileUtils.writeFile(imageMapDir + "mapNavigation.html",
                    VISNAV_PAGE.replaceAll("PLACE_HOLDER_VISUALISATION_LINKS", mapNavigation.toString())
                            .replaceAll("PLACE_HOLDER_DEFAULT_VIS",
                                    visualisations[visualisations.length - 1][0]));

            // the main frameset index, dividing into map & navigtation frame and details frame
            StringBuffer map = new StringBuffer();
            map.append("<frame src=\"" + visualisations[visualisations.length - 1][0]
                    + ".html\" name=\"map\" noresize=\"noresize\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" />\n");
            map.append(
                    "<frame src=\"mapNavigation.html\" name=\"mapNavigation\" noresize=\"noresize\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" />\n");
            FileUtils.writeFile(imageMapDir + "mapIndex.html",
                    XHTML_FRAMESET.replaceAll("PLACEHOLDER_TITLE", imageMapTitle)
                            .replaceAll("PLACE_HOLDER_FRAME_LAYOUT", "rows=\"*, 32\"")
                            .replaceAll("PLACEHOLDER_FRAMES", map.toString()));
        }

        boolean firstUnit = true;
        boolean firstDataItem = true;

        StringBuffer imageMap = new StringBuffer();
        for (int x = 0; x < layer.getXSize(); x++) {
            for (int y = 0; y < layer.getYSize(); y++) {
                Unit unit = layer.getUnit(x, y);
                if (unit != null) {
                    if (firstUnit) {
                        firstUnit = false;
                        if (isAudioSOM) {
                            XHTML_FRAMESET_INDEXFRAME = XHTML_FRAMESET_INDEXFRAME
                                    .replaceAll("PLACEHOLDER_DETAIL_FILE",
                                            detailsDirRelative + "unit_" + x + "_" + y + ".html")
                                    .replaceAll("PLACEHOLDER_TITLE", imageMapTitle);
                        } else {
                            XHTML_FRAMESET_UNITDETAILS = XHTML_FRAMESET_UNITDETAILS.replaceAll(
                                    "PLACEHOLDER_SOURCE_UNITDETAILS",
                                    "../" + detailsDirRelative + "unit_" + x + "_" + y + ".html");
                        }
                    }
                    String coordinates = x * unitWidth + "," + y * unitWidth + " " + (x + 1) * unitWidth + ","
                            + (y + 1) * unitWidth;
                    String[] mappedData = unit.getMappedInputNames();
                    Label[] labels = unit.getLabels();
                    boolean hasLabels = !isAudioSOM && labels != null && labels.length > 0;
                    if (mappedData != null) {
                        imageMap.append("  <area shape=\"rect\" href=\"../" + detailsDirRelative + "unit_" + x
                                + "_" + y + ".html" + "\" target=\"" + unitDetailsTarget + "\"");
                        imageMap.append("coords=\"" + coordinates + "\" title=\"");

                        StringBuffer unitDetails = new StringBuffer();
                        String playListLink = "";
                        String playList = "";
                        for (int i = 0; i < mappedData.length; i++) {
                            String dataName = mappedData[i];

                            // in an audio SOM we don't have labels - we just use the data names as tooltip pop-up
                            if (!hasLabels) {
                                if (cleanDataNamesMapping != null) {
                                    dataName = cleanDataNamesMapping.getProperty(dataName, dataName);
                                } else {
                                    dataName = dataName.substring(dataName.lastIndexOf("/") + 1)
                                            .replaceAll(".mp3", "").replaceAll("_", " ");
                                }
                                imageMap.append(dataName);
                                if (i + 1 < mappedData.length) {
                                    imageMap.append(DATA_ITEM_SEPERATOR);
                                }
                            }

                            if (classInfo != null) {
                                int classNr = classInfo.getClassIndex(mappedData[i]);
                                if (classNr != -1) {
                                    Color c = colors[classNr];
                                    String dataItemDetails = "      <span title=\""
                                            + classInfo.classNames()[classNr]
                                            + "\" style=\"background-color: rgb(" + c.getRed() + ","
                                            + c.getGreen() + "," + c.getBlue()
                                            + ")\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;";
                                    unitDetails.append(dataItemDetails);
                                }
                            }

                            String filePath = inputDataFilesPrefix + File.separator + mappedData[i];
                            boolean haveFile = new File(filePath).exists();
                            // add iconFileType
                            // if (haveFile || forceLinkGeneration) {
                            // unitDetails.append("<img src=\"" + imageDirRelative + iconFileType +
                            // "\" height=\"12\" border=\"0\" />&nbsp;");
                            // }
                            unitDetails.append(dataName);
                            if (haveFile || forceLinkGeneration) {
                                if (isAudioSOM) { // generate playlist
                                    // add iconFileType
                                    unitDetails.append("<img src=\"" + imageDirRelative + iconFileType
                                            + "\" height=\"12\" border=\"0\" />&nbsp;");

                                    new File((playlistDir + mappedData[i]).substring(0,
                                            (playlistDir + mappedData[i]).lastIndexOf(File.separator)))
                                                    .mkdirs();

                                    String mediaLocation;
                                    if (outputDataFilesPrefix != null) {
                                        if (FileUtils.isURL(outputDataFilesPrefix)) {
                                            mediaLocation = outputDataFilesPrefix + File.separator
                                                    + StringUtils.URLencode(mappedData[i]);
                                        } else {
                                            mediaLocation = outputDataFilesPrefix + File.separator
                                                    + mappedData[i];
                                            // + playlistDirRelative + mappedData[i];
                                        }
                                    } else {
                                        mediaLocation = mappedData[i]
                                                .substring(mappedData[i].lastIndexOf(File.separator) + 1);
                                    }

                                    String playListName = mappedData[i].substring(0, mappedData[i].length() - 4)
                                            + ".m3u";
                                    FileWriter playlistFileOut = new FileWriter(playlistDir + playListName);

                                    playlistFileOut.write(mediaLocation + "\n");
                                    playList += mediaLocation + "\n";
                                    playlistFileOut.close();
                                    unitDetails.append("&nbsp;&nbsp; ");
                                    unitDetails.append("<a href=\"../" + playlistDirRelative + playListName
                                            + "\" title=\"Play as m3u stream\" target=\"_download\">[<img src=\""
                                            + imageDirRelative
                                            + "play.png\" height=\"12\" border=\"0\" >stream]</a>");
                                    unitDetails.append("&nbsp; ");
                                    unitDetails.append("<a href=\"" + mediaLocation
                                            + "\" title=\"Download as MP3\" target=\"_download\">[<img src=\""
                                            + imageDirRelative
                                            + "download.gif\" height=\"12\" border=\"0\" >mp3]</a>");
                                } else { // just add link to view content in browser
                                    unitDetails.append("&nbsp;&nbsp; ");
                                    String dataLink = outputDataFilesPrefix + File.separator + mappedData[i];
                                    if (new File(absolutePath + File.separator + dataLink + ".html").exists()) {
                                        dataLink += ".html";
                                    }
                                    unitDetails.append("<a href=\"../" + dataLink
                                            + "\" target=\"contentDetails\" title=\"View\">[");
                                    // add iconFileType
                                    // unitDetails.append("<img src=\"" + imageDirRelative + iconFileType +
                                    // "\" height=\"12\" border=\"0\" >");
                                    unitDetails.append("view]</a>");
                                    if (firstDataItem) {
                                        firstDataItem = false;
                                        XHTML_FRAMESET_UNITDETAILS = XHTML_FRAMESET_UNITDETAILS.replaceAll(
                                                "PLACEHOLDER_SOURCE_CONTENTFILE",
                                                detailsDirRelative + "UnitDetails_empty.html");
                                        // "../" + dataLink);
                                    }
                                }
                            }
                            unitDetails.append("\n      <br/>\n");
                        }
                        // we have a SOM with labels
                        if (hasLabels) {
                            for (int i = 0; i < labels.length; i++) {
                                imageMap.append(labels[i].getName());
                                if (i + 1 < labels.length) {
                                    imageMap.append(DATA_ITEM_SEPERATOR);
                                }
                            }
                        }
                        imageMap.append("\" />\n");

                        if (playList.trim().length() > 0) {
                            String playListName = "unit_" + x + "_" + y + ".m3u";
                            FileWriter playlistUnitFileOut = new FileWriter(playlistDir + playListName);
                            playlistUnitFileOut.write(playList);
                            playlistUnitFileOut.close();
                            playListLink = "<a href=\"../" + playlistDirRelative + playListName
                                    + "\" title=\"Play all songs on this unit\" target=\"_download\">[<img src=\""
                                    + imageDirRelative + "play.png\" height=\"12\" border=\"0\" >play all]</a>";
                        }

                        String unitDetail = UNIT_DETAIL_PAGE
                                .replaceAll("PLACEHOLDER_UNIT_DETAILS", unitDetails.toString())
                                .replaceAll("PLACEHOLDER_UNIT_ID", x + "/" + y)
                                .replaceAll("PLACEHOLDER_PLAYLIST", playListLink);
                        unitDetail = unitDetail.replaceAll("PLACEHOLDER_CLASS_LEGEND", classLegend.toString());
                        if (isAudioSOM) {
                            if (generateRhythmPatterns) {
                                unitDetail = unitDetail.replaceAll("PLACEHOLDER_RP_IMAGE",
                                        "rp_" + x + "_" + y + ".jpg");
                                // TODO be careful: RP dimensions hardcoded again!
                                FileUtils.saveImageToFile(detailsDir + "rp_" + x + "_" + y + ".jpg",
                                        new RhythmPattern(layer.getUnit(x, y).getWeightVector(), 60, 24)
                                                .getImage());
                            }
                        }
                        FileUtils.writeFile(detailsDir + "unit_" + x + "_" + y + ".html", unitDetail);
                    }
                }
            }
        }

        FileUtils.writeFile(fullPath + "_index.html", XHTML_FRAMESET_INDEXFRAME);

        if (imageMapTitle == null) {
            imageMapTitle = "";
        } else {
            imageMapTitle = "<h2>" + imageMapTitle + "</h2>";
        }
        String imageMapPage = IMAGE_MAP_PAGE.replaceAll("PLACEHOLDER_MAP_AREAS", imageMap.toString())
                .replaceAll("PLACEHOLDER_IMAGE_MAP_TITLE", imageMapTitle);
        for (int i = 0; i < visualisations.length; i++) {
            if (!visualisations[i][0].equals("SPACER")) {
                FileUtils.writeFile(imageMapDir + visualisations[i][0] + ".html",
                        imageMapPage
                                .replaceAll("PLACE_HOLDER_MAP_IMAGE",
                                        imageDirRelative + visualisations[i][0] + ".png")
                                .replaceAll("PLACEHOLDER_TITLE", "Play-SOM - " + visualisations[i][0]));
            }
        }
        if (!isAudioSOM) {
            // the unit details frame on the right side
            FileUtils.writeFile(imageMapDir + "unitDetailsContentFrame.html", XHTML_FRAMESET_UNITDETAILS);
        }
    } catch (FileNotFoundException e) {
        throw new SOMToolboxException(e.getMessage());
    } catch (IOException e) {
        throw new SOMToolboxException(e.getMessage());
    }
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

protected final static void setBackground(Component c, NuclosScript ns, final Collectable clct,
        EntityMetaDataVO meta, boolean isEnabled) {
    try {/*from w  w  w. j  a  v a 2 s  .  c  o m*/
        String rgb = Integer.toHexString(c.getBackground().getRGB());
        rgb = rgb.substring(2, rgb.length());
        Object o = ScriptEvaluator.getInstance().eval(ns, new CollectableScriptContext(clct), "#" + rgb);

        if (o instanceof String) {
            Color color = Color.decode((String) o);
            if (isEnabled) {
                c.setBackground(color);
            } else {
                c.setBackground(new Color(Math.max(0, color.getRed() - (color.getRed() * 15 / 100)),
                        Math.max(0, color.getGreen() - (color.getGreen() * 15 / 100)),
                        Math.max(0, color.getBlue() - (color.getBlue() * 15 / 100))));
            }
        }
    } catch (Exception ex) {
        LOG.warn(ex);
    }
}