Java Code Examples for java.awt.Graphics2D#getComposite()
The following examples show how to use
java.awt.Graphics2D#getComposite() .
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 File: GroupingMode.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
@Override public void paint( Graphics2D g, Rectangle srcRect, double magnification, boolean active, int channels, Layer active_layer, List<Layer> layers) { final AffineTransform at = g.getTransform(); final AffineTransform atp = new AffineTransform(); atp.translate( -pad, -pad ); g.setTransform( atp ); Composite original_composite = null; if (Displayable.COMPOSITE_NORMAL != compositeMode) { original_composite = g.getComposite(); g.setComposite(Displayable.getComposite(compositeMode, 1.0f)); } g.drawImage( transformedImage, 0, 0, null ); if (null != original_composite) { g.setComposite(original_composite); } g.setTransform( at ); }
Example 2
Source File: SeaGlassBrowser.java From seaglass with Apache License 2.0 | 6 votes |
static void printInsets(PrintWriter html, Insets insets) { html.println("<td>Insets (" + insets.top + "," + insets.left + "," + insets.bottom + "," + insets.right + ")</pre></td>"); int w = 50 + insets.left + insets.right; int h = 20 + insets.top + insets.bottom; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.Clear); g2.fillRect(0, 0, w, h); g2.setComposite(old); g2.setColor(Color.BLACK); g2.drawRect(insets.left, insets.top, 49, 19); g2.setColor(Color.RED); g2.drawRect(0, 0, w - 1, h - 1); g2.dispose(); html.println("<td>" + saveImage(img) + "</td>"); }
Example 3
Source File: LivreBase.java From brModelo with GNU General Public License v3.0 | 5 votes |
@Override protected void PinteRegiao(Graphics2D g) { Composite originalComposite = g.getComposite(); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa)); g.setPaint(this.getForeColor()); if (isGradiente()) { int dist = 0; int w = getWidth() - dist; int h = getHeight() - dist; int L = getLeft(); int T = getTop(); boolean dv = getGDirecao() == VERTICAL; GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + w, dv ? T + h : T, getGradienteEndColor(), true); g.setPaint(GP); } if (getTipoDesenho() != TipoDraw.tpTexto) { Stroke bkp = g.getStroke(); if (isDashed()) { g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0)); } if (isGradiente()) { g.fill(getRegiao()); } g.draw(getRegiao()); //Pinta as eventuais linhas internas do dezenho. Ex. LivreVariosDocumemtos g.setStroke(bkp); } g.setComposite(originalComposite); }
Example 4
Source File: FormaArea.java From brModelo with GNU General Public License v3.0 | 5 votes |
protected void PaintGradiente(Graphics2D g) { //, boolean round) { Paint bkp = g.getPaint(); int dist = distSelecao; int W = getWidth() - dist; int H = 2 * alturaTexto - 1 - dist; boolean dv = getGDirecao() == VERTICAL; Composite originalComposite = g.getComposite(); int type = AlphaComposite.SRC_OVER; g.setComposite(AlphaComposite.getInstance(type, alfa)); Stroke bkps = g.getStroke(); if (isDashed()) { g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0)); } // GradientPaint GP = new GradientPaint(getLeft(), getTop(), Color.LIGHT_GRAY, dv ? getLeft() : getLeft() + W, dv ? getTop() + H : getTop(), Color.white, true); // g.setPaint(GP); int w = getWidth() - dist; int h = getHeight() - dist; int L = getLeft(); int T = getTop(); GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + w, dv ? T + h : T, getGradienteEndColor(), true); g.setPaint(GP); g.fillRect(getLeft() + 1, getTop() + 1, W, H); g.setComposite(originalComposite); g.setPaint(bkp); g.setStroke(bkps); }
Example 5
Source File: SpiderWebPlot.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Draws the label for one axis. * * @param g2 the graphics device. * @param plotArea the plot area * @param value the value of the label (ignored). * @param cat the category (zero-based index). * @param startAngle the starting angle. * @param extent the extent of the arc. */ protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value, int cat, double startAngle, double extent) { FontRenderContext frc = g2.getFontRenderContext(); String label; if (this.dataExtractOrder == TableOrder.BY_ROW) { // if series are in rows, then the categories are the column keys label = this.labelGenerator.generateColumnLabel(this.dataset, cat); } else { // if series are in columns, then the categories are the row keys label = this.labelGenerator.generateRowLabel(this.dataset, cat); } Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc); LineMetrics lm = getLabelFont().getLineMetrics(label, frc); double ascent = lm.getAscent(); Point2D labelLocation = calculateLabelLocation(labelBounds, ascent, plotArea, startAngle); Composite saveComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.setPaint(getLabelPaint()); g2.setFont(getLabelFont()); g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY()); g2.setComposite(saveComposite); }
Example 6
Source File: FreeColComboBoxRenderer.java From freecol with GNU General Public License v2.0 | 5 votes |
@Override public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; Composite oldComposite = g2d.getComposite(); Color oldColor = g2d.getColor(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, getWidth(), getHeight()); g2d.setComposite(oldComposite); g2d.setColor(oldColor); super.paintComponent(g); }
Example 7
Source File: SpiderWebPlot.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Draws the label for one axis. * * @param g2 the graphics device. * @param plotArea the plot area * @param value the value of the label (ignored). * @param cat the category (zero-based index). * @param startAngle the starting angle. * @param extent the extent of the arc. */ protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value, int cat, double startAngle, double extent) { FontRenderContext frc = g2.getFontRenderContext(); String label; if (this.dataExtractOrder == TableOrder.BY_ROW) { // if series are in rows, then the categories are the column keys label = this.labelGenerator.generateColumnLabel(this.dataset, cat); } else { // if series are in columns, then the categories are the row keys label = this.labelGenerator.generateRowLabel(this.dataset, cat); } Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc); LineMetrics lm = getLabelFont().getLineMetrics(label, frc); double ascent = lm.getAscent(); Point2D labelLocation = calculateLabelLocation(labelBounds, ascent, plotArea, startAngle); Composite saveComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.setPaint(getLabelPaint()); g2.setFont(getLabelFont()); g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY()); g2.setComposite(saveComposite); }
Example 8
Source File: ClipPath.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Draws the clip path. * * @param g2 current graphics2D. * @param dataArea the dataArea that the plot is being draw in. * @param horizontalAxis the horizontal axis. * @param verticalAxis the vertical axis. * * @return The GeneralPath defining the outline */ public GeneralPath draw(Graphics2D g2, Rectangle2D dataArea, ValueAxis horizontalAxis, ValueAxis verticalAxis) { GeneralPath generalPath = generateClipPath( dataArea, horizontalAxis, verticalAxis ); if (this.fillPath || this.drawPath) { Composite saveComposite = g2.getComposite(); Paint savePaint = g2.getPaint(); Stroke saveStroke = g2.getStroke(); if (this.fillPaint != null) { g2.setPaint(this.fillPaint); } if (this.composite != null) { g2.setComposite(this.composite); } if (this.fillPath) { g2.fill(generalPath); } if (this.drawStroke != null) { g2.setStroke(this.drawStroke); } if (this.drawPath) { g2.draw(generalPath); } g2.setPaint(savePaint); g2.setComposite(saveComposite); g2.setStroke(saveStroke); } return generalPath; }
Example 9
Source File: WaitLayerUIPanel.java From mars-sim with GNU General Public License v3.0 | 5 votes |
@Override public void paint(Graphics g, JComponent c) { int w = c.getWidth(); int h = c.getHeight(); super.paint(g, c); // Paint the view. if (!mIsRunning) { return; } Graphics2D g2 = (Graphics2D) g.create(); float fade = (float) mFadeCount / (float) mFadeLimit; Composite urComposite = g2.getComposite(); // Gray it out. g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f * fade)); g2.fillRect(0, 0, w, h); g2.setComposite(urComposite); int s = Math.min(w, h) / 5;// Paint the wait indicator. int cx = w / 2; int cy = h / 2; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); g2.setPaint(Color.white); g2.rotate(Math.PI * mAngle / 180, cx, cy); for (int i = 0; i < 12; i++) { float scale = (11.0f - (float) i) / 11.0f; g2.drawLine(cx + s, cy, cx + s * 2, cy); g2.rotate(-Math.PI / 6, cx, cy); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, scale * fade)); } g2.dispose(); }
Example 10
Source File: GameOverScreen.java From open-ig with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void draw(Graphics2D g2) { continueButton.visible(false); mainMenuButton.visible(false); winLabel.visible(false); if (showImage) { g2.setColor(Color.BLACK); g2.fillRect(0, 0, width, height); BufferedImage gameover = commons.background().gameover; Composite save0 = g2.getComposite(); if (imageAlpha < 1) { g2.setComposite(AlphaComposite.SrcOver.derive(imageAlpha)); } int bw = gameover.getWidth(); int bh = gameover.getHeight(); int dx = (width - bw) / 2; int dy = (height - bh) / 2; g2.drawImage(gameover, dx, dy, null); loadButton.visible(true); mainMenuButton.visible(true); continueButton.visible(win); winLabel.visible(win); winLabel.location(dx, dy + 40); winLabel.size(bw, 30); winLabel.horizontally(HorizontalAlignment.CENTER); winLabel.color(TextRenderer.YELLOW); int by = dy + bh - 50; placeButtons(dx, by, bw, 20, continueButton, loadButton, mainMenuButton); super.draw(g2); g2.setComposite(save0); } }
Example 11
Source File: Arja_0062_t.java From coming with MIT License | 4 votes |
/** * Draws a marker for the domain axis. * * @param g2 the graphics device (not <code>null</code>). * @param plot the plot (not <code>null</code>). * @param axis the range axis (not <code>null</code>). * @param marker the marker to be drawn (not <code>null</code>). * @param dataArea the area inside the axes (not <code>null</code>). * * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker, * Rectangle2D) */ public void drawDomainMarker(Graphics2D g2, CategoryPlot plot, CategoryAxis axis, CategoryMarker marker, Rectangle2D dataArea) { Comparable category = marker.getKey(); CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this)); int columnIndex = dataset.getColumnIndex(category); if (columnIndex < 0) { return; } final Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, marker.getAlpha())); PlotOrientation orientation = plot.getOrientation(); Rectangle2D bounds = null; if (marker.getDrawAsLine()) { double v = axis.getCategoryMiddle(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } g2.setPaint(marker.getPaint()); g2.setStroke(marker.getStroke()); g2.draw(line); bounds = line.getBounds2D(); } else { double v0 = axis.getCategoryStart(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); double v1 = axis.getCategoryEnd(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Rectangle2D area = null; if (orientation == PlotOrientation.HORIZONTAL) { area = new Rectangle2D.Double(dataArea.getMinX(), v0, dataArea.getWidth(), (v1 - v0)); } else if (orientation == PlotOrientation.VERTICAL) { area = new Rectangle2D.Double(v0, dataArea.getMinY(), (v1 - v0), dataArea.getHeight()); } g2.setPaint(marker.getPaint()); g2.fill(area); bounds = area; } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); g2.setFont(labelFont); g2.setPaint(marker.getLabelPaint()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint( g2, orientation, dataArea, bounds, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor()); } g2.setComposite(savedComposite); }
Example 12
Source File: Cardumen_00139_t.java From coming with MIT License | 4 votes |
/** * Draws a marker for the domain axis. * * @param g2 the graphics device (not <code>null</code>). * @param plot the plot (not <code>null</code>). * @param axis the range axis (not <code>null</code>). * @param marker the marker to be drawn (not <code>null</code>). * @param dataArea the area inside the axes (not <code>null</code>). * * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker, * Rectangle2D) */ public void drawDomainMarker(Graphics2D g2, CategoryPlot plot, CategoryAxis axis, CategoryMarker marker, Rectangle2D dataArea) { Comparable category = marker.getKey(); CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this)); int columnIndex = dataset.getColumnIndex(category); if (columnIndex < 0) { return; } final Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, marker.getAlpha())); PlotOrientation orientation = plot.getOrientation(); Rectangle2D bounds = null; if (marker.getDrawAsLine()) { double v = axis.getCategoryMiddle(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } g2.setPaint(marker.getPaint()); g2.setStroke(marker.getStroke()); g2.draw(line); bounds = line.getBounds2D(); } else { double v0 = axis.getCategoryStart(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); double v1 = axis.getCategoryEnd(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Rectangle2D area = null; if (orientation == PlotOrientation.HORIZONTAL) { area = new Rectangle2D.Double(dataArea.getMinX(), v0, dataArea.getWidth(), (v1 - v0)); } else if (orientation == PlotOrientation.VERTICAL) { area = new Rectangle2D.Double(v0, dataArea.getMinY(), (v1 - v0), dataArea.getHeight()); } g2.setPaint(marker.getPaint()); g2.fill(area); bounds = area; } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); g2.setFont(labelFont); g2.setPaint(marker.getLabelPaint()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint( g2, orientation, dataArea, bounds, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor()); } g2.setComposite(savedComposite); }
Example 13
Source File: JSoftGraph.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
void paintNodeInArc(Graphics2D g, Node node) { double inMin = node.getInMin(); double inMax = node.getInMax(); double inSize = inMax - inMin; int nTotal = node.getInLinks().size(); if(inSize < nTotal) { Composite oldComp = g.getComposite(); Composite alpha = inArcActive ? alphaHalf : alphaSome; g.setComposite(alpha); double aStart = 180.0 * inMin / nTotal; double aSize = Math.max(2, 180.0 * inSize / nTotal); int rx = 40; int ry = (int)(rx * .8); Util.setAntialias(g, true); // background arc g.setColor(arcInCol1); g.fillArc((int)(0 - rx), (int)(0 - ry), rx * 2, ry * 2, 180, 180); // g.setComposite(alphaHalf); // size arc g.setColor(arcInCol2); g.fillArc((int)(0 - rx), (int)(0 - ry), rx * 2, ry * 2, 180 + (int)aStart, (int)aSize); g.setComposite(oldComp); Util.setAntialias(g, false); } }
Example 14
Source File: PiePlot.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Draws the labels for the pie sections. * * @param g2 the graphics device. * @param keys the keys. * @param totalValue the total value. * @param plotArea the plot area. * @param linkArea the link area. * @param state the state. */ protected void drawLabels(Graphics2D g2, List keys, double totalValue, Rectangle2D plotArea, Rectangle2D linkArea, PiePlotState state) { Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); // classify the keys according to which side the label will appear... DefaultKeyedValues leftKeys = new DefaultKeyedValues(); DefaultKeyedValues rightKeys = new DefaultKeyedValues(); double runningTotal = 0.0; Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); boolean include; double v = 0.0; Number n = this.dataset.getValue(key); if (n == null) { include = !this.ignoreNullValues; } else { v = n.doubleValue(); include = this.ignoreZeroValues ? v > 0.0 : v >= 0.0; } if (include) { runningTotal = runningTotal + v; // work out the mid angle (0 - 90 and 270 - 360) = right, // otherwise left double mid = this.startAngle + (this.direction.getFactor() * ((runningTotal - v / 2.0) * 360) / totalValue); if (Math.cos(Math.toRadians(mid)) < 0.0) { leftKeys.addValue(key, new Double(mid)); } else { rightKeys.addValue(key, new Double(mid)); } } } g2.setFont(getLabelFont()); // calculate the max label width from the plot dimensions, because // a circular pie can leave a lot more room for labels... double marginX = plotArea.getX(); double gap = plotArea.getWidth() * this.labelGap; double ww = linkArea.getX() - gap - marginX; float labelWidth = (float) this.labelPadding.trimWidth(ww); // draw the labels... if (this.labelGenerator != null) { drawLeftLabels(leftKeys, g2, plotArea, linkArea, labelWidth, state); drawRightLabels(rightKeys, g2, plotArea, linkArea, labelWidth, state); } g2.setComposite(originalComposite); }
Example 15
Source File: jMutRepair_000_s.java From coming with MIT License | 4 votes |
/** * Draws a marker for the domain axis. * * @param g2 the graphics device (not <code>null</code>). * @param plot the plot (not <code>null</code>). * @param axis the range axis (not <code>null</code>). * @param marker the marker to be drawn (not <code>null</code>). * @param dataArea the area inside the axes (not <code>null</code>). * * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker, * Rectangle2D) */ public void drawDomainMarker(Graphics2D g2, CategoryPlot plot, CategoryAxis axis, CategoryMarker marker, Rectangle2D dataArea) { Comparable category = marker.getKey(); CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this)); int columnIndex = dataset.getColumnIndex(category); if (columnIndex < 0) { return; } final Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, marker.getAlpha())); PlotOrientation orientation = plot.getOrientation(); Rectangle2D bounds = null; if (marker.getDrawAsLine()) { double v = axis.getCategoryMiddle(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } g2.setPaint(marker.getPaint()); g2.setStroke(marker.getStroke()); g2.draw(line); bounds = line.getBounds2D(); } else { double v0 = axis.getCategoryStart(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); double v1 = axis.getCategoryEnd(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Rectangle2D area = null; if (orientation == PlotOrientation.HORIZONTAL) { area = new Rectangle2D.Double(dataArea.getMinX(), v0, dataArea.getWidth(), (v1 - v0)); } else if (orientation == PlotOrientation.VERTICAL) { area = new Rectangle2D.Double(v0, dataArea.getMinY(), (v1 - v0), dataArea.getHeight()); } g2.setPaint(marker.getPaint()); g2.fill(area); bounds = area; } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); g2.setFont(labelFont); g2.setPaint(marker.getLabelPaint()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint( g2, orientation, dataArea, bounds, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor()); } g2.setComposite(savedComposite); }
Example 16
Source File: PiePlot.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Draws the labels for the pie sections. * * @param g2 the graphics device. * @param keys the keys. * @param totalValue the total value. * @param plotArea the plot area. * @param linkArea the link area. * @param state the state. */ protected void drawLabels(Graphics2D g2, List keys, double totalValue, Rectangle2D plotArea, Rectangle2D linkArea, PiePlotState state) { Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); // classify the keys according to which side the label will appear... DefaultKeyedValues leftKeys = new DefaultKeyedValues(); DefaultKeyedValues rightKeys = new DefaultKeyedValues(); double runningTotal = 0.0; Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); boolean include; double v = 0.0; Number n = this.dataset.getValue(key); if (n == null) { include = !this.ignoreNullValues; } else { v = n.doubleValue(); include = this.ignoreZeroValues ? v > 0.0 : v >= 0.0; } if (include) { runningTotal = runningTotal + v; // work out the mid angle (0 - 90 and 270 - 360) = right, // otherwise left double mid = this.startAngle + (this.direction.getFactor() * ((runningTotal - v / 2.0) * 360) / totalValue); if (Math.cos(Math.toRadians(mid)) < 0.0) { leftKeys.addValue(key, new Double(mid)); } else { rightKeys.addValue(key, new Double(mid)); } } } g2.setFont(getLabelFont()); // calculate the max label width from the plot dimensions, because // a circular pie can leave a lot more room for labels... double marginX = plotArea.getX(); double gap = plotArea.getWidth() * this.labelGap; double ww = linkArea.getX() - gap - marginX; float labelWidth = (float) this.labelPadding.trimWidth(ww); // draw the labels... if (this.labelGenerator != null) { drawLeftLabels(leftKeys, g2, plotArea, linkArea, labelWidth, state); drawRightLabels(rightKeys, g2, plotArea, linkArea, labelWidth, state); } g2.setComposite(originalComposite); }
Example 17
Source File: jKali_0031_s.java From coming with MIT License | 4 votes |
/** * Draws a marker for the domain axis. * * @param g2 the graphics device (not <code>null</code>). * @param plot the plot (not <code>null</code>). * @param axis the range axis (not <code>null</code>). * @param marker the marker to be drawn (not <code>null</code>). * @param dataArea the area inside the axes (not <code>null</code>). * * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker, * Rectangle2D) */ public void drawDomainMarker(Graphics2D g2, CategoryPlot plot, CategoryAxis axis, CategoryMarker marker, Rectangle2D dataArea) { Comparable category = marker.getKey(); CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this)); int columnIndex = dataset.getColumnIndex(category); if (columnIndex < 0) { return; } final Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, marker.getAlpha())); PlotOrientation orientation = plot.getOrientation(); Rectangle2D bounds = null; if (marker.getDrawAsLine()) { double v = axis.getCategoryMiddle(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } g2.setPaint(marker.getPaint()); g2.setStroke(marker.getStroke()); g2.draw(line); bounds = line.getBounds2D(); } else { double v0 = axis.getCategoryStart(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); double v1 = axis.getCategoryEnd(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Rectangle2D area = null; if (orientation == PlotOrientation.HORIZONTAL) { area = new Rectangle2D.Double(dataArea.getMinX(), v0, dataArea.getWidth(), (v1 - v0)); } else if (orientation == PlotOrientation.VERTICAL) { area = new Rectangle2D.Double(v0, dataArea.getMinY(), (v1 - v0), dataArea.getHeight()); } g2.setPaint(marker.getPaint()); g2.fill(area); bounds = area; } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); g2.setFont(labelFont); g2.setPaint(marker.getLabelPaint()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint( g2, orientation, dataArea, bounds, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor()); } g2.setComposite(savedComposite); }
Example 18
Source File: LuckScrollBarUI.java From littleluck with Apache License 2.0 | 4 votes |
/** * <p>使用点九图绘制滑块。</p> * * <p>use nine patch image to draw the thumb.</p> */ protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) { return; } int w = thumbBounds.width; int h = thumbBounds.height; g.translate(thumbBounds.x, thumbBounds.y); // 为了美观,这里和内容面板保持一个像素的间距。 // For aesthetic reasons, this and the content panel maintain a pixel pitch. if(scrollbar.getOrientation() == JScrollBar.VERTICAL) { w = w - 1; } else if(scrollbar.getOrientation() == JScrollBar.HORIZONTAL) { h = h - 1; } // 增加hover效果 Graphics2D g2d = (Graphics2D)g; AlphaComposite composite = (AlphaComposite) g2d.getComposite(); if(!isThumbRollover()) { AlphaComposite transulent = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.7f); g2d.setComposite(transulent); } if (np != null) { np.drawNinePatch(g2d, 0, 0, w, h); } g.translate(-thumbBounds.x, -thumbBounds.y); g2d.setComposite(composite); }
Example 19
Source File: JSoftGraph.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 3 votes |
static void paintMirror(Graphics2D g, Color c, String s, int x, int y, double k, boolean bMirror) { Composite oldComp = g.getComposite(); AffineTransform oldTrans = g.getTransform(); Util.setAntialias(g, true); g.translate(x, y); g.scale(k, k); g.setColor(c); g.drawString(s, 0, 0); if(bMirror) { g.setComposite(alphaSome); g.setTransform(oldTrans); g.translate(x, y); g.scale(k, -k*1.2); g.shear(-0.25, 0); g.setColor(c); g.drawString(s, 0, 0); } g.setTransform(oldTrans); g.setComposite(oldComp); Util.setAntialias(g, false); }
Example 20
Source File: AvatarChooser.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | votes |
private void drawAvatarName(Graphics2D g2) { Composite composite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, textAlphaLevel)); double bulletWidth = 150.0; double bulletHeight = 30.0; double x = (getWidth() - bulletWidth) / 2.0; double y = (getHeight() - 164) / 2.0 - bulletHeight * 1.4; drawAvatarBullet(g2, x, y, bulletWidth, bulletHeight); drawAvatarText(g2, y, bulletHeight); g2.setComposite(composite); }