diff --git a/dist/xchart-1.0.0.jar b/dist/xchart-1.0.0.jar
new file mode 100644
index 0000000000000000000000000000000000000000..975bb4a371b0e9f5d73755946336444a7e9f1b5d
Binary files /dev/null and b/dist/xchart-1.0.0.jar differ
diff --git a/src/com/xeiam/swing/ButtonDemo.java b/src/com/xeiam/swing/ButtonDemo.java
new file mode 100644
index 0000000000000000000000000000000000000000..a14854925695eaba312711338f4db5bc6ce3bc23
--- /dev/null
+++ b/src/com/xeiam/swing/ButtonDemo.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of Oracle or the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package com.xeiam.swing;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+
+import javax.swing.AbstractButton;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+/*
+ * ButtonDemo.java requires the following files:
+ * images/right.gif
+ * images/middle.gif
+ * images/left.gif
+ */
+public class ButtonDemo extends JPanel implements ActionListener {
+ protected JButton b1, b2, b3;
+
+ public ButtonDemo() {
+ ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
+ ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
+ ImageIcon rightButtonIcon = createImageIcon("images/left.gif");
+
+ b1 = new JButton("Disable middle button", leftButtonIcon);
+ b1.setVerticalTextPosition(AbstractButton.CENTER);
+ b1.setHorizontalTextPosition(AbstractButton.LEADING); // aka LEFT, for left-to-right locales
+ b1.setMnemonic(KeyEvent.VK_D);
+ b1.setActionCommand("disable");
+
+ b2 = new JButton("Middle button", middleButtonIcon);
+ b2.setVerticalTextPosition(AbstractButton.BOTTOM);
+ b2.setHorizontalTextPosition(AbstractButton.CENTER);
+ b2.setMnemonic(KeyEvent.VK_M);
+
+ b3 = new JButton("Enable middle button", rightButtonIcon);
+ // Use the default text position of CENTER, TRAILING (RIGHT).
+ b3.setMnemonic(KeyEvent.VK_E);
+ b3.setActionCommand("enable");
+ b3.setEnabled(false);
+
+ // Listen for actions on buttons 1 and 3.
+ b1.addActionListener(this);
+ b3.addActionListener(this);
+
+ b1.setToolTipText("Click this button to disable the middle button.");
+ b2.setToolTipText("This middle button does nothing when you click it.");
+ b3.setToolTipText("Click this button to enable the middle button.");
+
+ // Add Components to this container, using the default FlowLayout.
+ add(b1);
+ add(b2);
+ add(b3);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if ("disable".equals(e.getActionCommand())) {
+ b2.setEnabled(false);
+ b1.setEnabled(false);
+ b3.setEnabled(true);
+ } else {
+ b2.setEnabled(true);
+ b1.setEnabled(true);
+ b3.setEnabled(false);
+ }
+ }
+
+ /** Returns an ImageIcon, or null if the path was invalid. */
+ protected static ImageIcon createImageIcon(String path) {
+ java.net.URL imgURL = ButtonDemo.class.getResource(path);
+ if (imgURL != null) {
+ return new ImageIcon(imgURL);
+ } else {
+ System.err.println("Couldn't find file: " + path);
+ return null;
+ }
+ }
+
+ /**
+ * Create the GUI and show it. For thread safety, this method should be invoked from the event-dispatching thread.
+ */
+ private static void createAndShowGUI() {
+
+ // Create and set up the window.
+ JFrame frame = new JFrame("ButtonDemo");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ // Create and set up the content pane.
+ ButtonDemo newContentPane = new ButtonDemo();
+ newContentPane.setOpaque(true); // content panes must be opaque
+ frame.setContentPane(newContentPane);
+
+ // Display the window.
+ frame.pack();
+ frame.setVisible(true);
+ }
+
+ public static void main(String[] args) {
+ // Schedule a job for the event-dispatching thread:
+ // creating and showing this application's GUI.
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ createAndShowGUI();
+ }
+ });
+ }
+}
diff --git a/src/com/xeiam/swing/SwingHelper.java b/src/com/xeiam/swing/SwingHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..8ec2783d969202b9d844d9ae1da22a1ece446f73
--- /dev/null
+++ b/src/com/xeiam/swing/SwingHelper.java
@@ -0,0 +1,55 @@
+package com.xeiam.swing;
+
+import javax.swing.BoxLayout;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+import com.xeiam.xcharts.Chart;
+import com.xeiam.xcharts.JChartPanel;
+
+public class SwingHelper {
+
+ Chart[] charts;
+
+ public SwingHelper(Chart chart) {
+ this.charts = new Chart[1];
+ charts[0] = chart;
+ }
+
+ public SwingHelper(Chart[] charts) {
+ this.charts = charts;
+ }
+
+ /**
+ * Create the GUI and show it. For thread safety, this method should be invoked from the event-dispatching thread.
+ */
+ private void createAndShowGUI() {
+
+ // Create and set up the window.
+ JFrame frame = new JFrame("XChart");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
+
+ for (int i = 0; i < charts.length; i++) {
+ JPanel chartPanel = new JChartPanel(charts[i]);
+ frame.getContentPane().add(chartPanel);
+ }
+
+ // frame.setContentPane(newContentPane);
+
+ // Display the window.
+ frame.pack();
+ frame.setVisible(true);
+ }
+
+ public void displayChart() {
+ // Schedule a job for the event-dispatching thread:
+ // creating and showing this application's GUI.
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ createAndShowGUI();
+ }
+ });
+ }
+}
diff --git a/src/com/xeiam/xcharts/example/HugeChart.java b/src/com/xeiam/xcharts/example/HugeChart.java
deleted file mode 100644
index 7858eecd6c8e113e91a619bfeaf32c3be89511fc..0000000000000000000000000000000000000000
--- a/src/com/xeiam/xcharts/example/HugeChart.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * Copyright 2011 Xeiam LLC.
- *
- * 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 com.xeiam.xcharts.example;
-
-import java.awt.BorderLayout;
-
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-
-import com.xeiam.xcharts.Chart;
-import com.xeiam.xcharts.JChartPanel;
-import com.xeiam.xcharts.series.Series;
-
-/**
- * @author timmolter
- */
-public class HugeChart {
-
- private static void createAndShowGUI() {
-
- // Create and set up the window.
- JFrame frame = new JFrame("XChart");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setUndecorated(true);
-
- // Create Chart
- Chart chart = new Chart(800, 600);
-
- long t = System.currentTimeMillis();
- // generates linear data
- int b = 1000000;
- double[] xData = new double[b + 1];
- double[] yData = new double[b + 1];
- for (int x = 0; x <= b; x++) {
- xData[x] = x;
- yData[x] = x;
- }
- long t1 = System.currentTimeMillis() - t;
- t = System.currentTimeMillis();
- System.out.println("B:" + System.currentTimeMillis());
- // Customize Chart
- chart.setChartTitle("Sample Chart");
- chart.setXAxisTitle("X");
- chart.setYAxisTitle("Y");
- // chart.setChartTitleVisible(false);
- // chart.setChartLegendVisible(false);
- // chart.setAxisTitlesVisible(false);
-
- Series series = chart.addSeries("big data set", xData, yData);
- // series.setLineColor(SeriesColor.PURPLE);
- // series.setLineStyle(SeriesLineStyle.NONE);
- // series.setMarkerColor(SeriesColor.GREEN);
- // series.setMarker(SeriesMarker.NONE);
-
- // Swing
- JPanel chartPanel = new JChartPanel(chart);
-
- // add the panel to the content pane
- frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
-
- // Display the window
- frame.pack();
- frame.setLocationRelativeTo(null); // centers on screen
- frame.setVisible(true);
-
- long t2 = System.currentTimeMillis() - t;
- System.out.println("Data Generation Time: " + t1);
- System.out.println("Plot Generation Time: " + t2);
- }
-
- public static void main(String[] args) {
-
- // Schedule a job for the event-dispatching thread:
- // creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- createAndShowGUI();
- }
- });
- }
-}
diff --git a/src/com/xeiam/xcharts/example/SwingChart.java b/src/com/xeiam/xcharts/example/SwingChart.java
index d6a7487d9ad81efa662c556fcae848fdd84110ce..2033d512aafd1b09a912f054a3ce0b9911c795c0 100644
--- a/src/com/xeiam/xcharts/example/SwingChart.java
+++ b/src/com/xeiam/xcharts/example/SwingChart.java
@@ -15,14 +15,11 @@
*/
package com.xeiam.xcharts.example;
-import java.awt.BorderLayout;
-
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-
+import com.xeiam.swing.SwingHelper;
import com.xeiam.xcharts.Chart;
-import com.xeiam.xcharts.JChartPanel;
import com.xeiam.xcharts.series.Series;
+import com.xeiam.xcharts.series.SeriesColor;
+import com.xeiam.xcharts.series.SeriesLineStyle;
import com.xeiam.xcharts.series.SeriesMarker;
/**
@@ -32,15 +29,15 @@ public class SwingChart {
private static void createAndShowGUI() {
- // // generates sine data
- // int size = 100;
- // double[] xData1 = new double[size + 1];
- // double[] yData1 = new double[size + 1];
- // for (int i = 0; i <= size; i++) {
- // double radians = (Math.PI / (size / 2) * i);
- // xData1[i] = i - size / 2;
- // yData1[i] = size * Math.sin(radians);
- // }
+ // generates sine data
+ int size = 100;
+ double[] xData1 = new double[size + 1];
+ double[] yData1 = new double[size + 1];
+ for (int i = 0; i <= size; i++) {
+ double radians = (Math.PI / (size / 2) * i);
+ xData1[i] = i - size / 2;
+ yData1[i] = size * Math.sin(radians);
+ }
// generates linear data
int size2 = 100;
@@ -52,9 +49,6 @@ public class SwingChart {
}
// Create and set up the window.
- JFrame frame = new JFrame("XChart");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setUndecorated(true);
// Create Chart
Chart chart = new Chart(800, 600);
@@ -68,29 +62,21 @@ public class SwingChart {
// chart.setAxisTitlesVisible(false);
// Series 1
- // Series series1 = chart.addSeries("y=sin(x)", xData1, yData1);
- // series1.setLineColor(SeriesColor.PURPLE);
- // series1.setLineStyle(SeriesLineStyle.NONE);
- // series1.setMarkerColor(SeriesColor.GREEN);
- // series1.setMarker(SeriesMarker.NONE);
+ Series series1 = chart.addSeries("y=sin(x)", xData1, yData1);
+ series1.setLineColor(SeriesColor.PURPLE);
+ series1.setLineStyle(SeriesLineStyle.NONE);
+ series1.setMarkerColor(SeriesColor.GREEN);
+ series1.setMarker(SeriesMarker.NONE);
// Series 2
- Series series2 = chart.addSeries("y=x", xData2, yData2);
+ // Series series2 = chart.addSeries("y=x", xData2, yData2);
// series2.setLineColor(SeriesColor.PURPLE);
// series2.setLineStyle(SeriesLineStyle.NONE);
// series2.setMarkerColor(SeriesColor.GREEN);
- series2.setMarker(SeriesMarker.NONE);
-
- // Swing
- JPanel chartPanel = new JChartPanel(chart);
-
- // add the panel to the content pane
- frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
+ // series2.setMarker(SeriesMarker.NONE);
- // Display the window
- frame.pack();
- frame.setLocationRelativeTo(null); // centers on screen
- frame.setVisible(true);
+ SwingHelper swingHelper = new SwingHelper(chart);
+ swingHelper.displayChart();
}
public static void main(String[] args) {
diff --git a/src/com/xeiam/xcharts/example/SwingChart2.java b/src/com/xeiam/xcharts/example/SwingChart2.java
index a0d22d13575e8a73eda59b1a26881b8633cc2570..ec068a7c154c65602c4b6e307d853f62330e6c3d 100644
--- a/src/com/xeiam/xcharts/example/SwingChart2.java
+++ b/src/com/xeiam/xcharts/example/SwingChart2.java
@@ -15,13 +15,8 @@
*/
package com.xeiam.xcharts.example;
-import java.awt.BorderLayout;
-
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-
+import com.xeiam.swing.SwingHelper;
import com.xeiam.xcharts.Chart;
-import com.xeiam.xcharts.JChartPanel;
import com.xeiam.xcharts.series.Series;
/**
@@ -31,11 +26,6 @@ public class SwingChart2 {
private static void createAndShowGUI() {
- // Create and set up the window.
- JFrame frame = new JFrame("XChart");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setUndecorated(true);
-
// Create Chart
Chart chart = new Chart(800, 600);
@@ -65,16 +55,8 @@ public class SwingChart2 {
// series.setMarker(SeriesMarker.NONE);
}
- // Swing
- JPanel chartPanel = new JChartPanel(chart);
-
- // add the panel to the content pane
- frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
-
- // Display the window
- frame.pack();
- frame.setLocationRelativeTo(null); // centers on screen
- frame.setVisible(true);
+ SwingHelper swingHelper = new SwingHelper(chart);
+ swingHelper.displayChart();
}
public static void main(String[] args) {
diff --git a/src/com/xeiam/xcharts/example/SwingChart3.java b/src/com/xeiam/xcharts/example/SwingChart3.java
index c0e74bd288d32ce2b5db67d20a3cea9e56c494eb..c78652b7f66c15cdf5f59564293168fe11484494 100644
--- a/src/com/xeiam/xcharts/example/SwingChart3.java
+++ b/src/com/xeiam/xcharts/example/SwingChart3.java
@@ -15,13 +15,8 @@
*/
package com.xeiam.xcharts.example;
-import java.awt.BorderLayout;
-
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-
+import com.xeiam.swing.SwingHelper;
import com.xeiam.xcharts.Chart;
-import com.xeiam.xcharts.JChartPanel;
import com.xeiam.xcharts.series.Series;
/**
@@ -39,11 +34,6 @@ public class SwingChart3 {
double[] xData2 = new double[] { 0.0, 0.0, 0.0 };
double[] yData2 = new double[] { 0.0, 1.0, 2.0 };
- // Create and set up the window.
- JFrame frame = new JFrame("XChart");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setUndecorated(true);
-
// Create Chart
Chart chart = new Chart(800, 600);
@@ -59,16 +49,8 @@ public class SwingChart3 {
Series series1 = chart.addSeries("y=0", xData1, yData1);
Series series2 = chart.addSeries("x=0", xData2, yData2);
- // Swing
- JPanel chartPanel = new JChartPanel(chart);
-
- // add the panel to the content pane
- frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
-
- // Display the window
- frame.pack();
- frame.setLocationRelativeTo(null); // centers on screen
- frame.setVisible(true);
+ SwingHelper swingHelper = new SwingHelper(chart);
+ swingHelper.displayChart();
}
public static void main(String[] args) {
diff --git a/src/com/xeiam/xcharts/example/SwingChart4.java b/src/com/xeiam/xcharts/example/SwingChart4.java
index 0ebd99309407beff927461157ee8bf154c6b4e27..a294877c29283eacaff62e00e4ee8f9b3ae69ca7 100644
--- a/src/com/xeiam/xcharts/example/SwingChart4.java
+++ b/src/com/xeiam/xcharts/example/SwingChart4.java
@@ -15,13 +15,8 @@
*/
package com.xeiam.xcharts.example;
-import java.awt.BorderLayout;
-
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-
+import com.xeiam.swing.SwingHelper;
import com.xeiam.xcharts.Chart;
-import com.xeiam.xcharts.JChartPanel;
import com.xeiam.xcharts.series.Series;
import com.xeiam.xcharts.series.SeriesMarker;
@@ -37,36 +32,24 @@ public class SwingChart4 {
// generates linear data
double[] yData1 = new double[] { 0.0, 0.0, 0.0, -10.0, 15.0, 15.0 };
- // Create and set up the window.
- JFrame frame = new JFrame("XChart");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setUndecorated(true);
-
// Create Chart
- Chart chart = new Chart(800, 600);
+ Chart chart = new Chart(600, 300);
// Customize Chart
chart.setChartTitle("Sample Chart");
chart.setXAxisTitle("X");
chart.setYAxisTitle("Y");
- chart.setChartTitleVisible(false);
- chart.setChartLegendVisible(false);
- chart.setAxisTitlesVisible(false);
+ chart.setChartTitleVisible(true);
+ chart.setChartLegendVisible(true);
+ chart.setAxisTitlesVisible(true);
// Series
Series series1 = chart.addSeries("y=0", null, yData1);
series1.setMarker(SeriesMarker.NONE);
- // Swing
- JPanel chartPanel = new JChartPanel(chart);
-
- // add the panel to the content pane
- frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
+ SwingHelper swingHelper = new SwingHelper(chart);
+ swingHelper.displayChart();
- // Display the window
- frame.pack();
- frame.setLocationRelativeTo(null); // centers on screen
- frame.setVisible(true);
}
public static void main(String[] args) {
diff --git a/src/com/xeiam/xcharts/example/SwingChart5.java b/src/com/xeiam/xcharts/example/SwingChart5.java
new file mode 100644
index 0000000000000000000000000000000000000000..97297f2ee21edf74e4205726e33105687aa3cdca
--- /dev/null
+++ b/src/com/xeiam/xcharts/example/SwingChart5.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2011 Xeiam LLC.
+ *
+ * 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 com.xeiam.xcharts.example;
+
+import com.xeiam.swing.SwingHelper;
+import com.xeiam.xcharts.Chart;
+import com.xeiam.xcharts.series.Series;
+import com.xeiam.xcharts.series.SeriesMarker;
+
+/**
+ * Demonstrated/Tests plotting horizontal and vertical lines
+ *
+ * @author timmolter
+ */
+public class SwingChart5 {
+
+ private static void createAndShowGUI() {
+
+ Chart[] charts = new Chart[3];
+ for (int i = 0; i < charts.length; i++) {
+ charts[i] = getRandomWalkChart(1000);
+ }
+
+ SwingHelper swingHelper = new SwingHelper(charts);
+ swingHelper.displayChart();
+
+ }
+
+ private static Chart getRandomWalkChart(int N) {
+
+ double[] y = new double[N];
+ for (int i = 1; i < y.length; i++) {
+ y[i] = y[i - 1] + Math.random() - .5;
+ }
+
+ // Create Chart
+ Chart chart = new Chart(600, 300);
+
+ // Customize Chart
+ chart.setChartTitle("Random Walk");
+ chart.setXAxisTitle("X");
+ chart.setYAxisTitle("Y");
+ chart.setChartTitleVisible(true);
+ chart.setChartLegendVisible(true);
+ chart.setAxisTitlesVisible(true);
+
+ // Series
+ Series series1 = chart.addSeries("y=0", null, y);
+ series1.setMarker(SeriesMarker.NONE);
+
+ return chart;
+
+ }
+
+ public static void main(String[] args) {
+
+ // Schedule a job for the event-dispatching thread:
+ // creating and showing this application's GUI.
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ createAndShowGUI();
+ }
+ });
+ }
+}