List of usage examples for java.awt Color HSBtoRGB
public static int HSBtoRGB(float hue, float saturation, float brightness)
From source file:net.sf.maltcms.chromaui.foldChangeViewer.tasks.FoldChangeViewLoaderWorker.java
@Override public void run() { ProgressHandle handle = ProgressHandleFactory.createHandle("Creating fold change plot"); try {/*from w w w . j av a2 s.c o m*/ handle.setDisplayName("Loading fold change elements");//+new File(this.files.getResourceLocation()).getName()); handle.start(5); handle.progress("Reading settings", 1); RTUnit rtAxisUnit = RTUnit.valueOf(sp.getProperty("rtAxisUnit", "SECONDS")); handle.progress("Retrieving data", 2); XYShapeRenderer renderer = new XYShapeRenderer() { @Override protected Paint getPaint(XYDataset dataset, int series, int item) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Math.abs(x) < 1.0) { Paint p = super.getPaint(dataset, series, item); if (p instanceof Color) { Color color = (Color) p; float[] values = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]); Color hsb = new Color( Color.HSBtoRGB(values[0], (float) Math.max(0.1, values[1] - 0.9), values[2])); return new Color(hsb.getRed(), hsb.getGreen(), hsb.getBlue(), 64); } } return super.getPaint(dataset, series, item); } }; renderer.setAutoPopulateSeriesFillPaint(true); renderer.setAutoPopulateSeriesOutlinePaint(true); renderer.setBaseCreateEntities(true); handle.progress("Building plot", 3); XYPlot plot = new XYPlot(dataset, new NumberAxis("log2 fold change"), new NumberAxis("-log10 p-value"), renderer); BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, new float[] { 5.0f }, 0.0f); ValueMarker marker = new ValueMarker(-Math.log10(0.05), Color.RED, dashed); marker.setLabel("p-value=0.05"); marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); marker.setLabelOffset(new RectangleInsets(UnitType.ABSOLUTE, 0, 50, 10, 0)); marker.setLabelOffsetType(LengthAdjustmentType.EXPAND); marker.setLabelPaint(Color.LIGHT_GRAY); plot.addRangeMarker(marker); Font font1 = new Font("SansSerif", Font.PLAIN, 12); SelectionAwareXYTooltipGenerator tooltipGenerator = cvtc.getLookup() .lookup(SelectionAwareXYTooltipGenerator.class); if (tooltipGenerator == null) { tooltipGenerator = new SelectionAwareXYTooltipGenerator(tooltipGenerator) { @Override public String createSelectionAwareTooltip(XYDataset xyd, int i, int i1) { FoldChangeDataset dataset = (FoldChangeDataset) xyd; FoldChangeElement fce = dataset.getNamedElementProvider().get(i).get(i1); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(fce.getPeakGroup().getMajorityDisplayName()); sb.append("<br>"); sb.append("log2 fold change="); sb.append(fce.getFoldChange()); sb.append("<br>"); sb.append("p-value="); sb.append(Math.pow(10, -fce.getPvalue())); sb.append("</html>"); return sb.toString(); } }; } tooltipGenerator.setXYToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Comparable comp = xyd.getSeriesKey(i); double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(comp); sb.append("<br>"); sb.append("log2 fold change="); sb.append(x); sb.append("<br>"); sb.append("p-value="); sb.append(sb.append(Math.pow(10, -y))); sb.append("</html>"); return sb.toString(); } }); plot.getRenderer().setBaseToolTipGenerator(tooltipGenerator); handle.progress("Configuring plot", 4); configurePlot(plot, rtAxisUnit); final FoldChangeViewPanel cmhp = cvtc.getLookup().lookup(FoldChangeViewPanel.class); Range domainRange = null; Range valueRange = null; if (cmhp != null) { XYPlot xyplot = cmhp.getPlot(); if (xyplot != null) { ValueAxis domain = xyplot.getDomainAxis(); domainRange = domain.getRange(); ValueAxis range = xyplot.getRangeAxis(); valueRange = range.getRange(); } } if (domainRange != null) { plot.getDomainAxis().setRange(domainRange); } if (valueRange != null) { Logger.getLogger(getClass().getName()).info("Setting previous value range!"); } handle.progress("Adding plot to panel", 5); final XYPlot targetPlot = plot; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final FoldChangeViewPanel cmhp = cvtc.getLookup().lookup(FoldChangeViewPanel.class); cmhp.setPlot(targetPlot); cvtc.requestActive(); } }); } finally { handle.finish(); } }
From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java
private static int getNewPixelRGB(int replacement, int destRGB) { float[] destHSB = getHSBArray(destRGB); float[] replHSB = getHSBArray(replacement); int rgbnew = Color.HSBtoRGB(replHSB[HUE], replHSB[SATURATION], destHSB[BRIGHTNESS]); return rgbnew; }
From source file:uk.bl.wa.tika.parser.imagefeatures.FaceDetectionParser.java
private static Color maxBrightness(Color c) { float[] hsv = new float[3]; Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsv); return new Color(Color.HSBtoRGB(hsv[0], hsv[1], 1.0f)); }
From source file:org.polymap.rhei.batik.engine.svg.Svg2Png.java
private static BufferedImage shiftHue(BufferedImage img, ImageConfiguration imageConfiguration) { int height = img.getHeight(); int width = img.getWidth(); int imageType = 0; if (imageConfiguration.getColorType() == COLOR_TYPE.MONOCHROM) { imageType = BufferedImage.TYPE_BYTE_BINARY; } else if (imageConfiguration.getColorType() == COLOR_TYPE.GRAY) { imageType = BufferedImage.TYPE_BYTE_GRAY; } else if (imageConfiguration.getColorType() == COLOR_TYPE.RGB) { imageType = BufferedImage.TYPE_INT_RGB; } else {/* www .j ava 2 s .c om*/ imageType = BufferedImage.TYPE_INT_ARGB; } BufferedImage finalThresholdImage = new BufferedImage(width, height, imageType); Float hueDelta = null; Float saturationDelta = null; Float brightnessDelta = null; if (imageConfiguration.getRgb() != null) { hueDelta = degreeToPercent(imageConfiguration.getRgb().getHSB()[0]); saturationDelta = imageConfiguration.getRgb().getHSB()[1]; brightnessDelta = imageConfiguration.getRgb().getHSB()[2]; } else { hueDelta = imageConfiguration.getAdjHue(); saturationDelta = imageConfiguration.getAdjSaturation(); brightnessDelta = imageConfiguration.getAdjBrightness(); } if (hueDelta == null) { hueDelta = 0f; } if (saturationDelta == null) { saturationDelta = 0f; } if (brightnessDelta == null) { brightnessDelta = 0f; } for (int x = 0; x < width; x++) { try { for (int y = 0; y < height; y++) { int rgb = img.getRGB(x, y); Color color = new Color(rgb); float[] hsb = getHsb(imageConfiguration, color); hsb = applyDeltas(imageConfiguration, hueDelta, saturationDelta, brightnessDelta, hsb); hsb = replaceColors(imageConfiguration, color, hsb); int newRGB = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]); finalThresholdImage.setRGB(x, y, newRGB); if (imageType == BufferedImage.TYPE_INT_ARGB) { setAlpha(finalThresholdImage, x, y, rgb); finalThresholdImage = makeColorsTransparent(finalThresholdImage, imageConfiguration, new Color(newRGB)); } } } catch (Exception e) { e.getMessage(); } } return finalThresholdImage; }
From source file:hudson.plugins.plot.PlotData.java
/** * Generates the plot and stores it in the plot instance variable. * // w w w . j av a2 s .c o m * @param forceGenerate if true, force the plot to be re-generated * even if the on-disk data hasn't changed */ private void generatePlot(boolean forceGenerate) { class Label implements Comparable<Label> { final private Integer buildNum; final private String buildDate; final private String text; public Label(String buildNum, String buildTime, String text) { this.buildNum = Integer.parseInt(buildNum); synchronized (DATE_FORMAT) { this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime))); } this.text = text; } public int compareTo(Label that) { return this.buildNum - that.buildNum; } @Override public boolean equals(Object o) { return o instanceof Label && ((Label) o).buildNum.equals(buildNum); } @Override public int hashCode() { return buildNum.hashCode(); } public String numDateString() { return "#" + buildNum + " (" + buildDate + ")"; } @Override public String toString() { return text != null ? text : numDateString(); } } LOGGER.fine("Generating plot from file: " + csvFilePath.getName()); PlotCategoryDataset dataset = new PlotCategoryDataset(); for (String[] record : rawPlotData) { // record: series y-value, series label, build number, build date, url int buildNum; try { buildNum = Integer.valueOf(record[2]); if (project.getBuildByNumber(buildNum) == null || buildNum > getRightBuildNum()) { continue; // skip this record } } catch (NumberFormatException nfe) { continue; // skip this record all together } Number value = null; try { value = Integer.valueOf(record[0]); } catch (NumberFormatException nfe) { try { value = Double.valueOf(record[0]); } catch (NumberFormatException nfe2) { continue; // skip this record all together } } String series = record[1]; Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum)) : new Label(record[2], record[3], getBuildName(buildNum)); String url = null; if (record.length >= 5) url = record[4]; dataset.setValue(value, url, series, xlabel); } int numBuilds; try { numBuilds = Integer.parseInt(getURLNumBuilds()); } catch (NumberFormatException nfe) { numBuilds = DEFAULT_NUMBUILDS; } dataset.clipDataset(numBuilds); plot = createChart(dataset); CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot(); categoryPlot.setDomainGridlinePaint(Color.black); categoryPlot.setRangeGridlinePaint(Color.black); categoryPlot.setDrawingSupplier(PlotData.supplier); CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build()); categoryPlot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.03); domainAxis.setCategoryMargin(0.0); for (Object category : dataset.getColumnKeys()) { Label label = (Label) category; if (label.text != null) { domainAxis.addCategoryLabelToolTip(label, label.numDateString()); } else { domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum)); } } AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer(); int numColors = dataset.getRowCount(); for (int i = 0; i < numColors; i++) { renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f))); } renderer.setStroke(new BasicStroke(2.0f)); renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}", NumberFormat.getInstance())); renderer.setItemURLGenerator(new PointURLGenerator()); if (renderer instanceof LineAndShapeRenderer) { LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer; lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary } }
From source file:hudson.plugins.plot.Plot.java
/** * Generates the plot and stores it in the plot instance variable. * * @param forceGenerate/*w w w . j a v a2s . co m*/ * if true, force the plot to be re-generated even if the on-disk * data hasn't changed */ private void generatePlot(boolean forceGenerate) { class Label implements Comparable<Label> { final private Integer buildNum; final private String buildDate; final private String text; public Label(String buildNum, String buildTime, String text) { this.buildNum = Integer.parseInt(buildNum); synchronized (DATE_FORMAT) { this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime))); } this.text = text; } public Label(String buildNum, String buildTime) { this(buildNum, buildTime, null); } public int compareTo(Label that) { return this.buildNum - that.buildNum; } @Override public boolean equals(Object o) { return o instanceof Label && ((Label) o).buildNum.equals(buildNum); } @Override public int hashCode() { return buildNum.hashCode(); } public String numDateString() { return "#" + buildNum + " (" + buildDate + ")"; } @Override public String toString() { return text != null ? text : numDateString(); } } // LOGGER.info("Determining if we should generate plot " + // getCsvFileName()); File csvFile = new File(project.getRootDir(), getCsvFileName()); if (csvFile.lastModified() == csvLastModification && plot != null && !forceGenerate) { // data hasn't changed so don't regenerate the plot return; } if (rawPlotData == null || csvFile.lastModified() > csvLastModification) { // data has changed or has not been loaded so load it now loadPlotData(); } // LOGGER.info("Generating plot " + getCsvFileName()); csvLastModification = csvFile.lastModified(); PlotCategoryDataset dataset = new PlotCategoryDataset(); for (String[] record : rawPlotData) { // record: series y-value, series label, build number, build date, // url int buildNum; try { buildNum = Integer.valueOf(record[2]); if (!reportBuild(buildNum) || buildNum > getRightBuildNum()) { continue; // skip this record } } catch (NumberFormatException nfe) { LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe); continue; // skip this record all together } Number value = null; try { value = Integer.valueOf(record[0]); } catch (NumberFormatException nfe) { try { value = Double.valueOf(record[0]); } catch (NumberFormatException nfe2) { LOGGER.log(Level.SEVERE, "Exception converting to number", nfe2); continue; // skip this record all together } } String series = record[1]; Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum)) : new Label(record[2], record[3]); String url = null; if (record.length >= 5) url = record[4]; dataset.setValue(value, url, series, xlabel); } String urlNumBuilds = getURLNumBuilds(); int numBuilds; if (StringUtils.isBlank(urlNumBuilds)) { numBuilds = Integer.MAX_VALUE; } else { try { numBuilds = Integer.parseInt(urlNumBuilds); } catch (NumberFormatException nfe) { LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe); numBuilds = Integer.MAX_VALUE; } } dataset.clipDataset(numBuilds); plot = createChart(dataset); CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot(); categoryPlot.setDomainGridlinePaint(Color.black); categoryPlot.setRangeGridlinePaint(Color.black); categoryPlot.setDrawingSupplier(Plot.supplier); CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build()); categoryPlot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.03); domainAxis.setCategoryMargin(0.0); for (Object category : dataset.getColumnKeys()) { Label label = (Label) category; if (label.text != null) { domainAxis.addCategoryLabelToolTip(label, label.numDateString()); } else { domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum)); } } // Replace the range axis by a logarithmic axis if the option is // selected if (isLogarithmic()) { LogarithmicAxis logAxis = new LogarithmicAxis(getYaxis()); logAxis.setExpTickLabelsFlag(true); categoryPlot.setRangeAxis(logAxis); } // optionally exclude zero as default y-axis value ValueAxis rangeAxis = categoryPlot.getRangeAxis(); if ((rangeAxis != null) && (rangeAxis instanceof NumberAxis)) { if (hasYaxisMinimum()) { ((NumberAxis) rangeAxis).setLowerBound(getYaxisMinimum()); } if (hasYaxisMaximum()) { ((NumberAxis) rangeAxis).setUpperBound(getYaxisMaximum()); } ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(!getExclZero()); } AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer(); int numColors = dataset.getRowCount(); for (int i = 0; i < numColors; i++) { renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f))); } renderer.setBaseStroke(new BasicStroke(2.0f)); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}", NumberFormat.getInstance())); renderer.setBaseItemURLGenerator(new PointURLGenerator()); if (renderer instanceof LineAndShapeRenderer) { String s = getUrlStyle(); LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer; if ("lineSimple".equalsIgnoreCase(s)) { lasRenderer.setShapesVisible(false); // TODO: deprecated, may be unnecessary } else { lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary } } }
From source file:de._13ducks.cor.graphics.GraphicsComponent.java
protected void calcColoredMaps(Color[] colors) { // Berechnet die eingefrbten Texturen, z.B. fr Gebude ArrayList<CoRImage> tList = new ArrayList<CoRImage>(); tList.addAll(coloredImgMap.values()); coloredImgMap.clear();/*from w w w .j a va 2 s .c o m*/ for (int i = 0; i < tList.size(); i++) { BufferedImage im = (BufferedImage) tList.get(i).getImage(); for (int playerId = 0; playerId < colors.length; playerId++) { BufferedImage preImg = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < im.getWidth(); x++) { for (int y = 0; y < im.getHeight(); y++) { // Das ganze Raster durchgehen und Farben ersetzen // Ersetzfarbe da? int rgb = im.getRGB(x, y); float[] col = Color.RGBtoHSB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff, null); if (col[0] >= 0.8583333f && col[0] <= 0.8666666f) { // Ja, ersetzen Color tc = colors[playerId]; int targetC = Color.HSBtoRGB( Color.RGBtoHSB(tc.getRed(), tc.getGreen(), tc.getBlue(), null)[0], 1.0f, col[2]); int a = (rgb >> 24) & 0xff; targetC = (targetC & (~(0xff << 24)) | (a << 24)); preImg.setRGB(x, y, targetC); } else { preImg.setRGB(x, y, im.getRGB(x, y)); } } } // Bild berechnet, einfgen CoRImage newImg = new CoRImage(preImg); newImg.setImageName(tList.get(i).getImageName()); coloredImgMap.put(newImg.getImageName() + playerId, newImg); } } }
From source file:self.philbrown.javaQuery.$.java
/** * Include the html string the selected views. If a view has a setText method, it is used. Otherwise, * a new TextView is created. This html can also handle image tags for both urls and local files. * Local files should be the name (for example, for R.id.ic_launcher, just use ic_launcher). * @param html the HTML String to include *///from w w w. j a v a 2 s . co m public $ html(String html) { for (Component view : this.views) { try { Method m = view.getClass().getMethod("setText", new Class<?>[] { String.class }); m.invoke(view, html); } catch (Throwable t) { if (view instanceof Container) { try { //no setText method. Try a TextView JLabel label = new JLabel(); int rgba = Color.HSBtoRGB(0, 0, 0); rgba |= (0 & 0xff); label.setBackground(new Color(rgba, true)); label.setBounds(label.getParent().getBounds()); ((Container) view).add(label); label.setText(html); } catch (Throwable t2) { //unable to set content Log.w("javaQuery", "unable to set HTML content"); } } else { //unable to set content Log.w("javaQuery", "unable to set textual content"); } } } return this; }
From source file:self.philbrown.javaQuery.$.java
/** * Includes the given text string inside of the selected views. If a view has a setText method, it is used * otherwise, if possible, a textview is added as a child to display the text. * @param text the text to include//from w ww . j a v a 2 s .c o m */ public $ text(String text) { for (Component view : this.views) { try { Method m = view.getClass().getMethod("setText", new Class<?>[] { String.class }); m.invoke(view, text); } catch (Throwable t) { if (view instanceof Container) { try { //no setText method. Try a TextView JLabel label = new JLabel(); int rgba = Color.HSBtoRGB(0, 0, 0); rgba |= (0 & 0xff); label.setBackground(new Color(rgba, true)); label.setBounds(label.getParent().getBounds()); ((Container) view).add(label); label.setText(text); } catch (Throwable t2) { //unable to set content Log.w("javaQuery", "unable to set textual content"); } } else { //unable to set content Log.w("javaQuery", "unable to set textual content"); } } } return this; }