You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2012/04/27 14:50:20 UTC

svn commit: r1331397 - in /pivot/trunk: core/src/org/apache/pivot/util/ tests/src/org/apache/pivot/tests/ wtk/src/org/apache/pivot/wtk/

Author: smartini
Date: Fri Apr 27 12:50:20 2012
New Revision: 1331397

URL: http://svn.apache.org/viewvc?rev=1331397&view=rev
Log:
PIVOT-852

Added:
    pivot/trunk/core/src/org/apache/pivot/util/Console.java
    pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.bxml
    pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.js
Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java

Added: pivot/trunk/core/src/org/apache/pivot/util/Console.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/Console.java?rev=1331397&view=auto
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/Console.java (added)
+++ pivot/trunk/core/src/org/apache/pivot/util/Console.java Fri Apr 27 12:50:20 2012
@@ -0,0 +1,49 @@
+/*
+ * 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.util;
+
+/**
+ * Utility class for a simple log to the console, for example from scripts.
+ */
+public class Console  {
+
+    private Console() {
+    }
+
+    public static final void log(String message) {
+    	logOutput(message);
+    }
+
+    public static final void log(Throwable t) {
+    	if (t != null) {
+    	    t.printStackTrace();
+        }
+    }
+
+    public static final void logExceptionMessage(Throwable t) {
+    	logOutput(t.getMessage());
+    }
+
+    public static final void logOutput(String message) {
+    	System.out.println(message != null ? message : "");
+    }
+
+    public static final void logError(String message) {
+    	System.err.println(message != null ? message : "");
+    }
+
+}

Added: pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.bxml?rev=1331397&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.bxml (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.bxml Fri Apr 27 12:50:20 2012
@@ -0,0 +1,59 @@
+<?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 title="Scripts diagnostic messages" maximized="true"
+    bxml:id="window"
+    xmlns:bxml="http://pivot.apache.org/bxml"
+    xmlns="org.apache.pivot.wtk"
+>
+    <bxml:script src="scripts_diagnostic_messages.js"/>
+
+    <TablePane styles="{horizontalSpacing:4, verticalSpacing:4}">
+        <columns>
+            <TablePane.Column width="1*"/>
+            <TablePane.Column width="1*"/>
+            <TablePane.Column width="1*"/>
+        </columns>
+
+        <TablePane.Row height="-1">
+            <BoxPane orientation="vertical" styles="{fill:true}">
+                <BoxPane styles="{horizontalAlignment:'center'}">
+                    <Label text="Alerts: "/>
+                    <PushButton buttonData="Alert using .alert" ButtonPressListener.buttonPressed="alert1()"/>
+                    <PushButton buttonData="Alert using constructor" ButtonPressListener.buttonPressed="alert2()"/>
+                </BoxPane>
+            </BoxPane>
+
+            <BoxPane styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
+                    <Label text="Prompts: "/>
+                    <PushButton buttonData="Prompt using .prompt" ButtonPressListener.buttonPressed="prompt1()"/>
+                    <PushButton buttonData="Prompt using constructor" ButtonPressListener.buttonPressed="prompt2()"/>
+            </BoxPane>
+
+            <BoxPane styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
+                    <Label text="Log using System.out/err: "/>
+                    <PushButton buttonData="Log message" ButtonPressListener.buttonPressed="logDirectMessage()"/>
+                    <PushButton buttonData="Log error" ButtonPressListener.buttonPressed="logDirectError()"/>
+                    <Label text=" - "/>
+                    <Label text="Log using Console: "/>
+                    <PushButton buttonData="Log message" ButtonPressListener.buttonPressed="logConsoleMessage()"/>
+                    <PushButton buttonData="Log error" ButtonPressListener.buttonPressed="logConsoleError()"/>
+            </BoxPane>
+        </TablePane.Row>
+    </TablePane>
+</Window>

Added: pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.js
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.js?rev=1331397&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.js (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/scripts_diagnostic_messages.js Fri Apr 27 12:50:20 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+importPackage(java.lang);  // required to use System.out and System.err
+importPackage(org.apache.pivot.util);  // required to use Pivot Utility class Console
+importPackage(org.apache.pivot.wtk);   // required to use Pivot WTK classes
+
+function alert1() {
+	Alert.alert("Alert message", window);
+}
+
+function alert2() {
+	Alert("Alert message").open(window);
+}
+
+function prompt1() {
+	Prompt.prompt("Prompt message", window);
+}
+
+function prompt2() {
+	Prompt("Prompt message").open(window);
+}
+
+function logDirectMessage() {
+	System.out.println("Log message via direct call to System.out");
+}
+
+function logDirectError() {
+	System.err.println("Log error via direct call to System.err");
+}
+
+function logConsoleMessage() {
+	Console.log("Log message via Console");
+}
+
+function logConsoleError() {
+	Console.logError("Log error via Console");
+}
+

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=1331397&r1=1331396&r2=1331397&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 27 12:50:20 2012
@@ -187,6 +187,10 @@ public class Alert extends Dialog {
         this(null, null, null);
     }
 
+    public Alert(String message) {
+        this(null, message, null, true);
+    }
+
     public Alert(MessageType messageType, String message, Sequence<?> options) {
         this(messageType, message, options, true);
     }

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=1331397&r1=1331396&r2=1331397&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 27 12:50:20 2012
@@ -187,6 +187,10 @@ public class Prompt extends Sheet {
         this(null, null, null);
     }
 
+    public Prompt(String message) {
+        this(null, message, null, null);
+    }
+
     public Prompt(MessageType messageType, String message, Sequence<?> options) {
         this(messageType, message, options, null);
     }