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

@Override
public void paint(Graphics g, JComponent c) {
    super.paint(g, c);
    if (c instanceof JLayer == false) {
        return;//ww  w  . j a va2 s . c o  m
    }
    JLayer jlayer = (JLayer) c;
    JTabbedPane tabPane = (JTabbedPane) jlayer.getView();
    for (int i = 0; i < tabPane.getTabCount(); i++) {
        Rectangle rect = tabPane.getBoundsAt(i);
        Dimension d = button.getPreferredSize();
        int x = rect.x + rect.width - d.width - 2;
        int y = rect.y + (rect.height - d.height) / 2;
        Rectangle r = new Rectangle(x, y, d.width, d.height);
        button.setForeground(r.contains(pt) ? Color.RED : Color.BLACK);
        SwingUtilities.paintComponent(g, button, p, r);
    }
}

From source file:net.rptools.maptool.client.ui.ChatTypingNotification.java

/**
 * This component is only made visible when there are notifications to be displayed. That means the first couple of
 * IF statements in this method are redundant since paintComponent() will not be called unless the component is
 * visible, and it will only be visible when there are notifications...
 *//*from   w  w  w  .  j a v a 2 s .  c o m*/
@Override
protected void paintComponent(Graphics g) {
    //      System.out.println("Chat panel is painting itself...");
    if (AppPreferences.getTypingNotificationDuration() == 0) {
        return;
    }
    LinkedMap chatTypers = MapTool.getFrame().getChatNotificationTimers().getChatTypers();
    if (chatTypers == null || chatTypers.isEmpty()) {
        return;
    }
    Boolean showBackground = AppPreferences.getChatNotificationShowBackground();

    Graphics2D statsG = (Graphics2D) g.create();

    Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD);
    Font font = AppStyle.labelFont;
    FontMetrics valueFM = g.getFontMetrics(font);
    FontMetrics keyFM = g.getFontMetrics(boldFont);

    int PADDING7 = 7;
    int PADDING3 = 3;
    int PADDING2 = 2;

    BufferedImage img = AppStyle.panelTexture;
    int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight());

    setBorder(null);
    int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin();
    int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin()
            + AppStyle.miniMapBorder.getBottomMargin();

    statsG.setFont(font);
    SwingUtil.useAntiAliasing(statsG);
    Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(),
            height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width,
            getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin()
                    + PADDING2);

    int y = bounds.y + rowHeight;
    rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight());

    setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight)) + AppStyle.miniMapBorder.getTopMargin()
            + AppStyle.miniMapBorder.getBottomMargin()));

    if (showBackground) {
        g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this);
        AppStyle.miniMapBorder.paintAround(statsG, bounds);
    }
    Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7,
            AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(),
            AppStyle.chatImage.getHeight());

    Set<?> keySet = chatTypers.keySet();
    @SuppressWarnings("unchecked")
    Set<String> playerTimers = (Set<String>) keySet;
    for (String playerNamer : playerTimers) {
        if (showBackground) {
            statsG.setColor(new Color(249, 241, 230, 140));
            statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                    (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
            statsG.setColor(new Color(175, 163, 149));
            statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                    (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
        }
        g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(),
                (int) rightRow.getHeight(), this);

        // Values
        statsG.setColor(MapTool.getFrame().getChatTypingLabelColor());
        statsG.setFont(boldFont);
        statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer),
                bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5);

        y += PADDING2 + rowHeight;
    }
    if (showBackground) {
        AppStyle.shadowBorder.paintWithin(statsG, bounds);
    } else {
        setOpaque(false);
    }
}

From source file:accessories.plugins.util.html.ClickableImageCreator.java

/**
 * @param regExpLinkReplacement if for example the link abc must be replaced with FMabcFM,
 * then this string has to be FM$1FM./*from   ww w . j  a  v  a2 s  . c  om*/
 */
public ClickableImageCreator(MindMapNode root, ModeController modeController, String regExpLinkReplacement) {
    super();
    this.root = root;
    this.regExpLinkReplacement = regExpLinkReplacement;
    mapView = modeController.getView();
    if (mapView != null) {
        innerBounds = mapView.getInnerBounds();
    } else {
        // test case: give any bounds:
        innerBounds = new Rectangle(0, 0, 100, 100);
    }
    this.modeController = modeController;
    createArea();
}

From source file:com.ariatemplates.seleniumjavarobot.calibrator.Calibrator.java

public static Point calibrate(RobotizedBrowser robotizedBrowser, int colorTolerance)
        throws InterruptedException {
    Server server = new Server(0);
    try {//from www  . j  a va  2s  .  c o m
        server.setHandler(new CalibrationHandler());
        server.start();
        robotizedBrowser.browser.get("http://127.0.0.1:" + server.getURI().getPort() + "/");
        server.stop();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // call the calibration script:
    @SuppressWarnings("unchecked")
    Map<String, Long> jsInfos = (Map<String, Long>) robotizedBrowser.browser.executeScript(CALIBRATOR_SCRIPT);
    int width = jsInfos.get("width").intValue();
    int height = jsInfos.get("height").intValue();
    SeleniumJavaRobot.log(String.format("Viewport size: %d x %d", width, height));
    Point windowPosition = robotizedBrowser.browser.getWindowPosition();
    Dimension windowSize = robotizedBrowser.browser.getWindowSize();
    Rectangle windowRectangle = new Rectangle(windowPosition.x, windowPosition.y, windowSize.width,
            windowSize.height);
    SeleniumJavaRobot.log("Browser window rectangle: " + windowRectangle);
    // Give some time to the browser to display the expected color:
    Thread.sleep(500);
    // look for the rectangle full of the expected color:
    Rectangle rect = RectangleFinder.findRectangle(robotizedBrowser.robot, CALIBRATION_COLOR, windowRectangle,
            width - 2 * BORDER, height - 2 * BORDER, colorTolerance);
    if (rect == null) {
        throw new RuntimeException("Calibration failed.");
    }
    return new Point(rect.x - BORDER - windowPosition.x, rect.y - BORDER - windowPosition.y);
}

From source file:io.wcm.handler.media.CropDimension.java

/**
 * @return Rectangle/*w  w w .  j a  v  a 2s.  co m*/
 */
public Rectangle2D getRectangle() {
    return new Rectangle((int) getLeft(), (int) getTop(), (int) getWidth(), (int) getHeight());
}

From source file:com.t3.client.ui.ChatTypingNotification.java

/**
 * This component is only made visible when there are notifications to be displayed. That means the first couple of
 * IF statements in this method are redundant since paintComponent() will not be called unless the component is
 * visible, and it will only be visible when there are notifications...
 *//*w  w  w .ja  v  a 2  s  .  c o m*/
@Override
protected void paintComponent(Graphics g) {
    //      System.out.println("Chat panel is painting itself...");
    if (AppPreferences.getTypingNotificationDuration() != 0) {
        LinkedMap<String, Long> chatTypers = TabletopTool.getFrame().getChatNotificationTimers()
                .getChatTypers();
        if (chatTypers == null || chatTypers.isEmpty()) {
            return;
        }
        Boolean showBackground = AppPreferences.getChatNotificationShowBackground();

        Graphics2D statsG = (Graphics2D) g.create();

        Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD);
        Font font = AppStyle.labelFont;
        FontMetrics valueFM = g.getFontMetrics(font);
        FontMetrics keyFM = g.getFontMetrics(boldFont);

        int PADDING7 = 7;
        int PADDING3 = 3;
        int PADDING2 = 2;

        BufferedImage img = AppStyle.panelTexture;
        int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight());

        setBorder(null);
        int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin();
        int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin()
                + AppStyle.miniMapBorder.getBottomMargin();

        statsG.setFont(font);
        SwingUtil.useAntiAliasing(statsG);
        Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(),
                height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width,
                getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin()
                        + PADDING2);

        int y = bounds.y + rowHeight;
        rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight());

        setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight))
                + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin()));

        if (showBackground) {
            g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this);
            AppStyle.miniMapBorder.paintAround(statsG, bounds);
        }
        Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7,
                AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(),
                AppStyle.chatImage.getHeight());

        Set<?> keySet = chatTypers.keySet();
        @SuppressWarnings("unchecked")
        Set<String> playerTimers = (Set<String>) keySet;
        Color c1 = new Color(249, 241, 230, 140);
        Color c2 = new Color(175, 163, 149);
        for (String playerNamer : playerTimers) {
            if (showBackground) {
                statsG.setColor(c1);
                statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                        (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
                statsG.setColor(c2);
                statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                        (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
            }
            g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(),
                    (int) rightRow.getHeight(), this);

            // Values
            statsG.setColor(TabletopTool.getFrame().getChatTypingLabelColor());
            statsG.setFont(boldFont);
            statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer),
                    bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5);

            y += PADDING2 + rowHeight;
        }
        if (showBackground) {
            AppStyle.shadowBorder.paintWithin(statsG, bounds);
        } else {
            setOpaque(false);
        }
    }
}

From source file:XYLayout.java

Rectangle getComponentBounds(Component component, boolean doPreferred) {
    XYConstraints constraints = (XYConstraints) info.get(component);
    if (constraints == null)
        constraints = defaultConstraints;
    Rectangle r = new Rectangle(constraints.x, constraints.y, constraints.width, constraints.height);
    if (r.width <= 0 || r.height <= 0) {
        Dimension d = doPreferred ? component.getPreferredSize() : component.getMinimumSize();
        if (r.width <= 0)
            r.width = d.width;//from  w  w w.j  a v a  2s  .c  o  m
        if (r.height <= 0)
            r.height = d.height;
    }
    return r;
}

From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java

/**
 * Construct a rectangle with the given parameters. Note that in screen
 * coordinates, the origin is the top left edge.
 * /*from w  w w  .j  a va  2  s  .  c  om*/
 * @param leftEdge
 *            the distance of the box from the y axis
 * @param bottomEdge
 *            the distance of the box from the x axis (in screen
 *            coordinates, a more appropriate name would be <code>topEdge</code>
 * @param width
 *            the width of the box
 * @param height
 *            the height of the box
 */
public BoundingBox(int leftEdge, int bottomEdge, int width, int height) {
    rect = new Rectangle(leftEdge, bottomEdge, width, height);
}

From source file:SquareLayout.java

/**
 * Lays out the container in the specified panel. 
 *//*from ww w  .  ja v a  2s. c  om*/

public void layoutContainer(Container container) {
    Component child = getChild(container);
    if (child == null)
        return;

    Dimension parentSize = container.getSize();
    Insets insets = container.getInsets();

    // A rectangle specifying the actual area available for layout. 
    Rectangle rect = new Rectangle(insets.left, insets.top, parentSize.width - insets.left - insets.right,
            parentSize.height - insets.top - insets.bottom);

    int minSize = rect.width < rect.height ? rect.width : rect.height;
    int widthSpace = rect.width - minSize;
    int heightSpace = rect.height - minSize;
    child.setBounds(rect.x + (int) (widthSpace * child.getAlignmentX()),
            rect.y + (int) (heightSpace * child.getAlignmentY()), minSize, minSize);
}

From source file:com.iana.dver.pdf.scrapper.DVERScrapperTask.java

/**
 * Step - 1 : Read PDF from the path//from  w w w  . ja v  a  2 s .  com
 * 
 * @param file
 * @return
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private PDFTextStripperByArea readDVER(final File file) throws IOException {
    PDDocument document = PDDocument.load(file);
    PDFTextStripperByArea textStripper = new PDFTextStripperByArea();

    Rectangle addressRect = new Rectangle(10, 50, 200, 50);
    textStripper.addRegion("ADDRESS", addressRect);

    Rectangle reportInfoRect = new Rectangle(300, 50, 300, 50);
    textStripper.addRegion("REPORT_INFO", reportInfoRect);

    Rectangle iepRect = new Rectangle(10, 100, 630, 40);
    textStripper.addRegion("IEP_INFO", iepRect);

    Rectangle mcRect = new Rectangle(10, 140, 630, 80);
    textStripper.addRegion("MC_INFO", mcRect);

    Rectangle driverQueRect = new Rectangle(10, 220, 630, 20);
    textStripper.addRegion("DRIVER_CHOICE", driverQueRect);

    Rectangle vehicleIdRect = new Rectangle(10, 240, 630, 30);
    textStripper.addRegion("VEHICLE_ID", vehicleIdRect);

    Rectangle brkAdjRect = new Rectangle(10, 270, 630, 20);
    textStripper.addRegion("BREAK_ADJ", brkAdjRect);

    Rectangle violationRect = new Rectangle(10, 290, 630, 30);
    textStripper.addRegion("CHASSIS_VIOLATION", violationRect);

    Rectangle otherViolationRect = new Rectangle(10, 320, 630, 50);
    textStripper.addRegion("OTHER_CHASSIS_VIOLATION", otherViolationRect);

    Rectangle driverNotesRect = new Rectangle(10, 370, 630, 30);
    textStripper.addRegion("DRIVER_NOTES", driverNotesRect);

    Rectangle iepNotesRect = new Rectangle(10, 400, 630, 60);
    textStripper.addRegion("IEP_NOTES", iepNotesRect);

    Rectangle dverCreationRect = new Rectangle(10, 720, 630, 60);
    textStripper.addRegion("CREATION_NOTES", dverCreationRect);

    List<PDPage> allPages = document.getDocumentCatalog().getAllPages();
    PDPage firstPage = allPages.get(0);
    textStripper.extractRegions(firstPage);

    return textStripper;
}