List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:ejemplo.grafica.java
public void paint(Graphics2D gd, JProgressBar t, int width, int height) { gd.setColor(color);//w w w . j a v a 2s . co m gd.fillRect(0, 0, width, height); }
From source file:at.tuwien.ifs.somtoolbox.visualization.ClusterConnectionsVisualizer.java
@Override public BufferedImage createVisualization(int variantIndex, GrowingSOM gsom, int width, int height) throws SOMToolboxException { GrowingLayer layer = gsom.getLayer(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); g.setBackground(Color.WHITE); g.clearRect(0, 0, width, height);//w ww. j a v a 2s. c o m // need to calculate some params relative to the unit width/height, which is relative to the desired output size // a unitWidth/Height of 10, as used previously, works by default only fine in the SOMViewer int somWidth = layer.getXSize(); int somHeight = layer.getYSize(); double unitWidth = width / somWidth; double unitHeight = height / somHeight; DoubleMatrix2D unitDistanceMatrix = gsom.getLayer().getUnitDistanceMatrix(); for (int col = 0; col < somWidth; col++) { for (int row = 0; row < somHeight; row++) { if (col < somWidth - 1) { // draw horizontal connection double distanceRight = unitDistanceMatrix.get(layer.getUnitIndex(col, row), layer.getUnitIndex(col + 1, row)); g.setPaint(getColor(distanceRight)); int xPos = (int) (col * unitHeight + unitHeight * 0.7); int yPos = (int) (row * unitWidth + unitWidth * 0.4); g.fillRect(xPos, yPos, (int) (unitWidth * 0.6), (int) (unitHeight * 0.2)); } if (row < somHeight - 1) { // draw vertical connection double distanceLower = unitDistanceMatrix.get(layer.getUnitIndex(col, row), layer.getUnitIndex(col, row + 1)); g.setPaint(getColor(distanceLower)); int xPos = (int) (col * unitHeight + unitHeight * 0.4); int yPos = (int) (row * unitWidth + unitWidth * 0.7); g.fillRect(xPos, yPos, (int) (unitWidth * 0.2), (int) (unitHeight * 0.6)); } } } return image; }
From source file:com.pronoiahealth.olhie.server.services.BookCoverImageService.java
/** * Create a back cover//from w w w . ja v a2s.c om * * @param coverId * @param titleStr * @param textColor * @param width * @param height * @param type * @param imgFormat * @param macColors * - for PNG images reduce the color palette (must be greater * than 2) * @return * @throws Exception */ public byte[] createBackCover(String coverId, String titleStr, String spineColor, String textColor, int width, int height, int type, ImageFormat imgFormat, int maxColors) throws Exception { Graphics2D g2D = null; try { // Front cover first // Read in base cover image BufferedImage coverImg = Imaging.getBufferedImage(coverMap.get(coverId)); // Resize cover image to the basic 300 X 400 for front cover BufferedImage backCoverImg = resize(coverImg, 300, 400, type); g2D = (Graphics2D) backCoverImg.getGraphics(); // Add title if present if (titleStr != null && titleStr.length() > 0) { BufferedImage titleTextImg = createText(82, 220, titleStr, textColor, true, backTitleFontMap, type); g2D.drawImage(titleTextImg, 40, 35, null); } // Add spine if present if (spineColor != null && spineColor.length() > 0) { g2D.setColor(Color.decode(spineColor)); g2D.fillRect(backCoverImg.getWidth() - 2, 0, 2, backCoverImg.getHeight()); } // If the requested size is not 300X400 convert the image BufferedImage outImg = null; if (width != 300 || height != 400) { outImg = resize(backCoverImg, width, height, type); } else { outImg = backCoverImg; } // Do we want a PNG with a fixed number of colors if (maxColors >= 2 && imgFormat == ImageFormat.IMAGE_FORMAT_PNG) { outImg = ImageUtils.reduce32(outImg, maxColors); } // Return bytes Map<String, Object> params = new HashMap<String, Object>(); byte[] outBytes = Imaging.writeImageToBytes(outImg, imgFormat, params); return outBytes; } finally { if (g2D != null) { g2D.dispose(); } } }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
private boolean redraw() { Village[][] mVisibleVillages = DataHolder.getSingleton().getVillages(); if (mVisibleVillages == null || mBuffer == null) { return false; }/*from w w w . j a v a 2s .c om*/ Graphics2D g2d = (Graphics2D) mBuffer.getGraphics(); Composite tempC = g2d.getComposite(); //clear g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g2d.fillRect(0, 0, mBuffer.getWidth(), mBuffer.getHeight()); //reset composite g2d.setComposite(tempC); boolean markPlayer = GlobalOptions.getProperties().getBoolean("mark.villages.on.minimap"); if (ServerSettings.getSingleton().getMapDimension() == null) { //could not draw minimap if dimensions are not loaded yet return false; } boolean showBarbarian = GlobalOptions.getProperties().getBoolean("show.barbarian"); Color DEFAULT = Constants.DS_DEFAULT_MARKER; try { int mark = Integer.parseInt(GlobalOptions.getProperty("default.mark")); if (mark == 0) { DEFAULT = Constants.DS_DEFAULT_MARKER; } else if (mark == 1) { DEFAULT = Color.RED; } else if (mark == 2) { DEFAULT = Color.WHITE; } } catch (Exception e) { DEFAULT = Constants.DS_DEFAULT_MARKER; } Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); double wField = mapDim.getWidth() / (double) visiblePart.width; double hField = mapDim.getHeight() / (double) visiblePart.height; UserProfile profile = GlobalOptions.getSelectedProfile(); Tribe currentTribe = InvalidTribe.getSingleton(); if (profile != null) { currentTribe = profile.getTribe(); } for (int i = visiblePart.x; i < (visiblePart.width + visiblePart.x); i++) { for (int j = visiblePart.y; j < (visiblePart.height + visiblePart.y); j++) { Village v = mVisibleVillages[i][j]; if (v != null) { Color markerColor = null; boolean isLeft = false; if (v.getTribe() == Barbarians.getSingleton()) { isLeft = true; } else { if ((currentTribe != null) && (v.getTribe().getId() == currentTribe.getId())) { //village is owned by current player. mark it dependent on settings if (markPlayer) { markerColor = Color.YELLOW; } } else { try { Marker marker = MarkerManager.getSingleton().getMarker(v.getTribe()); if (marker != null && !marker.isShownOnMap()) { marker = null; markerColor = DEFAULT; } if (marker == null) { marker = MarkerManager.getSingleton().getMarker(v.getTribe().getAlly()); if (marker != null && marker.isShownOnMap()) { markerColor = marker.getMarkerColor(); } } else { if (marker.isShownOnMap()) { markerColor = marker.getMarkerColor(); } } } catch (Exception e) { markerColor = null; } } } if (!isLeft) { if (markerColor != null) { g2d.setColor(markerColor); } else { g2d.setColor(DEFAULT); } g2d.fillRect((int) Math.round((i - visiblePart.x) * wField), (int) Math.round((j - visiblePart.y) * hField), (int) Math.floor(wField), (int) Math.floor(hField)); } else { if (showBarbarian) { g2d.setColor(Color.LIGHT_GRAY); g2d.fillRect((int) Math.round((i - visiblePart.x) * wField), (int) Math.round((j - visiblePart.y) * hField), (int) Math.floor(wField), (int) Math.floor(hField)); } } } } } try { if (GlobalOptions.getProperties().getBoolean("map.showcontinents")) { g2d.setColor(Color.BLACK); Composite c = g2d.getComposite(); Composite a = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f); Font f = g2d.getFont(); Font t = new Font("Serif", Font.BOLD, (int) Math.round(30 * hField)); g2d.setFont(t); int fact = 10; int mid = (int) Math.round(50 * wField); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { g2d.setComposite(a); String conti = "K" + (j * 10 + i); Rectangle2D bounds = g2d.getFontMetrics(t).getStringBounds(conti, g2d); int cx = i * fact * 10 - visiblePart.x; int cy = j * fact * 10 - visiblePart.y; cx = (int) Math.round(cx * wField); cy = (int) Math.round(cy * hField); g2d.drawString(conti, (int) Math.rint(cx + mid - bounds.getWidth() / 2), (int) Math.rint(cy + mid + bounds.getHeight() / 2)); g2d.setComposite(c); int wk = 100; int hk = 100; if (i == 9) { wk -= 1; } if (j == 9) { hk -= 1; } g2d.drawRect(cx, cy, (int) Math.round(wk * wField), (int) Math.round(hk * hField)); } } g2d.setFont(f); } } catch (Exception e) { logger.error("Creation of Minimap failed", e); } g2d.dispose(); return true; }
From source file:org.squidy.designer.zoom.ConnectorShape.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { super.paintShapeZoomedIn(paintContext); if (getInputPort().getVisible() || getOutputPort().getVisible()) { Graphics2D g = paintContext.getGraphics(); PBounds bounds = getBoundsReference(); double x = bounds.getX(); double y = bounds.getY(); double centerY = bounds.getCenterY(); double width = bounds.getWidth(); // Paint a border for zoom ports. // g.setStroke(new BasicStroke(6f)); // g.setColor(Color.RED); // g.draw(getBoundsReference()); // Painting left port. if (getInputPort().getVisible()) { if (shapePortLeft == null) { double portScale = inputPort.getScale(); double portWidth = inputPort.getWidth() * portScale; double portHeight = inputPort.getHeight() * portScale; shapePortLeft = new RoundRectangle2D.Double(x - portWidth + 15, centerY - portHeight / 2 - 5, 35, 60, 10, 10); }/*from w w w . j a v a 2 s . com*/ Rectangle boundsPort = shapePortLeft.getBounds(); g.setColor(Constants.Color.COLOR_SHAPE_BACKGROUND); if (isRenderPrimitiveRect()) g.fillRect(boundsPort.x, boundsPort.y, boundsPort.width, boundsPort.height); else g.fill(shapePortLeft); g.setColor(Constants.Color.COLOR_SHAPE_BORDER); g.setStroke(StrokeUtils.getBasicStroke(3f)); if (isRenderPrimitiveRect()) g.drawRect(boundsPort.x, boundsPort.y, boundsPort.width, boundsPort.height); else g.draw(shapePortLeft); } // Painting right port. if (getOutputPort().getVisible()) { if (shapePortRight == null) { double portScale = outputPort.getScale(); double portWidth = outputPort.getWidth() * portScale; double portHeight = outputPort.getHeight() * portScale; shapePortRight = new RoundRectangle2D.Double(x + width - portWidth - 21, centerY - portHeight / 2 - 5, 35, 60, 10, 10); } Rectangle boundsPort = shapePortRight.getBounds(); g.setColor(Constants.Color.COLOR_SHAPE_BACKGROUND); if (isRenderPrimitiveRect()) g.fillRect(boundsPort.x, boundsPort.y, boundsPort.width, boundsPort.height); else g.fill(shapePortRight); g.setColor(Constants.Color.COLOR_SHAPE_BORDER); g.setStroke(StrokeUtils.getBasicStroke(3f)); if (isRenderPrimitiveRect()) g.drawRect(boundsPort.x, boundsPort.y, boundsPort.width, boundsPort.height); else g.draw(shapePortRight); } } }
From source file:org.tsho.dmc2.core.chart.CowebRenderer.java
public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) { state = STATE_RUNNING;// w w w .jav a2s .co m if (plot.isAlpha()) { g2.setComposite(AlphaComposite.SrcOver); } Stepper.Point2D result = stepper.getCurrentPoint2D(); int transX, transY; double start = (int) dataArea.getMinX(); double end = (int) dataArea.getMaxX(); double[] value = new double[1]; int prevY = 0; boolean flagOld = false; boolean flagNew = false; label: for (double i = start; i <= end; i += 1) { value[0] = this.domainAxis.java2DToValue(i, dataArea, RectangleEdge.BOTTOM); stepper.setInitialValue(value); stepper.initialize(); for (int j = 0; j < power; j++) { stepper.step(); } result = stepper.getCurrentPoint2D(); transX = (int) i; transY = (int) rangeAxis.valueToJava2D(result.getX(), dataArea, RectangleEdge.LEFT); flagNew = Double.isNaN(result.getX()); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i > start) { if (!flagOld && !flagNew) g2.drawLine(transX, transY, transX - 1, prevY); } prevY = transY; flagOld = flagNew; } if (stopped) { state = STATE_STOPPED; return; } } if (animate) { animateCowebPlot(g2, dataArea); } state = STATE_FINISHED; }
From source file:com.codename1.android.AndroidLayoutImporter.java
Border createImageBorder(String imageName) { Image im = outputResources.getImage(imageName); if (im == null) { return null; }/*from ww w .j a v a2 s. c o m*/ EncodedImage eim = null; if (im instanceof EncodedImage) { eim = (EncodedImage) im; } else { eim = EncodedImage.createFromImage(im, imageName.endsWith(".jpg")); } BufferedImage center = new BufferedImage(1, im.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) center.createGraphics(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g2.fillRect(0, 0, im.getWidth(), im.getHeight()); g2.dispose(); EncodedImage placeholder = EncodedImage.create(toPng(center)); outputResources.setImage("TransparentPlaceholer" + center.getWidth() + "x" + center.getHeight() + ".png", placeholder); return Border.createHorizonalImageBorder(eim, placeholder, placeholder); }
From source file:org.cruk.mga.CreateReport.java
/** * Creates a summary plot for the given set of multi-genome alignment summaries. * * @param multiGenomeAlignmentSummaries/*from www . j a v a 2s. c o m*/ * @param the name of the image file * @throws IOException */ private void createSummaryPlot(Collection<MultiGenomeAlignmentSummary> multiGenomeAlignmentSummaries, String imageFilename) throws IOException { if (imageFilename == null) return; int n = multiGenomeAlignmentSummaries.size(); log.debug("Number of summaries = " + n); scaleForPlotWidth(); int fontHeight = getFontHeight(); int rowHeight = (int) (fontHeight * ROW_HEIGHT_SCALING_FACTOR); int labelOffset = (rowHeight - fontHeight) / 2; int rowGap = (int) (fontHeight * ROW_GAP_SCALING_FACTOR); int height = (rowHeight + rowGap) * (n + 3); int rowSeparation = rowHeight + rowGap; BufferedImage image = new BufferedImage(plotWidth, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setStroke(new BasicStroke(Math.max(1.0f, 0.65f * scaleFactor))); g2.setFont(font); g2.setColor(Color.WHITE); g2.fillRect(0, 0, plotWidth, height); g2.setColor(Color.BLACK); int offset = rowGap + rowHeight - labelOffset; int x0 = drawLabels(g2, offset, rowSeparation, multiGenomeAlignmentSummaries); long maxSequenceCount = getMaximumSequenceCount(multiGenomeAlignmentSummaries); log.debug("Maximum sequence count: " + maxSequenceCount); maxSequenceCount = Math.max(maxSequenceCount, minimumSequenceCount); long tickInterval = (int) getTickInterval(maxSequenceCount); log.debug("Tick interval: " + tickInterval); int tickIntervals = (int) (Math.max(1, maxSequenceCount) / tickInterval); if (maxSequenceCount % tickInterval != 0) tickIntervals += 1; maxSequenceCount = tickIntervals * tickInterval; log.debug("No. tick intervals: " + tickIntervals); log.debug("Maximum sequence count: " + maxSequenceCount); int y = rowGap + n * rowSeparation; int x1 = drawAxisAndLegend(g2, x0, y, tickIntervals, maxSequenceCount); offset = rowGap; drawAlignmentBars(g2, offset, rowHeight, rowSeparation, x0, x1, maxSequenceCount, multiGenomeAlignmentSummaries); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(imageFilename)); ImageIO.write(image, "png", out); out.close(); }
From source file:Filter3dTest.java
public void draw(Graphics2D g) { // draw background g.setColor(new Color(0x33cc33)); g.fillRect(0, 0, screen.getWidth(), screen.getHeight()); // draw listener g.drawImage(listener.getImage(), Math.round(listener.getX()), Math.round(listener.getY()), null); // draw fly/*from w w w . ja v a2 s. c o m*/ g.drawImage(fly.getImage(), Math.round(fly.getX()), Math.round(fly.getY()), null); }
From source file:WeatherWizard.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension size = getSize();//from w w w.j av a 2 s .c o m Composite origComposite; setupWeatherReport(); origComposite = g2.getComposite(); if (alpha0 != null) g2.setComposite(alpha0); g2.drawImage(img0, 0, 0, size.width, size.height, 0, 0, img0.getWidth(null), img0.getHeight(null), null); if (img1 != null) { if (alpha1 != null) g2.setComposite(alpha1); g2.drawImage(img1, 0, 0, size.width, size.height, 0, 0, img1.getWidth(null), img1.getHeight(null), null); } g2.setComposite(origComposite); // Freezing, Cold, Cool, Warm, Hot, // Blue, Green, Yellow, Orange, Red Font font = new Font("Serif", Font.PLAIN, 36); g.setFont(font); String tempString = feels + " " + temperature + "F"; FontRenderContext frc = ((Graphics2D) g).getFontRenderContext(); Rectangle2D boundsTemp = font.getStringBounds(tempString, frc); Rectangle2D boundsCond = font.getStringBounds(condStr, frc); int wText = Math.max((int) boundsTemp.getWidth(), (int) boundsCond.getWidth()); int hText = (int) boundsTemp.getHeight() + (int) boundsCond.getHeight(); int rX = (size.width - wText) / 2; int rY = (size.height - hText) / 2; g.setColor(Color.LIGHT_GRAY); g2.fillRect(rX, rY, wText, hText); g.setColor(textColor); int xTextTemp = rX - (int) boundsTemp.getX(); int yTextTemp = rY - (int) boundsTemp.getY(); g.drawString(tempString, xTextTemp, yTextTemp); int xTextCond = rX - (int) boundsCond.getX(); int yTextCond = rY - (int) boundsCond.getY() + (int) boundsTemp.getHeight(); g.drawString(condStr, xTextCond, yTextCond); }