Java Code Examples for java.awt.Graphics2D

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project addis, under directory /application/src/main/java/org/drugis/addis/gui/.

Source file: DrugVertexView.java

  23 
vote

@Override public void paint(Graphics g){
  setSize(200,50);
  Graphics2D g2d=(Graphics2D)g;
  setBorder(BorderFactory.createLineBorder(Color.black,3));
  setBackground(Color.WHITE);
  setForeground(Color.BLACK);
  g.setColor(Color.BLACK);
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.draw(new Ellipse2D.Double(0,0,200,50));
  char[] text=getText().toCharArray();
  g.drawChars(text,0,text.length,20,20);
}
 

Example 2

From project Agot-Java, under directory /src/main/java/got/ui/.

Source file: DrawManager.java

  22 
vote

private void highlightTerritory(String terrName,Color color){
  TerritoryInfo ti=gameInfo.getTerrMap().get(terrName);
  Graphics2D g2d=(Graphics2D)graphics;
  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.1f));
  g2d.setColor(color);
  g2d.fillPolygon(ti.getPoly());
  g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1f));
}
 

Example 3

From project autopsy, under directory /Core/src/org/sleuthkit/autopsy/corecomponents/.

Source file: ThumbnailViewNode.java

  18 
vote

private static BufferedImage toBufferedImage(Image src){
  int w=src.getWidth(null);
  int h=src.getHeight(null);
  int type=BufferedImage.TYPE_INT_RGB;
  BufferedImage dest=new BufferedImage(w,h,type);
  Graphics2D g2=dest.createGraphics();
  g2.drawImage(src,0,0,null);
  g2.dispose();
  return dest;
}
 

Example 4

From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/image/local/.

Source file: LocalImageService.java

  18 
vote

/** 
 * Splices the specified image1 and image2 horizontally.
 * @param image1 the specified image1
 * @param image2 the specified image2
 * @return the spliced image
 */
private static BufferedImage splice(final java.awt.Image image1,final java.awt.Image image2){
  final int[][] size={{image1.getWidth(null),image1.getHeight(null)},{image2.getWidth(null),image2.getHeight(null)}};
  final int width=size[0][0] + size[1][0];
  final int height=Math.max(size[0][1],size[1][1]);
  final BufferedImage ret=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
  final Graphics2D g2=ret.createGraphics();
  g2.drawImage(image1,0,0,null);
  g2.drawImage(image2,size[0][0],0,null);
  return ret;
}
 

Example 5

From project beanmill_1, under directory /src/main/java/com/traxel/lumbermill/event/.

Source file: EventViewVieport.java

  18 
vote

@Override public void paintChildren(final Graphics g){
  final Graphics2D g2d=(Graphics2D)g;
  final Composite alphaComp=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.15f);
  final Composite noAlphaComp=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1f);
  g2d.setComposite(alphaComp);
  if ((ev != null) && (ev.getLogo() != null)) {
    g2d.drawImage(ev.getLogo(),getWidth() - ev.getLogo().getWidth(null),getHeight() - ev.getLogo().getHeight(null),this);
  }
  g2d.setComposite(noAlphaComp);
  super.paintChildren(g);
}
 

Example 6

From project Briss, under directory /src/main/java/at/laborg/briss/gui/.

Source file: MergedPanel.java

  18 
vote

@Override public void update(Graphics g){
  if (!isEnabled())   return;
  Graphics2D g2=(Graphics2D)g;
  g2.drawImage(img,null,0,0);
  int cropCnt=0;
  for (  DrawableCropRect crop : crops) {
    drawNormalCropRectangle(g2,cropCnt,crop);
    if (crop.isSelected()) {
      drawSelectionOverlay(g2,crop);
    }
    cropCnt++;
  }
  g2.dispose();
}
 

Example 7

From project Calendar-Application, under directory /com/toedter/components/.

Source file: JTitlePanel.java

  18 
vote

public void paintComponent(Graphics g){
  super.paintComponent(g);
  if (isOpaque()) {
    Color controlColor=new Color(165,201,215);
    int width=getWidth();
    int height=getHeight();
    Graphics2D g2=(Graphics2D)g;
    Paint oldPaint=g2.getPaint();
    g2.setPaint(new GradientPaint(0,0,getBackground(),width,0,controlColor));
    g2.fillRect(0,0,width,height);
    g2.setPaint(oldPaint);
  }
}
 

Example 8

From project Carolina-Digital-Repository, under directory /djatoka-cdr/src/gov/lanl/adore/djatoka/plugin/.

Source file: TextWatermark.java

  18 
vote

/** 
 * Performs the transformation based on the provided global and instance properties.
 * @param bi the extracted region BufferedImage to be transformed
 * @return the resulting BufferedImage or the same bi if no changes are made
 * @throws TransformException
 */
public BufferedImage run(BufferedImage bi) throws TransformException {
  if (!isTransformable())   return bi;
  Graphics2D graphics=bi.createGraphics();
  graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,fontOpacity));
  graphics.setColor(color);
  graphics.setFont(new Font(fontName,Font.PLAIN,fontSize));
  graphics.drawString(msg,10,bi.getHeight() - 10);
  return bi;
}
 

Example 9

From project ceres, under directory /ceres-glayer/src/main/java/com/bc/ceres/glayer/support/.

Source file: BackgroundLayer.java

  18 
vote

@Override protected void renderLayer(Rendering rendering){
  final Graphics2D g=rendering.getGraphics();
  Paint oldPaint=g.getPaint();
  g.setPaint(getColor());
  Rectangle bounds=g.getClipBounds();
  g.fillRect(bounds.x,bounds.y,bounds.width,bounds.height);
  g.setPaint(oldPaint);
}
 

Example 10

From project Chess_1, under directory /src/chess/gui/.

Source file: ColorEditor.java

  18 
vote

public void paintIcon(Component c,Graphics g,int x,int y){
  Rectangle r=new Rectangle(x,y,WIDTH - 1,HEIGHT - 1);
  Graphics2D g2=(Graphics2D)g;
  Color oldColor=g2.getColor();
  g2.setColor(color);
  g2.fill(r);
  g2.setColor(Color.BLACK);
  g2.draw(r);
  g2.setColor(oldColor);
}
 

Example 11

From project ChkBugReport, under directory /src/com/sonyericsson/chkbugreport/traceview/.

Source file: TreePNGPlugin.java

  18 
vote

private void createEmptyChart(Chart chart){
  BufferedImage img=new BufferedImage(W,H,BufferedImage.TYPE_INT_RGB);
  Graphics2D g=(Graphics2D)img.getGraphics();
  g.setColor(Color.BLACK);
  g.fillRect(0,0,W,H);
  chart.img=img;
  chart.g=g;
}
 

Example 12

From project Cinch, under directory /example/com/palantir/ptoss/cinch/example/demo/.

Source file: DrawingCanvas.java

  18 
vote

@Override protected void paintComponent(Graphics g){
  Graphics2D g2=(Graphics2D)g;
  g2.setColor(Color.WHITE);
  g2.fillRect(0,0,getWidth(),getHeight());
  g2.setColor(Color.BLACK);
  for (  Line2D line : model.getLines()) {
    g2.draw(line);
  }
  for (  Point2D point : model.getPoints()) {
    g2.fillOval((int)point.getX(),(int)point.getY(),5,5);
  }
}
 

Example 13

From project CIShell, under directory /core/org.cishell.utilities/src/org/cishell/utilities/.

Source file: ImageUtilities.java

  18 
vote

public static BufferedImage createBufferedImageFilledWithColor(Color fillColor){
  BufferedImage bufferedImage=new BufferedImage(TEMPORARY_IMAGE_WIDTH,TEMPORARY_IMAGE_HEIGHT,BufferedImage.TYPE_INT_RGB);
  Graphics2D bufferedImageGraphics2D=bufferedImage.createGraphics();
  bufferedImageGraphics2D.setBackground(fillColor);
  return bufferedImage;
}
 

Example 14

From project Clotho-Core, under directory /ClothoApps/CollectionViewTool/src/org/clothocad/tool/collectionview/.

Source file: GlassMessage.java

  18 
vote

@Override public void paintComponent(Graphics g){
  if (image == null) {
    createAnimationImage();
  }
  g.setColor(new Color(255,255,255,0));
  g.fillRect(0,0,getWidth(),getHeight());
  Graphics2D gFade=(Graphics2D)g.create();
  gFade.setComposite(AlphaComposite.SrcOver.derive(opacity));
  gFade.drawImage(image,fadeX,fadeY,null);
  gFade.dispose();
}
 

Example 15

From project core_4, under directory /impl/src/main/java/org/richfaces/resource/.

Source file: Java2DUserResourceWrapperImpl.java

  18 
vote

protected Graphics2D createGraphics(BufferedImage image){
  Graphics2D g2d=image.createGraphics();
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.setRenderingHint(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_ENABLE);
  g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
  g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
  g2d.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  return g2d;
}
 

Example 16

From project core_5, under directory /exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/image/.

Source file: ImageProcessingServiceImpl.java

  18 
vote

public BufferedImage createScaledImage(BufferedImage img,double factor){
  int imgWidth=img.getWidth();
  int imgHeight=img.getHeight();
  int newWidth=(new Double(imgWidth * factor)).intValue();
  int newHeight=(new Double(imgHeight * factor)).intValue();
  Image imgScaled=img.getScaledInstance(newWidth,newHeight,Image.SCALE_DEFAULT);
  BufferedImage scaledImage=new BufferedImage(newWidth,newHeight,BufferedImage.TYPE_INT_RGB);
  Graphics2D aImage=scaledImage.createGraphics();
  aImage.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
  aImage.drawImage(imgScaled,0,0,newWidth,newHeight,null);
  return scaledImage;
}
 

Example 17

From project cowgraph, under directory /CowGraph/CowGraphVisualEditor/src/zbeans/cowgraph/visual/editor/widget/.

Source file: ArrowWidget.java

  18 
vote

@Override protected void paintWidget(){
  super.paintWidget();
  Graphics2D gr=getGraphics();
  gr.setColor(element.getColor());
  gr.drawLine(element.getX(),element.getY(),element.getToX(),element.getToY());
}
 

Example 18

From project CraftMania, under directory /CraftMania/src/org/craftmania/game/.

Source file: TextureStorage.java

  18 
vote

public static Texture loadStichedTexture(String id,String resource0,String resource1) throws IOException {
  BufferedImage img0=ImageIO.read(getTextureFile(resource0));
  BufferedImage img1=ImageIO.read(getTextureFile(resource1));
  if (img0.getWidth() != img1.getWidth()) {
    throw new IOException("Images do not have the same width");
  }
  BufferedImage img=new BufferedImage(img0.getWidth(),img0.getHeight() + img1.getHeight(),img0.getType());
  Graphics2D g=img.createGraphics();
  g.drawImage(img0,0,0,null);
  g.drawImage(img1,0,img0.getHeight(),null);
  g.dispose();
  return loadTexture(id,img);
}
 

Example 19

From project Custom-Salem, under directory /src/haven/.

Source file: RichText.java

  18 
vote

public Foundry(Parser parser){
  this.parser=parser;
  BufferedImage junk=TexI.mkbuf(new Coord(10,10));
  Graphics2D g=junk.createGraphics();
  rs=new RState(g.getFontRenderContext());
}
 

Example 20

From project dawn-common, under directory /org.dawb.gda.extensions/src/org/dawb/gda/extensions/util/.

Source file: ImageThumbnailCreator.java

  18 
vote

static Image getImageSWT(File file){
  ImageIcon systemIcon=(ImageIcon)FileSystemView.getFileSystemView().getSystemIcon(file);
  java.awt.Image image=systemIcon.getImage();
  if (image instanceof BufferedImage) {
    return new Image(Display.getDefault(),convertToSWT((BufferedImage)image));
  }
  int width=image.getWidth(null);
  int height=image.getHeight(null);
  BufferedImage bufferedImage=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2d=bufferedImage.createGraphics();
  g2d.drawImage(image,0,0,null);
  g2d.dispose();
  return new Image(Display.getDefault(),convertToSWT(bufferedImage));
}
 

Example 21

From project drugis-common, under directory /common-extra/src/main/java/org/drugis/common/gui/.

Source file: ImageExporter.java

  18 
vote

protected static <T>void writePNG(String path,DrawCommand<T,Graphics2D> drawer,T toDraw,Dimension dim){
  GraphicsConfiguration config=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
  BufferedImage bufferedImage=config.createCompatibleImage(dim.width,dim.height,Transparency.OPAQUE);
  Graphics2D canvas=bufferedImage.createGraphics();
  canvas.setBackground(Color.WHITE);
  canvas.clearRect(0,0,bufferedImage.getWidth(),bufferedImage.getHeight());
  canvas.setColor(Color.BLACK);
  drawer.draw(toDraw,canvas,dim);
  writePNG(path,bufferedImage);
}
 

Example 22

From project en4j, under directory /NBPlatformApp/MainModule/src/main/java/com/rubenlaguna/en4j/mainmodule/.

Source file: CustomGlassPane.java

  18 
vote

@Override protected void paintComponent(Graphics g){
  Rectangle clip=g.getClipBounds();
  Graphics2D g2=(Graphics2D)g.create();
  AlphaComposite alpha=AlphaComposite.SrcOver.derive(0.65f);
  g2.setComposite(alpha);
  g2.setColor(getBackground());
  g2.fillRect(clip.x,clip.y,clip.width,clip.height);
}
 

Example 23

From project encog-java-workbench, under directory /src/main/java/org/encog/workbench/tabs/visualize/scatter/.

Source file: LegendPanel.java

  18 
vote

public void paint(Graphics g){
  Graphics2D g2d=(Graphics2D)g;
  BlockParams p=new BlockParams();
  p.setGenerateEntities(true);
  Rectangle area=new Rectangle(0,0,this.getWidth(),this.getHeight());
  legend.arrange(g2d);
  legend.draw(g2d,area,p);
}
 

Example 24

From project entando-core-engine, under directory /src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/imageresizer/.

Source file: PNGImageResizer.java

  18 
vote

/** 
 * Crea e restituisce un'immagine in base all'immagine master ed alle dimensioni massime consentite. L'immagine risultante sar? un'immagine rispettante le proporzioni dell'immagine sorgente.
 * @param imageIcon L'immagine sorgente.
 * @param dimensioneX la dimensione orizzontale massima.
 * @param dimensioneY La dimensione verticale massima.
 * @return L'immagine risultante.
 * @throws ApsSystemException In caso di errore.
 */
protected BufferedImage getResizedImage(ImageIcon imageIcon,int dimensioneX,int dimensioneY) throws ApsSystemException {
  Image image=imageIcon.getImage();
  BufferedImage bi=this.toBufferedImage(image);
  double scale=this.computeScale(image.getWidth(null),image.getHeight(null),dimensioneX,dimensioneY);
  int scaledW=(int)(scale * image.getWidth(null));
  int scaledH=(int)(scale * image.getHeight(null));
  BufferedImage biRes=new BufferedImage(bi.getColorModel(),bi.getColorModel().createCompatibleWritableRaster(scaledW,scaledH),bi.isAlphaPremultiplied(),null);
  AffineTransform tx=new AffineTransform();
  tx.scale(scale,scale);
  Graphics2D bufImageGraphics=biRes.createGraphics();
  bufImageGraphics.drawImage(image,tx,null);
  return biRes;
}
 

Example 25

From project Euclidean-Pattern-Generator, under directory /src/com/hisschemoller/sequencer/view/components/.

Source file: JPanelRoundedCorners.java

  18 
vote

public void paintComponent(Graphics graphics){
  super.paintComponent(graphics);
  Graphics2D graphics2=(Graphics2D)graphics;
  graphics2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  int radius=8;
  Color color=new Color(0xFFFFFFFF);
  graphics2.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),255));
  graphics2.fillRoundRect(0,0,getWidth(),getHeight(),radius,radius);
}
 

Example 26

From project flyingsaucer, under directory /flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/.

Source file: Java2DTextRenderer.java

  18 
vote

public FSFontMetrics getFSFontMetrics(FontContext fc,FSFont font,String string){
  Object fracHint=null;
  Graphics2D graphics=((Java2DFontContext)fc).getGraphics();
  fracHint=graphics.getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS);
  graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,fractionalFontMetricsHint);
  LineMetricsAdapter adapter=new LineMetricsAdapter(((AWTFSFont)font).getAWTFont().getLineMetrics(string,graphics.getFontRenderContext()));
  graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,fracHint);
  return adapter;
}
 

Example 27

From project blogs, under directory /request-mappers/src/main/java/com/wicketinaction/requestmappers/resources/images/.

Source file: ImageResourceReference.java

  17 
vote

/** 
 * Generates an image with a label. For real life application this method will read the image bytes from  external source.
 * @param label the image text to render
 * @return
 */
private byte[] getImageAsBytes(String label){
  BufferedImage image=new BufferedImage(800,600,BufferedImage.TYPE_INT_RGB);
  Graphics2D g=(Graphics2D)image.getGraphics();
  g.setColor(Color.BLACK);
  g.setBackground(Color.WHITE);
  g.clearRect(0,0,image.getWidth(),image.getHeight());
  g.setFont(new Font("SansSerif",Font.PLAIN,48));
  g.drawString(label,50,50);
  g.dispose();
  Iterator<ImageWriter> writers=ImageIO.getImageWritersByFormatName("jpg");
  ImageWriter writer=writers.next();
  if (writer == null) {
    throw new RuntimeException("JPG not supported?!");
  }
  final ByteArrayOutputStream out=new ByteArrayOutputStream();
  byte[] imageBytes=null;
  try {
    ImageOutputStream imageOut=ImageIO.createImageOutputStream(out);
    writer.setOutput(imageOut);
    writer.write(image);
    imageOut.close();
    imageBytes=out.toByteArray();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return imageBytes;
}
 

Example 28

From project BMach, under directory /src/bmach/ui/gui/components/.

Source file: JAddressTextField.java

  17 
vote

@Override protected void paintComponent(Graphics g){
  String text=getText();
  if (text.equals("")) {
    this.setIcon(pencilIcon);
  }
 else   if (text.matches("0x[0-9a-fA-F]{2}")) {
    this.setIcon(acceptIcon);
  }
 else {
    this.setIcon(errorIcon);
  }
  super.paintComponent(g);
  if (!this.hasFocus() && this.getText().equals("")) {
    int height=this.getHeight();
    Font prev=g.getFont();
    Font italic=prev.deriveFont(Font.ITALIC);
    Color prevColor=g.getColor();
    g.setFont(italic);
    g.setColor(UIManager.getColor("textInactiveText"));
    int h=g.getFontMetrics().getHeight();
    int textBottom=(height - h) / 2 + h - 4;
    int x=this.getInsets().left;
    Graphics2D g2d=(Graphics2D)g;
    RenderingHints hints=g2d.getRenderingHints();
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2d.drawString(textWhenNotFocused,x,textBottom);
    g2d.setRenderingHints(hints);
    g.setFont(prev);
    g.setColor(prevColor);
  }
}
 

Example 29

From project faces, under directory /Proyectos/showcase/src/main/java/org/primefaces/examples/view/.

Source file: DynamicImageController.java

  17 
vote

public DynamicImageController(){
  try {
    BufferedImage bufferedImg=new BufferedImage(100,25,BufferedImage.TYPE_INT_RGB);
    Graphics2D g2=bufferedImg.createGraphics();
    g2.drawString("This is a text",0,10);
    ByteArrayOutputStream os=new ByteArrayOutputStream();
    ImageIO.write(bufferedImg,"png",os);
    graphicText=new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()),"image/png");
    JFreeChart jfreechart=ChartFactory.createPieChart("Turkish Cities",createDataset(),true,true,false);
    File chartFile=new File("dynamichart");
    ChartUtilities.saveChartAsPNG(chartFile,jfreechart,375,300);
    chart=new DefaultStreamedContent(new FileInputStream(chartFile),"image/png");
    File barcodeFile=new File("dynamicbarcode");
    BarcodeImageHandler.saveJPEG(BarcodeFactory.createCode128("PRIMEFACES"),barcodeFile);
    barcode=new DefaultStreamedContent(new FileInputStream(barcodeFile),"image/jpeg");
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 30

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/rendering/.

Source file: Engine.java

  15 
vote

@Override public void run(){
  while (rendering) {
    long l1=System.nanoTime();
    scene.render((Graphics2D)getBackBufferGraphics());
    long l2=System.nanoTime();
    hud.render((Graphics2D)getBackBufferGraphics());
    long l3=System.nanoTime();
    stats_scene_time=(int)((l2 - l1) / 1000000);
    stats_hud_time=(int)((l3 - l2) / 1000000);
    updateGraphics(window.getGraphics());
  }
}
 

Example 31

From project alg-vis, under directory /src/algvis/gui/.

Source file: Screen.java

  15 
vote

void check_size(){
  Dimension d=getSize();
  if (I == null || d.width != size.width || d.height != size.height) {
    I=createImage(d.width,d.height);
    G=I.getGraphics();
    V.setGraphics((Graphics2D)G,d.width,d.height);
    size=d;
  }
}
 

Example 32

From project ANNIS, under directory /annis-gui/src/main/java/annis/gui/visualizers/iframe/tree/backends/staticimg/.

Source file: Java2dBackend.java

  15 
vote

@Override public AbstractImageGraphicsItem makeLines(final Collection<Line2D> lines,final Color color,final Stroke stroke){
  return new AbstractImageGraphicsItem(){
    @Override public Rectangle2D getBounds(){
      return null;
    }
    @Override public void draw(    Graphics2D canvas){
      canvas.setColor(color);
      canvas.setStroke(stroke);
      for (      Line2D l : lines) {
        canvas.draw(l);
      }
    }
  }
;
}
 

Example 33

From project ardverk-dht, under directory /components/tools/src/main/java/org/ardverk/dht/ui/.

Source file: JuicePainter.java

  15 
vote

@Override protected void paint(Component c,Graphics2D g){
  double width=c.getWidth();
  double height=c.getHeight();
  double gap=50d;
  double radius=Math.max(Math.min(width / 2d,height / 2d) - gap,gap);
  double arc_x=width / 2d - radius;
  double arc_y=height / 2d - radius;
  double arc_width=2d * radius;
  double arc_height=2d * radius;
  g.setColor(Color.orange);
  g.setStroke(PainterUtils.TWO_PIXEL_STROKE);
  ellipse.setFrame(arc_x,arc_y,arc_width,arc_height);
  g.draw(ellipse);
  double fi=position(localhostId,2d * Math.PI) - Math.PI / 2d;
  double dx=width / 2d + radius * Math.cos(fi);
  double dy=height / 2d + radius * Math.sin(fi);
  localhost.setLocation(dx,dy);
  dot.setFrame(dx - PainterUtils.DOT_SIZE / 2d,dy - PainterUtils.DOT_SIZE / 2d,PainterUtils.DOT_SIZE,PainterUtils.DOT_SIZE);
synchronized (nodes) {
    for (Iterator<Node> it=nodes.iterator(); it.hasNext(); ) {
      if (it.next().paint(localhost,width,height,radius,g)) {
        it.remove();
      }
    }
  }
  g.setColor(Color.ORANGE);
  g.setStroke(PainterUtils.DEFAULT_STROKE);
  g.fill(dot);
}
 

Example 34

From project CBCJVM, under directory /cbc/CBCJVM/src/cbccore/display/.

Source file: SimulatedFramebuffer.java

  15 
vote

@Override public void sync(){
  if (!window.isVisible())   return;
  g=(Graphics2D)window.getGraphics();
  for (int iy=0; iy < getHeight(); ++iy) {
    for (int ix=0; ix < getWidth(); ++ix) {
      int i=iy * getWidth() + ix;
      byte[] working={bytes[i * 2],bytes[i * 2 + 1]};
      Pixel p=Pixel.fromRGB565(working);
      g.setColor(new Color(p.getRed(),p.getGreen(),p.getBlue()));
      g.drawLine(ix,iy,ix,iy);
    }
  }
}
 

Example 35

From project cdk, under directory /maven-cdk-plugin/src/main/resources/skin/archetype/src/main/java/images/.

Source file: BaseImage.java

  15 
vote

@Override protected void paint(ResourceContext context,Graphics2D graphics2D){
  graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  graphics2D.setRenderingHint(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_ENABLE);
  graphics2D.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
  graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
  graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
}
 

Example 36

From project engine, under directory /main/com/midtro/platform/.

Source file: AppGraphics.java

  15 
vote

/** 
 * Creates a new AppGraphics reference.
 * @param ref The Graphics2D to wrap.
 * @param textAntiAliasing Whether or not to turn on text anti-aliasing.
 */
public AppGraphics(final Graphics2D ref,final boolean textAntiAliasing){
  this.ref=ref;
  if (textAntiAliasing) {
    this.ref.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  }
}