Java Code Examples for java.awt.Graphics2D#fillArc()

The following examples show how to use java.awt.Graphics2D#fillArc() . 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: SlotWidget.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintWidget() {

    if (scene.getRealZoomFactor() < ZOOM_FACTOR) {
        return;
    }

    if (bufferImage == null) {
        Graphics2D g = this.getGraphics();
        g.setColor(Color.DARK_GRAY);
        int w = this.getBounds().width;
        int h = this.getBounds().height;

        if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && scene.getRealZoomFactor() >= TEXT_ZOOM_FACTOR) {
            Font f = new Font("Arial", Font.PLAIN, 8);
            g.setFont(f.deriveFont(7.5f));
            Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g);
            g.drawString(getSlot().getShortName(), (int) (this.getBounds().width - r1.getWidth()) / 2, (int) (this.getBounds().height + r1.getHeight()) / 2);
        } else {

            if (slot instanceof OutputSlot) {
                g.fillArc(w / 4, -h / 4 - 1, w / 2, h / 2, 180, 180);
            } else {
                g.fillArc(w / 4, 3 * h / 4, w / 2, h / 2, 0, 180);
            }
        }
    }
}
 
Example 2
Source File: SlotWidget.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintWidget() {

    if (scene.getRealZoomFactor() < ZOOM_FACTOR) {
        return;
    }

    if (bufferImage == null) {
        Graphics2D g = this.getGraphics();
        g.setColor(Color.DARK_GRAY);
        int w = this.getBounds().width;
        int h = this.getBounds().height;

        if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && scene.getRealZoomFactor() >= TEXT_ZOOM_FACTOR) {
            Font f = new Font("Arial", Font.PLAIN, 8);
            g.setFont(f.deriveFont(7.5f));
            Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g);
            g.drawString(getSlot().getShortName(), (int) (this.getBounds().width - r1.getWidth()) / 2, (int) (this.getBounds().height + r1.getHeight()) / 2);
        } else {

            if (slot instanceof OutputSlot) {
                g.fillArc(w / 4, -h / 4 - 1, w / 2, h / 2, 180, 180);
            } else {
                g.fillArc(w / 4, 3 * h / 4, w / 2, h / 2, 0, 180);
            }
        }
    }
}
 
Example 3
Source File: SlotWidget.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintWidget() {

    if (scene.getRealZoomFactor() < ZOOM_FACTOR) {
        return;
    }

    if (bufferImage == null) {
        Graphics2D g = this.getGraphics();
        g.setColor(Color.DARK_GRAY);
        int w = this.getBounds().width;
        int h = this.getBounds().height;

        if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && scene.getRealZoomFactor() >= TEXT_ZOOM_FACTOR) {
            Font f = new Font("Arial", Font.PLAIN, 8);
            g.setFont(f.deriveFont(7.5f));
            Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g);
            g.drawString(getSlot().getShortName(), (int) (this.getBounds().width - r1.getWidth()) / 2, (int) (this.getBounds().height + r1.getHeight()) / 2);
        } else {

            if (slot instanceof OutputSlot) {
                g.fillArc(w / 4, -h / 4 - 1, w / 2, h / 2, 180, 180);
            } else {
                g.fillArc(w / 4, 3 * h / 4, w / 2, h / 2, 0, 180);
            }
        }
    }
}
 
Example 4
Source File: SlotWidget.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintWidget() {

    if (scene.getRealZoomFactor() < ZOOM_FACTOR) {
        return;
    }

    if (bufferImage == null) {
        Graphics2D g = this.getGraphics();
        g.setColor(Color.DARK_GRAY);
        int w = this.getBounds().width;
        int h = this.getBounds().height;

        if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && scene.getRealZoomFactor() >= TEXT_ZOOM_FACTOR) {
            Font f = new Font("Arial", Font.PLAIN, 8);
            g.setFont(f.deriveFont(7.5f));
            Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g);
            g.drawString(getSlot().getShortName(), (int) (this.getBounds().width - r1.getWidth()) / 2, (int) (this.getBounds().height + r1.getHeight()) / 2);
        } else {

            if (slot instanceof OutputSlot) {
                g.fillArc(w / 4, -h / 4 - 1, w / 2, h / 2, 180, 180);
            } else {
                g.fillArc(w / 4, 3 * h / 4, w / 2, h / 2, 0, 180);
            }
        }
    }
}
 
Example 5
Source File: SlotWidget.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintWidget() {

    if (scene.getRealZoomFactor() < ZOOM_FACTOR) {
        return;
    }

    if (bufferImage == null) {
        Graphics2D g = this.getGraphics();
        g.setColor(Color.DARK_GRAY);
        int w = this.getBounds().width;
        int h = this.getBounds().height;

        if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && scene.getRealZoomFactor() >= TEXT_ZOOM_FACTOR) {
            Font f = new Font("Arial", Font.PLAIN, 8);
            g.setFont(f.deriveFont(7.5f));
            Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g);
            g.drawString(getSlot().getShortName(), (int) (this.getBounds().width - r1.getWidth()) / 2, (int) (this.getBounds().height + r1.getHeight()) / 2);
        } else {

            if (slot instanceof OutputSlot) {
                g.fillArc(w / 4, -h / 4 - 1, w / 2, h / 2, 180, 180);
            } else {
                g.fillArc(w / 4, 3 * h / 4, w / 2, h / 2, 0, 180);
            }
        }
    }
}
 
Example 6
Source File: GeoGebraLogoBox.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static void drawCircle(Graphics2D g2, float x, float y) {
    g2.setColor(blue);
    g2.translate(x, y);
    g2.fillArc(0, 0, 8, 8, 0, 360);
    g2.setColor(Color.BLACK);
    g2.drawArc(0, 0, 8, 8, 0, 360);
    g2.translate(-x, -y);
}
 
Example 7
Source File: SlotWidget.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintWidget() {

    if (scene.getRealZoomFactor() < ZOOM_FACTOR) {
        return;
    }

    if (bufferImage == null) {
        Graphics2D g = this.getGraphics();
        g.setColor(Color.DARK_GRAY);
        int w = this.getBounds().width;
        int h = this.getBounds().height;

        if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && scene.getRealZoomFactor() >= TEXT_ZOOM_FACTOR) {
            Font f = new Font("Arial", Font.PLAIN, 8);
            g.setFont(f.deriveFont(7.5f));
            Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g);
            g.drawString(getSlot().getShortName(), (int) (this.getBounds().width - r1.getWidth()) / 2, (int) (this.getBounds().height + r1.getHeight()) / 2);
        } else {

            if (slot instanceof OutputSlot) {
                g.fillArc(w / 4, -h / 4 - 1, w / 2, h / 2, 180, 180);
            } else {
                g.fillArc(w / 4, 3 * h / 4, w / 2, h / 2, 0, 180);
            }
        }
    }
}
 
Example 8
Source File: SlotWidget.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintWidget() {

    if (scene.getRealZoomFactor() < ZOOM_FACTOR) {
        return;
    }

    if (bufferImage == null) {
        Graphics2D g = this.getGraphics();
        g.setColor(Color.DARK_GRAY);
        int w = this.getBounds().width;
        int h = this.getBounds().height;

        if (getSlot().getShortName() != null && getSlot().getShortName().length() > 0 && scene.getRealZoomFactor() >= TEXT_ZOOM_FACTOR) {
            Font f = new Font("Arial", Font.PLAIN, 8);
            g.setFont(f.deriveFont(7.5f));
            Rectangle2D r1 = g.getFontMetrics().getStringBounds(getSlot().getShortName(), g);
            g.drawString(getSlot().getShortName(), (int) (this.getBounds().width - r1.getWidth()) / 2, (int) (this.getBounds().height + r1.getHeight()) / 2);
        } else {

            if (slot instanceof OutputSlot) {
                g.fillArc(w / 4, -h / 4 - 1, w / 2, h / 2, 180, 180);
            } else {
                g.fillArc(w / 4, 3 * h / 4, w / 2, h / 2, 0, 180);
            }
        }
    }
}
 
Example 9
Source File: AbstractTtlGate.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void paintInstance(InstancePainter painter) {
	painter.drawPorts();
	Graphics2D g = (Graphics2D) painter.getGraphics();
	painter.drawLabel();
	if (!painter.getAttributeValue(TTL.DRAW_INTERNAL_STRUCTURE)) {
		Direction dir = painter.getAttributeValue(StdAttr.FACING);
		Bounds bds = painter.getBounds();
		int x = bds.getX();
		int y = bds.getY();
		int xp = x, yp = y;
		int width = bds.getWidth();
		int height = bds.getHeight();
		for (byte i = 0; i < this.pinnumber; i++) {
			if (i == this.pinnumber / 2) {
				xp = x;
				yp = y;
				if (dir == Direction.WEST || dir == Direction.EAST) {
					g.setColor(Color.DARK_GRAY.darker());
					g.fillRoundRect(xp, yp + pinheight, width, height - pinheight * 2 + 2, 10, 10);
					g.setColor(Color.DARK_GRAY);
					g.fillRoundRect(xp, yp + pinheight, width, height - pinheight * 2 - 2, 10, 10);
					g.setColor(Color.BLACK);
					g.drawRoundRect(xp, yp + pinheight, width, height - pinheight * 2 - 2, 10, 10);
					g.drawRoundRect(xp, yp + pinheight, width, height - pinheight * 2 + 2, 10, 10);
				} else {
					g.setColor(Color.DARK_GRAY.darker());
					g.fillRoundRect(xp + pinheight, yp, width - pinheight * 2, height, 10, 10);
					g.setColor(Color.DARK_GRAY);
					g.fillRoundRect(xp + pinheight, yp, width - pinheight * 2, height - 4, 10, 10);
					g.setColor(Color.BLACK);
					g.drawRoundRect(xp + pinheight, yp, width - pinheight * 2, height - 4, 10, 10);
					g.drawRoundRect(xp + pinheight, yp, width - pinheight * 2, height, 10, 10);
				}
				if (dir == Direction.SOUTH)
					g.fillArc(xp + width / 2 - 7, yp - 7, 14, 14, 180, 180);
				else if (dir == Direction.WEST)
					g.fillArc(xp + width - 7, yp + height / 2 - 7, 14, 14, 90, 180);
				else if (dir == Direction.NORTH)
					g.fillArc(xp + width / 2 - 7, yp + height - 11, 14, 14, 0, 180);
				else // east
					g.fillArc(xp - 7, yp + height / 2 - 7, 14, 14, 270, 180);
			}
			if (i < this.pinnumber / 2) {
				if (dir == Direction.WEST || dir == Direction.EAST)
					xp = i * 20 + (10 - pinwidth / 2) + x;
				else
					yp = i * 20 + (10 - pinwidth / 2) + y;
			} else {
				if (dir == Direction.WEST || dir == Direction.EAST) {
					xp = (i - this.pinnumber / 2) * 20 + (10 - pinwidth / 2) + x;
					yp = height + y - pinheight;
				} else {
					yp = (i - this.pinnumber / 2) * 20 + (10 - pinwidth / 2) + y;
					xp = width + x - pinheight;
				}
			}
			if (dir == Direction.WEST || dir == Direction.EAST) {
				g.setColor(Color.LIGHT_GRAY);
				g.fillRect(xp, yp, pinwidth, pinheight);
				g.setColor(Color.BLACK);
				g.drawRect(xp, yp, pinwidth, pinheight);
			} else {
				g.setColor(Color.LIGHT_GRAY);
				g.fillRect(xp, yp, pinheight, pinwidth);
				g.setColor(Color.BLACK);
				g.drawRect(xp, yp, pinheight, pinwidth);
			}
		}

		g.setColor(Color.LIGHT_GRAY.brighter());
		g.rotate(Math.toRadians(-dir.toDegrees()), x + width / 2, y + height / 2);
		g.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 14));
		GraphicsUtil.drawCenteredText(g, this.name, x + width / 2, y + height / 2 - 4);
		g.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 7));
		if (dir == Direction.WEST || dir == Direction.EAST) {
			xp = x;
			yp = y;
		} else {
			xp = x + (width - height) / 2;
			yp = y + (height - width) / 2;
		}
		if (dir == Direction.SOUTH) {
			GraphicsUtil.drawCenteredText(g, "Vcc", xp + 10, yp + pinheight + 4);
			GraphicsUtil.drawCenteredText(g, "GND", xp + height - 14, yp + width - pinheight - 8);
		} else if (dir == Direction.WEST) {
			GraphicsUtil.drawCenteredText(g, "Vcc", xp + 10, yp + pinheight + 6);
			GraphicsUtil.drawCenteredText(g, "GND", xp + width - 10, yp + height - pinheight - 8);
		} else if (dir == Direction.NORTH) {
			GraphicsUtil.drawCenteredText(g, "Vcc", xp + 14, yp + pinheight + 4);
			GraphicsUtil.drawCenteredText(g, "GND", xp + height - 10, yp + width - pinheight - 8);
		} else { // east
			GraphicsUtil.drawCenteredText(g, "Vcc", xp + 10, yp + pinheight + 4);
			GraphicsUtil.drawCenteredText(g, "GND", xp + width - 10, yp + height - pinheight - 10);
		}
	} else
		paintInternalBase(painter);
}
 
Example 10
Source File: RoundBorder.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        Graphics2D g2 = (Graphics2D)g;

        g2.setPaint(fillColor);
        // NOTE: fillRoundRect seems to have poor performance on Linux
//            g2.fillRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
//                             width - borderStrokeWidth, height - borderStrokeWidth,
//                             arcRadius * 2, arcRadius * 2);

        int arcRadius2 = arcRadius * 2;
        int arcRadius2p1 = arcRadius2 + 1;

        g2.fillArc(x, y, arcRadius2, arcRadius2, 90, 90);
        g2.fillArc(x + width - arcRadius2p1, y, arcRadius2, arcRadius2, 0, 90);
        g2.fillArc(x, y + height - arcRadius2p1, arcRadius2, arcRadius2, 180, 90);
        g2.fillArc(x + width - arcRadius2p1, y + height - arcRadius2p1, arcRadius2, arcRadius2, 270, 90);

        g2.fillRect(x + arcRadius, y, width - arcRadius2p1, height);
        g2.fillRect(x, y + arcRadius, arcRadius, height - arcRadius2p1);
        g2.fillRect(x + width - arcRadius - 1, y + arcRadius, arcRadius, height - arcRadius2p1);

        Object aa = null;
        Object sc = null;
        if (!forceSpeed) {
            aa = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
            sc = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        }

        g2.setStroke(borderStroke);
        g2.setPaint(lineColor);
        g2.drawRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
                         width - borderStrokeWidth, height - borderStrokeWidth,
                         arcRadius * 2, arcRadius * 2);

        if (!forceSpeed) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa);
            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, sc);
        }
    }
 
Example 11
Source File: RoundBorder.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        Graphics2D g2 = (Graphics2D)g;

        g2.setPaint(fillColor);
        // NOTE: fillRoundRect seems to have poor performance on Linux
//            g2.fillRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
//                             width - borderStrokeWidth, height - borderStrokeWidth,
//                             arcRadius * 2, arcRadius * 2);

        int arcRadius2 = arcRadius * 2;
        int arcRadius2p1 = arcRadius2 + 1;

        g2.fillArc(x, y, arcRadius2, arcRadius2, 90, 90);
        g2.fillArc(x + width - arcRadius2p1, y, arcRadius2, arcRadius2, 0, 90);
        g2.fillArc(x, y + height - arcRadius2p1, arcRadius2, arcRadius2, 180, 90);
        g2.fillArc(x + width - arcRadius2p1, y + height - arcRadius2p1, arcRadius2, arcRadius2, 270, 90);

        g2.fillRect(x + arcRadius, y, width - arcRadius2p1, height);
        g2.fillRect(x, y + arcRadius, arcRadius, height - arcRadius2p1);
        g2.fillRect(x + width - arcRadius - 1, y + arcRadius, arcRadius, height - arcRadius2p1);

        Object aa = null;
        Object sc = null;
        if (!forceSpeed) {
            aa = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
            sc = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        }

        g2.setStroke(borderStroke);
        g2.setPaint(lineColor);
        g2.drawRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
                         width - borderStrokeWidth, height - borderStrokeWidth,
                         arcRadius * 2, arcRadius * 2);

        if (!forceSpeed) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa);
            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, sc);
        }
    }
 
Example 12
Source File: JSoftGraph.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void paintNodeOutArc(Graphics2D g, Node node) {
  double outMin    = node.getOutMin();
  double outMax    = node.getOutMax();
  double outSize   = outMax - outMin;

  int nTotal    = node.getOutLinks().size();

  if(outSize < nTotal) {

    Composite oldComp = g.getComposite();

    Composite alpha = outArcActive ? alphaHalf : alphaSome;
    g.setComposite(alpha);

    double aStart = 180.0 * outMin / nTotal;
    double aSize  = Math.max(2, 180.0 * outSize / nTotal);

    int rx = arcRadius;
    int ry = (int)(rx * .9);


    Util.setAntialias(g, true);

    // background arc
    g.setColor(arcOutCol1);
    g.fillArc((int)(0 - rx),
              (int)(0 - ry),
              rx * 2, ry * 2,
              0, 180);

    // g.setComposite(alpha);
    // size arc
    g.setColor(arcOutCol2);
    g.fillArc((int)(0 - rx),
              (int)(0 - ry),
              rx * 2, ry * 2,
              (int)aStart, (int)aSize);
    g.setComposite(oldComp);
    Util.setAntialias(g, false);
  }
}
 
Example 13
Source File: JSoftGraph.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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: AnimatedVillageInfoRenderer.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
private void renderTroopInfo(Village pCurrentVillage, Graphics2D g2d) {
    pRise = mVillage != null && mVillage.equals(pCurrentVillage);

    VillageTroopsHolder holder = null;
    int centerX = (int) Math.floor(mCurrentLocation.getCenterX());
    int centerY = (int) Math.floor(mCurrentLocation.getCenterY());
    int halfDiameter = (int) Math.floor(iDiameter / 2.0);

    if (GlobalOptions.getProperties().getBoolean("include.support")) {
        holder = TroopsManager.getSingleton().getTroopsForVillage(mVillage);
    } else {
        holder = TroopsManager.getSingleton().getTroopsForVillage(mVillage, TroopsManager.TROOP_TYPE.OWN);
    }

    if (mVillage != null && holder != null) {
        double offValue = holder.getTroops().getOffValue();
        double defArchValue = holder.getTroops().getDefArcherValue();
        double defCavValue = holder.getTroops().getDefCavalryValue();
        double defValue = holder.getTroops().getDefValue();
        double fightValueIn = offValue + defValue + defArchValue + defCavValue;
        Color before = g2d.getColor();
        Composite cb = g2d.getComposite();
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f));
        if (fightValueIn == 0) {
            g2d.setColor(Constants.DS_BACK_LIGHT);
            g2d.fillOval(centerX - halfDiameter, centerY - halfDiameter, iDiameter, iDiameter);
        } else {
            double percOff = offValue / fightValueIn;
            double percDef = defValue / fightValueIn;
            double percDefCav = defCavValue / fightValueIn;
            double percDefArch = defArchValue / fightValueIn;
            int degOff = 0;
            int degDef = 0;
            int degDefCav = 0;
            if (percOff > 0) {
                //draw off arc
                degOff = (int) Math.rint(360 * percOff);
                g2d.setColor(Color.RED);
                g2d.fillArc(centerX - halfDiameter, centerY - halfDiameter, iDiameter, iDiameter, 0, degOff);
            }
            if (percDef > 0) {
                //draw def arc
                degDef = (int) Math.rint(360 * percDef);
                g2d.setColor(Color.GREEN);
                g2d.fillArc(centerX - halfDiameter, centerY - halfDiameter, iDiameter, iDiameter, degOff, degDef);
            }
            if (percDefCav > 0) {
                //draw def cav arc
                degDefCav = (int) Math.rint(360 * percDefCav);
                g2d.setColor(Color.YELLOW);
                g2d.fillArc(centerX - halfDiameter, centerY - halfDiameter, iDiameter, iDiameter, degOff + degDef, degDefCav);
            }
            if (percDefArch > 0) {
                //draw def cav arc
                g2d.setColor(Color.ORANGE.darker());
                g2d.fillArc(centerX - halfDiameter, centerY - halfDiameter, iDiameter, iDiameter, degOff + degDef + degDefCav, 360 - (degOff + degDef + degDefCav));
            }

            renderTroopInfoLegend(centerX, centerY, offValue, defValue, defCavValue, defArchValue, g2d);

        }
        g2d.setColor(before);
        g2d.setComposite(cb);
    } else {
        g2d.setColor(Constants.DS_BACK_LIGHT);
        g2d.fillOval(centerX - halfDiameter, centerY - halfDiameter, iDiameter, iDiameter);
        if (iDiameter == 60) {
            g2d.setColor(Color.BLACK);
            Rectangle2D bounds = g2d.getFontMetrics().getStringBounds("Keine", g2d);
            g2d.drawString("Keine", centerX - Math.round(bounds.getWidth() / 2), Math.round(centerY));
            bounds = g2d.getFontMetrics().getStringBounds("Info", g2d);
            g2d.drawString("Info", centerX - Math.round(bounds.getWidth() / 2), Math.round(centerY + bounds.getHeight()));
        }
    }
}
 
Example 15
Source File: TroopDensityLayerRenderer.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
public void update(int row, int col, int pFieldWidth, int pFieldHeight, int pDx, int pDy, Graphics2D g2d) {
    Village villageAtMousePos = MapPanel.getSingleton().getVillageAtMousePos();
    pRise = villageAtMousePos != null && villageAtMousePos.equals(v);
    if (pRise) {
        if (iDiameter + 10 < 61) {
            iDiameter += 10;
        }
    } else {
        iDiameter -= 10;
        if (iDiameter <= 0) {
            bFinished = true;
            iDiameter = 0;
        }
    }
    VillageTroopsHolder holder = null;
    if (v != null && (holder = TroopsManager.getSingleton().getTroopsForVillage(v)) != null) {
        double offValue = holder.getTroops().getOffValue();
        double defArchValue = holder.getTroops().getDefArcherValue();
        double defCavValue = holder.getTroops().getDefCavalryValue();
        double defValue = holder.getTroops().getDefValue();

        double fightValueIn = offValue + defValue + defArchValue + defCavValue;
        int centerX = (int) Math.floor((double) col * pFieldWidth + pFieldWidth / 2.0 - 16 + pDx);
        int centerY = (int) Math.floor((double) row * pFieldHeight + pFieldHeight / 2.0 - 16 + pDy);
        int halfDiameter = (int) Math.floor(iDiameter / 2.0);
        Color before = g2d.getColor();
        Composite cb = g2d.getComposite();
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f));
        if (fightValueIn == 0) {
            g2d.setColor(Constants.DS_BACK_LIGHT);
            g2d.fillOval(centerX - halfDiameter + 16, centerY - halfDiameter + 16, iDiameter, iDiameter);
        } else {
            double percOff = offValue / fightValueIn;
            double percDef = defValue / fightValueIn;
            double percDefCav = defCavValue / fightValueIn;
            double percDefArch = defArchValue / fightValueIn;
            int degOff = 0;
            int degDef = 0;
            int degDefCav = 0;
            if (percOff > 0) {
                //draw off arc
                degOff = (int) Math.rint(360 * percOff);
                g2d.setColor(Color.RED);
                g2d.fillArc(centerX - halfDiameter + 16, centerY - halfDiameter + 16, iDiameter, iDiameter, 0, degOff);
            }
            if (percDef > 0) {
                //draw def arc
                degDef = (int) Math.rint(360 * percDef);
                g2d.setColor(Color.GREEN);
                g2d.fillArc(centerX - halfDiameter + 16, centerY - halfDiameter + 16, iDiameter, iDiameter, degOff, degDef);
            }
            if (percDefCav > 0) {
                //draw def cav arc
                degDefCav = (int) Math.rint(360 * percDefCav);
                g2d.setColor(Color.YELLOW);
                g2d.fillArc(centerX - halfDiameter + 16, centerY - halfDiameter + 16, iDiameter, iDiameter, degOff + degDef, degDefCav);
            }
            if (percDefArch > 0) {
                //draw def cav arc
                g2d.setColor(Color.ORANGE.darker());
                g2d.fillArc(centerX - halfDiameter + 16, centerY - halfDiameter + 16, iDiameter, iDiameter, degOff + degDef + degDefCav, 360 - (degOff + degDef + degDefCav));
            }

            drawLegend(centerX + 16, centerY + 16, offValue, defValue, defCavValue, defArchValue, g2d);

        }
        g2d.setColor(before);
        g2d.setComposite(cb);
    } else {
        bFinished = true;
    }
}
 
Example 16
Source File: RingChart.java    From android-classyshark with Apache License 2.0 4 votes vote down vote up
private void renderNode(int width, int height, int radius, int startAngle, int endAngle,
                        ClassNode rootNode, Graphics2D g2d, int depth, Color[] pallete) {
    if (rootNode.getChildNodes().isEmpty()) {
        return;
    }

    int nodeStartAngle;
    int nodeEndAngle = startAngle;
    int angleSize = endAngle - startAngle;
    int r = (radius / maxDepth) * depth;
    int x = (width - r) / 2;
    int y = (height - r) / 2;
    int currentNode = 0;
    int currentColor = 0;

    List<ClassNode> nodes = new ArrayList<>(rootNode.getChildNodes().values());
    Collections.sort(nodes, new Comparator<ClassNode>() {
        @Override
        public int compare(ClassNode o1, ClassNode o2) {
            return Integer.compare(o2.getMethodCount(), o1.getMethodCount());
        }
    });

    while (nodeEndAngle < endAngle) {
        ClassNode node = nodes.get(currentNode);
        nodeStartAngle = nodeEndAngle;
        String title = node.getKey();
        Color color = pallete[currentColor];

        nodeEndAngle = (int) ((double) node.getMethodCount()
                / rootNode.getMethodCount() * angleSize + nodeEndAngle);

        if (currentNode == nodes.size() - 1) {
            nodeEndAngle = endAngle;
        } else if (currentColor == pallete.length - 1 || 360 - nodeEndAngle < 5) {
            currentColor = pallete.length - 1;
            nodeEndAngle = endAngle;
            title = "Others";
            color = OTHERS_COLOR;
        }

        if (selectedNode != null && node == selectedNode) {
            color = getHighlightColor(color);
        }

        if (color != OTHERS_COLOR) {
            colorClassNodeMap.put(color.getRGB(), node);
        }

        if (depth < maxDepth && currentColor != pallete.length - 1) {
            Color[] newpallete = L2_PALLETES[currentColor];
            renderNode(
                    width, height, radius, nodeStartAngle, nodeEndAngle, node, g2d, depth + 1, newpallete);
        }

        g2d.setColor(color);

        g2d.fillArc(x, y, r, r, nodeStartAngle, nodeEndAngle - nodeStartAngle);
        g2d.setColor(Color.BLACK);
        g2d.drawArc(x, y, r, r, nodeStartAngle, nodeEndAngle - nodeStartAngle);

        //Render Lines between angles
        AffineTransform saved = g2d.getTransform();
        int cx = width / 2;
        int cy = height / 2;
        g2d.translate(cx, cy);

        double rads = Math.toRadians(nodeEndAngle);
        int py = (int)Math.round(Math.sin(rads) * (r / 2)) * -1;
        int px = (int)Math.round(Math.cos(rads) * (r / 2));

        g2d.drawLine(0, 0, px, py);

        //Render text
        int r2 = (radius / maxDepth) * (depth - 1);
        r2 = r + (r2 - r)/2;
        rads = Math.toRadians(nodeStartAngle + (nodeEndAngle - nodeStartAngle) / 2);
        py = (int)Math.round(Math.sin(rads) * (r2 / 2))* -1;
        px = (int)Math.round(Math.cos(rads) * (r2 / 2));
        g2d.drawString(title, px, py);

        g2d.setTransform(saved);

        currentNode++;
        currentColor++;
    }
}
 
Example 17
Source File: ImageDrawArc.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
	cfImageData im	= getImage( _session, argStruct );
	
	int x	= getNamedIntParam(argStruct, "x", -1 );
	int y	= getNamedIntParam(argStruct, "y", -1 );
	int w	= getNamedIntParam(argStruct, "width", -1 );
	int h	= getNamedIntParam(argStruct, "height", -1 );

	int sa	= getNamedIntParam(argStruct, "startangle", Integer.MIN_VALUE );
	int ar	= getNamedIntParam(argStruct, "arcangle", Integer.MIN_VALUE );
	
	boolean bFilled	= getNamedBooleanParam(argStruct, "filled", false );
	
	//Check boundaries
	BufferedImage	bim	= im.getImage();
	
	if ( x < 0 || x > bim.getWidth() )
		throwException(_session, "x (" + x + ") is outside the image" );
	
	if ( y < 0 || y > bim.getHeight() )
		throwException(_session, "y (" + y + ") is outside the image" );

	if ( (x+w) < 0 || (x+w) > bim.getWidth() )
		throwException(_session, "w (" + w + ") is outside the image" );

	if ( (y+w) < 0 || (y+w) > bim.getHeight() )
		throwException(_session, "w (" + w + ") is outside the image" );

	if ( sa == Integer.MIN_VALUE )
		throwException(_session, "startangle was not specified" );
	
	if ( ar == Integer.MIN_VALUE )
		throwException(_session, "arcangle  was not specified" );


	// Perform the operation
	Graphics2D g2 = im.createGraphics();
	
	if ( bFilled ){
		g2.fillArc( x, y, w, h, sa, ar );	
	}else{
		g2.drawArc(x, y, w, h, sa, ar );	
	}
	
	im.dispose(g2);
	return cfBooleanData.TRUE;
}
 
Example 18
Source File: FillArcEvent.java    From whyline with MIT License 2 votes vote down vote up
public void paint(Graphics2D g) {

	g.fillArc(getX(), getY(), getWidth(), getHeight(), getStartAngle(), getArcAngle());		

}