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:com.kbot2.scriptable.methods.wrappers.Interface.java

public Rectangle getArea() {
    return new Rectangle(getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight());
}

From source file:fxts.stations.trader.ui.frames.ChildFrame.java

/**
 * Loads settings from the persistent preferences.
 *///from w w  w  . j a  va 2s .  co  m
public void loadSettings() {
    UserPreferences preferences;
    try {
        preferences = UserPreferences.getUserPreferences(TradeDesk.getInst().getUserName());
    } catch (Exception ex) {
        ex.printStackTrace();
        return;
    }

    //loads settings from preferences
    int x = preferences.getInt("childframe." + getName() + ".x");
    int y = preferences.getInt("childframe." + getName() + ".y");
    int width = preferences.getInt("childframe." + getName() + ".width");
    int height = preferences.getInt("childframe." + getName() + ".height");
    boolean visible = preferences.getBoolean("childframe." + getName() + ".visible");

    //sets position of the frame
    setBounds(new Rectangle(x, y, width, height));

    //sets visibility of the frame
    setVisible(visible);

    //sets state of the corresponding menu item
    setMenuItemState(visible);
}

From source file:dbmods.InsertTemplateName.java

private void addLogWindow() {
    //START >>  jInfoArea
    jInfoArea = new JTextArea();
    scrollPane = new JScrollPane(jInfoArea);
    scrollPane.setViewportView(jInfoArea);
    getContentPane().add(scrollPane, BorderLayout.CENTER);

    Rectangle rect = new Rectangle(22, 223, 350, 115);
    scrollPane.setBounds(rect);/*from  www . j a v a  2s .c  om*/
    jInfoArea.setEditable(false);
    jInfoArea.setLineWrap(true);
    jInfoArea.setWrapStyleWord(true);
    jInfoArea.setBounds(rect);
    //END <<  jInfoArea
}

From source file:ImageBorderHack.java

public void fillTexture(Graphics2D g2, Image img, int x, int y, int w, int h) {
    BufferedImage buff = createBufferedImage(img);
    Rectangle anchor = new Rectangle(x, y, img.getWidth(null), img.getHeight(null));
    TexturePaint paint = new TexturePaint(buff, anchor);
    g2.setPaint(paint);//from  w w  w. j  av  a  2  s .  co m
    g2.fillRect(x, y, w, h);
}

From source file:fr.avianey.androidsvgdrawable.QualifiedSVGResourceFactory.java

/**
 * Extract the viewbox of the input SVG//from   w  w w  . j  a  v a 2 s  .com
 * @return
 * @throws MalformedURLException
 * @throws IOException
 */
private Rectangle extractSVGBounds(QualifiedSVGResource svg) throws IOException {
    // check <svg> attributes first : x, y, width, height
    SVGDocument svgDocument = getSVGDocument(svg);
    SVGSVGElement svgElement = svgDocument.getRootElement();
    if (svgElement.getAttributeNode("width") != null && svgElement.getAttribute("height") != null) {

        UserAgent userAgent = new DensityAwareUserAgent(svg.getDensity().getDpi());
        UnitProcessor.Context context = org.apache.batik.bridge.UnitProcessor
                .createContext(new BridgeContext(userAgent), svgElement);

        float width = svgLengthInPixels(svgElement.getWidth().getBaseVal(), context);
        float height = svgLengthInPixels(svgElement.getHeight().getBaseVal(), context);
        float x = 0;
        float y = 0;
        // check x and y attributes
        if (svgElement.getX() != null && svgElement.getX().getBaseVal() != null) {
            x = svgLengthInPixels(svgElement.getX().getBaseVal(), context);
        }
        if (svgElement.getY() != null && svgElement.getY().getBaseVal() != null) {
            y = svgLengthInPixels(svgElement.getY().getBaseVal(), context);
        }

        return new Rectangle((int) floor(x), (int) floor(y), (int) ceil(width), (int) ceil(height));
    }

    // use computed bounds
    log.warn("Take time to fix desired width and height attributes of the root <svg> node for this file... "
            + "ROI will be computed by magic using Batik " + boundsType.name() + " bounds");
    return boundsType.getBounds(getGraphicsNode(svgDocument, svg.getDensity().getDpi()));
}

From source file:components.ScrollDemo2.java

public void mouseReleased(MouseEvent e) {
    final int W = 100;
    final int H = 100;
    boolean changed = false;
    if (SwingUtilities.isRightMouseButton(e)) {
        //This will clear the graphic objects.
        circles.removeAllElements();//w  w  w .j  a  v  a 2s .  c om
        area.width = 0;
        area.height = 0;
        changed = true;
    } else {
        int x = e.getX() - W / 2;
        int y = e.getY() - H / 2;
        if (x < 0)
            x = 0;
        if (y < 0)
            y = 0;
        Rectangle rect = new Rectangle(x, y, W, H);
        circles.addElement(rect);
        drawingPane.scrollRectToVisible(rect);

        int this_width = (x + W + 2);
        if (this_width > area.width) {
            area.width = this_width;
            changed = true;
        }

        int this_height = (y + H + 2);
        if (this_height > area.height) {
            area.height = this_height;
            changed = true;
        }
    }
    if (changed) {
        //Update client's preferred size because
        //the area taken up by the graphics has
        //gotten larger or smaller (if cleared).
        drawingPane.setPreferredSize(area);

        //Let the scroll pane know to update itself
        //and its scrollbars.
        drawingPane.revalidate();
    }
    drawingPane.repaint();
}

From source file:Main.java

/**
 * Computes the maximum bounds of the current screen device. If this method is
 * called on JDK 1.4, Xinerama-aware results are returned. (See Sun-Bug-ID
 * 4463949 for details)./*w w  w  . j av a2s .c om*/
 * 
 * @return the maximum bounds of the current screen.
 */
public static Rectangle getMaximumWindowBounds() {
    final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        final Method method = GraphicsEnvironment.class.getMethod("getMaximumWindowBounds", (Class[]) null);
        return (Rectangle) method.invoke(localGraphicsEnvironment, (Object[]) null);
    } catch (Exception e) {
        // ignore ... will fail if this is not a JDK 1.4 ..
    }

    final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
    return new Rectangle(0, 0, s.width, s.height);
}

From source file:com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel.java

private void placeTitleComponent() {
    Insets insets = getInsets();/*from   w  ww  . j a  va 2s.com*/
    Rectangle containerRectangle = getBounds();
    if (borderVisible) {
        Rectangle componentRectangle = ((CollapsibleTitledBorder) getBorder())
                .getComponentRect(containerRectangle, insets);
        titleBtn.setBounds(componentRectangle);
    } else {
        Dimension compD = titleBtn.getPreferredSize();
        Rectangle compR = new Rectangle(20 - insets.left, 0, compD.width, compD.height);
        titleBtn.setBounds(compR);
    }
}

From source file:Main.java

  /**
 * Computes the maximum bounds of the current screen device. If this method is
 * called on JDK 1.4, Xinerama-aware results are returned. (See Sun-Bug-ID
 * 4463949 for details).//from  w  w w .j a  v  a  2 s  .co m
 * 
 * @return the maximum bounds of the current screen.
 */
public static Rectangle getMaximumWindowBounds() {
  final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment
      .getLocalGraphicsEnvironment();
  try {
    final Method method = GraphicsEnvironment.class.getMethod("getMaximumWindowBounds",
        (Class[]) null);
    return (Rectangle) method.invoke(localGraphicsEnvironment, (Object[]) null);
  } catch (Exception e) {
    // ignore ... will fail if this is not a JDK 1.4 ..
  }

  final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
  return new Rectangle(0, 0, s.width, s.height);
}

From source file:br.ufrgs.enq.jcosmo.ui.SigmaProfileAreaPanel.java

public void addProfile(String label, double[] sigma, double[] area, int rgb) {
    int n = sigma.length;
    XYSeries comp = new XYSeries(label, false, false);

    // charges represent the center of the segments
    comp.add(sigma[0], area[0]);/*w  ww .  ja va  2  s  .  c  om*/
    for (int j = 1; j < n; ++j) {
        double dsigma = (sigma[j] - sigma[j - 1]) / 2;
        comp.add(sigma[j] - dsigma, area[j]);
        comp.add(sigma[j] + dsigma + 1e-6, area[j]);
    }
    dataset.addSeries(comp);
    int series = dataset.getSeriesCount() - 1;

    int patternSize = 6;
    BufferedImage bi = new BufferedImage(patternSize, patternSize, BufferedImage.TYPE_INT_RGB);
    Rectangle r = new Rectangle(0, 0, patternSize, patternSize);
    Graphics2D big = bi.createGraphics();
    big.setColor(new Color(rgb, rgb, rgb));
    big.fillRect(0, 0, patternSize, patternSize);

    int pattern = series % 4;
    if (pattern == 1 || pattern == 3) {
        big.setColor(Color.WHITE);
        big.drawLine(0, patternSize / 2, patternSize, patternSize / 2);
    }
    if (pattern == 2 || pattern == 3) {
        big.setColor(Color.WHITE);
        big.drawLine(patternSize / 2, 0, patternSize / 2, patternSize);
    }

    TexturePaint paint = new TexturePaint(bi, r);
    sigmaProfilePlot.getRenderer().setSeriesPaint(series, paint); // new Color(rgb, rgb, rgb));
}