List of usage examples for java.awt Graphics fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:FancyCaret.java
public void paint(Graphics g) { JTextComponent comp = getComponent(); if (comp == null) return;/*from w w w . j ava 2 s.c o m*/ int dot = getDot(); Rectangle r = null; char dotChar; try { r = comp.modelToView(dot); if (r == null) return; dotChar = comp.getText(dot, 1).charAt(0); } catch (BadLocationException e) { return; } if ((x != r.x) || (y != r.y)) { repaint(); x = r.x; y = r.y; height = r.height; } g.setColor(comp.getCaretColor()); g.setXORMode(comp.getBackground()); if (dotChar == '\n') { int diam = r.height; if (isVisible()) g.fillArc(r.x - diam / 2, r.y, diam, diam, 270, 180); // half circle width = diam / 2 + 2; return; } if (dotChar == '\t') try { Rectangle nextr = comp.modelToView(dot + 1); if ((r.y == nextr.y) && (r.x < nextr.x)) { width = nextr.x - r.x; if (isVisible()) g.fillRoundRect(r.x, r.y, width, r.height, 12, 12); return; } else dotChar = ' '; } catch (BadLocationException e) { dotChar = ' '; } width = g.getFontMetrics().charWidth(dotChar); if (isVisible()) g.fillRect(r.x, r.y, width, r.height); }
From source file:com.jcraft.weirdx.Draw.java
static void reqImageText16(Client c, XDrawable d, GC gc, int x, int y) throws IOException { int len = c.data; int n = c.length; //int foo;//from w w w. j a va 2s . co m Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCFont); if (graphics == null) { c.client.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(4); n--; } return; } } XFont font = gc.font; n *= 4; c.client.readByte(c.bbuffer, 0, n); len *= 2; if (font.encoding != null) { len = font.encode(c.bbuffer, 0, len, c.cbuffer); if (len == 0) { return; } } else { for (int i = 0; i < len; i++) { c.cbuffer[i] = (char) (c.bbuffer[i] & 0xff); } for (int i = 0; i < len; i++) { if (c.cbuffer[i] != 0) { c.cbuffer[i / 2] = c.cbuffer[i]; } } len /= 2; } { Color tmp = graphics.getColor(); graphics.setColor(d.getColormap().getColor(gc.bgPixel)); graphics.fillRect(x, y - (font.ascent), font.charsWidth(c.cbuffer, 0, len), font.ascent + font.descent); graphics.setColor(tmp); graphics.drawChars(c.cbuffer, 0, len, x, y); } if (d instanceof XWindow) { ((XWindow) d).draw(x, y - (font.ascent), font.charsWidth(c.cbuffer, 0, len), font.ascent + font.descent); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java
/** * Draw depth of coverage for the starting or ending flanking region * * @param g2D/*from www. j a v a 2s . c om*/ * @param pixelStart * @param pixelLength * @param regionDepthArray * @param maxPossibleArcHeight * @param trackRectangle * @param isPositiveStrand */ protected void drawFlankingRegion(Graphics g2D, int pixelStart, int pixelLength, int[] regionDepthArray, int maxPossibleArcHeight, Rectangle trackRectangle, boolean isPositiveStrand) { for (int i = 0; i < pixelLength; i++) { float arrayIndicesPerPixel = (float) regionDepthArray.length / (float) pixelLength; int flankingRegionArrayPixelMinIndex = (int) (i * arrayIndicesPerPixel); int flankingRegionArrayPixelMaxIndex = (int) ((i + 1) * arrayIndicesPerPixel); flankingRegionArrayPixelMinIndex = Math.max(0, Math.min(flankingRegionArrayPixelMinIndex, regionDepthArray.length - 1)); flankingRegionArrayPixelMaxIndex = Math.max(0, Math.min(flankingRegionArrayPixelMaxIndex, regionDepthArray.length - 1)); int meanDepthThisPixel = 0; for (int j = flankingRegionArrayPixelMinIndex; j <= flankingRegionArrayPixelMaxIndex; j++) meanDepthThisPixel += regionDepthArray[j]; meanDepthThisPixel /= (flankingRegionArrayPixelMaxIndex - flankingRegionArrayPixelMinIndex + 1); meanDepthThisPixel = Math.min(maxDepth, meanDepthThisPixel); int pixelHeight = Math.max(maxPossibleArcHeight * meanDepthThisPixel / maxDepth, 2); g2D.fillRect(pixelStart + i, (int) trackRectangle.getCenterY() + (isPositiveStrand ? -pixelHeight : 0), 1, pixelHeight); } }
From source file:org.apache.cayenne.swing.components.textpane.JCayenneTextPane.java
public void paint(Graphics g) { super.paint(g); int start = getStartPositionInDocument(); int end = getEndPositionInDocument(); // end pos in doc // translate offsets to lines Document doc = pane.getDocument(); int startline = doc.getDefaultRootElement().getElementIndex(start) + 1; int endline = doc.getDefaultRootElement().getElementIndex(end) + 1; int fontHeight = g.getFontMetrics(pane.getFont()).getHeight(); int fontDesc = g.getFontMetrics(pane.getFont()).getDescent(); int starting_y = -1; try {//from w w w.j a v a 2 s . c o m if (pane.modelToView(start) == null) { starting_y = -1; } else { starting_y = pane.modelToView(start).y - scrollPane.getViewport().getViewPosition().y + fontHeight - fontDesc; } } catch (Exception e1) { logObj.warn("Error: ", e1); } for (int line = startline, y = starting_y; line <= endline; y += fontHeight, line++) { Color color = g.getColor(); if (line - 1 == doc.getDefaultRootElement().getElementIndex(pane.getCaretPosition())) { g.setColor(new Color(224, 224, 255)); g.fillRect(0, y - fontHeight + 3, 30, fontHeight + 1); } if (imageError) { Image img = ModelerUtil.buildIcon("error.gif").getImage(); g.drawImage(img, 0, endYPositionToolTip, this); } g.setColor(color); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * @see Graphics#drawImage(Image, int, int, int, int, int, int, int, int, Color, ImageObserver) */// w w w .jav a 2 s.c om @Override public boolean drawImage(final Image img, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2, final Color bgcolor, final ImageObserver observer) { waitForImage(img); final double dwidth = (double) dx2 - dx1; final double dheight = (double) dy2 - dy1; final double swidth = (double) sx2 - sx1; final double sheight = (double) sy2 - sy1; // if either width or height is 0, then there is nothing to draw if (dwidth == 0 || dheight == 0 || swidth == 0 || sheight == 0) { return true; } final double scalex = dwidth / swidth; final double scaley = dheight / sheight; final double transx = sx1 * scalex; final double transy = sy1 * scaley; final AffineTransform tx = AffineTransform.getTranslateInstance(dx1 - transx, dy1 - transy); tx.scale(scalex, scaley); final BufferedImage mask = new BufferedImage(img.getWidth(observer), img.getHeight(observer), BufferedImage.TYPE_BYTE_BINARY); final Graphics g = mask.getGraphics(); g.fillRect(sx1, sy1, (int) swidth, (int) sheight); drawImage(img, mask, tx, null, observer); g.dispose(); return true; }
From source file:tilt.image.page.Line.java
/** * Print the shapes onto the original image * @param g the graphics environment//w w w . j a va2 s .c o m * @param wr the raster to write on * @param n the number of the line */ public void print(Graphics g, WritableRaster wr, int n) { Color tColour; if (n % 3 == 0) tColour = new Color(255, 0, 0, 128); else if (n % 3 == 1) tColour = new Color(0, 255, 0, 128); else tColour = new Color(0, 0, 255, 128); Color old = g.getColor(); if (shapes.size() > 0) { Rectangle bounds = shapes.get(0).getBounds(); g.setColor(Color.black); g.drawString(Integer.toString(n), bounds.x - 20, (bounds.y * 2 + bounds.height) / 2); } for (int i = 0; i < shapes.size(); i++) { Shape s = shapes.get(i); g.setColor(tColour); if (s instanceof Polygon) g.fillPolygon((Polygon) s); else if (s instanceof Rectangle) { Rectangle r = (Rectangle) s; g.fillRect(r.x, r.y, r.width, r.height); } } g.setColor(old); }
From source file:es.emergya.ui.gis.CustomMapView.java
/** * Dibuja una brujula apuntando al norte * // w w w. j a va2 s . c o m * @param g */ @SuppressWarnings("unused") private void drawCompass(Graphics g) { int x = 50, y = getHeight() - 50; // ((Graphics2D)g).rotate(Math.PI + lastFollowAngle, x, y); ((Graphics2D) g).rotate(-PI_MEDIO - getAngle(), x, y); g.setColor(Color.LIGHT_GRAY); g.fillOval(0, getHeight() - 100, 100, 100); g.setColor(Color.BLACK); g.fillRect(x - 3, y - 3, 50, 6); g.setColor(Color.RED); g.fillRect(x + 42, y - 3, 6, 6); }
From source file:org.executequery.gui.editor.QueryEditorTextPane.java
/** * Paints the current line highlight and right-hand margin * before a call to the super class.// w ww .j av a 2 s . co m * * @param g the <code>Graphics</code> object to protect */ public void paintComponent(Graphics g) { int height = getHeight(); int width = getWidth(); g.setColor(getBackground()); g.fillRect(0, 0, width, height); // paint the current line highlight if (QueryEditorSettings.isDisplayLineHighlight()) { int currentRow = getCurrentCursorRow(); g.setColor(QueryEditorSettings.getLineHighlightColour()); g.fillRect(1, (currentRow * fontHeight) + 2, width - 1, fontHeight); } // paint the right-hand margin if (QueryEditorSettings.isDisplayRightMargin()) { int xPosn = fontWidth * QueryEditorSettings.getRightMarginSize(); g.setColor(QueryEditorSettings.getRightMarginColour()); g.drawLine(xPosn, 0, xPosn, height); } try { super.paintComponent(g); } catch (Exception e) { } }
From source file:VASSAL.build.module.map.LOS_Thread.java
/** * Writes text showing the range/*from www . j a v a 2 s . c o m*/ * * @param range the range to display, in whatever units returned * by the {@link MapGrid} containing the thread */ public void drawRange(Graphics g, int range) { Point mapArrow = map.componentCoordinates(arrow); Point mapAnchor = map.componentCoordinates(anchor); g.setColor(Color.black); g.setFont(RANGE_FONT); final FontMetrics fm = g.getFontMetrics(); final StringBuilder buffer = new StringBuilder(); int dummy = range; while (dummy >= 1) { dummy = dummy / 10; buffer.append("8"); } if (buffer.length() == 0) { buffer.append("8"); } String rangeMess = Resources.getString("LOS_Thread.range"); int wid = fm.stringWidth(" " + rangeMess + " " + buffer.toString()); int hgt = fm.getAscent() + 2; int w = mapArrow.x - mapAnchor.x; int h = mapArrow.y - mapAnchor.y; int x0 = mapArrow.x + (int) ((wid / 2 + 20) * w / Math.sqrt(w * w + h * h)); int y0 = mapArrow.y + (int) ((hgt / 2 + 20) * h / Math.sqrt(w * w + h * h)); g.fillRect(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid, hgt); g.setColor(Color.white); g.drawString(rangeMess + " " + range, x0 - wid / 2 + fm.stringWidth(" "), y0 + hgt / 2); lastRangeRect = new Rectangle(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid + 1, hgt + 1); Point np = map.mapCoordinates(new Point(lastRangeRect.x, lastRangeRect.y)); lastRangeRect.x = np.x; lastRangeRect.y = np.y; lastRange = String.valueOf(range); }
From source file:org.prom5.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * paints this log item panel and all contained log items as specified. * @param g the graphics object used for painting *///w w w. j a v a 2 s . c o m public void paintComponent(Graphics grx) { selectedIDIndices.clear(); // for exporting bDrawLine = dca.getSettingPanel().isDrawLine(); //todo bBottleneck = dca.getSettingPanel().isBottleneck(); bBottleneckforInstances = dca.getSettingPanel().isBottleneckforInstance(); double percentileL = dcModel.getOverallStatistics().getPercentile(dca.getSettingPanel().getPercentileL()); double percentileU = dcModel.getOverallStatistics().getPercentile(dca.getSettingPanel().getPercentileU()); Graphics gr = grx.create(); if (this.isOpaque()) { gr.setColor(colorBg); gr.fillRect(0, 0, getWidth(), getHeight()); } // paint the time indicator equipped component lane paintComponentLane(gr); // calculate are to be painted int height = (int) ((double) (getHeight() - (2 * border))); int unitHeight = height / getHashMapSize(); int currentTop = 0; // paint items if (dcModel.getItemMap().size() > 0) { String key = null; AbstractLogUnit item = null; // iterate through sets int index = 0; for (Iterator itSets = dcModel.getSortedKeySetList().iterator(); itSets.hasNext();) { key = (String) itSets.next(); // if key is not in instanceIDs, skip.. if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(key)) continue; currentTop = unit2Cord(index) + unitHeight / 2; LogUnitList tempUnitList = new LogUnitList(); AbstractLogUnit olditem = null; // for bottleneck boolean bInstances = false; boolean flag = true; if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances) { LogUnitList tempUnitList2; tempUnitList2 = ((LogUnitList) dcModel.getItemMap().get(key)); double percentile2L = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceL()); double percentile2U = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceU()); long tempDuration = (tempUnitList2 .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()) .getTime() - tempUnitList2.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()).getTime()); if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances && tempDuration >= percentile2L && tempDuration <= percentile2U) bInstances = true; } // end for bottleneck //////// // iterate through items for (Iterator itItm = ((LogUnitList) dcModel.getItemMap().get(key)).iterator(); itItm.hasNext();) { item = (AbstractLogUnit) itItm.next(); if (dcModel.getEventTypeToKeep() != null && (!dcModel.getEventTypeToKeep().contains(item.getType()) || !dcModel .getInstanceTypeToKeep().contains(item.getProcessInstance().getName()))) continue; if (bDrawLine && item.getType().equals(dca.getSettingPanel().getStartEvent())) tempUnitList.addEvent(item); assignColorByItem(item, gr); clipL = (int) gr.getClipBounds().getMinX() - 1; clipR = (int) gr.getClipBounds().getMaxX() + 1; long clipLeftTs2 = coord2timeMillis(clipL); long clipRightTs2 = coord2timeMillis(clipR); // if line is added if (bDrawLine && item.getType().equals(dca.getSettingPanel().getEndEvent())) { for (Iterator itr = tempUnitList.iterator(); itr.hasNext();) { AbstractLogUnit item2 = (AbstractLogUnit) itr.next(); if (item2.getElement().equals(item.getElement()) && item2.getProcessInstance().equals(item.getProcessInstance())) { paintItemLine(time2coord(item2.getCurrentTimeStamp()) + border, currentTop, time2coord(item.getCurrentTimeStamp()) + border, gr); tempUnitList.removeEvent(item2); break; } } } // if item is not shown on the screen, ship drawing if (item.getCurrentTimeStamp() == null || item.getCurrentTimeStamp().getTime() < clipLeftTs2 || item.getCurrentTimeStamp().getTime() > clipRightTs2) continue; // for botteleneck if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneck && olditem != null && (item.getCurrentTimeStamp().getTime() - olditem.getCurrentTimeStamp().getTime()) >= percentileL && (item.getCurrentTimeStamp().getTime() - olditem.getCurrentTimeStamp().getTime()) <= percentileU) { paintItemLineBottleneck(time2coord(olditem.getCurrentTimeStamp()) + border, currentTop, time2coord(item.getCurrentTimeStamp()) + border, gr); this.paintHighligtedItem(time2coord(olditem.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(olditem)); this.paintHighligtedItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); this.addExportingList(item); olditem = item; continue; } // paint an item if (bInstances) { this.paintHighligtedItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); if (flag) { this.addExportingList(item); flag = false; } } else { this.paintItem(time2coord(item.getCurrentTimeStamp()) + border, currentTop, gr, assignShapeByItem(item)); } olditem = item; } // move y point index++; } } // to do box for zoom if (p1 != null && p2 != null) { int x1 = Math.min(p1.x, p2.x); int y1 = Math.min(p1.y, p2.y); int width = Math.abs(p1.x - p2.x); height = Math.abs(p1.y - p2.y); grx.drawRect(x1, y1, width, height); } // for exporting if (selectedIDIndices.size() > 0) { int tempArray[] = new int[selectedIDIndices.size()]; int i = 0; for (Iterator itr = selectedIDIndices.iterator(); itr.hasNext();) { tempArray[i++] = (int) ((Integer) itr.next()); } dca.setSelectedInstanceIndicesfromScreen(tempArray); } }