List of usage examples for java.awt Graphics2D setRenderingHint
public abstract void setRenderingHint(Key hintKey, Object hintValue);
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void drawTitle(Graphics2D g2) { final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Color oldColor = g2.getColor(); final Font oldFont = g2.getFont(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final Font titleFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() * 1.5f); final int margin = 5; final FontMetrics titleFontMetrics = g2.getFontMetrics(titleFont); final FontMetrics oldFontMetrics = g2.getFontMetrics(oldFont); final java.text.NumberFormat numberFormat = java.text.NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); numberFormat.setMinimumFractionDigits(2); final double totalInvestValue = this.investmentFlowChartJDialog.getTotalInvestValue(); final double totalROIValue = this.investmentFlowChartJDialog.getTotalROIValue(); final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace(); final String invest = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalInvestValue);/*from ww w.j a v a2 s. c o m*/ final String roi = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalROIValue); final double gain = totalROIValue - totalInvestValue; final double percentage = totalInvestValue > 0.0 ? gain / totalInvestValue * 100.0 : 0.0; final String gain_str = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, gain); final String percentage_str = numberFormat.format(percentage); final String SELECTED = this.investmentFlowChartJDialog.getCurrentSelectedString(); final String INVEST = GUIBundle.getString("InvestmentFlowLayerUI_Invest"); final String RETURN = GUIBundle.getString("InvestmentFlowLayerUI_Return"); final String GAIN = (SELECTED.length() > 0 ? SELECTED + " " : "") + GUIBundle.getString("InvestmentFlowLayerUI_Gain"); final String LOSS = (SELECTED.length() > 0 ? SELECTED + " " : "") + GUIBundle.getString("InvestmentFlowLayerUI_Loss"); final int string_width = oldFontMetrics.stringWidth(INVEST + ": ") + titleFontMetrics.stringWidth(invest + " ") + oldFontMetrics.stringWidth(RETURN + ": ") + titleFontMetrics.stringWidth(roi + " ") + oldFontMetrics.stringWidth((gain >= 0 ? GAIN : LOSS) + ": ") + titleFontMetrics.stringWidth(gain_str + " (" + percentage_str + "%)"); int x = (int) (this.investmentFlowChartJDialog.getChartPanel().getWidth() - string_width) >> 1; final int y = margin + titleFontMetrics.getAscent(); g2.setFont(oldFont); g2.drawString(INVEST + ": ", x, y); x += oldFontMetrics.stringWidth(INVEST + ": "); g2.setFont(titleFont); g2.drawString(invest + " ", x, y); x += titleFontMetrics.stringWidth(invest + " "); g2.setFont(oldFont); g2.drawString(RETURN + ": ", x, y); x += oldFontMetrics.stringWidth(RETURN + ": "); g2.setFont(titleFont); g2.drawString(roi + " ", x, y); x += titleFontMetrics.stringWidth(roi + " "); g2.setFont(oldFont); if (gain >= 0) { if (gain > 0) { if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) { g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor()); } else { g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor()); } } g2.drawString(GAIN + ": ", x, y); x += oldFontMetrics.stringWidth(GAIN + ": "); } else { if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) { g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor()); } else { g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor()); } g2.drawString(LOSS + ": ", x, y); x += oldFontMetrics.stringWidth(LOSS + ": "); } g2.setFont(titleFont); g2.drawString(gain_str + " (" + percentage_str + "%)", x, y); g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); g2.setFont(oldFont); }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
protected BufferedImage getScaledImage(int width, int height) { BufferedImage tempImg = ImageUtils.createCompatibleBufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) tempImg.getGraphics(); g2d.setColor(new Color(35, 125, 0)); g2d.fillRect(0, 0, tempImg.getWidth(null), tempImg.getHeight(null)); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.drawImage(mBuffer, 0, 0, width, height, 0, 0, mBuffer.getWidth(), mBuffer.getHeight(), null); g2d.dispose();/* w w w.ja va 2s. co m*/ return tempImg; }
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 va 2s. com*/ * @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:org.moeaframework.analysis.plot.Plot.java
/** * Generates a string containing a rendering of the chart in SVG format. * This feature is only supported if the JFreeSVG library is included on * the classpath.//from ww w . j ava 2 s . c o m * * This is copied from JFreeChart's ChartPanel class (version 1.0.19). * * @return A string containing an SVG element for the current chart, or * <code>null</code> if there is a problem with the method invocation * by reflection. */ private String generateSVG(int width, int height) { Graphics2D g2 = createSVGGraphics2D(width, height); if (g2 == null) { throw new IllegalStateException("JFreeSVG library is not present."); } // we suppress shadow generation, because SVG is a vector format and // the shadow effect is applied via bitmap effects... g2.setRenderingHint(new RenderingHints.Key(0) { @Override public boolean isCompatibleValue(Object val) { return val instanceof Boolean; } }, true); String svg = null; Rectangle2D drawArea = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, drawArea); try { Method m = g2.getClass().getMethod("getSVGElement"); svg = (String) m.invoke(g2); } catch (NoSuchMethodException e) { // null will be returned } catch (SecurityException e) { // null will be returned } catch (IllegalAccessException e) { // null will be returned } catch (IllegalArgumentException e) { // null will be returned } catch (InvocationTargetException e) { // null will be returned } return svg; }
From source file:savant.view.tracks.BAMTrackRenderer.java
private void renderArcPairedMode(Graphics2D g2, GraphPaneAdapter gp) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); LOG.debug("YMAX for ARC mode: " + ((AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE)).getYMax()); AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); int discordantMin = (Integer) instructions.get(DrawingInstruction.DISCORDANT_MIN); int discordantMax = (Integer) instructions.get(DrawingInstruction.DISCORDANT_MAX); //LOG.info("discordantMin=" + discordantMin + " discordantMax=" + discordantMax); // set up colors Color normalArcColor = makeTransparent(cs.getColor(ColourKey.CONCORDANT_LENGTH)); Color invertedReadColor = makeTransparent(cs.getColor(ColourKey.ONE_READ_INVERTED)); Color evertedPairColor = makeTransparent(cs.getColor(ColourKey.EVERTED_PAIR)); Color discordantLengthColor = makeTransparent(cs.getColor(ColourKey.DISCORDANT_LENGTH)); Color unmappedMateColor = makeTransparent(cs.getColor(ColourKey.UNMAPPED_MATE)); // set graph pane's range parameters gp.setXRange(axisRange.getXRange()); gp.setYRange(axisRange.getYRange()); // iterate through the data and draw LOG.debug("BAMTrackRenderer.renderArcMatePairMode: " + data.size() + " records."); for (Record record : data) { BAMIntervalRecord bamRecord = (BAMIntervalRecord) record; SAMRecord samRecord = bamRecord.getSAMRecord(); SAMReadUtils.PairedSequencingProtocol prot = (SAMReadUtils.PairedSequencingProtocol) instructions .get(DrawingInstruction.PAIRED_PROTOCOL); SAMReadUtils.PairMappingType type = SAMReadUtils.getPairType(samRecord, prot); if (samRecord.getReadPairedFlag() && type != null) { if (samRecord.getMateUnmappedFlag()) { // Read with unmapped mate. int alignmentStart = samRecord.getAlignmentStart(); double x = gp.transformXPos(alignmentStart); double radius = 4.0; double top = gp.transformYPos(axisRange.getYRange().getTo() * 0.25) + radius; g2.setColor(unmappedMateColor); g2.setStroke(ONE_STROKE); Path2D flower = new Path2D.Double(); flower.moveTo(x, gp.transformYPos(0.0)); flower.lineTo(x, top);// www.j a v a 2s . c o m flower.moveTo(x - radius, top - radius); flower.lineTo(x + radius, top + radius); flower.moveTo(x - radius, top + radius); flower.lineTo(x + radius, top - radius); //flower.append(new Ellipse2D.Double(x - radius, top - radius, radius * 2.0, radius * 2.0), false); g2.draw(flower); recordToShapeMap.put(record, flower); // mates map to different chrs } else if (!samRecord.getMateReferenceName().equals(samRecord.getReferenceName())) { int alignmentStart = samRecord.getAlignmentStart(); double x = gp.transformXPos(alignmentStart); double arrowWidth = 10; double arrowHeight = 15; double top = gp.transformYPos(axisRange.getYRange().getTo() * 0.9); g2.setColor(invertedReadColor); g2.setStroke(TWO_STROKE); Path2D stem = new Path2D.Double(); stem.moveTo(x, gp.transformYPos(0.0)); stem.lineTo(x, top + arrowHeight); g2.draw(stem); Path2D pointer = new Path2D.Double(); pointer.moveTo(x, top); pointer.lineTo(x - arrowWidth / 2, top + arrowHeight); pointer.lineTo(x + arrowWidth / 2, top + arrowHeight); pointer.lineTo(x, top); g2.fill(pointer); pointer.append(stem, false); //flower.append(new Ellipse2D.Double(x - radius, top - radius, radius * 2.0, radius * 2.0), false); //g2.draw(pointer); recordToShapeMap.put(record, pointer); // mates map to the same chr } else { // Paired read with normal mate. int arcLength = Math.abs(samRecord.getInferredInsertSize()); // skip reads with a zero insert length--probably mapping errors if (arcLength == 0) { continue; } int alignmentStart; int mateAlignmentStart = samRecord.getMateAlignmentStart(); if (samRecord.getAlignmentStart() > mateAlignmentStart) { if (!(mateAlignmentStart < LocationController.getInstance().getRangeStart())) { // this is the second in the pair, and it doesn't span the beginning of the range, so don't draw anything continue; } else { // switch the mate start/end for the read start/end to deal with reversed position alignmentStart = mateAlignmentStart; } } else { alignmentStart = samRecord.getAlignmentStart(); } // at this point alignmentStart/End refers the the start end of the first occurrence in the pair int intervalStart; switch (type) { case INVERTED_READ: case INVERTED_MATE: intervalStart = alignmentStart; g2.setColor(invertedReadColor); g2.setStroke(TWO_STROKE); break; case EVERTED: intervalStart = alignmentStart; g2.setColor(evertedPairColor); g2.setStroke(TWO_STROKE); break; default: // make sure arclength is over our threshold /*if (threshold != 0.0d && threshold < 1.0d && arcLength < axisRange.getXRange().getLength()*threshold) { continue; } else if (threshold > 1.0d && arcLength < threshold) { continue; }*/ intervalStart = alignmentStart; if (arcLength > discordantMax || arcLength < discordantMin) { g2.setColor(discordantLengthColor); g2.setStroke(TWO_STROKE); } else { g2.setColor(normalArcColor); g2.setStroke(ONE_STROKE); } break; } int arcHeight = arcLength; double rectWidth = arcLength * gp.getUnitWidth(); double rectHeight = arcHeight * 2 * gp.getUnitHeight(); double xOrigin = gp.transformXPos(intervalStart); double yOrigin = gp.transformYPos(arcHeight); Arc2D arc = new Arc2D.Double(xOrigin, yOrigin, rectWidth, rectHeight, -180, -180, Arc2D.OPEN); g2.draw(arc); recordToShapeMap.put(record, arc); } } } }
From source file:savant.view.swing.GraphPane.java
/** * Draw an informational message on top of this GraphPane. * * @param g2 the graphics to be rendered * @param message text of the message to be displayed *///from ww w . j av a 2s .c o m private void drawMessage(Graphics2D g2, String message) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = g2.getFont(); Font subFont = font; int h = getSize().height / 3; int w = getWidth(); if (w > 500) { font = font.deriveFont(Font.PLAIN, 36); subFont = subFont.deriveFont(Font.PLAIN, 18); } else if (w > 150) { font = font.deriveFont(Font.PLAIN, 24); subFont = subFont.deriveFont(Font.PLAIN, 12); } else { font = font.deriveFont(Font.PLAIN, 12); subFont = subFont.deriveFont(Font.PLAIN, 8); } int returnPos = message.indexOf('\n'); g2.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_MESSAGE)); if (returnPos > 0) { drawMessageHelper(g2, message.substring(0, returnPos), font, w, h, -(subFont.getSize() / 2)); drawMessageHelper(g2, message.substring(returnPos + 1), subFont, w, h, font.getSize() - (subFont.getSize() / 2)); } else { drawMessageHelper(g2, message, font, w, h, 0); } }
From source file:au.org.ala.biocache.web.WMSController.java
public static ImgObj create(int width, int height) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) img.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); return new ImgObj(g, img); }
From source file:savant.view.swing.GraphPane.java
private void renderCurrentSelected(Graphics2D g2) { // Temporarily shift the origin g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(0, getOffset());/*from w w w. j av a2 s .c om*/ for (Track t : tracks) { if (t.getRenderer().hasMappedValues()) { List<Shape> currentSelected = t.getRenderer().getCurrentSelectedShapes(this); if (currentSelected.size() > 0) { boolean arcMode = t.getDrawingMode() == DrawingMode.ARC_PAIRED; for (Shape selectedShape : currentSelected) { if (selectedShape != currentOverShape) { if (arcMode) { g2.setColor(Color.GREEN); g2.draw(selectedShape); } else { //g2.setColor(Color.GREEN); g2.setColor(new Color(0, 255, 0, 150)); g2.fill(selectedShape); if (selectedShape.getBounds().getWidth() > 5) { g2.setColor(Color.BLACK); g2.draw(selectedShape); } } } } } break; } } if (currentOverShape != null) { if (tracks[0].getDrawingMode() == DrawingMode.ARC_PAIRED) { g2.setColor(Color.RED); g2.draw(currentOverShape); //get record pair BAMIntervalRecord rec1 = (BAMIntervalRecord) currentOverRecord; BAMIntervalRecord rec2 = ((BAMTrack) tracks[0]).getMate(rec1); //mate //render reads with mismatches ((BAMTrackRenderer) tracks[0].getRenderer()).renderReadsFromArc(g2, this, rec1, rec2, prevRange); } else { g2.setColor(new Color(255, 0, 0, 150)); g2.fill(currentOverShape); if (currentOverShape.getBounds() != null && currentOverShape.getBounds().getWidth() > 5 && currentOverShape.getBounds().getHeight() > 3) { g2.setColor(Color.BLACK); g2.draw(currentOverShape); } } } //shift the origin back g2.translate(0, -getOffset()); }
From source file:au.com.gaiaresources.bdrs.controller.test.TestDataCreator.java
private byte[] createImage(int width, int height, String text) throws IOException { if (width < 0) { width = random.nextInt(DEFAULT_MAX_IMAGE_WIDTH - DEFAULT_MIN_IMAGE_WIDTH) + DEFAULT_MIN_IMAGE_WIDTH; }//from w w w . j a v a2 s . c o m if (height < 0) { height = random.nextInt(DEFAULT_MAX_IMAGE_HEIGHT - DEFAULT_MIN_IMAGE_HEIGHT) + DEFAULT_MIN_IMAGE_HEIGHT; } BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) img.getGraphics(); g2.setBackground(new Color(220, 220, 220)); Dimension size; float fontSize = g2.getFont().getSize(); // Make the text as large as possible. do { g2.setFont(g2.getFont().deriveFont(fontSize)); FontMetrics metrics = g2.getFontMetrics(g2.getFont()); int hgt = metrics.getHeight(); int adv = metrics.stringWidth(text); size = new Dimension(adv + 2, hgt + 2); fontSize = fontSize + 1f; } while (size.width < Math.round(0.9 * width) && size.height < Math.round(0.9 * height)); g2.setColor(Color.DARK_GRAY); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.drawString(text, (width - size.width) / 2, (height - size.height) / 2); g2.setColor(Color.LIGHT_GRAY); g2.drawRect(0, 0, width - 1, height - 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(width * height); ImageIO.write(img, "png", baos); baos.flush(); byte[] rawBytes = baos.toByteArray(); baos.close(); return rawBytes; }
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 w w w.j a v a 2 s. c o m*/ 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; }