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.bsc.autonomic.powermodeller.graphics.TotalPowerVsTotalPrediction.java

public static JPanel createPanel() {
    //Axis configuration
    NumberAxis sampleAxis = new NumberAxis("Sample");
    sampleAxis.setAutoRangeIncludesZero(false);
    NumberAxis powerAxis = new NumberAxis("Power (Watts)");
    powerAxis.setAutoRangeIncludesZero(false);

    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();

    XYPlot xyplot = new XYPlot(data, sampleAxis, powerAxis, xysplinerenderer);
    for (int i = 0; i < data.getSeriesCount(); i++) {
        xyplot.getRenderer().setSeriesShape(i, new Rectangle());
    }//from  w ww . j a v a2 s  . co m

    //Panel layout configuration
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

    JFreeChart jfreechart = new JFreeChart(NAME, JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);

    ChartUtilities.applyCurrentTheme(jfreechart);
    ChartPanel chartpanel = new ChartPanel(jfreechart);

    return chartpanel;
}

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

/**
 * Construct the empty bounding box.
 */
public BoundingBox() {
    rect = new Rectangle();
}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

@Override
public void mouseDragged(MouseEvent e) {
    super.mouseDragged(e);

    ChartPanel chartPanel = getChartPanel(e);
    JFreeChart selectedChart = chartPanel.getChart();
    ChartDescriptor cd = ChartUtils.getChartDescriptor(selectedChart);
    int[] indices = cd.getSourceIndices();

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();

    //Create double buffer
    Image buffer = chartPanel.createImage(chartPanel.getWidth(), chartPanel.getHeight());
    Graphics bufferGraphics = buffer.getGraphics();
    chartPanel.paint(bufferGraphics);/*from ww w .  j  a v  a 2s. com*/

    if (lastX == 0 && lastY == 0) {
        lastX = e.getX();
        lastY = e.getY();
    }

    drawRect = new Rectangle();
    int x1 = Math.min(Math.min(e.getX(), lastX), startX);
    int y1 = Math.min(Math.min(e.getY(), lastY), startY);
    int x2 = Math.max(Math.max(e.getX(), lastX), startX);
    int y2 = Math.max(Math.max(e.getY(), lastY), startY);

    drawRect.x = x1;
    drawRect.y = y1;
    drawRect.width = x2 - drawRect.x;
    drawRect.height = y2 - drawRect.y;

    //Create a clipping rectangle
    Rectangle clipRect = new Rectangle(drawRect.x - 100, drawRect.y - 100, drawRect.width + 200,
            drawRect.height + 200);

    //Check for selected points
    for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) {
        for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) {
            Number xK = plot.getDataset().getX(i, j);
            Number yK = plot.getDataset().getY(i, j);
            Point2D datasetPoint2D = new Point2D.Double(domainValueTo2D(chartPanel, plot, xK.doubleValue()),
                    rangeValueTo2D(chartPanel, plot, yK.doubleValue()));

            if (drawRect.contains(datasetPoint2D)) {
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                boolean pointAdded = mouseDragSelection.addPoint(cp);
                if (pointAdded) {
                    ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(j, i);
                    selectedChart.plotChanged(new PlotChangeEvent(plot));
                }
            } else if (!mouseDragSelection.isEmpty()) {
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                boolean pointRemoved = mouseDragSelection.removePoint(cp);
                if (pointRemoved) {
                    ((ScatterPlotRenderer) plot.getRenderer()).removeMarkedPoint(new Point(j, i));
                    selectedChart.plotChanged(new PlotChangeEvent(plot));
                }
            }
        }
    }

    Iterator<PlotPointData> iterator = currentSelection.iterator();
    while (iterator.hasNext()) {
        PlotPointData next = iterator.next();
        Point dataPoint = next.getDataPoint();
        ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(dataPoint);
    }

    lastX = e.getX();
    lastY = e.getY();

    Graphics graphics = chartPanel.getGraphics();
    graphics.setClip(clipRect);

    //Draw selection rectangle
    bufferGraphics.drawRect(drawRect.x, drawRect.y, drawRect.width, drawRect.height);

    graphics.drawImage(buffer, 0, 0, chartPanel.getWidth(), chartPanel.getHeight(), null);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.SmartLegendTitle.java

private Block createDefaultLegendItem(LegendItem item) {
    BlockContainer result = null;/*from  w  w  w.j a va 2  s. c  o m*/

    Shape shape = item.getShape();
    if (shape == null) {
        shape = new Rectangle();
    }
    LegendGraphic lg = new LegendGraphic(shape, item.getFillPaint());
    lg.setFillPaintTransformer(item.getFillPaintTransformer());
    lg.setShapeFilled(item.isShapeFilled());
    lg.setLine(item.getLine());
    lg.setLineStroke(item.getLineStroke());
    lg.setLinePaint(item.getLinePaint());
    lg.setLineVisible(item.isLineVisible());
    lg.setShapeVisible(item.isShapeVisible());
    lg.setShapeOutlineVisible(item.isShapeOutlineVisible());
    lg.setOutlinePaint(item.getOutlinePaint());
    lg.setOutlineStroke(item.getOutlineStroke());
    lg.setPadding(getLegendItemGraphicPadding());

    LegendItemBlockContainer legendItem = new LegendItemBlockContainer(new BorderArrangement(),
            item.getDataset(), item.getSeriesKey());
    lg.setShapeAnchor(getLegendItemGraphicAnchor());
    lg.setShapeLocation(getLegendItemGraphicLocation());
    legendItem.add(lg, getLegendItemGraphicEdge());

    Font textFont = item.getLabelFont();
    if (textFont == null) {
        textFont = getItemFont();
    }
    Paint textPaint = item.getLabelPaint();
    if (textPaint == null) {
        textPaint = getItemPaint();
    }
    LabelBlock labelBlock = new LabelBlock(item.getLabel(), textFont, textPaint);
    labelBlock.setPadding(getItemLabelPadding());
    legendItem.add(labelBlock);
    legendItem.setToolTipText(item.getToolTipText());
    legendItem.setURLText(item.getURLText());

    result = new BlockContainer(new CenterArrangement());
    result.add(legendItem);

    return result;
}

From source file:de.dakror.villagedefense.game.entity.Entity.java

public Entity(int x, int y, int width, int height) {
    this.x = x;//from  w ww .  j a  v a2  s. c  o  m
    this.y = y;
    this.width = width;
    this.height = height;

    bump = new Rectangle();
    attributes = new Attributes();
    resources = new Resources();
    massive = true;

    alpha = 1;
}

From source file:org.btrg.df.betterologist.swingui.ProjectJobSchedulingPanel.java

private JFreeChart createChart(Schedule schedule) {
    YIntervalSeriesCollection seriesCollection = new YIntervalSeriesCollection();
    Map<Project, YIntervalSeries> projectSeriesMap = new LinkedHashMap<Project, YIntervalSeries>(
            schedule.getProjectList().size());
    YIntervalRenderer renderer = new YIntervalRenderer();
    int maximumEndDate = 0;
    int seriesIndex = 0;
    for (Project project : schedule.getProjectList()) {
        YIntervalSeries projectSeries = new YIntervalSeries(project.getLabel());
        seriesCollection.addSeries(projectSeries);
        projectSeriesMap.put(project, projectSeries);
        renderer.setSeriesShape(seriesIndex, new Rectangle());
        renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
        seriesIndex++;/*from w  w  w .  ja  va  2s  .c o m*/
    }
    for (Allocation allocation : schedule.getAllocationList()) {
        int startDate = allocation.getStartDate();
        int endDate = allocation.getEndDate();
        YIntervalSeries projectSeries = projectSeriesMap.get(allocation.getProject());
        projectSeries.add(allocation.getId(), (startDate + endDate) / 2.0, startDate, endDate);
        maximumEndDate = Math.max(maximumEndDate, endDate);
    }
    NumberAxis domainAxis = new NumberAxis("Job");
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-0.5, schedule.getAllocationList().size() - 0.5);
    domainAxis.setInverted(true);
    NumberAxis rangeAxis = new NumberAxis("Day (start to end date)");
    rangeAxis.setRange(-0.5, maximumEndDate + 0.5);
    XYPlot plot = new XYPlot(seriesCollection, domainAxis, rangeAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    return new JFreeChart("Project Job Scheduling", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:com.adobe.acs.commons.images.transformers.impl.CropImageTransformerImpl.java

@Override
public final Layer transform(final Layer layer, final ValueMap properties) {
    if (properties == null || properties.isEmpty()) {
        log.warn("Transform [ {} ] requires parameters.", TYPE);
        return layer;
    }/* www.j a v  a2  s. c om*/

    log.debug("Transforming with [ {} ]", TYPE);

    final boolean smartBounding = properties.get(KEY_SMART_BOUNDING, true);
    final String[] bounds = StringUtils.split(properties.get(KEY_BOUNDS, ""), ",");

    if (bounds.length == NUM_BOUNDS_PARAMS) {
        int x = parseLength(bounds[PARAM_INDEX_X], layer.getWidth());
        int y = parseLength(bounds[PARAM_INDEX_Y], layer.getHeight());

        int width = parseLength(bounds[PARAM_INDEX_WIDTH], layer.getWidth());
        int height = parseLength(bounds[PARAM_INDEX_HEIGHT], layer.getHeight());

        Rectangle rectangle = new Rectangle();

        if (smartBounding) {
            rectangle = this.getSmartBounds(x, y, width, height, layer.getWidth(), layer.getHeight());
        } else {
            rectangle.setBounds(x, y, width, height);
        }

        layer.crop(rectangle);

        if (smartBounding && layer.getWidth() != width || layer.getHeight() != height) {
            log.debug("SmartBounding resulted in an image of an incorrect size (based on crop params). "
                    + "resizing to: [ width: {}, height: {} ]", width, height);
            layer.resize(width, height);
        }
    }

    return layer;
}

From source file:com.adobe.acs.commons.images.transformers.impl.CropImageTransformerImpl.java

@SuppressWarnings("squid:S2589")
private Rectangle getSmartBounds(int x, int y, int width, int height, int layerWidth, int layerHeight) {
    final Rectangle rectangle = new Rectangle();

    final int x2 = x + width;
    final int y2 = y + height;

    if (x2 >= layerWidth && y2 >= layerHeight) {
        // Both exceed, pick the dimension to use as the "master" clip

        final float clipPercentX = ((float) (x2 - layerWidth) / width);
        final float clipPercentY = ((float) (y2 - layerHeight) / height);

        if (clipPercentX >= clipPercentY) {
            // The proportional amount to clip is greatest on the x-axis, so trim both dimensions by the same %
            return constrainByWidth(x, y, width, height, layerWidth, x2);
        } else {//  w  w w.  ja  va  2  s .  co  m
            // The proportional amount to clip is greatest on the y-axis, so trim both dimensions by the same %
            return constrainByHeight(x, y, width, height, layerHeight, y2);
        }
    } else if (x2 >= layerWidth && y2 < layerHeight) {
        return constrainByWidth(x, y, width, height, layerWidth, x2);
    } else if (x2 < layerWidth && y2 >= layerHeight) {
        return constrainByHeight(x, y, width, height, layerHeight, y2);
    }

    // Crop within layer size
    rectangle.setBounds(x, y, width, height);
    return rectangle;
}

From source file:ch.epfl.lis.gnwgui.jungtransformers.ArrowShapeTransformer.java

/**
 * Create a rectangular arrow./*  w w w. j a  v a2  s .co m*/
 * @param w
 * @param h
 * @return The rectangular arrow
 */
public static Rectangle getRectangularArrow(int w, int h) {
    Rectangle arrow = new Rectangle();
    arrow.x = -w;
    arrow.y = -h / 2;
    arrow.height = h;
    arrow.width = w;
    return arrow;
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreeRenderer.java

/**
 * @param layoutComp/*from   w  ww .  j  av a  2s  .c om*/
 * @param isEditable
 * @param isViewMode
 */
public ContainerTreeRenderer(final Component layoutComp, final boolean isEditable, final boolean isViewMode) {
    this.isEditable = isEditable;
    this.isViewMode = isViewMode;

    Class<?>[] cls = { Container.class, CollectionObject.class };
    for (Class<?> c : cls) {
        iconHash.put(c, IconManager.getIcon(c.getSimpleName(), IconManager.IconSize.Std24));
        iconFadedHash.put(c, IconManager.getIcon(c.getSimpleName(), IconManager.IconSize.Std24Fade));
    }
    setIcon(iconHash.get(cls[0]));

    String[] fNames = { "Container", "Folder", "Sheet", "PlantSpecimen" };
    for (short i = 0; i < fNames.length; i++) {
        typeIconHash.put((short) i, IconManager.getIcon(fNames[i], IconManager.IconSize.Std24));
    }

    catNumFmt = DBTableIdMgr.getFieldFormatterFor(CollectionObject.class, "CatalogNumber");

    this.layoutComp = layoutComp;

    for (int i = 0; i < hitRects.length; i++) {
        hitRects[i] = new Rectangle();
    }
}