use of javax.swing.text.View in project Botnak by Gocnak.
the class BaseTabbedPaneUI method calculateTabWidth.
protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
Insets insets = getTabInsets(tabPlacement, tabIndex);
int width = insets.left + insets.right + 3;
Component tabComponent = getTabComponentAt(tabIndex);
if (tabComponent != null) {
width += tabComponent.getPreferredSize().width;
} else {
Icon icon = getIconForTab(tabIndex);
if (icon != null) {
width += icon.getIconWidth() + textIconGap;
}
View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
width += (int) v.getPreferredSpan(View.X_AXIS);
} else {
// plain text
String title = tabPane.getTitleAt(tabIndex);
width += SwingUtilities.computeStringWidth(metrics, title);
}
}
return width;
}
use of javax.swing.text.View in project Botnak by Gocnak.
the class HiFiTabbedPaneUI method paintText.
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) {
Color backColor = tabPane.getBackgroundAt(tabIndex);
if (!(backColor instanceof UIResource)) {
super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
return;
}
g.setFont(font);
View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
Graphics2D g2D = (Graphics2D) g;
Object savedRenderingHint = null;
if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
}
v.paint(g, textRect);
if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
}
} else {
// plain text
int mnemIndex = -1;
if (JTattooUtilities.getJavaVersion() >= 1.4) {
mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
}
Graphics2D g2D = (Graphics2D) g;
Composite composite = g2D.getComposite();
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
g2D.setComposite(alpha);
Color fc = tabPane.getForegroundAt(tabIndex);
if (isSelected) {
fc = AbstractLookAndFeel.getTheme().getTabSelectionForegroundColor();
}
if (!tabPane.isEnabled() || !tabPane.isEnabledAt(tabIndex)) {
fc = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
}
if (ColorHelper.getGrayValue(fc) > 128) {
g2D.setColor(Color.black);
} else {
g2D.setColor(Color.white);
}
JTattooUtilities.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x + 1, textRect.y + 1 + metrics.getAscent());
g2D.setComposite(composite);
g2D.setColor(fc);
JTattooUtilities.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
}
}
use of javax.swing.text.View in project java-swing-tips by aterai.
the class CloseableTabbedPaneUI method layoutLabel.
/**
* Layouts the label.
*
* @param tabPlacement the placement of the tabs
* @param metrics the font metrics
* @param tabIndex the index of the tab
* @param title the title of the tab
* @param icon the icon of the tab
* @param tabRect the tab boundaries
* @param iconRect the icon boundaries
* @param textRect the text boundaries
* @param isSelected true whether the tab is selected, false otherwise
*/
@Override
protected void layoutLabel(int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
textRect.setLocation(0, 0);
iconRect.setLocation(0, 0);
View v = getTextViewForTab(tabIndex);
if (Objects.nonNull(v)) {
tabPane.putClientProperty(HTML, v);
}
SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.CENTER, // SwingConstants.TRAILING,
horizTextPosition, tabRect, iconRect, textRect, textIconGap + 2);
tabPane.putClientProperty(HTML, null);
int xnudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
int ynudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
iconRect.x += xnudge;
iconRect.y += ynudge;
textRect.x += xnudge;
textRect.y += ynudge;
}
use of javax.swing.text.View in project java-swing-tips by aterai.
the class ColorIcon method layoutLabel.
@Override
protected void layoutLabel(int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
textRect.setLocation(0, 0);
iconRect.setLocation(0, 0);
View v = getTextViewForTab(tabIndex);
if (Objects.nonNull(v)) {
tabPane.putClientProperty("html", v);
}
SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, SwingConstants.CENTER, // CENTER, <----
SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.TRAILING, tabRect, iconRect, textRect, textIconGap);
tabPane.putClientProperty("html", null);
// <----
textRect.translate(tabInsets.left + 2, 0);
// <----
iconRect.translate(tabInsets.left + 2, 0);
int xnudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
int ynudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
iconRect.x += xnudge;
iconRect.y += ynudge;
textRect.x += xnudge;
textRect.y += ynudge;
}
use of javax.swing.text.View in project jadx by skylot.
the class LineNumbers method paintComponent.
@SuppressWarnings("deprecation")
@Override
public void paintComponent(Graphics g) {
visibleRect = g.getClipBounds(visibleRect);
if (visibleRect == null) {
visibleRect = getVisibleRect();
}
if (visibleRect == null) {
return;
}
applyRenderHints(g);
Font baseFont = codeArea.getFont();
Font font = baseFont.deriveFont(baseFont.getSize2D() - 1.0f);
g.setFont(font);
Dimension size = getSize();
g.setColor(codeArea.getBackground());
g.fillRect(0, visibleRect.y, size.width, visibleRect.height);
FontMetrics fontMetrics = codeArea.getFontMetrics(font);
Insets insets = getInsets();
int availableWidth = size.width - insets.right;
textAreaInsets = codeArea.getInsets(textAreaInsets);
if (visibleRect.y < textAreaInsets.top) {
visibleRect.height -= (textAreaInsets.top - visibleRect.y);
visibleRect.y = textAreaInsets.top;
}
boolean lineWrap = codeArea.getLineWrap();
int cellHeight = codeArea.getLineHeight();
int ascent = codeArea.getMaxAscent();
int currentLine = codeArea.getCaretLineNumber();
int y;
int topLine;
int linesCount;
View parentView = null;
Rectangle editorRect = null;
if (lineWrap) {
Element root = codeArea.getDocument().getDefaultRootElement();
parentView = codeArea.getUI().getRootView(codeArea).getView(0);
int topPosition = codeArea.viewToModel(new Point(visibleRect.x, visibleRect.y));
topLine = root.getElementIndex(topPosition);
linesCount = root.getElementCount();
editorRect = getEditorBoundingRect();
Rectangle topLineBounds = getLineBounds(parentView, topLine, editorRect);
if (topLineBounds == null) {
return;
}
y = ascent + topLineBounds.y;
} else {
linesCount = codeArea.getLineCount();
topLine = (visibleRect.y - textAreaInsets.top) / cellHeight;
y = ascent + topLine * cellHeight + textAreaInsets.top;
}
int endY = visibleRect.y + visibleRect.height + ascent;
int lineNum = topLine;
boolean isCurLine = updateColor(g, false, true);
while (y < endY && lineNum < linesCount) {
try {
String lineStr = getTextLineNumber(lineNum + 1);
if (lineStr != null) {
isCurLine = updateColor(g, lineNum == currentLine, isCurLine);
int x = availableWidth - fontMetrics.stringWidth(lineStr);
g.drawString(lineStr, x, y);
}
if (lineWrap) {
Rectangle lineBounds = getLineBounds(parentView, lineNum, editorRect);
if (lineBounds == null) {
return;
}
y += lineBounds.height;
} else {
y += cellHeight;
}
lineNum++;
} catch (Exception e) {
LOG.debug("Line numbers draw error", e);
break;
}
}
}
Aggregations