Example usage for java.awt Rectangle getHeight

List of usage examples for java.awt Rectangle getHeight

Introduction

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

Prototype

public double getHeight() 

Source Link

Document

Returns the height of the bounding Rectangle in double precision.

Usage

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];
        }/* ww w  .  j  a v a 2s .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: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  w  w w .  j  a  v  a  2 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:net.sourceforge.dvb.projectx.common.Common.java

/**
 * /*from  www  .jav  a  2 s  .co 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 w  w.j  a v a 2  s. c o 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:edu.stanford.epadd.launcher.Splash.java

public Splash() {
    final SplashScreen splash = (System.getProperty("nobrowseropen") == null) ? SplashScreen.getSplashScreen()
            : null;//w ww.j  a  va 2s .c  om
    if (splash == null) {
        System.out.println("SplashScreen.getSplashScreen() returned null");
        return;
    }
    Rectangle r = splash.getBounds();
    g = splash.createGraphics();
    if (g == null) {
        System.out.println("splash.createGraphics() returned null");
        return;
    }
    System.out.println("splash url = " + splash.getImageURL() + " w=" + r.getWidth() + " h=" + r.getHeight()
            + " size=" + r.getSize() + " loc=" + r.getLocation());
    //      setVisible(true);
    //      toFront();
}

From source file:ipnat.skel.Strahler.java

/**
 * This method is called when the plugin is loaded.
 *
 * @param arg//from  w  ww.  ja  v a  2 s  .  c om
 *            the arguments as specified in {@code plugins.config}
 *
 */
@Override
public void run(final String arg) {

    // Retrieve analysis image and its ROI
    srcImp = WindowManager.getCurrentImage();
    if (!validRequirements(srcImp))
        return;

    title = srcImp.getTitle();
    rootRoi = srcImp.getRoi();
    validRootRoi = (rootRoi != null && rootRoi.getType() == Roi.RECTANGLE);

    // TODO: 3D Roots are special. We need to:
    // 1) Check if ROI is associated with all slices or just one
    // 2) Ignore counts above/below the ROI, as needed
    // 3) Extend ip operations to stack
    if (srcImp.getNSlices() > 1) {
        final String warning = "3D images are currently supported with the following limitations:\n"
                + "    - 'Root-protecting' ROIs are not yet supported\n"
                + "    - Lengths are estimated from Z-projections\n \n"
                + "These issues will be addressed in future releases.";
        if (IJ.macroRunning())
            IJ.log(warning);
        else
            IJ.showMessage("Warning", warning);
        validRootRoi = false;
    }

    // Retrieve grayscale image for intensity-based pruning of skel. loops
    if (!getSettings())
        return;

    // Work on a skeletonized copy since we'll be modifing the image
    if (rootRoi != null)
        srcImp.killRoi();
    final ImagePlus imp = srcImp.duplicate();
    if (rootRoi != null)
        srcImp.setRoi(rootRoi);
    ip = imp.getProcessor();
    skeletonizeWithoutHermits(imp);

    // Initialize ResultsTable: main and detailed info
    final ResultsTable rt = Utils.getTable(STRAHLER_TABLE);
    final ResultsTable logrt = Utils.getTable(VERBOSE_TABLE);

    // Analyze root
    ImagePlus rootImp;
    ImageProcessor rootIp = null;
    SkeletonResult rootResult = null;
    ArrayList<Point> rootEndpointsList = null;
    int nRootEndpoints = 0, nRootJunctions = 0;

    if (validRootRoi && verbose) {

        // Duplicate entire canvas. Ignore tree(s) outside ROI
        rootImp = imp.duplicate();
        rootIp = rootImp.getProcessor();
        rootIp.setValue(0.0);
        rootIp.fillOutside(rootRoi);

        // Get root properties
        final AnalyzeSkeleton_ root = new AnalyzeSkeleton_();
        root.setup("", rootImp);
        rootResult = root.run(pruneChoice, false, false, grayscaleImp, true, false);
        rootImp.flush();

        // We assume ROI contains only end-point branches, slab voxels and
        // no junction points. We'll thus remove end-points at ROI
        // boundaries
        nRootJunctions = sum(rootResult.getJunctions());
        rootEndpointsList = rootResult.getListOfEndPoints();
        final ListIterator<Point> it = rootEndpointsList.listIterator();
        final Rectangle r = rootRoi.getBounds();
        while (it.hasNext()) {
            final Point p = it.next();
            if (p.x == r.x || p.y == r.y || p.x == (int) (r.x + r.getWidth() - 1)
                    || p.y == (int) (r.y + r.getHeight() - 1))
                it.remove();
        }
        rootResult.setListOfEndPoints(rootEndpointsList);
        nRootEndpoints = rootEndpointsList.size();

    }

    // Initialize display images. Use Z-projections to populate
    // iteration stack when dealing with 3D skeletons
    final int nSlices = imp.getNSlices();
    ZProjector zp = null;

    final ImageStack iterationStack = new ImageStack(imp.getWidth(), imp.getHeight());
    if (nSlices > 1) {
        zp = new ZProjector(imp);
        zp.setMethod(ZProjector.MAX_METHOD);
        zp.setStartSlice(1);
        zp.setStopSlice(nSlices);
    }

    // Initialize AnalyzeSkeleton_
    final AnalyzeSkeleton_ as = new AnalyzeSkeleton_();
    as.setup("", imp);

    // Perform the iterative pruning
    int order = 1, nEndpoints = 0, nJunctions = 0, nJunctions2 = 0;
    ArrayList<Point> endpointsList = null, junctionsList = null;
    String errorMsg = "";

    do {

        IJ.showStatus("Retrieving measurements for order " + order + "...");
        IJ.showProgress(order, getMaxOrder());

        // (Re)skeletonize image
        if (order > 1)
            skeletonizeWithoutHermits(imp);

        // Get properties of loop-resolved tree(s)
        final SkeletonResult sr = as.run(pruneChoice, false, false, grayscaleImp, true, false);
        nEndpoints = sum(sr.getEndPoints());
        nJunctions = sum(sr.getJunctions());

        if (order == 1) {
            // Remember initial properties
            endpointsList = sr.getListOfEndPoints();
            junctionsList = sr.getListOfJunctionVoxels();

            // Do not include root in 1st order calculations
            nEndpoints -= nRootEndpoints;
            nJunctions -= nRootJunctions;
        }

        // Is it worth proceeding?
        if (nEndpoints == 0 || nJunctions2 == nJunctions) {
            errorMsg = "Error! Iteration " + order + " aborted: ";
            errorMsg += (nEndpoints == 0) ? "No end-poins found" : "Unsolved loop(s) detected";
            break;
        }

        // Add current tree(s) to debug animation
        ImageProcessor ipd;
        if (nSlices > 1) {
            zp.doProjection();
            ipd = zp.getProjection().getProcessor();
        } else {
            ipd = ip.duplicate();
        }
        iterationStack.addSlice("Order " + IJ.pad(order, 2), ipd);

        // Report properties of pruned structures
        if (verbose) {
            logrt.incrementCounter();
            logrt.addValue("Image", title);
            logrt.addValue("Structure", "Skel. at iteration " + Integer.toString(order));
            logrt.addValue("Notes", errorMsg);
            logrt.addValue("# Trees", sr.getNumOfTrees());
            logrt.addValue("# Branches", sum(sr.getBranches()));
            logrt.addValue("# End-points", nEndpoints);
            logrt.addValue("# Junctions", nJunctions);
            logrt.addValue("# Triple points", sum(sr.getTriples()));
            logrt.addValue("# Quadruple points", sum(sr.getQuadruples()));
            logrt.addValue("Average branch length", average(sr.getAverageBranchLength()));
        }

        // Remember main results
        nJunctions2 = nJunctions;

        // Eliminate end-points
        as.run(pruneChoice, true, false, grayscaleImp, true, false, rootRoi);

    } while (order++ <= getMaxOrder() && nJunctions > 0);

    // Set counter to the de facto order
    order -= 1;

    // Append root properties to log table
    if (validRootRoi && verbose) {

        // Check if ROI contains unexpected structures
        final String msg = (nRootJunctions > 0) ? "Warning: ROI contains ramified root(s)"
                : "Root-branches inferred from ROI";
        logrt.incrementCounter();
        logrt.addValue("Image", title);
        logrt.addValue("Structure", "Root");
        logrt.addValue("Notes", msg);
        logrt.addValue("# Trees", rootResult.getNumOfTrees());
        logrt.addValue("# Branches", sum(rootResult.getBranches()));
        logrt.addValue("# End-points", nRootEndpoints);
        logrt.addValue("# Junctions", nRootJunctions);
        logrt.addValue("# Triple points", sum(rootResult.getTriples()));
        logrt.addValue("# Quadruple points", sum(rootResult.getQuadruples()));
        logrt.addValue("Average branch length", average(rootResult.getAverageBranchLength()));

    }

    // Safety check
    if (iterationStack == null || iterationStack.getSize() < 1) {
        error("Enable \"detailed\" mode and check " + VERBOSE_TABLE + " for details.");
        return;
    }

    // Create iteration stack
    final Calibration cal = srcImp.getCalibration();
    final ImagePlus imp2 = new ImagePlus("StrahlerIteration_" + title, iterationStack);
    imp2.setCalibration(cal);
    if (outIS) {
        if (validRootRoi) {
            iterationStack.addSlice("Root", rootIp);
            paintPoints(iterationStack, rootEndpointsList, 255, "Root end-points");
            imp2.setRoi(rootRoi);
        }
        paintPoints(iterationStack, endpointsList, 255, "End-points");
        paintPoints(iterationStack, junctionsList, 255, "Junction-points");
    }

    // Generate Strahler mask
    zp = new ZProjector(imp2);
    zp.setMethod(ZProjector.SUM_METHOD);
    zp.setStartSlice(1);
    zp.setStopSlice(order);
    zp.doProjection();
    final ImageProcessor ip3 = zp.getProjection().getProcessor().convertToShortProcessor(false);
    clearPoints(ip3, junctionsList); // disconnect branches
    ip3.multiply(1 / 255.0); // map intensities to Strahler orders
    final ImagePlus imp3 = new ImagePlus("StrahlerMask_" + title, ip3);
    imp3.setCalibration(cal);

    // Measure segmented orders
    double prevNbranches = Double.NaN;
    for (int i = 1; i <= order; i++) {

        // Segment branches by order
        final ImagePlus maskImp = imp3.duplicate(); // Calibration is
        // retained
        IJ.setThreshold(maskImp, i, i);
        IJ.run(maskImp, "Convert to Mask", "");

        // Analyze segmented order
        final AnalyzeSkeleton_ maskAs = new AnalyzeSkeleton_();
        maskAs.setup("", maskImp);
        final SkeletonResult maskSr = maskAs.run(pruneChoice, false, false, grayscaleImp, true, false);
        maskImp.flush();

        // Since all branches are disconnected at this stage, the n. of
        // branches is
        // the same as the # the trees unless zero-branches trees exist,
        // i.e., trees
        // with no slab voxels (defined by just an end-point). We will
        // ignore those
        // trees if the user requested it
        final int nBranches = (erodeIsolatedPixels) ? sum(maskSr.getBranches()) : maskSr.getNumOfTrees();

        // Log measurements
        rt.incrementCounter();
        rt.addValue("Image", title);
        rt.addValue("Strahler Order", i);
        rt.addValue("# Branches", nBranches);
        rt.addValue("Ramification ratios", prevNbranches / nBranches);
        rt.addValue("Average branch length", average(maskSr.getAverageBranchLength()));
        rt.addValue("Unit", cal.getUnit());
        String noteMsg = "";
        if (i == 1) {
            noteMsg = (erodeIsolatedPixels) ? "Ignoring" : "Including";
            noteMsg += " single-point arbors...";
        }
        rt.addValue("Notes", noteMsg);

        // Remember results for previous order
        prevNbranches = nBranches;

    }

    // Append any errors to last row
    rt.addValue("Notes", errorMsg);

    // Display outputs
    if (!tabular) {
        if (outIS)
            imp2.show();
        ip3.setMinAndMax(0, order);
        ColorMaps.applyMagmaColorMap(imp3, 200, false);
        if (validRootRoi)
            imp3.setRoi(rootRoi);
        imp3.show();
        addCalibrationBar(imp3, Math.min(order, 5), "Black");
    }
    if (verbose)
        logrt.show(VERBOSE_TABLE);
    rt.show(STRAHLER_TABLE);

    IJ.showProgress(0, 0);
    IJ.showTime(imp, imp.getStartTime(), "Strahler Analysis concluded... ");
    imp.flush();

}

From source file:net.rptools.maptool.client.ui.ChatTypingNotification.java

/**
 * This component is only made visible when there are notifications to be displayed. That means the first couple of
 * IF statements in this method are redundant since paintComponent() will not be called unless the component is
 * visible, and it will only be visible when there are notifications...
 *///from   w  w  w  .j  a  va 2 s. c o m
@Override
protected void paintComponent(Graphics g) {
    //      System.out.println("Chat panel is painting itself...");
    if (AppPreferences.getTypingNotificationDuration() == 0) {
        return;
    }
    LinkedMap chatTypers = MapTool.getFrame().getChatNotificationTimers().getChatTypers();
    if (chatTypers == null || chatTypers.isEmpty()) {
        return;
    }
    Boolean showBackground = AppPreferences.getChatNotificationShowBackground();

    Graphics2D statsG = (Graphics2D) g.create();

    Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD);
    Font font = AppStyle.labelFont;
    FontMetrics valueFM = g.getFontMetrics(font);
    FontMetrics keyFM = g.getFontMetrics(boldFont);

    int PADDING7 = 7;
    int PADDING3 = 3;
    int PADDING2 = 2;

    BufferedImage img = AppStyle.panelTexture;
    int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight());

    setBorder(null);
    int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin();
    int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin()
            + AppStyle.miniMapBorder.getBottomMargin();

    statsG.setFont(font);
    SwingUtil.useAntiAliasing(statsG);
    Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(),
            height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width,
            getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin()
                    + PADDING2);

    int y = bounds.y + rowHeight;
    rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight());

    setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight)) + AppStyle.miniMapBorder.getTopMargin()
            + AppStyle.miniMapBorder.getBottomMargin()));

    if (showBackground) {
        g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this);
        AppStyle.miniMapBorder.paintAround(statsG, bounds);
    }
    Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7,
            AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(),
            AppStyle.chatImage.getHeight());

    Set<?> keySet = chatTypers.keySet();
    @SuppressWarnings("unchecked")
    Set<String> playerTimers = (Set<String>) keySet;
    for (String playerNamer : playerTimers) {
        if (showBackground) {
            statsG.setColor(new Color(249, 241, 230, 140));
            statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                    (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
            statsG.setColor(new Color(175, 163, 149));
            statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                    (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
        }
        g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(),
                (int) rightRow.getHeight(), this);

        // Values
        statsG.setColor(MapTool.getFrame().getChatTypingLabelColor());
        statsG.setFont(boldFont);
        statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer),
                bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5);

        y += PADDING2 + rowHeight;
    }
    if (showBackground) {
        AppStyle.shadowBorder.paintWithin(statsG, bounds);
    } else {
        setOpaque(false);
    }
}

From source file:edu.umn.cs.spatialHadoop.core.OGCJTSShape.java

/**
 * Plots a Geometry from the library JTS into the given image.
 * @param graphics//from  ww  w .java 2s .  c  o m
 * @param geom
 * @param fileMbr
 * @param imageWidth
 * @param imageHeight
 * @param scale
 * @param shape_color
 * @deprecated - use {@link #drawJTSGeom(Graphics, Geometry, double, double)}
 */
@Deprecated
private static void drawJTSShape(Graphics graphics, Geometry geom, Rectangle fileMbr, int imageWidth,
        int imageHeight, double scale, Color shape_color) {
    if (geom instanceof GeometryCollection) {
        GeometryCollection geom_coll = (GeometryCollection) geom;
        for (int i = 0; i < geom_coll.getNumGeometries(); i++) {
            Geometry sub_geom = geom_coll.getGeometryN(i);
            // Recursive call to draw each geometry
            drawJTSShape(graphics, sub_geom, fileMbr, imageWidth, imageHeight, scale, shape_color);
        }
    } else if (geom instanceof com.vividsolutions.jts.geom.Polygon) {
        com.vividsolutions.jts.geom.Polygon poly = (com.vividsolutions.jts.geom.Polygon) geom;

        for (int i = 0; i < poly.getNumInteriorRing(); i++) {
            LineString ring = poly.getInteriorRingN(i);
            drawJTSShape(graphics, ring, fileMbr, imageWidth, imageHeight, scale, shape_color);
        }

        drawJTSShape(graphics, poly.getExteriorRing(), fileMbr, imageWidth, imageHeight, scale, shape_color);
    } else if (geom instanceof LineString) {
        LineString line = (LineString) geom;
        double geom_alpha = line.getLength() * scale;
        int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255);
        if (color_alpha == 0)
            return;

        int[] xpoints = new int[line.getNumPoints()];
        int[] ypoints = new int[line.getNumPoints()];

        for (int i = 0; i < xpoints.length; i++) {
            double px = line.getPointN(i).getX();
            double py = line.getPointN(i).getY();

            // Transform a point in the polygon to image coordinates
            xpoints[i] = (int) Math.round((px - fileMbr.x1) * imageWidth / fileMbr.getWidth());
            ypoints[i] = (int) Math.round((py - fileMbr.y1) * imageHeight / fileMbr.getHeight());
        }

        // Draw the polygon
        //graphics.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
        graphics.drawPolyline(xpoints, ypoints, xpoints.length);
    }
}

From source file:com.t3.client.ui.ChatTypingNotification.java

/**
 * This component is only made visible when there are notifications to be displayed. That means the first couple of
 * IF statements in this method are redundant since paintComponent() will not be called unless the component is
 * visible, and it will only be visible when there are notifications...
 *//* w ww. j  a v  a  2s .co  m*/
@Override
protected void paintComponent(Graphics g) {
    //      System.out.println("Chat panel is painting itself...");
    if (AppPreferences.getTypingNotificationDuration() != 0) {
        LinkedMap<String, Long> chatTypers = TabletopTool.getFrame().getChatNotificationTimers()
                .getChatTypers();
        if (chatTypers == null || chatTypers.isEmpty()) {
            return;
        }
        Boolean showBackground = AppPreferences.getChatNotificationShowBackground();

        Graphics2D statsG = (Graphics2D) g.create();

        Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD);
        Font font = AppStyle.labelFont;
        FontMetrics valueFM = g.getFontMetrics(font);
        FontMetrics keyFM = g.getFontMetrics(boldFont);

        int PADDING7 = 7;
        int PADDING3 = 3;
        int PADDING2 = 2;

        BufferedImage img = AppStyle.panelTexture;
        int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight());

        setBorder(null);
        int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin();
        int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin()
                + AppStyle.miniMapBorder.getBottomMargin();

        statsG.setFont(font);
        SwingUtil.useAntiAliasing(statsG);
        Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(),
                height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width,
                getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin()
                        + PADDING2);

        int y = bounds.y + rowHeight;
        rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight());

        setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight))
                + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin()));

        if (showBackground) {
            g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this);
            AppStyle.miniMapBorder.paintAround(statsG, bounds);
        }
        Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7,
                AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(),
                AppStyle.chatImage.getHeight());

        Set<?> keySet = chatTypers.keySet();
        @SuppressWarnings("unchecked")
        Set<String> playerTimers = (Set<String>) keySet;
        Color c1 = new Color(249, 241, 230, 140);
        Color c2 = new Color(175, 163, 149);
        for (String playerNamer : playerTimers) {
            if (showBackground) {
                statsG.setColor(c1);
                statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                        (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
                statsG.setColor(c2);
                statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                        (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
            }
            g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(),
                    (int) rightRow.getHeight(), this);

            // Values
            statsG.setColor(TabletopTool.getFrame().getChatTypingLabelColor());
            statsG.setFont(boldFont);
            statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer),
                    bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5);

            y += PADDING2 + rowHeight;
        }
        if (showBackground) {
            AppStyle.shadowBorder.paintWithin(statsG, bounds);
        } else {
            setOpaque(false);
        }
    }
}

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;//ww w  .j  a  va2s  .  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);
}