List of usage examples for java.awt RenderingHints VALUE_ANTIALIAS_ON
Object VALUE_ANTIALIAS_ON
To view the source code for java.awt RenderingHints VALUE_ANTIALIAS_ON.
Click Source Link
From source file:savant.view.swing.GraphPane.java
public boolean render(Graphics2D g2, Range xRange, Range yRange) { LOG.trace("GraphPane.render(g2, " + xRange + ", " + yRange + ")"); double oldUnitHeight = unitHeight; int oldYMax = yMax; // Paint a gradient from top to bottom GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0, getHeight(), ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM)); g2.setPaint(gp0);/*from www. j a v a2 s .c om*/ g2.fillRect(0, 0, getWidth(), getHeight()); GraphPaneController gpc = GraphPaneController.getInstance(); LocationController lc = LocationController.getInstance(); JScrollBar scroller = getVerticalScrollBar(); if (gpc.isPanning() && !isLocked()) { double fromX = transformXPos(gpc.getMouseClickPosition()); double toX = transformXPos(gpc.getMouseReleasePosition()); g2.translate(toX - fromX, 0); } // Deal with the progress-bar. if (tracks == null) { parentFrame.updateProgress(); return false; } else { for (Track t : tracks) { if (t.getRenderer().isWaitingForData()) { String progressMsg = (String) t.getRenderer().getInstruction(DrawingInstruction.PROGRESS); setPreferredSize(new Dimension(getWidth(), 0)); showProgress(progressMsg, -1.0); return false; } } } if (progressPanel != null) { remove(progressPanel); progressPanel = null; } int minYRange = Integer.MAX_VALUE; int maxYRange = Integer.MIN_VALUE; AxisType bestYAxis = AxisType.NONE; for (Track t : tracks) { // ask renderers for extra info on range; consolidate to maximum Y range AxisRange axisRange = (AxisRange) t.getRenderer().getInstruction(DrawingInstruction.AXIS_RANGE); if (axisRange != null) { int axisYMin = axisRange.getYMin(); int axisYMax = axisRange.getYMax(); if (axisYMin < minYRange) { minYRange = axisYMin; } if (axisYMax > maxYRange) { maxYRange = axisYMax; } } // Ask renderers if they want horizontal grid-lines; if any say yes, draw them. switch (t.getYAxisType(t.getResolution(xRange))) { case INTEGER_GRIDLESS: if (bestYAxis == AxisType.NONE) { bestYAxis = AxisType.INTEGER_GRIDLESS; } break; case INTEGER: if (bestYAxis != AxisType.REAL) { bestYAxis = AxisType.INTEGER; } break; case REAL: bestYAxis = AxisType.REAL; break; } } setXAxisType(tracks[0].getXAxisType(tracks[0].getResolution(xRange))); setXRange(xRange); setYAxisType(bestYAxis); Range consolidatedYRange = new Range(minYRange, maxYRange); setYRange(consolidatedYRange); consolidatedYRange = new Range(yMin, yMax); DrawingMode currentMode = tracks[0].getDrawingMode(); boolean sameRange = (prevRange != null && xRange.equals(prevRange)); if (!sameRange) { PopupPanel.hidePopup(); } boolean sameMode = currentMode == prevMode; boolean sameSize = prevSize != null && getSize().equals(prevSize) && parentFrame.getFrameLandscape().getWidth() == oldWidth && parentFrame.getFrameLandscape().getHeight() == oldHeight; boolean sameRef = prevRef != null && lc.getReferenceName().equals(prevRef); boolean withinScrollBounds = bufferedImage != null && scroller.getValue() >= getOffset() && scroller.getValue() < getOffset() + getViewportHeight() * 2; //bufferedImage stores the current graphic for future use. If nothing //has changed in the track since the last render, bufferedImage will //be used to redraw the current view. This method allows for fast repaints //on tracks where nothing has changed (panning, selection, plumbline,...) //if nothing has changed draw buffered image if (sameRange && sameMode && sameSize && sameRef && !renderRequired && withinScrollBounds) { g2.drawImage(bufferedImage, 0, getOffset(), this); renderCurrentSelected(g2); //force unitHeight from last render unitHeight = oldUnitHeight; yMax = oldYMax; } else { // Otherwise prepare for new render. renderRequired = false; int h = getHeight(); if (!forcedHeight) { h = Math.min(h, getViewportHeight() * 3); } LOG.debug("Requesting " + getWidth() + "\u00D7" + h + " bufferedImage."); bufferedImage = new BufferedImage(getWidth(), h, BufferedImage.TYPE_INT_RGB); if (bufferedImage.getHeight() == getHeight()) { setOffset(0); } else { setOffset(scroller.getValue() - getViewportHeight()); } LOG.debug("Rendering fresh " + bufferedImage.getWidth() + "\u00D7" + bufferedImage.getHeight() + " bufferedImage at (0, " + getOffset() + ")"); Graphics2D g3 = bufferedImage.createGraphics(); g3.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); prevRange = xRange; prevSize = getSize(); prevMode = tracks[0].getDrawingMode(); prevRef = lc.getReferenceName(); renderBackground(g3, xAxisType == AxisType.INTEGER || xAxisType == AxisType.REAL, yAxisType == AxisType.INTEGER || yAxisType == AxisType.REAL); // Call the actual render() methods. boolean nothingRendered = true; String message = null; int priority = -1; for (Track t : tracks) { // Change renderers' drawing instructions to reflect consolidated YRange AxisRange axes = (AxisRange) t.getRenderer().getInstruction(DrawingInstruction.AXIS_RANGE); if (axes == null) { axes = new AxisRange(xRange, consolidatedYRange); } else { axes = new AxisRange(axes.getXRange(), consolidatedYRange); } //System.out.println("Consolidated y range for " + t.getName() + " is " + consolidatedYRange); t.getRenderer().addInstruction(DrawingInstruction.AXIS_RANGE, axes); try { t.getRenderer().render(g3, this); nothingRendered = false; } catch (RenderingException rx) { if (rx.getPriority() > priority) { // If we have more than one message with the same priority, the first one will end up being drawn. message = rx.getMessage(); priority = rx.getPriority(); } } catch (Throwable x) { // Renderer itself threw an exception. LOG.error("Error rendering " + t, x); message = MiscUtils.getMessage(x); priority = RenderingException.ERROR_PRIORITY; } } if (nothingRendered && message != null) { setPreferredSize(new Dimension(getWidth(), 0)); revalidate(); drawMessage(g3, message); } updateYMax(); // If a change has occured that affects scrollbar... if (paneResize) { paneResize = false; // Change size of current frame if (getHeight() != newHeight) { Dimension newSize = new Dimension(getWidth(), newHeight); setPreferredSize(newSize); setSize(newSize); parentFrame.validate(); // Ensures that scroller.getMaximum() is up to date. // If pane is resized, scrolling always starts at the bottom. The only place // where looks wrong is when we have a continuous track with negative values. scroller.setValue(scroller.getMaximum()); repaint(); return false; } } else if (oldViewHeight != -1 && oldViewHeight != getViewportHeight()) { int newViewHeight = getViewportHeight(); int oldScroll = scroller.getValue(); scroller.setValue(oldScroll + (oldViewHeight - newViewHeight)); oldViewHeight = newViewHeight; } oldWidth = parentFrame.getFrameLandscape().getWidth(); oldHeight = parentFrame.getFrameLandscape().getHeight(); g2.drawImage(bufferedImage, 0, getOffset(), this); fireExportEvent(xRange, bufferedImage); renderCurrentSelected(g2); } return true; }
From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java
/** * Draw a filled arc representing a single feature. The thickness and height of the arc are proportional to the * depth of coverage. Some of this gets a bit arcane -- the result of lots of visual tweaking. * * @param pixelFeatureStart the starting position of the feature, whether on-screen or not * @param pixelFeatureEnd the ending position of the feature, whether on-screen or not * @param pixelJunctionStart the starting position of the junction, whether on-screen or not * @param pixelJunctionEnd the ending position of the junction, whether on-screen or not * @param depth coverage depth * @param trackRectangle//from www.ja v a2s.co m * @param context * @param strand * @param junctionFeature * @param shouldHighlight * @param featureColor the color specified for this feature. May be null. */ protected void drawFeature(int pixelFeatureStart, int pixelFeatureEnd, int pixelJunctionStart, int pixelJunctionEnd, float depth, Rectangle trackRectangle, RenderContext context, Strand strand, SpliceJunctionFeature junctionFeature, boolean shouldHighlight, Color featureColor, boolean shouldShowFlankingRegions) { boolean isPositiveStrand = true; // Get the feature's direction, color appropriately if (strand != null && strand.equals(Strand.NEGATIVE)) isPositiveStrand = false; //If the feature color is specified, use it, except that we set our own alpha depending on whether //the feature is highlighted. Otherwise default based on strand and highlight. Color color; if (featureColor != null) { int r = featureColor.getRed(); int g = featureColor.getGreen(); int b = featureColor.getBlue(); int alpha = shouldHighlight ? 255 : 140; color = new Color(r, g, b, alpha); } else { if (isPositiveStrand) color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_POS : ARC_COLOR_POS; else color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_NEG : ARC_COLOR_NEG; } Graphics2D g2D = context.getGraphic2DForColor(color); if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) { g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } //Height of top of an arc of maximum depth int maxPossibleArcHeight = (trackRectangle.height - 1) / 2; if (shouldShowFlankingRegions) { if (junctionFeature.hasFlankingRegionDepthArrays()) { //draw a wigglegram of the splice junction flanking region depth of coverage int startFlankingRegionPixelLength = pixelJunctionStart - pixelFeatureStart; int endFlankingRegionPixelLength = pixelFeatureEnd - pixelJunctionEnd; drawFlankingRegion(g2D, pixelFeatureStart, startFlankingRegionPixelLength, junctionFeature.getStartFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle, isPositiveStrand); drawFlankingRegion(g2D, pixelJunctionEnd + 1, endFlankingRegionPixelLength, junctionFeature.getEndFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle, isPositiveStrand); } else { //Draw rectangles indicating the overlap on each side of the junction int overlapRectHeight = 3; int overlapRectTopX = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -2 : 0); if (pixelFeatureStart < pixelJunctionStart) { g2D.fillRect(pixelFeatureStart, overlapRectTopX, pixelJunctionStart - pixelFeatureStart, overlapRectHeight); } if (pixelJunctionEnd < pixelFeatureEnd) { g2D.fillRect(pixelJunctionEnd, overlapRectTopX, pixelFeatureEnd - pixelJunctionEnd, overlapRectHeight); } } } //Create a path describing the arc, using Bezier curves. The Bezier control points for the top and //bottom arcs are based on the boundary points of the rectangles containing the arcs //proportion of the maximum arc height used by a minimum-height arc double minArcHeightProportion = 0.33; int innerArcHeight = (int) (maxPossibleArcHeight * minArcHeightProportion); float depthProportionOfMax = Math.min(1, depth / maxDepth); int arcWidth = Math.max(1, (int) ((1 - minArcHeightProportion) * maxPossibleArcHeight * depthProportionOfMax)); int outerArcHeight = innerArcHeight + arcWidth; //Height of bottom of the arc int arcBeginY = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -1 : 1); int outerArcPeakY = isPositiveStrand ? arcBeginY - outerArcHeight : arcBeginY + outerArcHeight; int innerArcPeakY = isPositiveStrand ? arcBeginY - innerArcHeight : arcBeginY + innerArcHeight; //dhmay: I don't really understand Bezier curves. For some reason I have to put the Bezier control //points farther up or down than I want the arcs to extend. This multiplier seems about right int outerBezierY = arcBeginY + (int) (1.3 * (outerArcPeakY - arcBeginY)); int innerBezierY = arcBeginY + (int) (1.3 * (innerArcPeakY - arcBeginY)); //Putting the Bezier control points slightly off to the sides of the arc int bezierXPad = Math.max(1, (pixelJunctionEnd - pixelJunctionStart) / 30); GeneralPath arcPath = new GeneralPath(); arcPath.moveTo(pixelJunctionStart, arcBeginY); arcPath.curveTo(pixelJunctionStart - bezierXPad, outerBezierY, //Bezier 1 pixelJunctionEnd + bezierXPad, outerBezierY, //Bezier 2 pixelJunctionEnd, arcBeginY); //Arc end arcPath.curveTo(pixelJunctionEnd + bezierXPad, innerBezierY, //Bezier 1 pixelJunctionStart - bezierXPad, innerBezierY, //Bezier 2 pixelJunctionStart, arcBeginY); //Arc end //Draw the arc, to ensure outline is drawn completely (fill won't do it, necessarily). This will also //give the arc a darker outline g2D.draw(arcPath); //Fill the arc g2D.fill(arcPath); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); }
From source file:eu.udig.style.advanced.utils.Utilities.java
/** * Creates an {@link Image} for the given rule. * //from ww w.j av a 2s .co m * @param rule the rule for which to create the image. * @param width the image width. * @param height the image height. * @return the generated image. */ public static BufferedImage pointRuleToImage(final Rule rule, int width, int height) { DuplicatingStyleVisitor copyStyle = new DuplicatingStyleVisitor(); rule.accept(copyStyle); Rule newRule = (Rule) copyStyle.getCopy(); int pointSize = 0; Stroke stroke = null; Symbolizer[] symbolizers = newRule.getSymbolizers(); if (symbolizers.length > 0) { Symbolizer symbolizer = newRule.getSymbolizers()[0]; if (symbolizer instanceof PointSymbolizer) { PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer; pointSize = SLDs.pointSize(pointSymbolizer); stroke = SLDs.stroke(pointSymbolizer); } } int strokeSize = 0; if (stroke != null) { strokeSize = SLDs.width(stroke); if (strokeSize < 0) { strokeSize = 1; stroke.setWidth(ff.literal(strokeSize)); } } pointSize = pointSize + 2 * strokeSize; if (pointSize <= 0) { pointSize = width; } // pointSize = width; BufferedImage finalImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); BufferedImage pointImage = new BufferedImage(pointSize, pointSize, BufferedImage.TYPE_INT_ARGB); Point point = d.point(pointSize / 2, pointSize / 2); d.drawDirect(pointImage, d.feature(point), newRule); Graphics2D g2d = finalImage.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (pointSize > width || pointSize > height) { g2d.drawImage(pointImage, 0, 0, width, height, 0, 0, pointSize, pointSize, null); } else { int x = width / 2 - pointSize / 2; int y = height / 2 - pointSize / 2; g2d.drawImage(pointImage, x, y, null); } g2d.dispose(); return finalImage; }
From source file:Hexagon.java
public static BufferedImage drawCodePoint(char codePoint, int width, int height, Font font, Color color) { BufferedImage img = createImage(width, height); Graphics2D g2 = img.createGraphics(); String text = "" + codePoint; g2.setColor(color);// w w w. ja v a2 s.c om g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GlyphVector gv = font.createGlyphVector(g2.getFontRenderContext(), text); g2.drawGlyphVector(gv, 0f, (float) gv.getGlyphMetrics(0).getBounds2D().getHeight()); return img; }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawEntity(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();//from w ww .ja va 2s .c o m Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AffineTransform originalTransform = g2.getTransform(); Shape transformed = entity; FlatteningPathIterator iter = new FlatteningPathIterator( transformed.getPathIterator(new AffineTransform()), 1); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:uk.co.modularaudio.service.gui.impl.racktable.back.RackLinksCompositeOverlay.java
private final void drawLine(final Point sourcePoint, final Point sinkPoint) { final int fromX = sourcePoint.x; final int fromY = sourcePoint.y; final int toX = sinkPoint.x; final int toY = sinkPoint.y; float f1, f2, f3, f4, f5, f6, f7, f8 = 0.0f; f1 = fromX;// w ww . j ava2s . co m f2 = fromY; f3 = fromX; f4 = fromY + WIRE_DIP_PIXELS; f5 = toX; f6 = toY + WIRE_DIP_PIXELS; f7 = toX; f8 = toY; final CubicCurve2D cubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setColor(Color.BLACK); g2d.setStroke(WIRE_STROKE); g2d.draw(cubicCurve); g2d.setColor(Color.BLUE); // g2d.setColor( Color.YELLOW ); g2d.setStroke(WIRE_BODY_STROKE); g2d.draw(cubicCurve); // g2d.drawLine( sourcePoint.x, sourcePoint.y, sinkPoint.x, sinkPoint.y ); }
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
private void drawInformationBox(Graphics2D g2, JXLayer<? extends V> layer) { if (JStock.instance().getJStockOptions() .getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Hide) { return;//from www . jav a 2 s . c o m } final Font oldFont = g2.getFont(); final Font paramFont = oldFont; final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont); final Font valueFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() + 1); final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont); final Font dateFont = oldFont.deriveFont((float) oldFont.getSize() - 1); final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont); final List<ChartData> chartDatas = this.chartJDialog.getChartDatas(); List<String> values = new ArrayList<String>(); final ChartData chartData = chartDatas.get(this.mainTraceInfo.getDataIndex()); // Number formats are generally not synchronized. It is recommended to create separate format instances for each thread. // If multiple threads access a format concurrently, it must be synchronized externally. // http://stackoverflow.com/questions/2213410/usage-of-decimalformat-for-the-following-case final DecimalFormat integerFormat = new DecimalFormat("###,###"); // It is common to use OHLC for chat, instead of using PrevPrice. values.add(org.yccheok.jstock.gui.Utils.stockPriceDecimalFormat(chartData.openPrice)); values.add(org.yccheok.jstock.gui.Utils.stockPriceDecimalFormat(chartData.highPrice)); values.add(org.yccheok.jstock.gui.Utils.stockPriceDecimalFormat(chartData.lowPrice)); values.add(org.yccheok.jstock.gui.Utils.stockPriceDecimalFormat(chartData.lastPrice)); values.add(integerFormat.format(chartData.volume)); final List<String> indicatorParams = new ArrayList<String>(); final List<String> indicatorValues = new ArrayList<String>(); final DecimalFormat decimalFormat = new DecimalFormat("0.00"); for (TraceInfo indicatorTraceInfo : this.indicatorTraceInfos) { final int plotIndex = indicatorTraceInfo.getPlotIndex(); final int seriesIndex = indicatorTraceInfo.getSeriesIndex(); final int dataIndex = indicatorTraceInfo.getDataIndex(); final String name = this.getLegendName(plotIndex, seriesIndex); final Number value = this.getValue(plotIndex, seriesIndex, dataIndex); if (name == null || value == null) { continue; } indicatorParams.add(name); indicatorValues.add(decimalFormat.format(value)); } assert (values.size() == params.size()); int index = 0; final int paramValueWidthMargin = 10; final int paramValueHeightMargin = 0; // Slightly larger than dateInfoHeightMargin, as font for indicator is // larger than date's. final int infoIndicatorHeightMargin = 8; int maxInfoWidth = -1; // paramFontMetrics will always "smaller" than valueFontMetrics. int totalInfoHeight = Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight()) * values.size() + paramValueHeightMargin * (values.size() - 1); for (String param : params) { final String value = values.get(index++); final int paramStringWidth = paramFontMetrics.stringWidth(param + ":") + paramValueWidthMargin + valueFontMetrics.stringWidth(value); if (maxInfoWidth < paramStringWidth) { maxInfoWidth = paramStringWidth; } } if (indicatorValues.size() > 0) { totalInfoHeight += infoIndicatorHeightMargin; totalInfoHeight += Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight()) * indicatorValues.size() + paramValueHeightMargin * (indicatorValues.size() - 1); index = 0; for (String indicatorParam : indicatorParams) { final String indicatorValue = indicatorValues.get(index++); final int paramStringWidth = paramFontMetrics.stringWidth(indicatorParam + ":") + paramValueWidthMargin + valueFontMetrics.stringWidth(indicatorValue); if (maxInfoWidth < paramStringWidth) { maxInfoWidth = paramStringWidth; } } } final Date date = new Date(chartData.timestamp); // Date formats are not synchronized. It is recommended to create separate format instances for each thread. // If multiple threads access a format concurrently, it must be synchronized externally. final SimpleDateFormat simpleDateFormat = this.simpleDataFormatThreadLocal.get(); final String dateString = simpleDateFormat.format(date); final int dateStringWidth = dateFontMetrics.stringWidth(dateString); final int dateStringHeight = dateFontMetrics.getHeight(); // We want to avoid information box from keep changing its width while // user moves along the mouse. This will prevent user from feeling, // information box is flickering, which is uncomfortable to user's eye. final int maxStringWidth = Math.max(dateFontMetrics.stringWidth(longDateString), Math.max(this.maxWidth, Math.max(dateStringWidth, maxInfoWidth))); if (maxStringWidth > this.maxWidth) { this.maxWidth = maxStringWidth; } final int dateInfoHeightMargin = 5; final int maxStringHeight = dateStringHeight + dateInfoHeightMargin + totalInfoHeight; final int padding = 5; final int boxPointMargin = 8; final int width = maxStringWidth + (padding << 1); final int height = maxStringHeight + (padding << 1); /* Get Border Rect Information. */ /* fillRect(1, 1, 1, 1); // O is rect pixel xxx xOx xxx drawRect(0, 0, 2, 2); // O is rect pixel OOO OxO OOO */ final int borderWidth = width + 2; final int borderHeight = height + 2; // On left side of the ball. final double suggestedBorderX = this.mainTraceInfo.getPoint().getX() - borderWidth - boxPointMargin; final double suggestedBorderY = this.mainTraceInfo.getPoint().getY() - (borderHeight >> 1); double bestBorderX = 0; double bestBorderY = 0; if (JStock.instance().getJStockOptions() .getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Stay) { if (this.mainTraceInfo.getPoint() .getX() > ((int) (this.mainDrawArea.getX() + this.mainDrawArea.getWidth() + 0.5) >> 1)) { bestBorderX = this.mainDrawArea.getX(); bestBorderY = this.mainDrawArea.getY(); } else { bestBorderX = this.mainDrawArea.getX() + this.mainDrawArea.getWidth() - borderWidth; bestBorderY = this.mainDrawArea.getY(); } } else { assert (JStock.instance().getJStockOptions() .getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Follow); bestBorderX = suggestedBorderX > this.mainDrawArea.getX() ? (suggestedBorderX + borderWidth) < (this.mainDrawArea.getX() + this.mainDrawArea.getWidth()) ? suggestedBorderX : this.mainDrawArea.getX() + this.mainDrawArea.getWidth() - borderWidth - boxPointMargin : this.mainTraceInfo.getPoint().getX() + boxPointMargin; bestBorderY = suggestedBorderY > this.mainDrawArea.getY() ? (suggestedBorderY + borderHeight) < (this.mainDrawArea.getY() + this.mainDrawArea.getHeight()) ? suggestedBorderY : this.mainDrawArea.getY() + this.mainDrawArea.getHeight() - borderHeight - boxPointMargin : this.mainDrawArea.getY() + boxPointMargin; } final double x = bestBorderX + 1; final double y = bestBorderY + 1; final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Composite oldComposite = g2.getComposite(); final Color oldColor = g2.getColor(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(COLOR_BORDER); g2.drawRoundRect((int) (bestBorderX + 0.5), (int) (bestBorderY + 0.5), borderWidth - 1, borderHeight - 1, 15, 15); g2.setColor(COLOR_BACKGROUND); g2.setComposite(Utils.makeComposite(0.75f)); g2.fillRoundRect((int) (x + 0.5), (int) (y + 0.5), width, height, 15, 15); g2.setComposite(oldComposite); g2.setColor(oldColor); int yy = (int) (y + padding + dateFontMetrics.getAscent() + 0.5); g2.setFont(dateFont); g2.setColor(COLOR_BLUE); g2.drawString(dateString, (int) (((width - dateFontMetrics.stringWidth(dateString)) >> 1) + x + 0.5), yy); index = 0; yy += dateFontMetrics.getDescent() + dateInfoHeightMargin + valueFontMetrics.getAscent(); final String CLOSE_STR = GUIBundle.getString("StockHistory_Close"); for (String param : params) { final String value = values.get(index++); g2.setColor(Color.BLACK); if (param.equals(CLOSE_STR)) { // It is common to use OHLC for chat, instead of using PrevPrice. final double changePrice = chartData.lastPrice - chartData.openPrice; if (changePrice > 0.0) { g2.setColor(JStockOptions.DEFAULT_HIGHER_NUMERICAL_VALUE_FOREGROUND_COLOR); } else if (changePrice < 0.0) { g2.setColor(JStockOptions.DEFAULT_LOWER_NUMERICAL_VALUE_FOREGROUND_COLOR); } } g2.setFont(paramFont); g2.drawString(param + ":", (int) (padding + x + 0.5), yy); g2.setFont(valueFont); g2.drawString(value, (int) (width - padding - valueFontMetrics.stringWidth(value) + x + 0.5), yy); // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent() yy += paramValueHeightMargin + valueFontMetrics.getHeight(); } g2.setColor(Color.BLACK); yy -= paramValueHeightMargin; yy += infoIndicatorHeightMargin; index = 0; for (String indicatorParam : indicatorParams) { final String indicatorValue = indicatorValues.get(index++); g2.setFont(paramFont); g2.drawString(indicatorParam + ":", (int) (padding + x + 0.5), yy); g2.setFont(valueFont); g2.drawString(indicatorValue, (int) (width - padding - valueFontMetrics.stringWidth(indicatorValue) + x + 0.5), yy); // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent() yy += paramValueHeightMargin + valueFontMetrics.getHeight(); } g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); g2.setFont(oldFont); }
From source file:org.wikipathways.bots.utils.GenerateRSSM.java
private void addThumb(Element biosystem, Pathway p) throws IOException { VPathway vPathway = new VPathway(null); vPathway.fromModel(p);/* www .j a va 2s . com*/ double vh = vPathway.getVHeight(); double vw = vPathway.getVWidth(); double zoom = 100; if (vh >= vw) zoom = (double) imgSize / vPathway.getVHeight(); if (vw > vh) zoom = (double) imgSize / vPathway.getVWidth(); vPathway.setPctZoom(zoom * 100); BufferedImage imgThumb = new BufferedImage(vPathway.getVWidth(), vPathway.getVHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g = imgThumb.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); vPathway.draw(g); g.dispose(); ByteArrayOutputStream o = new ByteArrayOutputStream(); ImageIO.write(imgThumb, "png", o); o.flush(); byte[] thumbByte = o.toByteArray(); o.close(); byte[] base64enc = Base64.encodeBase64(thumbByte); Element thumb = new Element("thumbnail"); biosystem.addContent(thumb); Element image = new Element("image"); thumb.addContent(image); Element type = new Element("type"); type.addContent(new Element("png")); image.addContent(type); Element enc = new Element("encodedimage"); enc.setText(new String(base64enc)); image.addContent(enc); }
From source file:eu.udig.style.advanced.utils.Utilities.java
/** * Creates an image from a set of {@link RuleWrapper}s. * //from w w w .j ava 2 s . c o m * @param rulesWrapperList the list of rules wrapper. * @param width the image width. * @param height the image height. * @return the new created {@link BufferedImage}. */ public static BufferedImage polygonRulesWrapperToImage(final List<RuleWrapper> rulesWrapperList, int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (RuleWrapper rule : rulesWrapperList) { BufferedImage tmpImage = Utilities.polygonRuleWrapperToImage(rule, width, height); g2d.drawImage(tmpImage, 0, 0, null); } g2d.dispose(); return image; }
From source file:net.sf.firemox.tools.Picture.java
@Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); if (cardImage != null) { g.drawImage(cardImage, 0, 0, getWidth(), getHeight(), this); }//w ww .j av a 2 s . c o m }