Search in sources :

Example 1 with ColorSet

use of com.android.tools.sherpa.drawing.ColorSet in project android by JetBrains.

the class DrawAction method paint.

@Override
public void paint(Graphics2D g, SceneContext sceneContext) {
    int r = (int) (width * 0.3);
    ColorSet colorSet = sceneContext.getColorSet();
    g.setColor(colorSet.getComponentObligatoryBackground());
    g.fillRoundRect(x - 2, y - 2, width + 4, height + 4, r, r);
    if (myIsOver) {
        g.setColor(colorSet.getSelectedBackground());
        g.fillRoundRect(x, y, width, height, r, r);
        g.setColor(colorSet.getFrames());
        g.drawRoundRect(x, y, width, height, r, r);
    } else {
        g.setColor(colorSet.getFrames());
        g.fillRoundRect(x, y, width, height, r, r);
    }
    Color color = colorSet.getText();
    g.setColor(color);
    Icon icon = (colorSet.getStyle() == WidgetDecorator.BLUEPRINT_STYLE) ? SherpaIcons.DeleteConstraintB : SherpaIcons.DeleteConstraint;
    if (myMode == 1) {
        icon = (colorSet.getStyle() == WidgetDecorator.BLUEPRINT_STYLE) ? SherpaIcons.BaselineBlue : SherpaIcons.BaselineColor;
    } else if (myMode == 2) {
        icon = (colorSet.getStyle() == WidgetDecorator.BLUEPRINT_STYLE) ? SherpaIcons.ChainBlue : SherpaIcons.Chain;
    }
    g.setFont(mFont);
    FontMetrics fontMetrics = g.getFontMetrics();
    int iw = icon.getIconWidth();
    int ih = icon.getIconHeight();
    if (iw > width || ih > height) {
        double scale = Math.min(width / (double) iw, height / (double) ih);
        Graphics2D g2 = (Graphics2D) g.create();
        double tx = x + (width - iw * scale) / 2;
        double ty = y + (height - ih * scale) / 2;
        g2.translate(tx, ty);
        g2.scale(scale, scale);
        icon.paintIcon(null, g2, 0, 0);
    } else {
        int tx = x + (width - iw) / 2;
        int ty = y + (height - ih) / 2;
        icon.paintIcon(null, g, tx, ty);
    }
}
Also used : ColorSet(com.android.tools.sherpa.drawing.ColorSet)

Example 2 with ColorSet

use of com.android.tools.sherpa.drawing.ColorSet in project android by JetBrains.

the class DrawAnchor method paint.

@Override
public void paint(Graphics2D g, SceneContext sceneContext) {
    if (myType == TYPE_BASELINE) {
        paintBaseline(g, sceneContext);
        return;
    }
    ColorSet colorSet = sceneContext.getColorSet();
    Color background = colorSet.getComponentObligatoryBackground();
    Color color = colorSet.getFrames();
    if (myMode == OVER) {
        if (myIsConnected) {
            g.setColor(colorSet.getAnchorDisconnectionCircle());
        } else {
            g.setColor(colorSet.getAnchorConnectionCircle());
        }
        int delta = width / 3;
        int delta2 = delta * 2;
        g.fillRoundRect(x - delta, y - delta, width + delta2, height + delta2, width + delta2, height + delta2);
        g.drawRoundRect(x - delta, y - delta, width + delta2, height + delta2, width + delta2, height + delta2);
    }
    g.setColor(background);
    g.fillRoundRect(x, y, width, height, width, height);
    g.setColor(color);
    g.drawRoundRect(x, y, width, height, width, height);
    int delta = width / 4;
    int delta2 = delta * 2;
    if (myIsConnected) {
        g.fillRoundRect(x + delta, y + delta, width - delta2, height - delta2, width - delta2, height - delta2);
        g.drawRoundRect(x + delta, y + delta, width - delta2, height - delta2, width - 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(x, y, width, height, width, height);
        sceneContext.repaint();
        g.setComposite(comp);
    }
}
Also used : ColorSet(com.android.tools.sherpa.drawing.ColorSet)

Example 3 with ColorSet

use of com.android.tools.sherpa.drawing.ColorSet in project android by JetBrains.

the class DrawGuidelineCycle method paint.

@Override
public void paint(Graphics2D g, SceneContext sceneContext) {
    ColorSet colorSet = sceneContext.getColorSet();
    g.setColor(colorSet.getFrames());
    g.fillOval(x, y, width, height);
    if (myIsSelected) {
        g.setColor(colorSet.getSelectedFrames());
        g.setStroke(colorSet.getOutlineStroke());
    }
    g.drawOval(x, y, width, height);
    g.setColor(colorSet.getText());
    if (myMode == PERCENT) {
        String text = "%";
        g.setFont(mFont);
        FontMetrics fontMetrics = g.getFontMetrics();
        int tx = x + (width - fontMetrics.stringWidth(text)) / 2;
        int ty = y + (height / 2) + fontMetrics.getDescent();
        g.drawString(text, tx + 1, ty + 1);
    } else if (myMode == BEGIN) {
        int gap = 4;
        if (myIsHorizontal) {
            DrawConnectionUtils.getArrow(DrawConnection.DIR_BOTTOM, x + width / 2, y + height / 2 - gap, xPoints, yPoints);
        } else {
            DrawConnectionUtils.getArrow(DrawConnection.DIR_RIGHT, x + width / 2 - gap, y + height / 2, xPoints, yPoints);
        }
        g.fillPolygon(xPoints, yPoints, 3);
    } else {
        int gap = 4;
        if (myIsHorizontal) {
            DrawConnectionUtils.getArrow(DrawConnection.DIR_TOP, x + width / 2, y + height / 2 + gap, xPoints, yPoints);
        } else {
            DrawConnectionUtils.getArrow(DrawConnection.DIR_LEFT, x + width / 2 + gap, y + height / 2, xPoints, yPoints);
        }
        g.fillPolygon(xPoints, yPoints, 3);
    }
}
Also used : ColorSet(com.android.tools.sherpa.drawing.ColorSet)

Example 4 with ColorSet

use of com.android.tools.sherpa.drawing.ColorSet in project android by JetBrains.

the class DrawHorizontalGuideline method paint.

@Override
public void paint(Graphics2D g, SceneContext sceneContext) {
    ColorSet colorSet = sceneContext.getColorSet();
    if (myIsSelected) {
        g.setColor(colorSet.getSelectedFrames());
    } else {
        g.setColor(colorSet.getFrames());
    }
    Stroke stroke = g.getStroke();
    g.setStroke(DrawConnectionUtils.sDashedStroke);
    g.drawLine(x, y, x + width, y);
    g.setStroke(stroke);
    int gap = 48;
    if (myIsSelected) {
        if (myBegin != -1) {
            DrawConnectionUtils.drawVerticalMarginIndicator(g, String.valueOf(myBegin), false, x + GAP, myOriginY, y);
        } else if (myEnd != -1) {
            DrawConnectionUtils.drawVerticalMarginIndicator(g, String.valueOf(myEnd), false, x + GAP, y, myOriginY + myOriginHeight);
        } else {
            String percent = String.valueOf((int) (myPercent * 100)) + " %";
            g.setColor(colorSet.getFrames());
            DrawConnectionUtils.drawRoundRectText(g, mFont, colorSet.getText(), percent, x + gap, y);
        }
    }
}
Also used : ColorSet(com.android.tools.sherpa.drawing.ColorSet)

Example 5 with ColorSet

use of com.android.tools.sherpa.drawing.ColorSet in project android by JetBrains.

the class DrawComponentFrame method paint.

@Override
public void paint(Graphics2D g, SceneContext sceneContext) {
    ColorSet colorSet = sceneContext.getColorSet();
    Color[] colorFrame = { colorSet.getSubduedFrames(), colorSet.getFrames(), colorSet.getHighlightedFrames(), colorSet.getSelectedFrames() };
    Stroke previousStroke = g.getStroke();
    g.setStroke(myNormalStroke);
    g.setColor(colorFrame[myMode]);
    if (myHasHorizontalConstraints && myHasVerticalConstraints) {
        g.drawRect(x, y, width, height);
    } else {
        if (!myHasHorizontalConstraints) {
            g.setStroke(myProblemStroke);
            g.setColor(colorSet.getUnconstrainedColor());
        } else {
            g.setStroke(myNormalStroke);
            g.setColor(colorFrame[myMode]);
        }
        g.drawLine(x, y, x, y + height);
        g.drawLine(x + width, y, x + width, y + height);
        if (!myHasVerticalConstraints) {
            g.setStroke(myProblemStroke);
            g.setColor(colorSet.getUnconstrainedColor());
        } else {
            g.setStroke(myNormalStroke);
            g.setColor(colorFrame[myMode]);
        }
        g.drawLine(x, y, x + width, y);
        g.drawLine(x, y + height, x + width, y + height);
    }
    g.setStroke(previousStroke);
}
Also used : ColorSet(com.android.tools.sherpa.drawing.ColorSet)

Aggregations

ColorSet (com.android.tools.sherpa.drawing.ColorSet)14 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)1 StyledDocument (javax.swing.text.StyledDocument)1