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 2009/05/20 16:22:12 UTC

svn commit: r776709 - in /incubator/pivot/trunk: tutorials/src/pivot/tutorials/layout/ tutorials/src/pivot/tutorials/navigation/ wtk/src/pivot/wtk/skin/ wtk/src/pivot/wtk/skin/terra/ wtk/test/pivot/wtk/test/

Author: gbrown
Date: Wed May 20 14:22:11 2009
New Revision: 776709

URL: http://svn.apache.org/viewvc?rev=776709&view=rev
Log:
Fix minor issues in flow pane, card pane, and tab pane tutorials; automatically select the first card/tab/panel in CardPaneSkin, TerraTabPaneSkin, and TerraAccordionSkin.

Modified:
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/layout/FlowPanes.java
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/CardPanes.java
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/TabPanes.java
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/card_panes.wtkx
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/tab_panes.wtkx
    incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CardPaneSkin.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraAccordionSkin.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTabPaneSkin.java
    incubator/pivot/trunk/wtk/test/pivot/wtk/test/accordion_test.wtkx

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/layout/FlowPanes.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/layout/FlowPanes.java?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/layout/FlowPanes.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/layout/FlowPanes.java Wed May 20 14:22:11 2009
@@ -44,66 +44,29 @@
     @Bind(fieldName="window") private RadioButton verticalAlignmentCenterButton;
     @Bind(fieldName="window") private RadioButton verticalAlignmentJustifyButton;
 
-    private ButtonStateListener buttonStateListener = new ButtonStateListener() {
-        public void stateChanged(Button button, Button.State previousState) {
-            Orientation orientation = null;
-            if (horizontalOrientationButton.isSelected()) {
-                orientation = Orientation.HORIZONTAL;
-            } else if (verticalOrientationButton.isSelected()) {
-                orientation = Orientation.VERTICAL;
-            }
-
-            if (orientation != null) {
-                flowPane.setOrientation(orientation);
-            }
-
-            HorizontalAlignment horizontalAlignment = null;
-            if (horizontalAlignmentLeftButton.isSelected()) {
-                horizontalAlignment = HorizontalAlignment.LEFT;
-            } else if (horizontalAlignmentRightButton.isSelected()) {
-                horizontalAlignment = HorizontalAlignment.RIGHT;
-            } else if (horizontalAlignmentCenterButton.isSelected()) {
-                horizontalAlignment = HorizontalAlignment.CENTER;
-            } else if (horizontalAlignmentJustifyButton.isSelected()) {
-                horizontalAlignment = HorizontalAlignment.JUSTIFY;
-            }
-
-            if (horizontalAlignment != null) {
-                flowPane.getStyles().put("horizontalAlignment", horizontalAlignment);
-            }
-
-            VerticalAlignment verticalAlignment = null;
-            if (verticalAlignmentTopButton.isSelected()) {
-                verticalAlignment = VerticalAlignment.TOP;
-            } else if (verticalAlignmentBottomButton.isSelected()) {
-                verticalAlignment = VerticalAlignment.BOTTOM;
-            } else if (verticalAlignmentCenterButton.isSelected()) {
-                verticalAlignment = VerticalAlignment.CENTER;
-            } else if (verticalAlignmentJustifyButton.isSelected()) {
-                verticalAlignment = VerticalAlignment.JUSTIFY;
-            }
-
-            if (verticalAlignment != null) {
-                flowPane.getStyles().put("verticalAlignment", verticalAlignment);
-            }
-        }
-    };
-
     public void startup(Display display, Dictionary<String, String> properties) throws Exception {
         bind();
 
-        horizontalOrientationButton.getButtonStateListeners().add(buttonStateListener);
-        verticalOrientationButton.getButtonStateListeners().add(buttonStateListener);
-        horizontalAlignmentLeftButton.getButtonStateListeners().add(buttonStateListener);
-        horizontalAlignmentRightButton.getButtonStateListeners().add(buttonStateListener);
-        horizontalAlignmentCenterButton.getButtonStateListeners().add(buttonStateListener);
-        horizontalAlignmentJustifyButton.getButtonStateListeners().add(buttonStateListener);
-        verticalAlignmentTopButton.getButtonStateListeners().add(buttonStateListener);
-        verticalAlignmentBottomButton.getButtonStateListeners().add(buttonStateListener);
-        verticalAlignmentCenterButton.getButtonStateListeners().add(buttonStateListener);
-        verticalAlignmentJustifyButton.getButtonStateListeners().add(buttonStateListener);
+        ButtonStateListener radioButtonStateListener = new ButtonStateListener() {
+            public void stateChanged(Button button, Button.State previousState) {
+                if (button.isSelected()) {
+                    updateFlowPaneState();
+                }
+            }
+        };
+
+        horizontalOrientationButton.getButtonStateListeners().add(radioButtonStateListener);
+        verticalOrientationButton.getButtonStateListeners().add(radioButtonStateListener);
+        horizontalAlignmentLeftButton.getButtonStateListeners().add(radioButtonStateListener);
+        horizontalAlignmentRightButton.getButtonStateListeners().add(radioButtonStateListener);
+        horizontalAlignmentCenterButton.getButtonStateListeners().add(radioButtonStateListener);
+        horizontalAlignmentJustifyButton.getButtonStateListeners().add(radioButtonStateListener);
+        verticalAlignmentTopButton.getButtonStateListeners().add(radioButtonStateListener);
+        verticalAlignmentBottomButton.getButtonStateListeners().add(radioButtonStateListener);
+        verticalAlignmentCenterButton.getButtonStateListeners().add(radioButtonStateListener);
+        verticalAlignmentJustifyButton.getButtonStateListeners().add(radioButtonStateListener);
 
-        buttonStateListener.stateChanged(null, null);
+        updateFlowPaneState();
 
         window.open(display);
     }
@@ -122,6 +85,49 @@
     public void resume() {
     }
 
+    private void updateFlowPaneState() {
+        Orientation orientation = null;
+        if (horizontalOrientationButton.isSelected()) {
+            orientation = Orientation.HORIZONTAL;
+        } else if (verticalOrientationButton.isSelected()) {
+            orientation = Orientation.VERTICAL;
+        }
+
+        if (orientation != null) {
+            flowPane.setOrientation(orientation);
+        }
+
+        HorizontalAlignment horizontalAlignment = null;
+        if (horizontalAlignmentLeftButton.isSelected()) {
+            horizontalAlignment = HorizontalAlignment.LEFT;
+        } else if (horizontalAlignmentRightButton.isSelected()) {
+            horizontalAlignment = HorizontalAlignment.RIGHT;
+        } else if (horizontalAlignmentCenterButton.isSelected()) {
+            horizontalAlignment = HorizontalAlignment.CENTER;
+        } else if (horizontalAlignmentJustifyButton.isSelected()) {
+            horizontalAlignment = HorizontalAlignment.JUSTIFY;
+        }
+
+        if (horizontalAlignment != null) {
+            flowPane.getStyles().put("horizontalAlignment", horizontalAlignment);
+        }
+
+        VerticalAlignment verticalAlignment = null;
+        if (verticalAlignmentTopButton.isSelected()) {
+            verticalAlignment = VerticalAlignment.TOP;
+        } else if (verticalAlignmentBottomButton.isSelected()) {
+            verticalAlignment = VerticalAlignment.BOTTOM;
+        } else if (verticalAlignmentCenterButton.isSelected()) {
+            verticalAlignment = VerticalAlignment.CENTER;
+        } else if (verticalAlignmentJustifyButton.isSelected()) {
+            verticalAlignment = VerticalAlignment.JUSTIFY;
+        }
+
+        if (verticalAlignment != null) {
+            flowPane.getStyles().put("verticalAlignment", verticalAlignment);
+        }
+    }
+
     public static void main(String[] args) {
         DesktopApplicationContext.main(FlowPanes.class, args);
     }

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/CardPanes.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/CardPanes.java?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/CardPanes.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/CardPanes.java Wed May 20 14:22:11 2009
@@ -64,16 +64,25 @@
             }
         });
 
-        ButtonStateListener buttonStateListener = new ButtonStateListener() {
+        ButtonStateListener checkboxStateListener = new ButtonStateListener() {
             public void stateChanged(Button button, Button.State previousState) {
                 updateCardPane();
             }
         };
 
-        sizeToSelectionCheckbox.getButtonStateListeners().add(buttonStateListener);
-        crossfadeRadioButton.getButtonStateListeners().add(buttonStateListener);
-        horizontalSlideRadioButton.getButtonStateListeners().add(buttonStateListener);
-        verticalSlideRadioButton.getButtonStateListeners().add(buttonStateListener);
+        sizeToSelectionCheckbox.getButtonStateListeners().add(checkboxStateListener);
+
+        ButtonStateListener radioButtonStateListener = new ButtonStateListener() {
+            public void stateChanged(Button button, Button.State previousState) {
+                if (button.isSelected()) {
+                    updateCardPane();
+                }
+            }
+        };
+
+        crossfadeRadioButton.getButtonStateListeners().add(radioButtonStateListener);
+        horizontalSlideRadioButton.getButtonStateListeners().add(radioButtonStateListener);
+        verticalSlideRadioButton.getButtonStateListeners().add(radioButtonStateListener);
 
         updateCardPane();
         updateLinkButtonState();

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/TabPanes.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/TabPanes.java?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/TabPanes.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/TabPanes.java Wed May 20 14:22:11 2009
@@ -28,7 +28,6 @@
 import pivot.wtk.RadioButton;
 import pivot.wtk.TabPane;
 import pivot.wtk.Window;
-import pivot.wtk.Button.Group;
 import pivot.wtkx.Bindable;
 
 public class TabPanes extends Bindable implements Application {
@@ -36,26 +35,31 @@
     @Bind(fieldName="window") private TabPane tabPane;
     @Bind(fieldName="window") private Checkbox collapsibleCheckbox;
     @Bind(fieldName="window") private RadioButton horizontalRadioButton;
+    @Bind(fieldName="window") private RadioButton verticalRadioButton;
     @Bind(fieldName="window") private FlowPane cornerFlowPane;
 
-    private Button.Group tabOrientationGroup = null;
-
     public void startup(Display display, Dictionary<String, String> properties)
         throws Exception {
         bind();
 
-        collapsibleCheckbox.getButtonStateListeners().add(new ButtonStateListener() {
+        ButtonStateListener checkboxStateListener = new ButtonStateListener() {
             public void stateChanged(Button button, Button.State previousState) {
                 updateTabPane();
             }
-        });
+        };
 
-        tabOrientationGroup = Button.getGroup("tabOrientation");
-        tabOrientationGroup.getGroupListeners().add(new Button.GroupListener() {
-            public void selectionChanged(Group group, Button previousSelection) {
-                updateTabPane();
+        collapsibleCheckbox.getButtonStateListeners().add(checkboxStateListener);
+
+        ButtonStateListener radioButtonStateListener = new ButtonStateListener() {
+            public void stateChanged(Button button, Button.State previousState) {
+                if (button.isSelected()) {
+                    updateTabPane();
+                }
             }
-        });
+        };
+
+        horizontalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
+        verticalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
 
         updateTabPane();
 
@@ -79,7 +83,7 @@
     private void updateTabPane() {
         tabPane.getStyles().put("collapsible", collapsibleCheckbox.isSelected());
 
-        if (tabOrientationGroup.getSelection() == horizontalRadioButton) {
+        if (horizontalRadioButton.isSelected()) {
             tabPane.getStyles().put("tabOrientation", Orientation.HORIZONTAL);
             if (tabPane.getCorner() == null) {
                 tabPane.setCorner(cornerFlowPane);

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/card_panes.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/card_panes.wtkx?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/card_panes.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/card_panes.wtkx Wed May 20 14:22:11 2009
@@ -38,7 +38,7 @@
                                             backgroundColor:'#cccccc'}">
                                             <Border styles="{padding:6}">
                                                 <content>
-                                                    <CardPane wtkx:id="cardPane" selectedIndex="0">
+                                                    <CardPane wtkx:id="cardPane">
                                                         <ImageView image="pivot/tutorials/IMG_0725_2.jpg"/>
                                                         <ImageView image="pivot/tutorials/IMG_0735_2.jpg"/>
                                                         <ImageView image="pivot/tutorials/IMG_0767_2.jpg"/>

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/tab_panes.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/tab_panes.wtkx?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/tab_panes.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/tab_panes.wtkx Wed May 20 14:22:11 2009
@@ -29,7 +29,7 @@
                     <Border styles="{padding:12}">
                         <content>
                             <FlowPane>
-                                <TabPane wtkx:id="tabPane" selectedIndex="0">
+                                <TabPane wtkx:id="tabPane">
                                     <tabs>
                                         <FlowPane TabPane.icon="pivot/tutorials/bell.png" TabPane.name="Bell"
                                             styles="{horizontalAlignment:'center', verticalAlignment:'center'}">

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CardPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CardPaneSkin.java?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CardPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CardPaneSkin.java Wed May 20 14:22:11 2009
@@ -70,32 +70,23 @@
      * @author gbrown
      */
     public abstract class SelectionChangeTransition extends Transition {
-        private int from;
-        private int to;
+        private Component fromCard;
+        private Component toCard;
 
         public SelectionChangeTransition(int from, int to) {
             super(SELECTION_CHANGE_DURATION, SELECTION_CHANGE_RATE, false);
 
-            this.from = from;
-            this.to = to;
-        }
-
-        public int getFrom() {
-            return from;
-        }
-
-        public Component getFromCard() {
             CardPane cardPane = (CardPane)getComponent();
-            return (from == -1) ? null : cardPane.get(from);
+            fromCard = (from == -1) ? null : cardPane.get(from);
+            toCard = (to == -1) ? null : cardPane.get(to);
         }
 
-        public int getTo() {
-            return to;
+        public Component getFromCard() {
+            return fromCard;
         }
 
         public Component getToCard() {
-            CardPane cardPane = (CardPane)getComponent();
-            return (to == -1) ? null : cardPane.get(to);
+            return toCard;
         }
     }
 
@@ -165,10 +156,13 @@
      * @author gbrown
      */
     public class SlideTransition extends SelectionChangeTransition {
+        private int direction;
         private Easing slideEasing = new Quartic();
 
         public SlideTransition(int from, int to) {
             super(from, to);
+
+            direction = Integer.signum(from - to);
         }
 
         @Override
@@ -189,23 +183,16 @@
 
         @Override
         protected void update() {
-            CardPane cardPane = (CardPane)getComponent();
-
             int width = getWidth();
             int height = getHeight();
 
             float percentComplete = slideEasing.easeOut(getElapsedTime(), 0, 1, getDuration());
 
-            int from = getFrom();
-            int to = getTo();
-
-            int direction = Integer.signum(from - to);
-
             int dx = (int)((float)width * percentComplete) * direction;
             int dy = (int)((float)height * percentComplete) * direction;
 
-            Component fromCard = cardPane.get(from);
-            Component toCard = cardPane.get(to);
+            Component fromCard = getFromCard();
+            Component toCard = getToCard();
 
             if (selectionChangeEffect == SelectionChangeEffect.HORIZONTAL_SLIDE) {
                 fromCard.setLocation(dx, 0);
@@ -387,30 +374,26 @@
     @Override
     public void componentInserted(Container container, int index) {
         if (selectionChangeTransition != null) {
-            if (selectionChangeTransition.from >= index) {
-                selectionChangeTransition.from++;
-            }
-
-            if (selectionChangeTransition.to >= index) {
-                selectionChangeTransition.to++;
-            }
-
             selectionChangeTransition.end();
         }
 
         super.componentInserted(container, index);
 
-        Component card = container.get(index);
+        CardPane cardPane = (CardPane)container;
+        Component card = cardPane.get(index);
         card.setVisible(false);
 
+        if (cardPane.getLength() == 1) {
+            cardPane.setSelectedIndex(0);
+        }
+
         invalidateComponent();
     }
 
     @Override
     public void componentsRemoved(Container container, int index, Sequence<Component> removed) {
         if (selectionChangeTransition != null) {
-            selectionChangeTransition.stop();
-            selectionChangeTransition = null;
+            selectionChangeTransition.end();
         }
 
         super.componentsRemoved(container, index, removed);
@@ -454,7 +437,10 @@
 
                         SelectionChangeTransition selectionChangeTransition =
                             (SelectionChangeTransition)transition;
-                        cardPane.setSelectedIndex(selectionChangeTransition.getTo());
+
+                        Component toCard = selectionChangeTransition.getToCard();
+                        int selectedIndex = cardPane.indexOf(toCard);
+                        cardPane.setSelectedIndex(selectedIndex);
                         CardPaneSkin.this.selectionChangeTransition = null;
                     }
                 });

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraAccordionSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraAccordionSkin.java?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraAccordionSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraAccordionSkin.java Wed May 20 14:22:11 2009
@@ -649,6 +649,10 @@
         panelHeader.setGroup(panelHeaderGroup);
         panelHeaders.insert(panelHeader, index);
 
+        if (accordion.getPanels().getLength() == 1) {
+            accordion.setSelectedIndex(0);
+        }
+
         invalidateComponent();
     }
 

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTabPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTabPaneSkin.java?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTabPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTabPaneSkin.java Wed May 20 14:22:11 2009
@@ -1094,6 +1094,12 @@
         tabButton.setGroup(tabButtonGroup);
 
         buttonFlowPane.insert(tabButton, index);
+
+        if (tabPane.getTabs().getLength() == 1) {
+            tabPane.setSelectedIndex(0);
+        }
+
+        invalidateComponent();
     }
 
     public void tabsRemoved(TabPane tabPane, int index, Sequence<Component> removed) {
@@ -1111,6 +1117,8 @@
             TabButton tabButton = (TabButton)removedButtons.get(i);
             tabButton.setGroup((Group)null);
         }
+
+        invalidateComponent();
     }
 
     public void cornerChanged(TabPane tabPane, Component previousCorner) {

Modified: incubator/pivot/trunk/wtk/test/pivot/wtk/test/accordion_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/pivot/wtk/test/accordion_test.wtkx?rev=776709&r1=776708&r2=776709&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/pivot/wtk/test/accordion_test.wtkx (original)
+++ incubator/pivot/trunk/wtk/test/pivot/wtk/test/accordion_test.wtkx Wed May 20 14:22:11 2009
@@ -19,7 +19,7 @@
 <Frame title="Accordion Test" preferredWidth="240" preferredHeight="360"
     xmlns:wtkx="http://incubator.apache.org/pivot/wtkx/1.1" xmlns="pivot.wtk">
     <content>
-        <Accordion selectedIndex="0">
+        <Accordion>
             <panels>
                 <Label Accordion.name="A" text="Hello"/>
                 <Label Accordion.name="B" text="World"/>