Java Code Examples for java.awt.RenderingHints

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 ceres, under directory /ceres-glayer/src/main/java/com/bc/ceres/glayer/tools/.

Source file: Tools.java

  23 
vote

public static RenderedOp createTiledImage(RenderedImage image,int tileWidth,int tileHeight){
  final int dataType=image.getSampleModel().getDataType();
  final ImageLayout imageLayout=new ImageLayout();
  imageLayout.setTileWidth(tileWidth);
  imageLayout.setTileHeight(tileHeight);
  final RenderingHints hints=new RenderingHints(JAI.KEY_IMAGE_LAYOUT,imageLayout);
  return FormatDescriptor.create(image,dataType,hints);
}
 

Example 2

From project Clotho-Core, under directory /ClothoApps/PluginManager/src/org/clothocore/tool/pluginmanager/gui/.

Source file: CurvesPanel.java

  22 
vote

protected RenderingHints createRenderingHints(){
  RenderingHints hints=new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  hints.put(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  hints.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  return hints;
}
 

Example 3

From project jumpnevolve, under directory /lib/slick/src/org/newdawn/slick/font/effects/.

Source file: ShadowEffect.java

  22 
vote

/** 
 * Apply blurring to the generate image
 * @param image The image to be blurred
 */
private void blur(BufferedImage image){
  float[] matrix=GAUSSIAN_BLUR_KERNELS[blurKernelSize - 1];
  Kernel gaussianBlur1=new Kernel(matrix.length,1,matrix);
  Kernel gaussianBlur2=new Kernel(1,matrix.length,matrix);
  RenderingHints hints=new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED);
  ConvolveOp gaussianOp1=new ConvolveOp(gaussianBlur1,ConvolveOp.EDGE_NO_OP,hints);
  ConvolveOp gaussianOp2=new ConvolveOp(gaussianBlur2,ConvolveOp.EDGE_NO_OP,hints);
  BufferedImage scratchImage=EffectUtil.getScratchImage();
  for (int i=0; i < blurPasses; i++) {
    gaussianOp1.filter(image,scratchImage);
    gaussianOp2.filter(scratchImage,image);
  }
}
 

Example 4

From project sanselan, under directory /src/main/java/org/apache/commons/imaging/.

Source file: ColorTools.java

  22 
vote

public BufferedImage convertToColorSpace(BufferedImage bi,ColorSpace to){
  ColorSpace from=bi.getColorModel().getColorSpace();
  RenderingHints hints=new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  hints.put(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
  hints.put(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_ENABLE);
  ColorConvertOp op=new ColorConvertOp(from,to,hints);
  BufferedImage result=op.filter(bi,null);
  result=relabelColorSpace(result,to);
  return result;
}
 

Example 5

From project beam-meris-icol, under directory /src/main/java/org/esa/beam/meris/icol/.

Source file: DFTConvolutionOp.java

  21 
vote

@Override public void initialize() throws OperatorException {
  BorderExtender borderExtender=BorderExtender.createInstance(BorderExtender.BORDER_COPY);
  RenderingHints renderingHints=new RenderingHints(JAI.KEY_BORDER_EXTENDER,borderExtender);
  targetProduct=new Product("P","PT",sourceProduct.getSceneRasterWidth(),sourceProduct.getSceneRasterHeight());
  String[] sourceNames=sourceProduct.getBandNames();
  RenderedImage kernelFT=null;
  for (  String name : sourceNames) {
    if (name.startsWith(namePrefix)) {
      Band targetBand=ProductUtils.copyBand(name,sourceProduct,targetProduct,false);
      RenderedImage sourceImage=sourceProduct.getBand(name).getSourceImage();
      RenderedOp targetOp;
      if (useFT) {
        targetOp=DFTConvolveDescriptor.create(sourceImage,kernel,kernelFT,renderingHints);
        kernelFT=(RenderedImage)targetOp.getProperty("kernelFT");
      }
 else {
        targetOp=ConvolveDescriptor.create(sourceImage,kernel,renderingHints);
      }
      targetBand.setSourceImage(targetOp.getRendering());
    }
  }
}
 

Example 6

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

Source file: JAddressTextField.java

  21 
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 7

From project glg2d, under directory /src/main/java/glg2d/.

Source file: GLGraphics2D.java

  21 
vote

protected void resetRenderingHints(){
  hints=new RenderingHints(Collections.<Key,Object>emptyMap());
  for (  G2DDrawingHelper helper : helpers) {
    helper.resetHints();
  }
}
 

Example 8

From project Hphoto, under directory /src/java/com/hphoto/server/.

Source file: VerifyCodeImage.java

  21 
vote

public String saveVerifyImage(int width,int height,OutputStream out) throws IOException {
  GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
  BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED);
  Graphics2D g=(Graphics2D)image.getGraphics();
  g.setColor(new Color(0xFFFFFF));
  g.fillRect(0,0,width,height);
  String word;
  if (this.word == null)   word=getWord(4);
 else   word=this.word;
  float w=(float)(width * 0.9F);
  float h=(float)(height * 0.2F);
  int d=(int)(w / word.length());
  RenderingHints hints=new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  hints.add(new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY));
  g.setRenderingHints(hints);
  Font font=getFont();
  char[] wc=word.toCharArray();
  FontRenderContext frc=g.getFontRenderContext();
  g.setColor(getColor());
  g.setFont(font);
  GlyphVector gv=font.createGlyphVector(frc,wc);
  double charWitdth=gv.getVisualBounds().getWidth();
  int startPosX=(int)(width - charWitdth) / 2;
  g.drawChars(wc,0,wc.length,startPosX,height / 2 + (int)(height * 0.1));
  Captcha ca=captcha[generator.nextInt(captcha.length)];
  ca.setRange(w);
  image=ca.getDistortedImage(image);
  ImageIO.write(image,"JPEG",out);
  return word;
}
 

Example 9

From project iee, under directory /org.eclipse.iee.sample.graph/src/org/jfree/experimental/swt/.

Source file: SWTGraphics2D.java

  21 
vote

/** 
 * Creates a new instance.
 * @param gc  the graphics context.
 */
public SWTGraphics2D(GC gc){
  super();
  this.gc=gc;
  this.hints=new RenderingHints(null);
  this.composite=AlphaComposite.getInstance(AlphaComposite.SRC,1.0f);
}
 

Example 10

From project jgraphx, under directory /src/com/mxgraph/swing/.

Source file: mxGraphComponent.java

  21 
vote

/** 
 */
public void paintComponent(Graphics g){
  super.paintComponent(g);
  paintBackground(g);
  if (tripleBuffered) {
    checkTripleBuffer();
  }
 else   if (tripleBuffer != null) {
    destroyTripleBuffer();
  }
  if (tripleBuffer != null) {
    mxUtils.drawImageClip(g,tripleBuffer,this);
  }
 else {
    Graphics2D g2=(Graphics2D)g;
    RenderingHints tmp=g2.getRenderingHints();
    try {
      mxUtils.setAntiAlias(g2,antiAlias,textAntiAlias);
      drawGraph(g2,true);
    }
  finally {
      g2.setRenderingHints(tmp);
    }
  }
  eventSource.fireEvent(new mxEventObject(mxEvent.PAINT,"g",g));
}
 

Example 11

From project lpped, under directory /src/ccs/.

Source file: CCSystem.java

  21 
vote

public void paintComponent(Graphics g){
  super.paintComponent(g);
  Graphics2D g2d=(Graphics2D)g;
  if (niceGraphics) {
    RenderingHints rh=new RenderingHints(null);
    rh.put(RenderingHints.KEY_ALPHA_INTERPOLATION,RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    rh.put(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    rh.put(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_ENABLE);
    rh.put(RenderingHints.KEY_FRACTIONALMETRICS,RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    rh.put(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    rh.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    rh.put(RenderingHints.KEY_STROKE_CONTROL,RenderingHints.VALUE_STROKE_NORMALIZE);
    rh.put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2d.addRenderingHints(rh);
  }
  for (  CCSPolygon poly : polygons)   drawPolygon(g2d,poly);
  drawAxes(g2d);
  for (  CCSLine line : lines)   drawLine(g2d,line);
  for (  CCSPoint p : points)   drawPoint(g2d,p);
}
 

Example 12

From project mapfish-print, under directory /src/main/java/org/mapfish/print/output/.

Source file: InMemoryJaiMosaicOutputFactory.java

  21 
vote

private void drawImage(OutputStream out,List<? extends RenderedImage> images) throws IOException {
  ParameterBlock pbMosaic=new ParameterBlock();
  float height=0;
  float width=0;
  int i=0;
  for (  RenderedImage source : images) {
    i++;
    LOGGER.debug("Adding page image " + i + " bounds: ["+ 0+ ","+ height+ " "+ source.getWidth()+ ","+ (height + source.getHeight())+ "]");
    ParameterBlock pbTranslate=new ParameterBlock();
    pbTranslate.addSource(source);
    pbTranslate.add(0f);
    pbTranslate.add(height);
    RenderedOp translated=JAI.create("translate",pbTranslate);
    pbMosaic.addSource(translated);
    height+=source.getHeight() + MARGIN;
    if (width < source.getWidth())     width=source.getWidth();
  }
  TileCache cache=JAI.createTileCache((long)(height * width * 400));
  RenderingHints hints=new RenderingHints(JAI.KEY_TILE_CACHE,cache);
  RenderedOp mosaic=JAI.create("mosaic",pbMosaic,hints);
  ImageIO.write(mosaic,format,out);
}
 

Example 13

From project plugin-WoT-staging, under directory /src/plugins/WebOfTrust/introduction/captcha/kaptcha/impl/.

Source file: DefaultBackground.java

  21 
vote

/** 
 * @param baseImage the base image
 * @return an image with a gradient background added to the base image.
 */
public BufferedImage addBackground(BufferedImage baseImage){
  Color colorFrom=getConfig().getBackgroundColorFrom();
  Color colorTo=getConfig().getBackgroundColorTo();
  int width=baseImage.getWidth();
  int height=baseImage.getHeight();
  BufferedImage imageWithBackground=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
  Graphics2D graph=(Graphics2D)imageWithBackground.getGraphics();
  RenderingHints hints=new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
  hints.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY));
  hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION,RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY));
  hints.add(new RenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY));
  graph.setRenderingHints(hints);
  GradientPaint paint=new GradientPaint(0,0,colorFrom,width,height,colorTo);
  graph.setPaint(paint);
  graph.fill(new Rectangle2D.Double(0,0,width,height));
  graph.drawImage(baseImage,0,0,null);
  return imageWithBackground;
}
 

Example 14

From project PhonePledge, under directory /src/phonepledge/server/gui/.

Source file: PledgeDisplayPanel.java

  20 
vote

public PledgeDisplayPanel(){
  CodeSource codeSource=PledgeDisplayPanel.class.getProtectionDomain().getCodeSource();
  File jarFile=null, logoFile=null;
  try {
    jarFile=new File(codeSource.getLocation().toURI().getPath());
    logoFile=new File(jarFile.getParentFile().getAbsolutePath() + "/logo.png");
  }
 catch (  URISyntaxException e1) {
    e1.printStackTrace();
  }
  try {
    if (logoFile != null && logoFile.exists())     logo=ImageIO.read(logoFile);
 else     logo=ImageIO.read(getClass().getResource("pp-logo-large.png"));
  }
 catch (  IOException e) {
    System.err.println("Could not load logo");
    e.printStackTrace();
  }
  tickerLabel=new TickerLabel();
  tickerLabel.setVisible(true);
  slidePane=new SlidePane();
  slidePane.setVisible(false);
  pledgePane=new PledgePane();
  readProperties();
  idleTimer=new Timer(idleTimeout,new IdleTimeout());
  idleTimer.start();
  setBackground(backgroundColor);
  setForeground(Color.black);
  setLayout(null);
  renderHints=new RenderingHints(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  renderHints.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  addComponentListener(this);
  add(tickerLabel);
  add(pledgePane);
  add(slidePane);
  addMouseListener(this);
}
 

Example 15

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

Source file: ForestPlot.java

  19 
vote

@Override public void paint(Graphics g){
  d_g2d=(Graphics2D)g;
  d_g2d.translate(PADDING,PADDING);
  d_g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  drawVerticalCenterString(d_g2d,"Study",1,Align.LEFT,FULLROW * 0);
  drawVerticalCenterString(d_g2d,"Relative Effect (95% CI)",FULLWIDTH,Align.RIGHT,FULLROW * 0);
  d_g2d.drawRect(1,ROWHEIGHT,FULLWIDTH,1);
  for (int i=0; i < d_pm.getNumRelativeEffects(); ++i) {
    drawVerticalCenterString(d_g2d,d_pm.getStudyLabelAt(i),1,Align.LEFT,FULLROW * (i + 1));
    drawVerticalCenterString(d_g2d,d_pm.getCIlabelAt(i),FULLWIDTH,Align.RIGHT,FULLROW * (i + 1));
  }
  d_g2d.translate(STUDYWIDTH,FULLROW);
  for (int i=0; i < d_bars.size(); ++i) {
    if (d_pm.getRelativeEffectAt(i).isDefined())     d_bars.get(i).paint(d_g2d);
  }
  paintAxis(d_g2d);
}
 

Example 16

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

Source file: Util.java

  19 
vote

public static Image getBanner(final String text){
  final int w=400;
  final int h=60;
  final float loginStringX=w * .05f;
  final float loginStringY=h * .75f;
  final BufferedImage img=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
  final Graphics2D g2=img.createGraphics();
  final Font font=new Font("Arial Bold",Font.PLAIN,36);
  g2.setFont(font);
  final Graphics2D originalGraphics=g2;
  g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  g2.setColor(Color.GRAY);
  g2.fillRect(0,0,w,h);
  final GeneralPath curveShape=new GeneralPath(GeneralPath.WIND_NON_ZERO);
  curveShape.moveTo(0,h * .6f);
  curveShape.curveTo(w * .167f,h * 1.2f,w * .667f,h * -.5f,w,h * .75f);
  curveShape.lineTo(w,h);
  curveShape.lineTo(0,h);
  curveShape.lineTo(0,h * .8f);
  curveShape.closePath();
  final GradientPaint gp=new GradientPaint(0,h,Color.GRAY,0,0,Color.LIGHT_GRAY);
  g2.setPaint(gp);
  g2.fill(curveShape);
  originalGraphics.setColor(Color.WHITE);
  originalGraphics.drawString(text,loginStringX,loginStringY);
  return img;
}
 

Example 17

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

Source file: View.java

  19 
vote

public void setGraphics(Graphics2D g,int W,int H){
  this.g=g;
  this.W=W;
  this.H=H;
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  resetView();
}
 

Example 18

From project beam-third-party, under directory /mssl-stereomatcher/src/main/java/uk/ac/ucl/mssl/climatephysics/imaging/.

Source file: SqrtCRIF.java

  19 
vote

/** 
 * Creates a new instance of SubsampleOpImage in the rendered layer. This method satisfies the implementation of RIF.
 * @param paramBlock  The source image, the X and Y scale factors.
 * @param renderHints The hints possible including <code>ImageLayout</code>,<code>TileCache</code>, and <code>BorderExtender</code>.
 */
public RenderedImage create(ParameterBlock paramBlock,RenderingHints renderHints){
  RenderedImage source=paramBlock.getRenderedSource(0);
  ImageLayout layout=new ImageLayout();
  ComponentSampleModel sourceModel=(ComponentSampleModel)source.getSampleModel();
  SampleModel doubleModel=new ComponentSampleModel(DataBuffer.TYPE_DOUBLE,sourceModel.getWidth(),sourceModel.getHeight(),sourceModel.getPixelStride(),sourceModel.getScanlineStride(),sourceModel.getBandOffsets());
  layout.setSampleModel(doubleModel);
  return new SqrtOpImage(source,layout);
}
 

Example 19

From project Calendar-Application, under directory /calendar/.

Source file: CalendarPanel.java

  19 
vote

/** 
 * Constructor for CalendarPanel, the main Panel of the application
 * @param parent The parent frame
 */
public CalendarPanel(Calindrom parent){
  m_parent=parent;
  m_view=CalendarPanel.MONTH_VIEW;
  setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
  m_left_panel=new JPanel(){
    @Override protected void paintComponent(    Graphics grphcs){
      Graphics2D g2d=(Graphics2D)grphcs;
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
      GradientPaint gp=new GradientPaint(0,0,Calindrom.gray_yellow,0,getHeight(),Calindrom.gray);
      g2d.setPaint(gp);
      g2d.fillRect(0,0,getWidth(),getHeight());
      super.paintComponent(grphcs);
    }
  }
;
  m_left_panel.setOpaque(false);
  m_left_panel.setPreferredSize(new Dimension(CalendarPanel.LEFT_WIDTH,Integer.MAX_VALUE));
  m_left_panel.setMaximumSize(new Dimension(CalendarPanel.LEFT_WIDTH,Integer.MAX_VALUE));
  InitLeftPanel();
  m_right_panel=new MonthView(this);
  m_left_panel.setBorder(new MatteBorder(0,0,0,2,Color.black));
  m_right_panel.setBorder(new MatteBorder(0,1,0,0,Color.gray));
  add(m_left_panel);
  add(m_right_panel);
}
 

Example 20

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

Source file: ImageWatermark.java

  19 
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.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,imageOpacity));
  graphics.drawImage(overlayImage,bi.getWidth() - overlayImage.getWidth(),bi.getHeight() - overlayImage.getHeight(),null);
  if (msg != null) {
    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,fontOpacity));
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setColor(color);
    graphics.setFont(new Font(fontName,Font.PLAIN,fontSize));
    graphics.drawString(msg,10,bi.getHeight() - 10);
  }
  graphics.dispose();
  return bi;
}
 

Example 21

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

Source file: BaseImage.java

  19 
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 22

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

Source file: DefaultDisplay.java

  19 
vote

/** 
 * Paint a horizontally and vertically-centered text string.
 * @param g2 drawing surface
 * @param s string to draw (centered)
 * @param rect the bounding rectangle
 * @param fontHeight the desired height of the font. (The font will beshrunk in increments of sqrt(2)/2 if the text is too large.)
 * @param color the color in which to draw the text
 */
protected void paintCenteredText(Graphics2D g2,String s,Rectangle rect,double fontHeight,Color color){
  g2=(Graphics2D)g2.create();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setPaint(color);
  Rectangle2D bounds=null;
  LineMetrics lm=null;
  boolean done=false;
  while (!done) {
    g2.setFont(new Font("SansSerif",Font.BOLD,(int)(fontHeight * rect.height)));
    FontRenderContext frc=g2.getFontRenderContext();
    bounds=g2.getFont().getStringBounds(s,frc);
    if (bounds.getWidth() > rect.getWidth())     fontHeight=fontHeight * Math.sqrt(2) / 2;
 else {
      done=true;
      lm=g2.getFont().getLineMetrics(s,frc);
    }
  }
  float centerX=rect.x + rect.width / 2;
  float centerY=rect.y + rect.height / 2;
  float leftX=centerX - (float)bounds.getWidth() / 2;
  float baselineY=centerY - lm.getHeight() / 2 + lm.getAscent();
  g2.drawString(s,leftX,baselineY);
  g2.dispose();
}
 

Example 23

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

Source file: Util.java

  19 
vote

public static boolean createTimeBar(Module br,String fn,int w,long ts0,long ts1){
  int h=75;
  BufferedImage img=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
  Graphics2D g=(Graphics2D)img.getGraphics();
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g.setColor(Color.WHITE);
  g.fillRect(0,0,w,h);
  g.setColor(Color.BLACK);
  g.drawLine(0,h - 1,w,h - 1);
  if (!renderTimeBar(img,g,0,0,w,h,ts0,ts1,false)) {
    return false;
  }
  try {
    ImageIO.write(img,"png",new File(br.getBaseDir() + fn));
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return true;
}
 

Example 24

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

Source file: BaseGradient.java

  19 
vote

public void paint(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);
  paintGradient(graphics2d,getDimension());
}
 

Example 25

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

Source file: ImageProcessingServiceImpl.java

  19 
vote

public BufferedImage createCroppedImage(BufferedImage img,int chosenWidth,int chosenHeight){
  int topX=0;
  int topY=0;
  int newWidth=0;
  int newHeight=0;
  double factor=0;
  double scaleHorizontalFactor=getScaleFactor(chosenWidth,img.getWidth());
  double scaleVerticalFactor=getScaleFactor(chosenHeight,img.getHeight());
  if (scaleVerticalFactor > scaleHorizontalFactor) {
    factor=scaleVerticalFactor;
    newWidth=(int)Math.round(img.getWidth() * factor);
    newHeight=(int)Math.round(img.getHeight() * factor);
    topX=(int)Math.round((newWidth - chosenWidth) / 2);
  }
 else {
    factor=scaleHorizontalFactor;
    newWidth=(int)Math.round(img.getWidth() * factor);
    newHeight=(int)Math.round(img.getHeight() * factor);
    topY=(int)Math.round((newHeight - chosenHeight) / 2);
  }
  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(img,0,0,newWidth,newHeight,null);
  BufferedImage croppedImage=scaledImage.getSubimage(topX,topY,chosenWidth,chosenHeight);
  BufferedImage imageBuf=new BufferedImage(chosenWidth,chosenHeight,BufferedImage.TYPE_INT_RGB);
  Graphics2D newImage=imageBuf.createGraphics();
  newImage.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
  newImage.drawImage(croppedImage,0,0,chosenWidth,chosenHeight,null);
  return imageBuf;
}
 

Example 26

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

Source file: GLFont.java

  19 
vote

/** 
 * return a BufferedImage containing the given character drawn with the given font. Character will be drawn on its baseline, and centered horizontally in the image.
 * @param text a single character to render
 * @param font the font to render with
 * @param fgColor foreground (text) color as rgb or rgba values in range 0-1
 * @param bgColor background color as rgb or rgba values in range 0-1 (set alpha to 0 to make transparent)
 * @return
 */
public static BufferedImage createCharImage(String text,Font font,float[] fgColor,float[] bgColor){
  Color bg=bgColor == null ? new Color(0,0,0,0) : (bgColor.length == 3 ? new Color(bgColor[0],bgColor[1],bgColor[2],1) : new Color(bgColor[0],bgColor[1],bgColor[2],bgColor[3]));
  Color fg=fgColor == null ? new Color(1,1,1,1) : (fgColor.length == 3 ? new Color(fgColor[0],fgColor[1],fgColor[2],1) : new Color(fgColor[0],fgColor[1],fgColor[2],fgColor[3]));
  boolean isAntiAliased=true;
  boolean usesFractionalMetrics=false;
  int maxCharSize=getFontSize(font);
  int imgSize=MathHelper.getPowerOfTwoBiggerThan(maxCharSize);
  if (imgSize > 2048) {
    throw new RuntimeException("GLFont.createCharImage(): texture size will be too big (" + imgSize + ") Make the font size smaller.");
  }
  BufferedImage image=new BufferedImage(imgSize,imgSize,BufferedImage.TYPE_INT_ARGB);
  Graphics2D g=image.createGraphics();
  if (bg.getAlpha() < 255) {
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR,(float)bg.getAlpha() / 255f));
  }
  g.setColor(bg);
  g.fillRect(0,0,imgSize,imgSize);
  g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f));
  g.setColor(fg);
  g.setFont(font);
  g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,isAntiAliased ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
  g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,usesFractionalMetrics ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
  g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  FontMetrics fm=g.getFontMetrics();
  int cwidth=fm.charWidth(text.charAt(0));
  int height=fm.getHeight();
  int ascent=fm.getAscent();
  int vborder=(int)((float)(imgSize - height) / 2f);
  int hborder=(int)((float)(imgSize - cwidth) / 2f);
  g.drawString(text,hborder,vborder + ascent);
  g.dispose();
  return image;
}
 

Example 27

From project dawn-common, under directory /org.dawb.hdf5/src/ncsa/hdf/view/.

Source file: DefaultImageView.java

  19 
vote

public void paint(Graphics g){
  if (g instanceof Graphics2D && (zoomFactor < 0.99)) {
    Graphics2D g2=(Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    Image scaledImg=multiBiliner(image,imageSize.width,imageSize.height,true);
    g2.drawImage(scaledImg,0,0,imageSize.width,imageSize.height,this);
  }
 else   g.drawImage(image,0,0,imageSize.width,imageSize.height,this);
  if ((selectedArea.width > 0) && (selectedArea.height > 0)) {
    g.setColor(Color.red);
    g.drawRect(selectedArea.x,selectedArea.y,selectedArea.width,selectedArea.height);
  }
}
 

Example 28

From project en4j, under directory /NBPlatformApp/Synchronization/src/main/java/com/rubenlaguna/en4j/sync/.

Source file: GraphicsUtilities.java

  19 
vote

/** 
 * <p>Returns a thumbnail of a source image. <code>newSize</code> defines the length of the longest dimension of the thumbnail. The other dimension is then computed according to the dimensions ratio of the original picture.</p> <p>This method favors speed over quality. When the new size is less than half the longest dimension of the source image, {@link #createThumbnail(BufferedImage,int)} or{@link #createThumbnail(BufferedImage,int,int)} should be used insteadto ensure the quality of the result without sacrificing too much performance.</p>
 * @see #createThumbnailFast(java.awt.image.BufferedImage,int,int)
 * @see #createThumbnail(java.awt.image.BufferedImage,int)
 * @see #createThumbnail(java.awt.image.BufferedImage,int,int)
 * @param image the source image
 * @param newSize the length of the largest dimension of the thumbnail
 * @return a new compatible <code>BufferedImage</code> containing athumbnail of <code>image</code>
 * @throws IllegalArgumentException if <code>newSize</code> is larger thanthe largest dimension of <code>image</code> or &lt;= 0
 */
public static BufferedImage createThumbnailFast(BufferedImage image,int newSize){
  float ratio;
  int width=image.getWidth();
  int height=image.getHeight();
  if (width > height) {
    if (newSize >= width) {
      throw new IllegalArgumentException("newSize must be lower than" + " the image width");
    }
 else     if (newSize <= 0) {
      throw new IllegalArgumentException("newSize must" + " be greater than 0");
    }
    ratio=(float)width / (float)height;
    width=newSize;
    height=(int)(newSize / ratio);
  }
 else {
    if (newSize >= height) {
      throw new IllegalArgumentException("newSize must be lower than" + " the image height");
    }
 else     if (newSize <= 0) {
      throw new IllegalArgumentException("newSize must" + " be greater than 0");
    }
    ratio=(float)height / (float)width;
    height=newSize;
    width=(int)(newSize / ratio);
  }
  BufferedImage temp=createCompatibleImage(image,width,height);
  Graphics2D g2=temp.createGraphics();
  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2.drawImage(image,0,0,temp.getWidth(),temp.getHeight(),null);
  g2.dispose();
  return temp;
}
 

Example 29

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

Source file: AppGraphics.java

  19 
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);
  }
}
 

Example 30

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

Source file: DefaultImageResizer.java

  19 
vote

@Override public void saveResizedImage(ImageIcon imageIcon,String filePath,ImageResourceDimension dimension) throws ApsSystemException {
  Image image=imageIcon.getImage();
  double scale=this.computeScale(image.getWidth(null),image.getHeight(null),dimension.getDimx(),dimension.getDimy());
  int scaledW=(int)(scale * image.getWidth(null));
  int scaledH=(int)(scale * image.getHeight(null));
  BufferedImage outImage=new BufferedImage(scaledW,scaledH,BufferedImage.TYPE_INT_RGB);
  AffineTransform tx=new AffineTransform();
  tx.scale(scale,scale);
  Graphics2D g2d=outImage.createGraphics();
  g2d.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.drawImage(image,tx,null);
  g2d.dispose();
  try {
    File file=new File(filePath);
    ImageIO.write(outImage,this.getFileExtension(filePath),file);
  }
 catch (  Throwable t) {
    String msg=this.getClass().getName() + ": saveImageResized: " + t.toString();
    ApsSystemUtils.getLogger().throwing(this.getClass().getName(),"saveImageResized",t);
    throw new ApsSystemException(msg,t);
  }
}
 

Example 31

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

Source file: JPanelRoundedCorners.java

  19 
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 32

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

Source file: ListItemPainter.java

  19 
vote

private static void drawGlyph(RenderingContext c,BlockBox box,CalculatedStyle style,IdentValue listStyle){
  Object aa_key=c.getOutputDevice().getRenderingHint(RenderingHints.KEY_ANTIALIASING);
  c.getOutputDevice().setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  StrutMetrics strutMetrics=box.getMarkerData().getStructMetrics();
  MarkerData.GlyphMarker marker=box.getMarkerData().getGlyphMarker();
  int x=getReferenceX(c,box);
  x+=-marker.getLayoutWidth();
  int y=getReferenceBaseline(c,box) - (int)strutMetrics.getAscent() / 2 - marker.getDiameter() / 2;
  if (listStyle == IdentValue.DISC) {
    c.getOutputDevice().fillOval(x,y,marker.getDiameter(),marker.getDiameter());
  }
 else   if (listStyle == IdentValue.SQUARE) {
    c.getOutputDevice().fillRect(x,y,marker.getDiameter(),marker.getDiameter());
  }
 else   if (listStyle == IdentValue.CIRCLE) {
    c.getOutputDevice().drawOval(x,y,marker.getDiameter(),marker.getDiameter());
  }
  c.getOutputDevice().setRenderingHint(RenderingHints.KEY_ANTIALIASING,aa_key == null ? RenderingHints.VALUE_ANTIALIAS_DEFAULT : aa_key);
}
 

Example 33

From project formic, under directory /src/java/net/java/swingfx/waitwithstyle/.

Source file: SingleComponentInfiniteProgress.java

  19 
vote

protected double paintBars(final Graphics g,final boolean paintBackground){
  Rectangle oClip=g.getClipBounds();
  if (paintBackground) {
    if (imageBuf != null) {
      g.drawImage(imageBuf,oClip.x,oClip.y,oClip.x + oClip.width,oClip.y + oClip.height,oClip.x,oClip.y,oClip.x + oClip.width,oClip.y + oClip.height,null);
      g.drawImage(imageBuf,0,0,null);
    }
 else {
      Color color=getBackground();
      g.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),200));
      g.fillRect(oClip.x,oClip.y,oClip.width,oClip.height);
    }
  }
  Graphics2D g2=(Graphics2D)g.create();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.transform(centerAndScaleTransform);
  if (colors[0] == null) {
    for (int i=0; i < bars.length; i++) {
      int re=Math.abs(getBackground().getRed() - 128 / (i + 1));
      int gr=Math.abs(getBackground().getGreen() - 128 / (i + 1));
      int bl=Math.abs(getBackground().getBlue() - 128 / (i + 1));
      colors[i]=new Color(re,gr,bl);
      colors[numBars + i]=colors[i];
    }
  }
  for (int i=0; i < bars.length; i++) {
    g2.setColor(colors[i + colorOffset]);
    g2.fill(bars[i]);
  }
  double maxY=drawTextAt(text,getFont(),(Graphics2D)g,getWidth(),barsScreenBounds.getMaxY(),getForeground());
  return maxY;
}
 

Example 34

From project freemind, under directory /freemind/freemind/view/mindmapview/.

Source file: MapView.java

  19 
vote

/** 
 * P A I N T I N G 
 */
public void paint(Graphics g){
  long startMilli=System.currentTimeMillis();
  if (isValid()) {
    getRoot().getContent().getLocation(rootContentLocation);
    Tools.convertPointToAncestor(getRoot(),rootContentLocation,getParent());
  }
  final Graphics2D g2=(Graphics2D)g;
  final Object renderingHint=g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
  final Object renderingTextHint=g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
  getController().setTextRenderingHint(g2);
  final Object oldRenderingHintFM=g2.getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS);
  final Object newRenderingHintFM=getZoom() != 1F ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF;
  if (oldRenderingHintFM != newRenderingHintFM) {
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,newRenderingHintFM);
  }
  super.paint(g);
  if (oldRenderingHintFM != newRenderingHintFM && RenderingHints.KEY_FRACTIONALMETRICS.isCompatibleValue(oldRenderingHintFM)) {
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,oldRenderingHintFM);
  }
  if (RenderingHints.KEY_ANTIALIASING.isCompatibleValue(renderingHint)) {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,renderingHint);
  }
  if (RenderingHints.KEY_TEXT_ANTIALIASING.isCompatibleValue(renderingTextHint)) {
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,renderingTextHint);
  }
  long localTime=System.currentTimeMillis() - startMilli;
  mPaintingAmount++;
  mPaintingTime+=localTime;
  logger.fine("End paint of " + getModel().getRestorable() + " in "+ localTime+ ". Mean time:"+ (mPaintingTime / mPaintingAmount));
}
 

Example 35

From project FScape, under directory /src/main/java/de/sciss/fscape/gui/.

Source file: OpConnector.java

  19 
vote

/** 
 * Zeichnet den Pfeil zwischen den zum Connector gehoerenden Icons; nimmt dazu getParent().getGraphics();
 * @param mode	false, um statt mit schwarz zu zeichnen, den Pfeil zu loeschen
 */
public void drawArrow(boolean mode){
  final Container c=getParent();
  Graphics2D g;
  Point tempP;
  if (c != null) {
    g=(Graphics2D)c.getGraphics();
    if (g != null) {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(mode ? Color.black : c.getBackground());
      if (isVisible()) {
        g.drawLine(srcP.x,srcP.y,thisP.x,thisP.y);
        drawArrow(g,thisP.x,thisP.y,destP.x,destP.y,mode);
      }
 else {
        drawArrow(g,srcP.x,srcP.y,destP.x,destP.y,mode);
      }
      g.dispose();
    }
    g=(Graphics2D)srcIcon.getGraphics();
    if (g != null) {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
      tempP=isVisible() ? thisP : destP;
      g.setColor(mode ? Color.black : c.getBackground());
      g.drawLine(srcP.x - srcLoc.x,srcP.y - srcLoc.y,tempP.x - srcLoc.x,tempP.y - srcLoc.y);
      g.dispose();
    }
    g=(Graphics2D)destIcon.getGraphics();
    if (g != null) {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
      tempP=isVisible() ? thisP : srcP;
      g.setColor(mode ? Color.black : c.getBackground());
      drawArrow(g,tempP.x - destLoc.x,tempP.y - destLoc.y,destP.x - destLoc.x,destP.y - destLoc.y,mode);
      g.dispose();
      if (!mode)       destIcon.repaint();
    }
  }
}
 

Example 36

From project GAIL, under directory /src/gail/utils/.

Source file: PresentationScreen.java

  19 
vote

@Override protected void paintComponent(Graphics g){
  Graphics2D g2=(Graphics2D)g;
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,opacity));
  g2.setColor(getBackground());
  g2.fillRect(0,0,getWidth(),getHeight());
  g2.drawImage(logo,(attachedFrame.getWidth() / 2) - (logo.getWidth() / 2),topMargin,null);
}
 

Example 37

From project Game_3, under directory /java/src/playn/java/.

Source file: JavaCanvasImage.java

  19 
vote

JavaCanvasImage(GLContext ctx,float width,float height){
  super(ctx,new BufferedImage(ctx.scale.scaledCeil(width),ctx.scale.scaledCeil(height),BufferedImage.TYPE_INT_ARGB),ctx.scale);
  Graphics2D gfx=img.createGraphics();
  gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  gfx.scale(ctx.scale.factor,ctx.scale.factor);
  canvas=new JavaCanvas(gfx,width(),height());
}
 

Example 38

From project Gmote, under directory /gmoteserver/src/org/gmote/server/.

Source file: GmoteHttpServer.java

  19 
vote

private void sendImage(File originalImagePath,BufferedOutputStream dataOut) throws InterruptedException, ImageFormatException, IOException {
  LOGGER.info("Converting image to smaller scale");
  Image image=Toolkit.getDefaultToolkit().getImage(originalImagePath.getAbsolutePath());
  MediaTracker mediaTracker=new MediaTracker(new Container());
  mediaTracker.addImage(image,0);
  mediaTracker.waitForID(0);
  int imageWidth=image.getWidth(null);
  int imageHeight=image.getHeight(null);
  int thumbWidth=imageWidth;
  int thumbHeight=imageHeight;
  int MAX_SIZE=500;
  if (imageWidth > MAX_SIZE || imageHeight > MAX_SIZE) {
    double imageRatio=(double)imageWidth / (double)imageHeight;
    if (imageWidth > imageHeight) {
      thumbWidth=MAX_SIZE;
      thumbHeight=(int)(thumbWidth / imageRatio);
    }
 else {
      thumbHeight=MAX_SIZE;
      thumbWidth=(int)(thumbHeight * imageRatio);
    }
  }
  BufferedImage thumbImage;
  thumbImage=new BufferedImage(thumbWidth,thumbHeight,BufferedImage.TYPE_INT_RGB);
  Graphics2D graphics2D=thumbImage.createGraphics();
  graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  graphics2D.drawImage(image,0,0,thumbWidth,thumbHeight,null);
  if (PlatformUtil.isLinux()) {
    ImageIO.write(thumbImage,"JPEG",dataOut);
  }
 else {
    JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(dataOut);
    JPEGEncodeParam param=encoder.getDefaultJPEGEncodeParam(thumbImage);
    float quality=80;
    param.setQuality(quality / 100.0f,false);
    encoder.encode(thumbImage,param);
  }
  dataOut.close();
  LOGGER.info("Done sending image");
}
 

Example 39

From project gs-core, under directory /src/org/graphstream/ui/swingViewer/basicRenderer/.

Source file: SwingBasicGraphRenderer.java

  19 
vote

protected void setupGraphics(Graphics2D g){
  if (graph.hasAttribute("ui.antialias")) {
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,RenderingHints.VALUE_STROKE_PURE);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  }
 else {
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,RenderingHints.VALUE_STROKE_DEFAULT);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
  }
  if (graph.hasAttribute("ui.quality")) {
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_SPEED);
    g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
  }
 else {
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
  }
}
 

Example 40

From project gs-tool, under directory /src/org/graphstream/tool/gui/.

Source file: OptionSetter.java

  19 
vote

protected void paintComponent(Graphics g){
  int s=labelWidth + 10;
  int width=getWidth() - 1;
  if (g instanceof Graphics2D) {
    Graphics2D g2d=(Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  }
  g.setColor(Resources.getColor(ColorType.COMPONENT_LABEL_BACKGROUND));
  g.fillRoundRect(0,0,14,getHeight() - 1,7,7);
  g.fillRect(7,0,s - 7,getHeight() - 1);
  g.setColor(Resources.getColor(ColorType.COMPONENT_BACKGROUND));
  g.fillRect(s,0,width - 7 - s,getHeight() - 1);
  g.fillRoundRect(width - 14,0,14,getHeight() - 1,7,7);
  g.setColor(Resources.getColor(ColorType.COMPONENT_BORDER));
  g.drawRoundRect(0,0,width,getHeight() - 1,7,7);
}
 

Example 41

From project Haven-and-Hearth-client-modified-by-Ender, under directory /src/ender/.

Source file: HLInfo.java

  19 
vote

public Tex geticon(){
  if (icon == null) {
    BufferedImage img;
    if (icnname != null) {
      img=Resource.loadimg(icnname);
    }
 else {
      img=Resource.loadimg(name);
    }
    BufferedImage icnimg=new BufferedImage(20,20,BufferedImage.TYPE_INT_ARGB);
    Graphics2D g=icnimg.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setColor(col);
    g.fillOval(0,0,icnimg.getWidth() - 1,icnimg.getHeight() - 1);
    g.setColor(Color.DARK_GRAY);
    g.drawOval(0,0,icnimg.getWidth() - 1,icnimg.getHeight() - 1);
    Coord isz=Utils.imgsz(img);
    isz=isz.mul(16.0 / Math.max(16,Math.max(isz.x,isz.y)));
    g.drawImage(img,10 - isz.x / 2,10 - isz.y / 2,isz.x,isz.y,null);
    icon=new TexI(icnimg);
  }
  return icon;
}
 

Example 42

From project imageflow, under directory /src/de/danielsenff/imageflow/gui/.

Source file: BICanvas.java

  19 
vote

private void drawImage(Graphics g){
  int width=biRendered.getWidth(null), height=biRendered.getHeight(null);
  int newW=(int)(zoomFactor * width);
  int newH=(int)(zoomFactor * height);
  int offsetX=(int)((0.5 * g.getClipBounds().getWidth()) - (0.5 * newW));
  int offsetY=(int)((0.5 * g.getClipBounds().getHeight()) - (0.5 * newH));
  int moveX=0;
  int moveY=0;
  offsetX=0;
  offsetY=0;
  g.setColor(Color.WHITE);
  g.fillRect(0,0,width,height);
  ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
  g.drawImage(biRendered,offsetX,offsetY,newW + offsetX,newH + offsetY,moveX,moveY,biRendered.getWidth(null),biRendered.getHeight(null),null);
}
 

Example 43

From project imgscalr, under directory /src/main/java/org/imgscalr/.

Source file: Scalr.java

  19 
vote

/** 
 * Used to implement a straight-forward image-scaling operation using Java 2D. <p/> This method uses the Oracle-encouraged method of <code>Graphics2D.drawImage(...)</code> to scale the given image with the given interpolation hint.
 * @param src The image that will be scaled.
 * @param targetWidth The target width for the scaled image.
 * @param targetHeight The target height for the scaled image.
 * @param interpolationHintValue The  {@link RenderingHints} interpolation value used toindicate the method that  {@link Graphics2D} should use whenscaling the image.
 * @return the result of scaling the original <code>src</code> to the givendimensions using the given interpolation method.
 */
protected static BufferedImage scaleImage(BufferedImage src,int targetWidth,int targetHeight,Object interpolationHintValue){
  BufferedImage result=createOptimalImage(src,targetWidth,targetHeight);
  Graphics2D resultGraphics=result.createGraphics();
  resultGraphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,interpolationHintValue);
  resultGraphics.drawImage(src,0,0,targetWidth,targetHeight,null);
  resultGraphics.dispose();
  return result;
}
 

Example 44

From project james-mime4j, under directory /examples/src/main/java/org/apache/james/mime4j/samples/dom/.

Source file: MultipartMessage.java

  19 
vote

/** 
 * Draws an image; unrelated to Mime4j.
 */
private static BufferedImage renderSampleImage(){
  System.setProperty("java.awt.headless","true");
  final int size=100;
  BufferedImage img=new BufferedImage(size,size,BufferedImage.TYPE_BYTE_GRAY);
  Graphics2D gfx=img.createGraphics();
  gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  gfx.setStroke(new BasicStroke(size / 40f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
  gfx.setColor(Color.BLACK);
  gfx.setBackground(Color.WHITE);
  gfx.clearRect(0,0,size,size);
  int b=size / 30;
  gfx.drawOval(b,b,size - 1 - 2 * b,size - 1 - 2 * b);
  int esz=size / 7;
  int ex=(int)(0.27f * size);
  gfx.drawOval(ex,ex,esz,esz);
  gfx.drawOval(size - 1 - esz- ex,ex,esz,esz);
  b=size / 5;
  gfx.drawArc(b,b,size - 1 - 2 * b,size - 1 - 2 * b,200,140);
  return img;
}
 

Example 45

From project jAPS2, under directory /src/com/agiletec/plugins/jacms/aps/system/services/resource/model/imageresizer/.

Source file: DefaultImageResizer.java

  19 
vote

@Override public void saveResizedImage(ImageIcon imageIcon,String filePath,ImageResourceDimension dimension) throws ApsSystemException {
  Image image=imageIcon.getImage();
  double scale=this.computeScale(image.getWidth(null),image.getHeight(null),dimension.getDimx(),dimension.getDimy());
  int scaledW=(int)(scale * image.getWidth(null));
  int scaledH=(int)(scale * image.getHeight(null));
  BufferedImage outImage=new BufferedImage(scaledW,scaledH,BufferedImage.TYPE_INT_RGB);
  AffineTransform tx=new AffineTransform();
  tx.scale(scale,scale);
  Graphics2D g2d=outImage.createGraphics();
  g2d.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
  g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.drawImage(image,tx,null);
  g2d.dispose();
  try {
    File file=new File(filePath);
    ImageIO.write(outImage,this.getFileExtension(filePath),file);
  }
 catch (  Throwable t) {
    String msg=this.getClass().getName() + ": saveImageResized: " + t.toString();
    ApsSystemUtils.getLogger().throwing(this.getClass().getName(),"saveImageResized",t);
    throw new ApsSystemException(msg,t);
  }
}
 

Example 46

From project jbpm-plugin, under directory /jbpm/src/main/java/hudson/jbpm/rendering/.

Source file: ProcessInstanceRenderer.java

  19 
vote

public void paintTask(Graphics2D g2,Node node,Rectangle2D.Double rect){
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  Color nodeColor=getNodeColor(node);
  g2.setPaint(new GradientPaint(new Point2D.Double(rect.x,rect.y),nodeColor,new Point2D.Double(rect.x,rect.y + rect.height),NODE_COLOR_2));
  g2.fill(rect);
  g2.setPaint(LINE_COLOR);
  g2.draw(rect);
  double imageY=rect.y + rect.height / 2 - 16 / 2;
  Image image=GraphicsUtil.getImage(node);
  if (image != null) {
    int w=image.getWidth(null);
    int h=image.getHeight(null);
    g2.drawImage(image,(int)rect.x + 8,(int)imageY,(int)rect.x + 8 + w,(int)imageY + h,0,0,w,h,this);
  }
  int textWidth=g2.getFontMetrics().stringWidth(node.getName());
  int textHeight=g2.getFontMetrics().getAscent();
  g2.setColor(TEXT_COLOR);
  g2.setFont(FONT);
  g2.drawString(node.getName(),(int)(rect.x + 12 + (rect.width - textWidth) / 2),(int)(rect.y + (rect.height + textHeight) / 2));
}
 

Example 47

From project jchempaint, under directory /src/main/org/openscience/jchempaint/renderer/visitor/.

Source file: AWTDrawVisitor.java

  19 
vote

public void setRendererModel(RendererModel rendererModel){
  this.rendererModel=rendererModel;
  if (rendererModel.getUseAntiAliasing()) {
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  }
}
 

Example 48

From project jflow, under directory /src/be/pwnt/jflow/shape/.

Source file: Picture.java

  19 
vote

private void setHighQuality(boolean on,Graphics2D g){
  if (on) {
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  }
 else {
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
  }
}
 

Example 49

From project JMaNGOS, under directory /Tools/src/main/java/org/jmangos/tools/openGL/.

Source file: FontTT.java

  19 
vote

private BufferedImage getFontImage(final char ch){
  Font tempfont;
  tempfont=this.font.deriveFont((float)this.fontsize);
  final BufferedImage tempfontImage=new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
  final Graphics2D g=(Graphics2D)tempfontImage.getGraphics();
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g.setFont(tempfont);
  final FontMetrics fm=g.getFontMetrics();
  int charwidth=fm.charWidth(ch);
  if (charwidth <= 0) {
    charwidth=1;
  }
  int charheight=fm.getHeight();
  if (charheight <= 0) {
    charheight=this.fontsize;
  }
  BufferedImage fontImage;
  fontImage=new BufferedImage(charwidth,charheight,BufferedImage.TYPE_INT_ARGB);
  final Graphics2D gt=(Graphics2D)fontImage.getGraphics();
  gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  gt.setFont(tempfont);
  gt.setColor(Color.WHITE);
  final int charx=0;
  final int chary=0;
  gt.drawString(String.valueOf(ch),(charx),(chary) + fm.getAscent());
  return fontImage;
}
 

Example 50

From project jMemorize, under directory /src/jmemorize/gui/swing/panels/.

Source file: CardSidePanel.java

  19 
vote

@Override protected void paintComponent(Graphics g){
  super.paintComponent(g);
  if (m_image == null)   return;
  int imgWidth=m_image.getWidth(null);
  int imgHeight=m_image.getHeight(null);
  Dimension dimension=getSize();
  int w=dimension.width;
  int h=dimension.height;
  int padding=0;
  if (imgWidth > w || imgHeight > h) {
    float ratio=imgWidth / (float)w;
    h=(int)(imgHeight / ratio);
    if (h > dimension.height) {
      h=dimension.height;
      ratio=imgHeight / (float)h;
      w=(int)(imgWidth / ratio);
    }
    padding=m_padding;
  }
 else {
    w=imgWidth;
    h=imgHeight;
  }
  int left=padding + (dimension.width - w) / 2;
  int top=padding + (dimension.height - h) / 2;
  if (g instanceof Graphics2D) {
    Graphics2D g2d=(Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
  }
  g.drawImage(m_image,left,top,left + w - 2 * padding,top + h - 2 * padding,0,0,imgWidth,imgHeight,null);
}
 

Example 51

From project LateralGM, under directory /org/lateralgm/components/visual/.

Source file: PathEditor.java

  19 
vote

public void paint(Graphics g){
  Graphics2D g2=(Graphics2D)g;
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setColor(Color.BLACK);
  g2.setStroke(STROKE_OUTER);
  g2.drawLine(px0,py0,px1,py1);
  g2.setColor(Color.WHITE);
  g2.setStroke(STROKE_INNER);
  g2.drawLine(px0,py0,px1,py1);
}
 

Example 52

From project Longan, under directory /src/com/zarkonnen/longan/better/.

Source file: RotationFixingPreProcessor.java

  19 
vote

public BufferedImage process(BufferedImage img,HashMap<String,String> metadata){
  if (!metadata.containsKey("standardWhite") || !metadata.containsKey("blackWhiteBoundary")) {
    new IntensityHistogramPreProcessor().process(img,metadata);
  }
  int standardWhite=Integer.parseInt(metadata.get("standardWhite"));
  int blackWhiteBoundary=Integer.parseInt(metadata.get("blackWhiteBoundary"));
  double rotation=determineRotation(img,0.0,blackWhiteBoundary);
  if (Math.abs(rotation) > MIN_ADJUST) {
    BufferedImage img2=new BufferedImage((int)(img.getWidth() * (1.0 + Math.sin(Math.abs(rotation)))),(int)(img.getHeight() * (1.0 + Math.sin(Math.abs(rotation)))),img.getType());
    Graphics2D g2=img2.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    g2.setColor(new Color(standardWhite,standardWhite,standardWhite));
    g2.fillRect(0,0,img2.getWidth(),img2.getHeight());
    g2.translate(img2.getWidth() / 2,img2.getHeight() / 2);
    g2.rotate(rotation);
    g2.translate(-img.getWidth() / 2,-img.getHeight() / 2);
    g2.drawImage(img,0,0,null);
    img=img2;
  }
  return img;
}
 

Example 53

From project lor-jamwiki, under directory /jamwiki-core/src/main/java/org/jamwiki/utils/.

Source file: ImageProcessor.java

  19 
vote

/** 
 * Convenience method that returns a scaled instance of the provided image. This method never resizes by more than 50% since resizing by more than that amount causes quality issues with the BICUBIC and BILINEAR algorithms. Based on examples from the GraphicsUtilities sample from the book "Filthy Rich Clients" by Chet Haase and Romain Guy (http://filthyrichclients.org/). That source is dual licensed: LGPL (Sun and Romain Guy) and BSD (Romain Guy).
 * @param imageFile The file path for the original image to be scaled.
 * @param targetWidth the desired width of the scaled instance in pixels.
 * @param targetHeight the desired height of the scaled instance in pixels.
 * @return a scaled version of the original {@code BufferedImage}
 */
public static BufferedImage resizeImage(File imageFile,int targetWidth,int targetHeight) throws IOException {
  long start=System.currentTimeMillis();
  BufferedImage tmp=ImageProcessor.loadImage(imageFile);
  int type=(tmp.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
  int width=tmp.getWidth();
  int height=tmp.getHeight();
  BufferedImage resized=tmp;
  do {
    width/=2;
    if (width < targetWidth) {
      width=targetWidth;
    }
    height/=2;
    if (height < targetHeight) {
      height=targetHeight;
    }
    tmp=new BufferedImage(width,height,type);
    Graphics2D g2=tmp.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.drawImage(resized,0,0,width,height,null);
    g2.dispose();
    resized=tmp;
  }
 while (width != targetWidth || height != targetHeight);
  if (logger.isDebugEnabled()) {
    long current=System.currentTimeMillis();
    String message="Image resize time (" + ((current - start) / 1000.000) + " s), dimensions: "+ targetWidth+ "x"+ targetHeight+ " for file: "+ imageFile.getAbsolutePath();
    logger.debug(message);
  }
  return resized;
}
 

Example 54

From project McZLauncher, under directory /src/ru/zetrix/gui/.

Source file: ServerStats.java

  19 
vote

@Override protected void paintComponent(Graphics maing){
  Graphics2D g=(Graphics2D)maing.create();
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g.drawImage(ServerIcon,0,0,ServerIcon.getWidth(),ServerIcon.getHeight(),null);
  g.drawString(ServerStatus,ServerIcon.getWidth() + 2,ServerIcon.getHeight() / 2 + g.getFontMetrics().getHeight() / 4);
  g.dispose();
  super.paintComponent(maing);
}
 

Example 55

From project mdk, under directory /ui/src/main/java/net/sf/furbelow/.

Source file: SpinningDialWaitIndicator.java

  19 
vote

/** 
 * Fade the affected component to background, then apply a spinning wait indicator.
 */
public void paint(Graphics graphics){
  if (timer == null) {
    timer=new Timer(FADE_INTERVAL,this);
    timer.start();
  }
  Graphics2D g=(Graphics2D)graphics.create();
  Rectangle r=getComponent().getVisibleRect();
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  Color bg=getComponent().getBackground();
  g.setColor(new Color(bg.getRed(),bg.getGreen(),bg.getBlue(),fade));
  g.fillRect(r.x,r.y,r.width,r.height);
  if (fade < FADE_THRESHOLD)   return;
  int x=r.x;
  if (text == null)   x+=(r.width - dial.getIconWidth()) / 2;
 else   x+=dial.getIconWidth() / 4;
  int y=r.y + verticalOffset + (r.height - verticalOffset - dial.getIconHeight()) / 2;
  dial.paintIcon(getPainter(),g,x,y);
  if (text != null) {
    Font font=g.getFont();
    g.setFont(font.deriveFont(Font.PLAIN,12));
    FontMetrics m=g.getFontMetrics();
    x+=dial.getIconWidth() * 5 / 4;
    y+=dial.getIconHeight() - (dial.getIconHeight() - m.getAscent()) / 2;
    g.setColor(getComponent().getForeground());
    g.drawString(text,x,y);
  }
  g.dispose();
}
 

Example 56

From project MEditor, under directory /editor-common/editor-common-server/src/main/java/cz/mzk/editor/server/fedora/.

Source file: KrameriusImageSupport.java

  19 
vote

/** 
 * Convenience method that returns a scaled instance of the provided.
 * @param img the original image to be scaled
 * @param targetWidth the desired width of the scaled instance, in pixels
 * @param targetHeight the desired height of the scaled instance, in pixels
 * @param hint one of the rendering hints that corresponds to
 * @param higherQuality if true, this method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in downscaling cases, where  {@code targetWidth} or
 * @return a scaled version of the original {@code BufferedImage}{@code BufferedImage}.  {@code RenderingHints.KEY_INTERPOLATION}(e.g.  {@code RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR},  {@code RenderingHints.VALUE_INTERPOLATION_BILINEAR}, {@code RenderingHints.VALUE_INTERPOLATION_BICUBIC}) {@code targetHeight} is smaller than the original dimensions, andgenerally only when the  {@code BILINEAR} hint is specified)
 */
private static BufferedImage getScaledInstanceJava2D(BufferedImage img,int targetWidth,int targetHeight,Object hint,boolean higherQuality){
  int type=(img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
  BufferedImage ret=img;
  int w, h;
  if (higherQuality) {
    w=img.getWidth();
    h=img.getHeight();
  }
 else {
    w=targetWidth;
    h=targetHeight;
  }
  do {
    if (higherQuality && w > targetWidth) {
      w/=2;
      if (w < targetWidth) {
        w=targetWidth;
      }
    }
    if (higherQuality && h > targetHeight) {
      h/=2;
      if (h < targetHeight) {
        h=targetHeight;
      }
    }
    BufferedImage tmp=new BufferedImage(w,h,type);
    Graphics2D g2=tmp.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    g2.drawImage(ret,0,0,w,h,null);
    g2.dispose();
    ret=tmp;
  }
 while (w > targetWidth || h > targetHeight);
  return ret;
}
 

Example 57

From project medsavant, under directory /medsavant/MedSavantClient/src/org/ut/biolab/medsavant/view/component/.

Source file: LinkButton.java

  19 
vote

@Override public void paintComponent(Graphics g){
  if (totalWidth == 0) {
    resize();
  }
  Graphics2D g2d=(Graphics2D)g;
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  if (!isEnabled()) {
    g2d.setColor(disabledBGColor);
    g2d.fillRoundRect(0,0,totalWidth,totalHeight,5,5);
  }
 else {
    g2d.setColor(bgcolor);
    g2d.fillRoundRect(0,0,totalWidth,totalHeight,5,5);
  }
  if (isImage()) {
    g2d.drawImage(image,sidePadding,topPadding,null);
  }
 else {
    String title=getText();
    g2d.setFont(font);
    int width=g2d.getFontMetrics().stringWidth(title);
    int height=g2d.getFontMetrics().getAscent();
    if (this.isEnabled()) {
      totalWidth+=iconWidth + sidePadding;
    }
    if (this.isEnabled()) {
      g2d.drawImage(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.LINKOUT).getImage(),width + sidePadding + 3,2,null);
    }
    if (over || isSelected()) {
      g2d.setColor(textColor);
    }
 else {
      g2d.setColor(textColorUnselected);
    }
    g2d.drawString(title,sidePadding,topPadding / 2 + height - 1);
  }
}
 

Example 58

From project migration, under directory /open18_seam2/src/model/org/open18/captcha/.

Source file: Captcha.java

  19 
vote

@Override public BufferedImage renderChallenge(){
  BufferedImage challenge=new BufferedImage(70,20,BufferedImage.TYPE_INT_RGB);
  Graphics2D graphics=challenge.createGraphics();
  graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  graphics.setFont(new Font("SansSerif",Font.PLAIN,12));
  graphics.setColor(getChallengeBackgroundColor());
  graphics.fillRect(0,0,getChallengeImageWidth(),20);
  graphics.setColor(getChallengeTextColor());
  graphics.drawString(getChallenge(),5,14);
  return challenge;
}
 

Example 59

From project mtc, under directory /mtc-gui/src/main/java/org/drugis/mtc/gui/progressgraph/.

Source file: GraphBar.java

  19 
vote

@Override protected void paintComponent(Graphics g){
  Graphics2D g2=(Graphics2D)g;
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  Dimension s=getMaximumSize();
  g2.setColor(d_color);
  g2.fillRect(0,0,(int)s.getWidth(),(int)s.getHeight());
}
 

Example 60

From project multibit, under directory /src/main/java/org/multibit/viewsystem/swing/view/.

Source file: AbstractTradePanel.java

  19 
vote

private BufferedImage toBufferedImage(Image image,int width,int height){
  log.debug("toBufferedImage - 1");
  if (image == null) {
    return null;
  }
  if (width == -1) {
    width=image.getWidth(null);
  }
  if (height == -1) {
    height=image.getHeight(null);
  }
  log.debug("toBufferedImage - 2.2, image = " + image + ",width = "+ width+ ", height = "+ height);
  BufferedImage bufferedImage=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
  log.debug("toBufferedImage - 2.3, bufferedImage = " + bufferedImage);
  Graphics2D g2=bufferedImage.createGraphics();
  log.debug("toBufferedImage - 3");
  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2.drawImage(image,0,0,width,height,null);
  log.debug("toBufferedImage - 4");
  g2.dispose();
  return bufferedImage;
}
 

Example 61

From project nenya, under directory /core/src/main/java/com/threerings/media/animation/.

Source file: FadeLabelAnimation.java

  19 
vote

@Override protected void init(){
  super.init();
  if (!_label.isLaidOut()) {
    Graphics2D gfx=_mgr.createGraphics();
    if (gfx != null) {
      gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING,_antiAliased ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
      _label.layout(gfx);
      gfx.dispose();
    }
  }
  Dimension size=_label.getSize();
  _bounds.width=size.width;
  _bounds.height=size.height;
}
 

Example 62

From project oops, under directory /application/src/main/java/nl/rug/ai/mas/oops/render/.

Source file: TidyTree.java

  19 
vote

protected void paintComponent(Graphics g){
  if (g instanceof Graphics2D) {
    ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  }
  for (  Edge<ComponentCell> edge : d_layout.edgeIterable()) {
    JComponent cs=edge.getSource().getComponent();
    JComponent cd=edge.getDestination().getComponent();
    Point p1=cs.getLocation();
    Dimension d1=cs.getSize();
    Point p2=cd.getLocation();
    Dimension d2=cd.getSize();
    p1.x+=d1.width / 2;
    p1.y+=d1.height;
    p2.x+=d2.width / 2;
    g.drawLine(p1.x,p1.y,p2.x,p2.y);
  }
}
 

Example 63

From project Openbravo-POS-iPhone-App, under directory /UnicentaPOS/src-data/com/openbravo/data/gui/.

Source file: JImageEditor.java

  19 
vote

private BufferedImage resizeImage(BufferedImage img){
  int myheight=img.getHeight();
  int mywidth=img.getWidth();
  if (myheight > m_maxsize.height) {
    mywidth=(int)(mywidth * m_maxsize.height / myheight);
    myheight=m_maxsize.height;
  }
  if (mywidth > m_maxsize.width) {
    myheight=(int)(myheight * m_maxsize.width / mywidth);
    mywidth=m_maxsize.width;
  }
  BufferedImage thumb=new BufferedImage(mywidth,myheight,BufferedImage.TYPE_4BYTE_ABGR);
  double scalex=(double)mywidth / (double)img.getWidth(null);
  double scaley=(double)myheight / (double)img.getHeight(null);
  Graphics2D g2d=thumb.createGraphics();
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2d.setColor(new Color(0,0,0,0));
  g2d.fillRect(0,0,mywidth,myheight);
  if (scalex < scaley) {
    g2d.drawImage(img,0,(int)((myheight - img.getHeight(null) * scalex) / 2.0),mywidth,(int)(img.getHeight(null) * scalex),null);
  }
 else {
    g2d.drawImage(img,(int)((mywidth - img.getWidth(null) * scaley) / 2.0),0,(int)(img.getWidth(null) * scaley),myheight,null);
  }
  g2d.dispose();
  return thumb;
}
 

Example 64

From project PDF-to-unusual-HTML, under directory /PDF-to-unusual-HTML/src/org/apache/pdfbox/pdfviewer/.

Source file: PageDrawer.java

  19 
vote

/** 
 * This will draw the page to the requested context.
 * @param g The graphics context to draw onto.
 * @param p The page to draw.
 * @param pageDimension The size of the page to draw.
 * @throws IOException If there is an IO error while drawing the page.
 */
public void drawPage(Graphics g,PDPage p,Dimension pageDimension) throws IOException {
  graphics=(Graphics2D)g;
  page=p;
  pageSize=pageDimension;
  graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  if (page.getContents() != null) {
    PDResources resources=page.findResources();
    processStream(page,resources,page.getContents().getStream());
  }
  List annotations=page.getAnnotations();
  for (int i=0; i < annotations.size(); i++) {
    PDAnnotation annot=(PDAnnotation)annotations.get(i);
    PDRectangle rect=annot.getRectangle();
    String appearanceName=annot.getAppearanceStream();
    PDAppearanceDictionary appearDictionary=annot.getAppearance();
    if (appearDictionary != null) {
      if (appearanceName == null) {
        appearanceName="default";
      }
      Map appearanceMap=appearDictionary.getNormalAppearance();
      if (appearanceMap != null) {
        PDAppearanceStream appearance=(PDAppearanceStream)appearanceMap.get(appearanceName);
        if (appearance != null) {
          g.translate((int)rect.getLowerLeftX(),(int)-rect.getLowerLeftY());
          processSubStream(page,appearance.getResources(),appearance.getStream());
          g.translate((int)-rect.getLowerLeftX(),(int)+rect.getLowerLeftY());
        }
      }
    }
  }
}
 

Example 65

From project Pipeline, under directory /src/gui/figure/.

Source file: ColorSwatchButton.java

  19 
vote

public void paintComponent(Graphics g){
  Graphics2D g2d=(Graphics2D)g;
  ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  for (int i=0; i < getHeight(); i++) {
    g.setColor(new Color(245 - 2 * i,245 - 2 * i,245 - 2 * i));
    g.drawLine(1,getHeight() - i,getWidth(),getHeight() - i);
  }
  if (mouseOver) {
    g2d.setStroke(new BasicStroke(2.0f));
    g.setColor(new Color(100,100,100));
    ((Graphics2D)g).setStroke(new BasicStroke(1.25f));
  }
 else {
    g2d.setStroke(new BasicStroke(1.0f));
    g.setColor(new Color(180,180,180));
  }
  g.drawRoundRect(0,0,getWidth() - 1,getHeight() - 1,5,10);
  g.setColor(Color.LIGHT_GRAY);
  g.drawRect(3,2,getWidth() - 7,getHeight() - 5);
  g.setColor(swatchColor);
  g.fillRect(4,3,getWidth() - 8,getHeight() - 6);
}
 

Example 66

From project PixelController, under directory /src/main/java/com/neophob/sematrix/generator/.

Source file: Textwriter.java

  19 
vote

/** 
 * create image.
 * @param text the text
 */
public void createTextImage(String text){
  if (StringUtils.equals(text,this.text)) {
    return;
  }
  this.text=text;
  BufferedImage img=new BufferedImage(TEXT_BUFFER_X_SIZE,internalBufferYSize,BufferedImage.TYPE_INT_RGB);
  Graphics2D g2=img.createGraphics();
  FontRenderContext frc=g2.getFontRenderContext();
  TextLayout layout=new TextLayout(text,font,frc);
  Rectangle2D rect=layout.getBounds();
  int h=(int)(0.5f + rect.getHeight());
  maxXPos=(int)(0.5f + rect.getWidth()) + 5;
  ypos=internalBufferYSize - (internalBufferYSize - h) / 2;
  img=new BufferedImage(maxXPos,internalBufferYSize,BufferedImage.TYPE_INT_RGB);
  g2=img.createGraphics();
  g2.setColor(color);
  g2.setFont(font);
  g2.setClip(0,0,maxXPos,internalBufferYSize);
  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
  g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED);
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.drawString(text,xpos,ypos);
  DataBufferInt dbi=(DataBufferInt)img.getRaster().getDataBuffer();
  textBuffer=dbi.getData();
  g2.dispose();
  wait=0;
  xofs=0;
  scrollRight=false;
}
 

Example 67

From project playn, under directory /java/src/playn/java/.

Source file: JavaCanvasImage.java

  19 
vote

JavaCanvasImage(GLContext ctx,float width,float height){
  super(ctx,new BufferedImage(ctx.scale.scaledCeil(width),ctx.scale.scaledCeil(height),BufferedImage.TYPE_INT_ARGB),ctx.scale);
  Graphics2D gfx=img.createGraphics();
  gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  gfx.scale(ctx.scale.factor,ctx.scale.factor);
  canvas=new JavaCanvas(gfx,width(),height());
}
 

Example 68

From project pos_1, under directory /src-data/com/openbravo/data/gui/.

Source file: JImageEditor.java

  19 
vote

private BufferedImage resizeImage(BufferedImage img){
  int myheight=img.getHeight();
  int mywidth=img.getWidth();
  if (myheight > m_maxsize.height) {
    mywidth=(int)(mywidth * m_maxsize.height / myheight);
    myheight=m_maxsize.height;
  }
  if (mywidth > m_maxsize.width) {
    myheight=(int)(myheight * m_maxsize.width / mywidth);
    mywidth=m_maxsize.width;
  }
  BufferedImage thumb=new BufferedImage(mywidth,myheight,BufferedImage.TYPE_4BYTE_ABGR);
  double scalex=(double)mywidth / (double)img.getWidth(null);
  double scaley=(double)myheight / (double)img.getHeight(null);
  Graphics2D g2d=thumb.createGraphics();
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g2d.setColor(new Color(0,0,0,0));
  g2d.fillRect(0,0,mywidth,myheight);
  if (scalex < scaley) {
    g2d.drawImage(img,0,(int)((myheight - img.getHeight(null) * scalex) / 2.0),mywidth,(int)(img.getHeight(null) * scalex),null);
  }
 else {
    g2d.drawImage(img,(int)((mywidth - img.getWidth(null) * scaley) / 2.0),0,(int)(img.getWidth(null) * scaley),myheight,null);
  }
  g2d.dispose();
  return thumb;
}
 

Example 69

From project QView, under directory /QView-suite/MQProject/src/org/qview/gui/hypertree/.

Source file: HTGeodesic.java

  19 
vote

/** 
 * Draws this geodesic.
 * @param g    the graphic context
 */
void draw(Graphics g){
  g.setColor(HTColours.GEODESIC);
  if (g instanceof Graphics2D) {
    Graphics2D g2=(Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    if (fKleinMode) {
      g.drawLine(fScreenPointA.fx,fScreenPointA.fy,fScreenPointB.fx,fScreenPointB.fy);
    }
 else {
switch (fGeodesicType) {
case LINE:
        g.drawLine(fScreenPointA.fx,fScreenPointA.fy,fScreenPointB.fx,fScreenPointB.fy);
      break;
case ARC:
    if (fd != 0) {
      if (fQuadMode) {
        g2.draw(fCurve);
      }
 else {
        drawCurve(g);
      }
    }
  break;
default :
break;
}
}
}
 else {
System.err.println("Error : Hypertree 1.0 requires Java 1.2 " + "or superior.");
}
}
 

Example 70

From project rj-core, under directory /de.walware.rj.server.gd/pkg/src/java/.

Source file: GDCanvas.java

  19 
vote

public synchronized void paint(Graphics g){
  updatePending=false;
  Dimension d=getSize();
  if (!d.equals(lastSize)) {
    initRefresh();
    lastSize=d;
    return;
  }
  if (forceAntiAliasing) {
    Graphics2D g2=(Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  }
  int i=0, j=l.size();
  g.setFont(gs.f);
  g.setClip(0,0,d.width,d.height);
  while (i < j) {
    GDObject o=(GDObject)l.elementAt(i++);
    o.paint(this,gs,g);
  }
  lastUpdate=System.currentTimeMillis();
}
 

Example 71

From project Sagan-1, under directory /src/pro/carl/edu/sagan1/gui/viewcon/.

Source file: SimulationJPanel.java

  19 
vote

/** 
 * Call-back handling the PAINT event, drawing the simulation and all  what's around.
 */
@Override public void paintComponent(Graphics g){
  super.paintComponent(g);
  Graphics2D g2=(Graphics2D)g;
  if (landscape != null) {
    computeDisplayParameters(g2);
    drawLandscape(g2);
    drawRobot(g2);
  }
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  if (statusMessage != null && !statusMessage.isEmpty()) {
    g2.setColor(Color.WHITE);
    g2.setFont(statusMessageFont);
    String m=i18n("statusmsg.prefix") + statusMessage;
    g2.drawString(m,11,20);
    g2.drawString(m,9,20);
    g2.drawString(m,10,19);
    g2.drawString(m,10,21);
    g2.setColor(Color.RED);
    g2.setFont(statusMessageFont);
    g2.drawString(m,10,20);
  }
  if (landscape != null && Configuration.getInstance().showMouseCoordinates()) {
    g2.setFont(mouseposMessageFont);
    g2.setColor(Color.BLACK);
    g2.drawString("X:" + (int)(pix2mm(mousePos.getX() - x0px)) + ",Y:"+ (int)(pix2mm(y0px - mousePos.getY())),11,40);
  }
}
 

Example 72

From project scisoft-ui, under directory /uk.ac.diamond.scisoft.analysis.rcp/src/uk/ac/diamond/scisoft/analysis/rcp/plotting/.

Source file: PlotColorUtilityColours.java

  19 
vote

public static void main(String[] args){
  final Color[] colours=PlotColorUtility.GRAPH_DEFAULT_COLORS;
  final int width=300;
  final int spacing=40;
  final int height=spacing * (colours.length + 1);
  BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
  Graphics g=image.getGraphics();
  Graphics2D g2d=(Graphics2D)g;
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g.setColor(Color.WHITE);
  g.fillRect(0,0,width,height);
  for (int i=0; i < colours.length; i++) {
    final Color c=colours[i];
    g.setColor(c);
    final int y=spacing * (i + 1);
    g.drawLine(0,y,width,y);
    Polygon p=new Polygon();
    p.addPoint(width / 2,y);
    p.addPoint(width,y - 10);
    p.addPoint(width,y + 10);
    g.fillPolygon(p);
    final String text=String.format("%d: (%d, %d, %d)",i,c.getRed(),c.getGreen(),c.getBlue());
    g.drawString(text,20,y - 4);
  }
  JLabel label=new JLabel(new ImageIcon(image));
  JFrame frame=new JFrame(PlotColorUtility.class.getSimpleName() + " colours");
  frame.add(label);
  frame.pack();
  frame.setLocation(300,300);
  frame.setVisible(true);
}
 

Example 73

From project ScissLib, under directory /src/main/java/de/sciss/gui/.

Source file: AquaFocusBorder.java

  19 
vote

public void paintBorder(Component c,Graphics g,int x,int y,int width,int height){
  if (!c.hasFocus() || !visible)   return;
  final Graphics2D g2=(Graphics2D)g;
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  for (int j=0, k=1; j < 5; j++, k+=2) {
    g2.setColor(colrFocus[j]);
    g2.drawRoundRect(x + j,y + j,width - k,height - k,10 - k,10 - k);
  }
}