You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/01/20 19:42:43 UTC

svn commit: r901320 - in /pivot/trunk: tutorials/src/org/apache/pivot/tutorials/ wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/content/

Author: gbrown
Date: Wed Jan 20 18:42:42 2010
New Revision: 901320

URL: http://svn.apache.org/viewvc?rev=901320&view=rev
Log:
Add styles to control flag icon and flag highlight visibility in TerraFormSkin.

Modified:
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars.wtkx
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/spinners.wtkx
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text.wtkx
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewColorItemRenderer.java

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars.wtkx?rev=901320&r1=901319&r2=901320&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars.wtkx Wed Jan 20 18:42:42 2010
@@ -42,7 +42,7 @@
 
                 <BoxPane orientation="vertical">
                     <Label text="Calendar Buttons" styles="{font:{bold:true}}"/>
-                    <Form>
+                    <Form styles="{showFlagIcons:false, showFlagHighlight:false}">
                         <sections>
                             <Form.Section>
                                 <CalendarButton Form.label="English (US)" locale="{language:'en', country:'us'}"/>

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx?rev=901320&r1=901319&r2=901320&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists.wtkx Wed Jan 20 18:42:42 2010
@@ -120,7 +120,7 @@
 
             <BoxPane orientation="vertical" styles="{spacing:6}">
                 <Label text="List Buttons" styles="{font:{bold:true}}"/>
-                <Form>
+                <Form styles="{showFlagIcons:false, showFlagHighlight:false}">
                     <sections>
                         <Form.Section>
                             <ListButton Form.label="Basic" selectedIndex="0">

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/spinners.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/spinners.wtkx?rev=901320&r1=901319&r2=901320&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/spinners.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/spinners.wtkx Wed Jan 20 18:42:42 2010
@@ -23,7 +23,7 @@
         <content>
             <BoxPane orientation="vertical" styles="{padding:{top:2, left:4, bottom:8, right:4}}">
                 <Label text="Spinners" styles="{font:{bold:true}}"/>
-                <Form>
+                <Form styles="{showFlagIcons:false, showFlagHighlight:false}">
                     <sections>
                         <Form.Section>
                             <Spinner Form.label="Basic" preferredWidth="60"
@@ -43,7 +43,7 @@
         <content>
             <BoxPane orientation="vertical" styles="{padding:{top:2, left:4, bottom:8, right:4}}">
                 <Label text="Sliders" styles="{font:{bold:true}}"/>
-                <Form>
+                <Form styles="{showFlagIcons:false, showFlagHighlight:false}">
                     <sections>
                         <Form.Section>
                             <Slider wtkx:id="redSlider" Form.label="Red" range="{start:0, end:255}" value="0"/>

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text.wtkx
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text.wtkx?rev=901320&r1=901319&r2=901320&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text.wtkx (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/text.wtkx Wed Jan 20 18:42:42 2010
@@ -24,7 +24,7 @@
             <BoxPane orientation="vertical" styles="{fill:true,
                 padding:{top:2, left:4, bottom:12, right:4}}">
                 <Label text="Text Input" styles="{font:{bold:true}}"/>
-                <Form>
+                <Form styles="{showFlagHighlight:false}">
                     <sections>
                         <Form.Section>
                             <TextInput Form.label="Basic" text="Pivot" textSize="12"/>

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java?rev=901320&r1=901319&r2=901320&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFormSkin.java Wed Jan 20 18:42:42 2010
@@ -16,10 +16,13 @@
  */
 package org.apache.pivot.wtk.skin.terra;
 
+import java.awt.BasicStroke;
+import java.awt.Color;
 import java.awt.Graphics2D;
 
 import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.wtk.Bounds;
 import org.apache.pivot.wtk.BoxPane;
 import org.apache.pivot.wtk.Component;
 import org.apache.pivot.wtk.Dimensions;
@@ -43,15 +46,16 @@
     implements FormListener, FormAttributeListener {
     private ArrayList<Separator> separators = new ArrayList<Separator>();
     private ArrayList<ArrayList<BoxPane>> rowHeaders = new ArrayList<ArrayList<BoxPane>>();
-    // TODO
-    // private ArrayList<ArrayList<Label>> flagMessages = new ArrayList<ArrayList<Label>>();
+    // TODO private ArrayList<ArrayList<Label>> flagMessages = new ArrayList<ArrayList<Label>>();
 
-    private int horizontalSpacing = 4;
-    private int verticalSpacing = 4;
+    private int horizontalSpacing = 6;
+    private int verticalSpacing = 6;
     private int flagImageOffset = 4;
+    private boolean fill = false;
     private boolean showFirstSectionHeading = false;
+    private boolean showFlagIcons = true;
+    private boolean showFlagHighlight = true;
     private boolean showFlagMessagesInline = false;
-    private boolean fill = false;
     private boolean leftAlignLabels = false;
     private String delimiter = DEFAULT_DELIMITER;
 
@@ -112,8 +116,12 @@
             }
         }
 
-        preferredWidth = Math.max(maximumRowHeaderWidth + horizontalSpacing + maximumFieldWidth
-            + FLAG_HIGHLIGHT_PADDING * 2, maximumSeparatorWidth);
+        preferredWidth = Math.max(maximumRowHeaderWidth + horizontalSpacing + maximumFieldWidth,
+            maximumSeparatorWidth);
+
+        if (showFlagHighlight) {
+            preferredWidth += FLAG_HIGHLIGHT_PADDING * 2;
+        }
 
         return preferredWidth;
     }
@@ -149,8 +157,11 @@
                 }
             }
 
-            fieldWidth = Math.max(0, width - (maximumRowHeaderWidth + horizontalSpacing
-                + FLAG_HIGHLIGHT_PADDING * 2));
+            fieldWidth = Math.max(0, width - (maximumRowHeaderWidth + horizontalSpacing));
+
+            if (showFlagHighlight) {
+                fieldWidth = Math.max(0, fieldWidth - FLAG_HIGHLIGHT_PADDING * 2);
+            }
         }
 
         for (int sectionIndex = 0, sectionCount = sections.getLength();
@@ -210,7 +221,9 @@
             }
         }
 
-        preferredHeight += FLAG_HIGHLIGHT_PADDING * 2;
+        if (showFlagHighlight) {
+            preferredHeight += FLAG_HIGHLIGHT_PADDING * 2;
+        }
 
         return preferredHeight;
     }
@@ -250,8 +263,11 @@
                 }
             }
 
-            fieldWidth = Math.max(0, width - (maximumRowHeaderWidth + horizontalSpacing
-                + FLAG_HIGHLIGHT_PADDING * 2));
+            fieldWidth = Math.max(0, width - (maximumRowHeaderWidth + horizontalSpacing));
+
+            if (showFlagHighlight) {
+                fieldWidth = Math.max(0, FLAG_HIGHLIGHT_PADDING * 2);
+            }
         }
 
         int baseline = -1;
@@ -312,7 +328,9 @@
             sectionIndex++;
         }
 
-        baseline += FLAG_HIGHLIGHT_PADDING;
+        if (showFlagHighlight) {
+            baseline += FLAG_HIGHLIGHT_PADDING;
+        }
 
         return baseline;
     }
@@ -345,11 +363,20 @@
 
         // Determine the field width
         int width = getWidth();
-        int fieldWidth = Math.max(0, width - (maximumRowHeaderWidth + horizontalSpacing
-            + FLAG_HIGHLIGHT_PADDING * 2));
+        int fieldWidth = Math.max(0, width - (maximumRowHeaderWidth + horizontalSpacing));
+
+        if (showFlagHighlight) {
+            fieldWidth = Math.max(0, fieldWidth - FLAG_HIGHLIGHT_PADDING * 2);
+        }
 
         // Lay out the components
-        int rowY = FLAG_HIGHLIGHT_PADDING;
+        int rowX = 0;
+        int rowY = 0;
+
+        if (showFlagHighlight) {
+            rowX += FLAG_HIGHLIGHT_PADDING;
+            rowY += FLAG_HIGHLIGHT_PADDING;
+        }
 
         for (int sectionIndex = 0, sectionCount = sections.getLength();
             sectionIndex < sectionCount; sectionIndex++) {
@@ -362,7 +389,7 @@
             } else {
                 separator.setVisible(true);
                 separator.setSize(width, separator.getPreferredHeight(width));
-                separator.setLocation(FLAG_HIGHLIGHT_PADDING, rowY);
+                separator.setLocation(rowX, rowY);
                 rowY += separator.getHeight();
             }
 
@@ -400,7 +427,7 @@
 
                     int fieldAscent = field.getBaseline(fieldSize.width, fieldSize.height);
                     if (fieldAscent == -1) {
-                        fieldAscent = fieldSize.height;
+                        fieldAscent = rowHeaderAscent;
                     }
 
                     int fieldDescent = fieldSize.height - fieldAscent;
@@ -410,12 +437,20 @@
                     int rowHeight = baseline + Math.max(rowHeaderDescent, fieldDescent);
 
                     // Position the row header
-                    int rowHeaderX = FLAG_HIGHLIGHT_PADDING;
+                    int rowHeaderX = 0;
+                    if (showFlagHighlight) {
+                        rowHeaderX += FLAG_HIGHLIGHT_PADDING;
+                    }
+
                     int rowHeaderY = rowY + (baseline - rowHeaderAscent);
                     rowHeader.setLocation(rowHeaderX, rowHeaderY);
 
                     // Position the field
-                    int fieldX = FLAG_HIGHLIGHT_PADDING + maximumRowHeaderWidth + horizontalSpacing;
+                    int fieldX = maximumRowHeaderWidth + horizontalSpacing;
+                    if (showFlagHighlight) {
+                        fieldX += FLAG_HIGHLIGHT_PADDING;
+                    }
+
                     int fieldY = rowY + (baseline - fieldAscent);
                     field.setLocation(fieldX, fieldY);
 
@@ -442,8 +477,42 @@
 
             for (int fieldIndex = 0, fieldCount = section.getLength();
                 fieldIndex < fieldCount; fieldIndex++) {
-                // TODO
-                // Component field = section.get(fieldIndex);
+                Component field = section.get(fieldIndex);
+
+                Form.Flag flag = Form.getFlag(field);
+                if (flag != null && showFlagHighlight) {
+                    MessageType messageType = flag.getMessageType();
+                    // TODO Get colors from theme
+                    Color highlightColor = null;
+
+                    switch (messageType) {
+                        case ERROR: {
+                            highlightColor = Color.RED;
+                            break;
+                        }
+
+                        case WARNING: {
+                            highlightColor = Color.YELLOW;
+                            break;
+                        }
+
+                        case QUESTION: {
+                            highlightColor = Color.BLUE;
+                            break;
+                        }
+                    }
+
+                    if (highlightColor != null) {
+                        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);
+                    }
+                }
             }
         }
     }
@@ -501,7 +570,20 @@
 
         this.flagImageOffset = flagImageOffset;
 
-        // TODO Set spacing style of all existing row headers to flagImageOffset
+        // Set spacing style of existing row headers to flagImageOffset
+        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++) {
+                BoxPane rowHeader = rowHeaders.get(sectionIndex).get(fieldIndex);
+                rowHeader.getStyles().put("spacing", flagImageOffset);
+            }
+        }
 
         invalidateComponent();
     }
@@ -514,6 +596,15 @@
         setFlagImageOffset(flagImageOffset.intValue());
     }
 
+    public boolean getFill() {
+        return fill;
+    }
+
+    public void setFill(boolean fill) {
+        this.fill = fill;
+        invalidateComponent();
+    }
+
     public boolean getShowFirstSectionHeading() {
         return showFirstSectionHeading;
     }
@@ -523,24 +614,50 @@
         invalidateComponent();
     }
 
-    public boolean getShowFlagMessagesInline() {
-        return showFlagMessagesInline;
+    public boolean getShowFlagIcons() {
+        return showFlagIcons;
     }
 
-    public void setShowFlagMessagesInline(boolean showFlagMessagesInline) {
-        this.showFlagMessagesInline = showFlagMessagesInline;
+    public void setShowFlagIcons(boolean showFlagIcons) {
+        this.showFlagIcons = showFlagIcons;
 
-        // TODO?
+        // Set visibility of existing flag image views to false
+        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++) {
+                BoxPane rowHeader = rowHeaders.get(sectionIndex).get(fieldIndex);
+                ImageView flagImageView = (ImageView)rowHeader.get(0);
+                flagImageView.setVisible(showFlagIcons);
+            }
+        }
 
         invalidateComponent();
     }
 
-    public boolean getFill() {
-        return fill;
+    public boolean getShowFlagHighlight() {
+        return showFlagHighlight;
     }
 
-    public void setFill(boolean fill) {
-        this.fill = fill;
+    public void setShowFlagHighlight(boolean showFlagHighlight) {
+        this.showFlagHighlight = showFlagHighlight;
+        invalidateComponent();
+    }
+
+    public boolean getShowFlagMessagesInline() {
+        return showFlagMessagesInline;
+    }
+
+    public void setShowFlagMessagesInline(boolean showFlagMessagesInline) {
+        this.showFlagMessagesInline = showFlagMessagesInline;
+
+        // TODO?
+
         invalidateComponent();
     }
 
@@ -551,7 +668,21 @@
     public void setLeftAlignLabels(boolean leftAlignLabels) {
         this.leftAlignLabels = leftAlignLabels;
 
-        // TODO Set horizontal alignment style of all existing row headers to left or right
+        // Set horizontal alignment style of existing row headers to left or right
+        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++) {
+                BoxPane rowHeader = rowHeaders.get(sectionIndex).get(fieldIndex);
+                rowHeader.getStyles().put("horizontalAlignment", leftAlignLabels ?
+                    HorizontalAlignment.LEFT : HorizontalAlignment.RIGHT);
+            }
+        }
 
         invalidateComponent();
     }
@@ -683,6 +814,8 @@
 
         ImageView flagImageView = new ImageView();
         flagImageView.setPreferredSize(FLAG_IMAGE_SIZE, FLAG_IMAGE_SIZE);
+        flagImageView.setVisible(showFlagIcons);
+
         rowHeader.add(flagImageView);
 
         Label label = new Label();
@@ -734,22 +867,58 @@
         Form form = (Form)getComponent();
         Component field = section.get(fieldIndex);
 
+        TerraTheme theme = (TerraTheme) Theme.getTheme();
+
         int sectionIndex = form.getSections().indexOf(section);
         BoxPane rowHeader = rowHeaders.get(sectionIndex).get(fieldIndex);
         ImageView flagImageView = (ImageView)rowHeader.get(0);
+        Label label = (Label)rowHeader.get(1);
+
         Form.Flag flag = Form.getFlag(field);
+        if (flag == null) {
+            flagImageView.setImage((Image)null);
+            label.getStyles().put("color", 1);
+            field.setTooltipText(null);
+        } else {
+            MessageType messageType = flag.getMessageType();
+            flagImageView.setImage(theme.getSmallMessageIcon(messageType));
+
+            // TODO Get colors from theme
+            Color labelColor = null;
+
+            switch (messageType) {
+                case ERROR: {
+                    labelColor = Color.RED;
+                    break;
+                }
+
+                case WARNING: {
+                    labelColor = Color.YELLOW;
+                    break;
+                }
 
-        Image flagImage = null;
-        String flagMessage = null;
+                case QUESTION: {
+                    labelColor = Color.BLACK;
+                    break;
+                }
+
+                case INFO: {
+                    labelColor = Color.BLACK;
+                    break;
+                }
+            }
+
+            label.getStyles().put("color", labelColor);
 
-        if (flag != null) {
-            TerraTheme theme = (TerraTheme) Theme.getTheme();
-            MessageType flagMessageType = flag.getMessageType();
-            flagImage = theme.getSmallMessageIcon(flagMessageType);
-            flagMessage = flag.getMessage();
+            field.setTooltipText(flag.getMessage());
         }
 
-        flagImageView.setImage(flagImage);
-        field.setTooltipText(flagMessage);
+        if (showFlagHighlight) {
+            Bounds fieldBounds = field.getBounds();
+            repaintComponent(fieldBounds.x - FLAG_HIGHLIGHT_PADDING,
+                fieldBounds.y - FLAG_HIGHLIGHT_PADDING,
+                fieldBounds.width + FLAG_HIGHLIGHT_PADDING * 2 - 1,
+                fieldBounds.height + FLAG_HIGHLIGHT_PADDING * 2 - 1);
+        }
     }
 }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewColorItemRenderer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewColorItemRenderer.java?rev=901320&r1=901319&r2=901320&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewColorItemRenderer.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewColorItemRenderer.java Wed Jan 20 18:42:42 2010
@@ -44,6 +44,11 @@
             return SIZE;
         }
 
+        @Override
+        public int getBaseline() {
+            return SIZE - 2;
+        }
+
         public Color getColor() {
             return color;
         }