Author: gbrown
Date: Fri Apr 23 14:02:05 2010
New Revision: 937305
URL: http://svn.apache.org/viewvc?rev=937305&view=rev
Log:
Resolve PIVOT-415.
Added:
pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.wtkx
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraAlertSkin.java
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraPromptSkin.java
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_alert_skin.wtkx
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_prompt_skin.wtkx
pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java
Added: pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.wtkx
URL:
http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.wtkx?rev=937305&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.wtkx (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.wtkx Fri Apr
23 14:02:05 2010
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window wtkx:id="window" title="Alert/Prompt Test" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns="org.apache.pivot.wtk">
+ <wtkx:define>
+ <Alert wtkx:id="alert" title="My Alert" message="Hello World!">
+ <body>
+ <TextArea text="This is a text area." editable="false"/>
+ </body>
+
+ <options>
+ <content:ButtonData icon="@bell.png" text="Bell"/>
+ <content:ButtonData icon="@clock.png" text="Clock"/>
+ <content:ButtonData icon="@cup.png" text="Cup"/>
+ </options>
+ </Alert>
+
+ <Prompt wtkx:id="prompt" title="My Prompt" message="Hello World!"
+ options="['One', 'Two', 'Three']">
+ <body>
+ <TextArea text="This is a text area." editable="false"/>
+ </body>
+ </Prompt>
+ </wtkx:define>
+
+ <content>
+ <FlowPane>
+ <PushButton buttonData="Stock Alert"
+
ButtonPressListener.buttonPressed="org.apache.pivot.wtk.Alert.alert('Hello
World!', window);"/>
+ <PushButton buttonData="Stock Prompt"
+
ButtonPressListener.buttonPressed="org.apache.pivot.wtk.Prompt.prompt('Hello
World!', window);"/>
+ <PushButton buttonData="Custom Alert"
+ ButtonPressListener.buttonPressed="alert.open(window);"/>
+ <PushButton buttonData="Custom Prompt"
+ ButtonPressListener.buttonPressed="prompt.open(window);"/>
+ </FlowPane>
+ </content>
+</Window>
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraAlertSkin.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraAlertSkin.java?rev=937305&r1=937304&r2=937305&view=diff
==============================================================================
---
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraAlertSkin.java
(original)
+++
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraAlertSkin.java
Fri Apr 23 14:02:05 2010
@@ -20,7 +20,6 @@ import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
-import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.Map;
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.json.JSONSerializer;
@@ -48,17 +47,12 @@ public class TerraAlertSkin extends Terr
private ImageView typeImageView = null;
private Label messageLabel = null;
private BoxPane messageBoxPane = null;
-
- // TODO Rename to optionButtonBoxPane?
- private BoxPane buttonBoxPane = null;
-
- // TODO Do we need this?
- private ArrayList<Button> optionButtons = new ArrayList<Button>();
+ private BoxPane optionButtonBoxPane = null;
private ButtonPressListener optionButtonPressListener = new
ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
- int optionIndex = optionButtons.indexOf(button);
+ int optionIndex = optionButtonBoxPane.indexOf(button);
if (optionIndex >= 0) {
Alert alert = (Alert)getComponent();
@@ -118,15 +112,14 @@ public class TerraAlertSkin extends Terr
typeImageView = (ImageView)wtkxSerializer.get("typeImageView");
messageLabel = (Label)wtkxSerializer.get("messageLabel");
messageBoxPane = (BoxPane)wtkxSerializer.get("messageBoxPane");
- buttonBoxPane = (BoxPane)wtkxSerializer.get("buttonBoxPane");
+ optionButtonBoxPane =
(BoxPane)wtkxSerializer.get("optionButtonBoxPane");
for (Object option : alert.getOptions()) {
PushButton optionButton = new PushButton(option);
optionButton.setStyles(commandButtonStyles);
optionButton.getButtonPressListeners().add(optionButtonPressListener);
- buttonBoxPane.add(optionButton);
- optionButtons.add(optionButton);
+ optionButtonBoxPane.add(optionButton);
}
messageTypeChanged(alert, null);
@@ -142,7 +135,7 @@ public class TerraAlertSkin extends Terr
int index = alert.getSelectedOption();
if (index >= 0) {
- optionButtons.get(index).requestFocus();
+ optionButtonBoxPane.get(index).requestFocus();
} else {
window.requestFocus();
}
@@ -179,14 +172,12 @@ public class TerraAlertSkin extends Terr
optionButton.setStyles(commandButtonStyles);
optionButton.getButtonPressListeners().add(optionButtonPressListener);
- buttonBoxPane.insert(optionButton, index);
- optionButtons.insert(optionButton, index);
+ optionButtonBoxPane.insert(optionButton, index);
}
@Override
public void optionsRemoved(Alert alert, int index, Sequence<?> removed) {
- buttonBoxPane.remove(index, removed.getLength());
- optionButtons.remove(index, removed.getLength());
+ optionButtonBoxPane.remove(index, removed.getLength());
}
@Override
@@ -195,7 +186,7 @@ public class TerraAlertSkin extends Terr
if (alert.isOpen()
&& index >= 0) {
- optionButtons.get(index).requestFocus();
+ optionButtonBoxPane.get(index).requestFocus();
}
}
}
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraPromptSkin.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraPromptSkin.java?rev=937305&r1=937304&r2=937305&view=diff
==============================================================================
---
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraPromptSkin.java
(original)
+++
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraPromptSkin.java
Fri Apr 23 14:02:05 2010
@@ -20,7 +20,6 @@ import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
-import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.Map;
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.json.JSONSerializer;
@@ -48,17 +47,12 @@ public class TerraPromptSkin extends Ter
private ImageView typeImageView = null;
private Label messageLabel = null;
private BoxPane messageBoxPane = null;
-
- // TODO Rename to optionButtonBoxPane?
- private BoxPane buttonBoxPane = null;
-
- // TODO Do we need this?
- private ArrayList<Button> optionButtons = new ArrayList<Button>();
+ private BoxPane optionButtonBoxPane = null;
private ButtonPressListener optionButtonPressListener = new
ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
- int optionIndex = optionButtons.indexOf(button);
+ int optionIndex = optionButtonBoxPane.indexOf(button);
if (optionIndex >= 0) {
Prompt prompt = (Prompt)getComponent();
@@ -111,15 +105,14 @@ public class TerraPromptSkin extends Ter
typeImageView = (ImageView)wtkxSerializer.get("typeImageView");
messageLabel = (Label)wtkxSerializer.get("messageLabel");
messageBoxPane = (BoxPane)wtkxSerializer.get("messageBoxPane");
- buttonBoxPane = (BoxPane)wtkxSerializer.get("buttonBoxPane");
+ optionButtonBoxPane =
(BoxPane)wtkxSerializer.get("optionButtonBoxPane");
for (Object option : prompt.getOptions()) {
PushButton optionButton = new PushButton(option);
optionButton.setStyles(commandButtonStyles);
optionButton.getButtonPressListeners().add(optionButtonPressListener);
- buttonBoxPane.add(optionButton);
- optionButtons.add(optionButton);
+ optionButtonBoxPane.add(optionButton);
}
messageTypeChanged(prompt, null);
@@ -135,7 +128,7 @@ public class TerraPromptSkin extends Ter
int index = prompt.getSelectedOption();
if (index >= 0) {
- optionButtons.get(index).requestFocus();
+ optionButtonBoxPane.get(index).requestFocus();
} else {
window.requestFocus();
}
@@ -172,14 +165,12 @@ public class TerraPromptSkin extends Ter
optionButton.setStyles(commandButtonStyles);
optionButton.getButtonPressListeners().add(optionButtonPressListener);
- buttonBoxPane.insert(optionButton, index);
- optionButtons.insert(optionButton, index);
+ optionButtonBoxPane.insert(optionButton, index);
}
@Override
public void optionsRemoved(Prompt prompt, int index, Sequence<?> removed) {
- buttonBoxPane.remove(index, removed.getLength());
- optionButtons.remove(index, removed.getLength());
+ optionButtonBoxPane.remove(index, removed.getLength());
}
@Override
@@ -188,7 +179,7 @@ public class TerraPromptSkin extends Ter
if (prompt.isOpen()
&& index >= 0) {
- optionButtons.get(index).requestFocus();
+ optionButtonBoxPane.get(index).requestFocus();
}
}
}
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_alert_skin.wtkx
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_alert_skin.wtkx?rev=937305&r1=937304&r2=937305&view=diff
==============================================================================
---
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_alert_skin.wtkx
(original)
+++
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_alert_skin.wtkx
Fri Apr 23 14:02:05 2010
@@ -42,6 +42,6 @@ limitations under the License.
</TablePane>
</content>
</Border>
- <BoxPane wtkx:id="buttonBoxPane"
+ <BoxPane wtkx:id="optionButtonBoxPane"
styles="{horizontalAlignment:'right', fill:true}"/>
</BoxPane>
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_prompt_skin.wtkx
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_prompt_skin.wtkx?rev=937305&r1=937304&r2=937305&view=diff
==============================================================================
---
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_prompt_skin.wtkx
(original)
+++
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/terra_prompt_skin.wtkx
Fri Apr 23 14:02:05 2010
@@ -49,7 +49,7 @@ limitations under the License.
</Border>
</TablePane.Row>
<TablePane.Row height="-1">
- <BoxPane wtkx:id="buttonBoxPane"
+ <BoxPane wtkx:id="optionButtonBoxPane"
styles="{horizontalAlignment:'right', fill:true}"/>
</TablePane.Row>
</rows>
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java?rev=937305&r1=937304&r2=937305&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java Fri Apr 23 14:02:05 2010
@@ -204,17 +204,20 @@ public class Alert extends Dialog {
messageType = MessageType.INFO;
}
- if (options == null) {
- options = new ArrayList<Object>(resources.get("defaultOption"));
- }
-
setMessageType(messageType);
setMessage(message);
setBody(body);
- setOptions(options);
+
+ if (options != null
+ && options.getLength() > 0) {
+ for (int i = 0, n = options.getLength(); i < n; i++) {
+ optionSequence.add(options.get(i));
+ }
+
+ setSelectedOption(0);
+ }
setTitle((String)resources.get("defaultTitle"));
- setSelectedOption(0);
installThemeSkin(Alert.class);
}
@@ -263,17 +266,13 @@ public class Alert extends Dialog {
return optionSequence;
}
- public void setOptions(Sequence<?> options) {
+ public void setOptions(String options) {
optionSequence.remove(0, optionSequence.getLength());
- for (int i = 0, n = options.getLength(); i < n; i++) {
- optionSequence.add(options.get(i));
- }
- }
-
- public void setOptions(String options) {
try {
- setOptions(JSONSerializer.parseList(options));
+ for (Object option : JSONSerializer.parseList(options)) {
+ optionSequence.add(option);
+ }
} catch (SerializationException exception) {
throw new IllegalArgumentException(exception);
}
@@ -315,7 +314,8 @@ public class Alert extends Dialog {
public static void alert(MessageType messageType, String message,
Component body, Display display,
DialogCloseListener dialogCloseListener) {
- Alert alert = new Alert(messageType, message, null, body);
+ Alert alert = new Alert(messageType, message,
+ new ArrayList<Object>(resources.get("defaultOption")), body);
alert.setModal(false);
alert.open(display, dialogCloseListener);
}
@@ -339,7 +339,8 @@ public class Alert extends Dialog {
public static void alert(MessageType messageType, String message,
Component body, Window owner,
DialogCloseListener dialogCloseListener) {
- Alert alert = new Alert(messageType, message, null, body);
+ Alert alert = new Alert(messageType, message,
+ new ArrayList<Object>(resources.get("defaultOption")), body);
alert.open(owner.getDisplay(), owner, dialogCloseListener);
}
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java?rev=937305&r1=937304&r2=937305&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java Fri Apr 23 14:02:05
2010
@@ -194,17 +194,20 @@ public class Prompt extends Sheet {
messageType = MessageType.INFO;
}
- if (options == null) {
- options = new ArrayList<Object>(resources.get("defaultOption"));
- }
-
setMessageType(messageType);
setMessage(message);
setBody(body);
- setOptions(options);
+
+ if (options != null
+ && options.getLength() > 0) {
+ for (int i = 0, n = options.getLength(); i < n; i++) {
+ optionSequence.add(options.get(i));
+ }
+
+ setSelectedOption(0);
+ }
setTitle((String)resources.get("defaultTitle"));
- setSelectedOption(0);
installThemeSkin(Prompt.class);
}
@@ -253,17 +256,13 @@ public class Prompt extends Sheet {
return optionSequence;
}
- public void setOptions(Sequence<?> options) {
+ public void setOptions(String options) {
optionSequence.remove(0, optionSequence.getLength());
- for (int i = 0, n = options.getLength(); i < n; i++) {
- optionSequence.add(options.get(i));
- }
- }
-
- public void setOptions(String options) {
try {
- setOptions(JSONSerializer.parseList(options));
+ for (Object option : JSONSerializer.parseList(options)) {
+ optionSequence.add(option);
+ }
} catch (SerializationException exception) {
throw new IllegalArgumentException(exception);
}
@@ -310,7 +309,8 @@ public class Prompt extends Sheet {
public static void prompt(MessageType messageType, String message,
Component body, Window owner,
SheetCloseListener sheetCloseListener) {
- Prompt prompt = new Prompt(messageType, message, null, body);
+ Prompt prompt = new Prompt(messageType, message,
+ new ArrayList<Object>(resources.get("defaultOption")), body);
prompt.open(owner, sheetCloseListener);
}
}