static { defaultRenderingHints = new RenderingHints(null); defaultRenderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); defaultRenderingHints.put( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); }
public void paintComponent(Graphics g) { if (OSPRuntime.antiAliasText) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } super.paintComponent(g); }
/** * Sets a rendering hint * * @param arg0 * @param arg1 */ public void setRenderingHint(Key arg0, Object arg1) { if (arg1 != null) { rhints.put(arg0, arg1); } else { if (arg0 instanceof HyperLinkKey) { rhints.put(arg0, HyperLinkKey.VALUE_HYPERLINKKEY_OFF); } else { rhints.remove(arg0); } } }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; RenderingHints hints = new RenderingHints(null); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHints(hints); g2.rotate(-Math.toRadians(degrees), w / 2, h / 2); g2.drawImage(dimg, 0, 0, this); g2.dispose(); }
@Override public void paint(Graphics g) { // init the paint super.paint(g); // cast g to a Graphics2D object so we can use its features Graphics2D g2 = (Graphics2D) g; // get a rendering hints object. not sure why. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // pass it some parameters rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // connect rh to the graphics object g2.setRenderingHints(rh); /** Lookup Table for which color to be 0 = dead, white 1 = alive, black */ Color[] lookup = {Color.white, Color.black}; int x, y, state; for (x = 0; x < sizex; x++) { for (y = 0; y < sizey; y++) { state = uni.getState(x, y); g2.setColor(lookup[state]); g2.fillRect(scale * x, scale * y, scale, scale); } } }
public void paint(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; Dimension size = getSize(); Insets insets = getInsets(); int w = size.width - insets.left - insets.right; int h = size.height - insets.top - insets.bottom; float scale = w / axis_size; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); g2d.translate(w / 2, 3.5 * h / 8); g2d.setColor(Color.black); drawPoints(g2d, scale); drawTimeLines(g2d, scale); drawInitialGraph(g2d, scale); drawMessages(g2d, scale); }
public PledgeDisplayPanel() { try { logo = ImageIO.read(getClass().getResource("pp-logo-large.png")); } catch (IOException e) { System.err.println("Could not load background image"); e.printStackTrace(); } tickerLabel = new TickerLabel(); tickerLabel.setVisible(true); slidePane = new SlidePane(); slidePane.setVisible(false); pledgePane = new PledgePane(); readProperties(); idleTimer = new Timer(idleTimeout, new IdleTimeout()); idleTimer.start(); setForeground(Color.black); setLayout(null); renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); addComponentListener(this); add(tickerLabel); add(pledgePane); add(slidePane); addMouseListener(this); }
public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(new Color(219, 219, 72)); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); Font fnt = new Font("STENCIL", Font.BOLD, 100); g2d.setColor(new Color(62, 11, 214)); g2d.setFont(fnt); g2d.drawString("Hangman", 240, 100); fnt = new Font("STENCIL", Font.ITALIC, 30); g2d.setFont(fnt); g2d.setColor(new Color(11, 214, 201)); g2d.drawString("created by Ashwin Gupta", 240, 125); /*g2d.setFont(new Font("Arial", Font.PLAIN, 75)); g2d.drawString("PAINT BIG ", 100, 400); g2d.drawString("HANGMAN HERE", 100, 500);*/ // int offset= 20; HangComponents dh = new HangComponents(); g2d.setColor(Color.DARK_GRAY); for (int i = 0; i < 8; i++) { if (i == 7 || i == 6) { g2d.setStroke(new BasicStroke(45)); g2d.draw(dh.hangman[i]); } else g2d.fill(dh.hangman[i]); } }
private RenderedOp createScaledImage( RenderedImage sourceImage, S2Resolution resolution, int level) { int sourceWidth = sourceImage.getWidth(); int sourceHeight = sourceImage.getHeight(); int targetWidth = imageLayouts[0].width >> level; int targetHeight = imageLayouts[0].height >> level; float scaleX = (float) targetWidth / (float) sourceWidth; float scaleY = (float) targetHeight / (float) sourceHeight; float corrFactorX = resolution == S2Resolution.R20M ? R20M_X_FACTOR : R60M_X_FACTOR; float corrFactorY = resolution == S2Resolution.R20M ? R20M_Y_FACTOR : R60M_Y_FACTOR; final Dimension tileDim = getTileDim(targetWidth, targetHeight); ImageLayout imageLayout = new ImageLayout(); imageLayout.setTileWidth(tileDim.width); imageLayout.setTileHeight(tileDim.height); RenderingHints renderingHints = new RenderingHints( JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_ZERO)); renderingHints.put(JAI.KEY_IMAGE_LAYOUT, imageLayout); RenderedOp scaledImage = ScaleDescriptor.create( sourceImage, scaleX * corrFactorX, scaleY * corrFactorY, 0F, 0F, Interpolation.getInstance(Interpolation.INTERP_NEAREST), renderingHints); if (scaledImage.getWidth() != targetWidth || scaledImage.getHeight() != targetHeight) { return CropDescriptor.create( scaledImage, 0.0F, 0.0F, (float) targetWidth, (float) targetHeight, null); } else { return scaledImage; } }
private BufferedImage scale(BufferedImage image, int newWidth, int newHeight) { float width; float height; if (newWidth <= 0 || newHeight <= 0) { logger.warn("Invalid scale attempt aborted."); return null; } width = (float) newWidth / (float) image.getWidth(); height = (float) newHeight / (float) image.getHeight(); BufferedImage out = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = out.createGraphics(); RenderingHints qualityHints = new RenderingHints( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ANTIALIAS_ON); qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHints(qualityHints); AffineTransform at = AffineTransform.getScaleInstance(width, height); g2.drawImage(image, at, null); g2.dispose(); return out; }
/** * A paint class that will draw the needle, dots, and TO/FROM RenderingHints is IMPORTANT. It * will make sure that everything stays focused and not blurry whenever the image rotates. I * added an empty line between the 8 fillArcs, just so its easier to see that four of them * draw on the left side and four draw on the right side. */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints hints = new RenderingHints(null); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHints(hints); g2.setStroke(new BasicStroke(3)); // g2.drawString("TO", 190, 200); if (vor.isTo() == true) { if (vor.isAbeamed() == true) { // g2.setFont(new Font("default", Font.BOLD, 16)); // g2.setColor(Color.red); // g2.drawString("BAD", 190, 200); } else { // g2.setFont(new Font("default", Font.BOLD, 16)); g2.drawString("TO", 190, 200); } } else if (vor.isFrom() == true) { if (vor.isAbeamed() == true) { // g2.setFont(new Font("default", Font.BOLD, 16)); // g2.setColor(Color.red); // g2.drawString("BAD", 190, 300); } else { // g2.setFont(new Font("default", Font.BOLD, 13)); g2.drawString("FROM", 190, 300); } } else if (vor.isFrom() == false || vor.isTo() == false) { // is above the vor station no to or from } g2.fillArc(140, 240, 7, 7, 0, 360); g2.fillArc(125, 240, 7, 7, 0, 360); g2.fillArc(110, 240, 7, 7, 0, 360); g2.fillArc(95, 240, 7, 7, 0, 360); g2.fillArc(195, 240, 7, 7, 0, 360); g2.fillArc(210, 240, 7, 7, 0, 360); g2.fillArc(225, 240, 7, 7, 0, 360); g2.fillArc(240, 240, 7, 7, 0, 360); // g2.drawString("FROM",190, 300); g2.drawLine(x, y1, x, y2); super.paintComponent(g); g2.dispose(); }
/** Returns a RenderingHints parsed from the given Properties */ public static RenderingHints parseRenderingHints(Properties preferences) { RenderingHints rh = new RenderingHints(null); String str; str = preferences.getProperty("rendering.antialiasing"); if (str != null) { if (str.equals("on")) rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); else if (str.equals("off")) rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } str = preferences.getProperty("rendering.text-antialiasing"); if (str != null) { if (str.equals("on")) rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); else if (str.equals("off")) rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } str = preferences.getProperty("rendering.render"); if (str != null) { if (str.equals("speed")) rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); else if (str.equals("quality")) rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); } str = preferences.getProperty("rendering.dither"); if (str != null) { if (str.equals("on")) rh.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); else if (str.equals("off")) rh.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); } str = preferences.getProperty("rendering.fractional-metrics"); if (str != null) { if (str.equals("on")) rh.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); else if (str.equals("off")) rh.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); } return rh; }
static { hints = new RenderingHints(null); // fractional metrics distorts text spacing; not for this application! hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // hints.put(RenderingHints.KEY_ANTIALIASING , RenderingHints.VALUE_ANTIALIAS_OFF); hints.put( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); }
public void setupRendering(Graphics2D g2, boolean quality, Stroke stroke, Color color) { RenderingHints qualityHints = new RenderingHints(null); if (quality) { qualityHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f); g2.setComposite(ac); g2.setStroke(stroke); g2.setColor(color); } else { qualityHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2.setStroke(new BasicStroke()); // strip out alpha g2.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue())); } g2.setRenderingHints(qualityHints); }
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int width = 100; int height = 40; SecureRandom random = new SecureRandom(); BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = bufferedImage.createGraphics(); Font font = new Font("Georgia", Font.BOLD, 15); g2d.setFont(font); RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); GradientPaint gp = new GradientPaint(0, 0, Color.blue, 0, height / 2, Color.pink, true); g2d.setPaint(gp); g2d.fillRect(0, 0, width, height); g2d.setColor(Color.RED); Random r = new Random(); String captcha = new BigInteger(25, random).toString(32); request.getSession().setAttribute("real_captcha", captcha); int x = 0; int y = 0; for (int i = 0; i < captcha.length(); i++) { x += 10 + (Math.abs(r.nextInt()) % 15); y = 10 + Math.abs(r.nextInt()) % 20; g2d.drawChars(captcha.toCharArray(), i, 1, x, y); } g2d.dispose(); response.setContentType("image/png"); try (OutputStream os = response.getOutputStream()) { ImageIO.write(bufferedImage, "png", os); } }
// init private static void init() { if (frame != null) frame.setVisible(false); frame = new JFrame(); offscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); onscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); offscreen = offscreenImage.createGraphics(); onscreen = onscreenImage.createGraphics(); setXscale(); setYscale(); offscreen.setColor(DEFAULT_CLEAR_COLOR); offscreen.fillRect(0, 0, width, height); setPenColor(); setPenRadius(); setFont(); clear(); // add anti-aliasing RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); offscreen.addRenderingHints(hints); // frame stuff ImageIcon icon = new ImageIcon(onscreenImage); JLabel draw = new JLabel(icon); draw.addMouseListener(std); draw.addMouseMotionListener(std); frame.setContentPane(draw); frame.addKeyListener(std); // JLabel cannot get keyboard focus frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // closes all windows // frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // closes only current window frame.setTitle("Standard Draw"); frame.setJMenuBar(createMenuBar()); frame.pack(); frame.requestFocusInWindow(); frame.setVisible(true); }
// Draw elements: @Override public void paint(Graphics g) { // Set up Graphics Enigne: Graphics2D g2d = (Graphics2D) g; // Antialiasing: if (antialiasing == true) { RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); } // Draw rendered image g2d.drawImage( renderImage, 0, 0, width, height, 0, 0, resolution.width, resolution.height, this); g2d.setColor(Color.yellow); g2d.drawString("FPS: " + fps, 20, 20); }
static { ImageLayout layout = new ImageLayout(); layout.setColorModel(ColorModel.getRGBdefault()); RenderingHints screenHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); screenHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); screenHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); screenHints.put( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); screenHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); screenHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); screenHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); screenHints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); screenHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); screenContext = new RenderContext(AffineTransform.getTranslateInstance(0.0, 0.0), screenHints); RenderingHints draftHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); draftHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); draftHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); draftHints.put( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); draftHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); draftHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); draftHints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); draftHints.put( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); draftHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); draftContext = new RenderContext(AffineTransform.getTranslateInstance(0.0, 0.0), draftHints); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = g2d.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); // Background. D = this.getSize(); g.setColor(backgroundColor); g.fillRect(0, 0, D.width, D.height); Graphics2D g2 = (Graphics2D) g; g2.setStroke(lineStroke); // Axes, bounding box. g.setColor(Color.gray); g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset); g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset); g.drawLine(inset, inset, inset, D.height - inset); g.drawLine(inset, inset, D.width - inset, inset); double xDelta = (maxX - minX) / numIntervals; // X-ticks and labels. for (int i = 1; i <= numIntervals; i++) { double xTickd = i * xDelta; int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset)); g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5); double x = minX + i * xDelta; g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20); } // Y-ticks double yDelta = (maxY - minY) / numIntervals; for (int i = 0; i < numIntervals; i++) { int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals); g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset); double y = minY + (i + 1) * yDelta; g.drawString(df.format(y), 1, D.height - yTick - inset); } // Zoom+move Font savedFont = g.getFont(); g.setFont(plusFont); g.drawString("+", D.width - 25, 20); g.setFont(minusFont); g.drawString("-", D.width - 25, 50); drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left g.setFont(savedFont); // See if standard axes are in the middle. g.setColor(Color.gray); if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) { // Draw y-axis int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset)); g.drawLine(inset + x, D.height - inset, inset + x, inset); } if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) { // Draw x-axis int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset)); g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset); } // Draw the objects. drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines); if (animationMode) { drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines); // No images in animation mode. } drawScribbles(g); }
/** * Creates and returns the rendering hints for the GUI. Built from {@link #RENDER_HINTS} * * @return Hints to use when displaying the GUI. */ public static RenderingHints getRenderingHints() { RenderingHints hints = new RenderingHints(null); for (int i = 0; i < RENDER_HINTS.length; i++) hints.put(RENDER_HINTS[i][0], RENDER_HINTS[i][1]); return hints; }
/** * Sets a rendering hint * * @param arg0 * @param arg1 */ public void setRenderingHint(Key arg0, Object arg1) { rhints.put(arg0, arg1); }
static { _renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); _renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); }
/** * Applies the band select operation to a grid coverage. * * @param cropEnvelope the target envelope; always not null * @param cropROI the target ROI shape; nullable * @param roiTolerance; as read from op's params * @param sourceCoverage is the source {@link GridCoverage2D} that we want to crop. * @param hints A set of rendering hints, or {@code null} if none. * @param sourceGridToWorldTransform is the 2d grid-to-world transform for the source coverage. * @return The result as a grid coverage. */ private static GridCoverage2D buildResult( final GeneralEnvelope cropEnvelope, final Geometry cropROI, final double roiTolerance, final boolean forceMosaic, final Hints hints, final GridCoverage2D sourceCoverage, final AffineTransform sourceGridToWorldTransform) { // // Getting the source coverage and its child geolocation objects // final RenderedImage sourceImage = sourceCoverage.getRenderedImage(); final GridGeometry2D sourceGridGeometry = ((GridGeometry2D) sourceCoverage.getGridGeometry()); final GridEnvelope2D sourceGridRange = sourceGridGeometry.getGridRange2D(); // // Now we try to understand if we have a simple scale and translate or a // more elaborated grid-to-world transformation n which case a simple // crop could not be enough, but we may need a more elaborated chain of // operation in order to do a good job. As an instance if we // have a rotation which is not multiple of PI/2 we have to use // the mosaic with a ROI // final boolean isSimpleTransform = CoverageUtilities.isSimpleGridToWorldTransform(sourceGridToWorldTransform, EPS); // Do we need to explode the Palette to RGB(A)? // int actionTaken = 0; // // // // Layout // // // final RenderingHints targetHints = new RenderingHints(null); if (hints != null) targetHints.add(hints); final ImageLayout layout = initLayout(sourceImage, targetHints); targetHints.put(JAI.KEY_IMAGE_LAYOUT, layout); // // prepare the processor to use for this operation // final JAI processor = OperationJAI.getJAI(targetHints); final boolean useProvidedProcessor = !processor.equals(JAI.getDefaultInstance()); try { if (cropROI != null) { // replace the cropEnvelope with the envelope of the intersection // of the ROI and the cropEnvelope. // Remember that envelope(intersection(roi,cropEnvelope)) != intersection(cropEnvelope, // envelope(roi)) final Polygon modelSpaceROI = FeatureUtilities.getPolygon(cropEnvelope, GFACTORY); Geometry intersection = IntersectUtils.intersection(cropROI, modelSpaceROI); Envelope2D e2d = JTS.getEnvelope2D( intersection.getEnvelopeInternal(), cropEnvelope.getCoordinateReferenceSystem()); GeneralEnvelope ge = new GeneralEnvelope((org.opengis.geometry.Envelope) e2d); cropEnvelope.setEnvelope(ge); } // // // // Build the new range by keeping into // account translation of grid geometry constructor for respecting // OGC PIXEL-IS-CENTER ImageDatum assumption. // // // final AffineTransform sourceWorldToGridTransform = sourceGridToWorldTransform.createInverse(); // // // // finalRasterArea will hold the smallest rectangular integer raster area that contains the // floating point raster // area which we obtain when applying the world-to-grid transform to the cropEnvelope. Note // that we need to intersect // such an area with the area covered by the source coverage in order to be sure we do not try // to crop outside the // bounds of the source raster. // // // final Rectangle2D finalRasterAreaDouble = XAffineTransform.transform( sourceWorldToGridTransform, cropEnvelope.toRectangle2D(), null); final Rectangle finalRasterArea = finalRasterAreaDouble.getBounds(); // intersection with the original range in order to not try to crop outside the image bounds Rectangle.intersect(finalRasterArea, sourceGridRange, finalRasterArea); if (finalRasterArea.isEmpty()) throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP)); // // // // It is worth to point out that doing a crop the G2W transform // should not change while the envelope might change as // a consequence of the rounding of the underlying image datum // which uses integer factors or in case the G2W is very // complex. Note that we will always strive to // conserve the original grid-to-world transform. // // // // we do not have to crop in this case (should not really happen at // this time) if (finalRasterArea.equals(sourceGridRange) && isSimpleTransform && cropROI == null) return sourceCoverage; // // // // if I get here I have something to crop // using the world-to-grid transform for going from envelope to the // new grid range. // // // final double minX = finalRasterArea.getMinX(); final double minY = finalRasterArea.getMinY(); final double width = finalRasterArea.getWidth(); final double height = finalRasterArea.getHeight(); // // // // Check if we need to use mosaic or crop // // // final PlanarImage croppedImage; final ParameterBlock pbj = new ParameterBlock(); pbj.addSource(sourceImage); java.awt.Polygon rasterSpaceROI = null; String operatioName = null; if (!isSimpleTransform || cropROI != null) { // ///////////////////////////////////////////////////////////////////// // // We don't have a simple scale and translate transform, JAI // crop MAY NOT suffice. Let's decide whether or not we'll use // the Mosaic. // // ///////////////////////////////////////////////////////////////////// Polygon modelSpaceROI = FeatureUtilities.getPolygon(cropEnvelope, GFACTORY); // // // // Now convert this polygon back into a shape for the source // raster space. // // // final List<Point2D> points = new ArrayList<Point2D>(5); rasterSpaceROI = FeatureUtilities.convertPolygonToPointArray( modelSpaceROI, ProjectiveTransform.create(sourceWorldToGridTransform), points); if (rasterSpaceROI == null || rasterSpaceROI.getBounds().isEmpty()) if (finalRasterArea.isEmpty()) throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP)); final boolean doMosaic = forceMosaic ? true : decideJAIOperation(roiTolerance, rasterSpaceROI.getBounds2D(), points); if (doMosaic || cropROI != null) { // prepare the params for the mosaic final ROI[] roiarr; try { if (cropROI != null) { final LiteShape2 cropRoiLS2 = new LiteShape2( cropROI, ProjectiveTransform.create(sourceWorldToGridTransform), null, false); ROI cropRS = new ROIShape(cropRoiLS2); Rectangle2D rt = cropRoiLS2.getBounds2D(); if (!hasIntegerBounds(rt)) { // Approximate Geometry Geometry geo = (Geometry) cropRoiLS2.getGeometry().clone(); transformGeometry(geo); cropRS = new ROIShape(new LiteShape2(geo, null, null, false)); } roiarr = new ROI[] {cropRS}; } else { final ROIShape roi = new ROIShape(rasterSpaceROI); roiarr = new ROI[] {roi}; } } catch (FactoryException ex) { throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP), ex); } pbj.add(MosaicDescriptor.MOSAIC_TYPE_OVERLAY); pbj.add(null); pbj.add(roiarr); pbj.add(null); pbj.add(CoverageUtilities.getBackgroundValues(sourceCoverage)); // prepare the final layout final Rectangle bounds = rasterSpaceROI.getBounds2D().getBounds(); Rectangle.intersect(bounds, sourceGridRange, bounds); if (bounds.isEmpty()) throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP)); // we do not have to crop in this case (should not really happen at // this time) if (!doMosaic && bounds.getBounds().equals(sourceGridRange) && isSimpleTransform) return sourceCoverage; // nice trick, we use the layout to do the actual crop final Rectangle boundsInt = bounds.getBounds(); layout.setMinX(boundsInt.x); layout.setWidth(boundsInt.width); layout.setMinY(boundsInt.y); layout.setHeight(boundsInt.height); operatioName = "Mosaic"; } } // do we still have to set the operation name? If so that means we have to go for crop. if (operatioName == null) { // executing the crop pbj.add((float) minX); pbj.add((float) minY); pbj.add((float) width); pbj.add((float) height); operatioName = "GTCrop"; } // // // // Apply operation // // // if (!useProvidedProcessor) { croppedImage = JAI.create(operatioName, pbj, targetHints); } else { croppedImage = processor.createNS(operatioName, pbj, targetHints); } // conserve the input grid to world transformation Map sourceProperties = sourceCoverage.getProperties(); Map properties = null; if (sourceProperties != null && !sourceProperties.isEmpty()) { properties = new HashMap(sourceProperties); } if (rasterSpaceROI != null) { if (properties != null) { properties.put("GC_ROI", rasterSpaceROI); } else { properties = Collections.singletonMap("GC_ROI", rasterSpaceROI); } } return new GridCoverageFactory(hints) .create( sourceCoverage.getName(), croppedImage, new GridGeometry2D( new GridEnvelope2D(croppedImage.getBounds()), sourceGridGeometry.getGridToCRS2D(PixelOrientation.CENTER), sourceCoverage.getCoordinateReferenceSystem()), (GridSampleDimension[]) (actionTaken == 1 ? null : sourceCoverage.getSampleDimensions().clone()), new GridCoverage[] {sourceCoverage}, properties); } catch (TransformException e) { throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP), e); } catch (NoninvertibleTransformException e) { throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP), e); } }
public void paint(Graphics g) { g2d = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); // Set the font for displaying the text information on the screen. g2d.setFont(new Font("Purisa", Font.PLAIN, 14)); // Set to gray and fill info window g2d.setColor(new Color(240, 240, 240)); g2d.fillRect(0, 0, infoWidth, windowHeight); // Set to white and fill the plot window g2d.setColor(new Color(255, 255, 255)); g2d.fillRect(infoWidth, 0, windowWidth, windowHeight); // Draw the axes g2d.setColor(new Color(0, 0, 0)); g2d.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // y axis g2d.drawLine( infoWidth + (axesWidth * 3 / 4) - 5, windowHeight - axesWidth * 3 / 4, infoWidth + (axesWidth * 3 / 4) - 5, edgeBuffer); // x axis g2d.drawLine( infoWidth + (axesWidth * 3 / 4), windowHeight - axesWidth * 3 / 4, windowWidth - edgeBuffer, windowHeight - axesWidth * 3 / 4); // Draw the ticks g2d.setStroke(new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); for (int i = 0; i < numTicks; i++) { // Horizontal ticks on y axis int vertTickPoint = i * ((windowHeight - axesWidth * 3 / 4) - edgeBuffer) / (numTicks - 1); g2d.drawLine( infoWidth + (axesWidth * 3 / 4) - tickLength - 5, edgeBuffer + vertTickPoint, infoWidth + (axesWidth * 3 / 4) + tickLength - 5, edgeBuffer + vertTickPoint); g2d.drawString( (float) (numTicks - 1 - i) * ((float) numReqs / (float) (numTicks - 1)) + "", infoWidth + (axesWidth * 3 / 4) - 60, edgeBuffer + vertTickPoint + 5); // Vertical ticks on x axis int horTickPoint = i * ((windowWidth - edgeBuffer) - (infoWidth + (axesWidth * 3 / 4))) / (numTicks - 1); g2d.drawLine( horTickPoint + (infoWidth + (axesWidth * 3 / 4)), windowHeight - axesWidth * 3 / 4 - tickLength, horTickPoint + (infoWidth + (axesWidth * 3 / 4)), windowHeight - axesWidth * 3 / 4 + tickLength); g2d.drawString( (float) (i) * ((float) execTime / (float) (numTicks - 1)) + "", horTickPoint + (infoWidth + (axesWidth * 3 / 4)) - 22, windowHeight - axesWidth * 3 / 4 + tickLength + 15); } // Draw the stepfunctionlines for (StepFunctionLine l : randLines) { l.setGraphics(g2d); l.drawStep(); } for (int i = 0; i < lines.size(); i++) { if (show[i] == true) { lines.get(i).setGraphics(g2d); lines.get(i).drawStep(); } } // Draw the plot info g2d.setColor(new Color(0, 0, 0)); g2d.drawString("Coverage: " + matrixFile, 17, 30); g2d.drawString("Timing: " + timeFile, 17, 50); g2d.drawString("Test Cases: " + lines.get(0).getNumTests(), 17, 70); // g2d.drawString("Execution Time: " + lines.get(0).getExecutionTime()+ " ms", 17, 70); // Draw a separator box g2d.drawRect(0, 0, infoWidth - 1, 85); ////////////////// Original and Reverse g2d.setStroke(new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // Draw vert lines between to delimit original/reverse buttons for (int i = 0; i <= 1; i++) { g2d.drawLine( originalGridStartX + i * gridSpacingX, originalGridStartY, originalGridStartX + i * gridSpacingX, originalGridStartY + oTechniques.length * gridSpacingY); } // Draw hor lines between to delimit original/reverse button grids for (int i = 0; i <= oTechniques.length; i++) { g2d.drawLine( originalGridStartX, originalGridStartY + i * gridSpacingY, originalGridStartX + gridSpacingX, originalGridStartY + i * gridSpacingY); } // Draw the text labels for the technique buttons for (int i = 0; i < oTechniques.length; i++) { g2d.drawString( oTechniques[i], originalGridStartX - originalLabelsOffsetX, originalGridStartY + originalLabelsOffsetY + i * gridSpacingY); } // The buttons for (int i = 0; i < 2; i++) { if (show[i] == true) { int row = i / 1; int col = i % 1; g2d.fillRect( originalGridStartX + col * gridSpacingX + buttonInsetX / 2, originalGridStartY + row * gridSpacingY + buttonInsetY / 2, gridSpacingX - buttonInsetX, gridSpacingY - buttonInsetY); } } // Labels over the controls g2d.drawString("Prioritization Techniques", originalGridStartX - 46, originalGridStartY - 30); g2d.drawString("Random Prioritizations", scrollBarStartX + 65, scrollBarStartY - 30); /////////////////////////// Big Button grid // Draw vert lines between to delimit buttons for (int i = 0; i <= gcm.length; i++) { g2d.drawLine( gridStartX + i * gridSpacingX, gridStartY, gridStartX + i * gridSpacingX, gridStartY + techniques.length * gridSpacingY); } // Draw hor lines between to delimit grids for (int i = 0; i <= techniques.length; i++) { g2d.drawLine( gridStartX, gridStartY + i * gridSpacingY, gridStartX + gcm.length * gridSpacingX, gridStartY + i * gridSpacingY); } // Draw the text labels for the technique buttons for (int i = 0; i < techniques.length; i++) { g2d.setColor(colors[i]); g2d.drawString( techniques[i], gridStartX - techniqueLabelsOffsetX, gridStartY + techniqueLabelsOffsetY + i * gridSpacingY); } g2d.setColor(Color.BLACK); // Draw the gcm labels for the technique buttons for (int i = 0; i < gcm.length; i++) { g2d.drawString( gcm[i], gridStartX + gcmLabelsOffsetX + i * gridSpacingX, gridStartY - gcmLabelsOffsetY); } // The buttons for (int i = 2; i < lines.size(); i++) { g2d.setColor(colors[(i - 2) / gcm.length]); if (show[i] == true) { int row = (i - 2) / gcm.length; int col = (i - 2) % gcm.length; g2d.fillRect( gridStartX + col * gridSpacingX + buttonInsetX / 2, gridStartY + row * gridSpacingY + buttonInsetY / 2, gridSpacingX - buttonInsetX, gridSpacingY - buttonInsetY); } } // Scroll Bar // g2d.drawLine(scrollBarStartX, scrollBarStartY, scrollBarStartX+scrollBarLength, // scrollBarStartY); g2d.setColor(Color.WHITE); g2d.fillRect( scrollBarStartX, scrollBarStartY - ((gridSpacingY - buttonInsetY) / 2), scrollBarLength, gridSpacingY - buttonInsetY); g2d.setColor(new Color(200, 200, 200)); g2d.fillRect( scrollBoxX, scrollBoxY - ((gridSpacingY - buttonInsetY) / 2), gridSpacingX - buttonInsetX, gridSpacingY - buttonInsetY); g2d.setColor(Color.BLACK); g2d.setFont(new Font("Purisa", Font.PLAIN, 18)); g2d.drawString(numRand + "", scrollBoxX + 26, scrollBoxY + 7); g2d.setFont(new Font("Purisa", Font.PLAIN, 14)); // Stats for random g2d.drawString("Avg CE: " + aveRandCE, scrollBarStartX - 5, scrollBarStartY + 29); g2d.drawString( "Running Avg CE: " + runningAveRandCE, scrollBarStartX - 5, scrollBarStartY + 49); g2d.drawString("St. Dev.: " + randSTDev, scrollBarStartX - 5, scrollBarStartY + 69); g2d.drawString( "Running St. Dev. " + runningRandSTDev, scrollBarStartX - 5, scrollBarStartY + 89); // axis labels g2d.setColor(Color.black); g2d.drawString( "Execution Time (ms)", (windowWidth - infoWidth) / 2 + infoWidth - 35, windowHeight - axesWidth * 3 / 4 + 45); g2d.translate((infoWidth + 15), (windowHeight / 2)); g2d.rotate(-Math.PI / 2); g2d.drawString("Covered Requirements", -55, -2); g2d.rotate(Math.PI / 2); }
/** * Sets a given rendering hint. * * @param key hint key * @param hint to be associated with key */ public void setRenderingHint(RenderingHints.Key key, Object hint) { // extra protection, failed on under MacOS X 10.2.6, jdk 1.4.1_01-39/14 if ((key == null) || (hint == null)) return; hints.put(key, hint); }