List of usage examples for java.awt Graphics create
public abstract Graphics create();
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Paints the component by drawing the chart to fill the entire component, * but allowing for the insets (which will be non-zero if a border has been * set for this component). To increase performance (at the expense of * memory), an off-screen buffer image can be used. * * @param g the graphics device for drawing on. *//*w w w . j av a 2 s . co m*/ public void paintComponent(Graphics g) { super.paintComponent(g); if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if (this.useBuffer) { // if buffer is being refreshed, it needs clearing unless it is // new - use the following flag to track this... boolean clearBuffer = true; // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight); // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; clearBuffer = false; // buffer is new, no clearing required } // do we need to redraw the buffer? if (this.refreshBuffer) { this.refreshBuffer = false; // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth, this.chartBufferHeight); Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics(); if (clearBuffer) { bufferG2.clearRect(0, 0, this.chartBufferWidth, this.chartBufferHeight); } if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); bufferG2.transform(st); this.chart.draw(bufferG2, chartArea, this.anchor, this.info); bufferG2.setTransform(saved); } else { this.chart.draw(bufferG2, bufferArea, this.anchor, this.info); } } g2.drawImage(this.chartBuffer, insets.left, insets.top, this); g2.draw((Shape) activeROI.getShapesList().get(1)); // Dibujar las rois que se encuentren activas } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.drawImage(this.chartBuffer, insets.left, insets.top, this); // Se pintan las Roi activa drawsROIs(g2); g2.setTransform(saved); } g2.dispose(); this.anchor = null; }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, * but allowing for the insets (which will be non-zero if a border has been * set for this component). To increase performance (at the expense of * memory), an off-screen buffer image can be used. * * @param g the graphics device for drawing on. *//* ww w. java 2s .c om*/ public void paintComponent(final Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); Insets insets = getInsets(); if (bufferExtents == null || !bufferExtents.equals(getChartArea())) { createBuffer(); ((AbstractDmcPlot) chart.getPlot()).setNoData(true); Graphics2D bufferG2 = (Graphics2D) chartBuffer.getGraphics(); chart.draw(bufferG2, bufferExtents, info); } g2.drawImage(chartBuffer, insets.left, insets.right, this); this.verticalTraceLine = null; this.horizontalTraceLine = null; }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
@Override @SuppressWarnings("unchecked") public void paintComponent(final Graphics g) { final Graphics2D gfx = (Graphics2D) g.create(); try {/*from ww w . j a v a2 s. c o m*/ final String error = this.errorText; Utils.prepareGraphicsForQuality(gfx); if (error != null) { drawErrorText(gfx, this.getSize(), error); } else { revalidate(); drawOnGraphicsForConfiguration(gfx, this.config, this.model, true, this.selectedTopics); drawDestinationElement(gfx, this.config); } paintChildren(g); if (this.draggedElement != null) { this.draggedElement.draw(gfx); } else if (this.mouseDragSelection != null) { gfx.setColor(COLOR_MOUSE_DRAG_SELECTION); gfx.fill(this.mouseDragSelection.asRectangle()); } } finally { gfx.dispose(); } }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override public void paintComponent(Graphics g) { // TODO Auto-generated method stub super.paintComponent(g); if (isInternalLegendEnabled) { Graphics2D g2 = (Graphics2D) g.create(); drawInternalLegend(g2);//from w w w .j ava 2 s . c o m } }
From source file:org.gumtree.vis.awt.JChartPanel.java
@Override public void paintComponent(Graphics g) { // long time = System.currentTimeMillis(); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); // ChartMaskingUtilities.drawDomainMask(g2, getScreenDataArea(), maskList, // selectedMask, getChart()); if (isMaskingEnabled) { ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), maskList, selectedMask, getChart()); }//from w ww . j a va 2 s.c o m if (isShapeEnabled()) { drawShapes(g2); } if (selectedMarker != null) { drawSelectedMarker(g2); } if (getHorizontalAxisTrace()) { drawHorizontalAxisTrace(g2, horizontalTraceLocation); } if (getVerticalAxisTrace()) { drawVerticalAxisTrace(g2, verticalTraceLocation); } if (isToolTipFollowerEnabled) { drawToolTipFollower(g2, horizontalTraceLocation, verticalTraceLocation); } // if (isTextInputEnabled && textInputFlag && textInputPoint != null){ drawTextInputBox(g2); // } // long diff = System.currentTimeMillis() - time; // if (diff > 100) { // System.out.println("refreshing cost: " + diff); // } }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, but allowing for the * insets (which will be non-zero if a border has been set for this component). To increase * performance (at the expense of memory), an off-screen buffer image can be used. * /*w w w . j av a2 s .c o m*/ * @param g * the graphics device for drawing on. */ public void paintComponent(Graphics g) { super.paintComponent(g); if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if (this.useBuffer) { // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); this.chartBuffer = new BufferedImage(this.chartBufferWidth, this.chartBufferHeight, BufferedImage.TYPE_INT_RGB); //this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight); -by Max // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; } // do we need to redraw the buffer? if (this.refreshBuffer) { Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth, this.chartBufferHeight); Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics(); if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); bufferG2.transform(st); this.chart.draw(bufferG2, chartArea, this.anchor, this.info); bufferG2.setTransform(saved); } else { this.chart.draw(bufferG2, bufferArea, this.anchor, this.info); } this.refreshBuffer = false; } // zap the buffer onto the panel... g2.drawImage(this.chartBuffer, insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.setTransform(saved); } // Redraw the zoom rectangle (if present) drawZoomRectangle(g2); g2.dispose(); this.anchor = null; this.verticalTraceLine = null; this.horizontalTraceLine = null; }
From source file:edu.purdue.cc.bionet.ui.HeatMap.java
/** * This method retrieves a heatmap image from jfreechart and places it on the panel * along with black divider lines and labels to create a heat map graph. * /*from ww w .ja v a 2 s.c o m*/ * @param g The Graphics for the jpanel. */ public void paintComponent(Graphics g) { super.paintComponent(g); if (moleculeList.size() > 0) { float tickStep; BufferedImage drawing = HeatMapUtilities.createHeatMapImage(this.getDataset(), this.spectrum); int leftEdge = this.getWidth() / 8; int topEdge = this.getHeight() / 32; int bottomEdge = this.getHeight() * 7 / 8; int rightEdge = this.getWidth() * 31 / 32; mapPosition = new Rectangle(leftEdge, topEdge, rightEdge - leftEdge, bottomEdge - topEdge); g.drawImage(drawing, leftEdge, topEdge, rightEdge - leftEdge, bottomEdge - topEdge, this.getBackground(), this); // y-axis int yAxisPos = leftEdge - 1; // g.drawLine( yAxisPos, topEdge, yAxisPos, bottomEdge ); tickStep = (bottomEdge - topEdge) / (float) moleculeList.size(); for (int i = 0; i <= moleculeList.size(); i++) { int tickY = Math.round(topEdge + i * tickStep); g.drawLine(rightEdge, tickY, yAxisPos - tickSize, tickY); if (i < moleculeList.size()) { String name = this.moleculeList.get(this.moleculeList.size() - 1 - i).toString(); g.drawString(name, yAxisPos - 4 - g.getFontMetrics().stringWidth(name), (int) (tickY + tickStep)); } } // x-axis int xAxisPos = bottomEdge; tickStep = (rightEdge - leftEdge) / (float) moleculeList.size(); // g.drawLine( leftEdge, xAxisPos, rightEdge, xAxisPos ); for (int i = 0; i <= moleculeList.size(); i++) { int tickX = (int) (leftEdge + i * tickStep); g.drawLine(tickX, topEdge, tickX, xAxisPos + tickSize); } // transform clockwise 90 degrees for the vertical text AffineTransform at = new AffineTransform(); at.quadrantRotate(3); Graphics2D g2d = (Graphics2D) g.create(); g2d.transform(at); for (int i = 0; i < moleculeList.size(); i++) { int tickX = Math.round(leftEdge + i * tickStep); String name = this.moleculeList.get(i).toString(); g2d.drawString(name, -(int) (xAxisPos + 4 + g.getFontMetrics().stringWidth(name)), (int) (tickX + tickStep)); } } }
From source file:com.epiq.bitshark.ui.IVQPanel.java
public IVQPanel() { initComponents();/* w ww.j av a 2 s. c om*/ initGraph(); JPanel holderPanel = new JPanel() { @Override public void paint(Graphics g) { Range newDomain = null; // x Range newRange = null; // y Range currentDomainRange = plot.getDomainAxis().getRange(); Range currentRangeRange = plot.getRangeAxis().getRange(); if (plot.getDomainAxis().isAutoRange()) { plot.getDomainAxis().setAutoRange(false); } if (plot.getRangeAxis().isAutoRange()) { plot.getRangeAxis().setAutoRange(false); } Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double width = dataArea.getWidth(); double height = dataArea.getHeight(); double domainScale = 1; double rangeScale = 1; // scale the domain values up to match the pixels if (width > height) { domainScale = width / height; double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound(); newDomain = new Range(-(extent * domainScale) / 2, (extent * domainScale) / 2); } else if (height > width) { rangeScale = height / width; double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound(); newRange = new Range(-(extent * rangeScale) / 2, (extent * rangeScale) / 2); } if (newDomain == null) { double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound(); newDomain = new Range(-(extent) / 2, (extent) / 2); } if (newRange == null) { double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound(); newRange = new Range(-(extent) / 2, (extent) / 2); } if (newDomain != null) { plot.getDomainAxis().setRange(newDomain, true, false); } if (newRange != null) { plot.getRangeAxis().setRange(newRange, true, false); } Graphics2D g2 = (Graphics2D) g.create(); super.paint(g2); g2.dispose(); } }; holderPanel.setLayout(new BorderLayout()); holderPanel.add(chartPanel, BorderLayout.CENTER); mainPanel.add(holderPanel, BorderLayout.CENTER); headerPanel.setBackgroundPainter(Common.getHeaderPainter()); chartLabel.setUI(new BasicLabelUI()); }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, * but allowing for the insets (which will be non-zero if a border has been * set for this component). To increase performance (at the expense of * memory), an off-screen buffer image can be used. * * @param g the graphics device for drawing on. *///from w ww. j a v a 2s .co m public void paintComponent(Graphics g) { super.paintComponent(g); if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if (this.useBuffer) { // if buffer is being refreshed, it needs clearing unless it is // new - use the following flag to track this... boolean clearBuffer = true; // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight); // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; clearBuffer = false; // buffer is new, no clearing required } // do we need to redraw the buffer? if (this.refreshBuffer) { this.refreshBuffer = false; // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth, this.chartBufferHeight); Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics(); if (clearBuffer) { bufferG2.clearRect(0, 0, this.chartBufferWidth, this.chartBufferHeight); } if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); bufferG2.transform(st); this.chart.draw(bufferG2, chartArea, this.anchor, this.info); bufferG2.setTransform(saved); } else { this.chart.draw(bufferG2, bufferArea, this.anchor, this.info); } } // zap the buffer onto the panel... g2.drawImage(this.chartBuffer, insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.setTransform(saved); } // Redraw the zoom rectangle (if present) drawZoomRectangle(g2); g2.dispose(); this.anchor = null; this.verticalTraceLine = null; this.horizontalTraceLine = null; }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, but allowing for the * insets (which will be non-zero if a border has been set for this component). To increase * performance (at the expense of memory), an off-screen buffer image can be used. * /*from w ww . j av a 2s. co m*/ * @param g * the graphics device for drawing on. */ @Override public void paintComponent(Graphics g) { if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // redrawing the chart every time... AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.setTransform(saved); Iterator<Overlay> iterator = this.overlays.iterator(); while (iterator.hasNext()) { Overlay overlay = iterator.next(); overlay.paintOverlay(g2, this); } // redraw the zoom rectangle (if present) - if useBuffer is false, // we use XOR so we can XOR the rectangle away again without redrawing // the chart drawSelectionRectangle(g2); g2.dispose(); this.anchor = null; this.verticalTraceLine = null; this.horizontalTraceLine = null; }