use of com.android.tools.sherpa.drawing.ColorSet 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);
}
}
use of com.android.tools.sherpa.drawing.ColorSet in project android by JetBrains.
the class DrawVerticalGuideline method paint.
@Override
public void paint(Graphics2D g, SceneContext sceneContext) {
ColorSet colorSet = sceneContext.getColorSet();
Stroke stroke = g.getStroke();
if (myIsSelected) {
g.setColor(colorSet.getSelectedFrames());
} else {
g.setColor(colorSet.getFrames());
}
g.setStroke(DrawConnectionUtils.sDashedStroke);
g.drawLine(x, y, x, y + height);
g.setStroke(stroke);
int gap = 48;
if (myIsSelected) {
if (myBegin != -1) {
DrawConnectionUtils.drawHorizontalMarginIndicator(g, String.valueOf(myBegin), false, myOriginX, x, myOriginY + GAP);
} else if (myEnd != -1) {
DrawConnectionUtils.drawHorizontalMarginIndicator(g, String.valueOf(myEnd), false, x, myOriginX + myOriginWidth, myOriginY + GAP);
} else {
String percent = String.valueOf((int) (myPercent * 100)) + " %";
g.setColor(colorSet.getFrames());
DrawConnectionUtils.drawRoundRectText(g, mFont, colorSet.getText(), percent, x, y + gap);
}
}
}
use of com.android.tools.sherpa.drawing.ColorSet in project android by JetBrains.
the class DrawAnchor method paintBaseline.
public void paintBaseline(Graphics2D g, SceneContext sceneContext) {
int inset = width / 10;
ColorSet colorSet = sceneContext.getColorSet();
Color background = colorSet.getComponentObligatoryBackground();
Color color = colorSet.getFrames();
g.setColor(color);
g.fillRect(x, y + height / 2, width, 1);
int ovalX = x + inset;
int ovalW = width - 2 * inset;
g.setColor(background);
g.fillRoundRect(ovalX, y, ovalW, height, height, height);
g.setColor(color);
g.drawRoundRect(ovalX, y, ovalW, height, height, height);
int delta = 3;
int delta2 = delta * 2;
if (myIsConnected) {
g.fillRoundRect(ovalX + delta, y + delta, ovalW - delta2, height - delta2, height - delta2, height - delta2);
g.drawRoundRect(ovalX + delta, y + delta, ovalW - delta2, height - delta2, height - delta2, height - delta2);
}
if (myMode == OVER) {
int alpha = getPulseAlpha((int) (sceneContext.getTime() % 1000));
Composite comp = g.getComposite();
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha / 255f));
if (myIsConnected) {
g.setColor(colorSet.getAnchorDisconnectionCircle());
} else {
g.setColor(colorSet.getAnchorConnectionCircle());
}
g.fillRoundRect(ovalX, y, ovalW, height, height, height);
g.drawRoundRect(ovalX, y, ovalW, height, height, height);
sceneContext.repaint();
g.setComposite(comp);
}
}
use of com.android.tools.sherpa.drawing.ColorSet in project android by JetBrains.
the class DrawComponentBackground method paint.
@Override
public void paint(Graphics2D g, SceneContext sceneContext) {
ColorSet colorSet = sceneContext.getColorSet();
Color[] colorBackground = { colorSet.getComponentBackground(), colorSet.getComponentBackground(), colorSet.getComponentHighlightedBackground(), colorSet.getComponentHighlightedBackground() };
if (colorSet.drawBackground()) {
g.setColor(colorBackground[myMode]);
g.fillRect(x, y, width, height);
}
}
Aggregations