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;
}
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;
}
}
}
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);
}
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);
}
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());
}
Aggregations