public void paint(Graphics g){ //Graphics is a crayon box; Graphics2d is like an art kit BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D)image.getGraphics(); //Graphics2D g2 = (Graphics2D)g; g2.setColor(Color.white); g2.fillRect(0,0,width,height); g2.setColor(Color.pink); g2.drawOval(50, 50, width-100, height-100); g2.drawOval(175, 175, width-490, height-490); g2.drawOval(375, 175, width-490, height-490); g2.drawLine(0,10,height,0); g2.drawArc(175, 250, 250, 130, 200, 90); Hero hero2 = new Hero("Dorami", "/images/heroes/Dorami.jpg",100,100); if(Math.abs(hero1.getX()-hero2.getX()) + Math.abs(hero1.getY()-hero2.getY()) <20 ){ itemPickedUp=true; } if(!itemPickedUp){g2.drawImage(hero2.getImage(), hero2.getX(), hero2.getY(), null);} g2.drawImage(hero1.getImage(), hero1.getX(), hero1.getY(), null); //g2.fillOval(50,100,200,100); //g2.drawArc(50, 300, 200, 100,0,90); /* int c =0; int margin =2; int squareD =20; for(int x=0; x<width; x+= squareD +margin){ for(int y=0; y<height; y+= squareD+margin){ if(c<255) c++; else c=0; Color local = new Color((int) Math.floor(Math.random() * 256),(int) Math.floor(Math.random() * 256),c); g2.setColor(local); g2.fillRect(x,y,squareD,squareD); } }*/ g.drawImage(image, 0, 0, null); }
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); }
public void paintComponent(Graphics g) { setSize(xSize, ySize); super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if (PedigreeExplorer.thickLines) { // turn this off so they don't look blurry when exported g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } else { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } g2.setColor(Color.black); if (PedigreeExplorer.thickLines) { g2.setStroke(new BasicStroke(2)); } else { g2.setStroke(new BasicStroke(1)); } if (sex == male) { if (PedigreeExplorer.thickLines) { g2.drawRect(1, 1, symbolSize - 2, symbolSize - 2); } else { g2.drawRect(0, 0, symbolSize, symbolSize); } if (affection == affected) { g2.fillRect(0, 0, symbolSize, symbolSize); } } if (sex == female) { if (PedigreeExplorer.thickLines) { g2.drawArc(1, 1, symbolSize - 2, symbolSize - 2, 0, 360); } else { g2.drawArc(0, 0, symbolSize, symbolSize, 0, 360); } if (affection == affected) { g2.fillArc(0, 0, symbolSize, symbolSize, 0, 360); } } }
/** * draw * * @param g graphics * @param x x * @param y y * @param width width * @param height height * @param speed wind speed * @param dirDegrees wind dir */ public void draw( Graphics2D g, int x, int y, int width, int height, double speed, double dirDegrees) { this.windSpeed = speed; this.x0 = x0; this.y0 = y0; double theta = dirDegrees * DEG_TO_RAD; sint = Math.sin(theta); cost = Math.cos(theta); x0 = x + width / 2; y0 = y + height / 2; // calc how long the windBarb should be int len = 0; while (speed >= 47.5) { len += 6; speed -= 50; } while (speed >= 7.5) { len += 3; speed -= 10; } if (speed >= 2.5) { len += 3; } lenBarb = Math.max(len, width); // special case : calm if (windSpeed < 0.5) { int radius = 10; g.drawArc(x0 - radius / 2, y0 - radius / 2, radius, radius, 0, 360); return; } else { drawRotatedLine(g, 0, 0, 0, -lenBarb); } // draw the flags and lines int start = 0; speed = windSpeed; while (speed >= 47.5) { start = draw50knotFlag(g, start); speed -= 50; } while (speed >= 7.5) { start = draw10knotLine(g, start); speed -= 10; } if (speed >= 2.5) { if ((windSpeed >= 2.5) && (windSpeed < 7.5)) { // special case start = 3; } drawRotatedBarbLine(g, 0, -lenBarb + start, .2 * lenBarb, -lenBarb + start - 1.5); } }
public static void drawStandardLoop(Graphics2D g2, int x, int y) { g2.setStroke(BPMNUtils.defaultStroke); g2.drawArc( x - MARKER_ICON_SIZE / 2, y - MARKER_ICON_SIZE / 2, MARKER_ICON_SIZE, MARKER_ICON_SIZE, 315, 270); g2.drawLine(x, y, x, y + MARKER_ICON_SIZE / 2); g2.drawLine(x, y + MARKER_ICON_SIZE / 2, x + MARKER_ICON_SIZE / 2, y + MARKER_ICON_SIZE / 2); }
private void drawWaveAndMae(GBulletFiredEvent wave, Graphics2D g) { double maeLength = 300; double radius = wave.getVelocity() * (getTime() - wave.getFiringTime()); g.drawArc( (int) (wave.getFiringPosition().getX() - radius), (int) (wave.getFiringPosition().getY() - radius), (int) radius * 2, (int) radius * 2, 0, 360); g.drawRect( (int) wave.getFiringPosition().getX() - 5, (int) wave.getFiringPosition().getY() - 5, 10, 10); double absBearing = org.pattern.utils.Utils.absBearing(wave.getFiringPosition(), wave.getTargetPosition()); drawPoint(wave.getFiringPosition(), 4, g); drawPoint(wave.getTargetPosition(), 4, g); // //draw MAE g.drawLine( (int) wave.getFiringPosition().getX(), (int) wave.getFiringPosition().getY(), (int) (wave.getTargetPosition().getX()), (int) (wave.getTargetPosition().getY())); g.drawLine( (int) wave.getFiringPosition().getX(), (int) wave.getFiringPosition().getY(), (int) (wave.getFiringPosition().getX() + Math.sin(Math.toRadians(absBearing + wave.getMaxMAE())) * maeLength), (int) (wave.getFiringPosition().getY() + Math.cos(Math.toRadians(absBearing + wave.getMaxMAE())) * maeLength)); g.drawLine( (int) wave.getFiringPosition().getX(), (int) wave.getFiringPosition().getY(), (int) (wave.getFiringPosition().getX() + Math.sin(Math.toRadians(absBearing + wave.getMinMAE())) * maeLength), (int) (wave.getFiringPosition().getY() + Math.cos(Math.toRadians(absBearing + wave.getMinMAE())) * maeLength)); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; // g2d.setPaint(new GradientPaint(x, y, new Color(30, 145, 140), x, y + s, new Color(35, 185, // 185))); g2d.setStroke(new BasicStroke(2)); if (mode == 0) { end = angle + step; g2d.setColor(new Color(15, 125, 125, 100)); g2d.drawArc(x, y, s, s, 96 - (int) angle, 347 - (int) (step)); g2d.setColor(new Color(35, 185, 185)); g2d.drawArc(x, y, s, s, 90 - (int) (angle), (int) (angle - end)); } else if (mode == 1) { g2d.setColor(new Color(15, 125, 125, 100)); g2d.drawArc(x, y, s, s, 96 - (int) angle, 347 - (int) (step + end)); g2d.setColor(new Color(35, 185, 185)); g2d.drawArc(x, y, s, s, 90 - (int) (angle), (int) (angle - step) - 1); g2d.setColor(new Color(35, 185, 185, 160)); g2d.drawArc(x, y, s, s, 82 - (int) (angle + step), (int) (angle - end) + 8); } else { float empty = 0; for (int i = 0; i < colors.length; i++) { if (dist.length > i) { empty += dist[i]; g2d.setColor(colors[i]); g2d.setStroke(new BasicStroke(2)); g2d.drawArc(x, y, s, s, 90 - (int) empty, (int) dist[i] - 2); g2d.setStroke(new BasicStroke(1)); g2d.drawArc(x + 4, y + 4, s - 8, s - 8, 90 - (int) empty, (int) dist[i] - 2); } } g2d.setColor(new Color(15, 125, 125, 100)); g2d.setStroke(new BasicStroke(2)); g2d.drawArc(x, y, s, s, 91, (int) (357 - empty)); g2d.setStroke(new BasicStroke(1)); g2d.drawArc(x + 4, y + 4, s - 8, s - 8, 91, (int) (357 - empty)); } }
public static void drawRound3DBorder(Graphics g, Color c1, Color c2, int x, int y, int w, int h) { Graphics2D g2D = (Graphics2D) g; int x2 = x + w; int y2 = y + h; int d = h; int r = h / 2; Color cm = ColorHelper.median(c1, c2); Color c1m = ColorHelper.median(c1, cm); Color c2m = ColorHelper.median(c2, cm); Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // oben g2D.setColor(c1); g2D.drawLine(x + r, y, x2 - r, y); // rechts g2D.drawLine(x, y + r, x, y2 - r); // unten g2D.setColor(c2); g2D.drawLine(x + r, y2, x2 - r, y2); // links g2D.drawLine(x2, y + r, x2, y2 - r); // links g2D.setColor(c1); g2D.drawArc(x, y, d, d, 90, 45); g2D.setColor(c1m); g2D.drawArc(x, y, d, d, 135, 45); g2D.setColor(cm); g2D.drawArc(x, y, d, d, 180, 45); g2D.setColor(c2m); g2D.drawArc(x, y, d, d, 225, 45); // rechts g2D.setColor(c1m); g2D.drawArc(x2 - d, y, d, d, 45, 45); g2D.setColor(cm); g2D.drawArc(x2 - d, y, d, d, 0, 45); g2D.setColor(c2m); g2D.drawArc(x2 - d, y, d, d, -45, 45); g2D.setColor(c2); g2D.drawArc(x2 - d, y, d, d, -90, 45); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); }
public void paintOnTreePanel(TreeViewPanel panel, Graphics2D canvas) { TreeView view = panel.t; for (TreeViewNode n : view.treeNodes.values()) { int childID = n.id; if (forwardLinks.getData(childID) != null) { int forwardID = forwardLinks.getData(childID); TreeViewNode forward = view.treeNodes.get(forwardID); if (forward != null) { if (n.getEdgeDir().equals("sel")) { canvas.setColor(nodeColorings.get(childID)); } else { canvas.setColor(Color.LIGHT_GRAY); } if (forward.y > n.y) { TreeViewNode temp = forward; forward = n; n = temp; } int c = 80; int a = Math.abs(n.x - forward.x) + c; int x = Math.abs(n.x - forward.x); int y = n.y - forward.y; int b = y / 2; if (x != 0) { b = (int) (((a - Math.sqrt(a * a - x * x)) * y * a) / (x * x)); } int arcAngle = 180; if (x != 0) { arcAngle = (int) Math.round( (Math.atan((double) (y - b) / ((x / (x + 50.0)) * b)) * 180) / Math.PI); if (forward.x - n.x < 0) { arcAngle = 270 - arcAngle; } else { arcAngle += 90; } } canvas.drawArc(forward.x - a, forward.y, 2 * a, 2 * b, 90 + arcAngle, 360 - arcAngle); } } } }
public void draw(Graphics2D g2, float x, float y) { AffineTransform oldAt = g2.getTransform(); Color oldC = g2.getColor(); Stroke oldS = g2.getStroke(); g2.translate(x + 0.25f * height / 2.15f, y - 1.75f / 2.15f * height); g2.setColor(gray); g2.setStroke(st); g2.scale(0.05f * height / 2.15f, 0.05f * height / 2.15f); g2.rotate(-26 * Math.PI / 180, 20.5, 17.5); g2.drawArc(0, 0, 43, 32, 0, 360); g2.rotate(26 * Math.PI / 180, 20.5, 17.5); g2.setStroke(oldS); drawCircle(g2, 16f, -5f); drawCircle(g2, -1f, 7f); drawCircle(g2, 5f, 28f); drawCircle(g2, 27f, 24f); drawCircle(g2, 36f, 3f); g2.setStroke(oldS); g2.setTransform(oldAt); g2.setColor(oldC); }
public void paintIcon(Component c, Graphics graphics, int x, int y) { Font font = UIManager.getFont("TextField.font"); Graphics2D g = (Graphics2D) graphics.create(x, y, getIconWidth(), getIconHeight()); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setFont(font.deriveFont(Font.BOLD, getIconWidth() * 3 / 4)); g.setColor(Color.green.darker()); final int SW = Math.max(getIconWidth() / 10, 4); g.setStroke(new BasicStroke(SW)); g.drawArc(SW / 2, SW / 2, getIconWidth() - SW - 1, getIconHeight() - SW - 1, 0, 360); Rectangle2D bounds = font.getStringBounds("i", g.getFontRenderContext()); g.drawString( "i", Math.round((getIconWidth() - bounds.getWidth()) / 2 - getIconWidth() / 12), SW / 2 + Math.round( (getIconHeight() - bounds.getHeight()) / 2 - bounds.getY() + getIconHeight() / 8)); g.dispose(); }
private void doDrawing(Graphics g) throws InterruptedException { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.blue); Dimension size = getSize(); Insets insets = getInsets(); int w = size.width - insets.left - insets.right; int h = size.height - insets.top - insets.bottom; Random generator = new Random(); double[][] center = new double[NCLUSTERS][DIMENSION]; String inFilenamec = "/home/cloudera/workspace/training/datasource/center"; try { BufferedReader bwc = new BufferedReader(new FileReader(inFilenamec)); String line; for (int i = 0; i < NCLUSTERS; i++) { line = bwc.readLine(); String[] num = line.split(" "); center[i][0] = Double.parseDouble(num[0]); center[i][1] = Double.parseDouble(num[1]); } bwc.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String inFilename = "/home/cloudera/workspace/training/datasource/kmean"; try { BufferedReader bw = new BufferedReader(new FileReader(inFilename)); String line; for (int K = 0; K < 100; K++) { for (int i = 0; i < NCLUSTERS; i++) { line = bw.readLine(); String[] num = line.split(" "); double dx = Double.parseDouble(num[0]); double dy = Double.parseDouble(num[1]); g2d.setColor(Color.GREEN); int sP = 3; int x = (int) Math.abs(Math.round(dx * (w - 7))) + 3; int y = (int) Math.abs(Math.round(dy * (h - 7))) + 3; g2d.drawLine(x - sP, y, x + sP, y); g2d.drawLine(x, y - sP, x, y + sP); } } bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Done"); g2d.setColor(Color.RED); for (int i = 0; i < NCLUSTERS; i++) { double dx = center[i][0]; double dy = center[i][1]; int x = (int) Math.abs(Math.round(dx * w)) % w; int y = (int) Math.abs(Math.round(dy * h)) % h; g2d.drawArc(x - 5, y - 5, 11, 11, 0, 360); } double[][] precenter = new double[NCLUSTERS][DIMENSION]; for (int i = 0; i < NCLUSTERS; i++) { for (int j = 0; j < DIMENSION; j++) { precenter[i][j] = ((double) (i + 1)) / (NCLUSTERS + 1); ; } double dx = precenter[i][0]; double dy = precenter[i][1]; int x = (int) Math.abs(Math.round(dx * w)) % w; int y = (int) Math.abs(Math.round(dy * h)) % h; g2d.drawRect(x - 4, y - 4, 9, 9); } g2d.setColor(Color.BLUE); String outFilenamepre = "/home/cloudera/workspace/training/dataoutput/"; for (int k = 1; k < 20; k++) { String outFilename = outFilenamepre + "iteration" + k + "/part-00000"; try { BufferedReader bwo = new BufferedReader(new FileReader(outFilename)); String line; for (int i = 0; i < NCLUSTERS; i++) { line = bwo.readLine(); String[] num = line.split(" "); String[] num0 = num[0].split(" "); System.out.println("num[0]=" + num[0] + " line =" + num0[1]); double dxp = precenter[i][0]; double dyp = precenter[i][1]; int xp = (int) Math.abs(Math.round(dxp * w)) % w; int yp = (int) Math.abs(Math.round(dyp * h)) % h; double dx = Double.parseDouble(num0[1]); double dy = Double.parseDouble(num[1]); int x = (int) Math.abs(Math.round(dx * w)) % w; int y = (int) Math.abs(Math.round(dy * h)) % h; g2d.drawLine(xp, yp, x, y); g2d.drawRect(x - 4, y - 4, 9, 9); precenter[i][0] = dx; precenter[i][1] = dy; } // wait(1000); bwo.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // k }
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { hostGraphics.drawArc(x, y, width, height, startAngle, arcAngle); }
// also clip, transform, composite, // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;} // --------------------------------------------------------- private void doPaint(Graphics2D g, int s, Object o) { // process an operation from the buffer // System.out.println(s); Object o1 = null, o2 = null, o3 = null, o4 = null, o5 = null, o6 = null, o7 = null, o8 = null, o9 = null, o10 = null, o11 = null; if (o instanceof Object[]) { Object[] a = (Object[]) o; if (a.length > 0) o1 = a[0]; if (a.length > 1) o2 = a[1]; if (a.length > 2) o3 = a[2]; if (a.length > 3) o4 = a[3]; if (a.length > 4) o5 = a[4]; if (a.length > 5) o6 = a[5]; if (a.length > 6) o7 = a[6]; if (a.length > 7) o8 = a[7]; if (a.length > 8) o9 = a[8]; if (a.length > 9) o10 = a[9]; if (a.length > 10) o11 = a[10]; } switch (s) { case clear: paintBackground(g, theBackground); break; // public void addRenderingHints(Map<?,?> hints) // {toBuffer("addRenderingHints",hints );} case addRenderingHints: g.addRenderingHints((Map<?, ?>) o); break; case clip1: g.clip((Shape) o); break; case draw1: g.draw((Shape) o); break; case draw3DRect: g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case drawGlyphVector: g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3); break; case drawImage1: g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4); break; case drawImage2: g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3); break; case drawRenderableImage: g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2); break; case drawRenderedImage: g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2); break; case drawString1: g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3); break; case drawString2: g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3); break; case drawString3: g.drawString((String) o1, (Float) o2, (Float) o3); break; case drawString4: g.drawString((String) o1, (Integer) o2, (Integer) o3); break; case fill: g.fill((Shape) o); break; case fill3DRect: g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case rotate1: g.rotate((Double) o); break; case rotate2: g.rotate((Double) o1, (Double) o2, (Double) o3); break; case scale1: g.scale((Double) o1, (Double) o2); break; case setBackground: g.setBackground( (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/ break; case setComposite: g.setComposite((Composite) o); break; case setPaint: g.setPaint((Paint) o); break; case setRenderingHint: g.setRenderingHint((RenderingHints.Key) o1, o2); break; case setRenderingHints: g.setRenderingHints((Map<?, ?>) o); break; case setStroke: g.setStroke((Stroke) o); break; case setTransform: g.setTransform(makeTransform(o)); break; case shear: g.shear((Double) o1, (Double) o2); break; case transform1: g.transform(makeTransform(o)); break; case translate1: g.translate((Double) o1, (Double) o2); break; case translate2: g.translate((Integer) o1, (Integer) o2); break; case clearRect: g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case copyArea: g.copyArea( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawArc: g.drawArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawBytes: g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawChars: g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawImage4: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5); break; case drawImage5: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4); break; case drawImage6: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Color) o6, (ImageObserver) o7); break; case drawImage7: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6); break; case drawImage8: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (Color) o10, (ImageObserver) o11); break; case drawImage9: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (ImageObserver) o10); break; case drawLine: g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawOval: g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawPolygon1: g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case drawPolygon2: g.drawPolygon((Polygon) o); break; case drawPolyline: g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3); break; case drawRect: g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawRoundRect: g.drawRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillArc: g.fillArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillOval: g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; // {toBuffer("fillPolygon",mkArg(xPoints, yPoints, nPoints) );} case fillPolygon1: g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case fillPolygon2: g.fillPolygon((Polygon) o); break; case fillRect: g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case fillRoundRect: g.fillRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case setClip1: g.setClip((Shape) o); break; case setColor: g.setColor((Color) o); break; case setFont: g.setFont((Font) o); break; case setPaintMode: g.setPaintMode(); break; case setXORMode: g.setXORMode((Color) o); break; case opaque: super.setOpaque((Boolean) o); break; case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break; { FontRenderContext frc = g.getFontRenderContext(); TextLayout tl = new TextLayout((String) o1, g.getFont(), frc); Shape s1 = tl.getOutline(null); AffineTransform af = g.getTransform(); g.translate((Integer) o2, (Integer) o3); g.draw(s1); g.setTransform(af); } ; break; default: System.out.println("Unknown image operation " + s); } }
@Override protected void paintFoldShape(Graphics2D gfx, int top, int bottom) { gfx.drawArc(1, top, 8, (bottom - top), 0, 360); }
private void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { gRef.drawArc(x, y, width, height, startAngle, arcAngle); }
public void renderPlot(Graphics2D g) { g.setColor(Color.RED); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int xCenter = getCenterX(); int yCenter = getCenterY(); // g.drawRect(0, 0, xCenter, yCenter); // g.drawRect(0, 0, this.getDimension().width, // this.getDimension().height); DataModel1D model1 = (DataModel1D) this.getDataModel(); double total = getTotalValue().doubleValue(); int stop = model1.getSize(); computeColorsAndSpaces(); // spaces[0] = 10; int maxSpace = (int) spaces[0]; int height2 = Math.min(xCenter, yCenter) - maxSpace - this.getMaxLabelHeight(g) / 2 - 2; int width2 = height2; // Math.min(xCenter, yCenter) - maxSpace; int posX = (getCenterX() - width2); int posY = (getCenterY() - width2); double ratio = 360 / total; double startAngle = 0D; for (int i = 0; i < stop; i++) { Number n = model1.getValueAt(i); if (n == null) { continue; } int angle = (int) Math.round(n.doubleValue() * ratio); double moveAngle = startAngle - angle / 2D; double angleRadian = ((moveAngle) * Math.PI * 2) / 360; double current_space = spaces[i]; int x = posX + width2 / 2 + (int) ((Math.cos(angleRadian)) * current_space); int y = posY + height2 / 2 + (int) ((-Math.sin(angleRadian)) * current_space); g.setColor(colors[i]); g.setStroke( new BasicStroke( width2 - this.innerWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 12.0f, null, 10.0f)); g.drawArc(x, y, width2, height2, (int) Math.round(startAngle), -angle); g.setStroke(new BasicStroke()); if (i < labels.size()) { final String label = labels.get(i).getLabel(); int x1 = width2 + posX + (int) Math.round((Math.cos(angleRadian)) * (width2 + current_space)); int y1 = height2 + posY + (int) Math.round((-Math.sin(angleRadian)) * (height2 + current_space)); int x2 = width2 + posX + (int) Math.round((Math.cos(angleRadian)) * (width2 + current_space + 3)); int y2 = height2 + posY + (int) Math.round((-Math.sin(angleRadian)) * (height2 + current_space + 3)); g.setColor(Color.GRAY); g.drawLine(x1, y1, x2, y2); int x3; int xLabel; int y4 = y2 + g.getFontMetrics().getAscent() / 2 - 2; if (x1 > xCenter) { // Label a droite x3 = x2 + 2 + (this.getChartRectangle().width - x1) / 2; xLabel = x3 + 2; if (x3 + getLabelWidth(g, label) > this.getChartRectangle().getWidth()) { // Pas assez de place, besoin de decaler à gauche le label de droite x3 = (int) this.getChartRectangle().getWidth() - getLabelWidth(g, label) - 4; xLabel = x3 + 4; } } else { // Label à gauche x3 = x2; x2 = (xCenter - width2) / 2; xLabel = x2 - this.getMaxLabelWidth(g) - 2; if (xLabel < 0) { xLabel = 0; x2 = getLabelWidth(g, label); } } // ligne horizontale partant de la gauche vers la droite if (x2 < x3) { g.drawLine(x2, y2, x3, y2); } // if (xLabel < 0) { // xLabel = 0; // } g.drawString(label, xLabel, y4); } startAngle -= angle; } if (this.getSeparatorColor() != null) { startAngle = 0D; g.setStroke(new BasicStroke(2f)); g.setColor(this.getSeparatorColor()); // g.setColor(Color.RED); for (int i = 0; i < stop; i++) { Number n = model1.getValueAt(i); if (n == null) { continue; } int angle = (int) Math.round(n.doubleValue() * ratio); double angleRadian = ((startAngle) * Math.PI * 2) / 360; double current_space = spaces[i]; // int x1 = posX + width2 + (int) // Math.round((Math.cos(angleRadian)) * (current_space+1); // int y1 = posY + height2 + (int) // Math.round((-Math.sin(angleRadian)) * (current_space+1); int x2 = posX + width2 + (int) ((Math.cos(angleRadian)) * (width2 + current_space + 2)); int y2 = posY + height2 + (int) ((-Math.sin(angleRadian)) * (height2 + current_space + 2)); g.drawLine(xCenter, yCenter, x2, y2); startAngle -= angle; } } // renderInner(g, width2, height2, spaces); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; Point point = MouseInfo.getPointerInfo().getLocation(); Point loc = getLocationOnScreen(); g2d.setColor(new Color(20, 90, 95, 100)); g2d.fillRect(x, y, w, h); g2d.setPaint( new GradientPaint( x, y + 25, new Color(20, 100, 95, 0), x, y + h - 35, new Color(35, 200, 180, 30))); g2d.fillRect(x, y + 25, w, h - 60); g2d.setStroke(new BasicStroke(1)); g2d.setColor(new Color(35, 185, 185, 60)); g2d.drawLine(x, y + h, x + w, y + h); Rectangle tview = (view.width != 0 && view.height != 0) ? view : new Rectangle( (int) data[0][0], minY() - 5, (int) data[data.length - 1][0] - (int) data[0][0], maxY() - minY() + 10); int steps = 2 + (int) ((Math.log10(tview.height) - Math.floor(Math.log10(tview.height))) * 8) / 2; g2d.setClip(x, y, w, h - 35); g2d.setColor(new Color(35, 185, 185, 30)); g2d.setStroke( new BasicStroke( 1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {2.0f}, 1.0f)); for (int i = 1; i < steps; i++) { g2d.drawLine( x, y + (int) (((float) i / steps) * (h - 35)), x + w, y + (int) (((float) i / steps) * (h - 35))); } g2d.setColor(new Color(100, 120, 120, 150)); int ly = y + h - 38 - (int) ((double) ((line - tview.y) / tview.height) * (h - 35)); g2d.drawLine(x, ly, x + w - 37, ly); g2d.drawLine(x + w - 12, ly, x + w, ly); g2d.setFont(font); g2d.setColor(new Color(100, 10, 0, 20)); for (int dx = -1; dx < 2; dx++) { for (int dy = -1; dy < 2; dy++) { g2d.drawString("AVG", x + w - 35 + dx, ly + 4 + dx); } } g2d.setColor(new Color(200, 20, 0, 240)); g2d.drawString("AVG", x + w - 35, ly + 4); g2d.setColor(new Color(25, 185, 120, 150)); g2d.setStroke( new BasicStroke( 1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {3.0f}, 2.0f)); for (int i = 1; i < secondData.length; i++) { int tx = x + (int) ((double) ((secondData[i][0] - tview.x) / tview.width) * w); int ty = y + h - 35 - (int) ((double) ((secondData[i][1] - tview.y) / tview.height) * (h - 35)); int px = x + (int) ((double) ((secondData[i - 1][0] - tview.x) / tview.width) * w); int py = y + h - 35 - (int) ((double) ((secondData[i - 1][1] - tview.y) / tview.height) * (h - 35)); g2d.drawLine(px, py, tx, ty); } g2d.setStroke(new BasicStroke(1.5f)); boolean hasHover = false; for (int i = 0; i < data.length; i++) { if (data[i][0] >= tview.x && data[i][0] <= tview.getMaxX()) { if (data[i][1] >= tview.y && data[i][1] <= (int) tview.getMaxY()) { int tx = x - 3 + (int) ((double) ((data[i][0] - tview.x) / tview.width) * w); int ty = y + h - 38 - (int) ((double) ((data[i][1] - tview.y) / tview.height) * (h - 35)); boolean hover = Math.sqrt( Math.pow(point.x - loc.x - (tx + 3), 2) + Math.pow(point.y - loc.y - (ty + 3), 2)) <= 6; if (hover) { hasHover = true; if (lastHover != i) { lastHover = i; hoverpoint.fire(i, data[i]); } } if (i > 0) { int px = x + (int) ((double) ((data[i - 1][0] - tview.x) / tview.width) * w); int py = y + h - 35 - (int) ((double) ((data[i - 1][1] - tview.y) / tview.height) * (h - 35)); g2d.drawLine(px, py, tx + 3, ty + 3); } if (hover) { g2d.setColor(new Color(35, 185, 185)); g2d.fillArc(tx, ty, 6, 6, 0, 360); g2d.drawArc(tx - 4, ty - 4, 13, 13, 0, 360); int tw = textWidth(Integer.toString((int) data[i][1]), g2d); boolean above = ty - y > 30; int side = tx - x - tw / 2 - 12 < 0 ? 1 : (tx - x + tw / 2 + 12 > w ? -1 : 0); g2d.setColor(new Color(0, 0, 0, 200)); g2d.fillRoundRect( tx - tw / 2 - 8 + (side * (tw + 10)), side != 0 ? ty - 8 : (above ? ty - 28 : ty + 13), tw + 16, 19, 4, 4); g2d.setPaint( new GradientPaint( tx, side != 0 ? ty - 6 : (above ? ty - 25 : ty + 16), new Color(25, 90, 95, 140), tx, side != 0 ? ty + 6 : (above ? ty - 12 : ty + 29), new Color(30, 135, 137, 160))); g2d.fillRoundRect( tx - tw / 2 - 8 + (side * (tw + 10)), side != 0 ? ty - 8 : (above ? ty - 28 : ty + 13), tw + 16, 19, 4, 4); g2d.setColor(new Color(35, 185, 185)); g2d.drawString( Integer.toString((int) data[i][1]), tx - tw / 2 + (side * (tw + 10)), side != 0 ? ty + 5 : (above ? ty - 15 : ty + 26)); g2d.setColor(new Color(35, 185, 185, 200)); } else { g2d.setColor(new Color(35, 185, 185, 200)); g2d.drawArc(tx, ty, 6, 6, 0, 360); } } } } if (!hasHover) lastHover = -1; g2d.setColor(new Color(35, 200, 120, 200)); g2d.setClip(null); g2d.setColor(new Color(0, 0, 0, 200)); g2d.fillRect(x, y, 30, h - 35); g2d.setPaint( new GradientPaint( x, y, new Color(35, 175, 185, 45), x, y + h - 35, new Color(25, 150, 145, 100))); g2d.fillRect(x, y, 30, h - 35); g2d.setColor(new Color(35, 185, 185)); for (int i = 1; i < steps; i++) { float perc = ((float) i / steps); g2d.drawString( format((int) (tview.y + perc * tview.height)), x + 9, y + h - 31 - (int) (perc * (h - 35))); } g2d.setClip(x, y + h - 35, w, 35); for (int i = 0; i < bottomLabels.length; i++) { float perc = (float) (((double) i * labelInterval) + labelStart - tview.x) / (tview.width); if (perc > -0.2 && perc < 1.2) { if (perc > 0.9) { g2d.setColor(new Color(35, 185, 185, 255 - (int) ((perc - 0.9) * 10 * 200))); } else if (perc < 0.1) { g2d.setColor(new Color(35, 185, 185, 55 + (int) ((perc) * 10 * 200))); } else { g2d.setColor(new Color(35, 185, 185, 255)); } g2d.drawString( bottomLabels[i], x + perc * w - textWidth(bottomLabels[i], g2d) / 2, y + h - 12); } } g2d.setClip(null); }
private void render(Graphics g, int drawingPage, double scale) { Graphics2D g2 = (Graphics2D) g; g2.scale(scale, scale); int pageIndex; paperPanel.setPreferredSize(new Dimension(600, numberOfPages * (pageHeight + 25))); for (int page = 0; page < numberOfPages; page++) { g2.setColor(Color.white); g2.fillRect(0, page * (pageHeight + 25), pageWidth, pageHeight); } g2.setColor(Color.black); for (Object[] task : elements) { switch ((Integer) task[0]) { case DRAW_STRING: FontMetrics metrics = getFontMetrics(g2.getFont()); String string = task[1].toString(); int x = (Integer) task[2]; int y = (Integer) task[3]; pageIndex = (Integer) task[4]; if (drawingPage == -1) y += (pageIndex * (pageHeight + 25)); int width = metrics.stringWidth(string); if (drawingPage == -1 || drawingPage == pageIndex) { if (currentAlignment == LEFT) { g2.drawString(string, x, y); if (underline) { g2.drawLine(x, y + 3, x + width, y + 3); } } else if (currentAlignment == RIGHT) { g2.drawString(string, x - width, y); if (underline) { g2.drawLine(x, y + 3, x - width, y + 3); } } else if (currentAlignment == CENTER) { g2.drawString(string, x - (width / 2), y); if (underline) { g2.drawLine(x - (width / 2), y + 3, x + (width / 2), y + 3); } } } break; case DRAW_LINE: int x1 = (Integer) task[1], y1 = (Integer) task[2], x2 = (Integer) task[3], y2 = (Integer) task[4]; pageIndex = (Integer) task[5]; if (drawingPage == -1) g2.drawLine( x1, (pageIndex * (pageHeight + 25)) + y1, x2, (pageIndex * (pageHeight + 25)) + y2); else if (drawingPage == pageIndex) g2.drawLine(x1, y1, x2, y2); break; case DRAW_RECT: int rectX = (Integer) task[1], rectY = (Integer) task[2], rectWidth = (Integer) task[3], rectHeight = (Integer) task[4]; pageIndex = (Integer) task[5]; if (drawingPage == -1) g2.drawRect(rectX, (pageIndex * (pageHeight + 25)) + rectY, rectWidth, rectHeight); else if (drawingPage == pageIndex) g2.drawRect(rectX, rectY, rectWidth, rectHeight); break; case DRAW_OVAL: int ovalX = (Integer) task[1], ovalY = (Integer) task[3], ovalWidth = (Integer) task[3], ovalHeight = (Integer) task[4]; pageIndex = (Integer) task[5]; if (drawingPage == -1) g2.drawOval(ovalX, (pageIndex * (pageHeight + 25)) + ovalY, ovalWidth, ovalHeight); else if (drawingPage == pageIndex) g2.drawOval(ovalX, ovalY, ovalWidth, ovalHeight); break; case DRAW_IMAGE: Image image = (Image) task[1]; int imageX = (Integer) task[2], imageY = (Integer) task[3], imageWidth = (Integer) task[4], imageHeight = (Integer) task[5]; pageIndex = (Integer) task[6]; if (drawingPage == -1) g2.drawImage( image, imageX, (pageIndex * (pageHeight + 25)) + imageY, imageWidth, imageHeight, this); else if (drawingPage == pageIndex) g2.drawImage(image, imageX, imageY, imageWidth, imageHeight, this); break; case DRAW_POLYGON: int[] xPoints = (int[]) task[1], yPoints = (int[]) task[2]; int numberOfPoints = (Integer) task[3]; pageIndex = (Integer) task[4]; if (drawingPage == -1) { for (int i = 0; i < yPoints.length; i++) { yPoints[i] += (pageIndex * (pageHeight + 25)); } g2.drawPolygon(xPoints, yPoints, numberOfPoints); } else if (drawingPage == pageIndex) g2.drawPolygon(xPoints, yPoints, numberOfPoints); break; case DRAW_ARC: int arcX = (Integer) task[1], arcY = (Integer) task[2], arcWidth = (Integer) task[3], arcHeight = (Integer) task[4], startAngle = (Integer) task[5], arcAngle = (Integer) task[6]; pageIndex = (Integer) task[7]; if (drawingPage == -1) g2.drawArc( arcX, (pageIndex * (pageHeight + 25)) + arcY, arcWidth, arcHeight, startAngle, arcAngle); else if (drawingPage == pageIndex) g2.drawArc(arcX, arcY, arcWidth, arcHeight, startAngle, arcAngle); break; case FILL_RECT: int fillRectX = (Integer) task[1], fillRectY = (Integer) task[2], fillRectWidth = (Integer) task[3], fillRectHeight = (Integer) task[4]; pageIndex = (Integer) task[5]; if (drawingPage == -1) g2.fillRect( fillRectX, (pageIndex * (pageHeight + 25)) + fillRectY, fillRectWidth, fillRectHeight); else if (drawingPage == pageIndex) g2.fillRect(fillRectX, fillRectY, fillRectWidth, fillRectHeight); break; case FILL_OVAL: int fillOvalX = (Integer) task[1], fillOvalY = (Integer) task[2], fillOvalWidth = (Integer) task[3], fillOvalHeight = (Integer) task[4]; pageIndex = (Integer) task[5]; if (drawingPage == -1) g2.fillOval( fillOvalX, (pageIndex * (pageHeight + 25)) + fillOvalY, fillOvalWidth, fillOvalHeight); else if (drawingPage == pageIndex) g2.fillOval(fillOvalX, fillOvalY, fillOvalWidth, fillOvalHeight); break; case FILL_POLYGON: int[] fillXPoints = (int[]) task[1], fillYPoints = (int[]) task[2]; int fillNumberOfPoints = (Integer) task[3]; pageIndex = (Integer) task[4]; if (drawingPage == -1) { for (int i = 0; i < fillYPoints.length; i++) { fillYPoints[i] += (pageIndex * (pageHeight + 25)); } g2.fillPolygon(fillXPoints, fillYPoints, fillNumberOfPoints); } else if (drawingPage == pageIndex) g2.fillPolygon(fillXPoints, fillYPoints, fillNumberOfPoints); break; case FILL_ARC: int fillArcX = (Integer) task[1], fillArcY = (Integer) task[2], fillArcWidth = (Integer) task[3], fillArcHeight = (Integer) task[4], fillStartAngle = (Integer) task[5], fillArcAngle = (Integer) task[6]; pageIndex = (Integer) task[7]; if (drawingPage == -1) g2.fillArc( fillArcX, (pageIndex * (pageHeight + 25)) + fillArcY, fillArcWidth, fillArcHeight, fillStartAngle, fillArcAngle); else if (drawingPage == pageIndex) g2.fillArc( fillArcX, fillArcY, fillArcWidth, fillArcHeight, fillStartAngle, fillArcAngle); break; case SET_COLOR: g2.setColor((Color) task[1]); break; case SET_FONT: g2.setFont((Font) task[1]); break; case SET_STROKE: g2.setStroke((Stroke) task[1]); break; case SET_PAINT: g2.setPaint((Paint) task[1]); break; case SET_ALIGNMENT: currentAlignment = (Integer) task[1]; break; case SET_STYLE: int style = (Integer) task[1]; // currentStyle = style; styleFont = currentFont.deriveFont(Font.PLAIN); if (style == BOLD) styleFont = styleFont.deriveFont(Font.BOLD); if (style == ITALIC) styleFont = styleFont.deriveFont(Font.ITALIC); underline = (style == UNDERLINE); if (style == BOLD_UNDERLINE) { styleFont = styleFont.deriveFont(Font.BOLD); underline = true; } g2.setFont(styleFont); break; } } }
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { g2d.drawArc(x, y, width, height, startAngle, arcAngle); }