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

public Rectangle getBounds() {
    if (bounds != null)
        return bounds;
    if (size == 0)
        return null;
    bounds = new Rectangle(rects[0]);
    for (int i = 1; i < size; i++) {
        Rectangle r = rects[i];//w  w  w .j a v a2  s . c o m
        if (r.x < bounds.x) {
            bounds.width = bounds.x + bounds.width - r.x;
            bounds.x = r.x;
        }
        if (r.y < bounds.y) {
            bounds.height = bounds.y + bounds.height - r.y;
            bounds.y = r.y;
        }
        if (r.x + r.width > bounds.x + bounds.width)
            bounds.width = r.x + r.width - bounds.x;
        if (r.y + r.height > bounds.y + bounds.height)
            bounds.height = r.y + r.height - bounds.y;
    }
    return bounds;
}

From source file:net.java.sip.communicator.gui.AuthenticationSplash.java

/**
 * Centers the window on the screen./*from  ww w.j ava  2s. c  o  m*/
 */
private void centerWindow() {
    Rectangle screen = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    Point center = new Point((int) screen.getCenterX(), (int) screen.getCenterY());
    Point newLocation = new Point(center.x - this.getWidth() / 2, center.y - this.getHeight() / 2);
    if (screen.contains(newLocation.x, newLocation.y, this.getWidth(), this.getHeight())) {
        this.setLocation(newLocation);
    }
}

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

/**
 * @throws HeadlessException//from w ww .  j a va2 s.  c o  m
 */
public AgentDebuggerFrame(final boolean isStandalone, String serviceUrl) throws HeadlessException {
    super("Intuit Tank Agent Debugger");
    workingDir = PanelBuilder.createWorkingDir(this, serviceUrl);
    setSize(new Dimension(1024, 800));
    setBounds(new Rectangle(getSize()));
    setPreferredSize(getSize());
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setLayout(new BorderLayout());
    this.standalone = isStandalone;
    addWindowListener(new WindowAdapter() {
        public void windowClosed(WindowEvent e) {
            quit();
        }
    });
    errorIcon = ActionProducer.getIcon("bullet_error.png", IconSize.SMALL);
    modifiedIcon = ActionProducer.getIcon("bullet_code_change.png", IconSize.SMALL);
    skippedIcon = ActionProducer.getIcon("skip.png", IconSize.SMALL);

    this.glassPane = new InfiniteProgressPanel();
    setGlassPane(glassPane);
    debuggerActions = new ActionProducer(this, serviceUrl);
    requestResponsePanel = new RequestResponsePanel(this);
    requestResponsePanel.init();
    testPlanChooser = new JComboBox();
    testPlanChooser.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getItem() != null) {
                HDTestPlan selected = (HDTestPlan) event.getItem();
                if (!selected.equals(currentTestPlan)) {
                    setCurrentTestPlan(selected);
                }
            }

        }
    });

    tankClientChooser = new JComboBox<TankClientChoice>();
    debuggerActions.setChoiceComboBoxOptions(tankClientChooser);

    actionComponents = new ActionComponents(standalone, testPlanChooser, tankClientChooser, debuggerActions);
    addScriptChangedListener(actionComponents);
    setJMenuBar(actionComponents.getMenuBar());

    Component topPanel = PanelBuilder.createTopPanel(actionComponents);
    Component bottomPanel = PanelBuilder.createBottomPanel(this);
    Component contentPanel = PanelBuilder.createContentPanel(this);

    final JPopupMenu popup = actionComponents.getPopupMenu();
    scriptEditorTA.setPopupMenu(null);

    scriptEditorTA.addMouseListener(new MouseAdapter() {
        int lastHash;

        @Override
        public void mousePressed(MouseEvent e) {
            maybeShow(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            maybeShow(e);
        }

        private void maybeShow(MouseEvent e) {
            if (lastHash == getHash(e)) {
                return;
            }
            if (e.isPopupTrigger()) {
                // select the line
                try {
                    int offset = scriptEditorTA.viewToModel(e.getPoint());
                    Rectangle modelToView = scriptEditorTA.modelToView(offset);
                    Point point = new Point(modelToView.x + 1, e.getPoint().y);
                    if (modelToView.contains(point)) {
                        if (!multiSelect) {
                            int line = scriptEditorTA.getLineOfOffset(offset);
                            scriptEditorTA.setCurrentLine(line);
                        }
                        popup.show(e.getComponent(), e.getX(), e.getY());
                    }
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
            } else if (e.isShiftDown()) {
                int line = scriptEditorTA.getCaretLineNumber();
                int start = Math.min(line, lastLine);
                int end = Math.max(line, lastLine);
                multiSelect = end - start > 1;
                if (multiSelect) {
                    multiSelectStart = start;
                    multiSelectEnd = end;
                    try {
                        scriptEditorTA.setEnabled(true);
                        scriptEditorTA.select(scriptEditorTA.getLineStartOffset(start),
                                scriptEditorTA.getLineEndOffset(end));
                        scriptEditorTA.setEnabled(false);
                    } catch (BadLocationException e1) {
                        e1.printStackTrace();
                        multiSelect = false;
                    }
                }
            } else {
                multiSelect = false;
                lastLine = scriptEditorTA.getCaretLineNumber();
            }
            lastHash = getHash(e);
        }

        private int getHash(MouseEvent e) {
            return new HashCodeBuilder().append(e.getButton()).append(e.getSource().hashCode())
                    .append(e.getPoint()).toHashCode();
        }

    });

    JSplitPane mainSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    mainSplit.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    mainSplit.setTopComponent(contentPanel);
    mainSplit.setBottomComponent(bottomPanel);
    mainSplit.setDividerLocation(600);
    mainSplit.setResizeWeight(0.8D);
    mainSplit.setDividerSize(5);

    add(topPanel, BorderLayout.NORTH);
    add(mainSplit, BorderLayout.CENTER);

    WindowUtil.centerOnScreen(this);
    pack();

    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();

    manager.addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
                handleKeyEvent(e);
            }
            return false;
        }
    });
}

From source file:de.peterspan.csv2db.AppWindow.java

private void createContent() {
    PanelBuilder.setOpaqueDefault(true);
    frame.getContentPane().setLayout(new JideBorderLayout());

    FormLayout layout = new FormLayout("fill:pref:grow"); //$NON-NLS-1$
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();//  ww w . ja v  a2  s  .  co  m
    mainPanel = new MainPanel(frame);
    builder.append(mainPanel);

    frame.getContentPane().add(new JScrollPane(builder.getPanel()), BorderLayout.CENTER);

    Rectangle bounds = new Rectangle(builder.getPanel().getPreferredSize());
    bounds.grow(20, 35);
    frame.setResizable(true);

    frame.setBounds(bounds);
    frame.setLocationRelativeTo(null);

}

From source file:Utilities.java

/**
 * Returns the usable area of the screen where applications can place its
 * windows.  The method subtracts from the screen the area of taskbars,
 * system menus and the like./*from w w w  . ja  v a  2 s  . com*/
 *
 * @param gconf the GraphicsConfiguration of the monitor
 * @return the rectangle of the screen where one can place windows
 *
 * @since 2.5
 */
public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) {
    if (gconf == null) {
        gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration();
    }

    Rectangle bounds = new Rectangle(gconf.getBounds());

    String str;

    str = System.getProperty("netbeans.screen.insets"); // NOI18N

    if (str != null) {
        StringTokenizer st = new StringTokenizer(str, ", "); // NOI18N

        if (st.countTokens() == 4) {
            try {
                bounds.y = Integer.parseInt(st.nextToken());
                bounds.x = Integer.parseInt(st.nextToken());
                bounds.height -= (bounds.y + Integer.parseInt(st.nextToken()));
                bounds.width -= (bounds.x + Integer.parseInt(st.nextToken()));
            } catch (NumberFormatException ex) {
                Logger.getAnonymousLogger().log(Level.WARNING, null, ex);
            }
        }

        return bounds;
    }

    str = System.getProperty("netbeans.taskbar.height"); // NOI18N

    if (str != null) {
        bounds.height -= Integer.getInteger(str, 0).intValue();

        return bounds;
    }

    try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Insets insets = toolkit.getScreenInsets(gconf);
        bounds.y += insets.top;
        bounds.x += insets.left;
        bounds.height -= (insets.top + insets.bottom);
        bounds.width -= (insets.left + insets.right);
    } catch (Exception ex) {
        Logger.getAnonymousLogger().log(Level.WARNING, null, ex);
    }

    return bounds;
}

From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java

/**
 * Fill the frame with content//from   w w  w .j  a  v a  2 s.c om
 */
private void createContent() {
    frame.getContentPane().setLayout(new JideBorderLayout());

    FormLayout layout = new FormLayout("fill:pref:grow"); //$NON-NLS-1$
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();
    mainPanel = new MainPanel(frame);
    builder.append(mainPanel);

    frame.getContentPane().add(new JScrollPane(builder.getPanel()), BorderLayout.CENTER);

    Rectangle bounds = new Rectangle(builder.getPanel().getPreferredSize());
    bounds.grow(20, 35);
    frame.setResizable(true);

    frame.setBounds(bounds);
    frame.setLocationRelativeTo(null);

}

From source file:FormattedTextFieldExample.java

public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
    a = adjustAllocation(a);//from   ww  w. ja  v a 2  s.  co m
    Rectangle r = new Rectangle(a.getBounds());
    FontMetrics fm = getFontMetrics();
    r.height = fm.getHeight();

    int oldCount = contentBuff.count;

    if (pos < offsets.length) {
        contentBuff.count = offsets[pos];
    } else {
        // Beyond the end: point to the location
        // after the last model position.
        contentBuff.count = offsets[offsets.length - 1] + 1;
    }

    int offset = Utilities.getTabbedTextWidth(contentBuff, metrics, 0, this, element.getStartOffset());
    contentBuff.count = oldCount;

    r.x += offset;
    r.width = 1;

    return r;
}

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

private void createDetailsDialog() {
    detailsDialog = new JDialog(this);
    detailsDialog.setModal(true);//from  w  w w  .java  2  s  .com
    detailsDialog.setLayout(new BorderLayout());

    detailsTF = new JTextArea();
    detailsTF.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(detailsTF);
    detailsDialog.add(scrollPane, BorderLayout.CENTER);
    detailsDialog.setModal(true);
    detailsDialog.setSize(new Dimension(500, 300));
    detailsDialog.setBounds(new Rectangle(getSize()));
    detailsDialog.setPreferredSize(getSize());
    WindowUtil.centerOnScreen(detailsDialog);
}

From source file:jdroidremote.ServerFrame.java

private void startMonitoring() {
    thStartMonitoring = new Thread(new Runnable() {
        @Override/* w w  w  .j a  va  2 s.c  o m*/
        public void run() {
            try {

                System.out.println("START MONITORING..........");

                //                    while (1 == 1) {
                BufferedImage screenCapture = robot
                        .createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));

                Image cursor = ImageIO.read(new File("cursor.png"));
                int x = MouseInfo.getPointerInfo().getLocation().x;
                int y = MouseInfo.getPointerInfo().getLocation().y;
                Graphics2D graphics2D = screenCapture.createGraphics();
                graphics2D.drawImage(cursor, x, y, 13, 25, null); // cursor.gif is 16x16 size.
                ImageIO.write(screenCapture, "JPG", new File("2.jpg"));

                Thread.sleep(200);

                File file = new File("2.jpg");

                // Reading a Image file from file system
                FileInputStream imageInFile = new FileInputStream(file);
                byte imageData[] = new byte[(int) file.length()];
                imageInFile.read(imageData);

                // Converting Image byte array into Base64 String
                String imageDataString = ImageManipulation.encodeImage(imageData);

                System.out.println(imageDataString.length());

                //                        System.out.println(imageDataString);
                //                        // Converting a Base64 String into Image byte array
                //                        byte[] imageByteArray = ImageManipulation.decodeImage(imageDataString);
                //
                //                        // Write a image byte array into file system
                //                        FileOutputStream imageOutFile = new FileOutputStream(
                //                                "_avatar_.jpg");
                //
                //                        imageOutFile.write(imageByteArray);
                imageInFile.close();
                //                        imageOutFile.close();

                System.out.println("Image Successfully Manipulated!");

                // Split the five sandwiches.!
                StringBuilder sbImageDataString = new StringBuilder(imageDataString);

                for (int i = 0; i < sbImageDataString.toString().length(); i += 30000) {
                    if (i + 30000 <= sbImageDataString.toString().length()) {
                        dos.writeUTF(sbImageDataString.substring(i, i + 30000));
                        dos.flush();
                    } else {
                        dos.writeUTF(sbImageDataString.substring(i, sbImageDataString.toString().length()));
                        dos.flush();
                    }

                }
                dos.writeUTF("...");
                dos.flush();

                //                    }
            } catch (IOException ex) {
                Logger.getLogger(ServerFrame.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InterruptedException ex) {
                Logger.getLogger(ServerFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:ExtendedParagraphExample.java

public void paint(Graphics g, Shape a) {
    Container comp = getContainer();
    Rectangle alloc = new Rectangle(a.getBounds());

    alloc.x += paraInsets.left;//from ww  w. j  a  v a  2  s  .co m
    alloc.y += paraInsets.top;
    alloc.width -= paraInsets.left + paraInsets.right;
    alloc.height -= paraInsets.top + paraInsets.bottom;

    if (bgColor != null) {
        Color origColor = g.getColor();
        g.setColor(bgColor);
        g.fillRect(alloc.x, alloc.y, alloc.width, alloc.height);
        g.setColor(origColor);
    }

    if (border != null) {
        // Paint the border
        border.paintBorder(comp, g, alloc.x, alloc.y, alloc.width, alloc.height);
    }
    super.paint(g, a); // Note: pass ORIGINAL allocation
}