List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:business.model.CaptchaModel.java
/** * * @param CaptchaText// w w w . j a v a2 s. c o m * @return */ public static BufferedImage CreateCaptchaImageOld(String CaptchaText) { BufferedImage localBufferedImage = new BufferedImage(width, height, 1); try { Graphics2D localGraphics2D = localBufferedImage.createGraphics(); // List<Font> fonts = FontFactory.getListFont(); List<Font> fonts = new ArrayList<Font>(); if (fonts.isEmpty()) { fonts.add(new Font("Nimbus Roman No9 L", 1, 30)); fonts.add(new Font("VN-NTime", 1, 30)); fonts.add(new Font("DT-Times", 1, 30)); fonts.add(new Font("Times New Roman", 1, 30)); fonts.add(new Font("Vni-Book123", 1, 30)); fonts.add(new Font("VNI-Centur", 1, 30)); fonts.add(new Font("DT-Brookly", 1, 30)); } // fonts.add(loadFont("BINHLBI.TTF")); RenderingHints localRenderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); localRenderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); localGraphics2D.setRenderingHints(localRenderingHints); localGraphics2D.fillRect(0, 0, width, height); localGraphics2D.setColor(new Color(50, 50, 50)); Random localRandom = new Random(); int i = 0; int j = 0; for (int k = 0; k < CaptchaText.length(); k++) { i += 25 + Math.abs(localRandom.nextInt()) % 5; j = 25 + Math.abs(localRandom.nextInt()) % 20; int tmp = localRandom.nextInt(fonts.size() - 1); localGraphics2D.setFont(fonts.get(tmp)); localGraphics2D.drawChars(CaptchaText.toCharArray(), k, 1, i, j); } localBufferedImage = getDistortedImage(localBufferedImage); Graphics2D localGraphics2D2 = localBufferedImage.createGraphics(); localGraphics2D2.setRenderingHints(localRenderingHints); // localGraphics2D2.fillRect(0, 0, width, height); localGraphics2D2.setColor(new Color(50, 50, 50)); CubicCurve2D c = new CubicCurve2D.Double();// draw QuadCurve2D.Float with set coordinates for (int l = 0; l < 7; l++) { int x1 = Util.rand(0, width / 2); ; int x2 = Util.rand(width / 2, width); int y1 = Util.rand(0, height); int y2 = Util.rand(0, height); int ctrlx1 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly1 = y1; int ctrlx2 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly2 = y2; c.setCurve(x1, y1, ctrlx2, ctrly2, ctrlx1, ctrly1, x2, y2); localGraphics2D2.draw(c); // localGraphics2D2.drawLine(randomX1(), randomY1(), randomX2(), randomY2()); } localGraphics2D.dispose(); } catch (Exception e) { log.error(e.getMessage(), e); return null; } return localBufferedImage; }
From source file:org.n52.oxf.render.sos.AnimatedMapBarChartRenderer.java
protected Image renderFrame(ITimePosition[] sortedTimeArray, int currentTimeIndex, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> featuresWithCharts, ObservationSeriesCollection tupleFinder) { ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE);/*from ww w . j a v a 2 s . c o m*/ g.fillRect(0, 0, screenW, screenH); g.setColor(Color.BLACK); ITimePosition currentTimePos = sortedTimeArray[currentTimeIndex]; for (OXFFeature chartFeature : featuresWithCharts) { // // create Plot for each "chart feature" and add it to the cache: // if (!chartCache.contains(currentTimePos, chartFeature)) { // if there is a data tuple for the current time position -> create a new plot if (tupleFinder.getTuple(chartFeature, currentTimePos) != null) { CategoryPlot plot = drawChart4FOI(chartFeature.getID(), currentTimePos.toString(), tupleFinder.getTuple(chartFeature, currentTimePos)); chartCache.add(currentTimePos, chartFeature, plot); } } CategoryPlot plot = (CategoryPlot) chartCache.get(currentTimePos, chartFeature); // if there wasn't a plot for the current time position go backwards through the sortedTimeArray and take the most recent one: int j = currentTimeIndex - 1; while (plot == null && j >= 0) { plot = (CategoryPlot) chartCache.get(sortedTimeArray[j], chartFeature); j--; } // // draw the plots into the image at the georeferenced position of the corresponding chartFeature: // Point pRealWorld = (Point) chartFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); // if an appropriate plot was found -> draw it if (plot != null) { for (int i = 0; i < observedProperties.length; i++) { plot.getRangeAxis(i).setRange((Double) tupleFinder.getMinimum(i) - 5, (Double) tupleFinder.getMaximum(i)); if (i > 0) { plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); } } plot.draw(g, new Rectangle2D.Float(pScreen.x + X_SHIFT + 10, pScreen.y + Y_SHIFT, CHART_WIDTH + observedProperties.length * CHART_WIDTH_MULTIPLICATOR, CHART_HEIGHT), null, null, null); } // otherwise draw "no data available" else { g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT); } // draw point of feature: g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT); } return image; }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
/**Render default view if there is no timeframe yet*/ private void renderNoInfoView(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3))); g2d.fillRect(0, 0, getWidth(), getHeight()); Font f = g2d.getFont().deriveFont(Font.BOLD, 14.0f); g2d.setFont(f);/* ww w.ja v a 2 s.c om*/ Rectangle2D bounds = g2d.getFontMetrics().getStringBounds("Kein Zeitfenster aktiv", g); int dx = 10; if (getWidth() > bounds.getWidth()) { dx = (int) Math.rint((getWidth() - bounds.getWidth()) / 2); } int dy = 10; if (getHeight() > bounds.getHeight()) { dy = (int) Math.rint((getHeight() - bounds.getHeight()) / 2); } g2d.setColor(Color.black); g2d.drawString("Kein Zeitfenster aktiv", dx, dy); }
From source file:FieldValidator.java
@Override public void paint(Graphics g, JComponent c) { super.paint(g, c); JLayer jlayer = (JLayer) c; JFormattedTextField ftf = (JFormattedTextField) jlayer.getView(); if (!ftf.isEditValid()) { Graphics2D g2 = (Graphics2D) g.create(); // Paint the red X. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = c.getWidth(); int h = c.getHeight(); int s = 8; int pad = 4; int x = w - pad - s; int y = (h - s) / 2; g2.setPaint(Color.red);/* w w w . j av a2s . c o m*/ g2.fillRect(x, y, s + 1, s + 1); g2.setPaint(Color.white); g2.drawLine(x, y, x + s, y + s); g2.drawLine(x, y + s, x + s, y); g2.dispose(); } }
From source file:org.jas.gui.ImagePanel.java
@Override protected void paintComponent(Graphics g) { if (portrait == null) { super.paintComponent(g); return;//from w w w . jav a2s .com } try { // Create a translucent intermediate image in which we can perform the soft clipping GraphicsConfiguration gc = ((Graphics2D) g).getDeviceConfiguration(); BufferedImage intermediateBufferedImage = gc.createCompatibleImage(getWidth(), getHeight(), Transparency.TRANSLUCENT); Graphics2D bufferGraphics = intermediateBufferedImage.createGraphics(); // Clear the image so all pixels have zero alpha bufferGraphics.setComposite(AlphaComposite.Clear); bufferGraphics.fillRect(0, 0, getWidth(), getHeight()); // Render our clip shape into the image. Shape on where to paint bufferGraphics.setComposite(AlphaComposite.Src); bufferGraphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); bufferGraphics.setColor(Color.WHITE); bufferGraphics.fillRoundRect(0, 0, getWidth(), getHeight(), (int) (getWidth() * arcWidth), (int) (getHeight() * arcHeight)); // SrcAtop uses the alpha value as a coverage value for each pixel stored in the // destination shape. For the areas outside our clip shape, the destination // alpha will be zero, so nothing is rendered in those areas. For // the areas inside our clip shape, the destination alpha will be fully // opaque. bufferGraphics.setComposite(AlphaComposite.SrcAtop); bufferGraphics.drawImage(portrait, 0, 0, getWidth(), getHeight(), null); bufferGraphics.dispose(); // Copy our intermediate image to the screen g.drawImage(intermediateBufferedImage, 0, 0, null); } catch (Exception e) { log.warn("Error: Creating Renderings", e); } }
From source file:org.optaplanner.examples.flightcrewscheduling.swingui.FlightCrewSchedulingWorldPanel.java
public void resetPanel(FlightCrewSolution solution) { translator = new LatitudeLongitudeTranslator(); for (Airport airport : solution.getAirportList()) { translator.addCoordinates(airport.getLatitude(), airport.getLongitude()); }/*from w w w . j ava2s . c o m*/ Dimension size = getSize(); double width = size.getWidth(); double height = size.getHeight(); translator.prepareFor(width, height); Graphics2D g = createCanvas(width, height); g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE)); g.setColor(TangoColorFactory.PLUM_2); for (Airport airport : solution.getAirportList()) { int x = translator.translateLongitudeToX(airport.getLongitude()); int y = translator.translateLatitudeToY(airport.getLatitude()); g.fillRect(x - 1, y - 1, 3, 3); g.drawString(StringUtils.abbreviate(airport.getCode(), 20), x + 3, y - 3); } g.setColor(TangoColorFactory.CHOCOLATE_1); for (Flight flight : solution.getFlightList()) { Airport departureAirport = flight.getDepartureAirport(); Airport arrivalAirport = flight.getArrivalAirport(); translator.drawRoute(g, departureAirport.getLongitude(), departureAirport.getLatitude(), arrivalAirport.getLongitude(), arrivalAirport.getLatitude(), true, false); } g.setFont(g.getFont().deriveFont((float) TEXT_SIZE)); // Legend g.setColor(TangoColorFactory.PLUM_2); g.fillRect(6, (int) height - 11, 3, 3); g.drawString("Airport", 15, (int) height - 5); repaint(); }
From source file:fr.ign.cogit.geoxygene.appli.layer.LayerViewAwtPanel.java
private void saveImage() { LayerViewAwtPanel.logger.debug("record"); //$NON-NLS-1$ Color bg = this.getBackground(); BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setColor(bg);/*from w w w. j av a2 s. c o m*/ graphics.fillRect(0, 0, this.getWidth(), this.getHeight()); this.getRenderingManager().copyTo(graphics); this.recording = false; // this.paintOverlays(graphics); graphics.dispose(); try { NumberFormat format = NumberFormat.getInstance(); format.setMinimumIntegerDigits(3); ImgUtil.saveImage(image, this.recordFileName + format.format(this.recordIndex) + ".png"); //$NON-NLS-1$ this.recordIndex++; } catch (IOException e1) { e1.printStackTrace(); } }
From source file:test.unit.be.fedict.eid.applet.service.KmlGeneratorTest.java
@Test public void identityWithAddressAndPhotoKml() throws Exception { // setup/* ww w.j a v a 2 s . c o m*/ Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generateKml(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }
From source file:test.unit.be.fedict.eid.applet.service.PdfGeneratorTest.java
@Test public void identityWithAddressAndPhotoPdf() throws Exception { // setup//from w ww . j a v a 2 s.c om Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generatePdf(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }
From source file:test.unit.be.fedict.eid.applet.service.VcardGeneratorTest.java
@Test public void identityWithAddressAndPhotoVcard() throws Exception { // setup/*from www . j a v a2 s .c o m*/ Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generateVcard(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }