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() 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is at (0, 0) in the coordinate space, and whose width and height are both zero.

Usage

From source file:es.ubu.XRayDetector.interfaz.PanelAplicacion.java

/**
 * Initialize the contents of the frame.
 *//* ww  w  .j  av  a2 s .  c  o m*/
private void initialize() {

    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (ClassNotFoundException e) {
        MyLogHandler.writeException(e);
        e.printStackTrace();
    } catch (InstantiationException e) {
        MyLogHandler.writeException(e);
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        MyLogHandler.writeException(e);
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        MyLogHandler.writeException(e);
        e.printStackTrace();
    }

    getJFramePrincipal();

    JPanel panelControl = getPanelControl();

    getBtnAbrirImagen(panelControl);

    getBtnEntrenar(panelControl);

    getBtnAnalizar(panelControl);

    JPanel panelProgreso = getPanelProgreso();

    getProgressBar(panelProgreso);

    getBtnStop(panelProgreso);

    JPanel panelImagen = getPanelImagen();

    getImgPanel(panelImagen);

    JPanel panelLog = getPanelLog();

    txtLog = getTxtLog(panelLog);

    getBotonExportarLog();
    getBotonLimpiarLog();

    JPanel panelSlider = getPanelSlider();

    getSlider(panelSlider);

    getPanelTabla();

    getTablaResultados(panelTabla_1);
    imgPanel.setFocusable(true);

    JPanel panelAnalizarResultados = getPanelAnalizarResultados();

    getButtonGuardarImagenAnalizada(panelAnalizarResultados);

    getButtonGuardarImagenBinarizada(panelAnalizarResultados);

    getButtonPrecisionRecall(panelAnalizarResultados);

    selectionCopy = new Rectangle();

    try {
        File fichero = new File("./res/ayuda/ayuda.hs");
        URL hsURL = fichero.toURI().toURL();
        HelpSet hs = new HelpSet(null, hsURL);
        HelpBroker hb = hs.createHelpBroker();
        hb.enableHelpKey(frmXraydetector.getContentPane(), "ventanaentrenamientodeteccion", hs);
    } catch (MalformedURLException e) {
        MyLogHandler.writeException(e);
        e.printStackTrace();
    } catch (HelpSetException e) {
        MyLogHandler.writeException(e);
        e.printStackTrace();
    }

}

From source file:org.projectforge.statistics.TimesheetDisciplineChartBuilder.java

private JFreeChart create(final TimeSeries series1, final TimeSeries series2, final Shape shape,
        final Stroke stroke, final boolean showAxisValues, final String valueAxisUnitKey) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series1);/*from  w w  w .j av  a 2 s.c  om*/
    dataset.addSeries(series2);
    final JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
            true, true, false);

    final XYDifferenceRenderer renderer = new XYDifferenceRenderer(new Color(238, 176, 176),
            new Color(135, 206, 112), true);
    renderer.setSeriesPaint(0, new Color(222, 23, 33));
    renderer.setSeriesPaint(1, new Color(64, 169, 59));
    if (shape != null) {
        renderer.setSeriesShape(0, shape);
        renderer.setSeriesShape(1, shape);
    } else {
        final Shape none = new Rectangle();
        renderer.setSeriesShape(0, none);
        renderer.setSeriesShape(1, none);
    }
    renderer.setSeriesStroke(0, stroke);
    renderer.setSeriesStroke(1, stroke);
    renderer.setSeriesVisibleInLegend(0, false);
    renderer.setSeriesVisibleInLegend(1, false);
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    final DateAxis xAxis = new DateAxis();
    xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setVisible(showAxisValues);
    plot.setDomainAxis(xAxis);
    final NumberAxis yAxis;
    if (showAxisValues == true) {
        yAxis = new NumberAxis(PFUserContext.getLocalizedString(valueAxisUnitKey));
    } else {
        yAxis = new NumberAxis();
    }
    yAxis.setVisible(showAxisValues);
    plot.setRangeAxis(yAxis);
    plot.setOutlineVisible(false);
    return chart;
}

From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java

/**
 * Call this after changing the rectangle in any way. It removes rectangles
 * of size less than 1, and it also converts "composed" rectangles with
 * only one rectangle to uncomposed; it also updates the polygon.
 *//*from w  ww .jav a  2 s .c  o m*/
private void simplify() {
    boolean startedComposed = composed;
    if (composed) {
        if (pieces.size() == 0) {
            pieces = null;
            composed = false;
            rect = new Rectangle();
        } else if (pieces.size() == 1) {
            BoundingBox child = (BoundingBox) pieces.getFirst();
            composed = false;
            if (child != null)
                setTo(child);
            else
                pieces.clear();
        } else if (pieces.size() > 1) {
            boolean changed = false;
            ListIterator iter = pieces.listIterator(0);
            while (iter.hasNext())
                if (!(((BoundingBox) iter.next()).area()).greaterThan(0)) {
                    iter.remove();
                    changed = true;
                }
            if (changed)
                simplify();
        }
    }
    if (startedComposed && !composed)
        initPoly();
}

From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.PPTData.java

/**
 * Set a slide//  w  ww.  ja va2s .  c o  m
 * 
 * @param methodToCall method to invoke to create slide
 * @param where reference for setting
 * @param slide page number of slide to change
 * @throws PPTGeneratorException if error
 */
private void setSlide(Method methodToCall, String where, int slide) throws PPTGeneratorException {
    if (slide > presentation.getSlides().length || slide < 1) {
        handleException("export.audit_report.mapping.error.presentation_slide", new String[] { "" + slide });
    }
    try {
        Slide slideToSet = getPresentation().getSlides()[slide - 1];
        Rectangle whereRec = new Rectangle();
        for (int i = 0; i < slideToSet.getShapes().length; i++) {
            if (slideToSet.getShapes()[i] instanceof TextBox
                    && ((TextBox) slideToSet.getShapes()[i]).getText() != null
                    && where.equalsIgnoreCase(((TextBox) slideToSet.getShapes()[i]).getText().trim())) {
                whereRec = slideToSet.getShapes()[i].getAnchor();

            }
        }
        methodToCall.invoke(this, new Object[] { slideToSet, whereRec });
    } catch (IllegalArgumentException e) {
        handleException("export.audit_report.mapping.error.method_args",
                new String[] { methodToCall.getName() });
    } catch (IllegalAccessException e) {
        handleException("export.audit_report.mapping.error.method.access",
                new String[] { methodToCall.getName() });
    } catch (InvocationTargetException e) {
        handleException("export.audit_report.mapping.error.method_exception",
                new String[] { methodToCall.getName(), e.getMessage() });
    }
}

From source file:fxts.stations.ui.SideLayout.java

/**
 * Lays out the grid.//www . j a  v a2 s.c o  m
 *
 * @param aParent the layout container
 */
protected void arrangeGrid(Container aParent) {
    /////////////////////////////////////////////////////////
    //It`s only for debugging
    JComponent jc = (JComponent) aParent;
    String sType = (String) jc.getClientProperty("TYPE");
    if (sType != null) {
        boolean bInternal = "internal".equals(sType);
        mLogger.debug("\n" + sType);
    }
    //////////////////////////////////////////////////////////
    Component comp;
    int compindex;
    SideConstraints constraints;
    Insets insets = aParent.getInsets();
    Component[] components = aParent.getComponents();
    Dimension d;
    Rectangle r = new Rectangle();
    int i, diffw, diffh;
    double weight;
    SideLayoutInfo info;
    mRightToLeft = !aParent.getComponentOrientation().isLeftToRight();

    /*
    * If the parent has no slaves anymore, then don't do anything
    * at all:  just leave the parent's size as-is.
    */
    if (components.length == 0 && (mColumnWidths == null || mColumnWidths.length == 0)
            && (mRowHeights == null || mRowHeights.length == 0)) {
        return;
    }

    /*
    * Pass #1: scan all the slaves to figure out the total amount
    * of space needed.
    */

    info = getLayoutInfo(aParent, PREFERREDSIZE);
    d = getMinSize(aParent, info);

    //
    //    System.out.println("parent=w:" + parent.getWidth() + ",h:" + parent.getHeight() +
    //                       "min=w:" + d.getWidth() + ",h:" + d.getHeight());
    if (aParent.getWidth() < d.width || aParent.getHeight() < d.height) {
        info = getLayoutInfo(aParent, MINSIZE);
        d = getMinSize(aParent, info);
        //
        //      System.out.println("MINSIZE");
    } else {
        //
        //      System.out.println("Non MINSIZE");
    }
    mLayoutInfo = info;
    r.width = d.width;
    r.height = d.height;

    /*
    * If the current dimensions of the window don't match the desired
    * dimensions, then adjust the minWidth and minHeight arrays
    * according to the weights.
    */

    diffw = aParent.getWidth() - r.width;
    //
    //    System.out.println("diffw=" + diffw);
    if (diffw != 0) {
        weight = 0.0;
        for (i = 0; i < info.width; i++) {
            weight += info.weightX[i];
        }
        if (weight > 0.0) {
            for (i = 0; i < info.width; i++) {
                int dx = (int) (((double) diffw * info.weightX[i]) / weight);
                info.minWidth[i] += dx;
                r.width += dx;
                if (info.minWidth[i] < 0) {
                    r.width -= info.minWidth[i];
                    info.minWidth[i] = 0;
                }
            }
        }
        diffw = aParent.getWidth() - r.width;
    } else {
        diffw = 0;
    }
    diffh = aParent.getHeight() - r.height;
    //
    //    System.out.println("diffh=" + diffh);
    if (diffh != 0) {
        weight = 0.0;
        for (i = 0; i < info.height; i++) {
            weight += info.weightY[i];
        }
        if (weight > 0.0) {
            for (i = 0; i < info.height; i++) {
                int dy = (int) (((double) diffh * info.weightY[i]) / weight);
                info.minHeight[i] += dy;
                r.height += dy;
                if (info.minHeight[i] < 0) {
                    r.height -= info.minHeight[i];
                    info.minHeight[i] = 0;
                }
            }
        }
        diffh = aParent.getHeight() - r.height;
    } else {
        diffh = 0;
    }

    /*
    * Now do the actual layout of the slaves using the layout information
    * that has been collected.
    */

    info.startx = /*diffw/2 +*/ insets.left;
    info.starty = /*diffh/2 +*/ insets.top;
    //
    //    System.out.println("info.startx = " + info.startx);
    //    System.out.println("info.starty = " + info.startx);
    for (compindex = 0; compindex < components.length; compindex++) {
        comp = components[compindex];
        if (!comp.isVisible()) {
            continue;
        }
        constraints = lookupConstraints(comp);
        if (!mRightToLeft) {
            r.x = info.startx;
            for (i = 0; i < constraints.tempX; i++) {
                r.x += info.minWidth[i];
            }
        } else {
            r.x = aParent.getWidth() - insets.right;
            for (i = 0; i < constraints.tempX; i++) {
                r.x -= info.minWidth[i];
            }
        }
        r.y = info.starty;
        for (i = 0; i < constraints.tempY; i++) {
            r.y += info.minHeight[i];
        }
        r.width = 0;
        for (i = constraints.tempX; i < constraints.tempX + constraints.tempWidth; i++) {
            r.width += info.minWidth[i];
        }
        r.height = 0;
        for (i = constraints.tempY; i < constraints.tempY + constraints.tempHeight; i++) {
            r.height += info.minHeight[i];
        }
        adjustForGravity(constraints, r);
        if (r.x < 0) {
            r.width -= r.x;
            r.x = 0;
        }
        if (r.y < 0) {
            r.height -= r.y;
            r.y = 0;
        }

        /*
        * If the window is too small to be interesting then
        * unmap it.  Otherwise configure it and then make sure
        * it's mapped.
        */

        if (r.width <= 0 || r.height <= 0) {
            comp.setBounds(0, 0, 0, 0);
        } else {
            if (comp.getX() != r.x || comp.getY() != r.y || comp.getWidth() != r.width
                    || comp.getHeight() != r.height) {
                comp.setBounds(r.x, r.y, r.width, r.height);
            }
        }

        //        System.out.println("Initial component size (x = " + (int)comp.getX() +
        //                           ", y = " + (int)(comp.getY()) +
        //                           ", widht = " + (int)(comp.getWidth()) +
        //                           ", height = " + (int)(comp.getHeight()));
        if (diffw > 0) {
            //            System.out.println("It`s increasing by x!");
            //if (comp instanceof IResizableComponent) {
            //                System.out.println("It`s resizable component: " + comp);

            //IResizableComponent resizeComp = (IResizableComponent)comp;
            ResizeParameter param = constraints.resize;

            //                System.out.println("Params: Left=" + param.getLeft() + ",top=" + param.getTop() +
            //                                   ",Right=" + param.getRight() + ",bottom=" + param.getBottom());
            comp.setBounds((int) (comp.getX() + diffw * param.getLeft()), comp.getY(),
                    (int) (comp.getWidth() + diffw * (param.getRight() - param.getLeft())), comp.getHeight());

            //                System.out.println("Set Bounds (x = " + (int)(comp.getX() + diffw * param.getLeft()) +
            //                    ", y = " + (int)(comp.getY()) +
            //                    ", widht = " + (int)(comp.getWidth() +
            ///                                     diffw * (param.getRight() - param.getLeft())) +
            //                    ", height = " + (int)(comp.getHeight()));
            //            }
        }
        if (diffh > 0) {
            //            System.out.println("It`s increasing by y!");
            //            if (comp instanceof IResizableComponent) {
            //                System.out.println("It`s resizable component: " + comp);

            //                IResizableComponent resizeComp = (IResizableComponent)comp;
            ResizeParameter param = constraints.resize;

            //                System.out.println("Params: Left=" + param.getLeft() + ",top=" + param.getTop() +
            //                                   ",Right=" + param.getRight() + ",bottom=" + param.getBottom());
            comp.setBounds(comp.getX(), (int) (comp.getY() + diffh * param.getTop()), comp.getWidth(),
                    (int) (comp.getHeight() + diffh * (param.getBottom() - param.getTop())));

            //                System.out.println("Set Bounds (x = " + (int)(comp.getX()) +
            //                    ", y = " + (int)(comp.getY() + diffh * param.getTop()) +
            //                    ", widht = " + (int)(comp.getWidth()) +
            //                    ", height = " + (int)(comp.getHeight() +
            //                                     diffh * (param.getBottom() - param.getTop())));
            //            }
        }
    }
}

From source file:main.java.whiteSocket.Bloop.java

public static float[] setUnitTextbox(int[] corners) {
    /*//from  w  w  w. j av  a 2  s.  c om
    returns Rectangle to  -> x,y,width,height
    */

    Rectangle rect = new Rectangle();
    int x = corners[0];
    int y = corners[1];

    //      corner order UL, UR, LL, LR in x,y sequence

    int width = 0;
    int height = 0;

    if (corners[2] >= corners[6]) {
        width = corners[6] - x;
    } else {
        width = corners[2] - x;
    }

    if (corners[5] > corners[7]) {
        height = corners[7] - y;
    } else {
        height = corners[5] - y;
    }

    //   scales to display output
    double x2 = (double) x / (double) sketch.getWidth() * (double) blooprint.getWidth();
    double y2 = (double) y / (double) sketch.getHeight() * (double) blooprint.getHeight();
    double width2 = (double) width / (double) sketch.getWidth() * (double) blooprint.getWidth();
    double height2 = (double) height / (double) sketch.getHeight() * (double) blooprint.getHeight();

    int aa = (int) Math.round(x2);
    int bb = (int) Math.round(y2);
    int cc = (int) Math.round(width2);
    int dd = (int) Math.round(height2);

    rect.setBounds(aa, bb, cc, dd);

    /*
    Unit boc in order to scale to any client side browser screen dimensions.
    Must be re-scaled to web application DOM element textarea location
    */
    float[] unit = new float[4];
    unit[0] = (float) aa / (float) blooprint.getWidth();
    unit[1] = (float) bb / (float) blooprint.getHeight();
    unit[2] = (float) cc / (float) blooprint.getWidth();
    unit[3] = (float) dd / (float) blooprint.getHeight();

    return unit;
}

From source file:de.dakror.villagedefense.game.entity.struct.Struct.java

public Shape getAttackArea() {
    return new Rectangle();
}

From source file:com.att.aro.main.PacketPlots.java

/**
 * The utility method that creates the packet plots from a packet series map
 *///from   ww  w. j  ava2s .  com
private XYPlot createPlot() {

    // Create the plot renderer
    YIntervalRenderer renderer = new YIntervalRenderer() {
        private static final long serialVersionUID = 1L;

        public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
                PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {

            // setup for collecting optional entity info...
            Shape entityArea = null;
            EntityCollection entities = null;
            if (info != null) {
                entities = info.getOwner().getEntityCollection();
            }

            IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

            double x = intervalDataset.getXValue(series, item);
            double yLow = intervalDataset.getStartYValue(series, item);
            double yHigh = intervalDataset.getEndYValue(series, item);

            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

            double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
            double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

            Paint p = getItemPaint(series, item);
            Stroke s = getItemStroke(series, item);

            Line2D line = null;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                line = new Line2D.Double(yyLow, xx, yyHigh, xx);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line = new Line2D.Double(xx, yyLow, xx, yyHigh);
            }
            g2.setPaint(p);
            g2.setStroke(s);
            g2.draw(line);

            // add an entity for the item...
            if (entities != null) {
                if (entityArea == null) {
                    entityArea = line.getBounds();
                }
                String tip = null;
                XYToolTipGenerator generator = getToolTipGenerator(series, item);
                if (generator != null) {
                    tip = generator.generateToolTip(dataset, series, item);
                }
                XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null);
                entities.add(entity);
            }

        }

    };
    renderer.setAdditionalItemLabelGenerator(null);
    renderer.setBaseShape(new Rectangle());
    renderer.setAutoPopulateSeriesShape(false);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBasePaint(Color.GRAY);

    // Create the plot
    XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setVisible(false);

    return plot;
}

From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * Displays help window//from  w  w  w.  ja  v  a 2 s  .  c om
 */
private void help() {
    String msg = "";

    MutableDataSet options = new MutableDataSet();
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();

    try {
        msg = IOUtils.toString(Main.getFile("Usage.md", this));
        Node document = parser.parse(msg);
        msg = renderer.render(document);
    } catch (IOException e) {
        e.printStackTrace();
    }

    JTextPane area = new JTextPane();
    area.setContentType("text/html");
    area.setText(msg);
    area.setCaretPosition(0);
    area.setEditable(false);

    JScrollPane scrollPane = new JScrollPane(area);
    scrollPane
            .setMaximumSize(new Dimension(GraphicsRunner.SCREEN_SIZE.width, GraphicsRunner.SCREEN_SIZE.height));
    scrollPane.setPreferredSize(
            new Dimension(GraphicsRunner.SCREEN_SIZE.width - 10, GraphicsRunner.SCREEN_SIZE.height - 10));
    scrollPane.scrollRectToVisible(new Rectangle());
    JOptionPane.showMessageDialog(this, scrollPane, "Help", JOptionPane.PLAIN_MESSAGE);
}