Java Graphics Draw drawFocus(Graphics2D g2, int iX, int iY, int iWidth, int iHeight)

Here you can find the source of drawFocus(Graphics2D g2, int iX, int iY, int iWidth, int iHeight)

Description

Draw a focus rectangle on a graphics context.

License

Open Source License

Parameter

Parameter Description
g2 Graphics context
iX X position (e.g. 0)
iY Y position
iWidth Actual desired width (e.g. getWidth())
iHeight Actual desired height

Declaration

public static void drawFocus(Graphics2D g2, int iX, int iY, int iWidth, int iHeight) 

Method Source Code


//package com.java2s;
/*/*from   w w w  .  jav  a2  s .co m*/
This file is part of leafdigital util.
    
util is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
util is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with util.  If not, see <http://www.gnu.org/licenses/>.
    
Copyright 2011 Samuel Marshall.
*/

import java.awt.*;

public class Main {
    /**
     * Draw a focus rectangle on a graphics context.
     * @param g2 Graphics context
     * @param iX X position (e.g. 0)
     * @param iY Y position
     * @param iWidth Actual desired width (e.g. getWidth())
     * @param iHeight Actual desired height
     */
    public static void drawFocus(Graphics2D g2, int iX, int iY, int iWidth, int iHeight) {
        int FOCUSTRANSPARENCY = 96;
        Color beforeColor = g2.getColor();
        Stroke beforeStroke = g2.getStroke();
        g2.setColor(new Color(255, 255, 255, FOCUSTRANSPARENCY));
        g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f,
                new float[] { 1.0f, 1.0f }, 0.0f));
        g2.drawRect(iX, iY, iWidth - 1, iHeight - 1);
        g2.setColor(new Color(0, 0, 0, FOCUSTRANSPARENCY));
        g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f,
                new float[] { 1.0f, 1.0f }, 1.0f));
        g2.drawRect(iX, iY, iWidth - 1, iHeight - 1);
        g2.setColor(beforeColor);
        g2.setStroke(beforeStroke);
    }
}

Related

  1. drawFilledBox(Graphics2D g, int x, int y, int width, int height)
  2. drawFilledOctagon(Graphics2D g, int x, int y, float size)
  3. drawFilter(Graphics g, Color c, double transparency, int midx, int midy, int rx, int ry)
  4. drawFleche1(Graphics g, double x, double y, double x1, double y1, int L)
  5. drawFocus(Graphics g, int x, int y, int w, int h)
  6. drawFrank(Graphics g, int x, int y)
  7. drawGatter(Graphics g, int xDist, int yDist)
  8. drawGlow(Graphics2D g2, Area area, double width, Color color)
  9. drawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight)