Example usage for java.awt Rectangle setLocation

List of usage examples for java.awt Rectangle setLocation

Introduction

In this page you can find the example usage for java.awt Rectangle setLocation.

Prototype

public void setLocation(Point p) 

Source Link

Document

Moves this Rectangle to the specified location.

Usage

From source file:Main.java

public static void centerOnScreen(Window w, Window parent) {
    Rectangle r = new Rectangle();
    if (parent == null) {
        r.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    } else {/* w w  w .  j a  v a 2  s  . c  o m*/
        r.setLocation(parent.getLocation());
        r.setSize(parent.getSize());
    }
    // Determine the new location of the alert
    int x = r.x + (r.width - w.getWidth()) / 2;
    int y = r.y + (r.height - w.getHeight()) / 2;
    // Move the alert
    w.setLocation(x, y);
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle();

    r.setLocation(new Point(20, 20));
    r.setSize(new Dimension(10, 10));

    g2.fill(r);//from   ww w .ja va 2s. c om
    System.out.println(r.height);

}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle();

    r.setLocation(new Point(20, 20));
    r.setSize(new Dimension(10, 10));

    g2.fill(r);/*from   ww  w.  j av a 2  s . c om*/
    System.out.println(r.isEmpty());

}

From source file:com.github.srec.rec.DefaultScreenShot.java

private Rectangle getScreenSize(JInternalFrame iframe) {
    Point p = iframe.getLocationOnScreen();
    Rectangle r = iframe.getBounds();
    r.setLocation(p);
    return r;/*from  ww  w. j a va  2s .  c  o  m*/
}

From source file:com.hammurapi.jcapture.CaptureFrame.java

public CaptureFrame(final AbstractCaptureApplet applet) throws Exception {
    super("Screen capture");
    setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("camera.png")));

    setUndecorated(true);//from  w ww .  ja  v a 2s.  c o m

    Translucener.makeFrameTranslucent(this);

    setAlwaysOnTop(true);
    this.applet = applet;
    captureConfig = new CaptureConfig();
    captureConfig.load(applet.loadConfig());
    captureConfig.setBackgroundProcessor(applet.getBackgroundProcessor());

    //--- GUI construction ---

    capturePanel = new JPanel();

    final JLabel dimensionsLabel = new JLabel("");
    capturePanel.add(dimensionsLabel, BorderLayout.CENTER);

    capturePanel.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            super.componentResized(e);
            dimensionsLabel.setText(e.getComponent().getWidth() + " x " + e.getComponent().getHeight());
        }
    });

    JButton captureButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle bounds = capturePanel.getBounds();
            Point loc = bounds.getLocation();
            SwingUtilities.convertPointToScreen(loc, capturePanel);
            bounds.setLocation(loc);
            Properties props = captureConfig.setRecordingRectangle(bounds);
            if (props != null) {
                getApplet().storeConfig(props);
            }
            capturing.set(true);
            setVisible(false);
        }

    });
    captureButton.setText("Capture");
    captureButton.setToolTipText("Create a snapshot of the screen");
    capturePanel.add(captureButton, BorderLayout.CENTER);

    recordButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle bounds = capturePanel.getBounds();
            Point loc = bounds.getLocation();
            SwingUtilities.convertPointToScreen(loc, capturePanel);
            bounds.setLocation(loc);
            Properties props = captureConfig.setRecordingRectangle(bounds);
            if (props != null) {
                getApplet().storeConfig(props);
            }
            recording.set(true);
            setVisible(false);
        }

    });
    recordButton.setText("Record");
    setRecordButtonState();
    capturePanel.add(recordButton, BorderLayout.CENTER);

    JButton optionsButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new CaptureOptionsDialog(CaptureFrame.this).setVisible(true);
        }

    });
    optionsButton.setText("Options");
    capturePanel.add(optionsButton, BorderLayout.CENTER);

    JButton cancelButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            CaptureFrame.this.setVisible(false);
        }

    });
    cancelButton.setText("Cancel");
    capturePanel.add(cancelButton, BorderLayout.CENTER);

    getContentPane().add(capturePanel, BorderLayout.CENTER);

    capturePanel.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));

    if (captureConfig.getRecordingRectangle() == null) {
        setSize(400, 300);
        setLocationRelativeTo(null);
    } else {
        setBounds(captureConfig.getRecordingRectangle());
    }

    Insets dragInsets = new Insets(5, 5, 5, 5);
    new ComponentResizer(dragInsets, this);

    ComponentMover cm = new ComponentMover();
    cm.registerComponent(this);
    cm.setDragInsets(dragInsets);

    addComponentListener(new ComponentListener() {

        @Override
        public void componentShown(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentResized(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentMoved(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentHidden(ComponentEvent e) {
            if (capturing.get()) {
                capturing.set(false);
                try {
                    capture();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } else if (recording.get()) {
                recording.set(false);
                record();
            }
        }
    });

}

From source file:storybook.toolkit.swing.SwingUtil.java

public static void expandRectangle(Rectangle rect) {
    Point p = rect.getLocation();
    p.translate(-5, -5);/*from www.j av a 2 s .  c om*/
    rect.setLocation(p);
    rect.grow(10, 10);
}