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:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java

/**
 * Draw a box to the left of the selected region, and one to the right, that together
 * encompass everything but the selection
 *
 *
 * @param selectedRegion/*from   ww  w  . j  ava  2  s.c o  m*/
 * @param stroke
 * @param color
 */
protected void drawAllButSelectedRegionHoriz(Rectangle2D selectedRegion, Stroke stroke, Color color,
        boolean xorMode, Graphics2D g2) {
    Rectangle2D scaledDataArea = _chartPanel.getScreenDataArea();
    Rectangle2D firstBox = new Rectangle((int) scaledDataArea.getMinX(), (int) scaledDataArea.getMinY(),
            (int) (selectedRegion.getMinX() - scaledDataArea.getMinX()), (int) scaledDataArea.getMaxY());
    Rectangle2D secondBox = new Rectangle((int) selectedRegion.getMaxX(), (int) scaledDataArea.getMinY(),
            (int) (scaledDataArea.getMaxX() - selectedRegion.getMaxX()), (int) scaledDataArea.getMaxY());
    drawSelectedRegion(firstBox, stroke, color, xorMode, g2);
    drawSelectedRegion(secondBox, stroke, color, xorMode, g2);
}

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

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (mTimeFrame == null) {
        renderNoInfoView(g);/*w  ww  . ja va  2s . c  om*/
    } else {
        updateSize();
        LongRange startRange = mTimeFrame.getStartRange();
        LongRange arriveRange = mTimeFrame.getArriveRange();
        HashMap<LongRange, TimeSpan> startRanges = mTimeFrame
                .startTimespansToRangesMap(AnyTribe.getSingleton());
        HashMap<LongRange, TimeSpan> arriveRanges = mTimeFrame.arriveTimespansToRangesMap(null);
        long minValue = startRange.getMinimumLong();
        long maxValue = arriveRange.getMaximumLong();
        Graphics2D g2d = (Graphics2D) g;
        g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3)));
        g2d.fillRect(0, 0, getWidth(), getHeight());

        //draw frame around the entire range
        renderRange(new LongRange(startRange.getMinimumLong(), arriveRange.getMaximumLong()), startRange,
                arriveRange, false, false, g2d, null, popupInfo);
        g2d.setColor(Constants.DS_BACK);
        popupInfo.clear();
        //fill start range
        renderRange(startRange, startRange, arriveRange, true, false, g2d, null, popupInfo);
        //fill arrive range
        renderRange(arriveRange, startRange, arriveRange, false, true, g2d, null, popupInfo);
        Paint p = g2d.getPaint();
        Iterator<LongRange> rangeKeys = startRanges.keySet().iterator();
        while (rangeKeys.hasNext()) {
            LongRange currentRange = rangeKeys.next();

            TimeSpan spanForRange = startRanges.get(currentRange);
            if (spanForRange != null) {
                if (spanForRange.isValidAtEveryDay()) {
                    g2d.setPaint(new TexturePaint(DAILY_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                } else if (spanForRange.isValidAtExactTime()) {
                    g2d.setPaint(new TexturePaint(EXACT_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                } else {
                    g2d.setPaint(new TexturePaint(ONE_DAY_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                }
            }
            renderRange(currentRange, startRange, arriveRange, false, false, g2d, spanForRange, popupInfo);
        }

        Composite c = g2d.getComposite();
        rangeKeys = arriveRanges.keySet().iterator();
        while (rangeKeys.hasNext()) {
            LongRange currentRange = rangeKeys.next();
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
            g2d.setPaint(new TexturePaint(ARRIVE_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
            TimeSpan spanForRange = arriveRanges.get(currentRange);
            renderRange(currentRange, startRange, arriveRange, false, false, g2d, spanForRange, popupInfo);
        }
        g2d.setComposite(c);
        g2d.setPaint(p);
        renderDayMarkers(minValue, maxValue, g2d);
        renderPopup(popupInfo, g2d);
    }
}

From source file:com.funambol.LDAP.admin.LDAPSyncSourceConfigPanel.java

/**
 * Create the panel/* w ww .  j a  va  2 s . co m*/
 * @throws Exception if error occures during creation of the panel
 */
private void init() {
    // set layout
    this.setLayout(null);

    int startX = 14;
    int fontHeight = 18;
    int col1Size = 150;
    int col2X = startX + col1Size + 6; //170px 
    int col2Size = 350;
    int col3X = col2X + col2Size + 6; // 550
    int col3Size = 90;
    int chkboxSize = 18;
    // set properties of label, position and border
    // referred to the title of the panel
    titledBorder1 = new TitledBorder("");

    panelName.setFont(titlePanelFont);
    panelName.setText("Edit LDAP SyncSourceContacts");
    panelName.setBounds(new Rectangle(startX, 5, 316, 28));
    panelName.setAlignmentX(SwingConstants.CENTER);
    panelName.setBorder(titledBorder1);

    int baseline = 60;
    sourceUriLabel.setText("Source URI: ");
    sourceUriLabel.setToolTipText("Choose a unique word");
    sourceUriLabel.setFont(defaultFont);
    sourceUriLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    sourceUriValue.setFont(FONT_ARIAL);
    sourceUriValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30;
    nameLabel.setText("Name: ");
    nameLabel.setToolTipText("Choose a word and set this into your client in order to use this connector");
    nameLabel.setFont(defaultFont);
    nameLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    nameValue.setFont(FONT_ARIAL);
    nameValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30;
    typeLabel.setText("Type: ");
    typeLabel.setToolTipText("Only VCARD are supported, SIF is deprecated");
    typeLabel.setFont(defaultFont);
    typeLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    typeValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30;
    providerUrlLabel.setText("LDAP URI: ");
    providerUrlLabel.setToolTipText("eg. ldap://ldap.example.com , ldaps://ldap.example.com:390 ");
    providerUrlLabel.setFont(defaultFont);
    providerUrlLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    providerUrlValue.setFont(FONT_ARIAL);
    providerUrlValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30;
    ldapBaseLabel.setText("LDAP Base DN: ");
    ldapBaseLabel.setToolTipText(
            "This is used to define where to store/read user's data.\nRead install.txt notes to use parameters");
    ldapBaseLabel.setFont(defaultFont);
    ldapBaseLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    ldapBaseValue.setFont(FONT_ARIAL);
    ldapBaseValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30; // TODO contactDaoLabel, entryFilterLabel
    daoNameLabel.setText("DAO Class for converting item to LDAP");
    daoNameLabel.setToolTipText("piTypePerson, inetOrgPerson or organizationalPerson");
    daoNameLabel.setFont(defaultFont);
    daoNameLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    daoNameValue.setFont(FONT_ARIAL);
    daoNameValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30;
    entryFilterLabel.setText("Filter user by");
    entryFilterLabel
            .setToolTipText("A valid  LDAP search filter, eg: (&(objectclass=inetOrgPerson)(active=1))");
    entryFilterLabel.setFont(defaultFont);
    entryFilterLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    entryFilterValue.setFont(FONT_ARIAL);
    entryFilterValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30;
    ldapUserLabel.setText("LDAP User: ");
    ldapUserLabel.setToolTipText("LDAP Bind DN (username) to access the LDAP server");
    ldapUserLabel.setFont(defaultFont);
    ldapUserLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    ldapUserValue.setFont(FONT_ARIAL);
    ldapUserValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30;
    ldapPassLabel.setText("LDAP Password: ");
    ldapPassLabel.setToolTipText("LDAP Bind DN password to access LDAP server");
    ldapPassLabel.setFont(defaultFont);
    ldapPassLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    ldapPassValue.setFont(FONT_ARIAL);
    ldapPassValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    // follow referral
    followReferralLabel.setText("Follow Referral ");
    followReferralLabel.setToolTipText("Select this checkbox if you want ldap to follow smart-referrals");
    followReferralLabel.setFont(defaultFont);
    followReferralLabel.setBounds(new Rectangle(col3X, 270, col3Size, fontHeight));
    followReferralValue.setSelected(false);
    followReferralValue.setBounds(new Rectangle(col3X, 300, col3Size, fontHeight));
    // connection pooling
    connectionPoolingLabel.setText("Pooling ");
    connectionPoolingLabel.setToolTipText("Select this checkbox if you want use connection pooling");
    connectionPoolingLabel.setFont(defaultFont);
    connectionPoolingLabel.setBounds(new Rectangle(col3X + col3Size, 270, col3Size, fontHeight));
    connectionPoolingValue.setSelected(false);
    connectionPoolingValue.setBounds(new Rectangle(col3X + col3Size, 300, col3Size, fontHeight));

    baseline += 30;
    dbNameLabel.setText("Funambol DBMS Name: ");
    dbNameLabel.setToolTipText("Funambol DS table to store metadata. Use fnblcore");
    dbNameLabel.setFont(defaultFont);
    dbNameLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    dbNameValue.setFont(FONT_ARIAL);
    dbNameValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));

    baseline += 30;
    timeZoneLabel.setFont(defaultFont);
    timeZoneLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    timeZoneValue = new JComboBox(TimeZone.getAvailableIDs());
    timeZoneValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));
    // rpolli
    baseline += 30;
    ldapServerLabel.setText("LDAP Server Type");
    ldapServerLabel.setFont(defaultFont);
    ldapServerLabel.setBounds(new Rectangle(startX, baseline, col1Size, fontHeight));
    ldapServerValue.setBounds(new Rectangle(col2X, baseline, col2Size, fontHeight));
    ldapServerValue.setToolTipText("Select compatibility unique ID's per items.");
    confirmButton.setFont(defaultFont);
    confirmButton.setText("Add");
    confirmButton.setBounds(col2X, 420, 70, 25);

    confirmButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                validateValues();
                getValues();
                if (getState() == STATE_INSERT) {
                    LDAPSyncSourceConfigPanel.this.actionPerformed(new ActionEvent(
                            LDAPSyncSourceConfigPanel.this, ACTION_EVENT_INSERT, event.getActionCommand()));
                } else {
                    LDAPSyncSourceConfigPanel.this.actionPerformed(new ActionEvent(
                            LDAPSyncSourceConfigPanel.this, ACTION_EVENT_UPDATE, event.getActionCommand()));
                }
            } catch (Exception e) {
                e.printStackTrace();
                notifyError(new AdminException(e.getMessage()));
            }
        }
    });

    // add all components to the panel
    this.add(panelName, null);
    this.add(nameLabel, null);
    this.add(nameValue, null);
    this.add(typeLabel, null);
    this.add(typeValue, null);
    this.add(sourceUriLabel, null);
    this.add(sourceUriValue, null);

    //rpolli
    this.add(ldapServerLabel, null);
    this.add(ldapServerValue, null);
    this.add(this.daoNameLabel, null);
    this.add(this.daoNameValue, null);

    this.add(followReferralLabel, null);
    this.add(followReferralValue, null);
    this.add(connectionPoolingLabel, null);
    this.add(connectionPoolingValue, null);

    this.add(providerUrlLabel, null);
    this.add(providerUrlValue, null);
    //      this.add(ldapPortLabel    , null);
    //      this.add(ldapPortValue    , null);
    //      this.add(isSSLLabel       , null);
    //      this.add(isSSLValue       , null);
    this.add(ldapBaseLabel, null);
    this.add(ldapBaseValue, null);
    this.add(entryFilterLabel, null);
    this.add(entryFilterValue, null);

    this.add(ldapUserLabel, null);
    this.add(ldapUserValue, null);
    this.add(ldapPassLabel, null);
    this.add(ldapPassValue, null);
    this.add(timeZoneLabel, null);
    this.add(timeZoneValue, null);

    this.add(dbNameLabel, null);
    this.add(dbNameValue, null);

    this.add(confirmButton, null);
}

From source file:ala.soils2sat.DrawingUtils.java

/**
 * Draws the text by creating a rectange centered around x, y
 *
 * @param g/*ww w .j  a v a 2  s .  c o  m*/
 * @param font
 * @param x
 * @param y
 * @return The rectangle that bounds the text
 */
public static Rectangle drawCentredText(Graphics2D g, Font font, String text, int x, int y) {
    g.setFont(font);
    FontMetrics fm = g.getFontMetrics(font);

    setPreferredAliasingMode(g);

    Rectangle ret = new Rectangle(x, y, 0, 0);

    if (text == null) {
        return ret;
    }
    String[] alines = text.split("\\n");
    ArrayList<String> lines = new ArrayList<String>();
    for (String s : alines) {
        if (s.length() > 0) {
            lines.add(s);
        }
    }
    int numlines = lines.size();
    if (numlines > 0) {
        int maxwidth = 0;
        int totalheight = 0;
        for (int idx = 0; idx < numlines; ++idx) {
            String line = lines.get(idx);
            int stringWidth = fm.stringWidth(line);
            if (stringWidth > maxwidth) {
                maxwidth = stringWidth;
            }
            totalheight += fm.getAscent() + fm.getDescent();
        }
        ret.width = maxwidth;
        ret.height = totalheight;
        ret.x = x - (maxwidth / 2);
        ret.y = y - (totalheight / 2);

        drawString(g, font, text, ret, TEXT_ALIGN_CENTER);

        return ret;
    }
    return ret;

}

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

public Rectangle getArea(boolean world) {
    return new Rectangle((int) x + (world ? Game.world.x : 0), (int) y + (world ? Game.world.y : 0), width,
            height);/*  w w  w .  j  a  va  2 s .  c  o m*/
}

From source file:ucar.unidata.idv.control.chart.MyScatterPlot.java

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the
 * screen or a printer)./*from  w  ww.j  av a  2 s.  c  o  m*/
 * a
 * @param g2  the graphics device.
 * @param dataArea the data area
 * @param index which data set
 * @param info  collects chart drawing information (<code>null</code>
 *              permitted).
 * @param crosshairState crosshairState
 *
 * @return did something
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    if (index >= series.size()) {
        return false;
    }
    XYDataset dataset = getDataset(index);
    g2.setStroke(new BasicStroke());
    //                   getRendererForDataset(dataset).getSeriesStroke(0));
    ScatterPlotChartWrapper.MyRenderer renderer = (ScatterPlotChartWrapper.MyRenderer) getRendererForDataset(
            dataset);
    g2.setPaint(renderer.getSeriesPaint(0));
    int shape = renderer.shape;

    PlotOrientation orientation = getOrientation();
    int seenCnt = 0;

    int xx = (int) dataArea.getMinX();
    int ww = (int) dataArea.getWidth();
    int yy = (int) dataArea.getMaxY();
    int hh = (int) dataArea.getHeight();
    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    ValueAxis domainAxis = getDomainAxisForDataset(index);
    double domainMin = domainAxis.getLowerBound();
    double domainLength = domainAxis.getUpperBound() - domainMin;
    double rangeMin = rangeAxis.getLowerBound();
    double rangeLength = rangeAxis.getUpperBound() - rangeMin;
    int boxWidth = 6;

    double[][] data = (double[][]) series.get(index);

    double[] d1 = data[0];
    double[] d2 = data[1];
    int size = d1.length;

    Hashtable seen = new Hashtable();
    int lastX = 0;
    int lastY = 0;
    //TODO: Check for clipping
    //TODO: Try to create a GeneralPath with the points
    //and cal g2.draw just once
    GeneralPath path = new GeneralPath();
    long t1 = System.currentTimeMillis();

    for (int i = 0; i < size; i++) {
        int transX = (int) (xx + ww * (d1[i] - domainMin) / domainLength);
        int transY = (int) (yy - hh * (d2[i] - rangeMin) / rangeLength);
        Object key = transX + "_" + transY;
        if (seen.get(key) != null) {
            seenCnt++;
            continue;
        }
        seen.put(key, key);
        if (crosshairState != null) {
            crosshairState.updateCrosshairPoint(d1[i], d2[i], transX, transY, orientation);
        }

        switch (shape) {

        case LineState.SHAPE_VLINE:
            if (i > 1) {
                g2.drawLine(lastX, lastY, transX, transY);
            }
            lastX = transX;
            lastY = transY;

        case LineState.SHAPE_POINT:
            path.append(new Rectangle((int) transX, (int) transY, 1, 1), false);
            break;

        case LineState.SHAPE_LARGEPOINT:
            path.append(new Rectangle((int) transX, (int) transY, 2, 2), false);
            break;

        case LineState.SHAPE_RECTANGLE:
            path.append(
                    new Rectangle((int) transX - boxWidth / 2, (int) transY - boxWidth / 2, boxWidth, boxWidth),
                    false);
            break;

        case LineState.SHAPE_X:
            g2.drawLine(transX - boxWidth / 2, transY - boxWidth / 2, transX + boxWidth - boxWidth / 2,
                    transY + boxWidth - boxWidth / 2);
            g2.drawLine(transX + boxWidth - boxWidth / 2, transY - boxWidth / 2, transX - boxWidth / 2,
                    transY + boxWidth - boxWidth / 2);
            break;

        case LineState.SHAPE_PLUS:
            g2.drawLine(transX + boxWidth / 2, transY, transX + boxWidth / 2, transY + boxWidth);
            g2.drawLine(transX, transY + boxWidth / 2, transX + boxWidth, transY + boxWidth / 2);
            break;

        }
    }
    g2.fill(path);
    long t2 = System.currentTimeMillis();
    //        System.out.println ("time:" + (t2-t1));
    return true;
}

From source file:XMLWriteTest.java

/**
 * Create a new random drawing.//from   w ww.  j  a  v a  2s.  c  o m
 */
public void newDrawing() {
    int n = 10 + generator.nextInt(20);
    rects.clear();
    colors.clear();
    for (int i = 1; i <= n; i++) {
        int x = generator.nextInt(getWidth());
        int y = generator.nextInt(getHeight());
        int width = generator.nextInt(getWidth() - x);
        int height = generator.nextInt(getHeight() - y);
        rects.add(new Rectangle(x, y, width, height));
        int r = generator.nextInt(256);
        int g = generator.nextInt(256);
        int b = generator.nextInt(256);
        colors.add(new Color(r, g, b));
    }
    repaint();
}

From source file:SVGJUnitTest.java

public void paint(Graphics2D g2d) {

    g2d.setPaint(Color.red);
    g2d.fill(new Rectangle(10, 10, 100, 100));
}

From source file:org.jfree.graphics2d.demo.CanvasTimeSeriesChartDemo1.java

/**
 * Starting point for the demo.//w  w  w .j  a v  a2 s  .c  o  m
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    JFreeChart chart = createChart(createDataset());
    CanvasGraphics2D g2 = new CanvasGraphics2D("id");
    int width = 600;
    int height = 400;
    chart.draw(g2, new Rectangle(0, 0, width, height));
    File f = new File("CanvasTimeSeriesChartDemo1.html");
    CanvasUtils.writeToHTML(f, "CanvasTimeSeriesChartDemo1", g2.getCanvasID(), width, height, g2.getScript());
}

From source file:SVGJUnitTest.java

public void paint2(Graphics2D g2d) {

    g2d.setPaint(Color.green);
    g2d.fill(new Rectangle(90, 90, 100, 100));
}