use of java.awt.font.TextLayout in project limelight by slagyr.
the class TextPanel method buildLines.
public synchronized void buildLines() {
consumableArea = panel.getChildConsumableBounds();
lines = new LinkedList<TextLayout>();
if (text != null && text.length() > 0) {
StyledTextParser parser = new StyledTextParser();
textChunks = parser.parse(text);
final Scene root = getRoot();
if (// TODO MDM - It happens.... but how? Ah! Need to acquire tree lock when removing panels.
root != null) {
Map<String, RichStyle> styleMap = root.getStyles();
for (StyledText styledText : textChunks) styledText.setupStyles(styleMap, getStyle(), this);
// TODO MDM StyleObservers may cause a memory leak. Styles keep track of panels that are no longer used?
addLines();
}
}
}
use of java.awt.font.TextLayout in project limelight by slagyr.
the class TextPanel method addLines.
private synchronized void addLines() {
AttributedString aText = prepareAttributedString();
AttributedCharacterIterator styledTextIterator = aText.getIterator();
List<Integer> newlineLocations = getNewlineLocations(styledTextIterator);
LineBreakMeasurer lbm = new LineBreakMeasurer(styledTextIterator, getRenderContext());
float width = (float) consumableArea.width;
if (width <= 0)
return;
TextLayout layout;
int startOfNextLayout;
int currentLine = 0;
int endIndex = styledTextIterator.getEndIndex();
do {
if (currentLine < newlineLocations.size())
startOfNextLayout = newlineLocations.get(currentLine) + 1;
else
startOfNextLayout = endIndex + 1;
layout = lbm.nextLayout(width, startOfNextLayout, false);
lines.add(layout);
if (lbm.getPosition() == startOfNextLayout)
currentLine += 1;
} while (layout != null && lbm.getPosition() < endIndex);
}
use of java.awt.font.TextLayout in project limelight by slagyr.
the class TextPanel method calculateDimensions.
private void calculateDimensions() {
consumedHeight = 0;
consumedWidth = 0;
synchronized (this) {
for (TextLayout layout : lines) {
consumedHeight += (layout.getAscent() + layout.getDescent() + layout.getLeading());
double lineWidth = widthOf(layout);
if (lineWidth > consumedWidth)
consumedWidth = lineWidth;
}
}
}
use of java.awt.font.TextLayout in project hid-serial by rayshobby.
the class GLinearTrackControl method drawLimits.
protected void drawLimits() {
Graphics2D g2d = buffer.g2;
float px, py;
TextLayout line;
if (limitsInvalid) {
ssStartLimit = new StyledString(getNumericDisplayString(startLimit));
ssEndLimit = new StyledString(getNumericDisplayString(endLimit));
limitsInvalid = false;
}
switch(textOrientation) {
case ORIENT_LEFT:
line = ssStartLimit.getLines(g2d).getFirst().layout;
px = -trackLength / 2 + line.getDescent();
py = trackOffset + line.getVisibleAdvance();
buffer.pushMatrix();
buffer.translate(px, py);
buffer.rotate(-PI / 2);
line.draw(g2d, 0, 0);
buffer.popMatrix();
line = ssEndLimit.getLines(g2d).getFirst().layout;
px = trackLength / 2 + line.getDescent();
py = trackOffset + line.getVisibleAdvance();
buffer.pushMatrix();
buffer.translate(px, py);
buffer.rotate(-PI / 2);
line.draw(g2d, 0, 0);
buffer.popMatrix();
break;
case ORIENT_RIGHT:
line = ssStartLimit.getLines(g2d).getFirst().layout;
px = -trackLength / 2 - line.getDescent();
py = trackOffset;
buffer.pushMatrix();
buffer.translate(px, py);
buffer.rotate(PI / 2);
line.draw(g2d, 0, 0);
buffer.popMatrix();
line = ssEndLimit.getLines(g2d).getFirst().layout;
px = trackLength / 2 - line.getDescent();
py = trackOffset;
buffer.pushMatrix();
buffer.translate(px, py);
buffer.rotate(PI / 2);
line.draw(g2d, 0, 0);
buffer.popMatrix();
break;
case ORIENT_TRACK:
line = ssStartLimit.getLines(g2d).getFirst().layout;
px = -(trackLength + trackWidth) / 2;
py = trackOffset + line.getAscent();
line.draw(g2d, px, py);
line = ssEndLimit.getLines(g2d).getFirst().layout;
px = (trackLength + trackWidth) / 2 - line.getVisibleAdvance();
py = trackOffset + line.getAscent();
line.draw(g2d, px, py);
break;
}
}
use of java.awt.font.TextLayout in project hid-serial by rayshobby.
the class GPanel method updateBuffer.
protected void updateBuffer() {
if (bufferInvalid) {
Graphics2D g2d = buffer.g2;
buffer.beginDraw();
buffer.background(buffer.color(255, 0));
buffer.noStroke();
buffer.fill(palette[4]);
if (tabOnly) {
buffer.rect(0, 0, tabWidth, tabHeight);
} else {
buffer.rect(0, 0, width, tabHeight);
}
stext.getLines(g2d);
g2d.setColor(jpalette[12]);
TextLayout tl = stext.getTLIforLineNo(0).layout;
tl.draw(g2d, 4, 2 + tl.getAscent());
if (!tabOnly) {
buffer.noStroke();
buffer.fill(palette[5]);
buffer.rect(0, tabHeight, width, height - tabHeight);
}
buffer.endDraw();
}
}
Aggregations