List of usage examples for java.awt RenderingHints KEY_COLOR_RENDERING
Key KEY_COLOR_RENDERING
To view the source code for java.awt RenderingHints KEY_COLOR_RENDERING.
Click Source Link
From source file:Main.java
public static void main(String[] args) throws Exception { String text = "java2s.com"; BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); Font font = new Font("Arial", Font.PLAIN, 48); g2d.setFont(font);//from w w w. j a v a2 s. c o m FontMetrics fm = g2d.getFontMetrics(); int width = fm.stringWidth(text); int height = fm.getHeight(); g2d.dispose(); img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g2d.setFont(font); fm = g2d.getFontMetrics(); g2d.setColor(Color.BLACK); g2d.drawString(text, 0, fm.getAscent()); g2d.dispose(); ImageIO.write(img, "png", new File("Text.png")); }
From source file:net.sf.maltcms.common.charts.api.XYChartBuilder.java
/** * *//*from w w w. j av a 2 s . c om*/ public XYChartBuilder() { plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); chart = new JFreeChart(plot); renderingHints = new RenderingHints(null); renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); renderingHints.put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100); renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); renderingHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); renderingHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); renderingHints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); renderingHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); renderingHints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); renderingHints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); }
From source file:juicebox.mapcolorui.HeatmapRenderer.java
public boolean render(int originX, int originY, int width, int height, final MatrixZoomData zd, final MatrixZoomData controlZD, final MatrixType displayOption, final NormalizationType normalizationType, final ExpectedValueFunction df, Graphics2D g) { g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); int chr1 = zd.getChr1Idx(); int chr2 = zd.getChr2Idx(); int x = originX; int y = originY; boolean isWholeGenome = chr1 == 0 && chr2 == 0; boolean sameChr = (chr1 == chr2); if (sameChr) { // Data is transposable, transpose if necessary. Convention is to use lower diagonal if (x > y) { //noinspection SuspiciousNameCombination x = originY;/*from w ww. ja v a 2 s . co m*/ y = originX; int tmp = width; width = height; height = tmp; } } int maxX = x + width - 1; int maxY = y + height - 1; if (displayOption == MatrixType.PEARSON) { BasicMatrix bm = zd.getPearsons(df); ((HiCColorScale) pearsonColorScale).setMin(bm.getLowerValue()); ((HiCColorScale) pearsonColorScale).setMax(bm.getUpperValue()); renderMatrix(bm, originX, originY, width, height, pearsonColorScale, g); } else { // Iterate through blocks overlapping visible region List<Block> blocks = zd.getNormalizedBlocksOverlapping(x, y, maxX, maxY, normalizationType); if (blocks == null) { return false; } boolean hasControl = controlZD != null && (displayOption == MatrixType.CONTROL || displayOption == MatrixType.RATIO); Map<Integer, Block> controlBlocks = new HashMap<Integer, Block>(); if (hasControl) { List<Block> ctrls = controlZD.getNormalizedBlocksOverlapping(x, y, maxX, maxY, normalizationType); for (Block b : ctrls) { controlBlocks.put(b.getNumber(), b); } } String key = zd.getKey() + displayOption; ColorScale cs = getColorScale(key, displayOption, isWholeGenome, blocks); double averageCount = zd.getAverageCount(); // Will get overwritten for intra-chr double ctrlAverageCount = controlZD == null ? 1 : controlZD.getAverageCount(); for (Block b : blocks) { Collection<ContactRecord> recs = b.getContactRecords(); if (recs != null) { Map<String, ContactRecord> controlRecords = new HashMap<String, ContactRecord>(); if (hasControl) { Block cb = controlBlocks.get(b.getNumber()); if (cb != null) { for (ContactRecord ctrlRec : cb.getContactRecords()) { controlRecords.put(ctrlRec.getKey(), ctrlRec); } } } for (ContactRecord rec : recs) { double score = Double.NaN; if (displayOption == MatrixType.OE || displayOption == MatrixType.EXPECTED) { double expected = 0; if (chr1 == chr2) { if (df != null) { int binX = rec.getBinX(); int binY = rec.getBinY(); int dist = Math.abs(binX - binY); expected = df.getExpectedValue(chr1, dist); } } else { expected = (averageCount > 0 ? averageCount : 1); } if (displayOption == MatrixType.OE) { score = rec.getCounts() / expected; } else { score = expected; } } else if (displayOption == MatrixType.CONTROL && hasControl) { ContactRecord ctrlRecord = controlRecords.get(rec.getKey()); if (ctrlRecord != null) score = ctrlRecord.getCounts(); } else if (displayOption == MatrixType.RATIO && hasControl) { ContactRecord ctrlRecord = controlRecords.get(rec.getKey()); if (ctrlRecord != null && ctrlRecord.getCounts() > 0) { double num = rec.getCounts() / averageCount; double den = ctrlRecord.getCounts() / ctrlAverageCount; score = num / den; } } else { score = rec.getCounts(); } if (Double.isNaN(score)) continue; Color color = cs.getColor((float) score); g.setColor(color); int px = rec.getBinX() - originX; int py = rec.getBinY() - originY; if (px > -1 && py > -1 && px <= width && py <= height) { g.fillRect(px, py, HiCGlobals.BIN_PIXEL_WIDTH, HiCGlobals.BIN_PIXEL_WIDTH); } if (sameChr && (rec.getBinX() != rec.getBinY())) { px = (rec.getBinY() - originX); py = (rec.getBinX() - originY); if (px > -1 && py > -1 && px <= width && py <= height) { g.fillRect(px, py, HiCGlobals.BIN_PIXEL_WIDTH, HiCGlobals.BIN_PIXEL_WIDTH); } } } } } } return true; }
From source file:com.hmsinc.epicenter.spatial.render.SpatialScanRenderer.java
/** * @param context//www . j ava2 s . c om * @return */ private BufferedImage renderImage(final MapContext context, int width, int height) { logger.trace("Image width: {} height: {}", width, height); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics2D = (Graphics2D) image.getGraphics(); final GTRenderer renderer = new StreamingRenderer(); final RenderingHints h = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); h.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); h.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); h.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); h.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); renderer.setJava2DHints(h); renderer.setContext(context); renderer.paint(graphics2D, new Rectangle(width, height), context.getAreaOfInterest()); return image; }
From source file:ch.entwine.weblounge.preview.jai.JAIPreviewGenerator.java
/** * Resizes the given image to what is defined by the image style and writes * the result to the output stream./*from ww w. j av a2 s . co m*/ * * @param is * the input stream * @param os * the output stream * @param format * the image format * @param style * the style * @throws IllegalArgumentException * if the image is in an unsupported format * @throws IllegalArgumentException * if the input stream is empty * @throws IOException * if reading from or writing to the stream fails * @throws OutOfMemoryError * if the image is too large to be processed in memory */ private void style(InputStream is, OutputStream os, String format, ImageStyle style) throws IllegalArgumentException, IOException, OutOfMemoryError { // Does the input stream contain any data? if (is.available() == 0) throw new IllegalArgumentException("Empty input stream was passed to image styling"); // Do we need to do any work at all? if (style == null || ImageScalingMode.None.equals(style.getScalingMode())) { logger.trace("No scaling needed, performing a noop stream copy"); IOUtils.copy(is, os); return; } SeekableStream seekableInputStream = null; RenderedOp image = null; try { // Load the image from the given input stream seekableInputStream = new FileCacheSeekableStream(is); image = JAI.create("stream", seekableInputStream); if (image == null) throw new IOException("Error reading image from input stream"); // Get the original image size int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); // Resizing float scale = ImageStyleUtils.getScale(imageWidth, imageHeight, style); RenderingHints scaleHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); scaleHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); scaleHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); scaleHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int scaledWidth = Math.round(scale * image.getWidth()); int scaledHeight = Math.round(scale * image.getHeight()); int cropX = 0; int cropY = 0; // If either one of scaledWidth or scaledHeight is < 1.0, then // the scale needs to be adapted to scale to 1.0 exactly and accomplish // the rest by cropping. if (scaledWidth < 1.0f) { scale = 1.0f / imageWidth; scaledWidth = 1; cropY = imageHeight - scaledHeight; scaledHeight = Math.round(imageHeight * scale); } else if (scaledHeight < 1.0f) { scale = 1.0f / imageHeight; scaledHeight = 1; cropX = imageWidth - scaledWidth; scaledWidth = Math.round(imageWidth * scale); } if (scale > 1.0) { ParameterBlock scaleParams = new ParameterBlock(); scaleParams.addSource(image); scaleParams.add(scale).add(scale).add(0.0f).add(0.0f); scaleParams.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2)); image = JAI.create("scale", scaleParams, scaleHints); } else if (scale < 1.0) { ParameterBlock subsampleAverageParams = new ParameterBlock(); subsampleAverageParams.addSource(image); subsampleAverageParams.add(Double.valueOf(scale)); subsampleAverageParams.add(Double.valueOf(scale)); image = JAI.create("subsampleaverage", subsampleAverageParams, scaleHints); } // Cropping cropX = (int) Math.max(cropX, (float) Math.ceil(ImageStyleUtils.getCropX(scaledWidth, scaledHeight, style))); cropY = (int) Math.max(cropY, (float) Math.ceil(ImageStyleUtils.getCropY(scaledWidth, scaledHeight, style))); if ((cropX > 0 && Math.floor(cropX / 2.0f) > 0) || (cropY > 0 && Math.floor(cropY / 2.0f) > 0)) { ParameterBlock cropTopLeftParams = new ParameterBlock(); cropTopLeftParams.addSource(image); cropTopLeftParams.add(cropX > 0 ? ((float) Math.floor(cropX / 2.0f)) : 0.0f); cropTopLeftParams.add(cropY > 0 ? ((float) Math.floor(cropY / 2.0f)) : 0.0f); cropTopLeftParams.add(scaledWidth - Math.max(cropX, 0.0f)); // width cropTopLeftParams.add(scaledHeight - Math.max(cropY, 0.0f)); // height RenderingHints croppingHints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY)); image = JAI.create("crop", cropTopLeftParams, croppingHints); } // Write resized/cropped image encoded as JPEG to the output stream ParameterBlock encodeParams = new ParameterBlock(); encodeParams.addSource(image); encodeParams.add(os); encodeParams.add("jpeg"); JAI.create("encode", encodeParams); } catch (Throwable t) { if (t.getClass().getName().contains("ImageFormat")) { throw new IllegalArgumentException(t.getMessage()); } } finally { IOUtils.closeQuietly(seekableInputStream); if (image != null) image.dispose(); } }
From source file:net.geoprism.dashboard.DashboardMap.java
private BufferedImage getLegendTitleImage(DashboardLayer layer) { FontMetrics fm;//from w ww . j a v a 2 s. c o m int textWidth; int textHeight; int textBoxHorizontalPadding = 4; int textBoxVerticalPadding = 4; int borderWidth = 2; int paddedTitleHeight; int paddedTitleWidth; int titleLeftPadding = textBoxHorizontalPadding; BufferedImage newLegendTitleBase; Graphics2D newLegendTitleBaseGraphic = null; try { // Build the Font object Font titleFont = new Font(layer.getName(), Font.BOLD, 14); // Build variables for base legend graphic construction try { newLegendTitleBase = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); newLegendTitleBaseGraphic = newLegendTitleBase.createGraphics(); newLegendTitleBaseGraphic.setFont(titleFont); fm = newLegendTitleBaseGraphic.getFontMetrics(); textHeight = fm.getHeight(); textWidth = fm.stringWidth(layer.getName()); paddedTitleWidth = textWidth + (textBoxHorizontalPadding * 2) + (borderWidth * 2); paddedTitleHeight = textHeight + (textBoxVerticalPadding * 2) + (borderWidth * 2); } finally { // dispose of temporary graphics context if (newLegendTitleBaseGraphic != null) { newLegendTitleBaseGraphic.dispose(); } } titleLeftPadding = ((paddedTitleWidth / 2) - ((textWidth + (textBoxHorizontalPadding * 2) + (borderWidth * 2)) / 2)) + textBoxHorizontalPadding; newLegendTitleBase = new BufferedImage(paddedTitleWidth, paddedTitleHeight, BufferedImage.TYPE_INT_ARGB); newLegendTitleBaseGraphic = newLegendTitleBase.createGraphics(); newLegendTitleBaseGraphic.drawImage(newLegendTitleBase, 0, 0, null); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); newLegendTitleBaseGraphic.setFont(titleFont); // draw title text fm = newLegendTitleBaseGraphic.getFontMetrics(); newLegendTitleBaseGraphic.setColor(Color.WHITE); newLegendTitleBaseGraphic.drawString(layer.getName(), titleLeftPadding, fm.getAscent() + textBoxVerticalPadding); newLegendTitleBaseGraphic.drawImage(newLegendTitleBase, 0, 0, null); } finally { if (newLegendTitleBaseGraphic != null) { newLegendTitleBaseGraphic.dispose(); } } return newLegendTitleBase; }
From source file:org.jcurl.core.swing.RockLocationDisplayBase.java
public void exportPng(File dst) throws IOException { final BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) img.getGraphics(); {//from w ww . j ava 2 s. c om final Map hints = new HashMap(); hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.addRenderingHints(hints); } this.paintComponent(g2); g2.dispose(); if (!dst.getName().endsWith(".png")) dst = new File(dst.getName() + ".png"); ImageIO.write(img, "png", dst); }
From source file:org.jcurl.core.swing.WCComponent.java
private BufferedImage renderPng(final String watermark) { final BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) img.getGraphics(); {// w w w . j a v a 2 s . c o m final Map<Key, Object> hints = new HashMap<Key, Object>(); hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.addRenderingHints(hints); } final Font f0 = g2.getFont(); paint(g2); g2.setTransform(new AffineTransform()); if (watermark != null) { if (log.isDebugEnabled()) log.debug(f0); g2.setFont(f0); g2.setColor(new Color(0, 0, 0, 128)); g2.drawString(watermark, 10, 20); } g2.dispose(); return img; }
From source file:org.squidy.designer.shape.VisualShape.java
@Override protected final void paint(PPaintContext paintContext) { super.paint(paintContext); Graphics2D g = paintContext.getGraphics(); // Set default font. g.setFont(internalFont);//from w w w . j a v a2s. c om // if (!renderingHintsSet) { if (isRenderPrimitive()) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } else { // Use anti aliasing -> May slow down performance. g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } // renderingHintsSet = true; // } // Paint the shapes visual representation. paintShape(paintContext); // Allows visual debugging if enabled. if (DebugConstants.ENABLED) { paintDebug(paintContext); } }
From source file:springapp.web.controller.theme.ProcessThemeController.java
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { HttpSession session = httpServletRequest.getSession(); String templateIdString = httpServletRequest.getParameter(ApplicationConstants.TEMPLATE_ID); byte templateId = 0; int oldColor = 0; int newColor = 0; int oldHeaderColor = 0; int newHeaderColor = 0; int oldBgColor = 0; int newBgColor = 0; int oldFontColor = 0; int newFontColor = 0; int oldHeaderFontColor = 0; int newHeaderFontColor = 0; int oldBorderColor = 0; int newBorderColor = 0; int oldTransp = 0; int newTransp = 0; byte sizeHeaderFontDiff = 11; byte sizeFontDiff = 11; ThemeParametersHolder themeParametersHolder = null; String toolsetName = httpServletRequest.getParameter(ApplicationConstants.TOOLSET_NAME); String versionString = httpServletRequest.getParameter(ApplicationConstants.VERSION); String version = (null == versionString) ? ApplicationConstants.DEFAULT_EXTJS_VERSION : versionString; String familyHeaderFont = httpServletRequest.getParameter(ApplicationConstants.FAMILY_HEADER_FONT); String familyFont = httpServletRequest.getParameter(ApplicationConstants.FAMILY_FONT); String weightHeaderFont = httpServletRequest.getParameter(ApplicationConstants.WEIGHT_HEADER_FONT); String weightFont = httpServletRequest.getParameter(ApplicationConstants.WEIGHT_FONT); try {/*from w w w . j a va2 s . c om*/ templateId = null != templateIdString ? Byte.parseByte(templateIdString) : 0; String oldColorString = (0 == templateId) ? "#DFE8F6" : "#F1F1F1"; String newColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_COLOR); String oldHeaderColorString = (0 == templateId) ? "#CDDEF3" : "#D7D7D7"; String newHeaderColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_HEADER_COLOR); String oldBgColorString = "#FFFFFF"; String newBgColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_BG_COLOR); String oldFontColorString = "#000000"; String newFontColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_FONT_COLOR); String oldHeaderFontColorString = (0 == templateId) ? "#15428B" : "#222222"; String newHeaderFontColorString = httpServletRequest .getParameter(ApplicationConstants.NEW_HEADER_FONT_COLOR); String sizeHeaderFontString = httpServletRequest.getParameter(ApplicationConstants.SIZE_HEADER_FONT); String sizeFontString = httpServletRequest.getParameter(ApplicationConstants.SIZE_FONT); String oldBorderColorString = (0 == templateId) ? "#99BBE8" : "#D0D0D0"; String newBorderColorString = httpServletRequest.getParameter(ApplicationConstants.NEW_BORDER_COLOR); String oldTranspString = "255"; String newTranspString = httpServletRequest.getParameter(ApplicationConstants.NEW_TRANSP); themeParametersHolder = new ThemeParametersHolder(templateIdString, newColorString, newHeaderColorString, newBgColorString, newFontColorString, newHeaderFontColorString, familyHeaderFont, weightHeaderFont, sizeHeaderFontString, familyFont, weightFont, sizeFontString, newBorderColorString, newTranspString, toolsetName, version); oldColor = null != oldColorString ? Integer.parseInt(oldColorString.replaceFirst("#", ""), 16) : 0; newColor = null != newColorString ? Integer.parseInt(newColorString.replaceFirst("#", ""), 16) : 0; oldHeaderColor = null != oldHeaderColorString ? Integer.parseInt(oldHeaderColorString.replaceFirst("#", ""), 16) : 0; newHeaderColor = null != newHeaderColorString ? Integer.parseInt(newHeaderColorString.replaceFirst("#", ""), 16) : 0; oldBgColor = null != oldBgColorString ? Integer.parseInt(oldBgColorString.replaceFirst("#", ""), 16) : 0; newBgColor = null != newBgColorString ? Integer.parseInt(newBgColorString.replaceFirst("#", ""), 16) : 0; oldFontColor = null != oldFontColorString ? Integer.parseInt(oldFontColorString.replaceFirst("#", ""), 16) : 0; newFontColor = null != newFontColorString ? Integer.parseInt(newFontColorString.replaceFirst("#", ""), 16) : 0; oldHeaderFontColor = null != oldHeaderFontColorString ? Integer.parseInt(oldHeaderFontColorString.replaceFirst("#", ""), 16) : 0; newHeaderFontColor = null != newHeaderFontColorString ? Integer.parseInt(newHeaderFontColorString.replaceFirst("#", ""), 16) : 0; oldBorderColor = null != oldBorderColorString ? Integer.parseInt(oldBorderColorString.replaceFirst("#", ""), 16) : 0; newBorderColor = null != newBorderColorString ? Integer.parseInt(newBorderColorString.replaceFirst("#", ""), 16) : 0; oldTransp = null != oldTranspString ? Integer.parseInt(oldTranspString) : 0; newTransp = null != newTranspString ? Integer.parseInt(newTranspString) : 0; sizeHeaderFontDiff = (byte) ((null != sizeHeaderFontString ? Byte.parseByte(sizeHeaderFontString) : 11) - 11); sizeFontDiff = (byte) ((null != sizeFontString ? Byte.parseByte(sizeFontString) : 11) - 11); } catch (Exception e) { logger.error(e); } int oldR = (oldColor >> 16) & 0xff; int oldG = (oldColor >> 8) & 0xff; int oldB = oldColor & 0xff; int newR = (newColor >> 16) & 0xff; int newG = (newColor >> 8) & 0xff; int newB = newColor & 0xff; int oldHeaderR = (oldHeaderColor >> 16) & 0xff; int oldHeaderG = (oldHeaderColor >> 8) & 0xff; int oldHeaderB = oldHeaderColor & 0xff; int newHeaderR = (newHeaderColor >> 16) & 0xff; int newHeaderG = (newHeaderColor >> 8) & 0xff; int newHeaderB = newHeaderColor & 0xff; int oldBgR = (oldBgColor >> 16) & 0xff; int oldBgG = (oldBgColor >> 8) & 0xff; int oldBgB = oldBgColor & 0xff; int newBgR = (newBgColor >> 16) & 0xff; int newBgG = (newBgColor >> 8) & 0xff; int newBgB = newBgColor & 0xff; int oldFontR = (oldFontColor >> 16) & 0xff; int oldFontG = (oldFontColor >> 8) & 0xff; int oldFontB = oldFontColor & 0xff; int newFontR = (newFontColor >> 16) & 0xff; int newFontG = (newFontColor >> 8) & 0xff; int newFontB = newFontColor & 0xff; int oldHeaderFontR = (oldHeaderFontColor >> 16) & 0xff; int oldHeaderFontG = (oldHeaderFontColor >> 8) & 0xff; int oldHeaderFontB = oldHeaderFontColor & 0xff; int newHeaderFontR = (newHeaderFontColor >> 16) & 0xff; int newHeaderFontG = (newHeaderFontColor >> 8) & 0xff; int newHeaderFontB = newHeaderFontColor & 0xff; int oldBorderR = (oldBorderColor >> 16) & 0xff; int oldBorderG = (oldBorderColor >> 8) & 0xff; int oldBorderB = oldBorderColor & 0xff; int newBorderR = (newBorderColor >> 16) & 0xff; int newBorderG = (newBorderColor >> 8) & 0xff; int newBorderB = newBorderColor & 0xff; ServletContext servletContext = session.getServletContext(); WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); ResourcesProcessorFactory resourcesProcessorFactory = (ResourcesProcessorFactory) context .getBean("processorFactory"); ResourcesHolder schemaHolder; ResourcesProcessor processor; /* schemaHolder = getResourcesHolderForProcessing(templateId, ""); processor = resourcesProcessorFactory.getResourcesProcessor(schemaHolder, context);*/ //operation definition //hints HashMap hints = new HashMap(); hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); RenderingHints renderingHints = new RenderingHints(hints); int rDiff = newR - oldR; int gDiff = newG - oldG; int bDiff = newB - oldB; int rHeaderDiff = newHeaderR - oldHeaderR; int gHeaderDiff = newHeaderG - oldHeaderG; int bHeaderDiff = newHeaderB - oldHeaderB; int rBgDiff = newBgR - oldBgR; int gBgDiff = newBgG - oldBgG; int bBgDiff = newBgB - oldBgB; int rFontDiff = newFontR - oldFontR; int gFontDiff = newFontG - oldFontG; int bFontDiff = newFontB - oldFontB; int rHeaderFontDiff = newHeaderFontR - oldHeaderFontR; int gHeaderFontDiff = newHeaderFontG - oldHeaderFontG; int bHeaderFontDiff = newHeaderFontB - oldHeaderFontB; int rBorderDiff = newBorderR - oldBorderR; int gBorderDiff = newBorderG - oldBorderG; int bBorderDiff = newBorderB - oldBorderB; float transparencyDiff = newTransp - oldTransp; float[] offsets = { rDiff, gDiff, bDiff, 0f }; float[] offsetsHeader = { rHeaderDiff, gHeaderDiff, bHeaderDiff, 0f }; float[] offsetsBg = { rBgDiff, gBgDiff, bBgDiff, 0f }; float[] offsetsFont = { rFontDiff, gFontDiff, bFontDiff, 0f }; float[] offsetsHeaderFont = { rHeaderFontDiff, gHeaderFontDiff, bHeaderFontDiff, 0f }; float[] offsetsBorder = { rBorderDiff, gBorderDiff, bBorderDiff, 0f }; float[] offsetsTranceparency = (0 == transparencyDiff) ? null : new float[] { 0, 0, 0, transparencyDiff }; float[] offsetsShadowTransparency = { 0, 0, 0, transparencyDiff / 5 }; float liteDivider = 2.5f; float[] liteoffsets = { rDiff / liteDivider, gDiff / liteDivider, bDiff / liteDivider, 0f }; float[] scaleFactors = { 1.0f, 1.0f, 1.0f, 1.0f }; ExtJSRescaleOp brightenOp = new ExtJSRescaleOp(scaleFactors, // 1 ,1 ,1 offsets, renderingHints); ExtJSRescaleOp headerOp = new ExtJSRescaleOp(scaleFactors, // 1 ,1 ,1 offsetsHeader, renderingHints); ExtJSRescaleOp liteOp = new ExtJSRescaleOp(scaleFactors, // 1 ,1 ,1 liteoffsets, renderingHints); ExtJSRescaleOp bgOp = new ExtJSRescaleOp(scaleFactors, // 1 ,1 ,1 offsetsBg, renderingHints); ExtJSRescaleOp fontOp = new ExtJSRescaleOp(scaleFactors, // 1 ,1 ,1 offsetsFont, renderingHints); ExtJSRescaleOp headerFontOp = new ExtJSRescaleOp(scaleFactors, // 1 ,1 ,1 offsetsHeaderFont, renderingHints); ExtJSRescaleOp borderOp = new ExtJSRescaleOp(scaleFactors, // 1 ,1 ,1 offsetsBorder, renderingHints); ExtJSRescaleOp transparencyOp = (0 == transparencyDiff) ? null : new ExtJSRescaleOp(scaleFactors, // 1 ,1 ,1 offsetsTranceparency, renderingHints); ExtJSRescaleOp shadowTransparencyOp = null/*new ExtJSRescaleOp( scaleFactors,// 1 ,1 ,1 offsetsShadowTransparency, renderingHints)*/; /* ShiftOp shiftOp = new ShiftOp(new float[]{1, 1, 1, 1} , offsets, renderingHints, true); int csRGB = ColorSpace.CS_sRGB; int csGRAY = ColorSpace.CS_GRAY; ColorSpace srcCS = ColorSpace.getInstance(csRGB); ColorSpace destCS = ColorSpace.getInstance(csGRAY); */ //operation with inversion of color #for heading font color ForegroundShiftOp foregroundOp = new ForegroundShiftOp(newR, newG, newB); AffineTransformOp affineTransformOp = null/*new AffineTransformOp( AffineTransform.getScaleInstance(2,2), AffineTransformOp.TYPE_BICUBIC)*/; //end operation definition //get toolset holder ResourceHolderPool holderToolsetPool = this.holderToolsetPool; ResourcesHolder toolsetSchemaHolder = holderToolsetPool.checkOut(); // //get drawable holder ResourceHolderPool holderDrawablePool = this.holderDrawablePool; ResourcesHolder drawableSchemaHolder = holderDrawablePool.checkOut(); // /* process(processor, templateId, schemaHolder, brightenOp, foregroundOp, liteOp, bgOp, fontOp, transparencyOp, session, borderOp, affineTransformOp, headerFontOp, shadowTransparencyOp, headerOp, toolsetSchemaHolder, toolsetName, familyHeaderFont, weightHeaderFont, sizeHeaderFontDiff, familyFont, weightFont, sizeFontDiff, drawableSchemaHolder, "3.2"*//*version*//*); if (!"3.2".equals(version)){*/ schemaHolder = getResourcesHolderForProcessing(templateId, version); processor = resourcesProcessorFactory.getResourcesProcessor(schemaHolder, context); process(processor, themeParametersHolder, templateId, schemaHolder, brightenOp, foregroundOp, liteOp, bgOp, fontOp, transparencyOp, session, borderOp, affineTransformOp, headerFontOp, shadowTransparencyOp, headerOp, toolsetSchemaHolder, toolsetName, familyHeaderFont, weightHeaderFont, sizeHeaderFontDiff, familyFont, weightFont, sizeFontDiff, drawableSchemaHolder, version); /* }*/ logger.info("ProcessThemeController ! IP=" + httpServletRequest.getRemoteAddr()); return new ModelAndView("json/success"); }