java.awt.RenderingHints Java Examples

The following examples show how to use java.awt.RenderingHints. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FastScatterPlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea,
        List ticks) {
    if (!isDomainGridlinesVisible()) {
        return;
    }
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        ValueTick tick = (ValueTick) iterator.next();
        double v = this.domainAxis.valueToJava2D(tick.getValue(),
                dataArea, RectangleEdge.BOTTOM);
        Line2D line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
        g2.setPaint(getDomainGridlinePaint());
        g2.setStroke(getDomainGridlineStroke());
        g2.draw(line);
    }
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example #2
Source File: TestApplet.java    From Azzet with Open Software License 3.0 6 votes vote down vote up
public synchronized void paint(Graphics g) 
{
	long time = System.nanoTime();
	update( (time - currentTime) * 0.000000001f );
	currentTime = time;
	
	BufferedImage buffer = getBuffer();
	
	Graphics2D gr = buffer.createGraphics();
	gr.setColor( getBackground() );
	gr.clearRect( 0, 0, buffer.getWidth(), buffer.getHeight() );
	gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	
	draw( gr );
	
	g.drawImage( buffer, 0, 0, this );
}
 
Example #3
Source File: AWTPainter.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void closePath(){
	if(this.pathEmpty){
		System.out.println("Warning: Empty Path!");
	}
	if( (this.style & PATH_DRAW) != 0){
		this.gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		this.gc.setColor(this.foreground.getHandle(this.alpha));
		this.gc.draw(this.path);
	}
	if( (this.style & PATH_FILL) != 0){
		this.gc.setColor(this.background.getHandle(this.alpha));
		this.gc.fill(this.path);
	}
	this.style = 0;
	this.path = null;
	this.pathEmpty = true;
	this.setAntialias( false );
}
 
Example #4
Source File: ColorTools.java    From commons-imaging with Apache License 2.0 6 votes vote down vote up
public BufferedImage convertToColorSpace(final BufferedImage bi, final ColorSpace to) {
    final ColorSpace from = bi.getColorModel().getColorSpace();

    final 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);

    final ColorConvertOp op = new ColorConvertOp(from, to, hints);

    BufferedImage result = op.filter(bi, null);

    result = relabelColorSpace(result, to);

    return result;
}
 
Example #5
Source File: Blend.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
@Override
public CompositeContext createContext(ColorModel srcColorModel,
		ColorModel dstColorModel,
		RenderingHints arg2) {
	switch (mode) {
	case MULTIPLY:
		return new MultiplyContext();
	// Modes with significant creation overhead (lookup tables). Cache those
	case SOFT_LIGHT:
		CompositeContext ctx = cache.get(Mode.SOFT_LIGHT);
		if (ctx == null) {
			ctx = new BlendContext(mode, color);
			cache.put(Mode.SOFT_LIGHT, ctx);
		}
		return ctx;
	default:
		return new BlendContext(mode, color);
	}
}
 
Example #6
Source File: HelvLtOblTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
BufferedImage drawText(boolean doGV) {
    int w = 400;
    int h = 50;
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0,0,w,h);
    g.setColor(Color.black);
    Font f = helvFont.deriveFont(Font.PLAIN, 40);
    g.setFont(f);
    int x = 5;
    int y = h - 10;
    if (doGV) {
        FontRenderContext frc = new FontRenderContext(null, true, true);
        GlyphVector gv = f.createGlyphVector(frc, codes);
        g.drawGlyphVector(gv, 5, y);
   } else {
       g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                          RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
       g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                          RenderingHints.VALUE_FRACTIONALMETRICS_ON);
       g.drawString(str, x, y);
   }
   return bi;
}
 
Example #7
Source File: AddRulesTest.java    From pumpernickel with MIT License 6 votes vote down vote up
private void reportFailure(String id, Shape good, Shape bad) {
	Rectangle2D r = good.getBounds2D();
	r.add(bad.getBounds2D());

	BufferedImage image = new BufferedImage(500, 500,
			BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = image.createGraphics();
	g.transform(RectangularTransform.create(r,
			new Rectangle(0, 0, image.getWidth(), image.getHeight())));
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setColor(Color.blue);
	g.fill(good);
	g.setColor(new Color(255, 0, 0, 128));
	g.fill(bad);
	g.dispose();
	printStream.println("the resulting shape for \"" + id
			+ "\" wasn't correct.");
	try {
		ImageIO.write(image, "png", new File("comparison " + (ctr++)
				+ ".png"));
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example #8
Source File: ScalingDemo.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public BufferedImage call() throws Exception {
	BufferedImage bi = new BufferedImage(80, 60,
			BufferedImage.TYPE_INT_RGB);
	Graphics2D g = bi.createGraphics();
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
			RenderingHints.VALUE_COLOR_RENDER_QUALITY);
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
			RenderingHints.VALUE_INTERPOLATION_BICUBIC);
	g.setRenderingHint(RenderingHints.KEY_RENDERING,
			RenderingHints.VALUE_RENDER_QUALITY);
	g.transform(TransformUtils.createAffineTransform(new Dimension(
			sampleImage.getWidth(), sampleImage.getHeight()),
			new Dimension(bi.getWidth(), bi.getHeight())));
	g.drawImage(sampleImage, 0, 0, null);
	g.dispose();
	return bi;
}
 
Example #9
Source File: FontTask.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addToResources(EditableResources e) {
    if(logicalName == null) {
        logicalName = "Arial" + getIdentity() + size;
        createBitmap = false;
    } else {
        if(logicalName.indexOf('-') < 0) {
            logicalName += getIdentity() + size;
        }
    }
    Object aa;
    if(antiAliasing) {
        aa = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
    } else {
        aa = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF;
    }
    EditorFont f = new EditorFont(Font.createSystemFont(systemFace, systemStyle, systemSize),
            null, logicalName, createBitmap, aa, charset);
    e.setFont(getName(), f);
}
 
Example #10
Source File: PdfGraphics2D.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Constructor for PDFGraphics2D.
 */
public PdfGraphics2D( final PdfContentByte cb, final float width, final float height,
    final PdfOutputProcessorMetaData metaData ) {
  this.metaData = metaData;
  dg2.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON );
  setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON );

  this.transform = new AffineTransform();

  paint = Color.black;
  background = Color.white;
  setFont( new Font( "sanserif", Font.PLAIN, 12 ) );
  this.cb = cb;
  cb.saveState();
  this.width = width;
  this.height = height;
  clip = new Area( new Rectangle2D.Float( 0, 0, width, height ) );
  clip( clip );
  oldStroke = strokeOne;
  stroke = strokeOne;
  originalStroke = strokeOne;
  setStrokeDiff( stroke, null );
  cb.saveState();
}
 
Example #11
Source File: SimplePositionListener.java    From Ardulink-1 with Apache License 2.0 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.RED);
    int x = 0;
    int y = 0;
    Dimension dimension = getSize();
    int dim = Math.min(dimension.width, dimension.height) / 2;
    if(position != null) {
    	x = position.x * dim / maxSize;
    	y = position.y * dim / maxSize;
    }
    g2.fillOval((dimension.width / 2) + x - (POINT_DIM / 2), (dimension.height / 2) - y - (POINT_DIM / 2), POINT_DIM, POINT_DIM);
    // g2.drawRect(0, 0, dimension.width - 1, dimension.height - 1);
}
 
Example #12
Source File: ColorConvertOp.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a new ColorConvertOp from a ColorSpace object.
 * The RenderingHints argument may be null.  This
 * Op can be used only with BufferedImages, and is primarily useful
 * when the {@link #filter(BufferedImage, BufferedImage) filter}
 * method is invoked with a destination argument of null.
 * In that case, the ColorSpace defines the destination color space
 * for the destination created by the filter method.  Otherwise, the
 * ColorSpace defines an intermediate space to which the source is
 * converted before being converted to the destination space.
 * @param cspace defines the destination <code>ColorSpace</code> or an
 *        intermediate <code>ColorSpace</code>
 * @param hints the <code>RenderingHints</code> object used to control
 *        the color conversion, or <code>null</code>
 * @throws NullPointerException if cspace is null
 */
public ColorConvertOp (ColorSpace cspace, RenderingHints hints)
{
    if (cspace == null) {
        throw new NullPointerException("ColorSpace cannot be null");
    }
    if (cspace instanceof ICC_ColorSpace) {
        profileList = new ICC_Profile [1];    /* 1 profile in the list */

        profileList [0] = ((ICC_ColorSpace) cspace).getProfile();
    }
    else {
        CSList = new ColorSpace[1]; /* non-ICC case: 1 ColorSpace in list */
        CSList[0] = cspace;
    }
    this.hints  = hints;
}
 
Example #13
Source File: RingChart.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
public void render(int width, int height, ClassNode rootNode, Graphics g) {
    image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D imageG2d = (Graphics2D)image.getGraphics();
    imageG2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    imageG2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    imageG2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    imageG2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    imageG2d.setComposite(AlphaComposite.Src);
    imageG2d.setColor(GuiMode.getTheme().getBackgroundColor());
    imageG2d.fillRect(0, 0, width, height);

    int graphWidth = width - MARGIN * 2;
    int graphHeight = height - MARGIN * 2;
    imageG2d.translate(MARGIN, MARGIN);
    int size = Math.min(graphWidth, graphHeight);
    renderNode(graphWidth, graphHeight, size, 0, 360, rootNode, imageG2d, 1, PALETTE);
    imageG2d.dispose();

    g.drawImage(image, 0, 0, null);
    g.dispose();
}
 
Example #14
Source File: LowDiscrepancyGeneratorComparison.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);

    int w = getWidth();
    int h = getHeight();

    g2.clearRect(0, 0, w, h);
    
    g2.setPaint(Color.black);
    g2.drawRect(0, 0, w - 1, h - 1);
    
    for (Vector2D point : points) {
        Vector2D p = transform(point, w, h);
        double[] arr = p.toArray();
        g2.draw(new Rectangle2D.Double(arr[0] - 1, arr[1] - 1, 2, 2));
    }
}
 
Example #15
Source File: JGenProg2015_000_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the input stream.
 *
 * @throws IOException  if there is an I/O error.
 * @throws ClassNotFoundException  if there is a classpath problem.
 */
private void readObject(ObjectInputStream stream) 
    throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    this.borderStroke = SerialUtilities.readStroke(stream);
    this.borderPaint = SerialUtilities.readPaint(stream);
    this.backgroundPaint = SerialUtilities.readPaint(stream);
    this.progressListeners = new EventListenerList();
    this.changeListeners = new EventListenerList();
    this.renderingHints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);

    // register as a listener with sub-components...
    if (this.title != null) {
        this.title.addChangeListener(this);
    }

    for (int i = 0; i < getSubtitleCount(); i++) {
        getSubtitle(i).addChangeListener(this);
    }
    this.plot.addChangeListener(this);
}
 
Example #16
Source File: DrawRotatedString.java    From jdk8u_jdk with GNU General Public License v2.0 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 #17
Source File: TSFrame.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void render(Graphics g, int w, int h, boolean useNonOpaque) {
    if (useNonOpaque) {
        Graphics2D g2d = (Graphics2D)g;
        GradientPaint p =
            new GradientPaint(0.0f, 0.0f,
                              new Color(rnd.nextInt(0xffffff)),
                              w, h,
                              new Color(rnd.nextInt(0xff),
                                        rnd.nextInt(0xff),
                                        rnd.nextInt(0xff), 0),
                              true);
        g2d.setPaint(p);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.fillOval(0, 0, w, h);
    } else {
        g.setColor(new Color(rnd.nextInt(0xffffff)));
        g.fillRect(0, 0, w, h);
    }
}
 
Example #18
Source File: ImageContext.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Return the interpolation rendering hint to use. This will not return
 * null. If this is undefined, then the antialiasing and rendering hints are
 * consulted (which will return either NEAREST_NEIGHBOR or BILINEAR). If
 * nothing is defined then this returns BILINEAR.
 */
protected Object getInterpolationRenderingHint() {
	Object v = renderingHints.get(RenderingHints.KEY_INTERPOLATION);
	if (v != null)
		return v;

	v = renderingHints.get(RenderingHints.KEY_ANTIALIASING);
	if (RenderingHints.VALUE_ANTIALIAS_ON.equals(v)) {
		return RenderingHints.VALUE_INTERPOLATION_BILINEAR;
	} else if (RenderingHints.VALUE_ANTIALIAS_OFF.equals(v)) {
		return RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
	}

	v = renderingHints.get(RenderingHints.KEY_RENDERING);
	if (RenderingHints.VALUE_RENDER_QUALITY.equals(v)) {
		return RenderingHints.VALUE_INTERPOLATION_BILINEAR;
	} else if (RenderingHints.VALUE_RENDER_SPEED.equals(v)) {
		return RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
	}

	// nothing is defined:
	return RenderingHints.VALUE_INTERPOLATION_BILINEAR;
}
 
Example #19
Source File: IncorrectAlphaConversionBicubic.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    final GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final VolatileImage vi =
            gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
    final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
    final int expected = bi.getRGB(2, 2);

    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        final Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.scale(2, 2);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                             RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.drawImage(bi, 0, 0, null);
        g2d.dispose();

        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    final int actual = snapshot.getRGB(2, 2);
    if (actual != expected) {
        System.err.println("Actual: " + Integer.toHexString(actual));
        System.err.println("Expected: " + Integer.toHexString(expected));
        throw new RuntimeException("Test failed");
    }
}
 
Example #20
Source File: RenderTools.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Enable and disable the bilinear interpolation mode for the graphics.
 * @param g2 the target graphics object.
 * @param active activate?
 */
public static void setInterpolation(Graphics2D g2, boolean active) {
	if (active) {
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, 
				RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	} else {
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, 
				RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
	}
}
 
Example #21
Source File: StrikeDisposalCrashTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void renderText(Frame frame, Font f1) {
    VolatileImage vi = frame.createVolatileImage(256, 32);
    vi.validate(frame.getGraphicsConfiguration());

    Graphics2D g = vi.createGraphics();
    g.setFont(f1);
    g.drawString(text, 0, vi.getHeight()/2);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                       RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.drawString(text, 0, vi.getHeight()/2);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                       RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    g.drawString(text, 0, vi.getHeight()/2);
    Toolkit.getDefaultToolkit().sync();
}
 
Example #22
Source File: SearchFieldIconPainter.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void paintCancelIcon(Graphics2D g, int x, int y, int width, int height, Color color) {
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape s = shapeGenerator.createCancelIcon(2, 2, width - 4, height - 4);
    g.setColor(color);
    g.fill(s);
}
 
Example #23
Source File: NavlinkUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();

	String text = layout(b, g.getFontMetrics(), b.getWidth(), b.getHeight());

	clearTextShiftOffset();

	if (model.isArmed() && model.isPressed()) {
		paintButtonPressed(g, b);
	} else if (b.isRolloverEnabled() && model.isRollover()) {
		paintButtonPressed(g, b);
	}

	if (b.getIcon() != null) {
		paintIcon(g, c, iconRect);
	}

	if (b.isFocusPainted() && b.isFocusOwner()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
		if (iconRect != null && iconRect.width > 0 && iconRect.height > 0) {
			if (b.getIcon() != null) {
				paintIcon(g, c, iconRect);
			}
		}
	}

	if (text != null && !text.equals("")) {
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g2, textRect);
		} else {
			paintText(g2, b, textRect, text);
		}
	}
}
 
Example #24
Source File: AffineTransformOp.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an <CODE>AffineTransformOp</CODE> given an affine transform.
 * The interpolation type is determined from the
 * <CODE>RenderingHints</CODE> 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</CODE> is null),
 * the interpolation type is {@link #TYPE_NEAREST_NEIGHBOR
 * TYPE_NEAREST_NEIGHBOR}.
 *
 * @param xform The <CODE>AffineTransform</CODE> to use for the
 * operation.
 *
 * @param hints The <CODE>RenderingHints</CODE> 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(hints.KEY_INTERPOLATION);
        if (value == null) {
            value = hints.get(hints.KEY_RENDERING);
            if (value == hints.VALUE_RENDER_SPEED) {
                interpolationType = TYPE_NEAREST_NEIGHBOR;
            }
            else if (value == hints.VALUE_RENDER_QUALITY) {
                interpolationType = TYPE_BILINEAR;
            }
        }
        else if (value == hints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) {
            interpolationType = TYPE_NEAREST_NEIGHBOR;
        }
        else if (value == hints.VALUE_INTERPOLATION_BILINEAR) {
            interpolationType = TYPE_BILINEAR;
        }
        else if (value == hints.VALUE_INTERPOLATION_BICUBIC) {
            interpolationType = TYPE_BICUBIC;
        }
    }
    else {
        interpolationType = TYPE_NEAREST_NEIGHBOR;
    }
}
 
Example #25
Source File: EllipticGradientPaint.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public java.awt.PaintContext createContext(final ColorModel COLOR_MODEL,
                                           final Rectangle DEVICE_BOUNDS,
                                           final Rectangle2D USER_BOUNDS,
                                           final AffineTransform TRANSFORM,
                                           final RenderingHints RENDERING_HINTS) {
    final Point2D TRANSFORMED_CENTER = TRANSFORM.transform(CENTER, null);
    final Point2D TRANSFORMED_RADIUS_XY = TRANSFORM.deltaTransform(RADIUS_X_Y, null);
    return new OvalGradientContext(TRANSFORMED_CENTER, TRANSFORMED_RADIUS_XY, FRACTIONS, COLORS);
}
 
Example #26
Source File: Cardumen_003_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Clones the object, and takes care of listeners.
 * Note: caller shall register its own listeners on cloned graph.
 * 
 * @return A clone.
 * 
 * @throws CloneNotSupportedException if the chart is not cloneable.
 */
public Object clone() throws CloneNotSupportedException {
    JFreeChart chart = (JFreeChart) super.clone();

    chart.renderingHints = (RenderingHints) this.renderingHints.clone();
    // private boolean borderVisible;
    // private transient Stroke borderStroke;
    // private transient Paint borderPaint;

    if (this.title != null) {
        chart.title = (TextTitle) this.title.clone();
        chart.title.addChangeListener(chart);
    }

    chart.subtitles = new ArrayList();
    for (int i = 0; i < getSubtitleCount(); i++) {
        Title subtitle = (Title) getSubtitle(i).clone();
        chart.subtitles.add(subtitle);
        subtitle.addChangeListener(chart);
    }

    if (this.plot != null) {
        chart.plot = (Plot) this.plot.clone();
        chart.plot.addChangeListener(chart);
    }

    chart.progressListeners = new EventListenerList();
    chart.changeListeners = new EventListenerList();
    return chart;
}
 
Example #27
Source File: MemoryStatus.java    From scelight with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintComponent( final Graphics g ) {
	( (Graphics2D) g ).setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
	
	final Runtime runtime = Runtime.getRuntime();
	allocated = runtime.totalMemory();
	free = runtime.freeMemory();
	max = runtime.maxMemory();
	
	// Exclude border
	final int width = getWidth() - 4;
	final int height = getHeight() - 4;
	if ( width <= 0 || height <= 0 )
		return;
	
	g.translate( 2, 2 );
	g.setColor( COLOR_UNALLOCATED );
	g.fillRect( 0, 0, width, height );
	g.setColor( COLOR_FREE );
	g.fillRect( 0, 1, (int) ( allocated * width / max ), height - 2 );
	g.setColor( COLOR_IN_USE );
	g.fillRect( 0, 1, (int) ( ( allocated - free ) * width / max ), height - 2 );
	
	// Display used / allocated
	g.setFont( g.getFont().deriveFont( Font.BOLD ) );
	final FontMetrics fontMetrics = g.getFontMetrics();
	final String memString = SizeFormat.MB.formatSize( allocated - free, 0 ) + " / " + SizeFormat.MB.formatSize( allocated, 0 );
	
	final int x = width > fontMetrics.stringWidth( memString ) ? ( width - fontMetrics.stringWidth( memString ) ) / 2 : 0;
	final int y = ( height + fontMetrics.getAscent() ) / 2 - 1;
	g.setColor( Color.BLACK );
	g.drawString( memString, x + 1, y + 1 );
	g.setColor( Color.WHITE );
	g.drawString( memString, x, y );
	
	g.translate( -2, -2 );
}
 
Example #28
Source File: AnnotatedCardPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private void drawIcons(final Graphics2D g2d) {
    if (!cardIcons.isEmpty()) {
        final int BORDER_WIDTH = 2;
        final BasicStroke BORDER_STROKE = new BasicStroke(BORDER_WIDTH);
        final Stroke defaultStroke = g2d.getStroke();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        // draw icons
        int y = 10;
        int x = 0;
        final int ICON_WIDTH = 36;
        final int ICON_HEIGHT = 32;
        final int CORNER_ARC = 16;
        final GradientPaint PAINT_COLOR = new GradientPaint(0, 0, GRADIENT_FROM_COLOR, ICON_WIDTH, 0, GRADIENT_TO_COLOR);
        iconShapes.clear();
        for (CardIcon cardIcon : cardIcons) {
            // icon bounds should be relative to CardPopupPanel.
            final Rectangle2D iconShapeRect = new Rectangle2D.Double((double)x, (double)y, (double)ICON_WIDTH, 32d);
            iconShapes.add(iconShapeRect);
            //
            final Rectangle rect = new Rectangle(x, y, ICON_WIDTH, ICON_HEIGHT);
            g2d.setPaint(PAINT_COLOR);
            g2d.fillRoundRect(rect.x, rect.y, rect.width, rect.height, CORNER_ARC, CORNER_ARC);
            g2d.setPaint(Color.BLACK);
            g2d.setStroke(BORDER_STROKE);
            g2d.drawRoundRect(rect.x, rect.y, rect.width, rect.height, CORNER_ARC, CORNER_ARC);
            g2d.setStroke(defaultStroke);
            //
            final ImageIcon icon = cardIcon.getIcon();
            final int iconOffsetX = (ICON_WIDTH / 2) - (icon.getIconWidth() / 2);
            final int iconOffsetY = 16 - (icon.getIconHeight() / 2);
            icon.paintIcon(this, g2d, x + iconOffsetX, y + iconOffsetY);
            y += ICON_HEIGHT + 1;
        }
    }
}
 
Example #29
Source File: ImagePanel.java    From amazon-kinesis-video-streams-parser-library with Apache License 2.0 5 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    if (image != null) {
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.clearRect(0, 0, image.getWidth(), image.getHeight());
        g2.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
    }
}
 
Example #30
Source File: MultiThumbSliderUI.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public void paint(Graphics g, JComponent slider2) {
	if (slider2 != slider)
		throw new RuntimeException(
				"only use this UI on the GradientSlider it was constructed with");

	Graphics2D g2 = (Graphics2D) g;
	int w = slider.getWidth();
	int h = slider.getHeight();

	if (slider.isOpaque()) {
		g.setColor(slider.getBackground());
		g.fillRect(0, 0, w, h);
	}

	if (slider2.hasFocus()) {
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		paintFocus(g2);
	}
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_OFF);
	paintTrack(g2);
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	paintThumbs(g2);
}