Search in sources :

Example 71 with Rectangle

use of java.awt.Rectangle in project sonarqube by SonarSource.

the class TextLineNumber method getOffsetY.

/*
   * Determine the Y offset for the current row
   */
private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics) throws BadLocationException {
    // Get the bounding rectangle of the row
    Rectangle r = component.modelToView(rowStartOffset);
    int lineHeight = fontMetrics.getHeight();
    int y = r.y + r.height;
    int descent = 0;
    if (// default font is being used
    r.height == lineHeight) {
        descent = fontMetrics.getDescent();
    } else // We need to check all the attributes for font changes
    {
        if (fonts == null)
            fonts = new HashMap<>();
        Element root = component.getDocument().getDefaultRootElement();
        int index = root.getElementIndex(rowStartOffset);
        Element line = root.getElement(index);
        for (int i = 0; i < line.getElementCount(); i++) {
            Element child = line.getElement(i);
            AttributeSet as = child.getAttributes();
            String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily);
            Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize);
            String key = fontFamily + fontSize;
            FontMetrics fm = fonts.get(key);
            if (fm == null) {
                Font font = new Font(fontFamily, Font.PLAIN, fontSize);
                fm = component.getFontMetrics(font);
                fonts.put(key, fm);
            }
            descent = Math.max(descent, fm.getDescent());
        }
    }
    return y - descent;
}
Also used : HashMap(java.util.HashMap) AttributeSet(javax.swing.text.AttributeSet) FontMetrics(java.awt.FontMetrics) Element(javax.swing.text.Element) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Font(java.awt.Font)

Example 72 with Rectangle

use of java.awt.Rectangle in project sonarqube by SonarSource.

the class TextLineNumber method paintComponent.

/**
   *  Draw the line numbers
   */
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // Determine the width of the space available to draw the line number
    FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
    Insets insets = getInsets();
    int availableWidth = getSize().width - insets.left - insets.right;
    // Determine the rows to draw within the clipped bounds.
    Rectangle clip = g.getClipBounds();
    int rowStartOffset = component.viewToModel(new Point(0, clip.y));
    int endOffset = component.viewToModel(new Point(0, clip.y + clip.height));
    while (rowStartOffset <= endOffset) {
        try {
            if (isCurrentLine(rowStartOffset))
                g.setColor(getCurrentLineForeground());
            else
                g.setColor(getForeground());
            // Get the line number as a string and then determine the
            // "X" and "Y" offsets for drawing the string.
            String lineNumber = getTextLineNumber(rowStartOffset);
            int stringWidth = fontMetrics.stringWidth(lineNumber);
            int x = getOffsetX(availableWidth, stringWidth) + insets.left;
            int y = getOffsetY(rowStartOffset, fontMetrics);
            g.drawString(lineNumber, x, y);
            // Move to the next row
            rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1;
        } catch (Exception e) {
            break;
        }
    }
}
Also used : Insets(java.awt.Insets) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Example 73 with Rectangle

use of java.awt.Rectangle in project LogisticsPipes by RS485.

the class SneakyConfigurationPopup method initGui.

@Override
public void initGui() {
    super.initGui();
    buttonList.clear();
    configDisplay = new SideConfigDisplay(config) {

        @Override
        public void handleSelection(SelectedFace selection) {
            SneakyConfigurationPopup.this.handleSelection(selection);
        }
    };
    configDisplay.init();
    configDisplay.renderNeighbours = true;
    buttonList.add(new GuiButton(0, right - 106, bottom - 26, 100, 20, "Cancel"));
    bounds = new Rectangle(guiLeft + 5, guiTop + 20, this.xSize - 10, this.ySize - 50);
}
Also used : GuiButton(net.minecraft.client.gui.GuiButton) SideConfigDisplay(logisticspipes.utils.gui.sideconfig.SideConfigDisplay) Rectangle(java.awt.Rectangle)

Example 74 with Rectangle

use of java.awt.Rectangle in project LogisticsPipes by RS485.

the class SideConfigDisplay method applyCamera.

private void applyCamera(float partialTick) {
    Rectangle vp = camera.getViewport();
    GL11.glViewport(vp.x, vp.y, vp.width, vp.height);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    RenderUtil.loadMatrix(camera.getTransposeProjectionMatrix());
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    RenderUtil.loadMatrix(camera.getTransposeViewMatrix());
    GL11.glTranslatef(-(float) eye.x, -(float) eye.y, -(float) eye.z);
}
Also used : Rectangle(java.awt.Rectangle)

Example 75 with Rectangle

use of java.awt.Rectangle in project WordCram by danbernier.

the class AWordCramEngine method willSkipWordsWhoseShapesAreTooSmallEvenWhenMinShapeSizeIsZero.

@Test
public void willSkipWordsWhoseShapesAreTooSmallEvenWhenMinShapeSizeIsZero() {
    Word big = new Word("big", 10);
    Word small = new Word("small", 1);
    Shape bigShape = new Rectangle(0, 0, 20, 20);
    Shape smallShape = new Rectangle(0, 0, 0, 1);
    renderOptions.minShapeSize = 0;
    when(shaper.getShapeFor(eq(big.word), any(PFont.class), anyFloat(), anyFloat())).thenReturn(bigShape);
    when(shaper.getShapeFor(eq(small.word), any(PFont.class), anyFloat(), anyFloat())).thenReturn(smallShape);
    WordCramEngine engine = getEngine(big, small);
    Word[] skippedWords = engine.getSkippedWords();
    Assert.assertEquals(1, skippedWords.length);
    Assert.assertSame(small, skippedWords[0]);
    Assert.assertEquals(WordSkipReason.SHAPE_WAS_TOO_SMALL, small.wasSkippedBecause());
    Assert.assertNull(big.wasSkippedBecause());
}
Also used : Shape(java.awt.Shape) PFont(processing.core.PFont) Rectangle(java.awt.Rectangle) Test(org.junit.Test)

Aggregations

Rectangle (java.awt.Rectangle)809 Point (java.awt.Point)201 Dimension (java.awt.Dimension)81 BufferedImage (java.awt.image.BufferedImage)68 Graphics2D (java.awt.Graphics2D)65 Color (java.awt.Color)48 Insets (java.awt.Insets)47 ArrayList (java.util.ArrayList)37 Font (java.awt.Font)29 Test (org.junit.Test)28 IOException (java.io.IOException)27 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Paint (java.awt.Paint)23 GradientPaint (java.awt.GradientPaint)22 FontMetrics (java.awt.FontMetrics)21 Graphics (java.awt.Graphics)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Robot (java.awt.Robot)19 File (java.io.File)19 PeakResult (gdsc.smlm.results.PeakResult)18