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 2011/01/10 00:19:29 UTC
svn commit: r1057053 [10/12] - in /pivot/branches/3.x: ./ core/ core/src/
core/src/org/ core/src/org/apache/ core/src/org/apache/pivot/
core/src/org/apache/pivot/beans/ core/src/org/apache/pivot/bxml/
core/src/org/apache/pivot/csv/ core/src/org/apache/...
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/Stroke.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/Stroke.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/Stroke.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/Stroke.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,173 @@
+/*
+ * 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.scene;
+
+import java.util.Map;
+
+import org.apache.pivot.beans.BeanAdapter;
+import org.apache.pivot.io.SerializationException;
+import org.apache.pivot.json.JSONSerializer;
+
+/**
+ * Class representing a stroke.
+ */
+public class Stroke {
+ /**
+ * Enumeration representing a line cap.
+ */
+ public enum LineCap {
+ BUTT,
+ ROUND,
+ SQUARE
+ }
+
+ /**
+ * Enumeration representing a line join.
+ */
+ public enum LineJoin {
+ ROUND,
+ BEVEL,
+ MITER
+ }
+
+ /**
+ * Enumeration representing a line style.
+ */
+ public enum LineStyle {
+ SOLID,
+ DASHED,
+ DOTTED
+ }
+
+ public final int lineWidth;
+ public final LineCap lineCap;
+ public final LineJoin lineJoin;
+ public final LineStyle lineStyle;
+ public final int miterLimit;
+
+ private Object nativeStroke = null;
+
+ public static final int DEFAULT_LINE_WIDTH = 1;
+ public static final LineCap DEFAULT_LINE_CAP = LineCap.BUTT;
+ public static final LineJoin DEFAULT_LINE_JOIN = LineJoin.MITER;
+ public static final LineStyle DEFAULT_LINE_STYLE = LineStyle.SOLID;
+ public static final int DEFAULT_MITER_LIMIT = 10;
+
+ public static final String LINE_WIDTH_KEY = "lineWidth";
+ public static final String LINE_CAP_KEY = "lineCap";
+ public static final String LINE_JOIN_KEY = "lineJoin";
+ public static final String LINE_STYLE_KEY = "lineStyle";
+ public static final String MITER_LIMIT_KEY = "miterLimit";
+
+ public Stroke() {
+ this(DEFAULT_LINE_WIDTH);
+ }
+
+ public Stroke(int lineWidth) {
+ this(lineWidth, DEFAULT_LINE_CAP, DEFAULT_LINE_JOIN, DEFAULT_LINE_STYLE, DEFAULT_MITER_LIMIT);
+ }
+
+ public Stroke(int lineWidth, LineCap lineCap, LineJoin lineJoin, LineStyle lineStyle, int miterLimit) {
+ this.lineWidth = lineWidth;
+ this.lineCap = lineCap;
+ this.lineJoin = lineJoin;
+ this.lineStyle = lineStyle;
+ this.miterLimit = miterLimit;
+ }
+
+ protected Object getNativeStroke() {
+ if (nativeStroke == null) {
+ nativeStroke = Platform.getPlatform().getNativeStroke(this);
+ }
+
+ return nativeStroke;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ boolean equals = false;
+
+ if (object instanceof Stroke) {
+ Stroke stroke = (Stroke)object;
+ equals = (lineWidth == stroke.lineWidth
+ && lineCap == stroke.lineCap
+ && lineJoin == stroke.lineJoin
+ && miterLimit == stroke.miterLimit);
+ }
+
+ return equals;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + lineWidth;
+ result = prime * result + lineCap.ordinal();
+ result = prime * result + lineJoin.ordinal();
+ result = prime * result + miterLimit;
+
+ return result;
+ }
+
+ public static Stroke decode(String value) {
+ if (value == null) {
+ throw new IllegalArgumentException();
+ }
+
+ Stroke stroke;
+ if (value.startsWith("{")) {
+ Map<String, ?> map;
+ try {
+ map = JSONSerializer.parseMap(value);
+ } catch (SerializationException exception) {
+ throw new IllegalArgumentException(exception);
+ }
+
+ int lineWidth = DEFAULT_LINE_WIDTH;
+ if (map.containsKey(LINE_WIDTH_KEY)) {
+ lineWidth = BeanAdapter.getInt(map, LINE_WIDTH_KEY);
+ }
+
+ LineCap lineCap = DEFAULT_LINE_CAP;
+ if (map.containsKey(LINE_CAP_KEY)) {
+ lineCap = BeanAdapter.get(map, LINE_CAP_KEY);
+ }
+
+ LineJoin lineJoin = DEFAULT_LINE_JOIN;
+ if (map.containsKey(LINE_JOIN_KEY)) {
+ lineJoin = BeanAdapter.get(map, LINE_JOIN_KEY);
+ }
+
+ LineStyle lineStyle = DEFAULT_LINE_STYLE;
+ if (map.containsKey(LINE_STYLE_KEY)) {
+ lineStyle = BeanAdapter.get(map, LINE_STYLE_KEY);
+ }
+
+ int miterLimit = DEFAULT_MITER_LIMIT;
+ if (map.containsKey(MITER_LIMIT_KEY)) {
+ miterLimit = BeanAdapter.getInt(map, MITER_LIMIT_KEY);
+ }
+
+ stroke = new Stroke(lineWidth, lineCap, lineJoin, lineStyle, miterLimit);
+ } else {
+ stroke = new Stroke(Integer.parseInt(value));
+ }
+
+ return stroke;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/Transform.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/Transform.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/Transform.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/Transform.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,71 @@
+/*
+ * 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.scene;
+
+/**
+ * Class representing an affine transform.
+ */
+public class Transform {
+ public final float m11;
+ public final float m12;
+ public final float m21;
+ public final float m22;
+ public final float dx;
+ public final float dy;
+
+ public Transform(float m11, float m12, float m21, float m22, float dx, float dy) {
+ this.m11 = m11;
+ this.m12 = m12;
+ this.m21 = m21;
+ this.m22 = m22;
+
+ this.dx = dx;
+ this.dy = dy;
+ }
+
+ public Transform scale(float x, float y) {
+ // TODO
+ return null;
+ }
+
+ public Transform rotate(float angle) {
+ // TODO
+ return null;
+ }
+
+ public Transform translate(float x, float y) {
+ // TODO
+ return null;
+ }
+
+ public boolean isIdentity() {
+ // TODO
+ return true;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ // TODO
+ return super.equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ // TODO
+ return super.hashCode();
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/VerticalAlignment.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/VerticalAlignment.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/VerticalAlignment.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/VerticalAlignment.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,37 @@
+/*
+ * 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.scene;
+
+/**
+ * Enumeration representing vertical alignment values.
+ */
+public enum VerticalAlignment {
+ /**
+ * Align to top.
+ */
+ TOP,
+
+ /**
+ * Align to bottom.
+ */
+ BOTTOM,
+
+ /**
+ * Align to center.
+ */
+ CENTER
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/Visual.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/Visual.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/Visual.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/Visual.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.scene;
+
+/**
+ * Interface representing an object that can be drawn to the screen or
+ * other output device.
+ */
+public interface Visual {
+ /**
+ * Returns the visual's width.
+ */
+ public int getWidth();
+
+ /**
+ * Returns the visual's height.
+ */
+ public int getHeight();
+
+ /**
+ * Sets the visual's size.
+ *
+ * @param width
+ * @param height
+ */
+ public void setSize(int width, int height);
+
+ /**
+ * Returns the visual's preferred width given the provided height
+ * constraint.
+ *
+ * @param height
+ * The height by which to constrain the preferred width, or <tt>-1</tt>
+ * for no constraint.
+ */
+ public int getPreferredWidth(int height);
+
+ /**
+ * Returns the visual's preferred height given the provided width
+ * constraint.
+ *
+ * @param width
+ * The width by which to constrain the preferred height, or <tt>-1</tt>
+ * for no constraint.
+ */
+ public int getPreferredHeight(int width);
+
+ /**
+ * Returns the baseline for a given width and height.
+ *
+ * @param width
+ * @param height
+ *
+ * @return
+ * The baseline relative to the origin of this visual, or <tt>-1</tt> if
+ * this visual does not have a baseline.
+ */
+ public int getBaseline(int width, int height);
+
+ /**
+ * Paints the visual.
+ *
+ * @param graphics
+ * The graphics context in which to paint the visual.
+ */
+ public void paint(Graphics graphics);
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/CircularEasing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/CircularEasing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/CircularEasing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/CircularEasing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Circular easing operation.
+ */
+public class CircularEasing implements Easing {
+ public float easeIn(float time, float begin, float change, float duration) {
+ return -change * ((float)Math.sqrt(1f - (time /= duration) * time) - 1f) + begin;
+ }
+
+ public float easeOut(float time, float begin, float change, float duration) {
+ return change * (float)Math.sqrt(1f - (time = time / duration - 1f) * time) + begin;
+ }
+
+ public float easeInOut(float time, float begin, float change, float duration) {
+ if ((time /= duration / 2f) < 1f) {
+ return -change / 2f * ((float)Math.sqrt(1f - time * time) - 1f) + begin;
+ }
+
+ return change / 2f * ((float)Math.sqrt(1f - (time -= 2f) * time) + 1f) + begin;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/CubicEasing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/CubicEasing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/CubicEasing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/CubicEasing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Cubic easing operation.
+ */
+public class CubicEasing implements Easing {
+ public float easeIn(float time, float begin, float change, float duration) {
+ return change * (time /= duration) * time * time + begin;
+ }
+
+ public float easeOut(float time, float begin, float change, float duration) {
+ return change * ((time = time / duration - 1f) * time * time + 1f) + begin;
+ }
+
+ public float easeInOut(float time, float begin, float change, float duration) {
+ if ((time /= duration / 2f) < 1f) {
+ return change / 2f * time * time * time + begin;
+ }
+
+ return change / 2f * ((time -= 2f) * time * time + 2f) + begin;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/Easing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/Easing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/Easing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/Easing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,26 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Base interface for easing operations.
+ */
+public interface Easing {
+ public float easeIn(float time, float begin, float change, float duration);
+ public float easeOut(float time, float begin, float change, float duration);
+ public float easeInOut(float time, float begin, float change, float duration);
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/ExponentialEasing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/ExponentialEasing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/ExponentialEasing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/ExponentialEasing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,48 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Exponential easing operation.
+ */
+public class ExponentialEasing implements Easing {
+ public float easeIn(float time, float begin, float change, float duration) {
+ return (time == 0) ? begin
+ : change * (float)Math.pow(2, 10 * (time / duration - 1f)) + begin;
+ }
+
+ public float easeOut(float time, float begin, float change, float duration) {
+ return (time == duration) ? begin + change
+ : change * ((float)-Math.pow(2, -10 * time / duration) + 1f) + begin;
+ }
+
+ public float easeInOut(float time, float begin, float change, float duration) {
+ if (time == 0) {
+ return begin;
+ }
+
+ if (time == duration) {
+ return begin + change;
+ }
+
+ if ((time /= duration / 2f) < 1) {
+ return change / 2f * (float)Math.pow(2, 10 * (time - 1)) + begin;
+ }
+
+ return change / 2f * ((float)-Math.pow(2, -10 * (time - 1)) + 2) + begin;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/LinearEasing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/LinearEasing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/LinearEasing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/LinearEasing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Linear easing operation.
+ */
+public class LinearEasing implements Easing {
+ public float easeIn(float time, float begin, float change, float duration) {
+ return change * time / duration + begin;
+ }
+
+ public float easeOut(float time, float begin, float change, float duration) {
+ return change * time / duration + begin;
+ }
+
+ public float easeInOut(float time, float begin, float change, float duration) {
+ return change * time / duration + begin;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuadraticEasing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuadraticEasing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuadraticEasing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuadraticEasing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Quadratic easing operation.
+ */
+public class QuadraticEasing implements Easing {
+ public float easeIn(float time, float begin, float change, float duration) {
+ return change * (time /= duration) * time + begin;
+ }
+
+ public float easeOut(float time, float begin, float change, float duration) {
+ return -change * (time /= duration) * (time - 2) + begin;
+ }
+
+ public float easeInOut(float time, float begin, float change, float duration) {
+ if ((time /= duration / 2) < 1) {
+ return change / 2 * time * time + begin;
+ }
+
+ return -change / 2 * ((--time) * (time - 2) - 1) + begin;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuarticEasing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuarticEasing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuarticEasing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuarticEasing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Quartic easing operation.
+ */
+public class QuarticEasing implements Easing {
+ public float easeIn(float time, float begin, float change, float duration) {
+ return change * (time /= duration) * time * time * time + begin;
+ }
+
+ public float easeOut(float time, float begin, float change, float duration) {
+ return -change * ((time = time / duration - 1) * time * time * time - 1) + begin;
+ }
+
+ public float easeInOut(float time, float begin, float change, float duration) {
+ if ((time /= duration / 2f) < 1) {
+ return change / 2f * time * time * time * time + begin;
+ }
+
+ return -change / 2f * ((time -= 2) * time * time * time - 2) + begin;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuinticEasing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuinticEasing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuinticEasing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/QuinticEasing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Quintic easing operation.
+ */
+public class QuinticEasing implements Easing {
+ public float easeIn(float time, float begin, float change, float duration) {
+ return change * (time /= duration) * time * time * time * time + begin;
+ }
+
+ public float easeOut(float time, float begin, float change, float duration) {
+ return change * ((time = time / duration - 1) * time * time * time * time + 1) + begin;
+ }
+
+ public float easeInOut(float time, float begin, float change, float duration) {
+ if ((time /= duration / 2f) < 1) {
+ return change / 2f * time * time * time * time * time + begin;
+ }
+
+ return change / 2f * ((time -= 2) * time * time * time * time + 2) + begin;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/SineEasing.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/SineEasing.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/SineEasing.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/SineEasing.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Easing operation based on a sine curve.
+ */
+public class SineEasing implements Easing {
+ public float easeIn(float time, float begin, float change, float duration) {
+ return -change * (float)Math.cos(time / duration * (Math.PI/2)) + change + begin;
+ }
+
+ public float easeOut(float time, float begin, float change, float duration) {
+ return change * (float)Math.sin(time / duration * (Math.PI/2)) + begin;
+ }
+
+ public float easeInOut(float time, float begin, float change, float duration) {
+ return -change / 2f * (float)(Math.cos(Math.PI * time / duration) - 1) + begin;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/Transition.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/Transition.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/Transition.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/Transition.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,442 @@
+/*
+ * 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.scene.animation;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * Class for scheduling "transitions", which are generally used for animated
+ * application effects.
+ */
+public class Transition {
+ private class ScheduledCallback extends TimerTask {
+ private Runnable callback = new Runnable() {
+ @Override
+ public void run() {
+ currentTime = System.currentTimeMillis();
+
+ long endTime = startTime + duration;
+ if (currentTime >= endTime) {
+ if (repeating) {
+ startTime = endTime;
+ } else {
+ currentTime = endTime;
+ stop();
+
+ if (transitionListener != null) {
+ transitionListener.transitionCompleted(Transition.this);
+ }
+ }
+ }
+
+ updateCallback.run();
+ }
+ };
+
+ private QueuedCallback queuedCallback = null;
+
+ @Override
+ public void run() {
+ if (queuedCallback != null) {
+ queuedCallback.cancel();
+ }
+
+ QueuedCallback queuedCallback = new QueuedCallback(callback);
+ java.awt.EventQueue.invokeLater(queuedCallback);
+ }
+
+ @Override
+ public boolean cancel() {
+ if (queuedCallback != null) {
+ queuedCallback.cancel();
+ }
+
+ return super.cancel();
+ }
+ }
+
+ private static class QueuedCallback implements Runnable {
+ private Runnable callback;
+ private volatile boolean executed = false;
+ private volatile boolean cancelled = false;
+
+ private QueuedCallback(Runnable callback) {
+ this.callback = callback;
+ }
+
+ public void run() {
+ if (!cancelled) {
+ try {
+ callback.run();
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+
+ executed = true;
+ }
+ }
+
+ public boolean cancel() {
+ cancelled = true;
+ return (!executed);
+ }
+ }
+
+ private int duration;
+ private int rate;
+ private boolean repeating;
+
+ private boolean reversed = false;
+
+ private TransitionListener transitionListener;
+
+ private long startTime = 0;
+ private long currentTime = 0;
+
+ private Runnable updateCallback = null;
+ private ScheduledCallback scheduledCallback = null;
+
+ private static Timer timer = new Timer();
+
+ /**
+ * Creates a new non-repeating transition with the given duration and
+ * rate.
+ *
+ * @param duration
+ * Transition duration, in milliseconds.
+ *
+ * @param rate
+ * Transition rate, in frames per second.
+ */
+ public Transition(int duration, int rate) {
+ this(duration, rate, false);
+ }
+
+ /**
+ * Creates a new transition with the given duration, rate, and repeat.
+ *
+ * @param duration
+ * Transition duration, in milliseconds.
+ *
+ * @param rate
+ * Transition rate, in frames per second.
+ *
+ * @param repeating
+ * <tt>true</tt> if the transition should repeat; <tt>false</tt>, otherwise.
+ */
+ public Transition(int duration, int rate, boolean repeating) {
+ this(duration, rate, repeating, false);
+ }
+
+ /**
+ * Creates a new transition with the given duration, rate, and repeat.
+ *
+ * @param duration
+ * Transition duration, in milliseconds.
+ *
+ * @param rate
+ * Transition rate, in frames per second.
+ *
+ * @param repeating
+ * <tt>true</tt> if the transition should repeat; <tt>false</tt>, otherwise.
+ *
+ * @param reversed
+ * <tt>true</tt> if the transition should run in reverse; <tt>false</tt>
+ * otherwise.
+ */
+ public Transition(int duration, int rate, boolean repeating, boolean reversed) {
+ if (duration <= 0) {
+ throw new IllegalArgumentException("duration must be positive.");
+ }
+
+ this.duration = duration;
+ this.rate = rate;
+ this.repeating = repeating;
+ this.reversed = reversed;
+ }
+
+ /**
+ * Returns the transition duration.
+ *
+ * @return
+ * The duration of the transition, in milliseconds.
+ *
+ * @see #setDuration(int)
+ */
+ public int getDuration() {
+ return duration;
+ }
+
+ /**
+ * Sets the transition duration, the length of time the transition is
+ * scheduled to run.
+ *
+ * @param duration
+ * The duration of the transition, in milliseconds.
+ */
+ public void setDuration(int duration) {
+ if (duration < 0) {
+ throw new IllegalArgumentException("duration is negative.");
+ }
+
+ if (scheduledCallback != null) {
+ throw new IllegalStateException("Transition is currently running.");
+ }
+
+ this.duration = duration;
+ }
+
+ /**
+ * Returns the transition rate.
+ *
+ * @return
+ * The rate of the transition, in frames per second.
+ *
+ * @see #setRate(int)
+ */
+ public int getRate() {
+ return rate;
+ }
+
+ /**
+ * Sets the transition rate, the number of times the transition will be
+ * updated within the span of one second.
+ *
+ * @param rate
+ * The transition rate, in frames per second.
+ */
+ public void setRate(int rate) {
+ if (rate < 0) {
+ throw new IllegalArgumentException("rate is negative.");
+ }
+
+ if (scheduledCallback != null) {
+ throw new IllegalStateException("Transition is currently running.");
+ }
+
+ this.rate = rate;
+ }
+
+ /**
+ * Returns the transition interval, the number of milliseconds between
+ * updates.
+ *
+ * @return
+ * The transition interval, in milliseconds.
+ */
+ public int getInterval() {
+ return (int)((1f / rate) * 1000);
+ }
+
+ /**
+ * Returns the time at which the transition was started.
+ *
+ * @return
+ * The transition's start time.
+ */
+ public long getStartTime() {
+ return startTime;
+ }
+
+ /**
+ * Returns the last time the transition was updated.
+ *
+ * @return
+ * The most recent update time.
+ */
+ public long getCurrentTime() {
+ return currentTime;
+ }
+
+ /**
+ * Returns the elapsed time since the transition started.
+ *
+ * @return
+ * Returns the amount of time that has passed since the transition
+ * was started. If the transition is reversed, this value reflects the
+ * amount of time remaining.
+ */
+ public int getElapsedTime() {
+ long endTime = startTime + duration;
+
+ int elapsedTime;
+ if (reversed) {
+ elapsedTime = (int)(endTime - currentTime);
+ } else {
+ elapsedTime = (int)(currentTime - startTime);
+ }
+
+ return elapsedTime;
+ }
+
+ /**
+ * Returns the percentage of the transition that has completed.
+ *
+ * @return
+ * A value between 0 and 1, inclusive, representing the transition's
+ * percent complete. If the transition is reversed, this value reflects
+ * the percent remaining.
+ */
+ public float getPercentComplete() {
+ float percentComplete = (float)(currentTime - startTime) / (float)(duration);
+
+ if (reversed) {
+ percentComplete = 1.0f - percentComplete;
+ }
+
+ return percentComplete;
+ }
+
+ /**
+ * Tells whether or not the transition is currently running.
+ *
+ * @return
+ * <tt>true</tt> if the transition is currently running; <tt>false</tt> if
+ * it is not
+ */
+ public boolean isRunning() {
+ return (scheduledCallback != null);
+ }
+
+ /**
+ * Starts the transition with no listener.
+ *
+ * @param updateCallback
+ *
+ * @see #start(Runnable, TransitionListener)
+ */
+ public final void start(Runnable updateCallback) {
+ start(updateCallback, null);
+ }
+
+ /**
+ * Starts the transition. Calls {@link #update()} to establish the
+ * initial state and starts a timer that will repeatedly call
+ * {@link #update()} at the current rate. The specified
+ * <tt>TransitionListener</tt> will be notified when the transition
+ * completes.
+ *
+ * @param updateCallback
+ * A callback that will be invoked to update the transition state.
+ *
+ * @param transitionListener
+ * The listener to get notified when the transition completes, or
+ * <tt>null</tt> if no notification is necessary
+ */
+ public void start(Runnable updateCallback, TransitionListener transitionListener) {
+ if (updateCallback == null) {
+ throw new IllegalArgumentException();
+ }
+
+ if (this.updateCallback != null) {
+ throw new IllegalStateException("Transition is currently running.");
+ }
+
+ this.updateCallback = updateCallback;
+ this.transitionListener = transitionListener;
+
+ startTime = System.currentTimeMillis();
+ currentTime = startTime;
+
+ scheduledCallback = new ScheduledCallback();
+
+ // TODO This is a workaround for a potential OS X bug; revisit
+ try {
+ try {
+ timer.schedule(scheduledCallback, 0, getInterval());
+ } catch (IllegalStateException exception) {
+ timer = new Timer();
+ timer.schedule(scheduledCallback, 0, getInterval());
+ }
+ } catch (Throwable throwable) {
+ System.err.println("Unable to schedule callback: " + throwable);
+ }
+
+ updateCallback.run();
+ }
+
+ /**
+ * Stops the transition. Does not fire a
+ * {@link TransitionListener#transitionCompleted(Transition)} event.
+ */
+ public void stop() {
+ if (scheduledCallback != null) {
+ scheduledCallback.cancel();
+ }
+
+ scheduledCallback = null;
+ }
+
+ /**
+ * "Fast-forwards" to the end of the transition and fires a
+ * {@link TransitionListener#transitionCompleted(Transition)} event.
+ */
+ public void end() {
+ if (scheduledCallback != null) {
+ currentTime = startTime + duration;
+ stop();
+ updateCallback.run();
+ transitionListener.transitionCompleted(this);
+ }
+ }
+
+ public boolean isRepeating() {
+ return repeating;
+ }
+
+ /**
+ * Reverses the transition with no listener.
+ *
+ * @see #reverse(TransitionListener)
+ */
+ public void reverse() {
+ reverse(null);
+ }
+
+ /**
+ * Reverses the transition. Updates the start time so the reverse duration
+ * is the same as the current elapsed time.
+ *
+ * @param transitionListener
+ * The listener to get notified when the transition completes, or
+ * <tt>null</tt> if no notification is necessary
+ */
+ public void reverse(TransitionListener transitionListener) {
+ if (this.updateCallback == null) {
+ throw new IllegalStateException("Transition is not currently running.");
+ }
+
+ this.transitionListener = transitionListener;
+
+ long repeatDuration = currentTime - startTime;
+ long endTime = currentTime + repeatDuration;
+ startTime = endTime - duration;
+
+ reversed = !reversed;
+ }
+
+ /**
+ * Tests whether the transition is reversed.
+ *
+ * @return
+ * <tt>true</tt> if the transition is reversed; <tt>false</tt>, otherwise.
+ */
+ public boolean isReversed() {
+ return reversed;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/TransitionListener.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/TransitionListener.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/TransitionListener.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/animation/TransitionListener.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,29 @@
+/*
+ * 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.scene.animation;
+
+/**
+ * Transition listener interface.
+ */
+public interface TransitionListener {
+ /**
+ * Called when a transition has completed.
+ *
+ * @param transition
+ */
+ public void transitionCompleted(Transition transition);
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/Clipboard.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/Clipboard.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/Clipboard.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/Clipboard.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,94 @@
+/*
+ * 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.scene.data;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.ClipboardOwner;
+import java.awt.datatransfer.Transferable;
+
+/**
+ * Singleton class providing a means of sharing data between components and
+ * applications.
+ */
+public final class Clipboard {
+ private static LocalManifest content = null;
+ private static ClipboardContentListener clipboardContentListener = null;
+
+ /**
+ * Retrieves the contents of the clipboard.
+ */
+ public static Manifest getContent() {
+ Manifest content = Clipboard.content;
+
+ if (content == null) {
+ try {
+ java.awt.datatransfer.Clipboard awtClipboard =
+ Toolkit.getDefaultToolkit().getSystemClipboard();
+ content = new RemoteManifest(awtClipboard.getContents(null));
+ } catch(SecurityException exception) {
+ // No-op
+ }
+ }
+
+ return content;
+ }
+
+ /**
+ * Places content on the clipboard.
+ *
+ * @param content
+ */
+ public static void setContent(LocalManifest content) {
+ setContent(content, null);
+ }
+
+ /**
+ * Places content on the clipboard.
+ *
+ * @param content
+ */
+ public static void setContent(LocalManifest content,
+ ClipboardContentListener clipboardContentListener) {
+ if (content == null) {
+ throw new IllegalArgumentException("content is null");
+ }
+
+ try {
+ java.awt.datatransfer.Clipboard awtClipboard =
+ Toolkit.getDefaultToolkit().getSystemClipboard();
+
+ LocalManifestAdapter localManifestAdapter = new LocalManifestAdapter(content);
+ awtClipboard.setContents(localManifestAdapter, new ClipboardOwner() {
+ @Override
+ public void lostOwnership(java.awt.datatransfer.Clipboard clipboard,
+ Transferable contents) {
+ LocalManifest previousContent = Clipboard.content;
+ Clipboard.content = null;
+
+ if (Clipboard.clipboardContentListener != null) {
+ Clipboard.clipboardContentListener.contentChanged(previousContent);
+ }
+ }
+ });
+ } catch(SecurityException exception) {
+ // No-op
+ }
+
+ Clipboard.content = content;
+ Clipboard.clipboardContentListener = clipboardContentListener;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/ClipboardContentListener.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/ClipboardContentListener.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/ClipboardContentListener.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/ClipboardContentListener.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,29 @@
+/*
+ * 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.scene.data;
+
+/**
+ * Clipboard content listener interface.
+ */
+public interface ClipboardContentListener {
+ /**
+ * Called when the clipboard content has changed.
+ *
+ * @param previousContent
+ */
+ public void contentChanged(LocalManifest previousContent);
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/DropAction.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/DropAction.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/DropAction.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/DropAction.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.scene.data;
+
+/**
+ * Enumeration defining supported drop actions.
+ */
+public enum DropAction {
+ COPY,
+ MOVE,
+ LINK;
+
+ public int getMask() {
+ return 1 << ordinal();
+ }
+
+ public boolean isSelected(int dropActions) {
+ return ((dropActions & getMask()) > 0);
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/LocalManifest.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/LocalManifest.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/LocalManifest.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/LocalManifest.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,162 @@
+/*
+ * 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.scene.data;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.pivot.scene.media.Image;
+
+/**
+ * Manifest class that serves as data source for a clipboard or drag/drop
+ * operation.
+ */
+public class LocalManifest implements Manifest {
+ private String text = null;
+ private Image image = null;
+ private List<File> fileList = null;
+
+ @Override
+ public String getText() {
+ return text;
+ }
+
+ public void putText(String text) {
+ if (text == null) {
+ throw new IllegalArgumentException("text is null.");
+ }
+
+ this.text = text;
+ }
+
+ @Override
+ public boolean containsText() {
+ return (text != null);
+ }
+
+ @Override
+ public Image getImage() {
+ return image;
+ }
+
+ public void putImage(Image image) {
+ if (image == null) {
+ throw new IllegalArgumentException("image is null.");
+ }
+
+ this.image = image;
+ }
+
+ @Override
+ public boolean containsImage() {
+ return image != null;
+ }
+
+ @Override
+ public List<File> getFileList() {
+ return fileList;
+ }
+
+ public void putFileList(List<File> fileList) {
+ if (fileList == null) {
+ throw new IllegalArgumentException("fileList is null.");
+ }
+
+ this.fileList = fileList;
+ }
+
+ @Override
+ public boolean containsFileList() {
+ return fileList != null;
+ }
+}
+
+class LocalManifestAdapter implements Transferable {
+ private LocalManifest localManifest;
+ private ArrayList<DataFlavor> transferDataFlavors = new ArrayList<DataFlavor>();
+
+ private static final String URI_LIST_MIME_TYPE = "text/uri-list; class=java.lang.String";
+
+ public LocalManifestAdapter(LocalManifest localManifest) {
+ this.localManifest = localManifest;
+
+ if (localManifest.containsText()) {
+ transferDataFlavors.add(DataFlavor.stringFlavor);
+ }
+
+ if (localManifest.containsImage()) {
+ transferDataFlavors.add(DataFlavor.imageFlavor);
+ }
+
+ if (localManifest.containsFileList()) {
+ transferDataFlavors.add(DataFlavor.javaFileListFlavor);
+
+ try {
+ transferDataFlavors.add(new DataFlavor(URI_LIST_MIME_TYPE));
+ } catch (ClassNotFoundException exception) {
+ // No-op
+ }
+ }
+ }
+
+ @Override
+ public Object getTransferData(DataFlavor dataFlavor)
+ throws UnsupportedFlavorException {
+ Object transferData = null;
+
+ int index = transferDataFlavors.indexOf(dataFlavor);
+ if (index == -1) {
+ throw new UnsupportedFlavorException(dataFlavor);
+ }
+
+ if (dataFlavor.equals(DataFlavor.stringFlavor)) {
+ transferData = localManifest.getText();
+ } else if (dataFlavor.equals(DataFlavor.imageFlavor)) {
+ transferData = localManifest.getImage();
+ } else if (dataFlavor.equals(DataFlavor.javaFileListFlavor)) {
+ transferData = localManifest.getFileList();
+ } else if (dataFlavor.getMimeType().equals(URI_LIST_MIME_TYPE)) {
+ List<File> fileList = localManifest.getFileList();
+
+ StringBuilder buf = new StringBuilder();
+ for (File file : fileList) {
+ buf.append(file.toURI().toString()).append("\r\n");
+ }
+
+ transferData = buf.toString();
+ }
+
+ return transferData;
+ }
+
+ @Override
+ public DataFlavor[] getTransferDataFlavors() {
+ DataFlavor[] transferDataFlavors = new DataFlavor[this.transferDataFlavors.size()];
+ this.transferDataFlavors.toArray(transferDataFlavors);
+
+ return transferDataFlavors;
+ }
+
+ @Override
+ public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
+ return (transferDataFlavors.indexOf(dataFlavor) != -1);
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/Manifest.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/Manifest.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/Manifest.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/Manifest.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.scene.data;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pivot.scene.media.Image;
+
+/**
+ * Interface representing a "manifest". Manifests are collections of data used
+ * in clipboard and drag/drop operations.
+ */
+public interface Manifest {
+ public String getText() throws IOException;
+ public boolean containsText();
+
+ public Image getImage() throws IOException;
+ public boolean containsImage();
+
+ public List<File> getFileList() throws IOException;
+ public boolean containsFileList();
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/RemoteManifest.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/RemoteManifest.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/RemoteManifest.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/data/RemoteManifest.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,153 @@
+/*
+ * 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.scene.data;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.File;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.pivot.scene.media.Image;
+
+/**
+ * Manifest class that acts as a proxy to remote clipboard or drag/drop data.
+ * <p>
+ * TODO How to make this platform-independent?
+ */
+public class RemoteManifest implements Manifest {
+ private Transferable transferable;
+
+ private DataFlavor textDataFlavor = null;
+ private DataFlavor imageDataFlavor = null;
+ private DataFlavor fileListDataFlavor = null;
+ private DataFlavor uriListDataFlavor = null;
+
+ private static final String URI_LIST_MIME_TYPE = "text/uri-list";
+ private static final String FILE_URI_SCHEME = "file";
+
+ RemoteManifest(Transferable transferable) {
+ assert(transferable != null);
+ this.transferable = transferable;
+
+ DataFlavor[] transferDataFlavors = transferable.getTransferDataFlavors();
+ if (transferDataFlavors != null) {
+ for (int i = 0, n = transferDataFlavors.length; i < n; i++) {
+ DataFlavor dataFlavor = transferDataFlavors[i];
+
+ if (dataFlavor.equals(DataFlavor.stringFlavor)) {
+ textDataFlavor = dataFlavor;
+ } else if (dataFlavor.equals(DataFlavor.imageFlavor)) {
+ imageDataFlavor = dataFlavor;
+ } else if (dataFlavor.equals(DataFlavor.javaFileListFlavor)) {
+ fileListDataFlavor = dataFlavor;
+ } else if (dataFlavor.getMimeType().startsWith(URI_LIST_MIME_TYPE)
+ && dataFlavor.getRepresentationClass() == String.class) {
+ uriListDataFlavor = dataFlavor;
+ }
+ }
+ }
+ }
+
+ @Override
+ public String getText() throws IOException {
+ String text = null;
+ try {
+ text = (String)transferable.getTransferData(textDataFlavor);
+ } catch (UnsupportedFlavorException exception) {
+ // No-op
+ }
+
+ return text;
+ }
+
+ @Override
+ public boolean containsText() {
+ return (textDataFlavor != null);
+ }
+
+ @Override
+ public Image getImage() throws IOException {
+ Image image = null;
+
+ // TODO
+ /*
+ try {
+ image = new Image((BufferedImage)transferable.getTransferData(imageDataFlavor));
+ } catch (UnsupportedFlavorException exception) {
+ // No-op
+ }
+ */
+
+ return image;
+ }
+
+ @Override
+ public boolean containsImage() {
+ return (imageDataFlavor != null);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public List<File> getFileList() throws IOException {
+ List<File> fileList = null;
+
+ try {
+ if (fileListDataFlavor != null) {
+ fileList = (java.util.List<File>)transferable.getTransferData(fileListDataFlavor);
+ } else if (uriListDataFlavor != null) {
+ fileList = new ArrayList<File>();
+
+ String uriList = (String)transferable.getTransferData(uriListDataFlavor);
+ LineNumberReader reader = new LineNumberReader(new StringReader(uriList));
+
+ try {
+ String line = reader.readLine();
+ while (line != null) {
+ URI uri = new URI(line);
+ String scheme = uri.getScheme();
+
+ if (scheme != null
+ && scheme.equalsIgnoreCase(FILE_URI_SCHEME)) {
+ File file = new File(uri);
+ fileList.add(file);
+ }
+
+ line = reader.readLine();
+ }
+ } catch (URISyntaxException exception) {
+ // No-op
+ }
+ }
+ } catch (UnsupportedFlavorException exception) {
+ // No-op
+ }
+
+ return fileList;
+ }
+
+ @Override
+ public boolean containsFileList() {
+ return (fileListDataFlavor != null || uriListDataFlavor != null);
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/effect/Decorator.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/effect/Decorator.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/effect/Decorator.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/effect/Decorator.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.scene.effect;
+
+import org.apache.pivot.scene.Extents;
+import org.apache.pivot.scene.Graphics;
+import org.apache.pivot.scene.Node;
+import org.apache.pivot.scene.Transform;
+
+/**
+ * Interface defining a "decorator". Decorators allow a caller to attach
+ * additional rendering behaviors to a node.
+ * <p>
+ * Decorators use a chained prepare/update model to modify the graphics in
+ * which a node is painted. The <tt>prepare()</tt> method of each decorator
+ * in a node's decorator sequence is called in reverse order before the
+ * node's <tt>paint()</tt> method is called. <tt>prepare()</tt> returns
+ * an instance of {@link Graphics} that is passed to prior decorators,
+ * and ultimately to the node itself. This allows decorators to modify the
+ * graphics context before it reaches the node. After the node has
+ * been painted, each decorator's <tt>update()</tt> method is then called in
+ * order to allow the decorator to further modify the resulting output.
+ */
+public interface Decorator {
+ /**
+ * Prepares the graphics context into which the node or prior
+ * decorator will paint. This method is called immediately prior to
+ * {@link Node#paint(Graphics)}; decorators are called in
+ * descending order.
+ *
+ * @param node
+ * @param graphics
+ *
+ * @return
+ * The graphics context that should be used by the node or prior
+ * decorators.
+ */
+ public Graphics prepare(Node node, Graphics graphics);
+
+ /**
+ * Updates the graphics context into which the node or prior
+ * decorator was painted. This method is called immediately after
+ * {@link Node#paint(Graphics)}; decorators are called in
+ * ascending order.
+ */
+ public void update();
+
+ /**
+ * Returns the extents of the decorator.
+ *
+ * @param node
+ *
+ * @return
+ * The decorator's extents, relative to the nodes's origin.
+ */
+ public Extents getExtents(Node node);
+
+ /**
+ * Returns the transformation the decorator applies to the node's
+ * coordinate space.
+ *
+ * @return
+ * The decorator's transform.
+ */
+ public Transform getTransform(Node node);
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/effect/MaskDecorator.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/effect/MaskDecorator.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/effect/MaskDecorator.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/effect/MaskDecorator.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.scene.effect;
+
+import org.apache.pivot.scene.Extents;
+import org.apache.pivot.scene.Graphics;
+import org.apache.pivot.scene.Node;
+import org.apache.pivot.scene.Transform;
+
+/**
+ * Decorator that applies a mask shape to a node.
+ */
+public class MaskDecorator implements Decorator {
+ private Node mask;
+
+ public MaskDecorator(Node mask) {
+ if (mask == null) {
+ throw new IllegalArgumentException("mask is null.");
+ }
+
+ this.mask = mask;
+ }
+
+ public Node getMask() {
+ return mask;
+ }
+
+ @Override
+ public Graphics prepare(Node node, Graphics graphics) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void update() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Extents getExtents(Node node) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Transform getTransform(Node node) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/Image.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/Image.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/Image.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/Image.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,105 @@
+/*
+ * 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.scene.media;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.pivot.scene.Extents;
+import org.apache.pivot.scene.Graphics;
+import org.apache.pivot.scene.Node;
+import org.apache.pivot.scene.Platform;
+
+/**
+ * Node encapsulating a raster.
+ */
+public class Image extends Node {
+ private Raster raster;
+
+ public Image() {
+ this(null);
+ }
+
+ public Image(Raster raster) {
+ this.raster = raster;
+ }
+
+ public Raster getRaster() {
+ return raster;
+ }
+
+ public void setRaster(Raster raster) {
+ this.raster = raster;
+ }
+
+ public void setRaster(URL location) throws IOException {
+ setRaster(location.openStream());
+ }
+
+ public void setRaster(InputStream inputStream) throws IOException {
+ setRaster(Platform.getPlatform().readRaster(inputStream));
+ }
+
+ @Override
+ public Extents getExtents() {
+ // TODO
+ return null;
+ }
+
+ @Override
+ public boolean contains(int x, int y) {
+ // TODO
+ return false;
+ }
+
+ @Override
+ public boolean isFocusable() {
+ return false;
+ }
+
+ @Override
+ public int getPreferredWidth(int height) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int getPreferredHeight(int width) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int getBaseline(int width, int height) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void layout() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void paint(Graphics graphics) {
+ // TODO Auto-generated method stub
+ }
+
+ // TODO Add resample() methods here as well as in Platform
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/Raster.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/Raster.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/Raster.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/Raster.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.scene.media;
+
+import org.apache.pivot.scene.Color;
+import org.apache.pivot.scene.Graphics;
+
+/**
+ * Abstract base class for classes that represent raster image data.
+ */
+public abstract class Raster {
+ public abstract int getWidth();
+ public abstract int getHeight();
+
+ public abstract Color getPixel(int x, int y);
+ public abstract void setPixel(int x, int y, Color color);
+
+ public abstract Graphics getGraphics();
+
+ public abstract Object getNativeRaster();
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/RasterSerializer.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/RasterSerializer.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/RasterSerializer.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/media/RasterSerializer.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,94 @@
+package org.apache.pivot.scene.media;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.pivot.io.SerializationException;
+import org.apache.pivot.io.Serializer;
+import org.apache.pivot.scene.Platform;
+
+public class RasterSerializer implements Serializer<Raster> {
+ /**
+ * Supported image formats.
+ */
+ public enum Format {
+ PNG("png", "image/png"),
+ JPEG("jpeg", "image/jpeg"),
+ BMP("bmp", "image/bmp"),
+ WBMP("wbmp", "image/vnd.wap.wbmp"),
+ GIF("gif", "image/gif");
+
+ private String name;
+ private String mimeType;
+
+ private Format(String name, String mimeType) {
+ this.name = name;
+ this.mimeType = mimeType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getMIMEType() {
+ return mimeType;
+ }
+ }
+
+ private Format outputFormat;
+
+ public RasterSerializer() {
+ this(Format.PNG);
+ }
+
+ public RasterSerializer(Format outputFormat) {
+ setOutputFormat(outputFormat);
+ }
+
+ /**
+ * Gets the image format that this serializer is using for output.
+ */
+ public Format getOutputFormat() {
+ return outputFormat;
+ }
+
+ /**
+ * Sets the image format that this serializer should use for output.
+ */
+ public void setOutputFormat(Format outputFormat) {
+ if (outputFormat == null) {
+ throw new IllegalArgumentException("Output format is null.");
+ }
+
+ this.outputFormat = outputFormat;
+ }
+
+ @Override
+ public Raster readObject(InputStream inputStream) throws IOException, SerializationException {
+ if (inputStream == null) {
+ throw new IllegalArgumentException("inputStream is null.");
+ }
+
+ return Platform.getPlatform().readRaster(inputStream);
+ }
+
+ @Override
+ public void writeObject(Raster raster, OutputStream outputStream) throws IOException,
+ SerializationException {
+ if (raster == null) {
+ throw new IllegalArgumentException("bufferedImage is null.");
+ }
+
+ if (outputStream == null) {
+ throw new IllegalArgumentException("outputStream is null.");
+ }
+
+ Platform.getPlatform().writeRaster(raster, outputFormat.getName(), outputStream);
+ }
+
+ @Override
+ public String getMIMEType(Raster object) {
+ return outputFormat.getMIMEType();
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Arc.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Arc.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Arc.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Arc.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,96 @@
+/*
+ * 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.scene.shape;
+
+import org.apache.pivot.scene.Extents;
+import org.apache.pivot.scene.Graphics;
+
+/**
+ * Shape representing an arc.
+ */
+public class Arc extends Shape {
+ /**
+ * Enum representing an arc closure type.
+ */
+ public enum Type {
+ CHORD,
+ OPEN,
+ PIE
+ }
+
+ private float start = 0;
+ private float extent = 0;
+ private Type type = Type.CHORD;
+
+ public float getStart() {
+ return start;
+ }
+
+ public void setStart(float start) {
+ float previousStart = this.start;
+ if (previousStart != start) {
+ this.start = start;
+ invalidate();
+ }
+ }
+
+ public float getExtent() {
+ return extent;
+ }
+
+ public void setExtent(float extent) {
+ float previousExtent = this.extent;
+ if (previousExtent != extent) {
+ this.extent = extent;
+ invalidate();
+ }
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ Type previousType = this.type;
+ if (previousType != type) {
+ this.type = type;
+ invalidate();
+ }
+ }
+
+ @Override
+ public boolean contains(int x, int y) {
+ // TODO
+ return true;
+ }
+
+ @Override
+ public Extents getExtents() {
+ // TODO Calculate the actual extents based on start and extent
+ return new Extents(0, getWidth(), 0, getHeight());
+ }
+
+ @Override
+ protected void drawShape(Graphics graphics) {
+ graphics.drawArc(getX(), getY(), getWidth(), getHeight(), start, extent);
+ }
+
+ @Override
+ protected void fillShape(Graphics graphics) {
+ graphics.fillArc(getX(), getY(), getWidth(), getHeight(), start, extent);
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Ellipse.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Ellipse.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Ellipse.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Ellipse.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.scene.shape;
+
+import org.apache.pivot.scene.Extents;
+import org.apache.pivot.scene.Graphics;
+
+/**
+ * Shape representing an ellipse.
+ */
+public class Ellipse extends Shape {
+ @Override
+ public boolean contains(int x, int y) {
+ // TODO
+ return true;
+ }
+
+ @Override
+ public Extents getExtents() {
+ return new Extents(0, getWidth(), 0, getHeight());
+ }
+
+ @Override
+ protected void drawShape(Graphics graphics) {
+ graphics.drawEllipse(getX(), getY(), getWidth(), getHeight());
+ }
+
+ @Override
+ protected void fillShape(Graphics graphics) {
+ graphics.fillEllipse(getX(), getY(), getWidth(), getHeight());
+ }
+}
Added: pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Line.java
URL: http://svn.apache.org/viewvc/pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Line.java?rev=1057053&view=auto
==============================================================================
--- pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Line.java (added)
+++ pivot/branches/3.x/scene/src/org/apache/pivot/scene/shape/Line.java Sun Jan 9 23:19:19 2011
@@ -0,0 +1,126 @@
+/*
+ * 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.scene.shape;
+
+import org.apache.pivot.scene.Extents;
+import org.apache.pivot.scene.Graphics;
+import org.apache.pivot.scene.Point;
+
+/**
+ * Shape representing a line.
+*/
+public class Line extends Shape {
+ private int x1 = 0;
+ private int y1 = 0;
+
+ private int x2 = 0;
+ private int y2 = 0;
+
+ public int getX1() {
+ return x1;
+ }
+
+ public void setX1(int x1) {
+ setEndpoint1(x1, y1);
+ }
+
+ public int getY1() {
+ return y1;
+ }
+
+ public void setY1(int y1) {
+ setEndpoint1(x1, y1);
+ }
+
+ public int getX2() {
+ return x2;
+ }
+
+ public void setX2(int x2) {
+ setEndpoint2(x1, y1);
+ }
+
+ public int getY2() {
+ return y2;
+ }
+
+ public void setY2(int y2) {
+ setEndpoint2(x1, y1);
+ }
+
+ public Point getEndpoint1() {
+ return new Point(getX1(), getY1());
+ }
+
+ public void setEndpoint1(Point endpoint1) {
+ setEndpoint1(endpoint1.x, endpoint1.y);
+ }
+
+ public void setEndpoint1(int x1, int y1) {
+ int previousX1 = this.x1;
+ int previousY1 = this.y1;
+
+ if (previousX1 != x1
+ || previousY1 != y1) {
+ this.x1 = x1;
+ this.y1 = y1;
+
+ invalidate();
+ }
+ }
+
+ public Point getEndpoint2() {
+ return new Point(getX2(), getY2());
+ }
+
+ public void setEndpoint2(int x2, int y2) {
+ int previousX2 = this.x2;
+ int previousY2 = this.y2;
+
+ if (previousX2 != x2
+ || previousY2 != y2) {
+ this.x2 = x2;
+ this.y2 = y2;
+
+ invalidate();
+ }
+ }
+
+ @Override
+ public boolean contains(int x, int y) {
+ // TODO
+ return true;
+ }
+
+ @Override
+ public Extents getExtents() {
+ return new Extents(Math.min(x1, x2),
+ Math.max(x1, x2),
+ Math.min(y1, y2),
+ Math.min(y1, y2));
+ }
+
+ @Override
+ protected void drawShape(Graphics graphics) {
+ graphics.drawLine(x1, y1, x2, y2);
+ }
+
+ @Override
+ protected void fillShape(Graphics graphics) {
+ // No-op
+ }
+}