Java Code Examples for java.awt.geom.Arc2D#PIE
The following examples show how to use
java.awt.geom.Arc2D#PIE .
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: MultiStepProgressBar.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Paint the animated bubble indicating that the progress is currently made towards this bubble. * * @param g2 * the graphics to paint on * @param widthPerStep * the width per step (depending on the used step labels) * @param xPos * the current x-position * @param textY * the y-position of the texts */ private void paintAnimatedBubble(Graphics2D g2, int widthPerStep, int xPos, int textY) { // fill gray bubble with orange and then with gray again final boolean inOddAnimationPhase = bubbleAnimationPhase % 2 == 1; g2.setColor(inOddAnimationPhase ? BACKGROUND_COLOR : color); int bubbleX = (int) Math.round(xPos + widthPerStep / 2.0d - BUBBLE_DIAMETER / 2.0d); int bubbleY = (int) Math.round(textY + 8 + (LARGE_BUBBLE_DIAMETER - BUBBLE_DIAMETER) / 2.0d); g2.fillOval(bubbleX, bubbleY, BUBBLE_DIAMETER, BUBBLE_DIAMETER); // then orange partly filled bubble double percentage = animationStep / (double) MAX_ANIMATION_STEPS; double extent = 360d * percentage; g2.setColor(inOddAnimationPhase ? color : BACKGROUND_COLOR); Arc2D arc = new Arc2D.Double(bubbleX, bubbleY, BUBBLE_DIAMETER, BUBBLE_DIAMETER, 90, -extent, Arc2D.PIE); g2.fill(arc); }
Example 2
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
private void initShape() { if (!getBounds().equals(base)) { base = getBounds(); double ww = getWidth() * .5; double xx = ww * .5; Shape inner = new Ellipse2D.Double(xx, xx, ww, ww); if (ButtonLocation.CENTER == bl) { shape = inner; } else { // TEST: parent.isOptimizedDrawingEnabled: false double dw = getWidth() - 2d; double dh = getHeight() - 2d; Shape outer = new Arc2D.Double(1d, 1d, dw, dh, bl.getStartAngle(), 90d, Arc2D.PIE); Area area = new Area(outer); area.subtract(new Area(inner)); shape = area; } } }
Example 3
Source File: RadialWipeTransition2D.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
@Override public Transition2DInstruction[] getInstructions(float progress, Dimension size) { int multiplier2 = -1; if (type == COUNTER_CLOCKWISE) { multiplier2 = 1; } //for a good time, don't make multiplier1 = 0 int multiplier1 = 0; //multiplier2; int k = Math.max(size.width, size.height); Area area = new Area(new Arc2D.Double(new Rectangle2D.Double(size.width / 2 - 2 * k, size.height / 2 - 2 * k, k * 4, k * 4), 90 + multiplier1 * progress * 360, multiplier2 * progress * 360, Arc2D.PIE)); area.intersect(new Area(new Rectangle(0, 0, size.width, size.height))); return new ImageInstruction[]{ new ImageInstruction(true), new ImageInstruction(false, null, area) }; }
Example 4
Source File: RadialWipeTransition2D.java From pumpernickel with MIT License | 6 votes |
@Override public Transition2DInstruction[] getInstructions(float progress, Dimension size) { int multiplier2 = -1; if (type == COUNTER_CLOCKWISE) multiplier2 = 1; // for a good time, don't make multiplier1 = 0 int multiplier1 = 0; // multiplier2; int k = Math.max(size.width, size.height); Area area = new Area(new Arc2D.Double(new Rectangle2D.Double(size.width / 2 - 2 * k, size.height / 2 - 2 * k, k * 4, k * 4), 90 + multiplier1 * progress * 360, multiplier2 * progress * 360, Arc2D.PIE)); area.intersect(new Area(new Rectangle(0, 0, size.width, size.height))); return new ImageInstruction[] { new ImageInstruction(true), new ImageInstruction(false, null, area) }; }
Example 5
Source File: PlumNeedle.java From opensim-gui with Apache License 2.0 | 6 votes |
/** * Draws the needle. * * @param g2 the graphics device. * @param plotArea the plot area. * @param rotate the rotation point. * @param angle the angle. */ protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) { Arc2D shape = new Arc2D.Double(Arc2D.PIE); double radius = plotArea.getHeight(); double halfX = plotArea.getWidth() / 2; double diameter = 2 * radius; shape.setFrame(plotArea.getMinX() + halfX - radius , plotArea.getMinY() - radius, diameter, diameter); radius = Math.toDegrees(Math.asin(halfX / radius)); shape.setAngleStart(270 - radius); shape.setAngleExtent(2 * radius); Area s = new Area(shape); if ((rotate != null) && (angle != 0)) { /// we have rotation houston, please spin me getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); s.transform(getTransform()); } defaultDisplay(g2, s); }
Example 6
Source File: FXGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
private ArcType intToArcType(int t) { if (t == Arc2D.CHORD) { return ArcType.CHORD; } else if (t == Arc2D.OPEN) { return ArcType.OPEN; } else if (t == Arc2D.PIE) { return ArcType.ROUND; } throw new IllegalArgumentException("Unrecognised t: " + t); }
Example 7
Source File: MeterPlot.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Fills an arc on the dial between the given values. * * @param g2 the graphics device. * @param area the plot area. * @param minValue the minimum data value. * @param maxValue the maximum data value. * @param paint the background paint (<code>null</code> not permitted). * @param dial a flag that indicates whether the arc represents the whole * dial. */ protected void fillArc(Graphics2D g2, Rectangle2D area, double minValue, double maxValue, Paint paint, boolean dial) { ParamChecks.nullNotPermitted(paint, "paint"); double startAngle = valueToAngle(maxValue); double endAngle = valueToAngle(minValue); double extent = endAngle - startAngle; double x = area.getX(); double y = area.getY(); double w = area.getWidth(); double h = area.getHeight(); int joinType = Arc2D.OPEN; if (this.shape == DialShape.PIE) { joinType = Arc2D.PIE; } else if (this.shape == DialShape.CHORD) { if (dial && this.meterAngle > 180) { joinType = Arc2D.CHORD; } else { joinType = Arc2D.PIE; } } else if (this.shape == DialShape.CIRCLE) { joinType = Arc2D.PIE; if (dial) { extent = 360; } } else { throw new IllegalStateException("DialShape not recognised."); } g2.setPaint(paint); Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent, joinType); g2.fill(arc); }
Example 8
Source File: PlumNeedle.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Draws the needle. * * @param g2 the graphics device. * @param plotArea the plot area. * @param rotate the rotation point. * @param angle the angle. */ @Override protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) { Arc2D shape = new Arc2D.Double(Arc2D.PIE); double radius = plotArea.getHeight(); double halfX = plotArea.getWidth() / 2; double diameter = 2 * radius; shape.setFrame(plotArea.getMinX() + halfX - radius , plotArea.getMinY() - radius, diameter, diameter); radius = Math.toDegrees(Math.asin(halfX / radius)); shape.setAngleStart(270 - radius); shape.setAngleExtent(2 * radius); Area s = new Area(shape); if ((rotate != null) && (angle != 0)) { /// we have rotation houston, please spin me getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); s.transform(getTransform()); } defaultDisplay(g2, s); }
Example 9
Source File: MercuryLoadingUi.java From MercuryTrade with MIT License | 5 votes |
@Override public void paint(Graphics g, JComponent c) { if (component.getWidth() == 0) { return; } Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); double degree = 360 * component.getPercentComplete(); double size = 60; double outerR = size * .5; double innerR = outerR * .78; double pointX = component.getWidth() * .5; double pointY = component.getHeight() * .5; Shape inner = new Ellipse2D.Double(pointX - innerR, pointY - innerR, innerR * 2, innerR * 2); Shape outer = new Ellipse2D.Double(pointX - outerR, pointY - outerR, size, size); Shape sector = new Arc2D.Double(pointX - outerR, pointY - outerR, size, size, 90 - degree, degree, Arc2D.PIE); Area foreground = new Area(sector); Area background = new Area(outer); Area hole = new Area(inner); foreground.subtract(hole); background.subtract(hole); g2.setPaint(this.component.getBackground()); g2.fill(background); g2.setPaint(component.getForeground()); g2.fill(foreground); g2.dispose(); }
Example 10
Source File: FXGraphics2D.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
private ArcType intToArcType(int t) { if (t == Arc2D.CHORD) { return ArcType.CHORD; } else if (t == Arc2D.OPEN) { return ArcType.OPEN; } else if (t == Arc2D.PIE) { return ArcType.ROUND; } throw new IllegalArgumentException("Unrecognised t: " + t); }
Example 11
Source File: MeterPlot.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Fills an arc on the dial between the given values. * * @param g2 the graphics device. * @param area the plot area. * @param minValue the minimum data value. * @param maxValue the maximum data value. * @param paint the background paint (<code>null</code> not permitted). * @param dial a flag that indicates whether the arc represents the whole * dial. */ protected void fillArc(Graphics2D g2, Rectangle2D area, double minValue, double maxValue, Paint paint, boolean dial) { ParamChecks.nullNotPermitted(paint, "paint"); double startAngle = valueToAngle(maxValue); double endAngle = valueToAngle(minValue); double extent = endAngle - startAngle; double x = area.getX(); double y = area.getY(); double w = area.getWidth(); double h = area.getHeight(); int joinType = Arc2D.OPEN; if (this.shape == DialShape.PIE) { joinType = Arc2D.PIE; } else if (this.shape == DialShape.CHORD) { if (dial && this.meterAngle > 180) { joinType = Arc2D.CHORD; } else { joinType = Arc2D.PIE; } } else if (this.shape == DialShape.CIRCLE) { joinType = Arc2D.PIE; if (dial) { extent = 360; } } else { throw new IllegalStateException("DialShape not recognised."); } g2.setPaint(paint); Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent, joinType); g2.fill(arc); }
Example 12
Source File: G2dRendererBase.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * * @param iArcStyle * @return */ protected static final int toG2dArcType( int iArcStyle ) { switch ( iArcStyle ) { case ArcRenderEvent.OPEN : return Arc2D.OPEN; case ArcRenderEvent.CLOSED : return Arc2D.CHORD; case ArcRenderEvent.SECTOR : return Arc2D.PIE; } return -1; }
Example 13
Source File: FXGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
private ArcType intToArcType(int t) { if (t == Arc2D.CHORD) { return ArcType.CHORD; } else if (t == Arc2D.OPEN) { return ArcType.OPEN; } else if (t == Arc2D.PIE) { return ArcType.ROUND; } throw new IllegalArgumentException("Unrecognised t: " + t); }
Example 14
Source File: PiePlot.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Draws a single data item. * * @param g2 the graphics device (<code>null</code> not permitted). * @param section the section index. * @param dataArea the data plot area. * @param state state information for one chart. * @param currentPass the current pass index. */ protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) { Number n = this.dataset.getValue(section); if (n == null) { return; } double value = n.doubleValue(); double angle1 = 0.0; double angle2 = 0.0; if (this.direction == Rotation.CLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 - value / state.getTotal() * 360.0; } else if (this.direction == Rotation.ANTICLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 + value / state.getTotal() * 360.0; } else { throw new IllegalStateException("Rotation type not recognised."); } double angle = (angle2 - angle1); if (Math.abs(angle) > getMinimumArcAngleToDraw()) { double ep = 0.0; double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = getExplodePercent(section) / mep; } Rectangle2D arcBounds = getArcBounds(state.getPieArea(), state.getExplodedPieArea(), angle1, angle, ep); Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.PIE); if (currentPass == 0) { if (this.shadowPaint != null && this.shadowGenerator == null) { Shape shadowArc = ShapeUtilities.createTranslatedShape( arc, (float) this.shadowXOffset, (float) this.shadowYOffset); g2.setPaint(this.shadowPaint); g2.fill(shadowArc); } } else if (currentPass == 1) { Comparable key = getSectionKey(section); Paint paint = lookupSectionPaint(key, state); g2.setPaint(paint); g2.fill(arc); Paint outlinePaint = lookupSectionOutlinePaint(key); Stroke outlineStroke = lookupSectionOutlineStroke(key); if (this.sectionOutlinesVisible) { g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(arc); } // update the linking line target for later // add an entity for the pie section if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip( this.dataset, key); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, key, this.pieIndex); } PieSectionEntity entity = new PieSectionEntity( arc, this.dataset, this.pieIndex, section, key, tip, url); entities.add(entity); } } } } state.setLatestAngle(angle2); }
Example 15
Source File: MeterPlot.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Fills an arc on the dial between the given values. * * @param g2 the graphics device. * @param area the plot area. * @param minValue the minimum data value. * @param maxValue the maximum data value. * @param paint the background paint (<code>null</code> not permitted). * @param dial a flag that indicates whether the arc represents the whole * dial. */ protected void fillArc(Graphics2D g2, Rectangle2D area, double minValue, double maxValue, Paint paint, boolean dial) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument"); } double startAngle = valueToAngle(maxValue); double endAngle = valueToAngle(minValue); double extent = endAngle - startAngle; double x = area.getX(); double y = area.getY(); double w = area.getWidth(); double h = area.getHeight(); int joinType = Arc2D.OPEN; if (this.shape == DialShape.PIE) { joinType = Arc2D.PIE; } else if (this.shape == DialShape.CHORD) { if (dial && this.meterAngle > 180) { joinType = Arc2D.CHORD; } else { joinType = Arc2D.PIE; } } else if (this.shape == DialShape.CIRCLE) { joinType = Arc2D.PIE; if (dial) { extent = 360; } } else { throw new IllegalStateException("DialShape not recognised."); } g2.setPaint(paint); Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent, joinType); g2.fill(arc); }
Example 16
Source File: EllipseIconTrackerUI.java From MercuryTrade with MIT License | 4 votes |
@Override public void paint(Graphics g, JComponent c) { Insets b = tracker.getInsets(); int barRectWidth = tracker.getWidth(); int barRectHeight = tracker.getHeight(); if (barRectWidth <= 0 || barRectHeight <= 0) { return; } Graphics2D g2 = (Graphics2D) g.create(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g.setColor(tracker.getBackground()); g2.fillRect(0, 0, barRectWidth, barRectHeight); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); double degree = 360 * (1f - tracker.getPercentComplete()); double sz = Math.max(barRectWidth, barRectHeight) - 2; Shape outer = new Ellipse2D.Double(1, 1, sz, sz); Shape sector = new Arc2D.Double(-sz, -sz, sz * 3, sz * 3, 90 - degree, degree, Arc2D.PIE); Area foreground = new Area(sector); Area background = new Area(outer); foreground.intersect(background); g2.setPaint(new Color(59, 59, 59)); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); try { BufferedImage read = ImageIO.read(getClass().getClassLoader().getResource("app/adr/icons/" + descriptor.getIconPath() + ".png")); Shape imageEllipse = new Ellipse2D.Double(1, 1, sz, sz); g2.setClip(imageEllipse); g2.drawImage(read, 0, 0, (int) sz, (int) sz, null); g2.setClip(null); } catch (IOException e) { e.printStackTrace(); } g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); g2.fill(foreground); this.paintOvalBorder(g, barRectWidth, barRectHeight); g2.dispose(); this.paintString(g, 0, 0, barRectWidth, barRectHeight, 0); }
Example 17
Source File: PiePlot.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Returns a shape representing the hotspot for a pie section. * * @param g2 the graphics device. * @param dataArea the area within which the data is being rendered. * @param selected is the item selected? * * @return A shape equal to the hot spot for a data item. */ public Shape createHotSpotShape(Graphics2D g2, Rectangle2D dataArea, int section, boolean selected) { Number n = this.dataset.getValue(section); if (n == null) { return null; } double value = n.doubleValue(); double angle1 = 0.0; double angle2 = 0.0; double total = DatasetUtilities.calculatePieDatasetTotal(this.dataset); double lead = 0.0; if (this.direction == Rotation.CLOCKWISE) { for (int i = 0; i < section; i++) { n = this.dataset.getValue(i); if (n != null) { value = n.doubleValue(); if (value >= 0.0) { lead = lead + value; } } } angle1 = getStartAngle() - lead / total * 360.0; angle2 = angle1 - value / total * 360.0; } else if (this.direction == Rotation.ANTICLOCKWISE) { angle1 = getStartAngle() + lead / total * 360.0; angle2 = angle1 + value / total * 360.0; } else { throw new IllegalStateException("Rotation type not recognised."); } double angle = (angle2 - angle1); if (Math.abs(angle) > getMinimumArcAngleToDraw()) { double ep = 0.0; double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = getExplodePercent(getSectionKey(section)) / mep; } Rectangle2D arcBounds = getArcBounds(dataArea, dataArea, angle1, angle, ep); Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.PIE); return arc; } return null; }
Example 18
Source File: PiePlot.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Draws a single data item. * * @param g2 the graphics device (<code>null</code> not permitted). * @param section the section index. * @param dataArea the data plot area. * @param state state information for one chart. * @param currentPass the current pass index. */ protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) { Number n = this.dataset.getValue(section); if (n == null) { return; } double value = n.doubleValue(); double angle1 = 0.0; double angle2 = 0.0; if (this.direction == Rotation.CLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 - value / state.getTotal() * 360.0; } else if (this.direction == Rotation.ANTICLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 + value / state.getTotal() * 360.0; } else { throw new IllegalStateException("Rotation type not recognised."); } double angle = (angle2 - angle1); if (Math.abs(angle) > getMinimumArcAngleToDraw()) { double ep = 0.0; double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = getExplodePercent(section) / mep; } Rectangle2D arcBounds = getArcBounds(state.getPieArea(), state.getExplodedPieArea(), angle1, angle, ep); Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.PIE); if (currentPass == 0) { if (this.shadowPaint != null && this.shadowGenerator == null) { Shape shadowArc = ShapeUtilities.createTranslatedShape( arc, (float) this.shadowXOffset, (float) this.shadowYOffset); g2.setPaint(this.shadowPaint); g2.fill(shadowArc); } } else if (currentPass == 1) { Comparable key = getSectionKey(section); Paint paint = lookupSectionPaint(key, state); g2.setPaint(paint); g2.fill(arc); Paint outlinePaint = lookupSectionOutlinePaint(key); Stroke outlineStroke = lookupSectionOutlineStroke(key); if (this.sectionOutlinesVisible) { g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(arc); } // update the linking line target for later // add an entity for the pie section if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip( this.dataset, key); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, key, this.pieIndex); } PieSectionEntity entity = new PieSectionEntity( arc, this.dataset, this.pieIndex, section, key, tip, url); entities.add(entity); } } } } state.setLatestAngle(angle2); }
Example 19
Source File: XPTrackerPlugin.java From 07kit with GNU General Public License v3.0 | 4 votes |
private void drawOverlays() { List<TrackedSkill> changedSkills = trackingMap.values().stream() .filter(x -> System.currentTimeMillis() - x.updatedTime < (orbDuration * 1000)) .collect(Collectors.toList()); if (changedSkills.size() == 0) { // No bulbs = no render isRenderable = false; return; } Graphics2D g = (Graphics2D) screenBuffer.getGraphics().create(); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g.setBackground(new Color(0, 0, 0, 0)); g.clearRect(0, 0, screenBuffer.getWidth(), screenBuffer.getHeight()); boolean inResizable = Session.get().inResizableMode(); int trackerWidth = inResizable ? 50 : 40; int viewportOffset = ((changedSkills.size()) / 2) * trackerWidth; int xInset = 0; int yInset = inResizable ? 15 : 40; for (TrackedSkill tracker : changedSkills) { int widthOffset = (client().getViewportWidth() / 2) - viewportOffset + (xInset * trackerWidth); if (!inResizable) { widthOffset = (client().getViewportWidth() - (changedSkills.size() * trackerWidth) + (xInset * trackerWidth)) - 20; } // Draw the progress chart thingy int width = trackerWidth - 10; int height = trackerWidth - 10; int radius = Math.min(width, height); int centerX = widthOffset + ((width - radius) / 2); int centerY = yInset + ((height - radius) / 2); double extent = 360d * tracker.percentileToLevel; Arc2D completedSlice = new Arc2D.Double(centerX, centerY, radius, radius, 90, -extent, Arc2D.PIE); g.setColor(Application.COLOUR_SCHEME.getLight()); g.fill(completedSlice); extent = 360 - extent; Arc2D uncompletedSlice = new Arc2D.Double(centerX, centerY, radius, radius, 90, extent, Arc2D.PIE); g.setColor(Application.COLOUR_SCHEME.getDark()); g.fill(uncompletedSlice); // Draw the icon in the middle of the chart thingy if (tracker.icon != null) { g.drawImage(tracker.icon, centerX + (width / 4), centerY + (height / 4), width / 2, height / 2, null); } xInset++; tracker.renderedBounds = new Rectangle(centerX - 15, centerY - 15, width + 15, height + 15); // give us a nice area to work with lol } if (isHovering) { Graphics2D panelGraphics = (Graphics2D) hoverPanel.getGraphics(); panelGraphics.setBackground(new Color(0, 0, 0, 0)); panelGraphics.clearRect(0, 0, hoverPanel.getWidth(), hoverPanel.getHeight()); panelGraphics.setColor(new Color(75, 67, 54, 255)); panelGraphics.fillRect(0, 0, hoverPanel.getWidth(), hoverPanel.getHeight()); panelGraphics.setColor(Color.BLACK); panelGraphics.drawRect(0, 0, hoverPanel.getWidth() - 1, hoverPanel.getHeight() - 1); panelGraphics.setColor(Application.COLOUR_SCHEME.getText()); panelGraphics.setFont(panelGraphics.getFont().deriveFont(Font.BOLD, 11f)); int idx = 1; PaintUtils.drawString(panelGraphics, trackedSkill.skill.getName(), 10, idx * 15); idx++; PaintUtils.drawString(panelGraphics, "Levels gained: " + (trackedSkill.lastLevel - trackedSkill.startLevel), 10, idx * 15); idx++; PaintUtils.drawString(panelGraphics, "XP gained: " + (trackedSkill.xpGained + (trackedSkill.lastXp - trackedSkill.startXp)), 10, idx * 15); idx++; PaintUtils.drawString(panelGraphics, "XP/hr: " + trackedSkill.xpPerHour, 10, idx * 15); idx++; Duration duration = Duration.ofMillis(trackedSkill.timeToLevel); String s = String.format("%02d:%02d:%02d%n", duration.toHours(), duration.minusHours(duration.toHours()).toMinutes(), duration.minusMinutes(duration.toMinutes()).getSeconds()); PaintUtils.drawString(panelGraphics, "Time to level: " + s, 10, idx * 15); g.drawImage(hoverPanel, mouse.getPosition().x, mouse.getPosition().y, null); } g.dispose(); isRenderable = true; }
Example 20
Source File: SLGraphics.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Fills a circular or elliptical arc covering the specified rectangle. * <p> * The resulting arc begins at <code>startAngle</code> and extends * for <code>arcAngle</code> degrees. * Angles are interpreted such that 0 degrees * is at the 3 o'clock position. * A positive value indicates a counter-clockwise rotation * while a negative value indicates a clockwise rotation. * <p> * The center of the arc is the center of the rectangle whose origin * is (<i>x</i>, <i>y</i>) and whose size is specified by the * <code>width</code> and <code>height</code> arguments. * <p> * The resulting arc covers an area * <code>width + 1</code> pixels wide * by <code>height + 1</code> pixels tall. * <p> * The angles are specified relative to the non-square extents of * the bounding rectangle such that 45 degrees always falls on the * line from the center of the ellipse to the upper right corner of * the bounding rectangle. As a result, if the bounding rectangle is * noticeably longer in one axis than the other, the angles to the * start and end of the arc segment will be skewed farther along the * longer axis of the bounds. * @param x the <i>x</i> coordinate of the * upper-left corner of the arc to be filled. * @param y the <i>y</i> coordinate of the * upper-left corner of the arc to be filled. * @param width the width of the arc to be filled. * @param height the height of the arc to be filled. * @param startAngle the beginning angle. * @param arcAngle the angular extent of the arc, * relative to the start angle. * @see java.awt.Graphics#drawArc */ public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle){ Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE); fill(arc); }