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/10/05 21:20:34 UTC

svn commit: r1004774 - in /pivot/trunk: tutorials/src/org/apache/pivot/tutorials/lists/ tutorials/src/org/apache/pivot/tutorials/menus/ wtk/src/org/apache/pivot/wtk/content/

Author: gbrown
Date: Tue Oct  5 19:20:34 2010
New Revision: 1004774

URL: http://svn.apache.org/viewvc?rev=1004774&view=rev
Log:
Add repeatable list button tutorial and new menu button tutorial (to replace the previous version, which had been based on the now-obsolete drawing API).

Modified:
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/RepeatableListButtons.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/repeatable_list_buttons.bxml
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.bxml
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ColorItem.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorItemRenderer.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewColorItemRenderer.java

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/RepeatableListButtons.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/RepeatableListButtons.java?rev=1004774&r1=1004773&r2=1004774&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/RepeatableListButtons.java (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/RepeatableListButtons.java Tue Oct  5 19:20:34 2010
@@ -16,16 +16,76 @@
  */
 package org.apache.pivot.tutorials.lists;
 
+import java.awt.Color;
 import java.net.URL;
 
 import org.apache.pivot.beans.Bindable;
+import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.util.Resources;
+import org.apache.pivot.wtk.Action;
+import org.apache.pivot.wtk.BoxPane;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonStateListener;
+import org.apache.pivot.wtk.Checkbox;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.ListButton;
 import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtk.Button.State;
+import org.apache.pivot.wtk.content.ColorItem;
 
 public class RepeatableListButtons extends Window implements Bindable {
+    private ListButton colorListButton = null;
+    private BoxPane checkboxBoxPane = null;
+
+    private int selectedCount = 0;
+
+    private Action applyColorAction = new Action() {
+        @Override
+        public void perform(Component source) {
+            ColorItem colorItem = (ColorItem)colorListButton.getButtonData();
+            Color color = colorItem.getColor();
+
+            for (Component component : checkboxBoxPane) {
+                Checkbox checkbox = (Checkbox)component;
+                if (checkbox.isSelected()) {
+                    checkbox.getStyles().put("color", color);
+                    checkbox.setSelected(false);
+                }
+            }
+        }
+    };
+
+    public RepeatableListButtons() {
+        Action.getNamedActions().put("applyColor", applyColorAction);
+        applyColorAction.setEnabled(false);
+    }
+
     @Override
     public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
-        // TODO
+        colorListButton = (ListButton)namespace.get("colorListButton");
+        checkboxBoxPane = (BoxPane)namespace.get("checkboxBoxPane");
+
+        ButtonStateListener buttonStateListener = new ButtonStateListener() {
+            @Override
+            public void stateChanged(Button button, State previousState) {
+                if (button.isSelected()) {
+                    selectedCount++;
+                } else {
+                    selectedCount--;
+                }
+
+                applyColorAction.setEnabled(selectedCount > 0);
+            }
+        };
+
+        ArrayList<String> numbers = new ArrayList<String>("One", "Two", "Three", "Four", "Five",
+            "Six", "Seven", "Eight", "Nine", "Ten");
+
+        for (String number : numbers) {
+            Checkbox checkbox = new Checkbox(number);
+            checkbox.getButtonStateListeners().add(buttonStateListener);
+            checkboxBoxPane.add(checkbox);
+        }
     }
 }

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/repeatable_list_buttons.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/repeatable_list_buttons.bxml?rev=1004774&r1=1004773&r2=1004774&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/repeatable_list_buttons.bxml (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/repeatable_list_buttons.bxml Tue Oct  5 19:20:34 2010
@@ -16,9 +16,57 @@ See the License for the specific languag
 limitations under the License.
 -->
 
-<lists:ListButtons title="List Buttons" maximized="true"
+<lists:RepeatableListButtons title="Repeatable List Buttons" maximized="true"
     xmlns:bxml="http://pivot.apache.org/bxml"
+    xmlns:content="org.apache.pivot.wtk.content"
     xmlns:lists="org.apache.pivot.tutorials.lists"
     xmlns="org.apache.pivot.wtk">
-    <!-- TODO -->
-</lists:ListButtons>
+    <Border styles="{padding:8}">
+        <TablePane styles="{horizontalSpacing:4}">
+            <columns>
+                <TablePane.Column width="-1"/>
+                <TablePane.Column width="1*"/>
+            </columns>
+
+            <TablePane.Row height="1*">
+                <FlowPane>
+                    <Label text="Color:"/>
+                    <ListButton bxml:id="colorListButton" Form.label="Color"
+                        repeatable="true" action="applyColor" listSize="8"
+                        selectedIndex="0">
+                        <dataRenderer>
+                            <content:ListButtonColorItemRenderer/>
+                        </dataRenderer>
+                        <itemRenderer>
+                            <content:ListViewColorItemRenderer/>
+                        </itemRenderer>
+
+                        <content:ColorItem color="#000000" name="Black"/>
+                        <content:ColorItem color="#0000AA" name="Blue"/>
+                        <content:ColorItem color="#00AA00" name="Green"/>
+                        <content:ColorItem color="#00AAAA" name="Cyan"/>
+                        <content:ColorItem color="#AA0000" name="Red"/>
+                        <content:ColorItem color="#AA00AA" name="Magenta"/>
+                        <content:ColorItem color="#AA5500" name="Brown"/>
+                        <content:ColorItem color="#AAAAAA" name="Light Gray"/>
+                        <content:ColorItem color="#555555" name="Dark Gray"/>
+                        <content:ColorItem color="#5555FF" name="Bright Blue"/>
+                        <content:ColorItem color="#55FF55" name="Bright Green"/>
+                        <content:ColorItem color="#55FFFF" name="Bright Cyan"/>
+                        <content:ColorItem color="#FF5555" name="Bright Red"/>
+                        <content:ColorItem color="#FF55FF" name="Bright Magenta"/>
+                        <content:ColorItem color="#FFFF55" name="Bright Yellow"/>
+                        <content:ColorItem color="#FFFFFF" name="White"/>
+                    </ListButton>
+                </FlowPane>
+
+                <Border>
+                    <ScrollPane>
+                        <BoxPane bxml:id="checkboxBoxPane" orientation="vertical"
+                            styles="{padding:4, spacing:4}"/>
+                    </ScrollPane>
+                </Border>
+            </TablePane.Row>
+        </TablePane>
+    </Border>
+</lists:RepeatableListButtons>

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java?rev=1004774&r1=1004773&r2=1004774&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/MenuButtons.java Tue Oct  5 19:20:34 2010
@@ -21,11 +21,43 @@ import java.net.URL;
 import org.apache.pivot.beans.Bindable;
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.util.Resources;
+import org.apache.pivot.wtk.Action;
+import org.apache.pivot.wtk.BoxPane;
+import org.apache.pivot.wtk.Checkbox;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.RadioButton;
 import org.apache.pivot.wtk.Window;
 
 public class MenuButtons extends Window implements Bindable {
+    private BoxPane componentBoxPane = null;
+
+    public MenuButtons() {
+        Action.getNamedActions().put("addPushButton", new Action() {
+            @Override
+            public void perform(Component source) {
+                componentBoxPane.add(new PushButton("Push button"));
+
+            }
+        });
+
+        Action.getNamedActions().put("addCheckbox", new Action() {
+            @Override
+            public void perform(Component source) {
+                componentBoxPane.add(new Checkbox("Checkbox"));
+            }
+        });
+
+        Action.getNamedActions().put("addRadioButton", new Action() {
+            @Override
+            public void perform(Component source) {
+                componentBoxPane.add(new RadioButton("Radio button"));
+            }
+        });
+    }
+
     @Override
     public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
-        // TODO
+        componentBoxPane = (BoxPane)namespace.get("componentBoxPane");
     }
 }

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.bxml?rev=1004774&r1=1004773&r2=1004774&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.bxml (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/menus/menu_buttons.bxml Tue Oct  5 19:20:34 2010
@@ -21,5 +21,33 @@ limitations under the License.
     xmlns:content="org.apache.pivot.wtk.content"
     xmlns:menus="org.apache.pivot.tutorials.menus"
     xmlns="org.apache.pivot.wtk">
-    <!-- TODO -->
+    <Border styles="{padding:8}">
+        <TablePane styles="{horizontalSpacing:4}">
+            <columns>
+                <TablePane.Column width="-1"/>
+                <TablePane.Column width="1*"/>
+            </columns>
+
+            <TablePane.Row height="1*">
+                <BoxPane orientation="vertical">
+                    <MenuButton buttonData="Add Component">
+                        <Menu>
+                            <Menu.Section>
+                                <Menu.Item buttonData="Push Button" action="addPushButton"/>
+                                <Menu.Item buttonData="Checkbox" action="addCheckbox"/>
+                                <Menu.Item buttonData="Radio Button" action="addRadioButton"/>
+                            </Menu.Section>
+                        </Menu>
+                    </MenuButton>
+                </BoxPane>
+
+                <Border>
+                    <ScrollPane>
+                        <BoxPane bxml:id="componentBoxPane" orientation="vertical"
+                            styles="{padding:4, spacing:4}"/>
+                    </ScrollPane>
+                </Border>
+            </TablePane.Row>
+        </TablePane>
+    </Border>
 </menus:MenuButtons>

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ColorItem.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ColorItem.java?rev=1004774&r1=1004773&r2=1004774&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ColorItem.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ColorItem.java Tue Oct  5 19:20:34 2010
@@ -61,17 +61,15 @@ public class ColorItem {
     }
 
     public String getName() {
-        String name = this.name;
+        return name;
+    }
 
+    public void setName(String name) {
         if (name == null) {
             name = String.format("#%02X%02X%02X", color.getRed(), color.getGreen(),
                 color.getBlue());
         }
 
-        return name;
-    }
-
-    public void setName(String name) {
         this.name = name;
     }
 

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorItemRenderer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorItemRenderer.java?rev=1004774&r1=1004773&r2=1004774&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorItemRenderer.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonColorItemRenderer.java Tue Oct  5 19:20:34 2010
@@ -46,19 +46,19 @@ public class ListButtonColorItemRenderer
     @Override
     public void render(Object data, Button button, boolean highlighted) {
         Color color;
-
-        if (data instanceof ColorItem) {
+        if (data == null) {
+            color = Color.WHITE;
+        } else if (data instanceof ColorItem) {
             ColorItem colorItem = (ColorItem)data;
             color = colorItem.getColor();
-        } else  if (data instanceof Color) {
+        } else if (data instanceof Color) {
             color = (Color)data;
-        } else if (data != null) {
-            color = GraphicsUtilities.decodeColor(data.toString());
         } else {
-            color = Color.WHITE;
+            color = GraphicsUtilities.decodeColor(data.toString());
         }
 
-        colorBadge.setColor(color);
+        colorBadge.setColor(button.isEnabled() ?
+            color : new Color(color.getRed(), color.getGreen(), color.getBlue(), 0x99));
     }
 
     @Override

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=1004774&r1=1004773&r2=1004774&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 Tue Oct  5 19:20:34 2010
@@ -80,21 +80,22 @@ public class ListViewColorItemRenderer e
         boolean checked, boolean highlighted, boolean disabled) {
         if (item != null) {
             ColorItem colorItem;
-            if (item instanceof ColorItem) {
+            if (item == null) {
+                colorItem = new ColorItem(Color.WHITE);
+            } else if (item instanceof ColorItem) {
                 colorItem = (ColorItem)item;
+            } else if (item instanceof Color) {
+                colorItem = new ColorItem((Color)item);
             } else {
-                Color color;
-                if (item instanceof Color) {
-                    color = (Color)item;
-                } else {
-                    color = GraphicsUtilities.decodeColor(item.toString());
-                }
-
-                colorItem = new ColorItem(color);
+                colorItem = new ColorItem(GraphicsUtilities.decodeColor(item.toString()));
             }
 
-            colorBadge.setColor(colorItem.getColor());
-            listItem.setText(colorItem.getName());
+            Color color = colorItem.getColor();
+            String name = colorItem.getName();
+
+            colorBadge.setColor(listView.isEnabled() ?
+                color : new Color(color.getRed(), color.getGreen(), color.getBlue(), 0x99));
+            listItem.setText(name);
         }
 
         super.render(listItem, index, listView, selected, checked, highlighted, disabled);