Example usage for java.awt Graphics fill3DRect

List of usage examples for java.awt Graphics fill3DRect

Introduction

In this page you can find the example usage for java.awt Graphics fill3DRect.

Prototype

public void fill3DRect(int x, int y, int width, int height, boolean raised) 

Source Link

Document

Paints a 3-D highlighted rectangle filled with the current color.

Usage

From source file:DynamicIconExample.java

public static void main(String[] args) {
    final JSlider width = new JSlider(JSlider.HORIZONTAL, 1, 150, 75);
    final JSlider height = new JSlider(JSlider.VERTICAL, 1, 150, 75);

    class DynamicIcon implements Icon {
        public int getIconWidth() {
            return width.getValue();
        }//w  w  w .  j  a v  a2  s .c o m

        public int getIconHeight() {
            return height.getValue();
        }

        public void paintIcon(Component c, Graphics g, int x, int y) {
            g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true);
        }
    }

    Icon icon = new DynamicIcon();
    final JLabel dynamicLabel = new JLabel(icon);

    class Updater implements ChangeListener {
        public void stateChanged(ChangeEvent ev) {
            dynamicLabel.repaint();
        }
    }
    Updater updater = new Updater();

    width.addChangeListener(updater);
    height.addChangeListener(updater);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container c = f.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(width, BorderLayout.NORTH);
    c.add(height, BorderLayout.WEST);
    c.add(dynamicLabel, BorderLayout.CENTER);
    f.setSize(210, 210);
    f.setVisible(true);
}

From source file:MyCanvas.java

public void paint(Graphics g) {
    g.setColor(Color.RED);
    g.fill3DRect(20, 20, 200, 200, true);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.setColor(Color.yellow);
    g.fill3DRect(5, 15, 50, 75, true);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.setColor(Color.gray);/*ww w.j a  v  a  2  s  . co  m*/
    g.draw3DRect(25, 10, 50, 75, true);
    g.draw3DRect(25, 110, 50, 75, false);
    g.fill3DRect(100, 10, 50, 75, true);
    g.fill3DRect(100, 110, 50, 75, false);
}

From source file:SimpleBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Insets insets = getBorderInsets(c);
    if (color != null)
        g.setColor(color);// w w  w . jav  a 2  s. c  o  m

    g.fill3DRect(0, 0, width - insets.right, insets.top, true);

    g.fill3DRect(0, insets.top, insets.left, height - insets.top, true);
    g.fill3DRect(insets.left, height - insets.bottom, width - insets.left, insets.bottom, true);
    g.fill3DRect(width - insets.right, 0, insets.right, height - insets.bottom, true);
}

From source file:SimpleBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

    Insets insets = getBorderInsets(c);
    if (color != null)
        g.setColor(color);/*from   w w w .  j  a v  a2 s .  com*/

    g.fill3DRect(0, 0, width - insets.right, insets.top, true);

    g.fill3DRect(0, insets.top, insets.left, height - insets.top, true);
    g.fill3DRect(insets.left, height - insets.bottom, width - insets.left, insets.bottom, true);
    g.fill3DRect(width - insets.right, 0, insets.right, height - insets.bottom, true);
}

From source file:AlignLabels.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    Color oldColor = g.getColor();
    g.setColor(color);//  w  w w.  j av a2 s .c  om
    g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true);
    g.setColor(oldColor);
}

From source file:layout.BLDComponent.java

public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    float alignmentX = getAlignmentX();

    g.setColor(normalHue);//from  w  w  w  . j  a v a2 s  .  c om
    g.fill3DRect(0, 0, width, height, true);

    /* Draw a vertical white line at the alignment point.*/
    // XXX: This code is probably not the best.
    g.setColor(Color.white);
    int x = (int) (alignmentX * (float) width) - 1;
    g.drawLine(x, 0, x, height - 1);

    /* Say what the alignment point is. */
    g.setColor(Color.black);
    g.drawString(Float.toString(alignmentX), 3, height - 3);

    if (printSize) {
        System.out.println("BLDComponent " + name + ": size is " + width + "x" + height + "; preferred size is "
                + getPreferredSize().width + "x" + getPreferredSize().height);
    }
}

From source file:FillRectPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawRect(10, 10, 80, 30);// w  ww .  j a v a2 s.co  m
    g.drawRoundRect(100, 10, 80, 30, 15, 15);
    g.drawOval(10, 100, 80, 30);
    g.setColor(Color.red);
    g.fillRect(10, 10, 80, 30);
    g.fillRoundRect(100, 10, 80, 30, 15, 15);

    int thickness = 4;

    g.fill3DRect(200, 10, 80, 30, true);
    for (int i = 1; i <= thickness; i++)
        g.draw3DRect(200 - i, 10 - i, 80 + 2 * i - 1, 30 + 2 * i - 1, true);

    g.fill3DRect(200, 50, 80, 30, false);
    for (int i = 1; i <= thickness; i++)
        g.draw3DRect(200 - i, 50 - i, 80 + 2 * i - 1, 30 + 2 * i - 1, true);

    g.fillOval(10, 100, 80, 30);
}

From source file:org.fcrepo.localservices.imagemanip.ImageManipulation.java

/**
 * Method automatically called by browser to handle image manipulations.
 * // w w  w  . j  a va  2 s . co  m
 * @param req
 *        Browser request to servlet res Response sent back to browser after
 *        image manipulation
 * @throws IOException
 *         If an input or output exception occurred ServletException If a
 *         servlet exception occurred
 */
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    System.setProperty("java.awt.headless", "true");
    // collect all possible parameters for servlet
    String url = req.getParameter("url");
    String op = req.getParameter("op");
    String newWidth = req.getParameter("newWidth");
    String brightAmt = req.getParameter("brightAmt");
    String zoomAmt = req.getParameter("zoomAmt");
    String wmText = req.getParameter("wmText");
    String cropX = req.getParameter("cropX");
    String cropY = req.getParameter("cropY");
    String cropWidth = req.getParameter("cropWidth");
    String cropHeight = req.getParameter("cropHeight");
    String convertTo = req.getParameter("convertTo");
    if (convertTo != null) {
        convertTo = convertTo.toLowerCase();
    }
    try {
        if (op == null) {
            throw new ServletException("op parameter not specified.");
        }
        String outputMimeType;
        // get the image via url and put it into the ImagePlus processor.
        BufferedImage img = getImage(url);
        // do watermarking stuff
        if (op.equals("watermark")) {
            if (wmText == null) {
                throw new ServletException("Must specify wmText.");
            }
            Graphics g = img.getGraphics();
            int fontSize = img.getWidth() * 3 / 100;
            if (fontSize < 10) {
                fontSize = 10;
            }
            g.setFont(new Font("Lucida Sans", Font.BOLD, fontSize));
            FontMetrics fm = g.getFontMetrics();
            int stringWidth = (int) fm.getStringBounds(wmText, g).getWidth();
            int x = img.getWidth() / 2 - stringWidth / 2;
            int y = img.getHeight() - fm.getHeight();
            g.setColor(new Color(180, 180, 180));
            g.fill3DRect(x - 10, y - fm.getHeight() - 4, stringWidth + 20, fm.getHeight() + 12, true);
            g.setColor(new Color(100, 100, 100));
            g.drawString(wmText, x + 2, y + 2);
            g.setColor(new Color(240, 240, 240));
            g.drawString(wmText, x, y);
        }
        ImageProcessor ip = new ImagePlus("temp", img).getProcessor();
        // if the inputMimeType is image/gif, need to convert to RGB in any case
        if (inputMimeType.equals("image/gif")) {
            ip = ip.convertToRGB();
            alreadyConvertedToRGB = true;
        }
        // causes scale() and resize() to do bilinear interpolation
        ip.setInterpolate(true);
        if (!op.equals("convert")) {
            if (op.equals("resize")) {
                ip = resize(ip, newWidth);
            } else if (op.equals("zoom")) {
                ip = zoom(ip, zoomAmt);
            } else if (op.equals("brightness")) {
                ip = brightness(ip, brightAmt);
            } else if (op.equals("watermark")) {
                // this is now taken care of beforehand (see above)
            } else if (op.equals("grayscale")) {
                ip = grayscale(ip);
            } else if (op.equals("crop")) {
                ip = crop(ip, cropX, cropY, cropWidth, cropHeight);
            } else {
                throw new ServletException("Invalid operation: " + op);
            }
            outputMimeType = inputMimeType;
        } else {
            if (convertTo == null) {
                throw new ServletException("Neither op nor convertTo was specified.");
            }
            if (convertTo.equals("jpg") || convertTo.equals("jpeg")) {
                outputMimeType = "image/jpeg";
            } else if (convertTo.equals("gif")) {
                outputMimeType = "image/gif";
            } else if (convertTo.equals("tiff")) {
                outputMimeType = "image/tiff";
            } else if (convertTo.equals("bmp")) {
                outputMimeType = "image/bmp";
            } else if (convertTo.equals("png")) {
                outputMimeType = "image/png";
            } else {
                throw new ServletException("Invalid format: " + convertTo);
            }
        }
        res.setContentType(outputMimeType);
        BufferedOutputStream out = new BufferedOutputStream(res.getOutputStream());
        outputImage(ip, out, outputMimeType);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                e.getClass().getName() + ": " + e.getMessage());
    }
}