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: rapidminer   File: TextAreaUI.java   Source Code and License 8 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 2
Project: Neukoelln_SER316   File: HTMLEditorPane.java   Source Code and License 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 3
Project: rapidminer   File: ColorRGBComboBoxCellRenderer.java   Source Code and License 7 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 4
Project: GIFKR   File: ViewUtils.java   Source Code and License 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 5
Project: Tarski   File: OurAntiAlias.java   Source Code and License 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 6
Project: brModelo   File: Editor.java   Source Code and License 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 7
Project: OpenJSharp   File: Blit.java   Source Code and License 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 8
Project: OpenJSharp   File: AffineTransformOp.java   Source Code and License 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 9
Project: VISNode   File: JNodeBorder.java   Source Code and License 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 10
Project: jaer   File: RNNfilter.java   Source Code and License 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 11
Project: incubator-netbeans   File: BalloonManager.java   Source Code and License 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 12
Project: incubator-netbeans   File: ProgressLabel.java   Source Code and License 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 13
Project: jdk8u-jdk   File: NonOpaqueDestLCDAATest.java   Source Code and License 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 14
Project: OpenJSharp   File: Font2DTest.java   Source Code and License 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 15
Project: incubator-netbeans   File: RemoteAWTService.java   Source Code and License 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 16
Project: Tarski   File: GraphViewer.java   Source Code and License 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 17
Project: Logisim   File: Canvas.java   Source Code and License 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 18
Project: hackrf-spectrum-analyzer   File: WaterfallPlot.java   Source Code and License 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 19
Project: defense-solutions-proofs-of-concept   File: RoundedJPanel.java   Source Code and License 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 20
Project: hearthstone   File: Animacao.java   Source Code and License 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 21
Project: incubator-netbeans   File: BalloonManager.java   Source Code and License 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 22
Project: freecol   File: SimpleZippedAnimation.java   Source Code and License 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 23
Project: QN-ACTR-Release   File: HtmlPanel.java   Source Code and License 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 24
Project: hearthstone   File: DragAndDrop.java   Source Code and License 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 25
Project: AgentWorkbench   File: BasicGraphGuiVisViewer.java   Source Code and License 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 26
Project: BHBot   File: MarvinImage.java   Source Code and License 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 27
Project: Logisim   File: Canvas.java   Source Code and License 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 28
Project: rapidminer   File: ButtonUI.java   Source Code and License 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 29
Project: rapidminer   File: TextFieldUI.java   Source Code and License 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: rapidminer   File: FormattedTextFieldUI.java   Source Code and License 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 31
Project: jdk8u-jdk   File: DrawRotatedString.java   Source Code and License 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 32
Project: java-course   File: Circle.java   Source Code and License 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 33
Project: ramus   File: PIDEF0painter.java   Source Code and License 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 34
Project: Logisim   File: ZoomControl.java   Source Code and License 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 35
Project: rapidminer   File: AbstractConfigurationPanel.java   Source Code and License 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   Source Code and License 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: jmt   File: JobsDrawer.java   Source Code and License 6 votes vote down vote up
@Override
public void paint(Graphics g) {
	Graphics2D g2d = (Graphics2D) g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2d.clearRect(0, 0, this.getWidth(), this.getHeight());
	g2d.setStroke(dCst.getDrawStroke());
	changeDrawSettings(dCst);

	//draw jobs
	drawJobsRemaining(donejobs, totjobs, panelW * 0.15f, 10.0f, panelW * 0.7f, panelH / 2.0f, g2d);
}
 
Example 38
Project: parabuild-ci   File: JFreeChart.java   Source Code and License 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   Source Code and License 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   Source Code and License 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;	
}
 
Example 41
Project: DicomViewer   File: PaletteSelector.java   Source Code and License 5 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setColor(getBackground());
    g2.fillRect(0, 0, getWidth(), getHeight());

    int sx = getSizeX();
    int sy = getSizeY();

    int nbColor = palette.length;
    int row, col, k = 0;

    for (row = 0; row < nbLine; row++) {
        for (col = 0; col < nbEltByLine; col++) {
            if (k >= nbColor) {
                break;
            }

            g2.setColor(palette[k]);
            g2.fillRect(col * sx + 1, row * sy + 1, sx - 1, sy - 1);
            g2.setColor(Color.black);
            g2.drawRect(col * sx, row * sy, sx, sy);
            k++;
        }
    }
    highlightColor(g2, selectedId, Color.white, 5);
    if (over) {
        highlightColor(g2, overId, Color.white, 3);
    }
}
 
Example 42
Project: openjdk-jdk10   File: PgramUserBoundsTest.java   Source Code and License 5 votes vote down vote up
public PaintContext createContext(ColorModel cm,
                                  Rectangle deviceBounds,
                                  Rectangle2D userBounds,
                                  AffineTransform xform,
                                  RenderingHints hints)
{
    System.out.println("user bounds = "+userBounds);
    if (!userBounds.equals(expectedBounds)) {
        throw new RuntimeException("bounds fail to match");
    }
    return c.createContext(cm, deviceBounds, userBounds, xform, hints);
}
 
Example 43
Project: VASSAL-src   File: PieceMover.java   Source Code and License 5 votes vote down vote up
private BufferedImage featherDragImage(BufferedImage src,
                                           int w, int h, int b) {
// FIXME: This should be redone so that we draw the feathering onto the
// destination first, and then pass the Graphics2D on to draw the pieces
// directly over it. Presently this doesn't work because some of the
// pieces screw up the Graphics2D when passed it... The advantage to doing
// it this way is that we create only one BufferedImage instead of two.
      final BufferedImage dst =
        ImageUtils.createCompatibleTranslucentImage(w, h);

      final Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);

      // paint the rectangle occupied by the piece at specified alpha
      g.setColor(new Color(0xff, 0xff, 0xff, CURSOR_ALPHA));
      g.fillRect(0, 0, w, h);

      // feather outwards
      for (int f = 0; f < b; ++f) {
        final int alpha = CURSOR_ALPHA * (f + 1) / b;
        g.setColor(new Color(0xff, 0xff, 0xff, alpha));
        g.drawRect(f, f, w-2*f, h-2*f);
      }

      // paint in the source image
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN));
      g.drawImage(src, 0, 0, null);
      g.dispose();

      return dst;
    }
 
Example 44
Project: visuflow-plugin   File: GraphManager.java   Source Code and License 5 votes vote down vote up
/**
 * Resizes and returns the {@code image} to the dimensions of {@code width} and {@code height}.
 *
 * @param image - the source image to be resized
 * @param width - the new width
 * @param height - the new height
 * @return resized image - the resized image to the provided width and height
 *
 * @author Shashank B S
 */
private Image getScaledImage(Image image, int width, int height) {
	BufferedImage resizedImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g2 = resizedImg.createGraphics();

	g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2.drawImage(image, 0, 0, width, height, null);
	g2.dispose();

	return resizedImg;
}
 
Example 45
Project: powertext   File: BufferedImageBackgroundPainterStrategy.java   Source Code and License 5 votes vote down vote up
/**
 * Rescales the displayed image to be the specified size.
 *
 * @param width The new width of the image.
 * @param height The new height of the image.
 * @param hint The scaling hint to use.
 */
@Override
protected void rescaleImage(int width, int height, int hint) {

	Image master = getMasterImage();
	if (master!=null) {

		Map<RenderingHints.Key, Object> hints =
				new HashMap<RenderingHints.Key, Object>();
		switch (hint) {
			default:
			case Image.SCALE_AREA_AVERAGING:
			case Image.SCALE_SMOOTH:
				hints.put(RenderingHints.KEY_INTERPOLATION,
						RenderingHints.VALUE_INTERPOLATION_BICUBIC);
				hints.put(RenderingHints.KEY_RENDERING,
						RenderingHints.VALUE_RENDER_QUALITY);
				hints.put(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
		}

		bgImage = createAcceleratedImage(width, height);
		Graphics2D g = bgImage.createGraphics();
		g.addRenderingHints(hints);
		g.drawImage(master, 0,0, width,height, null);
		g.dispose();

	}
	else {
		bgImage = null;
	}
}
 
Example 46
Project: KeysPerSecond   File: BasePanel.java   Source Code and License 5 votes vote down vote up
@Override
public void paintComponent(Graphics g1) {
	Graphics2D g = (Graphics2D) g1;

	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, Main.config.getBackgroundOpacity()));
	g.setColor(Main.config.getBackgroundColor());
	g.fillRect(0, 0, this.getWidth(), this.getHeight());
	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getForegroundOpacity()));
	g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	BufferedImage colorImage = isActive() ? ColorManager.pressed : ColorManager.unpressed;
	g.drawImage(colorImage, 2, 2, this.getWidth() - 2, this.getHeight() - 2, 0, 0, colorImage.getWidth(), colorImage.getHeight(), this);

	g.setColor(isActive() ? Main.config.getBackgroundColor() : Main.config.getForegroundColor());

	String titleString = getTitle();
	Font titleFont = Main.config.mode.getTitleFont(titleString);
	Point namePos = Main.config.mode.getTitleDrawPosition(g, this, titleString, titleFont);
	g.setFont(titleFont);
	g.drawString(titleString, namePos.x, namePos.y);

	String valueString = getValue();
	Font valueFont = Main.config.mode.getValueFont(valueString);
	Point keyCountPos = Main.config.mode.getValueDrawPosition(g, this, valueString, valueFont);
	g.setFont(valueFont);
	g.drawString(valueString, keyCountPos.x, keyCountPos.y);
}
 
Example 47
Project: MapAnalyst   File: CoordinatesTooltip.java   Source Code and License 5 votes vote down vote up
void paintTooltip(Graphics2D g2d) {
    if (mousePositionPixel == null) {
        return;
    }        
    Point2D.Double xy = mapComponent.userToWorldSpace(mousePositionPixel);

    // test whether spherical coordinates for OpenStreetMap should be displayed
    boolean osm = "new".equals(mapComponent.getName())
            && manager != null && manager.isUsingOpenStreetMap();
    if (osm && manager.isPointOnOpenStreetMap(xy) == false) {
        return;
    }

    // format coordinate strings
    String[] str = mapComponent.coordinatesStrings(xy, osm);

    // background rectangle, which is a bit larger than the text
    g2d.setColor(BACKGROUND_COLOR);
    Font font = new Font("SansSerif", Font.PLAIN, TEXT_SIZE);
    int x = mousePositionPixel.x + CURSOR_OFFSET;
    int y = mousePositionPixel.y + CURSOR_OFFSET;
    FontMetrics metrics = g2d.getFontMetrics(font);
    int h = metrics.getHeight();
    int w = Math.max(metrics.stringWidth(str[0]), metrics.stringWidth(str[1]));
    g2d.fillRect(x, y, w + 2 * TEXT_PADDING, 2 * h + TEXT_PADDING);

    // text
    g2d.setColor(Color.DARK_GRAY);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2d.setFont(font);
    g2d.drawString(str[0], x + TEXT_PADDING, y + h);
    g2d.drawString(str[1], x + TEXT_PADDING, y + 2 * h);
}
 
Example 48
Project: OpenJSharp   File: RescaleOp.java   Source Code and License 5 votes vote down vote up
/**
 * Create a new RescaleOp object using the given scale factors and offsets.
 * 
 * The length of the arrays must be equal to the number of bands (or number of
 * data or color components) of the raster/image that this Op will be used on,
 * otherwise an IllegalArgumentException will be thrown when calling the
 * filter method.
 *  
 * @param scaleFactors an array of scale factors.
 * @param offsets an array of offsets.
 * @param hints any rendering hints to use (can be null).
 * @throws NullPointerException if the scaleFactors or offsets array is null.
 */
public RescaleOp(float[] scaleFactors,
   float[] offsets,
   RenderingHints hints)
{
  int length = Math.min(scaleFactors.length, offsets.length);
  
  scale = new float[length];
  System.arraycopy(scaleFactors, 0, this.scale, 0, length);
  
  this.offsets = new float[length];
  System.arraycopy(offsets, 0, this.offsets, 0, length);
  
  this.hints = hints;
}
 
Example 49
Project: parabuild-ci   File: JFreeChart.java   Source Code and License 5 votes vote down vote up
/**
 * Sets the rendering hints for the chart.  These will be added (using the Graphics2D
 * addRenderingHints(...) method) near the start of the JFreeChart.draw(...) method.
 *
 * @param renderingHints  the rendering hints (<code>null</code> not permitted).
 */
public void setRenderingHints(RenderingHints renderingHints) {
    if (renderingHints == null) {
        throw new NullPointerException("RenderingHints given are null");
    }
    this.renderingHints = renderingHints;
    fireChartChanged();
}
 
Example 50
Project: rapidminer   File: PerspectivesPanelBar.java   Source Code and License 5 votes vote down vote up
@Override
public void paint(Graphics g, JComponent c) {
	Graphics2D g2 = (Graphics2D) g.create();
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2.setColor(getBackgroundColor());
	Rectangle rec = contentPanel.getBounds();
	g2.fillRoundRect((int) rec.getX(), (int) rec.getY(), rec.width + 15, rec.height, 25, 25);
	g2.setColor(SwingTools.RAPIDMINER_ORANGE);
	g2.drawRoundRect((int) rec.getX(), (int) rec.getY(), rec.width + 15, rec.height - 1, 25, 25);
	g2.dispose();
	super.paint(g, c);
}
 
Example 51
Project: open-java-trade-manager   File: ChartLayerUI.java   Source Code and License 5 votes vote down vote up
@Override
protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) {
    super.paintLayer(g2, layer);
    
    if (this.mainTraceInfo.getPoint() == null) {
        return;
    }

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(COLOR_BLUE);
    final int BALL_RADIUS = 8;
    g2.fillOval((int)(this.mainTraceInfo.getPoint().getX() - (BALL_RADIUS >> 1) + 0.5), (int)(this.mainTraceInfo.getPoint().getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS);

    for (TraceInfo indicatorTraceInfo : this.indicatorTraceInfos) {
        final Point2D point = indicatorTraceInfo.getPoint();
        if (null == point) {
            continue;
        }
        g2.fillOval((int)(point.getX() - (BALL_RADIUS >> 1) + 0.5), (int)(point.getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS);
    }

    g2.setColor(oldColor);
    
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    this.drawInformationBox(g2, layer);
}
 
Example 52
Project: jdk8u-jdk   File: RenderToCustomBufferTest.java   Source Code and License 5 votes vote down vote up
private static void renderTo(BufferedImage dst) {
    System.out.println("The buffer: " + dst);
    Graphics2D g = dst.createGraphics();

    final int w = dst.getWidth();
    final int h = dst.getHeight();

    g.setColor(Color.blue);
    g.fillRect(0, 0, w, h);

    g.setColor(Color.red);
    Font f = g.getFont();
    g.setFont(f.deriveFont(48f));

    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    // NB: this clip ctriggers the problem
    g.setClip(50, 50, 200, 100);

    g.drawString("AA Text", 52, 90);

    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
           RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

    // NB: this clip ctriggers the problem
    g.setClip(50, 100, 100, 100);
    g.drawString("Text", 52, 148);

    g.dispose();
}
 
Example 53
Project: VASSAL-src   File: ImageUtils.java   Source Code and License 5 votes vote down vote up
@Deprecated
public static BufferedImage transform(BufferedImage src,
                                      double scale,
                                      double angle,
                                      RenderingHints hints,
                                      int quality) {
  return transform(src, scale, angle, hints);
}
 
Example 54
Project: openjdk-jdk10   File: AffineTransformOp.java   Source Code and License 5 votes vote down vote up
/**
 * Constructs an {@code AffineTransformOp} given an affine transform.
 * The interpolation type is determined from the
 * {@code RenderingHints} object.  If the interpolation hint is
 * defined, it will be used. Otherwise, if the rendering quality hint is
 * defined, the interpolation type is determined from its value.  If no
 * hints are specified ({@code hints} is null),
 * the interpolation type is {@link #TYPE_NEAREST_NEIGHBOR
 * TYPE_NEAREST_NEIGHBOR}.
 *
 * @param xform The {@code AffineTransform} to use for the
 * operation.
 *
 * @param hints The {@code RenderingHints} object used to specify
 * the interpolation type for the operation.
 *
 * @throws ImagingOpException if the transform is non-invertible.
 * @see java.awt.RenderingHints#KEY_INTERPOLATION
 * @see java.awt.RenderingHints#KEY_RENDERING
 */
public AffineTransformOp(AffineTransform xform, RenderingHints hints){
    validateTransform(xform);
    this.xform = (AffineTransform) xform.clone();
    this.hints = hints;

    if (hints != null) {
        Object value = hints.get(RenderingHints.KEY_INTERPOLATION);
        if (value == null) {
            value = hints.get(RenderingHints.KEY_RENDERING);
            if (value == RenderingHints.VALUE_RENDER_SPEED) {
                interpolationType = TYPE_NEAREST_NEIGHBOR;
            }
            else if (value == RenderingHints.VALUE_RENDER_QUALITY) {
                interpolationType = TYPE_BILINEAR;
            }
        }
        else if (value == RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) {
            interpolationType = TYPE_NEAREST_NEIGHBOR;
        }
        else if (value == RenderingHints.VALUE_INTERPOLATION_BILINEAR) {
            interpolationType = TYPE_BILINEAR;
        }
        else if (value == RenderingHints.VALUE_INTERPOLATION_BICUBIC) {
            interpolationType = TYPE_BICUBIC;
        }
    }
    else {
        interpolationType = TYPE_NEAREST_NEIGHBOR;
    }
}
 
Example 55
Project: faitic-checker   File: JCustomButton.java   Source Code and License 5 votes vote down vote up
@Override
public void paint(Graphics g){

	//super.paintComponent(g);
	
	Color borderColor= !isEnabled() ? new Color(200,200,200,255) : new Color(0,110,198,255);
	Color fontColor=getForeground();
	
	int maxwidth=super.getWidth();
	int maxheight=super.getHeight();
	int marginleft=(super.getWidth()-maxwidth)/2;
	int margintop=(super.getHeight()-maxheight)/2;

	Graphics2D g2=(Graphics2D) g;
	
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setColor(borderColor);
    
	g2.fillRoundRect(marginleft, margintop, maxwidth, maxheight, 6, 6);
	/*
	g2.setColor(borderColor.brighter());
	g2.setStroke(new BasicStroke(2));
	g2.drawRoundRect(marginleft, margintop, maxwidth-1, maxheight-1, 6, 6);
	
	g2.setColor(borderColor.darker());
	g2.setStroke(new BasicStroke(1));
	g2.drawRoundRect(marginleft, margintop, maxwidth-1, maxheight-1, 6, 6);
	*/
	g2.setColor(fontColor);
	g2.setFont(getFont());
	g2.drawString(getText(), (getWidth()-g.getFontMetrics().stringWidth(getText()))/2, g.getFontMetrics().getAscent()+(getHeight()-g.getFontMetrics().getAscent())/2);
	
	
}
 
Example 56
Project: org.alloytools.alloy   File: OurAntiAlias.java   Source Code and License 5 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 57
Project: FreeCol   File: ConceptDetailPanel.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void buildDetail(String id, JPanel panel) {
    if (this.id.equals(id)) return;

    panel.setLayout(new MigLayout("wrap 1, center"));

    JLabel header = Utility.localizedHeaderLabel(Messages.nameKey(id),
        SwingConstants.LEADING, FontLibrary.FontSize.SMALL);
    panel.add(header, "align center, wrap 20");

    JEditorPane editorPane = new JEditorPane("text/html",
        Messages.getDescription(id)) {

        @Override
        public void paintComponent(Graphics g) {
            Graphics2D graphics2d = (Graphics2D) g;
            graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                                        RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            /*
            graphics2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                                        RenderingHints.VALUE_RENDER_QUALITY);
            graphics2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                                        RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            */
            super.paintComponent(graphics2d);
        }
    };
    editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
                                 Boolean.TRUE);
    editorPane.setFont(panel.getFont());
    editorPane.setOpaque(false);
    editorPane.setEditable(false);
    editorPane.addHyperlinkListener(colopediaPanel);

    panel.add(editorPane, "width 95%");
}
 
Example 58
Project: VASSAL-src   File: Chatter.java   Source Code and License 5 votes vote down vote up
private int drawColoredText(Graphics g, int x, int y, TabExpander ex, Document doc,
                            int p0, int p1, Element elem) throws BadLocationException {
  final Segment s = new Segment();
  doc.getText(p0, p1 - p0, s);
  g.setColor(getColor(elem));

  final Graphics2D g2d = (Graphics2D) g;
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON);
  return Utilities.drawTabbedText(s, x, y, g, ex, p0);
}
 
Example 59
Project: Logisim   File: About.java   Source Code and License 5 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);
	}
	super.paintComponent(g);
	drawText(g, 10, 20);
}
 
Example 60
Project: openjdk-jdk10   File: SunGraphics2D.java   Source Code and License 5 votes vote down vote up
/**
 * Gets the preferences for the rendering algorithms.
 * Hint categories include controls for rendering quality and
 * overall time/quality trade-off in the rendering process.
 * @see RenderingHints
 */
public RenderingHints getRenderingHints() {
    if (hints == null) {
        return makeHints(null);
    } else {
        return (RenderingHints) hints.clone();
    }
}