List of usage examples for java.awt Color getRed
public int getRed()
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.PlateHeatMapController.java
/** * Plot the z-scores: simple scatterplot *///from w w w . j a va 2 s.co m private void plotZScores() { XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); Map<Well, Double> map = computeZScoresForMap(); List<PlateCondition> plateConditionList = trackCoordinatesController.getPlateConditionList(); for (int i = 0; i < plateConditionList.size(); i++) { // current condition PlateCondition condition = plateConditionList.get(i); XYSeries series = new XYSeries(i + "-" + condition); for (int j = 0; j < condition.getSingleCellAnalyzedWells().size(); j++) { // current well Well well = condition.getSingleCellAnalyzedWells().get(j); series.add(i + 1, map.get(well)); } xySeriesCollection.addSeries(series); } JFreeChart jfreechart = ChartFactory.createScatterPlot("z*-score", "condition number", "z*-score", xySeriesCollection, PlotOrientation.VERTICAL, false, true, false); JFreeChartUtils.setupXYPlot(jfreechart.getXYPlot()); jfreechart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // line for the median speed ValueMarker marker = new ValueMarker(0); marker.setPaint(Color.GRAY); Stroke dashedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 1.0f, 3.0f }, 0.0f); marker.setStroke(dashedStroke); jfreechart.getXYPlot().addRangeMarker(marker); marker = new ValueMarker(3); marker.setPaint(Color.GRAY); marker.setStroke(dashedStroke); jfreechart.getXYPlot().addRangeMarker(marker); marker = new ValueMarker(-3); marker.setPaint(Color.GRAY); marker.setStroke(dashedStroke); jfreechart.getXYPlot().addRangeMarker(marker); XYItemRenderer renderer = jfreechart.getXYPlot().getRenderer(); for (int i = 0; i < xySeriesCollection.getSeriesCount(); i++) { // plot lines according to conditions indexes int colorIndex = i % GuiUtils.getAvailableColors().length; Color color = GuiUtils.getAvailableColors()[colorIndex]; color = new Color(color.getRed(), color.getGreen(), color.getBlue(), 127); renderer.setSeriesPaint(i, color); renderer.setSeriesShape(i, new Ellipse2D.Double(0, 0, 10, 10)); } zScoreChartPanel.setChart(jfreechart); }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileChartPanelEditor.java
private Component createChartPanel() { depthSerie = new XYSeries("depth"); XYSeriesCollection depthCollection = new XYSeriesCollection(); depthCollection.addSeries(depthSerie); JFreeChart chart = ChartFactory.createXYLineChart("", I18nResourceManager.sharedInstance().getString("time"), I18nResourceManager.sharedInstance().getString("depth"), depthCollection, PlotOrientation.VERTICAL, true, true, false);/*from w w w.ja v a2 s. c o m*/ plot = chart.getXYPlot(); Paint p = new GradientPaint(0f, 0f, UIAgent.getInstance().getColorWaterBottom(), 200f, 200f, UIAgent.getInstance().getColorWaterSurface(), false); plot.setBackgroundPaint(p); XYAreaRenderer renderer0 = new XYAreaRenderer(); renderer0.setOutline(true); renderer0.setBaseOutlinePaint(UIAgent.getInstance().getColorProfileEdition()); Color baseColor = UIAgent.getInstance().getColorBaseBackground(); renderer0.setSeriesPaint(0, new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), 50)); plot.setRenderer(0, renderer0); dAxis = new NumberAxis(); rAxis = new NumberAxis(); // dAxis.setAutoRange(false); // rAxis.setAutoRange(false); // dAxis.setRange(0, maxTime); // rAxis.setRange(lowestDepth, 0); plot.setDomainAxis(dAxis); plot.setRangeAxis(rAxis); // plot.setRangeCrosshairLockedOnData(false); // plot.setDomainCrosshairLockedOnData(false); ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride(new MinutesNumberFormat()); panel = new ChartPanel(chart); // panel.addChartMouseListener(new ChartMouseListener() { // // @Override // public void chartMouseMoved(ChartMouseEvent arg0) { // // TODO Auto-generated method stub // // } // // @Override // public void chartMouseClicked(ChartMouseEvent evt) { // // double x = plot.getDomainAxis().java2DToValue( // panel.translateScreenToJava2D( // evt.getTrigger().getPoint()).getX(), // panel.getChartRenderingInfo().getPlotInfo() // .getDataArea(), plot.getDomainAxisEdge()); // // double y = plot.getRangeAxis().java2DToValue( // panel.translateScreenToJava2D( // evt.getTrigger().getPoint()).getY(), // panel.getChartRenderingInfo().getPlotInfo() // .getDataArea(), plot.getRangeAxisEdge()); // // diveProfileEditor.addEntry(x, y, this); // } // }); createDecoWarningCollection(); createAscentTooFastCollection(); createRemainBottomTimeCollection(); createDecoEntriesCollection(); return panel; }
From source file:nz.ac.massey.cs.gql4jung.browser.resultviews.GraphBasedResultView.java
private Map<String, Color> createColorMap(MotifInstance instance) { if (instance == null) return new HashMap<String, Color>(0); Set<Vertex> vertices = instance.getVertices(); Set<String> packages = new HashSet<String>(vertices.size()); for (Vertex v : vertices) { packages.add(v.getNamespace());/*from w ww . j a v a 2 s . c om*/ } int count = 0; Map<String, Color> pmap = new HashMap<String, Color>(packages.size()); float offset = 100 / packages.size(); offset = offset / 100; for (String p : packages) { Color hsb = Color.getHSBColor(count * offset, settings.getVertexSaturation(), settings.getVertexBrightness()); pmap.put(p, new Color(hsb.getRed(), hsb.getGreen(), hsb.getBlue(), settings.getVertexTransparency())); // transparency //pmap.put(p,hsb); count = count + 1; } return pmap; }
From source file:com.stitchgalaxy.domain.Product.java
/** * @param avgColor the avgColor to set//from w ww . j a v a 2 s . c o m */ public void setAvgColor(Color avgColor) { this.setAvgColorRed((Integer) avgColor.getRed()); this.setAvgColorGreen((Integer) avgColor.getGreen()); this.setAvgColorBlue((Integer) avgColor.getBlue()); }
From source file:com.db.comserv.main.utilities.HttpCaller.java
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DM_DEFAULT_ENCODING") public HttpResult runRequest(String type, String methodType, URL url, List<Map<String, String>> headers, String requestBody, String sslByPassOption, int connTimeOut, int readTimeout, HttpServletRequest req) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnsupportedEncodingException, IOException, UnknownHostException, URISyntaxException { StringBuffer response = new StringBuffer(); HttpResult httpResult = new HttpResult(); boolean gzip = false; final long startNano = System.nanoTime(); try {/* ww w .j a va2s. c o m*/ URL encodedUrl = new URL(Utility.encodeUrl(url.toString())); HttpURLConnection con = (HttpURLConnection) encodedUrl.openConnection(); TrustModifier.relaxHostChecking(con, sslByPassOption); // connection timeout 5s con.setConnectTimeout(connTimeOut); // read timeout 10s con.setReadTimeout(readTimeout * getQueryCost(req)); methodType = methodType.toUpperCase(); con.setRequestMethod(methodType); sLog.debug("Performing '{}' to '{}'", methodType, ServletUtil.filterUrl(url.toString())); // Get headers & set request property for (int i = 0; i < headers.size(); i++) { Map<String, String> header = headers.get(i); con.setRequestProperty(header.get("headerKey").toString(), header.get("headerValue").toString()); sLog.debug("Setting Header '{}' with value '{}'", header.get("headerKey").toString(), ServletUtil.filterHeaderValue(header.get("headerKey").toString(), header.get("headerValue").toString())); } if (con.getRequestProperty("Accept-Encoding") == null) { con.setRequestProperty("Accept-Encoding", "gzip"); } if (requestBody != null && !requestBody.equals("")) { con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.write(Utility.toUtf8Bytes(requestBody)); wr.flush(); wr.close(); } // push response BufferedReader in = null; String inputLine; List<String> contentEncoding = con.getHeaderFields().get("Content-Encoding"); if (contentEncoding != null) { for (String val : contentEncoding) { if ("gzip".equalsIgnoreCase(val)) { sLog.debug("Gzip enabled response"); gzip = true; break; } } } sLog.debug("Response: '{} {}' with headers '{}'", con.getResponseCode(), con.getResponseMessage(), ServletUtil.buildHeadersForLog(con.getHeaderFields())); if (con.getResponseCode() != 200 && con.getResponseCode() != 201) { if (con.getErrorStream() != null) { if (gzip) { in = new BufferedReader( new InputStreamReader(new GZIPInputStream(con.getErrorStream()), "UTF-8")); } else { in = new BufferedReader(new InputStreamReader(con.getErrorStream(), "UTF-8")); } } } else { String[] urlParts = url.toString().split("\\."); if (urlParts.length > 1) { String ext = urlParts[urlParts.length - 1]; if (ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg") || ext.equalsIgnoreCase("gif")) { BufferedImage imBuff; if (gzip) { imBuff = ImageIO.read(new GZIPInputStream(con.getInputStream())); } else { BufferedInputStream bfs = new BufferedInputStream(con.getInputStream()); imBuff = ImageIO.read(bfs); } BufferedImage newImage = new BufferedImage(imBuff.getWidth(), imBuff.getHeight(), BufferedImage.TYPE_3BYTE_BGR); // converting image to greyScale int width = imBuff.getWidth(); int height = imBuff.getHeight(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(imBuff.getRGB(j, i)); int red = (int) (c.getRed() * 0.21); int green = (int) (c.getGreen() * 0.72); int blue = (int) (c.getBlue() * 0.07); int sum = red + green + blue; Color newColor = new Color(sum, sum, sum); newImage.setRGB(j, i, newColor.getRGB()); } } ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(newImage, "jpg", out); byte[] bytes = out.toByteArray(); byte[] encodedBytes = Base64.encodeBase64(bytes); String base64Src = new String(encodedBytes); int imageSize = ((base64Src.length() * 3) / 4) / 1024; int initialImageSize = imageSize; int maxImageSize = Integer.parseInt(properties.getValue("Reduced_Image_Size")); float quality = 0.9f; if (!(imageSize <= maxImageSize)) { //This means that image size is greater and needs to be reduced. sLog.debug("Image size is greater than " + maxImageSize + " , compressing image."); while (!(imageSize < maxImageSize)) { base64Src = compress(base64Src, quality); imageSize = ((base64Src.length() * 3) / 4) / 1024; quality = quality - 0.1f; DecimalFormat df = new DecimalFormat("#.0"); quality = Float.parseFloat(df.format(quality)); if (quality <= 0.1) { break; } } } sLog.debug("Initial image size was : " + initialImageSize + " Final Image size is : " + imageSize + "Url is : " + url + "quality is :" + quality); String src = "data:image/" + urlParts[urlParts.length - 1] + ";base64," + new String(base64Src); JSONObject joResult = new JSONObject(); joResult.put("Image", src); out.close(); httpResult.setResponseCode(con.getResponseCode()); httpResult.setResponseHeader(con.getHeaderFields()); httpResult.setResponseBody(joResult.toString()); httpResult.setResponseMsg(con.getResponseMessage()); return httpResult; } } if (gzip) { in = new BufferedReader( new InputStreamReader(new GZIPInputStream(con.getInputStream()), "UTF-8")); } else { in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); } } if (in != null) { while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); } httpResult.setResponseCode(con.getResponseCode()); httpResult.setResponseHeader(con.getHeaderFields()); httpResult.setResponseBody(response.toString()); httpResult.setResponseMsg(con.getResponseMessage()); } catch (Exception e) { sLog.error("Failed to received HTTP response after timeout", e); httpResult.setTimeout(true); httpResult.setResponseCode(500); httpResult.setResponseMsg("Internal Server Error Timeout"); return httpResult; } return httpResult; }
From source file:bwem.example.MapPrinterExample.java
/** * Draws the specified map data to the internal map printer and generates an image file. * * @param theMap the specified BWEM map data to print * @param filename the specified file without a file extension *///from w w w.j av a 2s . c o m public void printMap(Map theMap, String filename) { java.util.Map<Integer, Color> mapZoneColor = new HashMap<>(); for (int y = 0; y < theMap.getData().getMapData().getWalkSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getWalkSize().getX(); ++x) { WalkPosition p = new WalkPosition(x, y); MiniTile miniTile = theMap.getData().getMiniTile(p, CheckMode.NO_CHECK); Color col; if (miniTile.isSea()) { if (mapPrinter.showSeaSide && theMap.getData().isSeaWithNonSeaNeighbors(p)) col = MapPrinter.CustomColor.SEA_SIDE.color(); else col = MapPrinter.CustomColor.SEA.color(); } else { if (mapPrinter.showLakes && miniTile.isLake()) { col = MapPrinter.CustomColor.LAKE.color(); } else { if (mapPrinter.showAltitude) { int c = 255 - ((miniTile.getAltitude().intValue() * 255) / theMap.getHighestAltitude().intValue()); col = new Color(c, c, c); } else { col = MapPrinter.CustomColor.TERRAIN.color(); } if (mapPrinter.showAreas || mapPrinter.showContinents) if (miniTile.getAreaId().intValue() > 0) { Area area = theMap.getArea(miniTile.getAreaId()); Color zoneColor = getZoneColor(area, mapZoneColor); int red = zoneColor.getRed() * col.getRed() / 255; int green = zoneColor.getGreen() * col.getGreen() / 255; col = new Color(red, green, 0); } else { col = MapPrinter.CustomColor.TINY_AREA.color(); } } } mapPrinter.point(p, col); } if (mapPrinter.showData) for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) { int data = ((TileImpl) theMap.getData().getTile(new TilePosition(x, y))).getInternalData(); int c = (((data / 1) * 1) % 256); Color col = new Color(c, c, c); WalkPosition origin = (new TilePosition(x, y)).toWalkPosition(); mapPrinter.rectangle(origin, origin.add(new WalkPosition(3, 3)), col, MapPrinter.fill_t.fill); } if (mapPrinter.showUnbuildable) for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) if (!theMap.getData().getTile(new TilePosition(x, y)).isBuildable()) { WalkPosition origin = (new TilePosition(x, y)).toWalkPosition(); mapPrinter.rectangle(origin.add(new WalkPosition(1, 1)), origin.add(new WalkPosition(2, 2)), MapPrinter.CustomColor.UNBUILDABLE.color()); } if (mapPrinter.showGroundHeight) for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) { Tile.GroundHeight groundHeight = theMap.getData().getTile(new TilePosition(x, y)) .getGroundHeight(); if (groundHeight.intValue() >= Tile.GroundHeight.HIGH_GROUND.intValue()) for (int dy = 0; dy < 4; ++dy) for (int dx = 0; dx < 4; ++dx) { WalkPosition p = (new TilePosition(x, y).toWalkPosition()) .add(new WalkPosition(dx, dy)); if (theMap.getData().getMiniTile(p, CheckMode.NO_CHECK).isWalkable()) // groundHeight is usefull only for walkable miniTiles if (((dx + dy) & (groundHeight == Tile.GroundHeight.HIGH_GROUND ? 1 : 3)) != 0) mapPrinter.point(p, MapPrinter.CustomColor.HIGHER_GROUND.color()); } } if (mapPrinter.showAssignedResources) for (Area area : theMap.getAreas()) for (Base base : area.getBases()) { for (Mineral m : base.getMinerals()) mapPrinter.line(base.getCenter().toWalkPosition(), m.getCenter().toWalkPosition(), MapPrinter.CustomColor.BASES.color()); for (Geyser g : base.getGeysers()) mapPrinter.line(base.getCenter().toWalkPosition(), g.getCenter().toWalkPosition(), MapPrinter.CustomColor.BASES.color()); } if (mapPrinter.showGeysers) for (Geyser g : theMap.getNeutralData().getGeysers()) printNeutral(theMap, g, MapPrinter.CustomColor.GEYSERS.color()); if (mapPrinter.showMinerals) for (Mineral m : theMap.getNeutralData().getMinerals()) printNeutral(theMap, m, MapPrinter.CustomColor.MINERALS.color()); if (mapPrinter.showStaticBuildings) for (StaticBuilding s : theMap.getNeutralData().getStaticBuildings()) printNeutral(theMap, s, MapPrinter.CustomColor.STATIC_BUILDINGS.color()); if (mapPrinter.showStartingLocations) for (TilePosition t : theMap.getData().getMapData().getStartingLocations()) { WalkPosition origin = t.toWalkPosition(); WalkPosition size = UnitType.Terran_Command_Center.tileSize().toWalkPosition(); // same size for other races mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.STARTING_LOCATIONS.color(), MapPrinter.fill_t.fill); } if (mapPrinter.showBases) for (Area area : theMap.getAreas()) { for (Base base : area.getBases()) { WalkPosition origin = base.getLocation().toWalkPosition(); WalkPosition size = UnitType.Terran_Command_Center.tileSize().toWalkPosition(); // same size for other races MapPrinter.dashed_t dashMode = base.getBlockingMinerals().isEmpty() ? MapPrinter.dashed_t.not_dashed : MapPrinter.dashed_t.dashed; mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.BASES.color(), MapPrinter.fill_t.do_not_fill, dashMode); } } if (mapPrinter.showChokePoints) { for (MutablePair<MutablePair<AreaId, AreaId>, WalkPosition> f : theMap.getRawFrontier()) mapPrinter.point(f.getRight(), mapPrinter.showAreas ? MapPrinter.CustomColor.CHOKE_POINTS_SHOW_AREAS.color() : MapPrinter.CustomColor.CHOKE_POINTS_SHOW_CONTINENTS.color()); for (Area area : theMap.getAreas()) for (ChokePoint cp : area.getChokePoints()) { ChokePoint.Node[] nodes = { ChokePoint.Node.END1, ChokePoint.Node.END2 }; for (ChokePoint.Node n : nodes) mapPrinter.square(cp.getNodePosition(n), 1, new Color(255, 0, 255), MapPrinter.fill_t.fill); mapPrinter.square(cp.getCenter(), 1, new Color(0, 0, 255), MapPrinter.fill_t.fill); } } //TODO: Handle exception. try { mapPrinter.writeImageToFile(Paths.get(filename + ".png"), "png"); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java
private void configureGradientAreaFill(Graphics2D g2, CategoryPlot plot, Paint itemPaint, PlotRenderingInfo info, GradientLineAreaFill gradientLineAreaFill) { double plotWidth = info.getPlotArea().getWidth(); double plotHeight = info.getPlotArea().getHeight(); Double mainColorTransparency = gradientLineAreaFill.getMaxValueTransparency(); Double bgColorTransparency = gradientLineAreaFill.getMinValueTransparency(); if (itemPaint instanceof Color) { Color itemColor = (Color) itemPaint; int red = itemColor.getRed(); int green = itemColor.getGreen(); int blue = itemColor.getBlue(); int mainColorAlpha = (mainColorTransparency >= 0.0 && mainColorTransparency <= 1.0) ? Math.round(255 * mainColorTransparency.floatValue()) : 150;/*from w ww .j a v a 2 s. c o m*/ int bgColorAlpha = (bgColorTransparency >= 0.0 && bgColorTransparency <= 1.0) ? Math.round(255 * bgColorTransparency.floatValue()) : 128; Color mainColor = new Color(red, green, blue, mainColorAlpha); Paint bgColor = getBackgroundPaint(); if (bgColor == null) { bgColor = plot.getBackgroundPaint(); } Color secondaryColor = getSecondaryColor(bgColorAlpha, bgColor); Paint areaPaint = getAreaFillPaint(plot, plotWidth, plotHeight, mainColor, secondaryColor); g2.setPaint(areaPaint); } else { g2.setPaint(itemPaint); } }
From source file:BlendCompositeDemo.java
/** * <p>Returns the HSL (Hue/Saturation/Luminance) equivalent of a given * RGB color. All three HSL components are between 0.0 and 1.0.</p> * * @param color the RGB color to convert * @return a new array of 3 floats corresponding to the HSL components *//* w w w. jav a 2 s . c o m*/ public static float[] RGBtoHSL(Color color) { return RGBtoHSL(color.getRed(), color.getGreen(), color.getBlue(), null); }
From source file:BlendCompositeDemo.java
/** * <p>Returns the HSL (Hue/Saturation/Luminance) equivalent of a given * RGB color. All three HSL components are between 0.0 and 1.0.</p> * * @param color the RGB color to convert * @param hsl a pre-allocated array of floats; can be null * @return <code>hsl</code> if non-null, a new array of 3 floats otherwise * @throws IllegalArgumentException if <code>hsl</code> has a length lower * than 3/* ww w . j a v a2 s. com*/ */ public static float[] RGBtoHSL(Color color, float[] hsl) { return RGBtoHSL(color.getRed(), color.getGreen(), color.getBlue(), hsl); }
From source file:com.groupdocs.HomeController.java
public int getIntFromColor(Color color) { return getIntFromColor(color.getRed(), color.getGreen(), color.getBlue()); }