Example usage for java.awt Rectangle getY

List of usage examples for java.awt Rectangle getY

Introduction

In this page you can find the example usage for java.awt Rectangle getY.

Prototype

public double getY() 

Source Link

Document

Returns the Y coordinate of the bounding Rectangle in double precision.

Usage

From source file:ch5ImageWriter.java

/**
 * write out the output image specified by index imageIndex using the
 * parameters specified by the ImageWriteParam object param
 *///w w  w  .j  ava  2s  . com
public void write(IIOMetadata metadata, IIOImage iioimage, ImageWriteParam param) {
    Node root = null;
    Node dimensionsElementNode = null;

    if (iioimage.getRenderedImage() != null)
        raster = iioimage.getRenderedImage().getData();
    else
        raster = iioimage.getRaster();

    /*
     * since this format allows you to write multiple images, the
     * streamMetadataWritten variable makes sure the stream metadata is
     * written only once
     */
    if (streamMetadataWritten == false) {
        if (metadata == null)
            metadata = getDefaultStreamMetadata(param);
        root = metadata.getAsTree("ch5.imageio.ch5stream_1.00");
        dimensionsElementNode = root.getFirstChild();
        Node numberImagesAttributeNode = dimensionsElementNode.getAttributes().getNamedItem("numberImages");
        String numberImages = numberImagesAttributeNode.getNodeValue();
        try {
            ios.writeBytes("5\n");
            ios.writeBytes(numberImages);
            ios.flush();
        } catch (IOException ioe) {
            System.err.println("IOException " + ioe.getMessage());
        }
        streamMetadataWritten = true;
    }

    String widthString;
    String heightString;
    IIOMetadata imageMetadata = (ch5ImageMetadata) iioimage.getMetadata();
    /*
     * don't really need image metadata object here since raster knows
     * necessary information
     */
    if (imageMetadata == null)
        imageMetadata = getDefaultImageMetadata(null, param);

    root = imageMetadata.getAsTree("ch5.imageio.ch5image_1.00");
    dimensionsElementNode = root.getFirstChild();

    Node widthAttributeNode = dimensionsElementNode.getAttributes().getNamedItem("imageWidth");
    widthString = widthAttributeNode.getNodeValue();

    Node heightAttributeNode = dimensionsElementNode.getAttributes().getNamedItem("imageHeight");
    heightString = heightAttributeNode.getNodeValue();

    int sourceWidth = Integer.parseInt(widthString);
    int sourceHeight = Integer.parseInt(heightString);
    int destinationWidth = -1;
    int destinationHeight = -1;
    int sourceRegionWidth = -1;
    int sourceRegionHeight = -1;
    int sourceRegionXOffset = -1;
    int sourceRegionYOffset = -1;
    int xSubsamplingFactor = -1;
    int ySubsamplingFactor = -1;

    if (param == null)
        param = getDefaultWriteParam();

    /*
     * get Rectangle object which will be used to clip the source image's
     * dimensions.
     */
    Rectangle sourceRegion = param.getSourceRegion();
    if (sourceRegion != null) {
        sourceRegionWidth = (int) sourceRegion.getWidth();
        sourceRegionHeight = (int) sourceRegion.getHeight();
        sourceRegionXOffset = (int) sourceRegion.getX();
        sourceRegionYOffset = (int) sourceRegion.getY();

        /*
         * correct for overextended source regions
         */
        if (sourceRegionXOffset + sourceRegionWidth > sourceWidth)
            destinationWidth = sourceWidth - sourceRegionXOffset;
        else
            destinationWidth = sourceRegionWidth;

        if (sourceRegionYOffset + sourceRegionHeight > sourceHeight)
            destinationHeight = sourceHeight - sourceRegionYOffset;
        else
            destinationHeight = sourceRegionHeight;
    } else {
        destinationWidth = sourceWidth;
        destinationHeight = sourceHeight;
        sourceRegionXOffset = sourceRegionYOffset = 0;
    }
    /*
     * get subsampling factors
     */
    xSubsamplingFactor = param.getSourceXSubsampling();
    ySubsamplingFactor = param.getSourceYSubsampling();

    destinationWidth = (destinationWidth - 1) / xSubsamplingFactor + 1;
    destinationHeight = (destinationHeight - 1) / ySubsamplingFactor + 1;

    byte[] sourceBuffer;
    byte[] destinationBuffer = new byte[destinationWidth];

    try {
        ios.writeBytes(new String("\n"));
        ios.writeBytes(new String(destinationWidth + "\n"));
        ios.writeBytes(new String(destinationHeight + "\n"));

        int jj;
        int index;
        for (int j = 0; j < sourceWidth; j++) {
            sourceBuffer = (byte[]) raster.getDataElements(0, j, sourceWidth, 1, null);
            jj = j - sourceRegionYOffset;
            if (jj % ySubsamplingFactor == 0) {
                jj /= ySubsamplingFactor;
                if ((jj >= 0) && (jj < destinationHeight)) {
                    for (int i = 0; i < destinationWidth; i++) {
                        index = sourceRegionXOffset + i * xSubsamplingFactor;
                        destinationBuffer[i] = sourceBuffer[index];
                    }
                    ios.write(destinationBuffer, 0, destinationWidth);
                    ios.flush();
                }
            }
        }
    } catch (IOException e) {
        System.err.println("IOException: " + e.getMessage());
    }
}

From source file:ch5ImageReader.java

/**
 * read in the input image specified by index imageIndex using the
 * parameters specified by the ImageReadParam object param
 *///w  w  w .  j  ava2 s .  co  m
public BufferedImage read(int imageIndex, ImageReadParam param) {

    checkIndex(imageIndex);

    if (isSeekForwardOnly())
        minIndex = imageIndex;
    else
        minIndex = 0;

    BufferedImage bimage = null;
    WritableRaster raster = null;

    /*
     * this method sets the image metadata so that we can use the getWidth
     * and getHeight methods
     */
    setImageMetadata(iis, imageIndex);

    int srcWidth = getWidth(imageIndex);
    int srcHeight = getHeight(imageIndex);

    // initialize values to -1
    int dstWidth = -1;
    int dstHeight = -1;
    int srcRegionWidth = -1;
    int srcRegionHeight = -1;
    int srcRegionXOffset = -1;
    int srcRegionYOffset = -1;
    int xSubsamplingFactor = -1;
    int ySubsamplingFactor = -1;
    if (param == null)
        param = getDefaultReadParam();

    Iterator imageTypes = getImageTypes(imageIndex);
    try {
        /*
         * get the destination BufferedImage which will be filled using the
         * input image's pixel data
         */
        bimage = getDestination(param, imageTypes, srcWidth, srcHeight);

        /*
         * get Rectangle object which will be used to clip the source
         * image's dimensions.
         */
        Rectangle srcRegion = param.getSourceRegion();
        if (srcRegion != null) {
            srcRegionWidth = (int) srcRegion.getWidth();
            srcRegionHeight = (int) srcRegion.getHeight();
            srcRegionXOffset = (int) srcRegion.getX();
            srcRegionYOffset = (int) srcRegion.getY();

            /*
             * correct for overextended source regions
             */
            if (srcRegionXOffset + srcRegionWidth > srcWidth)
                dstWidth = srcWidth - srcRegionXOffset;
            else
                dstWidth = srcRegionWidth;

            if (srcRegionYOffset + srcRegionHeight > srcHeight)
                dstHeight = srcHeight - srcRegionYOffset;
            else
                dstHeight = srcRegionHeight;
        } else {
            dstWidth = srcWidth;
            dstHeight = srcHeight;
            srcRegionXOffset = srcRegionYOffset = 0;
        }
        /*
         * get subsampling factors
         */
        xSubsamplingFactor = param.getSourceXSubsampling();
        ySubsamplingFactor = param.getSourceYSubsampling();

        /**
         * dstWidth and dstHeight should be equal to bimage.getWidth() and
         * bimage.getHeight() after these next two instructions
         */
        dstWidth = (dstWidth - 1) / xSubsamplingFactor + 1;
        dstHeight = (dstHeight - 1) / ySubsamplingFactor + 1;
    } catch (IIOException e) {
        System.err.println("Can't create destination BufferedImage");
    }
    raster = bimage.getWritableTile(0, 0);

    /*
     * using the parameters specified by the ImageReadParam object, read the
     * image image data into the destination BufferedImage
     */
    byte[] srcBuffer = new byte[srcWidth];
    byte[] dstBuffer = new byte[dstWidth];
    int jj;
    int index;
    try {
        for (int j = 0; j < srcHeight; j++) {
            iis.readFully(srcBuffer, 0, srcWidth);

            jj = j - srcRegionYOffset;
            if (jj % ySubsamplingFactor == 0) {
                jj /= ySubsamplingFactor;
                if ((jj >= 0) && (jj < dstHeight)) {
                    for (int i = 0; i < dstWidth; i++) {
                        index = srcRegionXOffset + i * xSubsamplingFactor;
                        dstBuffer[i] = srcBuffer[index];
                    }
                    raster.setDataElements(0, jj, dstWidth, 1, dstBuffer);
                }
            }
        }
    } catch (IOException e) {
        bimage = null;
    }
    return bimage;
}

From source file:net.sourceforge.dvb.projectx.common.Common.java

/**
 * //from  w w w  . jav a2s  .c o  m
 */
public static void getMainFrameBounds() {
    Rectangle rect = (Rectangle) getGuiInterface().getMainFrameBounds();

    if (rect != null) {
        getSettings().setIntProperty(Keys.KEY_WindowPositionMain_X[0], (int) rect.getX());
        getSettings().setIntProperty(Keys.KEY_WindowPositionMain_Y[0], (int) rect.getY());
        getSettings().setIntProperty(Keys.KEY_WindowPositionMain_Width[0], (int) rect.getWidth());
        getSettings().setIntProperty(Keys.KEY_WindowPositionMain_Height[0], (int) rect.getHeight());
    }
}

From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java

public boolean editCellAt(int row, int column, EventObject e) {
    boolean b = super.editCellAt(row, column, e);
    if (b && editorComp != null) {
        //          System.out.println("editing cell at " + row + " " + column);
        Component comp;/*from  w  ww .j ava2s.co  m*/
        boolean nameCell = false;
        if (editorComp instanceof NameCellComponent) {
            nameCell = true;
            NameCellComponent nameCellComp = (NameCellComponent) editorComp;
            comp = nameCellComp.getTextComponent();
        } else
            comp = editorComp;

        if (comp instanceof KeyboardFocusable)
            ((KeyboardFocusable) comp).selectAll(e == null);

        else if (comp instanceof ChangeAwareTextField) {
            ChangeAwareTextField text = ((ChangeAwareTextField) comp);
            if (e == null) {
                text.selectAll();
            } else if (e instanceof MouseEvent) {
                if (nameCell) {
                    MouseEvent me = (MouseEvent) e;
                    Rectangle bounds = text.getBounds(null);
                    Rectangle cell = getCellRect(row, column, false);
                    bounds.setFrame(cell.getX() + bounds.getX(), cell.getY() + bounds.getY(), bounds.getWidth(),
                            bounds.getHeight());
                    if (bounds.contains(me.getPoint())) {
                        text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked
                    } else { //because if it's outside there's no caret update
                        text.requestFocus();
                        text.selectAll();
                    }
                } else
                    text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked
            }
            text.resetChange();
        }
    }
    return b;
}

From source file:gov.lanl.adore.djatoka.plugin.ExtractPDF.java

/**
 * Extracts region defined in DjatokaDecodeParam as BufferedImage
 * @param input absolute file path of PDF file.
 * @param params DjatokaDecodeParam instance containing region and transform settings.
 * @return extracted region as a BufferedImage
 * @throws DjatokaException/*from   www .  j  a  v  a2  s  .  c  o  m*/
 */
@Override
public BufferedImage process(String input, DjatokaDecodeParam params) throws DjatokaException {

    logger.debug("ExtractPDF.process:\n\tinput: " + input + "\n\tparams: " + params);

    if (input == null)
        throw new DjatokaException("Unknown failure while converting file: no image produced.");

    try {
        setPDFCommandsPath();
    } catch (IllegalStateException e) {
        logger.error("Failed to set PDF commands path: ", e);
        throw e;
    }

    int page_number = 1 + params.getCompositingLayer(); // From 0-based to 1-based.
    int status = 0;
    BufferedImage processedImage = null;
    try {
        /*
        // First get max physical dim of bounding box of the page
        // to compute the DPI to ask for..  otherwise some AutoCAD
        // drawings can produce enormous files even at 75dpi, for
        // 48" drawings..
        int dpi = 0;
        Dimension pageSize = getPDFPageSize(input, page_number);
        if (pageSize == null)
        {
        logger.error("Sanity check: Did not find \"Page " + page_number + " size\" line in output of pdfinfo, file="+input);
        throw new IllegalArgumentException("Failed to get \"Page " + page_number + " size\" of PDF with pdfinfo.");
        }
        else
        {
        double w = pageSize.getWidth();
        double h = pageSize.getHeight();
        int maxdim = (int)Math.max(Math.abs(w), Math.abs(h));
        dpi = Math.min(MAX_DPI, (MAX_PX * 72 / maxdim));
        logger.debug("DPI: pdfinfo method got dpi="+dpi+" for max dim="+maxdim+" (points, 1/72\")");
        } */

        // Scale
        int dpi = getScaledDPI(params);

        // Requires Sun JAI imageio additions to read ppm directly.
        // this will get "-[0]+1.ppm" appended to it by pdftoppm
        File outPrefixF = File.createTempFile("pdftopng", "out");
        String outPrefix = outPrefixF.toString();
        outPrefixF.delete();

        //String pdfCmd[] = PDFTOPPM_COMMAND.clone();
        ArrayList<String> pdfCmd = new ArrayList<String>(Arrays.asList(PDFTOPPM_COMMAND));
        pdfCmd.set(PDFTOPPM_COMMAND_POSITION_BIN, pdftoppmPath);
        pdfCmd.set(PDFTOPPM_COMMAND_POSITION_FIRSTPAGE, "" + page_number);
        pdfCmd.set(PDFTOPPM_COMMAND_POSITION_LASTPAGE, "" + page_number);
        pdfCmd.set(PDFTOPPM_COMMAND_POSITION_DPI, String.valueOf(dpi));
        pdfCmd.set(PDFTOPPM_COMMAND_POSITION_FILE, input.toString());
        pdfCmd.set(PDFTOPPM_COMMAND_POSITION_OUTPUTFILE, outPrefix);

        // Crop
        Rectangle crop = getCropParam(params);
        if (crop != null) {
            String[] cropParams = { "-x", "" + (int) crop.getX(), "-y", "" + (int) crop.getY(), "-W",
                    "" + (int) crop.getWidth(), "-H", "" + (int) crop.getHeight() };
            pdfCmd.addAll(PDFTOPPM_COMMAND_POSITION_OPTIONAL_EXTRAS, Arrays.asList(cropParams));
        }

        String[] pdfCmdA = pdfCmd.toArray(new String[pdfCmd.size()]);
        logger.debug("Running pdftoppm command: " + Arrays.deepToString(pdfCmdA));
        //logger.debug("Running pdftoppm command: " + pdfCmd.toString());

        File outf = null;
        Process pdfProc = null;
        try {
            pdfProc = Runtime.getRuntime().exec(pdfCmdA);
            status = pdfProc.waitFor();
            logger.debug("status: " + status);

            // pdftoppm uses variable numbers of padding 0s to the output prefix.
            // E.g., may be prefix-000001.png, prefix-001.png or even prefix-01.png.
            // Version 0.12.3 (Poppler, not XPDF) seems to consider the total number of pages.
            // So, for example, in a PDF with 90 pages, the output will be "prefix-02.png";
            // for a PDF with 350 pages, the output will be "prefix-002.png".
            // FIXME: try some approach where the PDF number of pages is considered without
            // running pdfinfo command again, thus making it simpler to determine the number
            // of padding zeros. Right now we going "brute force" because we do not know if
            // it is feasable to once again run the pdfinfo command.
            String tests[] = { outPrefix + "-" + page_number + ".png", outPrefix + "-0" + page_number + ".png",
                    outPrefix + "-00" + page_number + ".png", outPrefix + "-000" + page_number + ".png",
                    outPrefix + "-0000" + page_number + ".png", outPrefix + "-00000" + page_number + ".png" };
            for (String outname : tests) {
                if ((new File(outname)).exists()) {
                    outf = new File(outname);
                    break;
                }
            }
            logger.debug("PDFTOPPM output is: " + outf + ", exists=" + outf != null ? outf.exists() : "!");
            processedImage = ImageIO.read(outf);

            // Rotate
            if (params.getRotationDegree() > 0) {
                processedImage = ImageProcessingUtils.rotate(processedImage, params.getRotationDegree());
            }
        } catch (InterruptedException e) {
            logger.error("Failed converting PDF file to image: ", e);
            throw new IllegalArgumentException("Failed converting PDF file to image: ", e);
        } finally {
            if (outf != null)
                outf.delete();
            // Our exec() should not produce any output, but we want to stay safe.
            // http://mark.koli.ch/2011/01/leaky-pipes-remember-to-close-your-streams-when-using-javas-runtimegetruntimeexec.html
            org.apache.commons.io.IOUtils.closeQuietly(pdfProc.getOutputStream());
            org.apache.commons.io.IOUtils.closeQuietly(pdfProc.getInputStream());
            org.apache.commons.io.IOUtils.closeQuietly(pdfProc.getErrorStream());
        }
    } catch (Exception e) {
        logger.error("Failed converting PDF file to image: ", e);
        throw new IllegalArgumentException("Failed converting PDF file to image: ", e);
    } finally {
        if (status != 0)
            logger.error("PDF conversion proc failed, exit status=" + status + ", file=" + input);
    }

    return processedImage;
}

From source file:com.projity.pm.graphic.gantt.GanttRenderer.java

public void updateShapes(ListIterator nodeIterator) {

    Rectangle bounds = ((GanttParams) graphInfo).getGanttBounds();
    CoordinatesConverter coord = ((GanttParams) graphInfo).getCoord();
    if (coord == null)
        return;/*from   w  ww. j  av a 2  s.  co  m*/
    double rowHeight = ((GanttParams) graphInfo).getRowHeight();

    int i0 = (int) Math.floor(bounds.getY() / rowHeight);
    int i1 = (int) Math.ceil(bounds.getMaxY() / rowHeight);
    double t0 = coord.toTime(bounds.getX());
    double t1 = coord.toTime(bounds.getMaxX());

    GraphicNode node;
    for (ListIterator i = nodeIterator; i.hasNext();) {
        node = (GraphicNode) i.next();
        node.setRow(i.previousIndex());
        if (i.previousIndex() >= i0 && i.previousIndex() < i1) {
            if (!node.isVoid())
                updateShape(node);
        }
    }
}

From source file:liveDriftCorrectionGUI.java

private LMA fitRois(float[][] imgData, Roi iRois, double[] InitParam) {
    Rectangle rec_ = iRois.getBounds();
    double[][] img;
    img = new double[(int) rec_.getWidth()][(int) rec_.getHeight()];
    for (int iCol = (int) rec_.getX(); iCol < rec_.getX() + rec_.getWidth(); iCol++) {
        for (int iRow = (int) rec_.getY(); iRow < rec_.getY() + rec_.getHeight(); iRow++) {
            int cX = iCol - (int) rec_.getX();
            int cY = iRow - (int) rec_.getY();
            //ReportingUtils.showMessage(Float.toString(imgData[iCol][iRow]));
            img[cX][cY] = (double) imgData[iCol][iRow];
        }//from  ww  w .  j  av  a  2 s .  co  m
    }
    double[][] InitConbineData;
    InitConbineData = LM2DGaussFit.GenerateDataPoint((int) rec_.getWidth(), (int) rec_.getHeight(), img);
    LMA lma = new LMA(new LM2DGaussFit.LM2DGaussFunction(), InitParam, InitConbineData);
    lma.maxIterations = 100;
    lma.fit();
    return lma;
}

From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java

public boolean isOnIcon(MouseEvent e) {
    Point p = e.getPoint();/*from  ww w  .  j a v a  2  s.c  om*/
    int row = rowAtPoint(p);
    int col = columnAtPoint(p);
    Rectangle bounds = getCellRect(row, col, false);
    SpreadSheetModel model = (SpreadSheetModel) getModel();
    GraphicNode node = model.getNode(row);
    return NameCellComponent.isOnIcon(
            new Point((int) (p.getX() - bounds.getX()), (int) (p.getY() - bounds.getY())), bounds.getSize(),
            model.getCache().getLevel(node));
}

From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java

public boolean isOnText(MouseEvent e) {
    Point p = e.getPoint();/*  ww  w.j a  va2 s  .c  om*/
    int row = rowAtPoint(p);
    int col = columnAtPoint(p);
    Rectangle bounds = getCellRect(row, col, false);
    SpreadSheetModel model = (SpreadSheetModel) getModel();
    GraphicNode node = model.getNode(row);
    return NameCellComponent.isOnText(
            new Point((int) (p.getX() - bounds.getX()), (int) (p.getY() - bounds.getY())), bounds.getSize(),
            model.getCache().getLevel(node));
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void solveConflict() {
    if (this.investPoint == null || this.ROIPoint == null) {
        /* No conflict to be solved. */
        return;/*from  ww  w .  j  av a  2  s  . co  m*/
    }

    /* Take border into consideration. */
    final Rectangle ROIRectWithBorder = new Rectangle((Rectangle) this.ROIRect);
    final Rectangle investRectWithBorder = new Rectangle((Rectangle) this.investRect);
    ROIRectWithBorder.setLocation((int) ROIRectWithBorder.getX() - 1, (int) ROIRectWithBorder.getY() - 1);
    ROIRectWithBorder.setSize((int) ROIRectWithBorder.getWidth() + 2, (int) ROIRectWithBorder.getHeight() + 2);
    investRectWithBorder.setLocation((int) investRectWithBorder.getX() - 1,
            (int) investRectWithBorder.getY() - 1);
    investRectWithBorder.setSize((int) investRectWithBorder.getWidth() + 2,
            (int) investRectWithBorder.getHeight() + 2);
    if (false == ROIRectWithBorder.intersects(investRectWithBorder)) {
        return;
    }

    final Rectangle oldROIRect = new Rectangle((Rectangle) this.ROIRect);
    final Rectangle oldInvestRect = new Rectangle((Rectangle) this.investRect);

    // Move to Down.
    if (this.ROIRect.getY() > this.investRect.getY()) {
        ((Rectangle) this.ROIRect).translate(0,
                (int) (this.investRect.getY() + this.investRect.getHeight() - this.ROIRect.getY() + 4));
    } else {
        ((Rectangle) this.investRect).translate(0,
                (int) (this.ROIRect.getY() + this.ROIRect.getHeight() - this.investRect.getY() + 4));
    }

    if ((this.drawArea.getY() + this.drawArea.getHeight()) > (this.ROIRect.getY() + this.ROIRect.getHeight())
            && (this.drawArea.getY() + this.drawArea.getHeight()) > (this.investRect.getY()
                    + this.investRect.getHeight())) {
        return;
    }

    this.ROIRect.setRect(oldROIRect);
    this.investRect.setRect(oldInvestRect);

    // Move to Up.
    if (this.ROIRect.getY() > this.investRect.getY()) {
        ((Rectangle) this.investRect).translate(0,
                -(int) (this.investRect.getY() + this.investRect.getHeight() - this.ROIRect.getY() + 4));
    } else {
        ((Rectangle) this.ROIRect).translate(0,
                -(int) (this.ROIRect.getY() + this.ROIRect.getHeight() - this.investRect.getY() + 4));
    }

    if ((this.drawArea.getY() < this.ROIRect.getY()) && (this.drawArea.getY() < this.investRect.getY())) {
        return;
    }

    this.ROIRect.setRect(oldROIRect);
    this.investRect.setRect(oldInvestRect);
}