Example usage for java.awt.geom Rectangle2D getHeight

List of usage examples for java.awt.geom Rectangle2D getHeight

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getHeight.

Prototype

public abstract double getHeight();

Source Link

Document

Returns the height of the framing rectangle in double precision.

Usage

From source file:pku.sei.checkedcoverage.jung.ShowJungGraph.java

public void displayGraph(DirectedGraph<VertexType, SliceEdge<VertexType>> graph) {
    JFrame mainFrame = new JFrame("slice graph display");
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Layout<VertexType, SliceEdge<VertexType>> layout = new KKLayout<VertexType, SliceEdge<VertexType>>(graph);
    final VisualizationViewer<VertexType, SliceEdge<VertexType>> viewer = new VisualizationViewer<VertexType, SliceEdge<VertexType>>(
            layout);/* w ww  .  j  a v a 2 s  .  c o m*/

    viewer.getRenderContext().setVertexLabelTransformer(this.vertexLabelTransformer);
    viewer.setVertexToolTipTransformer(this.vertexTooltipTransformer);
    viewer.getRenderContext().setEdgeLabelTransformer(new Transformer<SliceEdge<VertexType>, String>() {
        public String transform(SliceEdge<VertexType> edge) {
            Variable var = edge.getVariable();
            if (var instanceof ArrayElement) {
                ArrayElement elem = (ArrayElement) var;
                return "arr" + elem.getArrayId() + "[" + elem.getArrayIndex() + "]";
            } else if (var instanceof LocalVariable) {
                LocalVariable localVar = (LocalVariable) var;
                if (localVar.getVarName() != null)
                    return localVar.getVarName();
                return "local" + localVar.getVarIndex();
            } else if (var instanceof StackEntry) {
                return "stack";
            } else if (var instanceof ObjectField) {
                ObjectField objField = (ObjectField) var;
                return "obj" + objField.getObjectId() + "." + objField.getFieldName();
            } else if (var instanceof StaticField) {
                StaticField objField = (StaticField) var;
                String ownerInternalClassName = objField.getOwnerInternalClassName();
                String simpleClassName = getSimpleClassName(ownerInternalClassName);
                return simpleClassName + "." + objField.getFieldName();
            } else {
                assert var == null;
                return "";
            }
        }
    });
    viewer.setEdgeToolTipTransformer(new Transformer<SliceEdge<VertexType>, String>() {
        public String transform(SliceEdge<VertexType> edge) {
            Variable var = edge.getVariable();
            if (var instanceof ArrayElement) {
                ArrayElement elem = (ArrayElement) var;
                return "Array element " + elem.getArrayIndex() + " of array #" + elem.getArrayId();
            } else if (var instanceof LocalVariable) {
                LocalVariable localVar = (LocalVariable) var;
                if (localVar.getVarName() != null)
                    return "Local variable \"" + localVar.getVarName() + "\"";
                return "Local variable #" + localVar.getVarIndex();
            } else if (var instanceof StackEntry) {
                return "Dependency over the operand stack";
            } else if (var instanceof ObjectField) {
                ObjectField objField = (ObjectField) var;
                return "Field \"" + objField.getFieldName() + "\" of object #" + objField.getObjectId();
            } else if (var instanceof StaticField) {
                StaticField objField = (StaticField) var;
                String ownerInternalClassName = objField.getOwnerInternalClassName();
                return "Static field \"" + objField.getFieldName() + "\" of class \""
                        + Type.getType(ownerInternalClassName).getClassName();
            } else {
                assert var == null;
                return "Control dependency";
            }
        }
    });
    viewer.getRenderContext().setEdgeDrawPaintTransformer(new Transformer<SliceEdge<VertexType>, Paint>() {
        public Paint transform(SliceEdge<VertexType> edge) {
            return edge.getVariable() == null ? Color.red : Color.black;
        }
    });

    viewer.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    viewer.getRenderContext().setVertexShapeTransformer(new Transformer<VertexType, Shape>() {
        public Shape transform(VertexType inst) {
            Font font = viewer.getFont();
            String text = viewer.getRenderContext().getVertexLabelTransformer().transform(inst);
            FontRenderContext fontRenderContext = ((Graphics2D) viewer.getGraphics()).getFontRenderContext();
            Rectangle2D bounds = font.getStringBounds(text, fontRenderContext);
            return new RoundRectangle2D.Double(-.6 * bounds.getWidth(), -.6 * bounds.getHeight(),
                    1.2 * bounds.getWidth(), 1.2 * bounds.getHeight(), 8, 8);
        }
    });

    viewer.setBackground(Color.white);

    DefaultModalGraphMouse<InstructionInstance, SliceEdge<VertexType>> mouse = new DefaultModalGraphMouse<InstructionInstance, SliceEdge<VertexType>>();
    mouse.setMode(Mode.ANNOTATING);
    viewer.setGraphMouse(mouse);

    mainFrame.getContentPane().add(viewer);
    mainFrame.pack();

    mainFrame.setVisible(true);
}

From source file:de.dakror.villagedefense.game.entity.struct.Struct.java

public void setBump(Rectangle2D r) {
    super.setBump(new Rectangle((int) Math.round(r.getX() * Tile.SIZE), (int) Math.round(r.getY() * Tile.SIZE),
            (int) Math.round(r.getWidth() * Tile.SIZE), (int) Math.round(r.getHeight() * Tile.SIZE)));
}

From source file:net.sf.jasperreports.customizers.shape.AbstractShapeCustomizer.java

/**
 * Uses the points to build a polyline/*  www .  j  a  va2  s  .  c  o  m*/
 * 
 * @param baseShape the points of the polyline
 * @return a polyline shape or null if it can't be build from the current configuration
 */
protected Shape buildPolyline(ShapePoints baseShape) {
    Path2D path = null;
    List<Point> points = baseShape.getPoints();
    if (points != null && !points.isEmpty()) {
        float scaleFactorX = 1.0f;
        float scaleFactorY = 1.0f;

        Rectangle2D bounds = getBounds(baseShape);
        Integer width = getWidth();
        Integer height = getHeight();
        if (width != null) {
            scaleFactorX = (float) (width / bounds.getWidth());
        }
        if (height != null) {
            scaleFactorY = (float) (height / bounds.getHeight());
        }

        path = new Path2D.Double();

        if (points.size() > 1) {
            Point offset = getOffset(bounds);
            Point point = points.get(0);

            path.moveTo((point.getX() - offset.getX()) * scaleFactorX,
                    (point.getY() - offset.getY()) * scaleFactorY);
            for (int i = 1; i < points.size(); i++) {
                point = points.get(i);
                path.lineTo((point.getX() - offset.getX()) * scaleFactorX,
                        (point.getY() - offset.getY()) * scaleFactorY);
            }
        }
    }
    return path;
}

From source file:org.uva.itast.blended.omr.pages.PDFPageImage.java

/**
 * @param x/*w  w  w  .ja v a  2  s . com*/
 * @param y
 * @param w
 * @param h
 * @return
 */
private SubImage getSubimageWithPartialRendering(Rectangle2D rect, int imageType) {
    double pageHeight = getPage().getHeight();
    // Area in pixels according to preferred resolution
    Point upperLeft = toPixels(rect.getX(), rect.getY());

    Rectangle imageBBox = this.toPixels(rect); // subImage Bounding Box in pixels      
    Rectangle2D pdfAreaBBox = toPDFUnits(imageBBox); // subImage Bounding Box in PDF units

    Rectangle imageSize = new Rectangle(imageBBox.width, imageBBox.height); // subImage Size in pixels

    Rectangle2D clippingArea = new Rectangle(); // area of interest in the PDF
    clippingArea.setFrame(pdfAreaBBox.getX(), pageHeight - pdfAreaBBox.getY() - pdfAreaBBox.getHeight(), //PDF-Page coordinate space counts from bottomleft
            pdfAreaBBox.getWidth(), pdfAreaBBox.getHeight());

    SubImage img_pdf = new SubImage(imageSize.width, imageSize.height, imageType);
    // se configura la imagen con las medidas necesarias

    Graphics2D g2 = img_pdf.createGraphics(); // se crea un objeto grfico en dos dimensiones
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); // prefer to get sharp edges

    PDFRenderer renderer = new PDFRenderer(getPage(), g2, imageSize, clippingArea, Color.RED); // se renderiza la imgen 
    try {
        getPage().waitForFinish();
    } catch (InterruptedException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    renderer.run();

    img_pdf.setReference(upperLeft);
    img_pdf.setBoundingBox(imageBBox);

    return img_pdf;
}

From source file:com.hexidec.ekit.component.UnicodeDialog.java

public void init(int startIndex) {
    String customFont = Translatrix.getTranslationString("UnicodeDialogButtonFont");
    if (customFont != null && customFont.length() > 0) {
        buttonFont = new Font(Translatrix.getTranslationString("UnicodeDialogButtonFont"), Font.PLAIN, 12);
    } else {/*from w w  w  .j a v a 2  s  .  c o  m*/
        buttonFont = new Font("Monospaced", Font.PLAIN, 12);
    }

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new GridLayout(0, 17, 0, 0));
    buttonGroup = new ButtonGroup();

    int prefButtonWidth = 32;
    int prefButtonHeight = 32;

    centerPanel.add(new JLabel(""));
    for (int labelLoop = 0; labelLoop < 16; labelLoop++) {
        JLabel jlblMarker = new JLabel(
                "x" + (labelLoop > 9 ? "" + (char) (65 + (labelLoop - 10)) : "" + labelLoop));
        jlblMarker.setHorizontalAlignment(SwingConstants.CENTER);
        jlblMarker.setVerticalAlignment(SwingConstants.CENTER);
        jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f));
        centerPanel.add(jlblMarker);
    }

    int labelcount = 0;
    for (int counter = 0; counter < UNICODEBLOCKSIZE; counter++) {
        if ((counter % 16) == 0) {
            JLabel jlblMarker = new JLabel(
                    (labelcount > 9 ? "" + (char) (65 + (labelcount - 10)) : "" + labelcount) + "x");
            jlblMarker.setHorizontalAlignment(SwingConstants.CENTER);
            jlblMarker.setVerticalAlignment(SwingConstants.CENTER);
            jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f));
            centerPanel.add(jlblMarker);
            labelcount++;
        }
        buttonArray[counter] = new JToggleButton(" ");
        buttonArray[counter].getModel().setActionCommand("");
        buttonArray[counter].setFont(buttonFont);
        buttonArray[counter].setBorder(
                javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
        buttonArray[counter].addActionListener(this);
        if (counter == 0) {
            FontRenderContext frcLocal = ((java.awt.Graphics2D) (parentEkit.getGraphics()))
                    .getFontRenderContext();
            Rectangle2D fontBounds = buttonFont.getMaxCharBounds(frcLocal);
            int maxCharWidth = (int) (Math.abs(fontBounds.getX())) + (int) (Math.abs(fontBounds.getWidth()));
            int maxCharHeight = (int) (Math.abs(fontBounds.getY())) + (int) (Math.abs(fontBounds.getHeight()));
            Insets buttonInsets = buttonArray[counter].getBorder().getBorderInsets(buttonArray[counter]);
            prefButtonWidth = maxCharWidth + buttonInsets.left + buttonInsets.right;
            prefButtonHeight = maxCharHeight + buttonInsets.top + buttonInsets.bottom;
        }
        buttonArray[counter].setPreferredSize(new Dimension(prefButtonWidth, prefButtonHeight));
        centerPanel.add(buttonArray[counter]);
        buttonGroup.add(buttonArray[counter]);
    }

    JPanel selectorPanel = new JPanel();

    jcmbBlockSelector = new JComboBox(unicodeBlocks);
    jcmbBlockSelector.setSelectedIndex(startIndex);
    jcmbBlockSelector.setActionCommand(CMDCHANGEBLOCK);
    jcmbBlockSelector.addActionListener(this);

    String[] sPages = { "1" };
    jcmbPageSelector = new JComboBox(sPages);
    jcmbPageSelector.setSelectedIndex(0);
    jcmbPageSelector.setActionCommand(CMDCHANGEBLOCK);
    jcmbPageSelector.addActionListener(this);

    selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodeBlock")));
    selectorPanel.add(jcmbBlockSelector);
    selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodePage")));
    selectorPanel.add(jcmbPageSelector);

    JPanel buttonPanel = new JPanel();

    JButton closeButton = new JButton(Translatrix.getTranslationString("DialogClose"));
    closeButton.setActionCommand("close");
    closeButton.addActionListener(this);
    buttonPanel.add(closeButton);

    contentPane.add(centerPanel, BorderLayout.CENTER);
    contentPane.add(selectorPanel, BorderLayout.NORTH);
    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    this.pack();

    populateButtons(startIndex, 0);

    this.setVisible(true);
}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

/**Render default view if there is no timeframe yet*/
private void renderNoInfoView(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3)));
    g2d.fillRect(0, 0, getWidth(), getHeight());
    Font f = g2d.getFont().deriveFont(Font.BOLD, 14.0f);
    g2d.setFont(f);/*  ww w  .  j  a va2s .  co m*/
    Rectangle2D bounds = g2d.getFontMetrics().getStringBounds("Kein Zeitfenster aktiv", g);
    int dx = 10;
    if (getWidth() > bounds.getWidth()) {
        dx = (int) Math.rint((getWidth() - bounds.getWidth()) / 2);
    }

    int dy = 10;
    if (getHeight() > bounds.getHeight()) {
        dy = (int) Math.rint((getHeight() - bounds.getHeight()) / 2);
    }
    g2d.setColor(Color.black);
    g2d.drawString("Kein Zeitfenster aktiv", dx, dy);
}

From source file:de.unisb.cs.st.javaslicer.jung.ShowJungGraph.java

public void displayGraph(DirectedGraph<VertexType, SliceEdge<VertexType>> graph) {
    JFrame mainFrame = new JFrame("slice graph display");
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Layout<VertexType, SliceEdge<VertexType>> layout = new KKLayout<VertexType, SliceEdge<VertexType>>(graph);
    final VisualizationViewer<VertexType, SliceEdge<VertexType>> viewer = new VisualizationViewer<VertexType, SliceEdge<VertexType>>(
            layout);//from   w w  w.j a v a  2s.co m

    viewer.getRenderContext().setVertexLabelTransformer(this.vertexLabelTransformer);
    viewer.setVertexToolTipTransformer(this.vertexTooltipTransformer);
    viewer.getRenderContext().setEdgeLabelTransformer(new Transformer<SliceEdge<VertexType>, String>() {
        @Override
        public String transform(SliceEdge<VertexType> edge) {
            Variable var = edge.getVariable();
            if (var instanceof ArrayElement) {
                ArrayElement elem = (ArrayElement) var;
                return "arr" + elem.getArrayId() + "[" + elem.getArrayIndex() + "]";
            } else if (var instanceof LocalVariable) {
                LocalVariable localVar = (LocalVariable) var;
                if (localVar.getVarName() != null)
                    return localVar.getVarName();
                return "local" + localVar.getVarIndex();
            } else if (var instanceof StackEntry) {
                return "stack";
            } else if (var instanceof ObjectField) {
                ObjectField objField = (ObjectField) var;
                return "obj" + objField.getObjectId() + "." + objField.getFieldName();
            } else if (var instanceof StaticField) {
                StaticField objField = (StaticField) var;
                String ownerInternalClassName = objField.getOwnerInternalClassName();
                String simpleClassName = getSimpleClassName(ownerInternalClassName);
                return simpleClassName + "." + objField.getFieldName();
            } else {
                assert var == null;
                return "";
            }
        }
    });
    viewer.setEdgeToolTipTransformer(new Transformer<SliceEdge<VertexType>, String>() {
        @Override
        public String transform(SliceEdge<VertexType> edge) {
            Variable var = edge.getVariable();
            if (var instanceof ArrayElement) {
                ArrayElement elem = (ArrayElement) var;
                return "Array element " + elem.getArrayIndex() + " of array #" + elem.getArrayId();
            } else if (var instanceof LocalVariable) {
                LocalVariable localVar = (LocalVariable) var;
                if (localVar.getVarName() != null)
                    return "Local variable \"" + localVar.getVarName() + "\"";
                return "Local variable #" + localVar.getVarIndex();
            } else if (var instanceof StackEntry) {
                return "Dependency over the operand stack";
            } else if (var instanceof ObjectField) {
                ObjectField objField = (ObjectField) var;
                return "Field \"" + objField.getFieldName() + "\" of object #" + objField.getObjectId();
            } else if (var instanceof StaticField) {
                StaticField objField = (StaticField) var;
                String ownerInternalClassName = objField.getOwnerInternalClassName();
                return "Static field \"" + objField.getFieldName() + "\" of class \""
                        + Type.getType(ownerInternalClassName).getClassName();
            } else {
                assert var == null;
                return "Control dependency";
            }
        }
    });
    viewer.getRenderContext().setEdgeDrawPaintTransformer(new Transformer<SliceEdge<VertexType>, Paint>() {
        @Override
        public Paint transform(SliceEdge<VertexType> edge) {
            return edge.getVariable() == null ? Color.red : Color.black;
        }
    });

    viewer.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    viewer.getRenderContext().setVertexShapeTransformer(new Transformer<VertexType, Shape>() {
        @Override
        public Shape transform(VertexType inst) {
            Font font = viewer.getFont();
            String text = viewer.getRenderContext().getVertexLabelTransformer().transform(inst);
            FontRenderContext fontRenderContext = ((Graphics2D) viewer.getGraphics()).getFontRenderContext();
            Rectangle2D bounds = font.getStringBounds(text, fontRenderContext);
            return new RoundRectangle2D.Double(-.6 * bounds.getWidth(), -.6 * bounds.getHeight(),
                    1.2 * bounds.getWidth(), 1.2 * bounds.getHeight(), 8, 8);
        }
    });

    viewer.setBackground(Color.white);

    DefaultModalGraphMouse<InstructionInstance, SliceEdge<VertexType>> mouse = new DefaultModalGraphMouse<InstructionInstance, SliceEdge<VertexType>>();
    mouse.setMode(Mode.ANNOTATING);
    viewer.setGraphMouse(mouse);

    mainFrame.getContentPane().add(viewer);
    mainFrame.pack();

    mainFrame.setVisible(true);
}

From source file:net.sf.jasperreports.customizers.shape.AbstractShapeCustomizer.java

/**
 * Builds a polygon shape./* w ww .ja  v a  2  s.c om*/
 * 
 * @param shapePoints the points of the polygon
 * @return the polygon or null if it can't be build from the current configuration
 */
protected Shape buildPolygon(ShapePoints shapePoints) {
    Polygon polygon = null;
    List<Point> points = shapePoints.getPoints();
    if (points != null && !points.isEmpty()) {
        float scaleFactorX = 1.0f;
        float scaleFactorY = 1.0f;

        Rectangle2D bounds = getBounds(shapePoints);
        Integer width = getWidth();
        Integer height = getHeight();
        if (width != null) {
            scaleFactorX = (float) width / (float) bounds.getWidth();
        }
        if (height != null) {
            scaleFactorY = (float) height / (float) bounds.getHeight();
        }

        Point offset = getOffset(bounds);

        int[] pointsX = new int[points.size()];
        int[] pointsY = new int[points.size()];

        for (int i = 0; i < points.size(); i++) {
            Point point = points.get(i);
            pointsX[i] = Math.round((point.getX() - offset.getX()) * scaleFactorX);
            pointsY[i] = Math.round((point.getY() - offset.getY()) * scaleFactorY);
        }

        polygon = new Polygon(pointsX, pointsY, points.size());
    }
    return polygon;
}

From source file:org.jfree.experimental.chart.plot.dial.DialPlot.java

/**
 * Returns the frame surrounding the specified view rectangle.
 * /*  w  w w. j ava2 s  .com*/
 * @param view  the view rectangle (<code>null</code> not permitted).
 */
private Rectangle2D viewToFrame(Rectangle2D view) {
    double width = view.getWidth() / this.viewW;
    double height = view.getHeight() / this.viewH;
    double x = view.getX() - (width * this.viewX);
    double y = view.getY() - (height * this.viewY);
    return new Rectangle2D.Double(x, y, width, height);
}

From source file:org.apache.fop.render.pcl.PCLPainter.java

private void drawTextAsBitmap(final int x, final int y, final int letterSpacing, final int wordSpacing,
        final int[] dx, final String text, FontTriplet triplet) throws IFException {
    //Use Java2D to paint different fonts via bitmap
    final Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize());

    //for cursive fonts, so the text isn't clipped
    final FontMetricsMapper mapper = (FontMetricsMapper) parent.getFontInfo().getMetricsFor(font.getFontName());
    final int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000;
    final int ascent = mapper.getAscender(font.getFontSize()) / 1000;
    final int descent = mapper.getDescender(font.getFontSize()) / 1000;
    int safetyMargin = (int) (SAFETY_MARGIN_FACTOR * font.getFontSize());
    final int baselineOffset = maxAscent + safetyMargin;

    final Rectangle boundingBox = getTextBoundingBox(x, y, letterSpacing, wordSpacing, dx, text, font, mapper);
    final Dimension dim = boundingBox.getSize();

    Graphics2DImagePainter painter = new Graphics2DImagePainter() {

        public void paint(Graphics2D g2d, Rectangle2D area) {
            if (DEBUG) {
                g2d.setBackground(Color.LIGHT_GRAY);
                g2d.clearRect(0, 0, (int) area.getWidth(), (int) area.getHeight());
            }/*from  w w w . j a v a  2s .c o m*/
            g2d.translate(-x, -y + baselineOffset);

            if (DEBUG) {
                Rectangle rect = new Rectangle(x, y - maxAscent, 3000, maxAscent);
                g2d.draw(rect);
                rect = new Rectangle(x, y - ascent, 2000, ascent);
                g2d.draw(rect);
                rect = new Rectangle(x, y, 1000, -descent);
                g2d.draw(rect);
            }
            Java2DPainter painter = new Java2DPainter(g2d, getContext(), parent.getFontInfo(), state);
            try {
                painter.drawText(x, y, letterSpacing, wordSpacing, dx, text);
            } catch (IFException e) {
                //This should never happen with the Java2DPainter
                throw new RuntimeException("Unexpected error while painting text", e);
            }
        }

        public Dimension getImageSize() {
            return dim.getSize();
        }

    };
    paintMarksAsBitmap(painter, boundingBox);
}