List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:org.jls.toolbox.math.chart.XYBlockChart.java
/** * Permet de modifier l'chelle de couleur utilise par le graphique. Cela * va crer un gradient de couleur entre les deux couleurs spcifies, la * premire couleur correspondant aux valeurs les plus fortes de l'chelle * des donnes reprsenter. Les bornes infrieure et suprieure permettent * de prciser l'tendue des donnes reprsentes par cette chelle de * couleur./* w w w. ja va 2s . c o m*/ * * @param colorMin * Couleur d'arrive du gradient reprsentant les plus faibles * valeurs de l'chelle. * @param colorMax * Couleur de dpart du gradient reprsentant les plus fortes * valeurs de l'chelle. * @param lowerBound * Borne infrieure de l'chelle des donnes reprsentes. * @param upperBound * Bornes suprieure de l'chelle des donnes reprsentes. */ public void setColorGradient(Color colorMin, Color colorMax, double lowerBound, double upperBound) { LookupPaintScale scale = new LookupPaintScale(lowerBound, upperBound, Color.lightGray); double r1, r2, dr, g1, g2, dg, b1, b2, db; int nbVal = (int) (upperBound - lowerBound + 0.5); // Acquisition des composantes r1 = colorMax.getRed(); g1 = colorMax.getGreen(); b1 = colorMax.getBlue(); r2 = colorMin.getRed(); g2 = colorMin.getGreen(); b2 = colorMin.getBlue(); // Calcul du delta entre les composantes dr = (r2 - r1) / nbVal; dg = (g2 - g1) / nbVal; db = (b2 - b1) / nbVal; // Cration du gradient for (int i = 0; i < nbVal; i++) { scale.add(lowerBound + i, new Color((int) r2, (int) g2, (int) b2)); r2 = r2 - dr; g2 = g2 - dg; b2 = b2 - db; } // Mise jour du graphique this.renderer.setPaintScale(scale); this.scaleLegend.setScale(scale); // Du fait que la lgende n'est pas lie aux modifications de la courbe, // il faut rcrer la lgende la main. this.chart.removeSubtitle(this.scaleLegend); createPaintScaleLegend(scale); }
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 {/*from w w w. j a v a 2s .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:org.tros.logo.swing.LogoMenuBar.java
/** * Set up the tools menu./* ww w.java 2 s .c o m*/ * * @return */ private JMenu setupToolsMenu() { JMenu toolsMenu = new JMenu(Localization.getLocalizedString("ToolsMenu")); toolsPenColorChooser = new JMenuItem(Localization.getLocalizedString("ToolsPenColorChooser")); toolsCanvasColorChooser = new JMenuItem(Localization.getLocalizedString("ToolsCanvasColorChooser")); toolsPenColorChooser.setMnemonic('P'); toolsCanvasColorChooser.setMnemonic('C'); toolsPenColorChooser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Color selected = JColorChooser.showDialog(parent, Localization.getLocalizedString("ColorChooser"), null); if (selected != null) { int red = selected.getRed(); int green = selected.getGreen(); int blue = selected.getBlue(); String hex = String.format("#%02x%02x%02x", red, green, blue); controller.insertCommand("pencolor" + " " + hex); } } }); toolsCanvasColorChooser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Color selected = JColorChooser.showDialog(parent, Localization.getLocalizedString("ColorChooser"), null); if (selected != null) { int red = selected.getRed(); int green = selected.getGreen(); int blue = selected.getBlue(); String hex = String.format("#%02x%02x%02x", red, green, blue); controller.insertCommand("canvascolor" + " " + hex); } } }); toolsMenu.add(toolsPenColorChooser); toolsMenu.add(toolsCanvasColorChooser); toolsMenu.setMnemonic('T'); return (toolsMenu); }
From source file:org.openhab.binding.diyonxbee.internal.DiyOnXBeeBinding.java
private String makeRGB(Color color) { final StringBuilder sb = new StringBuilder(12); sb.append("RGB"); appendColor(sb, color.getRed());// www . ja va 2 s .c o m appendColor(sb, color.getGreen()); appendColor(sb, color.getBlue()); return sb.toString(); }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static float[][][] getResizedImageDifference(BufferedImage image1, BufferedImage image2, int newWidth, int newHeight) { // Calculate the subsampled difference between two buffered images float[][][] outputMap = new float[3][newWidth][newHeight]; float widthModifier = (float) image1.getWidth() / newWidth; float heightModifier = (float) image1.getHeight() / newHeight; Color tmpColor1, tmpColor2; for (int ii = 0; ii < newHeight; ii++) { for (int jj = 0; jj < newWidth; jj++) { try { tmpColor1 = new Color( image1.getRGB(Math.round(jj * widthModifier), Math.round(ii * heightModifier))); tmpColor2 = new Color( image2.getRGB(Math.round(jj * widthModifier), Math.round(ii * heightModifier))); outputMap[0][jj][ii] = (float) (tmpColor1.getRed() - tmpColor2.getRed()) * (tmpColor1.getRed() - tmpColor2.getRed()); outputMap[1][jj][ii] = (float) (tmpColor1.getGreen() - tmpColor2.getGreen()) * (tmpColor1.getGreen() - tmpColor2.getGreen()); outputMap[2][jj][ii] = (float) (tmpColor1.getBlue() - tmpColor2.getBlue()) * (tmpColor1.getBlue() - tmpColor2.getBlue()); } catch (Exception e) { System.out.println(newHeight + " " + newWidth + " " + image1.getHeight() + " " + image1.getWidth() + " " + ii + " " + jj + " " + Math.round(ii * heightModifier) + " " + Math.round(jj * widthModifier) + " " + heightModifier + " " + widthModifier); e.printStackTrace();/*w w w. j a v a2 s .c o m*/ return outputMap; } } } return outputMap; }
From source file:org.jtrfp.trcl.core.Texture.java
Texture(Color c, TR tr) { this(new PalettedVectorList(colorZeroRasterVL(), colorVL(c)), null, "SolidColor r=" + c.getRed() + " g=" + c.getGreen() + " b=" + c.getBlue(), tr, false); }
From source file:net.sf.jclal.gui.view.components.chart.ExternalBasicChart.java
/** * @param one/*from w w w .j av a 2s. c o m*/ * @param two * @param three * @return * <p> * return new color RBG */ private Color colorGenerator(Color one, Color two, Color three) { int red = (int) (one.getRed() + one.getBlue() + one.getGreen() / 3); int blue = (int) (two.getBlue() + two.getRed() + two.getGreen() / 3); int green = (int) (three.getGreen() + three.getRed() + three.getBlue() / 3); return new Color(red, blue, green); }
From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java
private void configureSolidAreaFill(Graphics2D g2, Paint itemPaint, SolidLineAreaFill solidLineAreaFill) { final Double transparency = solidLineAreaFill.getTransparency(); if (itemPaint instanceof Color && transparency >= 0.0 && transparency <= 1.0) { Color itemColor = (Color) itemPaint; int alpha = transparency >= 0.0 && transparency <= 1.0 ? Math.round(255 * transparency.floatValue()) : 255;/*ww w . j a v a 2 s . co m*/ g2.setPaint(new Color(itemColor.getRed(), itemColor.getGreen(), itemColor.getBlue(), alpha)); } else { g2.setPaint(itemPaint); } }
From source file:org.jfree.eastwood.ChartEngine.java
private static void applyColorsToPiePlot(PiePlot plot, Color[] colors) { if (colors.length == 1) { Color c = colors[0]; colors = new Color[2]; colors[0] = c;/* w ww .j a v a2 s . com*/ colors[1] = new Color(255 - ((255 - c.getRed()) / 5), 255 - ((255 - c.getGreen()) / 5), 255 - ((255 - c.getBlue()) / 5)); } PieDataset dataset = plot.getDataset(); int sectionCount = dataset.getItemCount(); if (colors.length < sectionCount) { // we need to interpolate some // colors for (int i = 0; i < colors.length - 1; i++) { Color c1 = colors[i]; Color c2 = colors[i + 1]; int s1 = sectionIndexForColor(i, colors.length, sectionCount); int s2 = sectionIndexForColor(i + 1, colors.length, sectionCount); for (int s = s1; s <= s2; s++) { Color c = interpolatedColor(c1, c2, s - s1, s2 - s1); plot.setSectionPaint(dataset.getKey(s), c); } } } else { for (int i = 0; i < sectionCount; i++) { plot.setSectionPaint(dataset.getKey(i), colors[i]); } } }
From source file:org.apache.fop.afp.DataStream.java
/** * This method will create shading on the page using the specified * coordinates (the shading contrast is controlled via the red, green, blue * parameters, by converting this to grey scale). * * @param x//from w w w . j a v a 2 s. co m * the x coordinate of the shading * @param y * the y coordinate of the shading * @param w * the width of the shaded area * @param h * the height of the shaded area * @param col * the shading color */ public void createShading(int x, int y, int w, int h, Color col) { currentPageObject.createShading(x, y, w, h, col.getRed(), col.getGreen(), col.getBlue()); }