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

Source Link

Document

Constructs a new Rectangle whose top left corner is (0, 0) and whose width and height are specified by the Dimension argument.

Usage

From source file:com.intuit.tank.tools.debugger.SelectDialog.java

/**
 * @param arg0//from ww w .j a  v  a 2  s .co  m
 */
public SelectDialog(Frame f, List<SELECTION_TYPE> items, String itemType, boolean singleSelection) {
    super(f, true);
    setLayout(new BorderLayout());
    this.items = items;
    filterField = new JTextField();
    filterField.addKeyListener(new KeyHandler());
    list = new JList(items.toArray());
    list.setSelectionMode(singleSelection ? ListSelectionModel.SINGLE_SELECTION
            : ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            okBT.setEnabled(list.getSelectedIndex() != -1);
        }
    });
    list.addMouseListener(new MouseAdapter() {

        /**
         * @{inheritDoc
         */
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                select();
            }
        }

    });
    JPanel labelPanel = new JPanel(new GridLayout(singleSelection ? 1 : 2, 1, 0, 5));
    labelPanel.add(new JLabel("Select a " + itemType + "."));
    if (!singleSelection) {
        String key = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1 ? "" : "control";
        System.out.println(key);
        labelPanel.add(new JLabel("Hold down the " + key + " key to select multiple " + itemType + "."));
    }
    add(labelPanel, BorderLayout.NORTH);
    JScrollPane sp = new JScrollPane(list);
    JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.add(filterField, BorderLayout.NORTH);
    centerPanel.add(sp, BorderLayout.CENTER);
    add(centerPanel, BorderLayout.CENTER);
    add(createButtonPanel(), BorderLayout.SOUTH);
    setSize(new Dimension(400, 500));
    setBounds(new Rectangle(getSize()));
    setPreferredSize(getSize());
    WindowUtil.centerOnParent(this);
}

From source file:visualize.Visualize.java

public static void makeScreenshot(final int index) {
    makeScreenshot(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()), index);
}

From source file:com.projity.pm.graphic.chart.AxisPanel.java

public void paintComponent(Graphics graphics) {
    super.paintComponent(graphics); // have to do this first for background
    if (axis == null)
        return; // no axis, don't paint it

    Rectangle plotArea = new Rectangle(getSize()); // use full panel size
    RectangleEdge edge = RectangleEdge.LEFT; // plot is on the right

    axis.setVisible(true); // this enables this axis to draw.  Later on the axis is made invisible so the chart axis won't draw

    Dimension d = getSize();/*  w w w. ja  v  a  2 s  . c  om*/
    int cursor = d.width; // set cursor to full width
    int footerOffset = (int) Math.round(chartInfo.getFooterHeight());
    int headerOffset = 0;//(int) Math.round(chartInfo.getHeaderHeight());
    Rectangle dataArea = new Rectangle(cursor, headerOffset, d.width, d.height - headerOffset - footerOffset); // draw right justified

    axis.draw((Graphics2D) graphics, cursor, plotArea, dataArea, edge, null);

    axis.setVisible(false); //now make it invisible so chart doesn't show it
}

From source file:com.jaeksoft.searchlib.util.ImageUtils.java

public static final void yellowHighlight(Image image, Collection<Rectangle> boxes, float outsetFactor) {
    if (CollectionUtils.isEmpty(boxes))
        return;/*  w  w w . j a  v  a 2 s  . com*/
    Graphics2D g2d = (Graphics2D) image.getGraphics();
    g2d.setPaint(Color.YELLOW);
    Composite originalComposite = g2d.getComposite();
    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
    g2d.setComposite(ac);
    for (Rectangle box : boxes) {
        if (outsetFactor != 1.0F) {
            box = new Rectangle(box);
            box.grow((int) (box.getHeight() * outsetFactor), (int) (box.getWidth() * outsetFactor));
        }
        g2d.fill(box);
    }
    g2d.setComposite(originalComposite);
}

From source file:com.truven.report.reporter.Reporter.java

/**
 * Save screen shot./*from   ww  w . ja v a2 s  .  c  o m*/
 *
 * @param reportFolderLocation the report folder location
 * @return the string
 */
private String saveScreenShot(final String reportFolderLocation) {

    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSS");
    String timestamp = sdf.format(date);
    Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    BufferedImage capture;
    String screenShotFile = timestamp + ".png";
    String screenShotImgFolder = reportFolderLocation + File.separator + "images";
    try {
        capture = new Robot().createScreenCapture(screenRect);
        File screenShotImgFolderFile = new File(screenShotImgFolder);

        if (!screenShotImgFolderFile.exists() && !screenShotImgFolderFile.mkdirs()) {

            throw new RuntimeException(
                    "Cannot create new folder in location " + screenShotImgFolderFile.getAbsolutePath());
        }
        File screenShotImg = new File(screenShotImgFolder + File.separator + screenShotFile);
        ImageIO.write(capture, "png", screenShotImg);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (AWTException e1) {
        e1.printStackTrace();
    } catch (Exception e2) {
        e2.printStackTrace();
    }
    return screenShotFile;
}

From source file:TileLayout.java

private void align(Dimension cont, Object cons[], Component comp) {
    int align = 0;
    Insets insets = null;// ww  w. j  a  va  2 s  . c o m
    Rectangle tile = null, fixd = null;
    if (cons != null) {
        for (int i = 0; i < cons.length; i++) { // gather constraints
            if (cons[i] != null) {
                if (cons[i] instanceof Rectangle)
                    fixd = (Rectangle) cons[i];
                else if (cons[i] instanceof Insets)
                    insets = (Insets) cons[i];
                else if (cons[i] instanceof Integer)
                    align = ((Integer) cons[i]).intValue();
                else if (cons[i] instanceof Component)
                    tile = ((Component) cons[i]).getBounds();
            }
        }
    }
    if (tile == null)
        tile = new Rectangle(cont);
    Rectangle pref = new Rectangle(tile.getLocation(), comp.getPreferredSize());

    // perform component positioning:

    if ((align & 0x004000) != 0)
        pref.width = fixd.width;
    else if ((align & 0x008000) != 0)
        pref.width = (tile.width * fixd.width + 500) / 1000;
    else if ((align & 0x010000) != 0)
        pref.width = tile.width;

    if ((align & 0x080000) != 0)
        pref.height = fixd.height;
    else if ((align & 0x100000) != 0)
        pref.height = (tile.height * fixd.height + 500) / 1000;
    else if ((align & 0x200000) != 0)
        pref.height = tile.height;

    if ((align & 0x000001) != 0)
        pref.x -= pref.width;
    else if ((align & 0x000002) != 0)
        pref.x += (tile.width - pref.width >> 1);
    else if ((align & 0x000004) != 0)
        pref.x += tile.width - pref.width;
    else if ((align & 0x000008) != 0)
        pref.x += tile.width;
    else if ((align & 0x000010) != 0)
        pref.x += fixd.x;
    else if ((align & 0x000020) != 0)
        pref.x += (tile.width * fixd.x + 500) / 1000;

    if ((align & 0x000040) != 0)
        pref.y -= pref.height;
    else if ((align & 0x000080) != 0)
        pref.y += (tile.height - pref.height >> 1);
    else if ((align & 0x000100) != 0)
        pref.y += tile.height - pref.height;
    else if ((align & 0x000200) != 0)
        pref.y += tile.height;
    else if ((align & 0x000400) != 0)
        pref.y += fixd.y;
    else if ((align & 0x000800) != 0)
        pref.y += (tile.height * fixd.y + 500) / 1000;

    if ((align & 0x001000) != 0)
        pref.setBounds(0, pref.y, pref.x + pref.width, pref.height);
    else if ((align & 0x002000) != 0)
        pref.width = cont.width - pref.x;

    if ((align & 0x020000) != 0)
        pref.setBounds(pref.x, 0, pref.width, pref.y + pref.height);
    else if ((align & 0x040000) != 0)
        pref.height = cont.height - pref.y;

    if (insets != null) { // apply insets, if any:
        pref.x += insets.left;
        pref.y += insets.top;
        pref.width -= insets.left + insets.right;
        pref.height -= insets.top + insets.bottom;
    }

    // Note: this can cause surprising results, so use it, if you dare. :-)
    // Honour component minimum size:
    Dimension d = comp.getMinimumSize();
    if (pref.width < d.width)
        pref.width = d.width;
    if (pref.height < d.height)
        pref.height = d.height;

    comp.setBounds(pref); // now the tile is set!
}

From source file:com.intuit.tank.proxy.ProxyApp.java

public ProxyApp() {
    super("Intuit Tank Recording Proxy");
    setSize(new Dimension(800, 600));
    setBounds(new Rectangle(getSize()));
    setPreferredSize(getSize());/*from w  w w .ja  v  a2 s. c  o  m*/
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setLayout(new BorderLayout());
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            try {
                stop();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            System.exit(0);
        }
    });
    keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    configDialog = new ProxyConfigDialog(this);
    createActions();
    this.setJMenuBar(createMenu());
    createDetailsDialog();

    JPanel tablePanel = getTransactionTable();
    this.add(createToolBar(), BorderLayout.NORTH);
    this.add(tablePanel, BorderLayout.CENTER);

    WindowUtil.centerOnScreen(this);
    pack();
    setVisible(true);
    requestFocus();
}

From source file:GraphPaperLayout.java

public void setConstraints(Component comp, Rectangle constraints) {
    compTable.put(comp, new Rectangle(constraints));
}

From source file:JXTransformer.java

private Rectangle getTransformedSize() {
    if (view != null) {
        Dimension viewSize = view.getSize();
        Rectangle viewRect = new Rectangle(viewSize);
        return at.createTransformedShape(viewRect).getBounds();
    }//from ww w .  j a v  a 2 s  .c  o m
    return new Rectangle(super.getPreferredSize());
}

From source file:com.ixxus.IxxusAbstractTest.java

public void saveOsScreenShot(String methodName) throws IOException, AWTException {
    Robot robot = new Robot();
    BufferedImage screenShot = robot
            .createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
    ImageIO.write(screenShot, "png", new File("target/webdriver-" + methodName + "_OS" + ".png"));
}