Java Code Examples for java.awt.RenderingHints

The following are top voted examples for showing how to use java.awt.RenderingHints. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Neukoelln_SER316   File: HTMLEditorPane.java   View source code 7 votes vote down vote up
public void paint(Graphics g) {
	if (antiAlias) {
		Graphics2D g2 = (Graphics2D) g;
		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);*/
		super.paint(g2);
	} else {
		super.paint(g);
	}
}
 
Example 2
Project: GIFKR   File: ViewUtils.java   View source code 6 votes vote down vote up
public static JPanel wrapMacFancy(JPanel content) {
	JPanel panel = new JPanel(new BorderLayout()) {

		private static final long serialVersionUID = 941275105778632480L;

		@Override
		public void paintComponent(Graphics g) {
			Color border = new Color(64, 64, 64, 64);
			Color bg = new Color(128, 128, 128, 64);

			Graphics2D g2 = (Graphics2D) g;
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			g2.setColor(bg);
			g2.fillRoundRect(1, 1, this.getWidth()-2, this.getHeight()-2, 10, 10);
			g2.setColor(border);
			g2.drawRoundRect(0, 0, this.getWidth()-1, this.getHeight()-1, 10, 10);
		}
	};
	
	panel.setOpaque(false);
	content.setOpaque(false);
	panel.add(content, BorderLayout.CENTER);
	
	return panel;
}
 
Example 3
Project: Tarski   File: OurAntiAlias.java   View source code 6 votes vote down vote up
/** Constructs an antialias-capable JTextPane with a DefaultHighlighter associated with it.
 * @param attributes - see {@link edu.mit.csail.sdg.alloy4.OurUtil#make OurUtil.make(component, attributes...)}
 */
public static JTextPane pane(Object... attributes) {
   JTextPane ans = new JTextPane() {
      static final long serialVersionUID = 0;
      @Override public void paint(Graphics gr) {
         if (antiAlias && gr instanceof Graphics2D) {
            ((Graphics2D)gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         }
         super.paint(gr);
      }
   };
   OurUtil.make(ans, attributes);
   ans.setHighlighter(new DefaultHighlighter());
   map.put(ans, Boolean.TRUE);
   return ans;
}
 
Example 4
Project: brModelo   File: Editor.java   View source code 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background

    if (diagramaAtual == null) {
        return;
    }

    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    Graphics2D Canvas = (Graphics2D) g;
    Canvas.addRenderingHints(renderHints);

    Canvas.setPaint(Color.BLACK);
    Stroke stroke = new BasicStroke(2.f,
            BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
    Canvas.setStroke(stroke);

    Canvas.drawRect(box.getLocation().x, box.getLocation().y, box.getWidth(), box.getHeight());
    Canvas.setPaint(Color.GRAY);
    Canvas.drawRect(box.getLocation().x + 1, box.getLocation().y + 1, box.getWidth(), box.getHeight());
    //Canvas.setPaint(Color.BLACK);
}
 
Example 5
Project: OpenJSharp   File: Blit.java   View source code 6 votes vote down vote up
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
Example 6
Project: OpenJSharp   File: AffineTransformOp.java   View source code 6 votes vote down vote up
/**
 * Construct AffineTransformOp with the given xform and rendering hints.
 * 
 * @param xform AffineTransform that will applied to the source image
 * @param hints rendering hints that will be used during transformation
 * @throws ImagingOpException if the transform matrix is noninvertible
 */
public AffineTransformOp (AffineTransform xform, RenderingHints hints)
{
  this.transform = xform;
  this.hints = hints;
  if (xform.getDeterminant() == 0)
    throw new ImagingOpException(null);
}
 
Example 7
Project: VISNode   File: JNodeBorder.java   View source code 6 votes vote down vote up
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(new Color(0x666666));
    g2d.fillRect(x + 5, y + 5, width - 11, height - 11);
    paintHeader(g2d, x, y, width, height);
    if (node.getParentNodeContainer().getSelection().contains(node)) {
        g2d.setColor(UIHelper.getColor("Node.border:selected"));
    } else {
        g2d.setColor(UIHelper.getColor("Node.border"));
    }
    g2d.drawRect(x + 5, y + 5, width - 11, height - 11);
    g2d.setColor(UIHelper.getColor("Node.Header.title"));
    g2d.drawString(title, 19, 22);
    g2d.dispose();
}
 
Example 8
Project: jaer   File: RNNfilter.java   View source code 6 votes vote down vote up
private BufferedImage getScaledImage() {
    BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
    g2d.drawImage(this.image.getImage(), 0, 0, getWidth(), getHeight(), null);
    return image;
}
 
Example 9
Project: incubator-netbeans   File: BalloonManager.java   View source code 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    
    g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
    
    Composite oldC = g2d.getComposite();
    Shape s = getMask( getWidth(), getHeight() );

    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.25f*currentAlpha ) );
    g2d.setColor( Color.black );
    g2d.fill( getShadowMask(s) );
    
    g2d.setColor( UIManager.getColor( "ToolTip.background" ) ); //NOI18N
    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, currentAlpha ) );
    Point2D p1 = s.getBounds().getLocation();
    Point2D p2 = new Point2D.Double(p1.getX(), p1.getY()+s.getBounds().getHeight());
    if( isMouseOverEffect )
        g2d.setPaint( new GradientPaint( p2, getMouseOverGradientStartColor(), p1, getMouseOverGradientFinishColor() ) );
    else
        g2d.setPaint( new GradientPaint( p2, getDefaultGradientStartColor(), p1, getDefaultGradientFinishColor() ) );
    g2d.fill(s);
    g2d.setColor( Color.black );
    g2d.draw(s);
    g2d.setComposite( oldC );
}
 
Example 10
Project: incubator-netbeans   File: ProgressLabel.java   View source code 6 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    if( g instanceof Graphics2D ) {
        Graphics2D g2d = (Graphics2D) g;
        //turn on high quality bitmap rendering
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g2d.translate(x, y);
        g2d.drawImage(img, at, null);
        g2d.translate(-x, -y);
    }
}
 
Example 11
Project: jdk8u-jdk   File: NonOpaqueDestLCDAATest.java   View source code 6 votes vote down vote up
private void render(Image im, int type, String s) {
    Graphics2D g2d = (Graphics2D) im.getGraphics();
    clear(g2d, type, im.getWidth(null), im.getHeight(null));
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    Font f = new Font("Dialog", Font.BOLD, 40);// g2d.getFont().deriveFont(32.0f);
    g2d.setColor(Color.white);
    g2d.setFont(g2d.getFont().deriveFont(36.0f));
    g2d.drawString(s, 10, im.getHeight(null) / 2);
}
 
Example 12
Project: OpenJSharp   File: Font2DTest.java   View source code 6 votes vote down vote up
public ChoiceV2Renderer(ChoiceV2 choice) {
    BufferedImage yes =
        new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = yes.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(Color.BLUE);
    g.drawLine(0, 5, 3, 10);
    g.drawLine(1, 5, 4, 10);
    g.drawLine(3, 10, 10, 0);
    g.drawLine(4, 9, 9, 0);
    g.dispose();
    BufferedImage blank =
        new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
    yesImage = new ImageIcon(yes);
    blankImage = new ImageIcon(blank);
    this.choice = choice;
}
 
Example 13
Project: incubator-netbeans   File: RemoteAWTService.java   View source code 6 votes vote down vote up
static Snapshot[] getGUISnapshots() {
    List snapshots = new ArrayList();   //System.err.println("gGUI: thread = "+Thread.currentThread());
    Window[] windows = Window.getWindows(); //System.err.println("gGUI: windows = "+windows.length);
    for (int wi = 0; wi < windows.length; wi++) {
        Window w = windows[wi]; //System.err.println("gGUI: w["+wi+"] = "+w+", is visible = "+w.isVisible());
        if (!w.isVisible()) {
            continue;
        }
        Dimension d = w.getSize();  //System.err.println("gGUI:  size = "+d);
        if (d.width == 0 || d.height == 0) {
            continue;
        }
        BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = bi.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
        w.paint(g);
        Raster raster = bi.getData();
        Object data = raster.getDataElements(0, 0, d.width, d.height, null);
        int[] dataArr;  //System.err.println("gGUI: data = "+data);
        if (data instanceof int[]) {
            dataArr = (int[]) data;
        } else {
            continue;
        }
        String title = null;
        if (w instanceof Frame) {
            title = ((Frame) w).getTitle();
        } else if (w instanceof Dialog) {
            title = ((Dialog) w).getTitle();
        }   //System.err.println("gGUI: title = "+title);
        snapshots.add(new Snapshot(w, title, d.width, d.height, dataArr));
    }
    Snapshot[] snapshotArr = (Snapshot[]) snapshots.toArray(new Snapshot[] {});
    lastGUISnapshots = snapshotArr;
    return snapshotArr;
}
 
Example 14
Project: Tarski   File: GraphViewer.java   View source code 6 votes vote down vote up
/** Export the current drawing as a PNG file with the given file name and image resolution. */
public void alloySaveAsPNG(String filename, double scale, double dpiX, double dpiY) throws IOException {
   try {
      int width = (int) (graph.getTotalWidth()*scale);   if (width<10) width=10;
      int height = (int) (graph.getTotalHeight()*scale); if (height<10) height=10;
      BufferedImage bf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics2D gr = (Graphics2D) (bf.getGraphics());
      gr.setColor(WHITE);
      gr.fillRect(0, 0, width, height);
      gr.setColor(BLACK);
      gr.scale(scale,scale);
      gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      graph.draw(new Artist(gr), scale, null, false);
      OurPNGWriter.writePNG(bf, filename, dpiX, dpiY);
   } catch(Throwable ex) {
      if (ex instanceof IOException) throw (IOException)ex;
      throw new IOException("Failure writing the PNG file to " + filename + " (" + ex + ")");
   }
}
 
Example 15
Project: Logisim   File: Canvas.java   View source code 6 votes vote down vote up
protected void paintBackground(Graphics g) {
	if (AppPreferences.ANTI_ALIASING.getBoolean()) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	}
	g.clearRect(0, 0, getWidth(), getHeight());
}
 
Example 16
Project: hackrf-spectrum-analyzer   File: WaterfallPlot.java   View source code 6 votes vote down vote up
@Override protected void paintComponent(Graphics arg0)
{
	Graphics2D g = (Graphics2D) arg0;
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	int w = chartWidth;
	int h = getHeight();
	g.setColor(Color.black);
	g.fillRect(0, 0, getWidth(), getHeight());

	g.drawImage(bufferedImages[drawIndex], chartXOffset, 0, w, h, null);
	
	if (displayMarker){
		g.setColor(Color.gray);
		g.drawLine(displayMarkerX, 0, displayMarkerX, h);
		g.drawString(String.format("%.1fMHz", displayMarkerFrequency/1000000.0), displayMarkerX+5, h/2);
	}//finish marker 
	
	g.setColor(Color.white);
	int x	= chartXOffset + w - 250;
	int y	= h - 20;
	g.drawString(renderingInfo, x, y-20);
	g.drawString(statusMessage, x, y);
}
 
Example 17
Project: defense-solutions-proofs-of-concept   File: RoundedJPanel.java   View source code 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    int borderWidth = 3;
    int x = borderWidth;
    int y = borderWidth;
    int w = getWidth() - (2 * borderWidth);
    int h = getHeight() - (2 * borderWidth);
    int arc = 30;

    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setColor(Color.WHITE);
    g2.fillRoundRect(x, y, w, h, arc, arc);

    g2.setStroke(new BasicStroke(borderWidth));
    g2.setColor(new Color(40, 40, 40));
    g2.drawRoundRect(x, y, w, h, arc, arc);

    g2.dispose();
}
 
Example 18
Project: hearthstone   File: Animacao.java   View source code 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    SwingUtilities.invokeLater(() -> {
        Graphics2D g2 = (Graphics2D) getGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setStroke(new BasicStroke(5, BasicStroke.JOIN_ROUND, BasicStroke.CAP_ROUND));
        g2.setColor(Color.red);
        g2.drawLine(origemEvento.x, origemEvento.y, destinoEvento.x, destinoEvento.y);
        g2.setStroke(new BasicStroke(5, BasicStroke.JOIN_ROUND, BasicStroke.CAP_ROUND));
        g2.drawOval(destinoEvento.x - 25, destinoEvento.y - 25, 50, 50);
        g2.fillOval(destinoEvento.x - 10, destinoEvento.y - 10, 20, 20);
        g2.dispose();
    });
}
 
Example 19
Project: incubator-netbeans   File: BalloonManager.java   View source code 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    
    g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
    
    Composite oldC = g2d.getComposite();
    Shape s = getMask( getWidth(), getHeight() );

    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.25f*currentAlpha ) );
    g2d.setColor( Color.black );
    g2d.fill( getShadowMask(s) );
    
    g2d.setColor( UIManager.getColor( "ToolTip.background" ) ); //NOI18N
    g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, currentAlpha ) );
    Point2D p1 = s.getBounds().getLocation();
    Point2D p2 = new Point2D.Double(p1.getX(), p1.getY()+s.getBounds().getHeight());
    if( isMouseOverEffect )
        g2d.setPaint( new GradientPaint( p2, getMouseOverGradientStartColor(), p1, getMouseOverGradientFinishColor() ) );
    else
        g2d.setPaint( new GradientPaint( p2, getDefaultGradientStartColor(), p1, getDefaultGradientFinishColor() ) );
    g2d.fill(s);
    g2d.setColor( Color.black );
    g2d.draw(s);
    g2d.setComposite( oldC );
}
 
Example 20
Project: freecol   File: SimpleZippedAnimation.java   View source code 6 votes vote down vote up
/**
 * Create a scaled version of this image animation.
 *
 * @param scale The scale factor to apply.
 * @return The scaled {@code AnimationEvent}.
 */
private AnimationEvent createScaledVersion(float scale) {
    final int width = (int)(getWidth() * scale);
    final int height = (int)(getHeight() * scale);
    BufferedImage scaled = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = scaled.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                       RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.drawImage(this.image, 0, 0, width, height, null);
    g.dispose();

    return new ImageAnimationEventImpl(scaled, this.durationInMs);
}
 
Example 21
Project: QN-ACTR-Release   File: HtmlPanel.java   View source code 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
	if (antiAliasing) {
		Graphics2D g2d = (Graphics2D) g;
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		super.paintComponent(g2d);
	} else {
		super.paintComponent(g);
	}
}
 
Example 22
Project: hearthstone   File: DragAndDrop.java   View source code 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    SwingUtilities.invokeLater(() -> {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) getGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setStroke(new BasicStroke(5, BasicStroke.JOIN_ROUND, BasicStroke.CAP_ROUND));
        g2.setColor(Color.red);
        g2.drawLine(pressed.x, pressed.y, released.x, released.y);
        g2.setStroke(new BasicStroke(5, BasicStroke.JOIN_ROUND, BasicStroke.CAP_ROUND));
        g2.drawOval(released.x - 25, released.y - 25, 50, 50);
        g2.fillOval(released.x - 10, released.y - 10, 20, 20);
        g2.dispose();
    });
}
 
Example 23
Project: AgentWorkbench   File: BasicGraphGuiVisViewer.java   View source code 6 votes vote down vote up
/**
	 * This Initializes the VisualizationViewer.
	 */
	private void initialize() {
		
		this.setBackground(Color.WHITE);
		this.setDoubleBuffered(true);
		
		// --- Configure some rendering hints in order to accelerate the visualisation --
		this.renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
		this.renderingHints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
		this.renderingHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
		this.renderingHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);

		this.renderingHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
		this.renderingHints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
		
		this.renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
		
		// --- useful and faster, but it makes the image quite unclear --------!!
//		this.renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); 
		
		// ------------------------------------------------------------------------------
		// --- Test area ----------------------------------------------------------------
		// ------------------------------------------------------------------------------
//		this.addPreRenderPaintable(new MapPreRenderer<V, E>(this));
		
	}
 
Example 24
Project: BHBot   File: MarvinImage.java   View source code 6 votes vote down vote up
/**
 * Resize and return the image passing the new height and width
 * @param height
 * @param width
 * @return
 */
public BufferedImage getBufferedImage(int width, int height)
{
	// using the new approach of Java 2D API 
	BufferedImage buf = new BufferedImage(width,height, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g2d = (Graphics2D) buf.getGraphics();
	g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2d.drawImage(image,0,0,width,height,null);
	g2d.dispose();
	return(buf);
}
 
Example 25
Project: Logisim   File: Canvas.java   View source code 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
	if (AppPreferences.ANTI_ALIASING.getBoolean()) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	}
	paintBackground(g);
	paintForeground(g);
}
 
Example 26
Project: rapidminer   File: ButtonUI.java   View source code 6 votes vote down vote up
@Override
protected void paintText(Graphics g, AbstractButton c, Rectangle textRect, String text) {
	// otherwise the tabs text would not have AA for some reason even though the rest of the
	// components has AA without this
	((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	super.paintText(g, c, textRect, text);
}
 
Example 27
Project: rapidminer   File: TextFieldUI.java   View source code 6 votes vote down vote up
@Override
protected void paintBackground(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	g2.setColor(getComponent().getBackground());
	g2.fillRoundRect(0, 0, getComponent().getWidth(), getComponent().getHeight(),
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
}
 
Example 28
Project: rapidminer   File: FormattedTextFieldUI.java   View source code 6 votes vote down vote up
@Override
protected void paintBackground(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (getComponent().isEnabled()) {
		g2.setColor(Colors.TEXTFIELD_BACKGROUND);
	} else {
		g2.setColor(Colors.TEXTFIELD_BACKGROUND_DISABLED);
	}

	g2.fillRoundRect(0, 0, getComponent().getWidth(), getComponent().getHeight(),
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
}
 
Example 29
Project: rapidminer   File: TextAreaUI.java   View source code 6 votes vote down vote up
@Override
protected void paintBackground(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	g2.setColor(getComponent().getBackground());
	g2.fillRoundRect(0, 0, getComponent().getWidth(), getComponent().getHeight(),
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
}
 
Example 30
Project: jdk8u-jdk   File: DrawRotatedString.java   View source code 6 votes vote down vote up
private static BufferedImage createBufferedImage(final boolean  aa) {
    final BufferedImage bi = new BufferedImage(SIZE, SIZE,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics2D bg = bi.createGraphics();
    bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        aa ? RenderingHints.VALUE_ANTIALIAS_ON
                           : RenderingHints.VALUE_ANTIALIAS_OFF);
    bg.setColor(Color.RED);
    bg.fillRect(0, 0, SIZE, SIZE);
    bg.translate(100, 100);
    bg.rotate(Math.toRadians(90));
    bg.setColor(Color.BLACK);
    bg.setFont(bg.getFont().deriveFont(20.0f));
    bg.drawString("MMMMMMMMMMMMMMMM", 0, 0);
    bg.dispose();
    return bi;
}
 
Example 31
Project: java-course   File: Circle.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void draw(Graphics g, RectBounds rect) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
            RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2.setColor(color);
    g2.drawOval(center.x - radius - rect.getMinX(), center.y - radius
            - rect.getMinY(), 2 * radius, 2 * radius);
}
 
Example 32
Project: ramus   File: PIDEF0painter.java   View source code 6 votes vote down vote up
private void writeImage(final OutputStream stream, final String format)
        throws IOException {
    final int y1 = movingArea.getIntOrdinate(movingArea.TOP_PART_A);

    final int y2 = movingArea.getIntOrdinate(movingArea.CLIENT_HEIGHT);
    final int y3 = movingArea.getIntOrdinate(movingArea.BOTTOM_PART_A);

    int height = y1 + y2 + y3 + 1;
    final BufferedImage bi = new BufferedImage(size.width, height,
            BufferedImage.TYPE_INT_RGB);
    final Graphics2D g = (Graphics2D) bi.getGraphics();
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
            RenderingHints.VALUE_STROKE_PURE);
    g.setColor(Color.white);
    g.fillRect(0, 0, size.width, size.height);
    g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
            RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    paint(g, 0, 0);
    ImageIO.write(bi, format, stream);
}
 
Example 33
Project: Logisim   File: ZoomControl.java   View source code 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
	if (AppPreferences.ANTI_ALIASING.getBoolean()) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	}
	int width = getWidth();
	int height = getHeight();
	g.setColor(state ? Color.black : getBackground().darker());
	int dim = (Math.min(width, height) - 4) / 3 * 3 + 1;
	int xoff = (width - dim) / 2;
	int yoff = (height - dim) / 2;
	for (int x = 0; x < dim; x += 3) {
		for (int y = 0; y < dim; y += 3) {
			g.drawLine(x + xoff, y + yoff, x + xoff, y + yoff);
		}
	}
}
 
Example 34
Project: rapidminer   File: ColorRGBComboBoxCellRenderer.java   View source code 6 votes vote down vote up
protected Icon createColoredRectangleIcon(Color color) {
	// create buffered image for colored icon
	BufferedImage bufferedImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g2 = bufferedImage.createGraphics();
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
			RenderingHints.VALUE_ANTIALIAS_ON);

	if (color != null) {
		// fill image with item color
		Color newColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
		g2.setColor(newColor);
	} else {
		g2.setColor(Color.gray);
	}
	g2.fillRect(0, 0, 10, 10);

	return new ImageIcon(bufferedImage);
}
 
Example 35
Project: rapidminer   File: AbstractConfigurationPanel.java   View source code 6 votes vote down vote up
protected Icon createColoredRectangleIcon(Color color) {
	// create buffered image for colored icon
	BufferedImage bufferedImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g2 = bufferedImage.createGraphics();
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
			RenderingHints.VALUE_ANTIALIAS_ON);

	if (color != null) {
		// fill image with item color
		Color newColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
		g2.setColor(newColor);
	} else {
		g2.setColor(Color.gray);
	}
	g2.fillRect(0, 0, 10, 10);

	return new ImageIcon(bufferedImage);
}
 
Example 36
Project: brModelo   File: InspectorItemBase.java   View source code 6 votes vote down vote up
@Override
public void paint(Graphics g) {
    super.paint(g);
    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    Graphics2D Canvas = (Graphics2D) g;

    Canvas.addRenderingHints(renderHints);

    Canvas.setStroke(new BasicStroke(
            1f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND));

    Canvas.setPaint(Color.BLACK);

    paint2D(Canvas);
}
 
Example 37
Project: org.alloytools.alloy   File: OurAntiAlias.java   View source code 6 votes vote down vote up
/**
 * Constructs an antialias-capable JTextPane with a DefaultHighlighter
 * associated with it.
 * 
 * @param attributes - see {@link edu.mit.csail.sdg.alloy4.OurUtil#make
 *            OurUtil.make(component, attributes...)}
 */
public static JTextPane pane(Object... attributes) {
	JTextPane ans = new JTextPane() {
		static final long serialVersionUID = 0;

		@Override
		public void paint(Graphics gr) {
			if (antiAlias && gr instanceof Graphics2D) {
				((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
			}
			super.paint(gr);
		}
	};
	OurUtil.make(ans, attributes);
	ans.setHighlighter(new DefaultHighlighter());
	map.put(ans, Boolean.TRUE);
	return ans;
}
 
Example 38
Project: parabuild-ci   File: JFreeChart.java   View source code 6 votes vote down vote up
/**
 * Sets a flag that indicates whether or not anti-aliasing is used when the
 * chart is drawn.
 * <P>
 * Anti-aliasing usually improves the appearance of charts, but is slower.
 *
 * @param flag  the new value of the flag.
 * 
 * @see #getAntiAlias()
 */
public void setAntiAlias(boolean flag) {

    Object val = this.renderingHints.get(RenderingHints.KEY_ANTIALIASING);
    if (val == null) {
        val = RenderingHints.VALUE_ANTIALIAS_DEFAULT;
    }
    if (!flag && RenderingHints.VALUE_ANTIALIAS_OFF.equals(val) 
        || flag && RenderingHints.VALUE_ANTIALIAS_ON.equals(val)) {
        // no change, do nothing
        return;
    }
    if (flag) {
        this.renderingHints.put(RenderingHints.KEY_ANTIALIASING, 
                                RenderingHints.VALUE_ANTIALIAS_ON);
    }
    else {
        this.renderingHints.put(RenderingHints.KEY_ANTIALIASING, 
                                RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    fireChartChanged();

}
 
Example 39
Project: parabuild-ci   File: JFreeChart.java   View source code 6 votes vote down vote up
/**
 * Sets a flag that indicates whether or not anti-aliasing is used when the
 * chart is drawn.
 * <P>
 * Anti-aliasing usually improves the appearance of charts, but is slower.
 *
 * @param flag  the new value of the flag.
 */
public void setAntiAlias(boolean flag) {

    Object o = this.renderingHints.get(RenderingHints.KEY_ANTIALIASING);
    if (o == null) {
        o = RenderingHints.VALUE_ANTIALIAS_DEFAULT;
    }
    if (!flag && RenderingHints.VALUE_ANTIALIAS_OFF.equals(o) 
        || flag && RenderingHints.VALUE_ANTIALIAS_ON.equals(o)) {
        // no change, do nothing
        return;
    }
    if (flag) {
        this.renderingHints.put(RenderingHints.KEY_ANTIALIASING, 
                                RenderingHints.VALUE_ANTIALIAS_ON);
    }
    else {
        this.renderingHints.put(RenderingHints.KEY_ANTIALIASING, 
                                RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    fireChartChanged();

}
 
Example 40
Project: GIFKR   File: ImageTools.java   View source code 6 votes vote down vote up
public static BufferedImage fitHeight(BufferedImage img, int width, int height, boolean fast){
	img=resize(img, (int)(img.getWidth()*(height/(double)img.getHeight())), height, fast);
	if(img.getHeight()>height){
		img=img.getSubimage((img.getWidth()-width)/2, 0, width, img.getHeight());
	}

	BufferedImage fullImage=new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g=(Graphics2D)fullImage.getGraphics();
	if(!fast){
		g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
	}
	g.drawImage(img, (width-img.getWidth())/2, 0, null);

	g.dispose();

	return fullImage;	
}