Example usage for java.awt Rectangle Rectangle

List of usage examples for java.awt Rectangle Rectangle

Introduction

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

Prototype

public Rectangle(int x, int y, int width, int height) 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.

Usage

From source file:cognitivej.vision.face.task.FaceRectangle.java

public Rectangle asAwtRectangle() {
    return new Rectangle(left, top, width, height);
}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

private void renderRange(LongRange pRange, LongRange pStartRange, LongRange pArriveRange, boolean pIsStartRange,
        boolean pIsArriveRange, Graphics2D pG2D, TimeSpan pSpanForRange, HashMap<String, Object> pPopupInfo) {
    int rangeStart = 0;
    int rangeWidth = 0;

    if (pRange.overlapsRange(pStartRange)) {
        //start range rendering
        long startDelta = pStartRange.getMinimumLong();
        rangeStart = Math.round((pRange.getMinimumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE);
        // int rangeEnd = Math.round((pRange.getMaximumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE);
        rangeWidth = Math//from   www .ja v  a 2  s .  c om
                .round((pRange.getMaximumLong() - pRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE);
    } else if (pRange.overlapsRange(pArriveRange)) {
        //end range rendering
        long startDelta = pStartRange.getMinimumLong();
        rangeStart = Math.round((pRange.getMinimumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE);
        // int rangeEnd = Math.round((pRange.getMaximumLong() - arriveDelta) / DateUtils.MILLIS_PER_MINUTE);
        rangeWidth = Math
                .round((pRange.getMaximumLong() - pRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE);
    }
    //correct small widths
    if (rangeWidth == 0) {
        rangeWidth = 5;
    }

    long max = Math.round(
            (pArriveRange.getMaximumLong() - pStartRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE);

    if (rangeStart > max) {
        return;
    }

    SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
    String labelString = "";
    if (pSpanForRange != null) {
        labelString = pSpanForRange.toString();
    } else {
        labelString = f.format(new Date(pRange.getMinimumLong())) + " bis "
                + f.format(new Date(pRange.getMaximumLong()));
    }
    Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(labelString, pG2D);
    if (pIsStartRange) {
        pG2D.setColor(Color.RED);
        pG2D.fillRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.BLACK);
        pG2D.drawRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.RED);
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 14.0f));
        pG2D.drawString(labelString, rangeStart, (int) labelBounds.getHeight());
    } else if (pIsArriveRange) {
        pG2D.setColor(Color.GREEN.darker());
        pG2D.fillRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.BLACK);
        pG2D.drawRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.GREEN.darker());
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 14.0f));
        pG2D.drawString(labelString, rangeStart, (int) labelBounds.getHeight() + 40);
    } else {
        pG2D.fillRect(rangeStart, 20, rangeWidth, 20);
        pG2D.setColor(Color.BLACK);
        pG2D.drawRect(rangeStart, 20, rangeWidth, 20);
        Point loc = getMousePosition();
        if (loc != null && new Rectangle(rangeStart, 20, rangeWidth, 20).contains(loc)) {
            pPopupInfo.put("popup.location", loc);
            pPopupInfo.put("popup.label", labelString);
            pPopupInfo.put("active.range", pRange);
            pPopupInfo.put("span.for.range", pSpanForRange);

        }
    }
}

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

private void scrollToVisible(int x, int y) {
    int scrollingDistance = 100;
    getGraph().scrollRectToVisible(new Rectangle(x - scrollingDistance, y - scrollingDistance,
            scrollingDistance * 2, scrollingDistance * 2));
}

From source file:OAT.ui.util.UiUtil.java

public static Rectangle[][] getChartFrameGrid() {
    Rectangle mainBound = Main.frame.getBounds();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    screenSize.height = screenSize.height - MENU_BAR_HEIGHT;
    Dimension chartFrameSize = getChartPanelSize();

    chartFrameSize.height += MENU_BAR_HEIGHT;

    int clearWidth = screenSize.width - mainBound.x - mainBound.width;
    int clearHeight = screenSize.height - mainBound.y;

    int x0 = mainBound.x + mainBound.width;
    int y0 = mainBound.y;
    int xN = clearWidth / chartFrameSize.width;
    int yN = clearHeight / chartFrameSize.height;

    Rectangle[][] grid = new Rectangle[yN][xN];

    for (int xI = 0; xI < xN; xI++) {
        for (int yI = 0; yI < yN; yI++) {
            grid[yI][xI] = new Rectangle(x0 + xI * chartFrameSize.width, y0 + yI * chartFrameSize.height,
                    chartFrameSize.width, chartFrameSize.height);
        }/*from w ww.  j a  v a2  s . c  om*/
    }

    return grid;
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.ProfilesComparisonReportChartCanvas.java

private Rectangle getViewArea(double scale) {
    int chart_width = Math.max(CHART_WIDTH, CHART_WIDTH_TICK * theDocument.getNoRows());
    return new Rectangle(0, 0, (int) (2 * DRAW_X_MARGIN + scale * (2 * CHART_X_MARGIN + chart_width)),
            (int) (2 * DRAW_Y_MARGIN + scale * (2 * CHART_X_MARGIN + CHART_HEIGHT)));
}

From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java

public void writeToFile(String outName)
        throws FileNotFoundException, UnsupportedEncodingException, IOException {
    calcMeans();//from   ww w .  jav a  2 s.c  o m
    calcAvgRulesBySeed();

    // Create JFreeChart Dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    HashMap<String, Double> measuresFirst = algorithmMeasures.entrySet().iterator().next().getValue();
    for (Map.Entry<String, Double> measure : measuresFirst.entrySet()) {
        String measureName = measure.getKey();
        //Double measureValue = measure.getValue();
        dataset.clear();

        for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet()) {
            String alg = entry.getKey();
            Double measureValue = entry.getValue().get(measureName);

            // Parse algorithm name to show it correctly
            String aName = alg.substring(0, alg.length() - 1);
            int startAlgName = aName.lastIndexOf("/");
            aName = aName.substring(startAlgName + 1);

            dataset.addValue(measureValue, aName, measureName);

            ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
            JFreeChart barChart = ChartFactory.createBarChart("Assotiation Rules Measures", measureName,
                    measureName, dataset, PlotOrientation.VERTICAL, true, true, false);
            StandardChartTheme.createLegacyTheme().apply(barChart);

            CategoryItemRenderer renderer = barChart.getCategoryPlot().getRenderer();

            // Black and White
            int numItems = algorithmMeasures.size();
            for (int i = 0; i < numItems; i++) {
                Color color = Color.DARK_GRAY;
                if (i % 2 == 1) {
                    color = Color.LIGHT_GRAY;
                }
                renderer.setSeriesPaint(i, color);
                renderer.setSeriesOutlinePaint(i, Color.BLACK);
            }

            int width = 640 * 2; /* Width of the image */
            int height = 480 * 2; /* Height of the image */

            // JPEG
            File BarChart = new File(outName + "_" + measureName + "_barchart.jpg");
            ChartUtilities.saveChartAsJPEG(BarChart, barChart, width, height);

            // SVG
            SVGGraphics2D g2 = new SVGGraphics2D(width, height);
            Rectangle r = new Rectangle(0, 0, width, height);
            barChart.draw(g2, r);
            File BarChartSVG = new File(outName + "_" + measureName + "_barchart.svg");
            SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement());
        }
    }
    /*
    for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet())
    {
    String alg = entry.getKey();
    HashMap<String, Double> measures = entry.getValue();
            
    for (Map.Entry<String, Double> entry1 : measures.entrySet())
    {
        String measureName = entry1.getKey();
        Double measureValue = entry1.getValue();
                
        dataset.addValue(measureValue, alg, measureName);
    }
    }
        */

}

From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java

private void drawSquares(Graphics squares, Point start, Rectangle bounds, Dataset dataset,
        boolean clusterColumns) {
    //        ColorFactory colors = ColorFactoryList.getInstance().getActiveColorFactory(dataset);
    colors = colorFactory.getActiveColorFactory(dataset);
    Rectangle view = getSquaresBounds(dataset);
    squares.translate(start.x, start.y);
    int rows = this.countgenes(this.rowNode);
    int counter = 0;
    double[] gengenscalevals = null;
    int[] upperArrangement = null;
    if (clusterColumns) {
        upperArrangement = upperTree.arrangement;
    } else {//from   w  w w  .j a v  a 2s  . c o  m
        upperArrangement = new int[dataset.getColumnIds().length];
        for (int x = 0; x < dataset.getColumnIds().length; x++)
            upperArrangement[x] = x;
    }
    double[][] dat = null;
    dat = dataset.getData();
    if (sideTree == null) {
        return;
    }
    for (int i = 0; i < sideTree.arrangement.length; i++) {
        double v = 0;
        Rectangle sqr = new Rectangle(0, 0, squareW, squareL);
        for (int j = 0; j < upperArrangement.length; j++) {
            if (bounds == null || bounds.intersects((j * squareW), (i * squareL), squareW, squareL)) {

                if (upperTree != null) {

                    sqr.setLocation((j * squareW), (i * squareL));
                    if (!view.intersects(sqr)) {
                        continue;
                    }

                    if (sideTree.arrangement[i] != -1 && upperArrangement[j] != -1) {

                        if (dataset.isMissing(sideTree.arrangement[i], upperArrangement[j])) {
                            squares.setColor(colors.getMissing());
                        } else {
                            if (!gengenscale) {
                                v = dat[sideTree.arrangement[i]][upperArrangement[j]];
                                squares.setColor(colors.getColor(v));
                            } else {
                                v = gengenscalevals[upperArrangement[j]];
                                squares.setColor(colors.getColor(v));
                            }
                        }
                        squares.fillRect((j * squareW), (i * squareL), squareW, squareL);
                    }
                } else {
                    sqr.setLocation((j * squareW), (i * squareL));
                    if (!view.intersects(sqr)) {
                        continue;
                    }

                    v = dat[sideTree.arrangement[i]][upperArrangement[j]];

                    if (dataset.isMissing(sideTree.arrangement[i], upperArrangement[j])) {
                        squares.setColor(colors.getMissing());
                    } else {
                        squares.setColor(colors.getColor(v));
                    }

                    squares.fillRect((j * squareW), (i * squareL), squareW, squareL);
                }
            }
        }
        counter++;
        if (counter == rows) {
            break;
        }
    }
    counter = 0;
    if (true) {
        squares.setColor(GridCol);
        for (int i = 0; i < sideTree.arrangement.length + 1; i++) {
            if (bounds == null
                    || bounds.intersects(0, i * squareL, upperArrangement.length * squareW, i * squareL)) {
                squares.drawLine(0, i * squareL, (upperArrangement.length * squareW) + 0, i * squareL);
            }
            counter++;
            if (counter > rows) {
                break;
            }
        }
        for (int j = 0; j < upperArrangement.length; j++) {
            if (bounds == null || bounds.intersects(j * squareW, 0, j * squareW, rows * squareL)) {
                squares.drawLine(j * squareW, 0, j * squareW, rows * squareL);
            }
        }

        if (bounds == null || bounds.intersects(upperArrangement.length * squareW, 0,
                upperArrangement.length * squareW, rows * squareL)) {
            squares.drawLine(upperArrangement.length * squareW, 0, upperArrangement.length * squareW,
                    rows * squareL);
        }

    }
    squares.translate(-start.x, -start.y);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.ProfilesComparisonReportChartCanvas.java

private Rectangle getDrawArea(double scale) {
    int chart_width = Math.max(CHART_WIDTH, CHART_WIDTH_TICK * theDocument.getNoRows());
    return new Rectangle(DRAW_X_MARGIN, DRAW_Y_MARGIN, (int) (scale * (2 * CHART_X_MARGIN + chart_width)),
            (int) (scale * (2 * CHART_Y_MARGIN + CHART_HEIGHT)));
}

From source file:JTreeUtil.java

private static void autoscroll(JTree tree, Point cursorLocation) {
    Insets insets = DEFAULT_INSETS;
    Rectangle outer = tree.getVisibleRect();
    Rectangle inner = new Rectangle(outer.x + insets.left, outer.y + insets.top,
            outer.width - (insets.left + insets.right), outer.height - (insets.top + insets.bottom));
    if (!inner.contains(cursorLocation)) {
        Rectangle scrollRect = new Rectangle(cursorLocation.x - insets.left, cursorLocation.y - insets.top,
                insets.left + insets.right, insets.top + insets.bottom);
        tree.scrollRectToVisible(scrollRect);
    }//from w w w  .ja v  a  2  s.c  o  m
}

From source file:cognitivej.vision.computervision.OCRResult.java

@NotNull
public static Rectangle splitBoundingBoxToRectangle(String boundingBox) {
    String[] split = StringUtils.split(boundingBox, ",");
    if (split.length == 4)
        return new Rectangle(valueOf(split[0]), valueOf(split[1]), valueOf(split[2]), valueOf(split[3]));
    else//ww w.  j a va2s. c  o m
        return new Rectangle();
}