You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/03/26 00:12:17 UTC
svn commit: r758461 [3/47] - in /incubator/pivot/branches: ./ 1.1/
1.1/charts-test/ 1.1/charts-test/src/ 1.1/charts-test/src/pivot/
1.1/charts-test/src/pivot/charts/ 1.1/charts-test/src/pivot/charts/test/
1.1/charts/ 1.1/charts/lib/ 1.1/charts/src/ 1.1...
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/LineChartView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/LineChartView.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/LineChartView.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/LineChartView.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts;
+
+import pivot.charts.skin.LineChartViewSkin;
+
+/**
+ * Presents chart data using a line plot.
+ *
+ * @author gbrown
+ */
+public class LineChartView extends ChartView {
+ public LineChartView() {
+ setSkin(new LineChartViewSkin());
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/PieChartView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/PieChartView.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/PieChartView.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/PieChartView.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts;
+
+import pivot.charts.skin.PieChartViewSkin;
+
+/**
+ * Presents chart data using a pie plot.
+ *
+ * @author gbrown
+ */
+public class PieChartView extends ChartView {
+ public PieChartView() {
+ setSkin(new PieChartViewSkin());
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Candlestick.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Candlestick.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Candlestick.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Candlestick.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.content;
+
+import java.util.Date;
+
+/**
+ * Represents value data for high/low chart views.
+ *
+ * @author gbrown
+ */
+public class Candlestick {
+ private Date date = null;
+ private float open = 0;
+ private float high = 0;
+ private float low = 0;
+ private float close = 0;
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ @SuppressWarnings("deprecation")
+ public final void setDate(String date) {
+ setDate(new Date(Date.parse(date)));
+ }
+
+ public float getOpen() {
+ return open;
+ }
+
+ public void setOpen(float open) {
+ this.open = open;
+ }
+
+ public float getHigh() {
+ return high;
+ }
+
+ public void setHigh(float high) {
+ this.high = high;
+ }
+
+ public float getLow() {
+ return low;
+ }
+
+ public void setLow(float low) {
+ this.low = low;
+ }
+
+ public float getClose() {
+ return close;
+ }
+
+ public void setClose(float close) {
+ this.close = close;
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/content/CategorySeries.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/content/CategorySeries.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/content/CategorySeries.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/content/CategorySeries.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.content;
+
+import pivot.collections.HashMap;
+
+/**
+ * Represents series data for category chart views.
+ *
+ * @author gbrown
+ */
+public class CategorySeries extends HashMap<String, Object> {
+ private static final long serialVersionUID = 0;
+
+ public static final String NAME_KEY = "name";
+
+ public CategorySeries() {
+ this(null);
+ }
+
+ public CategorySeries(String name) {
+ put(NAME_KEY, name);
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Interval.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Interval.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Interval.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Interval.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.content;
+
+/**
+ * Represents value data for interval chart views.
+ *
+ * @author gbrown
+ */
+public class Interval extends Point {
+ private float width = 0;
+
+ public float getWidth() {
+ return width;
+ }
+
+ public void setWidth(float width) {
+ this.width = width;
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Point.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Point.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Point.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/content/Point.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.content;
+
+/**
+ * Represents value data for x/y chart views.
+ *
+ * @author gbrown
+ */
+public class Point {
+ private float x = 0;
+ private float y = 0;
+
+ public float getX() {
+ return x;
+ }
+
+ public void setX(float x) {
+ this.x = x;
+ }
+
+ public float getY() {
+ return y;
+ }
+
+ public void setY(float y) {
+ this.y = y;
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/content/ValueSeries.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/content/ValueSeries.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/content/ValueSeries.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/content/ValueSeries.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.content;
+
+import pivot.collections.ArrayList;
+
+/**
+ * Represents series data for value chart views.
+ *
+ * @author gbrown
+ */
+public class ValueSeries<T> extends ArrayList<T> {
+ private static final long serialVersionUID = 0;
+
+ private String name = null;
+
+ public ValueSeries() {
+ this(null);
+ }
+
+ public ValueSeries(String name) {
+ setName(name);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/content/package.html
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/content/package.html?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/content/package.html (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/content/package.html Wed Mar 25 23:08:38 2009
@@ -0,0 +1,6 @@
+<html>
+<head></head>
+<body>
+<p>Contains classes representing chart data.</p>
+</body>
+</html>
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/package.html
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/package.html?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/package.html (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/package.html Wed Mar 25 23:08:38 2009
@@ -0,0 +1,6 @@
+<html>
+<head></head>
+<body>
+<p>Contains a collection of components for use in charting applications.</p>
+</body>
+</html>
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/AreaChartViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/AreaChartViewSkin.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/AreaChartViewSkin.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/AreaChartViewSkin.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.entity.CategoryItemEntity;
+import org.jfree.chart.entity.ChartEntity;
+import org.jfree.chart.entity.XYItemEntity;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.CategoryDataset;
+
+import pivot.charts.AreaChartView;
+import pivot.charts.ChartView;
+import pivot.collections.List;
+
+/**
+ * Area chart view skin.
+ *
+ * @author gbrown
+ */
+public class AreaChartViewSkin extends ChartViewSkin {
+ public ChartView.Element getElementAt(int x, int y) {
+ ChartView.Element element = null;
+
+ ChartEntity chartEntity = getChartEntityAt(x, y);
+ if (chartEntity instanceof CategoryItemEntity) {
+ CategoryItemEntity categoryItemEntity = (CategoryItemEntity)chartEntity;
+ CategoryDataset dataset = categoryItemEntity.getDataset();
+
+ String columnKey = (String)categoryItemEntity.getColumnKey();
+ int columnIndex = dataset.getColumnIndex(columnKey);
+
+ String rowKey = (String)categoryItemEntity.getRowKey();
+ int rowIndex = dataset.getRowIndex(rowKey);
+
+ element = new ChartView.Element(rowIndex, columnIndex);
+ } else if (chartEntity instanceof XYItemEntity) {
+ XYItemEntity xyItemEntity = (XYItemEntity)chartEntity;
+ element = new ChartView.Element(xyItemEntity.getSeriesIndex(),
+ xyItemEntity.getItem());
+ }
+
+ return element;
+ }
+
+ @Override
+ protected JFreeChart createChart() {
+ AreaChartView chartView = (AreaChartView)getComponent();
+
+ String title = chartView.getTitle();
+ String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
+ String verticalAxisLabel = chartView.getVerticalAxisLabel();
+ boolean showLegend = chartView.getShowLegend();
+
+ String seriesNameKey = chartView.getSeriesNameKey();
+ List<?> chartData = chartView.getChartData();
+
+ JFreeChart chart;
+ ChartView.CategorySequence categories = chartView.getCategories();
+ if (categories.getLength() > 0) {
+ CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);
+ chart = ChartFactory.createAreaChart(title, horizontalAxisLabel, verticalAxisLabel,
+ dataset, PlotOrientation.VERTICAL, showLegend, false, false);
+ } else {
+ chart = ChartFactory.createXYAreaChart(title, horizontalAxisLabel, verticalAxisLabel,
+ new XYSeriesDataset(seriesNameKey, chartData),
+ PlotOrientation.VERTICAL, showLegend, false, false);
+ }
+
+ return chart;
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/BarChartViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/BarChartViewSkin.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/BarChartViewSkin.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/BarChartViewSkin.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.entity.ChartEntity;
+import org.jfree.chart.entity.CategoryItemEntity;
+import org.jfree.chart.entity.XYItemEntity;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.CategoryDataset;
+
+import pivot.charts.BarChartView;
+import pivot.charts.ChartView;
+import pivot.collections.List;
+
+/**
+ * Bar chart view skin.
+ *
+ * @author gbrown
+ */
+public class BarChartViewSkin extends ChartViewSkin {
+ private boolean stacked = false;
+ private boolean threeDimensional = false;
+
+ public ChartView.Element getElementAt(int x, int y) {
+ ChartView.Element element = null;
+
+ ChartEntity chartEntity = getChartEntityAt(x, y);
+ if (chartEntity instanceof CategoryItemEntity) {
+ CategoryItemEntity categoryItemEntity = (CategoryItemEntity)chartEntity;
+ CategoryDataset dataset = categoryItemEntity.getDataset();
+
+ String columnKey = (String)categoryItemEntity.getColumnKey();
+ int columnIndex = dataset.getColumnIndex(columnKey);
+
+ String rowKey = (String)categoryItemEntity.getRowKey();
+ int rowIndex = dataset.getRowIndex(rowKey);
+
+ element = new ChartView.Element(rowIndex, columnIndex);
+ } else if (chartEntity instanceof XYItemEntity) {
+ XYItemEntity xyItemEntity = (XYItemEntity)chartEntity;
+ element = new ChartView.Element(xyItemEntity.getSeriesIndex(),
+ xyItemEntity.getItem());
+ }
+
+ return element;
+ }
+
+ protected JFreeChart createChart() {
+ BarChartView chartView = (BarChartView)getComponent();
+
+ String title = chartView.getTitle();
+ String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
+ String verticalAxisLabel = chartView.getVerticalAxisLabel();
+ boolean showLegend = chartView.getShowLegend();
+
+ String seriesNameKey = chartView.getSeriesNameKey();
+ List<?> chartData = chartView.getChartData();
+
+ // TODO Make plot orientation a style property
+
+ JFreeChart chart;
+ ChartView.CategorySequence categories = chartView.getCategories();
+ if (categories.getLength() > 0) {
+ CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);
+
+ if (stacked && threeDimensional) {
+ chart = ChartFactory.createStackedBarChart3D(title, horizontalAxisLabel, verticalAxisLabel,
+ dataset, PlotOrientation.VERTICAL, showLegend, false, false);
+ } else if (stacked) {
+ chart = ChartFactory.createStackedBarChart(title, horizontalAxisLabel, verticalAxisLabel,
+ dataset, PlotOrientation.VERTICAL, showLegend, false, false);
+ } else if (threeDimensional) {
+ chart = ChartFactory.createBarChart3D(title, horizontalAxisLabel, verticalAxisLabel,
+ dataset, PlotOrientation.VERTICAL, showLegend, false, false);
+ } else {
+ chart = ChartFactory.createBarChart(title, horizontalAxisLabel, verticalAxisLabel,
+ dataset, PlotOrientation.VERTICAL, showLegend, false, false);
+ }
+ } else {
+ // TODO Make the dateAxis argument a style property
+ chart = ChartFactory.createXYBarChart(title, horizontalAxisLabel, false, verticalAxisLabel,
+ new IntervalSeriesDataset(seriesNameKey, chartData),
+ PlotOrientation.VERTICAL, showLegend, false, false);
+ }
+
+ return chart;
+ }
+
+ public boolean isStacked() {
+ return stacked;
+ }
+
+ public void setStacked(boolean stacked) {
+ this.stacked = stacked;
+ repaintComponent();
+ }
+
+ public boolean isThreeDimensional() {
+ return threeDimensional;
+ }
+
+ public void setThreeDimensional(boolean threeDimensional) {
+ this.threeDimensional = threeDimensional;
+ repaintComponent();
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/CategorySeriesDataset.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/CategorySeriesDataset.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/CategorySeriesDataset.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/CategorySeriesDataset.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import org.jfree.data.category.CategoryDataset;
+import org.jfree.data.general.DatasetChangeListener;
+import org.jfree.data.general.DatasetGroup;
+
+import pivot.beans.BeanDictionary;
+import pivot.charts.ChartView;
+import pivot.collections.Dictionary;
+import pivot.collections.List;
+
+/**
+ * Implementation of JFreeChart CategoryDataset.
+ *
+ * @author gbrown
+ */
+@SuppressWarnings("unchecked")
+public class CategorySeriesDataset implements CategoryDataset {
+ private ChartView.CategorySequence categories;
+ private String seriesNameKey;
+ private List<?> chartData;
+
+ private DatasetGroup datasetGroup = null;
+
+ public CategorySeriesDataset(ChartView.CategorySequence categories,
+ String seriesNameKey, List<?> chartData) {
+ if (categories == null) {
+ throw new IllegalArgumentException("categories is null.");
+ }
+
+ if (seriesNameKey == null) {
+ throw new IllegalArgumentException("seriesNameKey is null.");
+ }
+
+ if (chartData == null) {
+ throw new IllegalArgumentException("chartData is null.");
+ }
+
+ this.categories = categories;
+ this.seriesNameKey = seriesNameKey;
+ this.chartData = chartData;
+ }
+
+ public DatasetGroup getGroup() {
+ return datasetGroup;
+ }
+
+ public void setGroup(DatasetGroup datasetGroup) {
+ this.datasetGroup = datasetGroup;
+ }
+
+ public int getColumnCount() {
+ return categories.getLength();
+ }
+
+ public int getRowCount() {
+ return chartData.getLength();
+ }
+
+ public int getColumnIndex(Comparable categoryLabel) {
+ if (categoryLabel == null) {
+ throw new IllegalArgumentException("categoryLabel is null.");
+ }
+
+ int columnIndex = -1;
+ for (int i = 0, n = categories.getLength(); i < n && columnIndex == -1; i++) {
+ ChartView.Category category = categories.get(i);
+
+ if (categoryLabel.compareTo(category.getLabel()) == 0) {
+ columnIndex = i;
+ }
+ }
+
+ return columnIndex;
+ }
+
+ public Comparable getColumnKey(int categoryIndex) {
+ if (categoryIndex < 0
+ || categoryIndex > categories.getLength() - 1) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ return categories.get(categoryIndex).getLabel();
+ }
+
+ public java.util.List getColumnKeys() {
+ java.util.ArrayList columnKeys = new java.util.ArrayList(categories.getLength());
+ for (int i = 0, n = categories.getLength(); i < n; i++) {
+ columnKeys.add(categories.get(i).getLabel());
+ }
+
+ return columnKeys;
+ }
+
+ public int getRowIndex(Comparable seriesName) {
+ if (seriesName == null) {
+ throw new IllegalArgumentException("seriesName is null.");
+ }
+
+ int rowIndex = -1;
+ for (int i = 0, n = chartData.getLength(); i < n && rowIndex == -1; i++) {
+ Dictionary<String, ?> seriesDictionary = getSeriesDictionary(i);
+
+ if (seriesName.compareTo(seriesDictionary.get(seriesNameKey)) == 0) {
+ rowIndex = i;
+ }
+ }
+
+ return rowIndex;
+ }
+
+ public Comparable getRowKey(int seriesIndex) {
+ Dictionary<String, ?> seriesDictionary = getSeriesDictionary(seriesIndex);
+ return (String)seriesDictionary.get(seriesNameKey);
+ }
+
+ public java.util.List getRowKeys() {
+ java.util.ArrayList rowKeys = new java.util.ArrayList(chartData.getLength());
+ for (int i = 0, n = chartData.getLength(); i < n; i++) {
+ rowKeys.add(getRowKey(i));
+ }
+
+ return rowKeys;
+ }
+
+ public Number getValue(int seriesIndex, int categoryIndex) {
+ Dictionary<String, ?> seriesDictionary = getSeriesDictionary(seriesIndex);
+
+ if (categoryIndex < 0
+ || categoryIndex > categories.getLength() - 1) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ ChartView.Category category = categories.get(categoryIndex);
+ String categoryKey = category.getKey();
+
+ Object value = seriesDictionary.get(categoryKey);
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+
+ return (Number)value;
+ }
+
+ public Number getValue(Comparable seriesName, Comparable categoryLabel) {
+ return getValue(getRowIndex(seriesName), getColumnIndex(categoryLabel));
+ }
+
+ protected Dictionary<String, ?> getSeriesDictionary(int seriesIndex) {
+ if (seriesIndex < 0
+ || seriesIndex > chartData.getLength() - 1) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ Object series = chartData.get(seriesIndex);
+
+ Dictionary<String, ?> seriesDictionary;
+ if (series instanceof Dictionary<?, ?>) {
+ seriesDictionary = (Dictionary<String, ?>)series;
+ } else {
+ seriesDictionary = new BeanDictionary(series);
+ }
+
+ return seriesDictionary;
+ }
+
+ public void addChangeListener(DatasetChangeListener listener) {
+ // No-op
+ }
+
+ public void removeChangeListener(DatasetChangeListener listener) {
+ // No-op
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/ChartViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/ChartViewSkin.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/ChartViewSkin.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/ChartViewSkin.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+
+import org.jfree.chart.ChartRenderingInfo;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.entity.ChartEntity;
+import org.jfree.chart.entity.EntityCollection;
+
+import pivot.charts.ChartView;
+import pivot.charts.ChartViewCategoryListener;
+import pivot.charts.ChartViewListener;
+import pivot.charts.ChartViewSeriesListener;
+import pivot.collections.List;
+import pivot.collections.Sequence;
+import pivot.wtk.Component;
+import pivot.wtk.Dimensions;
+import pivot.wtk.skin.ComponentSkin;
+
+/**
+ * Abstract base class for chart view skins.
+ *
+ * @author gbrown
+ */
+public abstract class ChartViewSkin extends ComponentSkin
+ implements ChartView.Skin,
+ ChartViewListener, ChartViewCategoryListener, ChartViewSeriesListener {
+ private BufferedImage bufferedImage = null;
+
+ private JFreeChart chart = null;
+ private ChartRenderingInfo chartRenderingInfo = new ChartRenderingInfo();
+
+ private Color backgroundColor = null;
+
+ private static final int PREFERRED_WIDTH = 320;
+ private static final int PREFERRED_HEIGHT = 240;
+
+ @Override
+ public void install(Component component) {
+ super.install(component);
+
+ // Add listeners
+ ChartView chartView = (ChartView)component;
+ chartView.getChartViewListeners().add(this);
+ chartView.getChartViewCategoryListeners().add(this);
+ chartView.getChartViewSeriesListeners().add(this);
+ }
+
+ @Override
+ public void uninstall() {
+ // Remove listeners
+ ChartView chartView = (ChartView)getComponent();
+ chartView.getChartViewListeners().remove(this);
+ chartView.getChartViewCategoryListeners().remove(this);
+ chartView.getChartViewSeriesListeners().remove(this);
+
+ super.uninstall();
+ }
+
+ public int getPreferredWidth(int height) {
+ return PREFERRED_WIDTH;
+ }
+
+
+ public int getPreferredHeight(int width) {
+ return PREFERRED_HEIGHT;
+ }
+
+ public Dimensions getPreferredSize() {
+ return new Dimensions(getPreferredWidth(-1), getPreferredHeight(-1));
+ }
+
+ public void layout() {
+ // No-op
+ }
+
+ public void paint(Graphics2D graphics) {
+ int width = getWidth();
+ int height = getHeight();
+
+ if (bufferedImage == null
+ || bufferedImage.getWidth() != width
+ || bufferedImage.getHeight() != height) {
+ chart = createChart();
+
+ bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D bufferedImageGraphics = (Graphics2D)bufferedImage.getGraphics();
+
+ java.awt.Rectangle area = new java.awt.Rectangle(0, 0, width, height);
+ chart.setBackgroundPaint(backgroundColor);
+ chart.draw(bufferedImageGraphics, area, chartRenderingInfo);
+
+ bufferedImageGraphics.dispose();
+ }
+
+ graphics.drawImage(bufferedImage, 0, 0, null);
+ }
+
+ @Override
+ public void repaintComponent() {
+ super.repaintComponent();
+ bufferedImage = null;
+ }
+
+ protected abstract JFreeChart createChart();
+
+ protected ChartEntity getChartEntityAt(int x, int y) {
+ ChartEntity result = null;
+
+ if (chartRenderingInfo != null) {
+ EntityCollection entities = chartRenderingInfo.getEntityCollection();
+ result = (entities != null) ? entities.getEntity(x, y) : null;
+ }
+
+ return result;
+ }
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ repaintComponent();
+ }
+
+ // Chart view events
+ public void chartDataChanged(ChartView chartView, List<?> previousChartData) {
+ repaintComponent();
+ }
+
+ public void seriesNameKeyChanged(ChartView chartView, String previousSeriesNameKey) {
+ repaintComponent();
+ }
+
+ public void titleChanged(ChartView chartView, String previousTitle) {
+ repaintComponent();
+ }
+
+ public void horizontalAxisLabelChanged(ChartView chartView, String previousHorizontalAxisLabel) {
+ repaintComponent();
+ }
+
+ public void verticalAxisLabelChanged(ChartView chartView, String previousVerticalAxisLabel) {
+ repaintComponent();
+ }
+
+ public void showLegendChanged(ChartView chartView) {
+ repaintComponent();
+ }
+
+ // Chart view category events
+ public void categoryInserted(ChartView chartView, int index) {
+ repaintComponent();
+ }
+
+ public void categoriesRemoved(ChartView chartView, int index, Sequence<ChartView.Category> categories) {
+ repaintComponent();
+ }
+
+ public void categoryKeyChanged(ChartView chartView, int index, String previousKey) {
+ repaintComponent();
+ }
+
+ public void categoryLabelChanged(ChartView chartView, int index, String previousLabel) {
+ repaintComponent();
+ }
+
+ // Chart view series events
+ public void seriesInserted(ChartView chartView, int index) {
+ repaintComponent();
+ }
+
+ public void seriesRemoved(ChartView chartView, int index, int count) {
+ repaintComponent();
+ }
+
+ public void seriesUpdated(ChartView chartView, int index) {
+ repaintComponent();
+ }
+
+ public void seriesSorted(ChartView chartView) {
+ repaintComponent();
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/HighLowChartViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/HighLowChartViewSkin.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/HighLowChartViewSkin.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/HighLowChartViewSkin.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.entity.ChartEntity;
+import org.jfree.chart.entity.XYItemEntity;
+
+import pivot.charts.ChartView;
+import pivot.charts.HighLowChartView;
+import pivot.collections.List;
+
+/**
+ * High/low chart view skin.
+ *
+ * @author gbrown
+ */
+public class HighLowChartViewSkin extends ChartViewSkin {
+ private boolean candlestick = false;
+
+ public ChartView.Element getElementAt(int x, int y) {
+ ChartView.Element element = null;
+
+ ChartEntity chartEntity = getChartEntityAt(x, y);
+ if (chartEntity instanceof XYItemEntity) {
+ XYItemEntity xyItemEntity = (XYItemEntity)chartEntity;
+ element = new ChartView.Element(xyItemEntity.getSeriesIndex(),
+ xyItemEntity.getItem());
+ }
+
+ return element;
+ }
+
+ @Override
+ protected JFreeChart createChart() {
+ HighLowChartView chartView = (HighLowChartView)getComponent();
+
+ String title = chartView.getTitle();
+ String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
+ String verticalAxisLabel = chartView.getVerticalAxisLabel();
+ boolean showLegend = chartView.getShowLegend();
+
+ String seriesNameKey = chartView.getSeriesNameKey();
+ List<?> chartData = chartView.getChartData();
+
+ JFreeChart chart;
+ OHLCSeriesDataset dataset = new OHLCSeriesDataset(seriesNameKey, chartData);
+
+ if (candlestick) {
+ chart = ChartFactory.createCandlestickChart(title,
+ horizontalAxisLabel, verticalAxisLabel, dataset, showLegend);
+ } else {
+ chart = ChartFactory.createHighLowChart(title,
+ horizontalAxisLabel, verticalAxisLabel, dataset, showLegend);
+ }
+
+ return chart;
+ }
+
+ public boolean isCandlestick() {
+ return candlestick;
+ }
+
+ public void setCandlestick(boolean candlestick) {
+ this.candlestick = candlestick;
+ repaintComponent();
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/IntervalSeriesDataset.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/IntervalSeriesDataset.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/IntervalSeriesDataset.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/IntervalSeriesDataset.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import org.jfree.data.xy.IntervalXYDataset;
+
+import pivot.collections.Dictionary;
+import pivot.collections.List;
+
+/**
+ * Implementation of JFreeChart IntervalXYDataset.
+ *
+ * @author gbrown
+ */
+public class IntervalSeriesDataset extends XYSeriesDataset implements IntervalXYDataset {
+ public static final String WIDTH_KEY = "width";
+ public static final String HEIGHT_KEY = "height";
+
+ public IntervalSeriesDataset(String seriesNameKey, List<?> chartData) {
+ super(seriesNameKey, chartData);
+ }
+
+ public Number getStartX(int seriesIndex, int itemIndex) {
+ return getX(seriesIndex, itemIndex);
+ }
+
+ public double getStartXValue(int seriesIndex, int itemIndex) {
+ return getX(seriesIndex, itemIndex).doubleValue();
+ }
+
+ public Number getEndX(int seriesIndex, int itemIndex) {
+ return getXValue(seriesIndex, itemIndex) + getWidthValue(seriesIndex, itemIndex);
+ }
+
+ public double getEndXValue(int seriesIndex, int itemIndex) {
+ return getEndX(seriesIndex, itemIndex).doubleValue();
+ }
+
+ public Number getStartY(int seriesIndex, int itemIndex) {
+ return getY(seriesIndex, itemIndex);
+ }
+
+ public double getStartYValue(int seriesIndex, int itemIndex) {
+ return getY(seriesIndex, itemIndex).doubleValue();
+ }
+
+ public Number getEndY(int seriesIndex, int itemIndex) {
+ return getYValue(seriesIndex, itemIndex) + getWidthValue(seriesIndex, itemIndex);
+ }
+
+ public double getEndYValue(int seriesIndex, int itemIndex) {
+ return getEndY(seriesIndex, itemIndex).doubleValue();
+ }
+
+ protected double getWidthValue(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(WIDTH_KEY);
+ if (value == null) {
+ throw new NullPointerException(WIDTH_KEY + " is null.");
+ }
+
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+
+ Number width = (Number)value;
+ return width.doubleValue();
+ }
+
+ protected double getHeightValue(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(HEIGHT_KEY);
+ if (value == null) {
+ throw new NullPointerException(HEIGHT_KEY + " is null.");
+ }
+
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+
+ Number height = (Number)value;
+ return height.doubleValue();
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/LineChartViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/LineChartViewSkin.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/LineChartViewSkin.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/LineChartViewSkin.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.entity.CategoryItemEntity;
+import org.jfree.chart.entity.ChartEntity;
+import org.jfree.chart.entity.XYItemEntity;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.CategoryDataset;
+
+import pivot.charts.ChartView;
+import pivot.charts.LineChartView;
+import pivot.collections.List;
+
+/**
+ * Line chart view skin.
+ *
+ * @author gbrown
+ */
+public class LineChartViewSkin extends ChartViewSkin {
+ private boolean threeDimensional = false;
+
+ public ChartView.Element getElementAt(int x, int y) {
+ ChartView.Element element = null;
+
+ ChartEntity chartEntity = getChartEntityAt(x, y);
+
+ if (chartEntity instanceof CategoryItemEntity) {
+ CategoryItemEntity categoryItemEntity = (CategoryItemEntity)chartEntity;
+ CategoryDataset dataset = categoryItemEntity.getDataset();
+
+ String columnKey = (String)categoryItemEntity.getColumnKey();
+ int columnIndex = dataset.getColumnIndex(columnKey);
+
+ String rowKey = (String)categoryItemEntity.getRowKey();
+ int rowIndex = dataset.getRowIndex(rowKey);
+
+ element = new ChartView.Element(rowIndex, columnIndex);
+ } else if (chartEntity instanceof XYItemEntity) {
+ XYItemEntity xyItemEntity = (XYItemEntity)chartEntity;
+ element = new ChartView.Element(xyItemEntity.getSeriesIndex(),
+ xyItemEntity.getItem());
+ }
+
+ return element;
+ }
+
+ protected JFreeChart createChart() {
+ LineChartView chartView = (LineChartView)getComponent();
+
+ String title = chartView.getTitle();
+ String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
+ String verticalAxisLabel = chartView.getVerticalAxisLabel();
+ boolean showLegend = chartView.getShowLegend();
+
+ String seriesNameKey = chartView.getSeriesNameKey();
+ List<?> chartData = chartView.getChartData();
+
+ JFreeChart chart;
+ ChartView.CategorySequence categories = chartView.getCategories();
+ if (categories.getLength() > 0) {
+ CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);
+
+ if (threeDimensional) {
+ chart = ChartFactory.createLineChart3D(title, horizontalAxisLabel, verticalAxisLabel,
+ dataset, PlotOrientation.VERTICAL, showLegend, false, false);
+ } else {
+ chart = ChartFactory.createLineChart(title, horizontalAxisLabel, verticalAxisLabel,
+ dataset, PlotOrientation.VERTICAL, showLegend, false, false);
+ }
+ } else {
+ chart = ChartFactory.createXYLineChart(title, horizontalAxisLabel, verticalAxisLabel,
+ new XYSeriesDataset(seriesNameKey, chartData),
+ PlotOrientation.VERTICAL, showLegend, false, false);
+ }
+
+ return chart;
+ }
+
+ public boolean isThreeDimensional() {
+ return threeDimensional;
+ }
+
+ public void setThreeDimensional(boolean threeDimensional) {
+ this.threeDimensional = threeDimensional;
+ repaintComponent();
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/OHLCSeriesDataset.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/OHLCSeriesDataset.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/OHLCSeriesDataset.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/OHLCSeriesDataset.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,146 @@
+package pivot.charts.skin;
+
+import java.util.Date;
+
+import org.jfree.data.xy.OHLCDataset;
+
+import pivot.collections.Dictionary;
+import pivot.collections.List;
+
+/**
+ * Implementation of JFreeChart OHLCDataset.
+ *
+ * @author gbrown
+ */
+public class OHLCSeriesDataset extends XYSeriesDataset implements OHLCDataset {
+ public static final String DATE_KEY = "date";
+ public static final String OPEN_KEY = "open";
+ public static final String HIGH_KEY = "high";
+ public static final String LOW_KEY = "low";
+ public static final String CLOSE_KEY = "close";
+ public static final String VOLUME_KEY = "volume";
+
+ public OHLCSeriesDataset(String seriesNameKey, List<?> chartData) {
+ super(seriesNameKey, chartData);
+ }
+
+ @Override
+ public Number getX(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(X_KEY);
+ if (value == null) {
+ value = itemDictionary.get(DATE_KEY);
+
+ if (value instanceof Date) {
+ value = ((Date)value).getTime();
+ }
+ }
+
+ if (value == null) {
+ throw new NullPointerException(X_KEY + " and " + DATE_KEY + " are null.");
+ }
+
+ return (Number)value;
+ }
+
+ @Override
+ public Number getY(int seriesIndex, int itemIndex) {
+ return getClose(seriesIndex, itemIndex);
+ }
+
+ public Number getOpen(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(OPEN_KEY);
+ if (value == null) {
+ value = Double.NaN;
+ } else {
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+ }
+
+ return (Number)value;
+ }
+
+ public double getOpenValue(int seriesIndex, int itemIndex) {
+ return getOpen(seriesIndex, itemIndex).doubleValue();
+ }
+
+ public Number getHigh(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(HIGH_KEY);
+ if (value == null) {
+ value = Double.NaN;
+ } else {
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+ }
+
+ return (Number)value;
+ }
+
+ public double getHighValue(int seriesIndex, int itemIndex) {
+ return getHigh(seriesIndex, itemIndex).doubleValue();
+ }
+
+ public Number getLow(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(LOW_KEY);
+ if (value == null) {
+ value = Double.NaN;
+ } else {
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+ }
+
+ return (Number)value;
+ }
+
+ public double getLowValue(int seriesIndex, int itemIndex) {
+ return getLow(seriesIndex, itemIndex).doubleValue();
+ }
+
+ public Number getClose(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(CLOSE_KEY);
+ if (value == null) {
+ value = Double.NaN;
+ } else {
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+ }
+
+ return (Number)value;
+ }
+
+ public double getCloseValue(int seriesIndex, int itemIndex) {
+ return getClose(seriesIndex, itemIndex).doubleValue();
+ }
+
+ public Number getVolume(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(VOLUME_KEY);
+ if (value == null) {
+ value = Double.NaN;
+ } else {
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+ }
+
+ return (Number)value;
+ }
+
+ public double getVolumeValue(int seriesIndex, int itemIndex) {
+ return getVolume(seriesIndex, itemIndex).doubleValue();
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/PieChartViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/PieChartViewSkin.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/PieChartViewSkin.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/PieChartViewSkin.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.entity.ChartEntity;
+import org.jfree.chart.entity.PieSectionEntity;
+import org.jfree.chart.plot.PiePlot;
+import org.jfree.chart.plot.PiePlot3D;
+import org.jfree.util.TableOrder;
+
+import pivot.charts.PieChartView;
+import pivot.charts.ChartView;
+import pivot.collections.HashMap;
+import pivot.collections.List;
+import pivot.collections.Map;
+
+/**
+ * Pie chart view skin.
+ *
+ * @author gbrown
+ */
+public class PieChartViewSkin extends ChartViewSkin {
+ private Map<String, Number> explodePercentages = new HashMap<String, Number>();
+
+ private boolean threeDimensional = false;
+ private boolean darkerSides = false;
+ private double depthFactor = 0.10d;
+
+ public ChartView.Element getElementAt(int x, int y) {
+ ChartView.Element element = null;
+
+ ChartEntity chartEntity = getChartEntityAt(x, y);
+ if (chartEntity instanceof PieSectionEntity) {
+ PieSectionEntity pieSectionEntity = (PieSectionEntity)chartEntity;
+ int sectionIndex = pieSectionEntity.getSectionIndex();
+ int seriesIndex = pieSectionEntity.getPieIndex();
+
+ element = new ChartView.Element(seriesIndex, sectionIndex);
+ }
+
+ return element;
+ }
+
+ protected JFreeChart createChart() {
+ PieChartView chartView = (PieChartView)getComponent();
+
+ String title = chartView.getTitle();
+ boolean showLegend = chartView.getShowLegend();
+
+ ChartView.CategorySequence categories = chartView.getCategories();
+ String seriesNameKey = chartView.getSeriesNameKey();
+ List<?> chartData = chartView.getChartData();
+
+
+ JFreeChart chart;
+ if (threeDimensional) {
+ if (chartData.getLength() > 1) {
+ CategorySeriesDataset dataset = new CategorySeriesDataset(categories,
+ seriesNameKey, chartData);
+
+ chart = ChartFactory.createMultiplePieChart3D(title, dataset, TableOrder.BY_ROW,
+ showLegend, false, false);
+ } else {
+ PieSeriesDataset dataset = new PieSeriesDataset(categories, chartData.get(0));
+ chart = ChartFactory.createPieChart3D(title, dataset, showLegend, false, false);
+
+ PiePlot3D plot = (PiePlot3D)chart.getPlot();
+ plot.setDarkerSides(darkerSides);
+ plot.setDepthFactor(depthFactor);
+ }
+ } else {
+ if (chartData.getLength() > 1) {
+ CategorySeriesDataset dataset = new CategorySeriesDataset(categories,
+ seriesNameKey, chartData);
+
+ chart = ChartFactory.createMultiplePieChart(title, dataset, TableOrder.BY_ROW,
+ showLegend, false, false);
+ } else {
+ PieSeriesDataset dataset = new PieSeriesDataset(categories, chartData.get(0));
+ chart = ChartFactory.createPieChart(title, dataset, showLegend, false, false);
+
+ HashMap<String, String> categoryLabels = new HashMap<String, String>();
+ for (int i = 0, n = categories.getLength(); i < n; i++) {
+ ChartView.Category category = categories.get(i);
+ categoryLabels.put(category.getKey(), category.getLabel());
+ }
+
+ PiePlot plot = (PiePlot)chart.getPlot();
+ for (String categoryKey : explodePercentages) {
+ plot.setExplodePercent(categoryLabels.get(categoryKey),
+ explodePercentages.get(categoryKey).doubleValue());
+ }
+ }
+ }
+
+ return chart;
+ }
+
+ public boolean isThreeDimensional() {
+ return threeDimensional;
+ }
+
+ public void setThreeDimensional(boolean threeDimensional) {
+ this.threeDimensional = threeDimensional;
+ repaintComponent();
+ }
+
+ public Map<String, Number> getExplodePercentages() {
+ return explodePercentages;
+ }
+
+ public void setExplodePercentages(Map<String, Number> explodePercentages) {
+ this.explodePercentages = explodePercentages;
+ repaintComponent();
+ }
+
+ public boolean getDarkerSides() {
+ return darkerSides;
+ }
+
+ public void setDarkerSides(boolean darkerSides) {
+ this.darkerSides = darkerSides;
+ repaintComponent();
+ }
+
+ public double getDepthFactor() {
+ return depthFactor;
+ }
+
+ public void setDepthFactor(double depthFactor) {
+ if (depthFactor < 0) {
+ throw new IllegalArgumentException("depthFactor is negative.");
+ }
+
+ this.depthFactor = depthFactor;
+ repaintComponent();
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/PieSeriesDataset.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/PieSeriesDataset.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/PieSeriesDataset.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/PieSeriesDataset.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import java.util.List;
+
+import org.jfree.data.general.DatasetChangeListener;
+import org.jfree.data.general.DatasetGroup;
+import org.jfree.data.general.PieDataset;
+
+import pivot.beans.BeanDictionary;
+import pivot.charts.ChartView;
+import pivot.collections.Dictionary;
+
+/**
+ * Implementation of JFreeChart PieDataset.
+ *
+ * @author gbrown
+ */
+@SuppressWarnings("unchecked")
+public class PieSeriesDataset implements PieDataset {
+ private ChartView.CategorySequence categories;
+ private Object series;
+
+ private DatasetGroup datasetGroup = null;
+
+ public PieSeriesDataset(ChartView.CategorySequence categories, Object series) {
+ if (categories == null) {
+ throw new IllegalArgumentException("categories is null.");
+ }
+
+ if (series == null) {
+ throw new IllegalArgumentException("series is null.");
+ }
+
+ this.categories = categories;
+ this.series = series;
+ }
+
+ public DatasetGroup getGroup() {
+ return datasetGroup;
+ }
+
+ public void setGroup(DatasetGroup datasetGroup) {
+ this.datasetGroup = datasetGroup;
+ }
+
+ public int getItemCount() {
+ return categories.getLength();
+ }
+
+ public int getIndex(Comparable categoryLabel) {
+ if (categoryLabel == null) {
+ throw new IllegalArgumentException("categoryLabel is null.");
+ }
+
+ int index = -1;
+ for (int i = 0, n = categories.getLength(); i < n && index == -1; i++) {
+ ChartView.Category category = categories.get(i);
+
+ if (categoryLabel.compareTo(category.getLabel()) == 0) {
+ index = i;
+ }
+ }
+
+ return index;
+ }
+
+ public Comparable getKey(int categoryIndex) {
+ if (categoryIndex < 0
+ || categoryIndex > categories.getLength() - 1) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ return categories.get(categoryIndex).getLabel();
+ }
+
+ public List getKeys() {
+ java.util.ArrayList columnKeys = new java.util.ArrayList(categories.getLength());
+ for (int i = 0, n = categories.getLength(); i < n; i++) {
+ columnKeys.add(categories.get(i).getLabel());
+ }
+
+ return columnKeys;
+ }
+
+ public Number getValue(int categoryIndex) {
+ if (categoryIndex < 0
+ || categoryIndex > categories.getLength() - 1) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ ChartView.Category category = categories.get(categoryIndex);
+ String categoryKey = category.getKey();
+
+ Dictionary<String, ?> seriesDictionary;
+ if (series instanceof Dictionary<?, ?>) {
+ seriesDictionary = (Dictionary<String, ?>)series;
+ } else {
+ seriesDictionary = new BeanDictionary(series);
+ }
+
+ Object value = seriesDictionary.get(categoryKey);
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+
+ return (Number)value;
+ }
+
+ public Number getValue(Comparable categoryLabel) {
+ return getValue(getIndex(categoryLabel));
+ }
+
+ public void addChangeListener(DatasetChangeListener listener) {
+ // No-op
+ }
+
+ public void removeChangeListener(DatasetChangeListener listener) {
+ // No-op
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/XYSeriesDataset.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/XYSeriesDataset.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/XYSeriesDataset.java (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/XYSeriesDataset.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.charts.skin;
+
+import org.jfree.data.DomainOrder;
+import org.jfree.data.general.DatasetChangeListener;
+import org.jfree.data.general.DatasetGroup;
+import org.jfree.data.xy.XYDataset;
+
+import pivot.beans.BeanDictionary;
+import pivot.collections.Dictionary;
+import pivot.collections.List;
+
+/**
+ * Implementation of JFreeChart XYDataset.
+ *
+ * @author gbrown
+ */
+@SuppressWarnings("unchecked")
+public class XYSeriesDataset implements XYDataset {
+ private String seriesNameKey;
+ private List<?> chartData;
+
+ private DatasetGroup datasetGroup = null;
+
+ public static final String X_KEY = "x";
+ public static final String Y_KEY = "y";
+
+ public XYSeriesDataset(String seriesNameKey, List<?> chartData) {
+ if (seriesNameKey == null) {
+ throw new IllegalArgumentException("seriesNameKey is null.");
+ }
+
+ if (chartData == null) {
+ throw new IllegalArgumentException("chartData is null.");
+ }
+
+ this.seriesNameKey = seriesNameKey;
+ this.chartData = chartData;
+ }
+
+ public DatasetGroup getGroup() {
+ return datasetGroup;
+ }
+
+ public void setGroup(DatasetGroup datasetGroup) {
+ this.datasetGroup = datasetGroup;
+ }
+
+ public int getSeriesCount() {
+ return chartData.getLength();
+ }
+
+ public Comparable getSeriesKey(int seriesIndex) {
+ Dictionary<String, ?> seriesDictionary = getSeriesDictionary(seriesIndex);
+ return (String)seriesDictionary.get(seriesNameKey);
+ }
+
+ public int indexOf(Comparable seriesName) {
+ if (seriesName == null) {
+ throw new IllegalArgumentException("seriesName is null.");
+ }
+
+ int index = -1;
+ for (int i = 0, n = chartData.getLength(); i < n && index == -1; i++) {
+ Dictionary<String, ?> seriesDictionary = getSeriesDictionary(i);
+
+ if (seriesName.compareTo(seriesDictionary.get(seriesNameKey)) == 0) {
+ index = i;
+ }
+ }
+
+ return index;
+ }
+
+ public DomainOrder getDomainOrder() {
+ return DomainOrder.NONE;
+ }
+
+ public int getItemCount(int seriesIndex) {
+ List<?> series = getSeries(seriesIndex);
+ return series.getLength();
+ }
+
+ public Number getX(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(X_KEY);
+ if (value == null) {
+ throw new NullPointerException(X_KEY + " is null.");
+ }
+
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+
+ return (Number)value;
+ }
+
+ public double getXValue(int seriesIndex, int itemIndex) {
+ return getX(seriesIndex, itemIndex).doubleValue();
+ }
+
+ public Number getY(int seriesIndex, int itemIndex) {
+ Dictionary<String, ?> itemDictionary = getItemDictionary(seriesIndex, itemIndex);
+
+ Object value = itemDictionary.get(Y_KEY);
+ if (value == null) {
+ throw new NullPointerException(Y_KEY + " is null.");
+ }
+
+ if (value instanceof String) {
+ value = Double.parseDouble((String)value);
+ }
+
+ return (Number)value;
+ }
+
+ public double getYValue(int seriesIndex, int itemIndex) {
+ return getY(seriesIndex, itemIndex).doubleValue();
+ }
+
+ private List<?> getSeries(int seriesIndex) {
+ if (seriesIndex < 0
+ || seriesIndex > chartData.getLength() - 1) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ List<?> series = (List<?>)chartData.get(seriesIndex);
+ return series;
+ }
+
+ protected Dictionary<String, ?> getSeriesDictionary(int seriesIndex) {
+ List<?> series = getSeries(seriesIndex);
+
+ Dictionary<String, ?> seriesDictionary;
+ if (series instanceof Dictionary<?, ?>) {
+ seriesDictionary = (Dictionary<String, ?>)series;
+ } else {
+ seriesDictionary = new BeanDictionary(series);
+ }
+
+ return seriesDictionary;
+ }
+
+ protected Dictionary<String, ?> getItemDictionary(int seriesIndex, int itemIndex) {
+ List<?> series = getSeries(seriesIndex);
+
+ if (itemIndex < 0
+ || itemIndex > series.getLength() - 1) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ Object item = series.get(itemIndex);
+
+ Dictionary<String, ?> itemDictionary;
+ if (item instanceof Dictionary<?, ?>) {
+ itemDictionary = (Dictionary<String, ?>)item;
+ } else {
+ itemDictionary = new BeanDictionary(item);
+ }
+
+ return itemDictionary;
+ }
+
+ public void addChangeListener(DatasetChangeListener listener) {
+ // No-op
+ }
+
+ public void removeChangeListener(DatasetChangeListener listener) {
+ // No-op
+ }
+}
Added: incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/package.html
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/package.html?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/package.html (added)
+++ incubator/pivot/branches/1.1/charts/src/pivot/charts/skin/package.html Wed Mar 25 23:08:38 2009
@@ -0,0 +1,6 @@
+<html>
+<head></head>
+<body>
+<p>Contains skin classes for charting components.</p>
+</body>
+</html>
Added: incubator/pivot/branches/1.1/core-test/.classpath
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/.classpath?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/.classpath (added)
+++ incubator/pivot/branches/1.1/core-test/.classpath Wed Mar 25 23:08:38 2009
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/core"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: incubator/pivot/branches/1.1/core-test/.project
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/.project?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/.project (added)
+++ incubator/pivot/branches/1.1/core-test/.project Wed Mar 25 23:08:38 2009
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>core-test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/BinarySerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/BinarySerializerTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/BinarySerializerTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/BinarySerializerTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.core.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import pivot.serialization.Serializer;
+import pivot.serialization.BinarySerializer;
+
+public class BinarySerializerTest {
+
+ public static void main(String[] args) {
+ Serializer<Object> serializer = new BinarySerializer();
+
+ Object[] testData = {
+ "Hello World",
+ 123.456,
+ true
+ };
+
+ ByteArrayOutputStream outputStream = null;
+ try {
+ try {
+ outputStream = new ByteArrayOutputStream();
+ serializer.writeObject(testData, outputStream);
+ } finally {
+ outputStream.close();
+ }
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+
+ ByteArrayInputStream inputStream = null;
+ try {
+ try {
+ inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ testData = (Object[])serializer.readObject(inputStream);
+
+ for (int i = 0, n = testData.length; i < n; i++) {
+ System.out.println("[" + i + "] " + testData[i]);
+ }
+ } finally {
+ inputStream.close();
+ }
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+ }
+}
Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/CSVSerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/CSVSerializerTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/CSVSerializerTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/CSVSerializerTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.core.test;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import pivot.collections.List;
+import pivot.serialization.CSVSerializer;
+
+public class CSVSerializerTest {
+ public static String[] testStrings = {
+ "\"Y\"\"HO,O\",26.11,-0.33,X",
+ "0,1,2,3\nQ,5,6,7\n8,9,10,11",
+ "a,b,c,d",
+ "hello,world",
+ "2,4,6,8,10"
+ };
+
+ public static void main(String[] args) {
+ CSVSerializer csvSerializer = new CSVSerializer();
+ csvSerializer.getKeys().add("A");
+ csvSerializer.getKeys().add("B");
+ csvSerializer.getKeys().add("C");
+ csvSerializer.getKeys().add("D");
+
+ for (int i = 0, n = testStrings.length; i < n; i++) {
+ try {
+ System.out.println("Input: " + testStrings[i]);
+ List<?> objects = csvSerializer.readObject(new StringReader(testStrings[i]));
+
+ StringWriter writer = new StringWriter();
+ csvSerializer.writeObject(objects, writer);
+ System.out.println("Output: " + writer);
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+ }
+ }
+}
Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/JSONSerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/JSONSerializerTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/JSONSerializerTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/JSONSerializerTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.core.test;
+
+import java.io.InputStream;
+// import java.io.OutputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import pivot.collections.HashMap;
+import pivot.collections.List;
+import pivot.collections.Map;
+import pivot.serialization.JSONSerializer;
+
+public class JSONSerializerTest {
+ public static String[] testStrings = {
+ "'hey\there'",
+ "'hey\\there'",
+ "'hey\\\\there'",
+ " null",
+ "\"Hello\\\" World\"",
+ "'Hello\\\' \"World'",
+ "\"ABCD",
+ " 10",
+ "+10",
+ " -10",
+ "10.1",
+ "+10.1",
+ "-1s0.1",
+ "true",
+ "false",
+ " [ 0, 1, 2, [3, 4]",
+ " [ \"A\", \"B\", \t\"C\", [\t0, 1, 2, 'abc', true]]",
+ "['A', 'B', 'C']",
+ "{ }",
+ "{null: 'foo'}",
+ "{: 'foo'}",
+ "{\"\": \"foo\"}",
+ "{ my0: 'ABCD\"ABCD' , 'my' : '\"My \\ example 3\"', null: null}",
+ "{a:null}",
+ "{a:''}",
+ "{a:1, b:2",
+ "{\"1a\" : 0, bc : 'hello', n:-100.56, c:true, d:{e:10, f:20}, g:{aa:10, bb:20, cc:30}, m:[1,2, 4]}",
+ "{\"a#b\" : '#ff'}"
+ };
+
+ public static void main(String[] args) {
+ test0();
+ // test1();
+ // test2();
+ test3();
+ }
+
+ public static void test0() {
+ HashMap<String, Object> a = new HashMap<String, Object>();
+ a.put("b", 100);
+
+ HashMap<String, Object> c = new HashMap<String, Object>();
+ c.put("d", "Hello World");
+ a.put("c", c);
+
+ StringWriter writer = new StringWriter();
+ JSONSerializer jsonSerializer = new JSONSerializer();
+ try {
+ jsonSerializer.writeObject(a, writer);
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+
+ System.out.println("Output: " + writer);
+ }
+
+ public static void test1() {
+ JSONSerializer jsonSerializer = new JSONSerializer();
+
+ for (int i = 0, n = testStrings.length; i < n; i++) {
+ try {
+ System.out.println("Input: " + testStrings[i]);
+ Object object = jsonSerializer.readObject(new StringReader(testStrings[i]));
+ System.out.println("Object: " + object);
+ StringWriter writer = new StringWriter();
+ jsonSerializer.writeObject(object, writer);
+
+ System.out.println("Output: " + writer);
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+ }
+
+ int i = Integer.MAX_VALUE;
+ long l1 = (long)i + 1;
+ long l2 = Long.MAX_VALUE;
+ float f = Float.MAX_VALUE;
+ double d1 = (double)f + 1;
+ double d2 = Double.MAX_VALUE;
+ String listString = "[" + i + ", " + l1 + ", " + l2 + ", "
+ + f + ", " + d1 + ", " + d2 + "]";
+ List<?> list = JSONSerializer.parseList(listString);
+ for (Object item : list) {
+ System.out.println(item);
+ }
+
+ Map<String, ?> map = JSONSerializer.parseMap("{a:100, b:200, c:300}");
+ for (String key : map) {
+ System.out.println(key + ":" + map.get(key));
+ }
+ }
+
+ public static void test2() {
+ testMap("{a: {b: [{cd:'hello'}, {c:'world'}]}}", "a.b[0].cd");
+ testMap("{a: {b: [{c:'hello'}, {c:'world'}]}}", "['a'].b[0].c");
+ testMap("{a: {b: [{c:'hello'}, {c:'world'}]}}", "a[\"b\"][0]['c']");
+ testMap("{a: {b: [{c:'hello'}, {c:'world'}]}}", "a.");
+ testMap("{a: {b: [{c:'hello', d:[0, 1, 2, 3, 4]}, {c:'world'}]}}", "a.b[0].d[2]");
+ testMap("{a: {b: [{c:'hello', d:[0, 1, 2, 3, 4]}, {c:'world'}]}}", "a.....");
+ testMap("{abc: {def: [{ghi:'hello', d:[0, 1, 2, 3, 4]}, {c:'world'}]}}", "abc.def[0].ghi");
+
+ testList("[[0, 1, 2], [3, 4, 5]]", "[1]");
+ testList("[[0, 1, 2], [3, 4, 5]]", "[1][0]");
+ testList("[[0, 1, 2], [3, 4, 5]]", "[1][0].c");
+ testList("[[0, 1, 2], [3, 4, 5]]", "[1][]");
+ testList("[[0, 1, 2], [3, 4, 5]]", "[1][0][0]");
+ }
+
+ public static void test3() {
+ JSONSerializer serializer = new JSONSerializer("ISO-8859-1");
+ InputStream inputStream = JSONSerializerTest.class.getResourceAsStream("json_serializer_test.json");
+
+ Object root = null;
+ try {
+ root = serializer.readObject(inputStream);
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+
+ if (root != null) {
+ System.out.println(JSONSerializer.getString(root, "foo"));
+ System.out.println(JSONSerializer.getString(root, "bar"));
+ }
+
+ try {
+ serializer.writeObject(root, System.out);
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+ }
+
+ private static void testList(String list, String path) {
+ JSONSerializer jsonSerializer = new JSONSerializer();
+
+ try {
+ jsonSerializer.writeObject(JSONSerializer.getValue(JSONSerializer.parseList(list), path),
+ System.out);
+ System.out.println();
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+ }
+
+ private static void testMap(String map, String path) {
+ JSONSerializer jsonSerializer = new JSONSerializer();
+
+ try {
+ jsonSerializer.writeObject(JSONSerializer.getValue(JSONSerializer.parseMap(map), path),
+ System.out);
+ System.out.println();
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+ }
+}
Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/ListenerListTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/ListenerListTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/ListenerListTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/ListenerListTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,76 @@
+package pivot.core.test;
+
+import pivot.util.ListenerList;
+
+public class ListenerListTest {
+ public static class TestHandler implements TestListener {
+ private int id;
+
+ public TestHandler(int id) {
+ this.id = id;
+ }
+
+ public void eventFired(TestSource testSource) {
+ System.out.println("Event processed by " + id);
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toString(id);
+ }
+ }
+
+ public static void main(String[] args) {
+ TestListener listener1 = new TestHandler(1);
+
+ TestListener listener2 = new TestHandler(2) {
+ public void eventFired(TestSource testSource) {
+ System.out.println("Removing listener 2");
+ testSource.getTestListeners().remove(this);
+ }
+ };
+
+ TestListener listener3 = new TestHandler(3);
+ TestListener listener4 = new TestHandler(4);
+
+ final TestSource testSource = new TestSource();
+ testSource.getTestListeners().add(listener1);
+ testSource.getTestListeners().add(listener2);
+ testSource.getTestListeners().add(listener3);
+ testSource.getTestListeners().add(listener4);
+ testSource.getTestListeners().add(listener3);
+ testSource.getTestListeners().add(listener4);
+
+ // testSource.getTestListeners().remove(listener1);
+ // testSource.getTestListeners().remove(listener4);
+
+ testSource.getTestListeners().add(listener1);
+
+ testSource.fireEvent();
+ }
+}
+
+interface TestListener {
+ public void eventFired(TestSource testSource);
+}
+
+class TestSource {
+ private static class TestListenerList extends ListenerList<TestListener>
+ implements TestListener {
+ public void eventFired(TestSource testSource) {
+ for (TestListener listener : this) {
+ listener.eventFired(testSource);
+ }
+ }
+ }
+
+ private TestListenerList testListeners = new TestListenerList();
+
+ public void fireEvent() {
+ testListeners.eventFired(this);
+ }
+
+ public ListenerList<TestListener> getTestListeners() {
+ return testListeners;
+ }
+}
\ No newline at end of file
Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/MIMETypeTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/MIMETypeTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/MIMETypeTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/MIMETypeTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,13 @@
+package pivot.core.test;
+
+import pivot.util.MIMEType;
+
+public class MIMETypeTest {
+ public static void main(String[] args) {
+ MIMEType mimeType = MIMEType.decode("foo; a=123; b=456; c=789");
+ System.out.println("Base type: " + mimeType.getBaseType());
+ System.out.println("a: " + mimeType.get("a"));
+ System.out.println("b: " + mimeType.get("b"));
+ System.out.println("c: " + mimeType.get("c"));
+ }
+}
Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/PropertiesSerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/PropertiesSerializerTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/PropertiesSerializerTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/PropertiesSerializerTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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 pivot.core.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import pivot.collections.HashMap;
+import pivot.collections.Map;
+import pivot.serialization.PropertiesSerializer;
+import pivot.serialization.Serializer;
+
+public class PropertiesSerializerTest
+{
+ @SuppressWarnings("unchecked")
+ public static void main(String[] args) {
+ Serializer serializer = new PropertiesSerializer();
+
+ Map<String, Object> testMap = new HashMap<String, Object>();
+ testMap.put("hello", "Hello World");
+ testMap.put("number", 123.456);
+ testMap.put("boolean", true);
+ testMap.put("i18n", " & ×××עש"); // test some chars to encode ...
+ testMap.put("object", new Object());
+
+ ByteArrayOutputStream outputStream = null;
+ try {
+ try {
+ outputStream = new ByteArrayOutputStream();
+ serializer.writeObject(testMap, outputStream);
+ } finally {
+ outputStream.close();
+
+ String dump = new String(outputStream.toByteArray());
+ System.out.println("Succesfully Written");
+ System.out.println(dump);
+ }
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+
+ ByteArrayInputStream inputStream = null;
+ Map<String, Object> readData = null;
+ try {
+ try {
+ inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ readData = (Map<String, Object>) serializer.readObject(inputStream);
+
+ System.out.println("Succesfully Read");
+ for (String key : readData) {
+ System.out.println(key + "=" + readData.get(key));
+ }
+ } finally {
+ inputStream.close();
+ }
+ } catch(Exception exception) {
+ System.out.println(exception);
+ }
+ }
+
+}