Example usage for java.awt Graphics2D drawRect

List of usage examples for java.awt Graphics2D drawRect

Introduction

In this page you can find the example usage for java.awt Graphics2D drawRect.

Prototype

public void drawRect(int x, int y, int width, int height) 

Source Link

Document

Draws the outline of the specified rectangle.

Usage

From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java

/**
 * @param g2 graphics2D object/*  w  w  w  .j a  v  a 2  s.c  o m*/
 */
private static void plotColorScaleBar(Graphics2D g2) {
    // calculate color scale bar dimensions & location
    Point csBarTL = new Point(heatmapWidth + colorScaleHorizontalMargin, colorScaleVerticalMargin);
    Point csBarBL = new Point(heatmapWidth + colorScaleHorizontalMargin, fullHeight - colorScaleVerticalMargin);
    Rectangle csBar = new Rectangle(csBarTL.x, csBarTL.y, colorScaleWidth - 2 * colorScaleHorizontalMargin,
            fullHeight - 2 * colorScaleVerticalMargin);

    // plot the color scale linear gradient
    LinearGradientPaint gradient = new LinearGradientPaint(csBarTL, csBarBL, gradientFractions, gradientColors);
    g2.setPaint(gradient);
    g2.fill(csBar);

    // plot a border around color scale
    g2.setColor(Color.black);
    g2.drawRect(csBar.x, csBar.y, csBar.width, csBar.height);
}

From source file:Textures.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(new Color(212, 212, 212));
    g2d.drawRect(10, 15, 90, 60);

    BufferedImage bimage1 = null;

    URL url1 = ClassLoader.getSystemResource("a.png");

    try {//from  w  w  w. j  a  v  a  2 s .c om
        bimage1 = ImageIO.read(url1);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    Rectangle rect1 = new Rectangle(0, 0, bimage1.getWidth(), bimage1.getHeight());
    TexturePaint texture1 = new TexturePaint(bimage1, rect1);

    g2d.setPaint(texture1);
    g2d.fillRect(10, 15, 90, 60);
}

From source file:com.liud.dailynote.ThumbnailatorTest.java

public void testYS7() throws IOException {
    String result = "src/main/resources/images/";
    BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    g.setColor(Color.LIGHT_GRAY);
    g.drawRect(0, 0, 10, 10);
    char[] data = "liudTest".toCharArray();
    g.drawChars(data, 0, data.length, 5, 32);

    // watermark ? 1.? 2.? 3.?
    Thumbnails.of(result + "sijili.jpg").scale(1.0f).watermark(Positions.CENTER, bi, 1.0f)
            .toFile(result + "image_warter_liud.jpg");
}

From source file:image.writer.ImageWriterExample1.java

/**
 * Paints a few things on a Graphics2D instance.
 * @param g2d the Graphics2D instance//from   ww w  .j  av  a 2  s .c o  m
 * @param pageNum a page number
 */
protected void paintSome(Graphics2D g2d, int pageNum) {
    //Paint a bounding box
    g2d.drawRect(0, 0, 400, 200);

    //A few rectangles rotated and with different color
    Graphics2D copy = (Graphics2D) g2d.create();
    int c = 12;
    for (int i = 0; i < c; i++) {
        float f = ((i + 1) / (float) c);
        Color col = new Color(0.0f, 1 - f, 0.0f);
        copy.setColor(col);
        copy.fillRect(70, 90, 50, 50);
        copy.rotate(-2 * Math.PI / (double) c, 70, 90);
    }
    copy.dispose();

    //Some text
    copy = (Graphics2D) g2d.create();
    copy.rotate(-0.25);
    copy.setColor(Color.RED);
    copy.setFont(new Font("sans-serif", Font.PLAIN, 36));
    copy.drawString("Hello world!", 140, 140);
    copy.setColor(Color.RED.darker());
    copy.setFont(new Font("serif", Font.PLAIN, 36));
    copy.drawString("Hello world!", 140, 180);
    copy.dispose();

    //Try attributed text
    AttributedString aString = new AttributedString("This is attributed text.");
    aString.addAttribute(TextAttribute.FAMILY, "SansSerif");
    aString.addAttribute(TextAttribute.FAMILY, "Serif", 8, 18);
    aString.addAttribute(TextAttribute.FOREGROUND, Color.orange, 8, 18);
    g2d.drawString(aString.getIterator(), 250, 170);

    g2d.drawString("Page: " + pageNum, 250, 190);
}

From source file:Shear.java

public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2d = (Graphics2D) g;

    AffineTransform tx1 = new AffineTransform();
    tx1.translate(50, 90);//from   www  .  j  av  a  2 s .  c o m

    g2d.setTransform(tx1);
    g2d.setColor(Color.green);
    g2d.drawRect(0, 0, 80, 50);

    AffineTransform tx2 = new AffineTransform();
    tx2.translate(50, 90);
    tx2.shear(0, 1);

    g2d.setTransform(tx2);
    g2d.setColor(Color.blue);

    g2d.draw(new Rectangle(0, 0, 80, 50));

}

From source file:util.ui.UiUtilities.java

/**
 * Creates a scaled Version of the Icon.
 *
 * The scaled Version will have a Background and a Border.
 *
 * @param ic/*from  w  ww.  ja v a  2s.co m*/
 * @return ImageIcon
 * @since 2.1
 */
public static ImageIcon createChannelIcon(Icon ic) {
    BufferedImage img = new BufferedImage(42, 22, BufferedImage.TYPE_INT_RGB);

    if (ic == null) {
        ic = new ImageIcon("./imgs/tvbrowser16.png");
    }

    int height = 20;
    int width = 40;

    if ((ic.getIconWidth() != 0) && (ic.getIconHeight() != 0)) {
        double iWidth = ic.getIconWidth();
        double iHeight = ic.getIconHeight();
        if (iWidth / iHeight < 2.0) {
            width = (int) (iWidth * (20.0 / iHeight));
        } else {
            height = (int) (iHeight * (40.0 / iWidth));
        }
    }
    ic = scaleIcon(ic, width, height);

    Graphics2D g = img.createGraphics();

    g.setColor(Color.WHITE);
    g.fillRect(1, 1, 40, 20);

    int x = 1 + 20 - ic.getIconWidth() / 2;
    int y = 1 + 10 - ic.getIconHeight() / 2;

    ic.paintIcon(null, g, x, y);

    g.setColor(Color.BLACK);
    g.drawRect(0, 0, 42, 22);

    return new ImageIcon(img);
}

From source file:TextQualityDemoVALUE_TEXT_ANTIALIAS_LCD_HBGR.java

public void paintComponent(Graphics g) {
    Dimension d = this.getSize();
    BufferedImage backBuffer = (BufferedImage) this.createImage(d.width, d.height);
    Graphics2D g2 = backBuffer.createGraphics();

    g2.setColor(Color.WHITE);//from  w  w  w  .  j av a2  s .  c  o  m
    g2.fillRect(0, 0, d.width, d.height);

    g2.setColor(Color.BLACK);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, hintValue);

    g2.drawRect(0, 0, d.width - 1, d.height - 1);

    g2.drawString("abcdefghijklmnopqrstuvwxyz", 20, 40);
    g2.drawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 20, 60);
    g2.drawString("1234567890-=!@#$%^&*()_+,./<>?", 20, 80);

    g.drawImage(backBuffer, 0, 0, this);
}

From source file:org.suren.autotest.web.framework.log.Image4SearchLog.java

@Around("execution(* org.suren.autotest.web.framework.core.ElementSearchStrategy.search*(..))")
public Object hello(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();

    Object res = joinPoint.proceed(args);
    WebDriver driver = engine.getDriver();
    if (res instanceof WebElement && driver instanceof TakesScreenshot) {
        TakesScreenshot shot = (TakesScreenshot) driver;

        File file = shot.getScreenshotAs(OutputType.FILE);
        BufferedImage bufImg = ImageIO.read(file);

        try {/*from w  w  w. jav a 2s .  c o  m*/
            WebElement webEle = (WebElement) res;
            Point loc = webEle.getLocation();
            Dimension size = webEle.getSize();

            Graphics2D g = bufImg.createGraphics();
            g.setColor(Color.red);
            g.drawRect(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
        } catch (StaleElementReferenceException e) {
            //
        }

        File elementSearchImageFile = new File(outputDir,
                progressIdentify + "_" + System.currentTimeMillis() + ".png");
        try (OutputStream output = new FileOutputStream(elementSearchImageFile)) {
            ImageIO.write(bufImg, "gif", output);
            elementSearchImageFileList.add(elementSearchImageFile);
            animatedGifEncoder.addFrame(bufImg);
        }
    }

    return res;
}

From source file:picocash.components.HeaderPanel.java

@Override
public void paint(Graphics2D g, Object object, int width, int height) {
    g.setPaint(gradientPaint);// w  ww. ja va  2  s  .  c  o m
    g.fillRect(0, 0, width, height);
    g.setColor(borderColor);
    g.drawRect(0, 0, width - 1, height - 1);
}

From source file:picocash.components.mode.ModePanel.java

@Override
public void paint(Graphics2D g, Object object, int width, int height) {
    g.setColor(PANEL_BACKGROUND_COLOR);//from  ww w  .ja  v a 2 s . c o  m
    g.fillRect(0, 0, width, height);

    g.setColor(borderColor);
    g.drawRect(0, 0, width - 1, height - 1);
}