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/06/02 22:37:06 UTC
svn commit: r781154 - in /incubator/pivot/trunk: core/src/pivot/util/
tutorials/src/pivot/tutorials/navigation/ wtk/src/pivot/wtk/skin/
wtk/src/pivot/wtk/skin/terra/
Author: gbrown
Date: Tue Jun 2 20:37:05 2009
New Revision: 781154
URL: http://svn.apache.org/viewvc?rev=781154&view=rev
Log:
Revert earlier change to ImmutableIterator; resolve PIVOT-128; partially resolve PIVOT-124; update Expander tutorial to call scrollAreaToVisible() on expand; add comments to CardPaneSkin, TerraAccordionSkin, and TerraTabPaneSkin.
Modified:
incubator/pivot/trunk/core/src/pivot/util/ImmutableIterator.java
incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/Expanders.java
incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/expanders.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/TerraExpanderSkin.java
incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraTabPaneSkin.java
Modified: incubator/pivot/trunk/core/src/pivot/util/ImmutableIterator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/pivot/util/ImmutableIterator.java?rev=781154&r1=781153&r2=781154&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/pivot/util/ImmutableIterator.java (original)
+++ incubator/pivot/trunk/core/src/pivot/util/ImmutableIterator.java Tue Jun 2 20:37:05 2009
@@ -24,9 +24,9 @@
* @author gbrown
*/
public class ImmutableIterator<T> implements Iterator<T> {
- Iterator<? extends T> iterator;
+ Iterator<T> iterator;
- public ImmutableIterator(Iterator<? extends T> iterator) {
+ public ImmutableIterator(Iterator<T> iterator) {
if (iterator == null) {
throw new IllegalArgumentException("iterator is null.");
}
Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/Expanders.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/Expanders.java?rev=781154&r1=781153&r2=781154&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/Expanders.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/Expanders.java Tue Jun 2 20:37:05 2009
@@ -20,15 +20,33 @@
import pivot.wtk.Application;
import pivot.wtk.DesktopApplicationContext;
import pivot.wtk.Display;
+import pivot.wtk.Expander;
+import pivot.wtk.ExpanderListener;
import pivot.wtk.Window;
import pivot.wtkx.Bindable;
public class Expanders extends Bindable implements Application {
@Load(resourceName="expanders.wtkx") private Window window;
+ @Bind(fieldName="window") private Expander stocksExpander;
+ @Bind(fieldName="window") private Expander weatherExpander;
+ @Bind(fieldName="window") private Expander calendarExpander;
public void startup(Display display, Dictionary<String, String> properties)
throws Exception {
bind();
+
+ ExpanderListener expanderListener = new ExpanderListener.Adapter() {
+ public void expandedChanged(Expander expander) {
+ if (expander.isExpanded()) {
+ expander.scrollAreaToVisible(0, 0, expander.getWidth(), expander.getHeight());
+ }
+ }
+ };
+
+ stocksExpander.getExpanderListeners().add(expanderListener);
+ weatherExpander.getExpanderListeners().add(expanderListener);
+ calendarExpander.getExpanderListeners().add(expanderListener);
+
window.open(display);
}
Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/expanders.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/expanders.wtkx?rev=781154&r1=781153&r2=781154&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/expanders.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/navigation/expanders.wtkx Tue Jun 2 20:37:05 2009
@@ -25,17 +25,17 @@
<view>
<FlowPane orientation="vertical" styles="{horizontalAlignment:'justify',
padding:{left:2, right:2}}">
- <Expander title="Stocks">
+ <Expander wtkx:id="stocksExpander" title="Stocks">
<content>
<wtkx:include src="stocks.wtkx"/>
</content>
</Expander>
- <Expander title="Weather" expanded="false">
+ <Expander wtkx:id="weatherExpander" title="Weather" expanded="false">
<content>
<wtkx:include src="weather.wtkx"/>
</content>
</Expander>
- <Expander title="Calendar" expanded="false">
+ <Expander wtkx:id="calendarExpander" title="Calendar" expanded="false">
<content>
<wtkx:include src="calendar.wtkx"/>
</content>
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=781154&r1=781153&r2=781154&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CardPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/CardPaneSkin.java Tue Jun 2 20:37:05 2009
@@ -438,8 +438,15 @@
public void selectedIndexChangeVetoed(CardPane cardPane, Vote reason) {
if (reason == Vote.DENY
&& selectionChangeTransition != null) {
+ // NOTE We stop, rather than end, the transition so the completion
+ // event isn't fired; if the event fires, the listener will set
+ // the selection state
selectionChangeTransition.stop();
selectionChangeTransition = null;
+
+ if (sizeToSelection) {
+ invalidateComponent();
+ }
}
}
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=781154&r1=781153&r2=781154&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 Tue Jun 2 20:37:05 2009
@@ -725,6 +725,9 @@
public void selectedIndexChangeVetoed(Accordion accordion, Vote reason) {
if (reason == Vote.DENY
&& selectionChangeTransition != null) {
+ // NOTE We stop, rather than end, the transition so the completion
+ // event isn't fired; if the event fires, the listener will set
+ // the selection state
selectionChangeTransition.stop();
selectionChangeTransition = null;
invalidateComponent();
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraExpanderSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraExpanderSkin.java?rev=781154&r1=781153&r2=781154&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraExpanderSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/terra/TerraExpanderSkin.java Tue Jun 2 20:37:05 2009
@@ -25,7 +25,6 @@
import pivot.collections.Dictionary;
import pivot.util.Vote;
-import pivot.wtk.ApplicationContext;
import pivot.wtk.Button;
import pivot.wtk.ButtonPressListener;
import pivot.wtk.Component;
@@ -44,7 +43,6 @@
import pivot.wtk.Theme;
import pivot.wtk.VerticalAlignment;
import pivot.wtk.content.ButtonDataRenderer;
-import pivot.wtk.effects.ClipDecorator;
import pivot.wtk.effects.Transition;
import pivot.wtk.effects.TransitionListener;
import pivot.wtk.effects.easing.Easing;
@@ -60,13 +58,12 @@
public class TerraExpanderSkin extends ContainerSkin
implements ButtonPressListener, ExpanderListener {
public class ExpandTransition extends Transition {
- private boolean collapse;
+ private boolean expand;
private Easing easing = new Quadratic();
- private ClipDecorator clipDecorator = new ClipDecorator();
- public ExpandTransition(boolean collapse, int duration, int rate) {
+ public ExpandTransition(boolean expand, int duration, int rate) {
super(duration, rate, false);
- this.collapse = collapse;
+ this.expand = expand;
}
public float getScale() {
@@ -74,10 +71,10 @@
int duration = getDuration();
float scale;
- if (collapse) {
- scale = easing.easeIn(elapsedTime, 1, -1, duration);
- } else {
+ if (expand) {
scale = easing.easeOut(elapsedTime, 0, 1, duration);
+ } else {
+ scale = easing.easeIn(elapsedTime, 1, -1, duration);
}
return scale;
@@ -85,23 +82,13 @@
@Override
public void start(TransitionListener transitionListener) {
- Expander expander = (Expander)getComponent();
- Component content = expander.getContent();
- content.getDecorators().add(clipDecorator);
-
getComponent().setEnabled(false);
-
super.start(transitionListener);
}
@Override
public void stop() {
- Expander expander = (Expander)getComponent();
- Component content = expander.getContent();
- content.getDecorators().remove(clipDecorator);
-
getComponent().setEnabled(true);
-
super.stop();
}
@@ -226,7 +213,7 @@
private ExpandTransition expandTransition = null;
- private static final int EXPAND_DURATION = 150;
+ private static final int EXPAND_DURATION = 250;
private static final int EXPAND_RATE = 30;
public TerraExpanderSkin() {
@@ -266,17 +253,6 @@
}
@Override
- public void setSize(int width, int height) {
- if (expandTransition != null
- && width != getWidth()) {
- expandTransition.end();
- expandTransition = null;
- }
-
- super.setSize(width, height);
- }
-
- @Override
public void install(Component component) {
super.install(component);
@@ -306,125 +282,129 @@
}
public int getPreferredWidth(int height) {
- int preferredWidth;
-
- if (expandTransition == null) {
- preferredWidth = 2;
-
- Expander expander = (Expander)getComponent();
- Component content = expander.getContent();
-
- int titleBarPreferredWidth = titleBarFlowPane.getPreferredWidth(-1);
- int contentPreferredWidth = 0;
-
- if (content != null) {
- int contentHeightConstraint = -1;
+ Expander expander = (Expander)getComponent();
+ Component content = expander.getContent();
- if (height >= 0) {
- int reservedHeight = 2 + padding.top + padding.bottom
- + titleBarFlowPane.getPreferredHeight(-1);
+ int preferredWidth = titleBarFlowPane.getPreferredWidth(-1);
- if (expander.isExpanded()) {
- // Title bar border is only drawn when expander is expanded
- reservedHeight += 1;
- }
+ if (content != null) {
+ int contentHeight = -1;
- contentHeightConstraint = Math.max(height - reservedHeight, 0);
+ if (height >= 0) {
+ int reservedHeight = 2 + padding.top + padding.bottom
+ + titleBarFlowPane.getPreferredHeight(-1);
+
+ if (expander.isExpanded()) {
+ // Title bar border is only drawn when expander is expanded
+ reservedHeight += 1;
}
- contentPreferredWidth = padding.left + padding.right
- + content.getPreferredWidth(contentHeightConstraint);
+ contentHeight = Math.max(height - reservedHeight, 0);
}
- preferredWidth += Math.max(titleBarPreferredWidth, contentPreferredWidth);
- } else {
- preferredWidth = getWidth();
+ preferredWidth = Math.max(content.getPreferredWidth(contentHeight)
+ + (padding.left + padding.right), preferredWidth);
}
+ preferredWidth += 2;
+
return preferredWidth;
}
public int getPreferredHeight(int width) {
- int preferredHeight = 2 + titleBarFlowPane.getPreferredHeight(-1);
-
Expander expander = (Expander)getComponent();
- if (expander.isExpanded()) {
- // Title bar border is only drawn when expander is expanded
+ Component content = expander.getContent();
+
+ int preferredHeight = titleBarFlowPane.getPreferredHeight(-1);
+
+ if (content != null
+ && (expander.isExpanded()
+ || (expandTransition != null
+ && expandTransition.expand))) {
+ // Title bar border is only drawn when content is non-null and
+ // expander is expanded or expanding
preferredHeight += 1;
- Component content = expander.getContent();
- if (content != null) {
- int contentWidthConstraint = -1;
-
- if (width >= 0) {
- int reservedWidth = 2 + padding.left + padding.right;
- contentWidthConstraint = Math.max(width - reservedWidth, 0);
- }
+ int contentWidth = -1;
+ if (width >= 0) {
+ contentWidth = Math.max(width - (2 + padding.left + padding.right), 0);
+ }
- if (expandTransition == null) {
- preferredHeight += (padding.top + padding.bottom
- + content.getPreferredHeight(contentWidthConstraint));
- } else {
- float scale = expandTransition.getScale();
- preferredHeight += (int)(scale * (float)(padding.top + padding.bottom
- + content.getHeight()));
- }
+ if (expandTransition == null) {
+ preferredHeight += (padding.top + padding.bottom
+ + content.getPreferredHeight(contentWidth));
+ } else {
+ float scale = expandTransition.getScale();
+ preferredHeight += (int)(scale * (float)(padding.top + padding.bottom
+ + content.getPreferredHeight(contentWidth)));
}
}
+ preferredHeight += 2;
+
return preferredHeight;
}
public Dimensions getPreferredSize() {
- // TODO Optimize
- return new Dimensions(this.getPreferredWidth(-1),
- this.getPreferredHeight(-1));
- }
-
- public void layout() {
Expander expander = (Expander)getComponent();
Component content = expander.getContent();
- int width = getWidth();
- int height = getHeight();
+ Dimensions titleBarSize = titleBarFlowPane.getPreferredSize();
- int titleBarHeight;
- if (expandTransition == null) {
- titleBarHeight = titleBarFlowPane.getPreferredHeight(-1);
- titleBarFlowPane.setSize(Math.max(width - 2, 0), titleBarHeight);
- titleBarFlowPane.setLocation(1, 1);
- } else {
- titleBarHeight = titleBarFlowPane.getHeight();
- }
+ int preferredWidth = titleBarSize.width;
+ int preferredHeight = titleBarSize.height;
if (content != null) {
- if (expander.isExpanded()) {
- content.setVisible(true);
+ Dimensions contentSize = content.getPreferredSize();
- int reservedWidth = 2 + padding.left + padding.right;
- int contentWidth = Math.max(width - reservedWidth, 0);
+ preferredWidth = Math.max(contentSize.width + (padding.left + padding.right),
+ preferredWidth);
- int reservedHeight = 3 + padding.top + padding.bottom + titleBarHeight;
- int contentHeight = Math.max(height - reservedHeight, 0);
+ if (expander.isExpanded()
+ || (expandTransition != null
+ && expandTransition.expand)) {
+ // Title bar border is only drawn when expander is expanded
+ // or expanding
+ preferredHeight += 1;
if (expandTransition == null) {
- content.setSize(contentWidth, contentHeight);
+ preferredHeight += (padding.top + padding.bottom + contentSize.height);
} else {
- if (!expandTransition.isRunning()) {
- content.setSize(contentWidth, content.getPreferredHeight(contentWidth));
- }
-
- expandTransition.clipDecorator.setWidth(contentWidth);
- expandTransition.clipDecorator.setHeight(contentHeight);
+ float scale = expandTransition.getScale();
+ preferredHeight += (int)(scale * (float)(padding.top + padding.bottom
+ + contentSize.height));
}
+ }
+ }
- int contentX = 1 + padding.left;
- int contentY = 2 + padding.top + titleBarHeight;
+ preferredWidth += 2;
+ preferredHeight += 2;
- content.setLocation(contentX, contentY);
- } else {
- content.setVisible(false);
- }
+ return new Dimensions(preferredWidth, preferredHeight);
+ }
+
+ public void layout() {
+ Expander expander = (Expander)getComponent();
+ Component content = expander.getContent();
+
+ int width = getWidth();
+ int height = getHeight();
+
+ int titleBarHeight = titleBarFlowPane.getPreferredHeight(-1);
+ titleBarFlowPane.setSize(Math.max(width - 2, 0), titleBarHeight);
+ titleBarFlowPane.setLocation(1, 1);
+
+ if ((expander.isExpanded()
+ || (expandTransition != null
+ && expandTransition.expand))
+ && content != null) {
+ int contentWidth = Math.max(width - (2 + padding.left + padding.right), 0);
+ int contentHeight = Math.max(height - (3 + padding.top + padding.bottom + titleBarHeight), 0);
+ content.setSize(contentWidth, contentHeight);
+
+ int contentX = 1 + padding.left;
+ int contentY = 2 + padding.top + titleBarHeight;
+ content.setLocation(contentX, contentY);
}
}
@@ -436,9 +416,10 @@
int height = getHeight();
Expander expander = (Expander)getComponent();
- if (expander.isExpanded()) {
+ if (expander.isExpanded()
+ || (expandTransition != null
+ && expandTransition.expand)) {
int titleBarHeight = titleBarFlowPane.getPreferredHeight(-1);
-
graphics.setPaint(titleBarBorderColor);
GraphicsUtilities.drawLine(graphics, 0, 1 + titleBarHeight, width, Orientation.HORIZONTAL);
}
@@ -624,29 +605,28 @@
}
public Vote previewExpandedChange(final Expander expander) {
- Vote vote = Vote.APPROVE;
+ Vote vote;
- if (expander.isShowing()) {
- if (expandTransition == null) {
- if (expander.isExpanded()
- && expander.getContent() != null) {
- expandTransition = new ExpandTransition(true, EXPAND_DURATION, EXPAND_RATE);
-
- layout();
- expandTransition.start(new TransitionListener() {
- public void transitionCompleted(Transition transition) {
- expander.setExpanded(false);
- expandTransition = null;
- }
- });
-
- vote = Vote.DEFER;
+ if (expander.isShowing()
+ && expandTransition == null
+ && expander.getContent() != null) {
+ final boolean expand = !expander.isExpanded();
+ shadeButton.setButtonData(expand ? collapseImage : expandImage);
+ expandTransition = new ExpandTransition(expand, EXPAND_DURATION, EXPAND_RATE);
+
+ expandTransition.start(new TransitionListener() {
+ public void transitionCompleted(Transition transition) {
+ expander.setExpanded(expand);
+ expandTransition = null;
}
- } else {
- if (expandTransition.isRunning()) {
- vote = Vote.DEFER;
- }
- }
+ });
+ }
+
+ if (expandTransition == null
+ || !expandTransition.isRunning()) {
+ vote = Vote.APPROVE;
+ } else {
+ vote = Vote.DEFER;
}
return vote;
@@ -655,42 +635,26 @@
public void expandedChangeVetoed(Expander expander, Vote reason) {
if (reason == Vote.DENY
&& expandTransition != null) {
+ // NOTE We stop, rather than end, the transition so the completion
+ // event isn't fired; if the event fires, the listener will set
+ // the expanded state
expandTransition.stop();
expandTransition = null;
+
+ shadeButton.setButtonData(expander.isExpanded() ? collapseImage : expandImage);
+
invalidateComponent();
}
}
public void expandedChanged(final Expander expander) {
- if (expander.isShowing()) {
- if (expander.isExpanded()
- && expander.getContent() != null) {
- expandTransition = new ExpandTransition(false, EXPAND_DURATION, EXPAND_RATE);
-
- layout();
- expandTransition.start(new TransitionListener() {
- public void transitionCompleted(Transition transition) {
- ApplicationContext.queueCallback(new Runnable() {
- public void run() {
- expander.scrollAreaToVisible(0, 0, expander.getWidth(), expander.getHeight());
- }
- });
- expandTransition = null;
- }
- });
- }
- }
-
- Image buttonData = expander.isExpanded() ? collapseImage : expandImage;
- shadeButton.setButtonData(buttonData);
-
+ shadeButton.setButtonData(expander.isExpanded() ? collapseImage : expandImage);
invalidateComponent();
}
public void contentChanged(Expander expander, Component previousContent) {
if (expandTransition != null) {
- expandTransition.stop();
- expandTransition = null;
+ expandTransition.end();
}
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=781154&r1=781153&r2=781154&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 Tue Jun 2 20:37:05 2009
@@ -1190,8 +1190,12 @@
public void selectedIndexChangeVetoed(TabPane tabPane, Vote reason) {
if (reason == Vote.DENY
&& selectionChangeTransition != null) {
+ // NOTE We stop, rather than end, the transition so the completion
+ // event isn't fired; if the event fires, the listener will set
+ // the selection state
selectionChangeTransition.stop();
selectionChangeTransition = null;
+ invalidateComponent();
}
}