List of usage examples for java.awt Color getRed
public int getRed()
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Internal implementation to add a sunburst chart (actually a doughnut chart) to a slide, based on a template. * @param template the parsed template information. * @param slide the slide to add to.// ww w .ja va 2s .c o m * @param anchor optional bounding rectangle to draw onto, in PowerPoint coordinates. * If null, we'll use the bounds from the original template chart. * @param data the sunburst data. * @param shapeId the slide shape ID, should be unique within the slide. * @param relId the relation ID to the chart data. * @throws TemplateLoadException if we can't create the sunburst; most likely due to an invalid template. */ private static void addSunburst(final SlideShowTemplate template, final XSLFSlide slide, final Rectangle2D.Double anchor, final SunburstData data, final int shapeId, final String relId) throws TemplateLoadException { final String[] categories = data.getCategories(); final double[] values = data.getValues(); final String title = data.getTitle(); slide.getXmlObject().getCSld().getSpTree().addNewGraphicFrame() .set(template.getDoughnutChartShapeXML(relId, shapeId, "chart" + shapeId, anchor)); final XSSFWorkbook workbook = new XSSFWorkbook(); final XSSFSheet sheet = workbook.createSheet(); final XSLFChart baseChart = template.getDoughnutChart(); final CTChartSpace chartSpace = (CTChartSpace) baseChart.getCTChartSpace().copy(); final CTChart ctChart = chartSpace.getChart(); final CTPlotArea plotArea = ctChart.getPlotArea(); if (StringUtils.isEmpty(title)) { if (ctChart.getAutoTitleDeleted() != null) { ctChart.getAutoTitleDeleted().setVal(true); } ctChart.unsetTitle(); } final CTDoughnutChart donutChart = plotArea.getDoughnutChartArray(0); final CTPieSer series = donutChart.getSerArray(0); final CTStrRef strRef = series.getTx().getStrRef(); strRef.getStrCache().getPtArray(0).setV(title); sheet.createRow(0).createCell(1).setCellValue(title); strRef.setF(new CellReference(sheet.getSheetName(), 0, 1, true, true).formatAsString()); final CTStrRef categoryRef = series.getCat().getStrRef(); final CTStrData categoryData = categoryRef.getStrCache(); final CTNumRef numRef = series.getVal().getNumRef(); final CTNumData numericData = numRef.getNumCache(); final String[] fillColors = data.getColors(); final String[] strokeColors = data.getStrokeColors(); final boolean overrideFill = ArrayUtils.isNotEmpty(fillColors); final boolean overrideStroke = ArrayUtils.isNotEmpty(strokeColors); final boolean overrideColors = overrideFill || overrideStroke; final List<CTDPt> dPtList = series.getDPtList(); final CTDPt templatePt = (CTDPt) dPtList.get(0).copy(); if (overrideColors) { dPtList.clear(); final CTShapeProperties spPr = templatePt.getSpPr(); final CTLineProperties ln = spPr.getLn(); // We need to unset any styles on the existing template if (overrideFill) { unsetSpPrFills(spPr); } if (overrideStroke) { unsetLineFills(ln); } } categoryData.setPtArray(null); numericData.setPtArray(null); CTLegend legend = null; final int[] showInLegend = data.getShowInLegend(); int nextLegendToShow = 0, nextLegendToShowIdx = -1; if (showInLegend != null) { // We need to write legendEntry elements to hide the legend for chart series we don't want. // Note this only works in PowerPoint, and not OpenOffice. legend = ctChart.isSetLegend() ? ctChart.getLegend() : ctChart.addNewLegend(); Arrays.sort(showInLegend); nextLegendToShow = showInLegend[++nextLegendToShowIdx]; } for (int idx = 0; idx < values.length; ++idx) { final CTStrVal categoryPoint = categoryData.addNewPt(); categoryPoint.setIdx(idx); categoryPoint.setV(categories[idx]); final CTNumVal numericPoint = numericData.addNewPt(); numericPoint.setIdx(idx); numericPoint.setV(Double.toString(values[idx])); if (overrideColors) { final CTDPt copiedPt = (CTDPt) templatePt.copy(); copiedPt.getIdx().setVal(idx); if (overrideFill) { final Color color = Color.decode(fillColors[idx % fillColors.length]); final CTSolidColorFillProperties fillClr = copiedPt.getSpPr().addNewSolidFill(); fillClr.addNewSrgbClr().setVal( new byte[] { (byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue() }); } if (overrideStroke) { final Color strokeColor = Color.decode(strokeColors[idx % strokeColors.length]); final CTSolidColorFillProperties strokeClr = copiedPt.getSpPr().getLn().addNewSolidFill(); strokeClr.addNewSrgbClr().setVal(new byte[] { (byte) strokeColor.getRed(), (byte) strokeColor.getGreen(), (byte) strokeColor.getBlue() }); } dPtList.add(copiedPt); } if (legend != null) { // We're hiding some legend elements. Should we show this index? if (nextLegendToShow == idx) { // We show this index, find the next one to show. ++nextLegendToShowIdx; if (nextLegendToShowIdx < showInLegend.length) { nextLegendToShow = showInLegend[nextLegendToShowIdx]; } } else { // We hide this index. If there's already a matching legend entry in the XML, update it, // otherwise we create a new legend entry. boolean found = false; for (int ii = 0, max = legend.sizeOfLegendEntryArray(); ii < max; ++ii) { final CTLegendEntry legendEntry = legend.getLegendEntryArray(ii); final CTUnsignedInt idxLegend = legendEntry.getIdx(); if (idxLegend != null && idxLegend.getVal() == idx) { found = true; if (legendEntry.isSetDelete()) { legendEntry.getDelete().setVal(true); } else { legendEntry.addNewDelete().setVal(true); } } } if (!found) { final CTLegendEntry idxLegend = legend.addNewLegendEntry(); idxLegend.addNewIdx().setVal(idx); idxLegend.addNewDelete().setVal(true); } } } XSSFRow row = sheet.createRow(idx + 1); row.createCell(0).setCellValue(categories[idx]); row.createCell(1).setCellValue(values[idx]); } categoryData.getPtCount().setVal(categories.length); numericData.getPtCount().setVal(values.length); categoryRef.setF(new CellRangeAddress(1, values.length, 0, 0).formatAsString(sheet.getSheetName(), true)); numRef.setF(new CellRangeAddress(1, values.length, 1, 1).formatAsString(sheet.getSheetName(), true)); try { writeChart(template.getSlideShow(), slide, baseChart, chartSpace, workbook, relId); } catch (IOException | InvalidFormatException e) { throw new TemplateLoadException("Error writing chart in loaded template", e); } }
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)); }/*from ww w . ja v a 2 s. com*/ } 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:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java
/** * Builds the "more" panel.//ww w . j a va 2s. co m * */ protected void buildMorePanel() { FormLayout formLayout = new FormLayout("15px,0px,p", "p"); PanelBuilder builder = new PanelBuilder(formLayout); CellConstraints cc = new CellConstraints(); moreBtn = createButton( String.format(getResourceString("MoreEntries"), new Object[] { (rowCount - topNumEntries) }));//(rowCount - topNumEntries)+" more..."); moreBtn.setCursor(handCursor); moreBtn.setBorderPainted(false); builder.add(createLabel(" "), cc.xy(1, 1)); builder.add(moreBtn, cc.xy(3, 1)); morePanel = builder.getPanel(); Color bgColor = table.getBackground(); bgColor = new Color(Math.max(bgColor.getRed() - 10, 0), Math.max(bgColor.getGreen() - 10, 0), Math.max(bgColor.getBlue() - 10, 0)); Color fgColor = new Color(Math.min(bannerColor.getRed() + 10, 255), Math.min(bannerColor.getGreen() + 10, 255), Math.min(bannerColor.getBlue() + 10, 255)); morePanel.setBackground(bgColor); moreBtn.setBackground(bgColor); moreBtn.setForeground(fgColor); add(builder.getPanel(), BorderLayout.SOUTH); moreBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { morePanel.setVisible(false); showTopNumEntriesBtn.setVisible(true); showingAllRows = true; setDisplayRows(rowCount, Integer.MAX_VALUE); esrPane.revalidateScroll(); } }); morePanel.setVisible(false); }
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:com.dlya.facturews.DlyaPdfExporter2.java
/** * *///from ww w .j a v 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:com.chart.SwingChart.java
/** * // w ww. ja va 2 s .co 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: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 w w . ja v a 2 s . c om*/ 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: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 . j a v a 2s .c o m 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() + ")\"> </span> " + 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() + ")\"> </span> "; 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\" /> "); // } unitDetails.append(dataName); if (haveFile || forceLinkGeneration) { if (isAudioSOM) { // generate playlist // add iconFileType unitDetails.append("<img src=\"" + imageDirRelative + iconFileType + "\" height=\"12\" border=\"0\" /> "); 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(" "); 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(" "); 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(" "); 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 ww . 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); } }
From source file:savant.view.tracks.BAMTrackRenderer.java
private Color makeTransparent(Color c) { return new Color(c.getRed(), c.getGreen(), c.getBlue(), 90); }