Example usage for java.awt Rectangle getCenterX

List of usage examples for java.awt Rectangle getCenterX

Introduction

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

Prototype

public double getCenterX() 

Source Link

Document

Returns the X coordinate of the center of the framing rectangle of the Shape in double precision.

Usage

From source file:Main.java

private static Rectangle getScreenBounds(Window aWindow) {

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();

    if (aWindow == null)
        return devices[0].getDefaultConfiguration().getBounds();

    Rectangle bounds = aWindow.getBounds();
    int centerX = (int) bounds.getCenterX();
    int centerY = (int) bounds.getCenterY();

    for (GraphicsDevice device : devices) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        Rectangle rect = gc.getBounds();
        if (rect.contains(centerX, centerY))
            return rect;
    }//from w  w  w. j a v a  2 s .c  o  m

    return null;
}

From source file:simulador.controle.GeradorGraficos.java

@Override
public void propertyChange(PropertyChangeEvent evt) {

    if (DEBUG) {//from   w w w. j a va  2s.c o  m
        System.out.println("GeradorGraficos.propertyChange: " + evt.getPropertyName());
    }

    switch (evt.getPropertyName()) {

    case BarraFerramentas.BT_SELECAO:

        Map<Integer, Point> pontosRadios = new HashMap();

        Map<Integer, Boolean> valoresCheckbox = (Map) evt.getNewValue();
        Map<Integer, Radio2D> radios2D = painelDesign.getRadios2D();

        for (Map.Entry<Integer, Boolean> parCheckbox : valoresCheckbox.entrySet()) {
            System.out.println("parCheckbox[" + parCheckbox.getKey() + ", " + parCheckbox.getValue() + "]");

            if (parCheckbox.getValue()) {

                Radio2D r2D = radios2D.get(parCheckbox.getKey());
                Rectangle forma = (Rectangle) r2D.getForma();
                Point localizacao = new Point((int) forma.getCenterX(), (int) forma.getCenterY());
                System.out
                        .println("radioCheckBox - localizacao: (" + localizacao.x + ", " + localizacao.y + ")");
                pontosRadios.put(parCheckbox.getKey(), localizacao);

            }
        }

        //int[] coordCelPontoClicado = painelDesign.buscarCelula((Point) evt.getOldValue());
        //PainelDesign.Celula cel = painelDesign.getMapaCelulas().get(coordCelPontoClicado[0]).get(coordCelPontoClicado[1]);
        //Point pontoFinal = new Point(cel.x, cel.y);
        Point pontoClicado = (Point) evt.getOldValue();

        criarGraficoRadiais(pontosRadios, pontoClicado);

        break;

    }

}

From source file:com.kbot2.scriptable.methods.wrappers.Interface.java

public Point getCenter() {
    Rectangle area = getArea();
    return new Point((int) area.getCenterX(), (int) area.getCenterY());
}

From source file:de.tor.tribes.ui.views.DSWorkbenchFormFrame.java

private void centerFormInGame() {
    List<AbstractForm> selection = getSelectedForms();
    if (selection.isEmpty()) {
        showError("Keine Zeichnung gewhlt");
        return;//from ww w. j  a va2 s  .co  m
    }
    Rectangle r = selection.get(0).getBounds();

    if (r != null) {
        BrowserInterface.centerCoordinate((int) Math.rint(r.getCenterX()), (int) Math.rint(r.getCenterY()));
    } else {
        showInfo("Ein Mittelpunkt kann fr diese Zeichnung nicht bestimmt werden");
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchFormFrame.java

private void centerFormOnMap() {
    List<AbstractForm> selection = getSelectedForms();
    if (selection.isEmpty()) {
        showError("Keine Zeichnung gewhlt");
        return;//from w ww .  j  a  v a 2 s. c  om
    }
    Rectangle r = selection.get(0).getBounds();

    if (r != null) {
        DSWorkbenchMainFrame.getSingleton().centerPosition((int) Math.rint(r.getCenterX()),
                (int) Math.rint(r.getCenterY()));
    } else {
        showInfo("Ein Mittelpunkt kann fr diese Zeichnung nicht bestimmt werden");
    }
}

From source file:JXTransformer.java

public void paint(Graphics g) {
    //repaint the whole transformer in case the view component was repainted
    Rectangle clipBounds = g.getClipBounds();        
    if (clipBounds != null && !clipBounds.equals(visibleRect)) {
        repaint();/*from w ww .ja  va  2s .c  o  m*/
    }
    //clear the background
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    if (view != null && at.getDeterminant() != 0) {
        Graphics2D g2 = (Graphics2D) g.create();
        Insets insets = getInsets();
        Rectangle bounds = getBounds();
            
        //don't forget about insets
        bounds.x += insets.left;
        bounds.y += insets.top;
        bounds.width -= insets.left + insets.right;
        bounds.height -= insets.top + insets.bottom;
        double centerX1 = bounds.getCenterX();
        double centerY1 = bounds.getCenterY();

        Rectangle tb = getTransformedSize();
        double centerX2 = tb.getCenterX();
        double centerY2 = tb.getCenterY();

        //set antialiasing by default
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        if (renderingHints != null) {
            g2.addRenderingHints(renderingHints);
        }
        //translate it to the center of the view component again
        double tx = centerX1 - centerX2 - getX();
        double ty = centerY1 - centerY2 - getY();
        g2.translate((int) tx, (int) ty);
        g2.transform(at);
        view.paint(g2);
        g2.dispose();
    }
    //paint the border
    paintBorder(g);
}

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

/**
 * Centers the window on the screen./*from w  w w.  jav  a2  s .c  om*/
 */
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:knop.psfj.BeadImage.java

/**
 * Gets the enlarged frame.//  w ww  .j a  v  a 2s . co  m
 *
 * @param r the r
 * @param f the f
 * @return the enlarged frame
 */
public static Rectangle getEnlargedFrame(Rectangle r, int f) {
    Rectangle rn = new Rectangle();
    rn.setLocation(round(r.getCenterX() - f / 2), round(r.getCenterY() - f / 2));
    rn.setSize(f, f);

    return rn;
}

From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java

private int drawText(Graphics2D graphics, String text, int hOffset) {
    Rectangle r = getTextBoundsRectangle();
    Rectangle2D textBounds = graphics.getFontMetrics().getStringBounds(text, graphics);
    if (textBounds.getWidth() > r.getWidth() - 4) {
        int y = coords[1] + hOffset;
        AttributedString attributedString = new AttributedString(text);
        attributedString.addAttribute(TextAttribute.FONT, graphics.getFont());
        AttributedCharacterIterator characterIterator = attributedString.getIterator();
        LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, graphics.getFontRenderContext());
        while (measurer.getPosition() < characterIterator.getEndIndex()) {
            TextLayout textLayout = measurer.nextLayout((float) r.getWidth() - 4);
            y += textLayout.getAscent();
            float x = (float) (r.getCenterX() + 2 - textLayout.getBounds().getCenterX());
            textLayout.draw(graphics, x, y);
            y += textLayout.getDescent() + textLayout.getLeading();
        }/*ww w  . ja  v  a 2 s  . co  m*/
        return y - coords[1];
    } else {
        graphics.drawString(text, (float) (r.getCenterX() + 2 - textBounds.getCenterX()),
                (float) (coords[1] + textBounds.getHeight() + hOffset));
        return (int) (textBounds.getHeight() + hOffset + 3);
    }
}

From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java

public Point getBendpoint() {
    Rectangle allRect = getRectangle();
    return new Point((int) allRect.getCenterX(), (int) allRect.getCenterY());
}