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:BufferedDraw.java

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

    if (firstTime) {
        Dimension dim = getSize();
        int w = dim.width;
        int h = dim.height;
        area = new Rectangle(dim);
        bi = (BufferedImage) createImage(w, h);
        big = bi.createGraphics();//from  w w  w.  jav a  2 s.c om
        rect.setLocation(w / 2 - 50, h / 2 - 25);
        big.setStroke(new BasicStroke(8.0f));
        firstTime = false;
    }

    big.setColor(Color.white);
    big.clearRect(0, 0, area.width, area.height);

    big.setPaint(Color.red);
    big.draw(rect);
    big.setPaint(Color.blue);
    big.fill(rect);

    g2.drawImage(bi, 0, 0, this);
}

From source file:net.librec.util.Systems.java

/**
 * Capture screen with the input string as file name
 *
 * @param fileName  a given file name/*from  w  w  w . ja  va  2 s  . co  m*/
 * @throws Exception if error occurs
 */
public static void captureScreen(String fileName) throws Exception {

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Rectangle screenRectangle = new Rectangle(screenSize);
    Robot robot = new Robot();
    BufferedImage image = robot.createScreenCapture(screenRectangle);

    File file = new File(fileName);
    ImageIO.write(image, "png", file);

    LOG.debug("A screenshot is captured to: " + file.getPath());
}

From source file:GUIUtils.java

/**
 * Centers <CODE>wind</CODE> within the screen. If centering would cause the
 * title bar to go off the top of the screen then move the window down.
 * /*  w w w .ja v a  2 s .  c  o m*/
 * @param wind
 *          The Window to be centered.
 * 
 * @throws IllegalArgumentException
 *           If <TT>wind</TT> is <TT>null</TT>.
 */
public static void centerWithinScreen(Window wind) {
    if (wind == null) {
        throw new IllegalArgumentException("null Window passed");
    }
    final Toolkit toolKit = Toolkit.getDefaultToolkit();
    final Rectangle rcScreen = new Rectangle(toolKit.getScreenSize());
    final Dimension windSize = wind.getSize();
    final Dimension parentSize = new Dimension(rcScreen.width, rcScreen.height);
    if (windSize.height > parentSize.height) {
        windSize.height = parentSize.height;
    }
    if (windSize.width > parentSize.width) {
        windSize.width = parentSize.width;
    }
    center(wind, rcScreen);
}

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

public VariableDialog(AgentDebuggerFrame f, Map<String, String> variables) {
    super(f, true);
    this.f = f;//from  w  ww  .  j ava2s . c  om
    setLayout(new BorderLayout());
    setTitle("View Edit Project Variables");
    DefaultTableModel model = new DefaultTableModel();
    model.addColumn("Variable Name");
    model.addColumn("Variable Value");
    List<String> keys = new ArrayList<String>(variables.keySet());
    Collections.sort(keys);
    for (String key : keys) {
        Object[] data = new Object[2];
        data[0] = key;
        data[1] = variables.get(key);
        model.addRow(data);
    }
    table = new JTable(model);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(this);
    table.setGridColor(Color.GRAY);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    table.setBorder(BorderFactory.createLineBorder(Color.GRAY));
    table.setShowGrid(true);
    table.getTableHeader().setReorderingAllowed(false);

    JScrollPane sp = new JScrollPane(table);
    JPanel panel = new JPanel(new BorderLayout());

    panel.add(table.getTableHeader(), BorderLayout.NORTH);
    panel.add(sp, BorderLayout.CENTER);

    add(panel, BorderLayout.CENTER);
    add(createButtonPanel(), BorderLayout.SOUTH);
    setSize(new Dimension(800, 600));
    setBounds(new Rectangle(getSize()));
    setPreferredSize(getSize());
    WindowUtil.centerOnParent(this);
}

From source file:ShapeMover.java

public void update(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension dim = getSize();//from  w  ww  .j  a va  2s. c o m
    int w = (int) dim.getWidth();
    int h = (int) dim.getHeight();
    g2.setStroke(new BasicStroke(8.0f));

    if (isFirstTime) {
        area = new Rectangle(dim);
        rect.setLocation(w / 2 - 50, h / 2 - 25);
        isFirstTime = false;
    }

    // Clears the rectangle that was previously drawn.
    g2.setPaint(Color.white);
    g2.fillRect(0, 0, w, h);

    g2.setColor(Color.red);
    g2.draw(rect);
    g2.setColor(Color.black);
    g2.fill(rect);
}

From source file:com.mgmtp.jfunk.core.util.ScreenCapturer.java

/**
 * Captures the whole screen and saves it as png to the specified file. The file must have the
 * extension {@code png}. Any necessary but non-existent parent directories of the specified
 * file are created./*from ww  w  . j a v a 2 s. c  o m*/
 * 
 * @param file
 *            the file to save the screenshot to
 */
public static void captureScreen(final File file) {
    Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    captureScreenRect(file, rectangle);
}

From source file:OAT.ui.BarChartFrame.java

@Override
protected void init() {
    //        setJMenuBar(new MainMenuBar(this));
    //        setContentPane(chartPanel);
    //        setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    //set getItemCount and location
    //Rectangle mainBound = Main.frame.getBounds();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    screenSize.height = screenSize.height - MENU_BAR_HEIGHT;
    //Dimension chartFrameSize = getChartPanelSize();
    //chartFrameSize.height += MENU_BAR_HEIGHT;

    int gridRows = Main.chartFramesGrid.length;
    int gridColumns = Main.chartFramesGrid[0].length;

    boolean isOccupied = false;
    for (int c = 0; c < gridColumns; c++) {
        for (int r = 0; r < gridRows; r++) {
            Rectangle bound = Main.chartFramesGrid[r][c];

            for (BarChartFrame existingFrame : Main.chartFrames) {
                if (bound.contains(existingFrame.getLocation())
                        || existingFrame.getBounds().contains(bound.intersection(new Rectangle(screenSize)))) {
                    isOccupied = true;//www .java  2 s  .com
                    break;
                }
            }

            if (!isOccupied) {
                setBounds(bound);
                break;
            }
        }

        if (!isOccupied) {
            break;
        }
    }

    if (isOccupied) {
        setBounds(Main.chartFramesGrid[Main.lastChartFrameGridId
                % gridRows][(Main.lastChartFrameGridId / gridRows) % gridColumns]);
    }

    Main.lastChartFrameGridId++;

    Main.chartFrames.add(this);

    addComponentListener(new java.awt.event.ComponentAdapter() {

        @Override
        public void componentHidden(java.awt.event.ComponentEvent evt) {
            formComponentHidden(evt);
        }
    });

    //pack and display
    pack();
}

From source file:com.intuit.tank.tools.script.ScriptFilterRunner.java

/**
 * @throws HeadlessException/*from   ww  w  . j  a v  a  2s  .com*/
 */
public ScriptFilterRunner(final boolean terminate, String serviceUrl) throws HeadlessException {
    super("Intuit Tank Script Filter Editor");
    setSize(new Dimension(1024, 800));
    setBounds(new Rectangle(getSize()));
    setPreferredSize(getSize());
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setLayout(new BorderLayout());
    addWindowListener(new WindowAdapter() {
        public void windowClosed(WindowEvent e) {
            if (terminate) {
                System.exit(0);
            }
        }
    });
    scriptServiceClient = new ScriptServiceClient(serviceUrl);

    Component topPanel = createTopPanel();
    Component bottomPanel = createBottomPanel();
    Component contentPanel = createContentPanel();

    add(topPanel, BorderLayout.NORTH);
    add(contentPanel, BorderLayout.CENTER);
    add(bottomPanel, BorderLayout.SOUTH);

    WindowUtil.centerOnScreen(this);
    pack();
}

From source file:com.wet.wired.jsr.recorder.DesktopScreenRecorder.java

public Rectangle initialiseScreenCapture() {
    try {/*w  w  w  .j av  a  2 s .c  o m*/
        robot = new Robot();
    } catch (AWTException awe) {
        awe.printStackTrace();
        return null;
    }
    return new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
}