use of javax.swing.text.SimpleAttributeSet in project android by JetBrains.
the class AndroidThemePreviewPanel method createErrorPanel.
private void createErrorPanel() {
myErrorLabel = new JTextPane() {
@Override
public Dimension getMaximumSize() {
// Necessary to vertically center it inside a Box.
return super.getPreferredSize();
}
};
myErrorLabel.setOpaque(false);
myErrorPanel = new Box(BoxLayout.PAGE_AXIS);
myErrorPanel.add(Box.createVerticalGlue());
myErrorPanel.add(myErrorLabel);
myErrorPanel.add(Box.createVerticalGlue());
myErrorPanel.setOpaque(false);
StyledDocument document = myErrorLabel.getStyledDocument();
SimpleAttributeSet attributes = new SimpleAttributeSet();
StyleConstants.setAlignment(attributes, StyleConstants.ALIGN_CENTER);
document.setParagraphAttributes(0, document.getLength(), attributes, false);
}
use of javax.swing.text.SimpleAttributeSet in project android by JetBrains.
the class TutorialStep method initStepNumber.
/**
* Create and add the step number indicator. Note that this is a custom
* display that surrounds the number with a circle thus has some tricky
* display characteristics. It's unclear if a form can be leveraged for this.
*/
private void initStepNumber() {
// Get standard label font.
Font font = new JLabel().getFont();
JTextPane stepNumber = new JTextPane();
stepNumber.setEditable(false);
stepNumber.setText(String.valueOf(myIndex));
Font boldFont = new Font(font.getFontName(), Font.BOLD, 11);
stepNumber.setFont(boldFont);
stepNumber.setOpaque(false);
stepNumber.setForeground(NUMBER_COLOR);
stepNumber.setBorder(new NumberBorder());
Dimension size = new Dimension(21, 21);
stepNumber.setSize(size);
stepNumber.setPreferredSize(size);
stepNumber.setMinimumSize(size);
stepNumber.setMaximumSize(size);
StyledDocument doc = stepNumber.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 0;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.CENTER;
c.insets = JBUI.insets(5);
add(stepNumber, c);
}
use of javax.swing.text.SimpleAttributeSet in project android by JetBrains.
the class DeviceSelectionPopup method initMessage.
private void initMessage() {
myMessage.setEditable(false);
myMessage.setFont(promptLabel.getFont());
myMessage.setBackground(myPanel.getBackground());
StyledDocument doc = myMessage.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
if (myNoMatchingDevice) {
myMessage.setText(NO_DEVICE_MESSAGE);
myMessage.setForeground(ERROR_COLOR);
} else {
myMessage.setText(PROMPT_HELP_TEXT);
myMessage.setForeground(MESSAGE_COLOR);
}
}
use of javax.swing.text.SimpleAttributeSet in project android by JetBrains.
the class TextWidget method drawText.
protected void drawText(ViewTransform transform, Graphics2D g, int x, int y) {
int tx = transform.getSwingX(x);
int ty = transform.getSwingY(y);
int h = transform.getSwingDimension(mWidget.getDrawHeight());
int w = transform.getSwingDimension(mWidget.getDrawWidth());
int horizontalPadding = transform.getSwingDimension(mHorizontalPadding + mHorizontalMargin);
int verticalPadding = transform.getSwingDimension(mVerticalPadding + mVerticalMargin);
int originalSize = mFont.getSize();
int scaleSize = transform.getSwingDimension(originalSize);
g.setFont(mFont.deriveFont((float) scaleSize));
FontMetrics fontMetrics = g.getFontMetrics();
Color color = mTextColor.getColor();
if (mWidget.getVisibility() == ConstraintWidget.INVISIBLE) {
color = new Color(color.getRed(), color.getGreen(), color.getBlue(), 100);
}
g.setColor(color);
String string = getText();
if (mToUpperCase) {
string = string.toUpperCase();
}
int ftx = 0;
int fty = 0;
int stringWidth = fontMetrics.stringWidth(string);
if (stringWidth > w && !mSingleLine) {
// if it is multi lined text use a swing text pane to do the wrap
mTextPane.setText(string);
mTextPane.setForeground(color);
mTextPane.setSize(w, h);
mTextPane.setFont(mFont.deriveFont((float) scaleSize * 0.88f));
StyledDocument doc = mTextPane.getStyledDocument();
SimpleAttributeSet attributeSet = new SimpleAttributeSet();
switch(mAlignmentX) {
case TEXT_ALIGNMENT_VIEW_START:
StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_LEFT);
break;
case TEXT_ALIGNMENT_CENTER:
StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_CENTER);
break;
case TEXT_ALIGNMENT_VIEW_END:
StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_RIGHT);
break;
}
switch(mAlignmentY) {
case TEXT_ALIGNMENT_VIEW_START:
mTextPane.setAlignmentY(JTextArea.TOP_ALIGNMENT);
break;
case TEXT_ALIGNMENT_CENTER:
mTextPane.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
break;
case TEXT_ALIGNMENT_VIEW_END:
mTextPane.setAlignmentY(JTextArea.BOTTOM_ALIGNMENT);
break;
}
doc.setParagraphAttributes(0, doc.getLength(), attributeSet, false);
g.translate(tx, ty);
Shape clip = g.getClip();
g.clipRect(0, 0, w, h);
mTextPane.paint(g);
g.setClip(clip);
g.translate(-tx, -ty);
} else {
switch(mAlignmentX) {
case TEXT_ALIGNMENT_VIEW_START:
{
ftx = tx + horizontalPadding;
}
break;
case TEXT_ALIGNMENT_CENTER:
{
int paddx = (w - stringWidth) / 2;
ftx = tx + paddx;
}
break;
case TEXT_ALIGNMENT_VIEW_END:
{
int padd = w - stringWidth + horizontalPadding;
ftx = tx + padd;
}
break;
}
switch(mAlignmentY) {
case TEXT_ALIGNMENT_VIEW_START:
{
fty = ty + fontMetrics.getAscent() + fontMetrics.getMaxDescent() + verticalPadding;
}
break;
case TEXT_ALIGNMENT_CENTER:
{
fty = ty + fontMetrics.getAscent() + (h - fontMetrics.getAscent()) / 2;
}
break;
case TEXT_ALIGNMENT_VIEW_END:
{
fty = ty + h - fontMetrics.getMaxDescent() - verticalPadding;
}
break;
}
Shape clip = g.getClip();
g.clipRect(tx, ty, w, h);
g.drawString(string, ftx, fty);
g.setClip(clip);
}
}
use of javax.swing.text.SimpleAttributeSet in project android by JetBrains.
the class DrawTextRegion method paint.
@Override
public void paint(Graphics2D g, SceneContext sceneContext) {
int tx = x;
int ty = y;
int h = height;
int w = width;
if (!sceneContext.getColorSet().drawBackground()) {
return;
}
super.paint(g, sceneContext);
ColorSet colorSet = sceneContext.getColorSet();
int horizontalPadding = mHorizontalPadding + mHorizontalMargin;
int verticalPadding = mVerticalPadding + mVerticalMargin;
g.setFont(mFont);
FontMetrics fontMetrics = g.getFontMetrics();
Color color = colorSet.getFrames();
g.setColor(color);
String string = mText;
if (mToUpperCase) {
string = string.toUpperCase();
}
int ftx = 0;
int fty = 0;
int stringWidth = fontMetrics.stringWidth(string);
if (stringWidth > w && !mSingleLine) {
// if it is multi lined text use a swing text pane to do the wrap
mTextPane.setText(string);
mTextPane.setForeground(color);
mTextPane.setSize(w, h);
mTextPane.setFont(mFont.deriveFont((float) mFont.getSize() * 0.88f));
StyledDocument doc = mTextPane.getStyledDocument();
SimpleAttributeSet attributeSet = new SimpleAttributeSet();
switch(mAlignmentX) {
case TEXT_ALIGNMENT_VIEW_START:
StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_LEFT);
break;
case TEXT_ALIGNMENT_CENTER:
StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_CENTER);
break;
case TEXT_ALIGNMENT_VIEW_END:
StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_RIGHT);
break;
}
switch(mAlignmentY) {
case TEXT_ALIGNMENT_VIEW_START:
mTextPane.setAlignmentY(JTextArea.TOP_ALIGNMENT);
break;
case TEXT_ALIGNMENT_CENTER:
mTextPane.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
break;
case TEXT_ALIGNMENT_VIEW_END:
mTextPane.setAlignmentY(JTextArea.BOTTOM_ALIGNMENT);
break;
}
doc.setParagraphAttributes(0, doc.getLength(), attributeSet, false);
g.translate(tx, ty);
Shape clip = g.getClip();
g.clipRect(0, 0, w, h);
mTextPane.paint(g);
g.setClip(clip);
g.translate(-tx, -ty);
} else {
switch(mAlignmentX) {
case TEXT_ALIGNMENT_VIEW_START:
{
ftx = tx + horizontalPadding;
}
break;
case TEXT_ALIGNMENT_CENTER:
{
int paddx = (w - stringWidth) / 2;
ftx = tx + paddx;
}
break;
case TEXT_ALIGNMENT_VIEW_END:
{
int padd = w - stringWidth + horizontalPadding;
ftx = tx + padd;
}
break;
}
fty = myBaseLineOffset + ty;
Shape clip = g.getClip();
g.clipRect(tx, ty, w, h);
g.drawString(string, ftx, fty);
g.setClip(clip);
}
}
Aggregations