Example usage for java.awt Rectangle getCenterY

List of usage examples for java.awt Rectangle getCenterY

Introduction

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

Prototype

public double getCenterY() 

Source Link

Document

Returns the Y 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  ww w .ja v a 2s  . c  o m*/

    return null;
}

From source file:simulador.controle.GeradorGraficos.java

@Override
public void propertyChange(PropertyChangeEvent evt) {

    if (DEBUG) {//  ww  w  . j a  v  a 2s .c  om
        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   w  ww.ja va  2s  .c  o 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 w  w.  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:net.java.sip.communicator.gui.AuthenticationSplash.java

/**
 * Centers the window on the screen./*from   ww  w.  j  a  v  a  2  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: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();//  w w w  .j  a  va2s  .  c  om
    }
    //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:knop.psfj.BeadImage.java

/**
 * Gets the enlarged frame./*  www  .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:org.broad.igv.renderer.SpliceJunctionRenderer.java

/**
 * Note:  assumption is that featureList is sorted by pStart position.
 *
 * @param featureList//from www . j  a va2  s.  c  om
 * @param context
 * @param trackRectangle
 * @param track
 */
@Override
public void render(List<IGVFeature> featureList, RenderContext context, Rectangle trackRectangle, Track track) {

    double origin = context.getOrigin();
    double locScale = context.getScale();

    // TODO -- use enum instead of string "Color"
    if ((featureList != null) && !featureList.isEmpty()) {

        // Create a graphics object to draw font names.  Graphics are not cached
        // by font, only by color, so its neccessary to create a new one to prevent
        // affecting other tracks.
        Font font = FontManager.getFont(track.getFontSize());
        Graphics2D fontGraphics = (Graphics2D) context.getGraphic2DForColor(Color.BLACK).create();

        if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) {
            fontGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        }
        fontGraphics.setFont(font);

        //determine whether to show flanking regions
        PreferenceManager prefs = PreferenceManager.getInstance();
        boolean shouldShowFlankingRegions = prefs
                .getAsBoolean(PreferenceManager.SAM_SHOW_JUNCTION_FLANKINGREGIONS);

        // Track coordinates
        double trackRectangleX = trackRectangle.getX();
        double trackRectangleMaxX = trackRectangle.getMaxX();

        SpliceJunctionFeature selectedFeature = (SpliceJunctionFeature) ((FeatureTrack) track)
                .getSelectedFeature();

        // Start of Roche-Tessella modification
        if (track.getAutoScale()) {
            Frequency f = new Frequency();
            List<Integer> scores = new ArrayList<Integer>();

            for (IGVFeature feature : featureList) {
                SpliceJunctionFeature junctionFeature = (SpliceJunctionFeature) feature;
                f.addValue(junctionFeature.getScore());
                scores.add((int) junctionFeature.getScore());
            }

            Collections.sort(scores);
            Collections.reverse(scores);
            for (int s : scores) {
                if (f.getCumPct(s) < 0.99) {
                    maxDepth = s;
                    break;
                }
            }

        }
        // End of Roche-Tessella modification

        for (IGVFeature feature : featureList) {
            SpliceJunctionFeature junctionFeature = (SpliceJunctionFeature) feature;
            //if same junction as selected feature, highlight
            boolean shouldHighlight = false;
            if (selectedFeature != null && selectedFeature.isSameJunction(junctionFeature)) {
                setHighlightFeature(junctionFeature);
                shouldHighlight = true;
            }

            // Get the pStart and pEnd of the entire feature.  at extreme zoom levels the
            // virtual pixel value can be too large for an int, so the computation is
            // done in double precision and cast to an int only when its confirmed its
            // within the field of view.
            int flankingStart = junctionFeature.getStart();
            int flankingEnd = junctionFeature.getEnd();

            int junctionStart = junctionFeature.getJunctionStart();
            int junctionEnd = junctionFeature.getJunctionEnd();

            double virtualPixelStart = Math.round((flankingStart - origin) / locScale);
            double virtualPixelEnd = Math.round((flankingEnd - origin) / locScale);

            double virtualPixelJunctionStart = Math.round((junctionStart - origin) / locScale);
            double virtualPixelJunctionEnd = Math.round((junctionEnd - origin) / locScale);

            // If the any part of the feature fits in the
            // Track rectangle draw it
            if ((virtualPixelEnd >= trackRectangleX) && (virtualPixelStart <= trackRectangleMaxX)) {

                //
                int displayPixelEnd = (int) Math.min(trackRectangleMaxX, virtualPixelEnd);
                int displayPixelStart = (int) Math.max(trackRectangleX, virtualPixelStart);

                float depth = junctionFeature.getJunctionDepth();
                Color color = feature.getColor();

                drawFeature((int) virtualPixelStart, (int) virtualPixelEnd, (int) virtualPixelJunctionStart,
                        (int) virtualPixelJunctionEnd, depth, trackRectangle, context, feature.getStrand(),
                        junctionFeature, shouldHighlight, color, shouldShowFlankingRegions);
            }
        }

        //draw a central horizontal line
        Graphics2D g2D = context.getGraphic2DForColor(COLOR_CENTERLINE);
        g2D.drawLine((int) trackRectangleX, (int) trackRectangle.getCenterY(), (int) trackRectangleMaxX,
                (int) trackRectangle.getCenterY());

    }
}

From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java

/**
 * Draw depth of coverage for the starting or ending flanking region
 *
 * @param g2D/*from  ww  w. ja va 2  s  . co m*/
 * @param pixelStart
 * @param pixelLength
 * @param regionDepthArray
 * @param maxPossibleArcHeight
 * @param trackRectangle
 * @param isPositiveStrand
 */
protected void drawFlankingRegion(Graphics g2D, int pixelStart, int pixelLength, int[] regionDepthArray,
        int maxPossibleArcHeight, Rectangle trackRectangle, boolean isPositiveStrand) {
    for (int i = 0; i < pixelLength; i++) {
        float arrayIndicesPerPixel = (float) regionDepthArray.length / (float) pixelLength;
        int flankingRegionArrayPixelMinIndex = (int) (i * arrayIndicesPerPixel);
        int flankingRegionArrayPixelMaxIndex = (int) ((i + 1) * arrayIndicesPerPixel);
        flankingRegionArrayPixelMinIndex = Math.max(0,
                Math.min(flankingRegionArrayPixelMinIndex, regionDepthArray.length - 1));
        flankingRegionArrayPixelMaxIndex = Math.max(0,
                Math.min(flankingRegionArrayPixelMaxIndex, regionDepthArray.length - 1));

        int meanDepthThisPixel = 0;
        for (int j = flankingRegionArrayPixelMinIndex; j <= flankingRegionArrayPixelMaxIndex; j++)
            meanDepthThisPixel += regionDepthArray[j];
        meanDepthThisPixel /= (flankingRegionArrayPixelMaxIndex - flankingRegionArrayPixelMinIndex + 1);
        meanDepthThisPixel = Math.min(maxDepth, meanDepthThisPixel);
        int pixelHeight = Math.max(maxPossibleArcHeight * meanDepthThisPixel / maxDepth, 2);
        g2D.fillRect(pixelStart + i, (int) trackRectangle.getCenterY() + (isPositiveStrand ? -pixelHeight : 0),
                1, pixelHeight);
    }
}