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/07/21 02:51:25 UTC

svn commit: r966062 - in /pivot/trunk: demos/src/org/apache/pivot/demos/swing/ examples/src/org/apache/pivot/examples/sheets/ wtk/src/org/apache/pivot/wtk/

Author: gbrown
Date: Wed Jul 21 00:51:25 2010
New Revision: 966062

URL: http://svn.apache.org/viewvc?rev=966062&view=rev
Log:
Add scroll panes to Swing demo; add an example application demonstrating how to use custom sheets for obtaining user input.

Added:
    pivot/trunk/examples/src/org/apache/pivot/examples/sheets/
    pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.java
    pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.json
    pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.java
    pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.json
    pivot/trunk/examples/src/org/apache/pivot/examples/sheets/edit_greeting_sheet.bxml
    pivot/trunk/examples/src/org/apache/pivot/examples/sheets/sheet_example_window.bxml
Modified:
    pivot/trunk/demos/src/org/apache/pivot/demos/swing/SwingDemo.java
    pivot/trunk/demos/src/org/apache/pivot/demos/swing/pivot_window.bxml
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java

Modified: pivot/trunk/demos/src/org/apache/pivot/demos/swing/SwingDemo.java
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/swing/SwingDemo.java?rev=966062&r1=966061&r2=966062&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/swing/SwingDemo.java (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/swing/SwingDemo.java Wed Jul 21 00:51:25 2010
@@ -30,6 +30,7 @@ import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JProgressBar;
 import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
 import javax.swing.SwingUtilities;
 import javax.swing.border.EmptyBorder;
 
@@ -126,12 +127,13 @@ public class SwingDemo extends Applicati
         jProgressBar.setIndeterminate(true);
         box.add(jProgressBar);
 
-        internalFrame.add(box);
+        internalFrame.add(new JScrollPane(box));
 
         // Open and select the internal frame
         internalFrame.setLocation(50, 50);
         internalFrame.setSize(480, 360);
         internalFrame.setVisible(true);
+        internalFrame.setResizable(true);
     }
 
     private static void createPivotFrame() {
@@ -164,6 +166,7 @@ public class SwingDemo extends Applicati
         internalFrame.setLocation(240, 100);
         internalFrame.setSize(480, 360);
         internalFrame.setVisible(true);
+        internalFrame.setResizable(true);
 
         try {
             internalFrame.setSelected(true);

Modified: pivot/trunk/demos/src/org/apache/pivot/demos/swing/pivot_window.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/swing/pivot_window.bxml?rev=966062&r1=966061&r2=966062&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/swing/pivot_window.bxml (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/swing/pivot_window.bxml Wed Jul 21 00:51:25 2010
@@ -19,22 +19,24 @@ limitations under the License.
 <Window title="Pivot Window" maximized="true"
     xmlns:bxml="http://pivot.apache.org/bxml"
     xmlns="org.apache.pivot.wtk">
-    <BoxPane orientation="vertical" styles="{padding:8, spacing:8}">
-        <Label text="Hello from Pivot!" styles="{font:{bold:true}}"/>
-        <PushButton buttonData="PushButton"/>
-        <Checkbox buttonData="Checkbox" selected="true"/>
+    <ScrollPane>
+        <BoxPane orientation="vertical" styles="{padding:8, spacing:8}">
+            <Label text="Hello from Pivot!" styles="{font:{bold:true}}"/>
+            <PushButton buttonData="PushButton"/>
+            <Checkbox buttonData="Checkbox" selected="true"/>
 
-        <Border>
-            <BoxPane orientation="vertical" styles="{padding:4, spacing:4}">
-                <bxml:define>
-                    <ButtonGroup bxml:id="buttonGroup"/>
-                </bxml:define>
-                <RadioButton buttonData="RadioButton 1" buttonGroup="$buttonGroup" selected="true"/>
-                <RadioButton buttonData="RadioButton 2" buttonGroup="$buttonGroup"/>
-                <RadioButton buttonData="RadioButton 3" buttonGroup="$buttonGroup"/>
-            </BoxPane>
-        </Border>
+            <Border>
+                <BoxPane orientation="vertical" styles="{padding:4, spacing:4}">
+                    <bxml:define>
+                        <ButtonGroup bxml:id="buttonGroup"/>
+                    </bxml:define>
+                    <RadioButton buttonData="RadioButton 1" buttonGroup="$buttonGroup" selected="true"/>
+                    <RadioButton buttonData="RadioButton 2" buttonGroup="$buttonGroup"/>
+                    <RadioButton buttonData="RadioButton 3" buttonGroup="$buttonGroup"/>
+                </BoxPane>
+            </Border>
 
-        <ActivityIndicator preferredWidth="32" preferredHeight="32" active="true"/>
-    </BoxPane>
+            <ActivityIndicator preferredWidth="32" preferredHeight="32" active="true"/>
+        </BoxPane>
+    </ScrollPane>
 </Window>

Added: pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.java
URL: http://svn.apache.org/viewvc/pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.java?rev=966062&view=auto
==============================================================================
--- pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.java (added)
+++ pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.java Wed Jul 21 00:51:25 2010
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+package org.apache.pivot.examples.sheets;
+
+import java.net.URL;
+
+import org.apache.pivot.beans.BXML;
+import org.apache.pivot.beans.Bindable;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.util.Resources;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Form;
+import org.apache.pivot.wtk.MessageType;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.Sheet;
+import org.apache.pivot.wtk.SheetCloseListener;
+import org.apache.pivot.wtk.TextInput;
+import org.apache.pivot.wtk.Window;
+
+/**
+ * Edit greeting sheet.
+ */
+public class EditGreetingSheet extends Sheet implements Bindable {
+    @BXML private Form form = null;
+    @BXML private TextInput greetingTextInput = null;
+    @BXML private PushButton cancelButton = null;
+    @BXML private PushButton okButton = null;
+
+    private Resources resources = null;
+
+    @Override
+    public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
+        this.resources = resources;
+
+        cancelButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                close(false);
+            }
+        });
+
+        okButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                close(true);
+            }
+        });
+    }
+
+    @Override
+    public void open(Display display, Window owner, SheetCloseListener sheetCloseListener) {
+        super.open(display, owner, sheetCloseListener);
+
+        greetingTextInput.selectAll();
+    }
+
+    @Override
+    public void close(boolean result) {
+        form.clearFlags();
+
+        if (result) {
+            if (greetingTextInput.getTextLength() == 0) {
+                Form.setFlag(greetingTextInput, new Form.Flag(MessageType.ERROR,
+                    (String)resources.get("greetingRequired")));
+            }
+        }
+
+        if (form.getFlaggedFieldCount(MessageType.ERROR) == 0) {
+            super.close(result);
+        }
+    }
+}

Added: pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.json
URL: http://svn.apache.org/viewvc/pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.json?rev=966062&view=auto
==============================================================================
--- pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.json (added)
+++ pivot/trunk/examples/src/org/apache/pivot/examples/sheets/EditGreetingSheet.json Wed Jul 21 00:51:25 2010
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+ {  title: "Edit Greeting",
+    greeting: "Greeting",
+    cancel: "Cancel",
+    ok: "OK",
+    greetingRequired: "A greeting is required."
+ }

Added: pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.java
URL: http://svn.apache.org/viewvc/pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.java?rev=966062&view=auto
==============================================================================
--- pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.java (added)
+++ pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.java Wed Jul 21 00:51:25 2010
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.pivot.examples.sheets;
+
+import java.net.URL;
+
+import org.apache.pivot.beans.BXML;
+import org.apache.pivot.beans.Bindable;
+import org.apache.pivot.collections.HashMap;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.util.Resources;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.Sheet;
+import org.apache.pivot.wtk.SheetCloseListener;
+import org.apache.pivot.wtk.Window;
+
+/**
+ * Main window.
+ */
+public class SheetExampleWindow extends Window implements Bindable {
+    @BXML private EditGreetingSheet editGreetingSheet = null;
+    @BXML private PushButton editGreetingButton = null;
+
+    @Override
+    public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
+        editGreetingButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                HashMap<String, Object> context = new HashMap<String, Object>();
+                store(context);
+                editGreetingSheet.load(context);
+
+                editGreetingSheet.open(SheetExampleWindow.this, new SheetCloseListener() {
+                    @Override
+                    public void sheetClosed(Sheet sheet) {
+                        if (sheet.getResult()) {
+                            HashMap<String, Object> context = new HashMap<String, Object>();
+                            editGreetingSheet.store(context);
+                            load(context);
+                        }
+                    }
+                });
+            }
+        });
+    }
+}

Added: pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.json
URL: http://svn.apache.org/viewvc/pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.json?rev=966062&view=auto
==============================================================================
--- pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.json (added)
+++ pivot/trunk/examples/src/org/apache/pivot/examples/sheets/SheetExampleWindow.json Wed Jul 21 00:51:25 2010
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+ {  title: "Sheet Example",
+    defaultGreeting: "Hello Pivot!",
+    editGreeting: "Edit Greeting"
+ }

Added: pivot/trunk/examples/src/org/apache/pivot/examples/sheets/edit_greeting_sheet.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/examples/src/org/apache/pivot/examples/sheets/edit_greeting_sheet.bxml?rev=966062&view=auto
==============================================================================
--- pivot/trunk/examples/src/org/apache/pivot/examples/sheets/edit_greeting_sheet.bxml (added)
+++ pivot/trunk/examples/src/org/apache/pivot/examples/sheets/edit_greeting_sheet.bxml Wed Jul 21 00:51:25 2010
@@ -0,0 +1,46 @@
+<?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.
+-->
+
+<sheets:EditGreetingSheet title="%title"
+    xmlns:bxml="http://pivot.apache.org/bxml"
+    xmlns:sheets="org.apache.pivot.examples.sheets"
+    xmlns="org.apache.pivot.wtk">
+    <TablePane styles="{verticalSpacing:8}">
+        <columns>
+            <TablePane.Column width="1*"/>
+        </columns>
+
+        <TablePane.Row>
+            <Form bxml:id="form">
+                <Form.Section>
+                    <TextInput bxml:id="greetingTextInput" Form.label="%greeting" textKey="greeting"/>
+                </Form.Section>
+            </Form>
+        </TablePane.Row>
+
+        <TablePane.Row>
+            <BoxPane styles="{horizontalAlignment:'right'}">
+                <PushButton bxml:id="cancelButton" buttonData="%cancel"
+                    styleName="org.apache.pivot.wtk.skin.terra.commandButton"/>
+                <PushButton bxml:id="okButton" buttonData="%ok"
+                    styleName="org.apache.pivot.wtk.skin.terra.commandButton"/>
+            </BoxPane>
+        </TablePane.Row>
+    </TablePane>
+</sheets:EditGreetingSheet>
+

Added: pivot/trunk/examples/src/org/apache/pivot/examples/sheets/sheet_example_window.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/examples/src/org/apache/pivot/examples/sheets/sheet_example_window.bxml?rev=966062&view=auto
==============================================================================
--- pivot/trunk/examples/src/org/apache/pivot/examples/sheets/sheet_example_window.bxml (added)
+++ pivot/trunk/examples/src/org/apache/pivot/examples/sheets/sheet_example_window.bxml Wed Jul 21 00:51:25 2010
@@ -0,0 +1,39 @@
+<?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.
+-->
+
+<sheets:SheetExampleWindow title="%title" maximized="true"
+    xmlns:bxml="http://pivot.apache.org/bxml"
+    xmlns:sheets="org.apache.pivot.examples.sheets"
+    xmlns="org.apache.pivot.wtk">
+    <bxml:define>
+        <bxml:include bxml:id="editGreetingSheet" src="edit_greeting_sheet.bxml"
+            resources="org.apache.pivot.examples.sheets.EditGreetingSheet"/>
+    </bxml:define>
+
+    <Border>
+        <BoxPane orientation="vertical" styles="{spacing:8,
+            horizontalAlignment:'center', verticalAlignment:'center'}">
+            <Label bxml:id="greetingLabel" text="%defaultGreeting" textKey="greeting"
+                styles="{font:{size:24, bold:true},
+                horizontalAlignment:'center', verticalAlignment:'center'}"/>
+            <PushButton bxml:id="editGreetingButton" buttonData="%editGreeting"
+                styles="{minimumAspectRatio:3}"/>
+        </BoxPane>
+    </Border>
+</sheets:SheetExampleWindow>
+

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java?rev=966062&r1=966061&r2=966062&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java Wed Jul 21 00:51:25 2010
@@ -458,7 +458,18 @@ public class Form extends Container {
     }
 
     /**
-     * Returns the number of fields that are flagged with a given flag type.
+     * Clears all field flags.
+     */
+    public void clearFlags() {
+        for (Section section : sections) {
+            for (Component field : section) {
+                setFlag(field, (Flag)null);
+            }
+        }
+    }
+
+    /**
+     * Returns the number of fields that are flagged with a given message type.
      *
      * @param messageType
      * The message type to count, or <tt>null</tt> to return the count of all

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java?rev=966062&r1=966061&r2=966062&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java Wed Jul 21 00:51:25 2010
@@ -48,7 +48,7 @@ public class ScriptApplication implement
         BXMLSerializer bxmlSerializer = new BXMLSerializer();
 
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        URL location = classLoader.getResource(src);
+        URL location = classLoader.getResource(src.substring(1));
 
         if (location == null) {
             File file = new File(src);