Search in sources :

Example 1 with MessageType

use of org.apache.pivot.wtk.MessageType in project pivot by apache.

the class TerraFormSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    super.paint(graphics);
    GraphicsUtilities.setAntialiasingOn(graphics);
    Form form = (Form) getComponent();
    Form.SectionSequence sections = form.getSections();
    for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
        Form.Section section = sections.get(sectionIndex);
        for (int fieldIndex = 0, fieldCount = section.getLength(); fieldIndex < fieldCount; fieldIndex++) {
            Component field = section.get(fieldIndex);
            if (field.isVisible()) {
                Form.Flag flag = Form.getFlag(field);
                if (flag != null) {
                    if (showFlagIcons) {
                        MessageType messageType = flag.getMessageType();
                        Image flagIcon = null;
                        switch(messageType) {
                            case ERROR:
                                {
                                    flagIcon = errorIcon;
                                    break;
                                }
                            case WARNING:
                                {
                                    flagIcon = warningIcon;
                                    break;
                                }
                            case QUESTION:
                                {
                                    flagIcon = questionIcon;
                                    break;
                                }
                            case INFO:
                                {
                                    flagIcon = infoIcon;
                                    break;
                                }
                            default:
                                {
                                    flagIcon = infoIcon;
                                    break;
                                }
                        }
                        Label label = labels.get(sectionIndex).get(fieldIndex);
                        int flagIconX = label.getX() - (flagIcon.getWidth() + flagIconOffset);
                        int flagIconY = label.getY() + (label.getHeight() - flagIcon.getHeight()) / 2;
                        graphics.translate(flagIconX, flagIconY);
                        flagIcon.paint(graphics);
                        graphics.translate(-flagIconX, -flagIconY);
                    }
                    if (showFlagHighlight) {
                        MessageType messageType = flag.getMessageType();
                        Color highlightColor = null;
                        switch(messageType) {
                            case ERROR:
                                {
                                    highlightColor = errorHighlightColor;
                                    break;
                                }
                            case WARNING:
                                {
                                    highlightColor = warningHighlightColor;
                                    break;
                                }
                            case QUESTION:
                                {
                                    highlightColor = questionHighlightColor;
                                    break;
                                }
                            case INFO:
                                {
                                    highlightColor = infoHighlightColor;
                                    break;
                                }
                            default:
                                {
                                    break;
                                }
                        }
                        Bounds fieldBounds = field.getBounds();
                        graphics.setColor(highlightColor);
                        graphics.setStroke(new BasicStroke(1));
                        graphics.drawRect(fieldBounds.x - FLAG_HIGHLIGHT_PADDING, fieldBounds.y - FLAG_HIGHLIGHT_PADDING, fieldBounds.width + FLAG_HIGHLIGHT_PADDING * 2 - 1, fieldBounds.height + FLAG_HIGHLIGHT_PADDING * 2 - 1);
                    }
                }
            }
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Form(org.apache.pivot.wtk.Form) Color(java.awt.Color) Bounds(org.apache.pivot.wtk.Bounds) Label(org.apache.pivot.wtk.Label) Component(org.apache.pivot.wtk.Component) Image(org.apache.pivot.wtk.media.Image) Point(org.apache.pivot.wtk.Point) MessageType(org.apache.pivot.wtk.MessageType)

Aggregations

BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Bounds (org.apache.pivot.wtk.Bounds)1 Component (org.apache.pivot.wtk.Component)1 Form (org.apache.pivot.wtk.Form)1 Label (org.apache.pivot.wtk.Label)1 MessageType (org.apache.pivot.wtk.MessageType)1 Point (org.apache.pivot.wtk.Point)1 Image (org.apache.pivot.wtk.media.Image)1