Java Code Examples for java.awt.Graphics2D#getClip()
The following examples show how to use
java.awt.Graphics2D#getClip() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: osp File: YAxis.java License: GNU General Public License v3.0 | 6 votes |
/** * Draws the axis in the drawing panel. * @param drawingPanel * @param g */ public void draw(DrawingPanel drawingPanel, Graphics g) { int pixLoc = drawingPanel.xToPix(location); if(pixLoc<1) { location = drawingPanel.getXMin(); } if(pixLoc>drawingPanel.getWidth()-1) { location = drawingPanel.getXMax(); } Graphics2D g2 = (Graphics2D) g; Shape clipShape = g2.getClip(); g2.clipRect(0, 0, drawingPanel.getWidth(), drawingPanel.getHeight()); switch(locationType) { case DRAW_AT_LOCATION : case DRAW_IN_DISPLAY : drawInsideDisplay(drawingPanel, g); break; case DRAW_IN_GUTTER : drawInsideGutter(drawingPanel, g); break; default : drawInsideDisplay(drawingPanel, g); break; } g2.setClip(clipShape); }
Example 2
Source Project: osp File: XAxis.java License: GNU General Public License v3.0 | 6 votes |
/** * Draws the axis in the drawing panel. * @param drawingPanel * @param g */ public void draw(DrawingPanel drawingPanel, Graphics g) { int pixLoc = drawingPanel.yToPix(location); if(pixLoc<1) { location = drawingPanel.getYMin(); } if(pixLoc>drawingPanel.getHeight()-1) { location = drawingPanel.getYMax(); } Graphics2D g2 = (Graphics2D) g; Shape clipShape = g2.getClip(); g2.clipRect(0, 0, drawingPanel.getWidth(), drawingPanel.getHeight()); switch(locationType) { case DRAW_AT_LOCATION : case DRAW_IN_DISPLAY : drawInsideDisplay(drawingPanel, g); break; case DRAW_IN_GUTTER : drawInsideGutter(drawingPanel, g); break; default : drawInsideDisplay(drawingPanel, g); break; } g2.setClip(clipShape); }
Example 3
Source Project: open-ig File: UIScrollBox.java License: GNU Lesser General Public License v3.0 | 6 votes |
@Override public void draw(Graphics2D g2) { int hgap = (height - upButton.height - downButton.height) / 3; upButton.x = width - upButton.width /* - gaps */; downButton.x = width - downButton.width /* - gaps */; upButton.y = hgap; downButton.y = hgap * 2 + upButton.height; Shape save0 = g2.getClip(); g2.clipRect(0, 0, width, height); super.draw(g2); if (borderColor != 0) { g2.setColor(new Color(borderColor, true)); g2.drawRect(0, 0, width - 1, height - 1); } g2.setClip(save0); }
Example 4
Source Project: astor File: SymbolAxis.java License: GNU General Public License v2.0 | 6 votes |
/** * Draws the grid bands. Alternate bands are colored using * <CODE>gridBandPaint<CODE> (<CODE>DEFAULT_GRID_BAND_PAINT</CODE> by * default). * * @param g2 the graphics device. * @param plotArea the area within which the chart should be drawn. * @param dataArea the area within which the plot should be drawn (a * subset of the drawArea). * @param edge the axis location. * @param ticks the ticks. */ protected void drawGridBands(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, List ticks) { Shape savedClip = g2.getClip(); g2.clip(dataArea); if (RectangleEdge.isTopOrBottom(edge)) { drawGridBandsHorizontal(g2, plotArea, dataArea, true, ticks); } else if (RectangleEdge.isLeftOrRight(edge)) { drawGridBandsVertical(g2, plotArea, dataArea, true, ticks); } g2.setClip(savedClip); }
Example 5
Source Project: ECG-Viewer File: Plot.java License: GNU General Public License v2.0 | 6 votes |
/** * Draws the background image (if there is one) aligned within the * specified area. * * @param g2 the graphics device. * @param area the area. * * @see #getBackgroundImage() * @see #getBackgroundImageAlignment() * @see #getBackgroundImageAlpha() */ public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) { if (this.backgroundImage == null) { return; // nothing to do } Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.backgroundImageAlpha)); Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0, this.backgroundImage.getWidth(null), this.backgroundImage.getHeight(null)); Align.align(dest, area, this.backgroundImageAlignment); Shape savedClip = g2.getClip(); g2.clip(area); g2.drawImage(this.backgroundImage, (int) dest.getX(), (int) dest.getY(), (int) dest.getWidth() + 1, (int) dest.getHeight() + 1, null); g2.setClip(savedClip); g2.setComposite(savedComposite); }
Example 6
Source Project: SIMVA-SoS File: Plot.java License: Apache License 2.0 | 6 votes |
/** * Draws a message to state that there is no data to plot. * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. */ protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) { Shape savedClip = g2.getClip(); g2.clip(area); String message = this.noDataMessage; if (message != null) { g2.setFont(this.noDataMessageFont); g2.setPaint(this.noDataMessagePaint); TextBlock block = TextUtilities.createTextBlock( this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint, 0.9f * (float) area.getWidth(), new G2TextMeasurer(g2)); block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER); } g2.setClip(savedClip); }
Example 7
Source Project: buffer_bci File: Plot.java License: GNU General Public License v3.0 | 6 votes |
/** * Draws a message to state that there is no data to plot. * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. */ protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) { Shape savedClip = g2.getClip(); g2.clip(area); String message = this.noDataMessage; if (message != null) { g2.setFont(this.noDataMessageFont); g2.setPaint(this.noDataMessagePaint); TextBlock block = TextUtilities.createTextBlock( this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint, 0.9f * (float) area.getWidth(), new G2TextMeasurer(g2)); block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER); } g2.setClip(savedClip); }
Example 8
Source Project: ccu-historian File: Plot.java License: GNU General Public License v3.0 | 6 votes |
/** * Draws the background image (if there is one) aligned within the * specified area. * * @param g2 the graphics device. * @param area the area. * * @see #getBackgroundImage() * @see #getBackgroundImageAlignment() * @see #getBackgroundImageAlpha() */ public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) { if (this.backgroundImage == null) { return; // nothing to do } Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.backgroundImageAlpha)); Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0, this.backgroundImage.getWidth(null), this.backgroundImage.getHeight(null)); Align.align(dest, area, this.backgroundImageAlignment); Shape savedClip = g2.getClip(); g2.clip(area); g2.drawImage(this.backgroundImage, (int) dest.getX(), (int) dest.getY(), (int) dest.getWidth() + 1, (int) dest.getHeight() + 1, null); g2.setClip(savedClip); g2.setComposite(savedComposite); }
Example 9
Source Project: orson-charts File: FlowElement.java License: GNU General Public License v3.0 | 5 votes |
/** * Draws the element within the specified bounds. * * @param g2 the graphics target ({@code null} not permitted). * @param bounds the bounds ({@code null} not permitted). * @param onDrawHandler an object that will receive notification before * and after the element is drawn ({@code null} permitted). * * @since 1.3 */ @Override public void draw(Graphics2D g2, Rectangle2D bounds, TableElementOnDraw onDrawHandler) { if (onDrawHandler != null) { onDrawHandler.beforeDraw(this, g2, bounds); } Shape savedClip = g2.getClip(); g2.clip(bounds); // find the preferred size of the flow layout Dimension2D prefDim = preferredSize(g2, bounds); // fit a rectangle of this dimension to the bounds according to the // element anchor Fit2D fitter = Fit2D.getNoScalingFitter(getRefPoint()); Rectangle2D dest = fitter.fit(prefDim, bounds); // perform layout within this bounding rectangle List<Rectangle2D> layoutInfo = this.layoutElements(g2, dest, null); // draw the elements for (int i = 0; i < this.elements.size(); i++) { Rectangle2D rect = layoutInfo.get(i); TableElement element = this.elements.get(i); element.draw(g2, rect, onDrawHandler); } g2.setClip(savedClip); if (onDrawHandler != null) { onDrawHandler.afterDraw(this, g2, bounds); } }
Example 10
Source Project: RipplePower File: Graphics2DStore.java License: Apache License 2.0 | 5 votes |
public void save(Graphics2D g2d) { paint = g2d.getPaint(); font = g2d.getFont(); stroke = g2d.getStroke(); transform = g2d.getTransform(); composite = g2d.getComposite(); clip = g2d.getClip(); renderingHints = g2d.getRenderingHints(); color = g2d.getColor(); background = g2d.getBackground(); }
Example 11
Source Project: coming File: Chart_15_PiePlot_s.java License: MIT License | 5 votes |
/** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing * (<code>null</code> permitted). */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); if (info != null) { info.setPlotArea(area); info.setDataArea(area); } drawBackground(g2, area); drawOutline(g2, area); Shape savedClip = g2.getClip(); g2.clip(area); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { drawPie(g2, area, info); } else { drawNoDataMessage(g2, area); } g2.setClip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, area); }
Example 12
Source Project: astor File: PiePlot.java License: GNU General Public License v2.0 | 5 votes |
/** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing * (<code>null</code> permitted). */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); if (info != null) { info.setPlotArea(area); info.setDataArea(area); } drawBackground(g2, area); drawOutline(g2, area); Shape savedClip = g2.getClip(); g2.clip(area); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { drawPie(g2, area, info); } else { drawNoDataMessage(g2, area); } g2.setClip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, area); }
Example 13
Source Project: ECG-Viewer File: FastScatterPlot.java License: GNU General Public License v2.0 | 4 votes |
/** * Draws the fast scatter plot on a Java 2D graphics device (such as the * screen or a printer). * * @param g2 the graphics device. * @param area the area within which the plot (including axis labels) * should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot (ignored). * @param info collects chart drawing information (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = new AxisSpace(); space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space); space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(area, null); if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); AxisState domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info); AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info); drawDomainGridlines(g2, dataArea, domainAxisState.getTicks()); drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); render(g2, dataArea, info, null); g2.setClip(originalClip); g2.setComposite(originalComposite); drawOutline(g2, dataArea); }
Example 14
Source Project: astor File: FastScatterPlot.java License: GNU General Public License v2.0 | 4 votes |
/** * Draws the fast scatter plot on a Java 2D graphics device (such as the * screen or a printer). * * @param g2 the graphics device. * @param area the area within which the plot (including axis labels) * should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot (ignored). * @param info collects chart drawing information (<code>null</code> * permitted). */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = new AxisSpace(); space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space); space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(area, null); if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); AxisState domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info); AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info); drawDomainGridlines(g2, dataArea, domainAxisState.getTicks()); drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); render(g2, dataArea, info, null); g2.setClip(originalClip); g2.setComposite(originalComposite); drawOutline(g2, dataArea); }
Example 15
Source Project: FlatLaf File: FlatComboBoxUI.java License: Apache License 2.0 | 4 votes |
@Override public void update( Graphics g, JComponent c ) { float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); float arc = FlatUIUtils.getBorderArc( c ); // fill background if opaque to avoid garbage if user sets opaque to true if( c.isOpaque() && (focusWidth > 0 || arc > 0) ) FlatUIUtils.paintParentBackground( g, c ); Graphics2D g2 = (Graphics2D) g; FlatUIUtils.setRenderingHints( g2 ); int width = c.getWidth(); int height = c.getHeight(); int arrowX = arrowButton.getX(); int arrowWidth = arrowButton.getWidth(); boolean paintButton = (comboBox.isEditable() || "button".equals( buttonStyle )) && !"none".equals( buttonStyle ); boolean enabled = comboBox.isEnabled(); boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight(); // paint background g2.setColor( getBackground( enabled ) ); FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); // paint arrow button background if( enabled ) { g2.setColor( paintButton ? buttonEditableBackground : buttonBackground ); Shape oldClip = g2.getClip(); if( isLeftToRight ) g2.clipRect( arrowX, 0, width - arrowX, height ); else g2.clipRect( 0, 0, arrowX + arrowWidth, height ); FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); g2.setClip( oldClip ); } // paint vertical line between value and arrow button if( paintButton ) { g2.setColor( enabled ? borderColor : disabledBorderColor ); float lw = scale( 1f ); float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw; g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2)) ); } paint( g, c ); }
Example 16
Source Project: astor File: WaferMapPlot.java License: GNU General Public License v2.0 | 4 votes |
/** * Calculates and draws the chip locations on the wafer. * * @param g2 the graphics device. * @param plotArea the plot area. */ protected void drawChipGrid(Graphics2D g2, Rectangle2D plotArea) { Shape savedClip = g2.getClip(); g2.setClip(getWaferEdge(plotArea)); Rectangle2D chip = new Rectangle2D.Double(); int xchips = 35; int ychips = 20; double space = 1d; if (this.dataset != null) { xchips = this.dataset.getMaxChipX() + 2; ychips = this.dataset.getMaxChipY() + 2; space = this.dataset.getChipSpace(); } double startX = plotArea.getX(); double startY = plotArea.getY(); double chipWidth = 1d; double chipHeight = 1d; if (plotArea.getWidth() != plotArea.getHeight()) { double major = 0d; double minor = 0d; if (plotArea.getWidth() > plotArea.getHeight()) { major = plotArea.getWidth(); minor = plotArea.getHeight(); } else { major = plotArea.getHeight(); minor = plotArea.getWidth(); } //set upperLeft point if (plotArea.getWidth() == minor) { // x is minor startY += (major - minor) / 2; chipWidth = (plotArea.getWidth() - (space * xchips - 1)) / xchips; chipHeight = (plotArea.getWidth() - (space * ychips - 1)) / ychips; } else { // y is minor startX += (major - minor) / 2; chipWidth = (plotArea.getHeight() - (space * xchips - 1)) / xchips; chipHeight = (plotArea.getHeight() - (space * ychips - 1)) / ychips; } } for (int x = 1; x <= xchips; x++) { double upperLeftX = (startX - chipWidth) + (chipWidth * x) + (space * (x - 1)); for (int y = 1; y <= ychips; y++) { double upperLeftY = (startY - chipHeight) + (chipHeight * y) + (space * (y - 1)); chip.setFrame(upperLeftX, upperLeftY, chipWidth, chipHeight); g2.setColor(Color.white); if (this.dataset.getChipValue(x - 1, ychips - y - 1) != null) { g2.setPaint( this.renderer.getChipColor( this.dataset.getChipValue(x - 1, ychips - y - 1) ) ); } g2.fill(chip); g2.setColor(Color.lightGray); g2.draw(chip); } } g2.setClip(savedClip); }
Example 17
Source Project: buffer_bci File: FastScatterPlot.java License: GNU General Public License v3.0 | 4 votes |
/** * Draws the fast scatter plot on a Java 2D graphics device (such as the * screen or a printer). * * @param g2 the graphics device. * @param area the area within which the plot (including axis labels) * should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot (ignored). * @param info collects chart drawing information (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = new AxisSpace(); space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space); space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(area, null); if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); AxisState domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info); AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info); drawDomainGridlines(g2, dataArea, domainAxisState.getTicks()); drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); render(g2, dataArea, info, null); g2.setClip(originalClip); g2.setComposite(originalComposite); drawOutline(g2, dataArea); }
Example 18
Source Project: SIMVA-SoS File: PolarPlot.java License: Apache License 2.0 | 4 votes |
/** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * <P> * This plot relies on a {@link PolarItemRenderer} to draw each * item in the plot. This allows the visual representation of the data to * be changed easily. * <P> * The optional info argument collects information about the rendering of * the plot (dimensions, tooltip information etc). Just pass in * <code>null</code> if you do not need this information. * * @param g2 the graphics device. * @param area the area within which the plot (including axes and * labels) should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState ignored. * @param info collects chart drawing information (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // if the plot area is too small, just return... boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); if (b1 || b2) { return; } // record the plot area... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); Rectangle2D dataArea = area; if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); int axisCount = this.axes.size(); AxisState state = null; for (int i = 0; i < axisCount; i++) { ValueAxis axis = getAxis(i); if (axis != null) { PolarAxisLocation location = (PolarAxisLocation) this.axisLocations.get(i); AxisState s = this.drawAxis(axis, location, g2, dataArea); if (i == 0) { state = s; } } } // now for each dataset, get the renderer and the appropriate axis // and render the dataset... Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); this.angleTicks = refreshAngleTicks(); drawGridlines(g2, dataArea, this.angleTicks, state.getTicks()); render(g2, dataArea, info); g2.setClip(originalClip); g2.setComposite(originalComposite); drawOutline(g2, dataArea); drawCornerTextItems(g2, dataArea); }
Example 19
Source Project: jasperreports File: TextDrawer.java License: GNU Lesser General Public License v3.0 | 4 votes |
@Override public void draw(Graphics2D grx, JRPrintText text, int offsetX, int offsetY) { textRenderer.initialize(grx, text, offsetX, offsetY); JRStyledText styledText = textRenderer.getStyledText(); if (styledText == null) { return; } double angle = 0; switch (text.getRotationValue()) { case LEFT : { angle = - Math.PI / 2; break; } case RIGHT : { angle = Math.PI / 2; break; } case UPSIDE_DOWN : { angle = Math.PI; break; } case NONE : default : { } } Shape oldClip = grx.getClip(); grx.rotate(angle, textRenderer.getX(), textRenderer.getY()); if (text.getModeValue() == ModeEnum.OPAQUE) { grx.setColor(text.getBackcolor()); grx.fillRect(textRenderer.getX(), textRenderer.getY(), textRenderer.getWidth(), textRenderer.getHeight()); } // else // { // /* // grx.setColor(text.getForecolor()); // grx.setStroke(new BasicStroke(1)); // grx.drawRect(x, y, width, height); // */ // } grx.clip( new Rectangle( textRenderer.getX() + textRenderer.getLeftPadding(), textRenderer.getY() + textRenderer.getTopPadding(), textRenderer.getWidth() - textRenderer.getLeftPadding() - textRenderer.getRightPadding(), textRenderer.getHeight() - textRenderer.getTopPadding() - textRenderer.getBottomPadding() ) ); try { String allText = textRenderer.getPlainText(); if (allText.length() > 0) { grx.setColor(text.getForecolor()); /* */ textRenderer.render(); } } finally { grx.rotate(-angle, textRenderer.getX(), textRenderer.getY()); grx.setClip(oldClip); } /* */ drawBox(grx, text.getLineBox(), text, offsetX, offsetY); }
Example 20
Source Project: SIMVA-SoS File: DialValueIndicator.java License: Apache License 2.0 | 4 votes |
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // the indicator bounds is calculated from the templateValue (which // determines the minimum size), the maxTemplateValue (which, if // specified, provides a maximum size) and the actual value FontMetrics fm = g2.getFontMetrics(this.font); double value = plot.getValue(this.datasetIndex); String valueStr = this.formatter.format(value); Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm); // calculate the bounds of the template value String s = this.formatter.format(this.templateValue); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); double minW = tb.getWidth(); double minH = tb.getHeight(); double maxW = Double.MAX_VALUE; double maxH = Double.MAX_VALUE; if (this.maxTemplateValue != null) { s = this.formatter.format(this.maxTemplateValue); tb = TextUtilities.getTextBounds(s, g2, fm); maxW = Math.max(tb.getWidth(), minW); maxH = Math.max(tb.getHeight(), minH); } double w = fixToRange(valueBounds.getWidth(), minW, maxW); double h = fixToRange(valueBounds.getHeight(), minH, maxH); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); // draw the background g2.setPaint(this.backgroundPaint); g2.fill(fb); // draw the border g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(fb); // now find the text anchor point Shape savedClip = g2.getClip(); g2.clip(fb); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); g2.setClip(savedClip); }