From: <jo...@us...> - 2008-04-16 13:31:28
|
Revision: 239 http://mspsim.svn.sourceforge.net/mspsim/?rev=239&view=rev Author: joxe Date: 2008-04-16 06:31:27 -0700 (Wed, 16 Apr 2008) Log Message: ----------- fixed the line sample chart to be an XYSeries chart. Modified Paths: -------------- mspsim/se/sics/mspsim/cli/WindowDataHandler.java mspsim/se/sics/mspsim/cli/WindowTarget.java mspsim/se/sics/mspsim/extutil/jfreechart/LineSampleChart.java mspsim/se/sics/mspsim/util/NetworkConnection.java Added Paths: ----------- mspsim/se/sics/mspsim/cli/AbstractWindowDataHandler.java Added: mspsim/se/sics/mspsim/cli/AbstractWindowDataHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/AbstractWindowDataHandler.java (rev 0) +++ mspsim/se/sics/mspsim/cli/AbstractWindowDataHandler.java 2008-04-16 13:31:27 UTC (rev 239) @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of the Institute nor 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of MSPSim. + * + * $Id: AsyncCommand.java 187 2008-03-17 19:34:12Z joxe $ + * + * ----------------------------------------------------------------- + * + * + * Author : Joakim Eriksson + * Created : 9 april 2008 + * Updated : $Date: 2008-03-17 20:34:12 +0100 (Mon, 17 Mar 2008) $ + * $Revision: 187 $ + */ +package se.sics.mspsim.cli; + +import javax.swing.JComponent; + +/** + * @author joakime + * + */ +public abstract class AbstractWindowDataHandler implements WindowDataHandler { + + @Override + public void handleCommand(String[] parts) { + String cmd = parts[0]; + if ("set".equals(cmd)) { + int index = atoi(parts[1]); + String[] args = new String[parts.length - 3]; + System.arraycopy(parts, 3, args, 0, args.length); + setProperty(index, parts[2], args); + } + } + + public abstract void setProperty(int index, String param, String[] args); + + public int atoi(String data) { + return Integer.parseInt(data); + } + +} Modified: mspsim/se/sics/mspsim/cli/WindowDataHandler.java =================================================================== --- mspsim/se/sics/mspsim/cli/WindowDataHandler.java 2008-04-16 13:26:40 UTC (rev 238) +++ mspsim/se/sics/mspsim/cli/WindowDataHandler.java 2008-04-16 13:31:27 UTC (rev 239) @@ -47,5 +47,6 @@ * */ public interface WindowDataHandler extends LineListener { - public JComponent getJComponent(); + public JComponent getComponent(); + public void handleCommand(String[] parts); } Modified: mspsim/se/sics/mspsim/cli/WindowTarget.java =================================================================== --- mspsim/se/sics/mspsim/cli/WindowTarget.java 2008-04-16 13:26:40 UTC (rev 238) +++ mspsim/se/sics/mspsim/cli/WindowTarget.java 2008-04-16 13:31:27 UTC (rev 239) @@ -9,13 +9,15 @@ private JFrame window; private String targetName; - private JTextArea jta = new JTextArea(20,20); + // Default in the current version - TODO: replace with better + private JTextArea jta = new JTextArea(40,40); private WindowDataHandler dataHandler = null; public WindowTarget(String name) { window = new JFrame(name); + window.getContentPane().add(jta); + window.pack(); window.setVisible(true); - window.getContentPane().add(jta); targetName = name; } @@ -24,6 +26,7 @@ // TODO Auto-generated method stub if (line != null && line.startsWith("#!")) { line = line.substring(2); + // TODO: replace with command parser String[] parts = line.split(" "); String cmd = parts[0]; if ("bounds".equals(cmd)) { @@ -42,8 +45,10 @@ if (dataHandler != null) { System.out.println("Replacing window data handler! " + parts[1] + " " + dataHandler); window.getContentPane().removeAll(); - window.getContentPane().add(dataHandler.getJComponent()); + window.getContentPane().add(dataHandler.getComponent()); } + } else if (dataHandler != null) { + dataHandler.handleCommand(parts); } } else { if (dataHandler != null) { Modified: mspsim/se/sics/mspsim/extutil/jfreechart/LineSampleChart.java =================================================================== --- mspsim/se/sics/mspsim/extutil/jfreechart/LineSampleChart.java 2008-04-16 13:26:40 UTC (rev 238) +++ mspsim/se/sics/mspsim/extutil/jfreechart/LineSampleChart.java 2008-04-16 13:31:27 UTC (rev 239) @@ -3,37 +3,32 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; -import java.util.Date; - import javax.swing.JComponent; import javax.swing.JPanel; - import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.DefaultXYItemRenderer; -import org.jfree.data.time.Millisecond; -import org.jfree.data.time.TimeSeries; -import org.jfree.data.time.TimeSeriesCollection; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import se.sics.mspsim.cli.AbstractWindowDataHandler; -import se.sics.mspsim.cli.WindowDataHandler; -public class LineSampleChart implements WindowDataHandler { +public class LineSampleChart extends AbstractWindowDataHandler { JPanel panel; - private TimeSeriesCollection dataset; - private TimeSeries timeSeries; + private XYSeriesCollection dataset; + private XYSeries dataSeries; public LineSampleChart() { - DateAxis domain = new DateAxis("Time"); + NumberAxis domain = new NumberAxis("Index"); NumberAxis range = new NumberAxis("Value"); XYPlot xyplot = new XYPlot(); xyplot.setDomainAxis(domain); xyplot.setRangeAxis(range); // xyplot.setBackgroundPaint(Color.black); - xyplot.setDataset(dataset = new TimeSeriesCollection()); + xyplot.setDataset(dataset = new XYSeriesCollection()); DefaultXYItemRenderer renderer = new DefaultXYItemRenderer(); renderer.setSeriesPaint(0, Color.black); @@ -54,23 +49,35 @@ panel.setPreferredSize(new Dimension(400, 200)); panel.add(chartPanel, BorderLayout.CENTER); - timeSeries = new TimeSeries("-", Millisecond.class); - timeSeries.setMaximumItemCount(200); - dataset.addSeries(timeSeries); + dataSeries = new XYSeries("-"); + dataSeries.setMaximumItemCount(200); + dataset.addSeries(dataSeries); } - public JComponent getJComponent() { + public JComponent getComponent() { return panel; } @Override public void lineRead(String line) { - System.out.println("Got line to: " + line); String parts[] = line.trim().split(" "); - timeSeries.clear(); + dataSeries.clear(); for (int i = 0; i < parts.length; i++) { - timeSeries.add(new Millisecond(new Date(i)), Integer.parseInt(parts[i])); + dataSeries.add(i, atoi(parts[i])); } panel.repaint(); } + + @Override + public void setProperty(int index, String param, String[] args) { + if (index != 0) { + throw new IndexOutOfBoundsException("Illegal index: " + index); + } + if ("label".equals(param)) { + System.out.println("setting label to: " + args[0]); + dataSeries.setKey(args[0]); + } + panel.repaint(); + } + } Modified: mspsim/se/sics/mspsim/util/NetworkConnection.java =================================================================== --- mspsim/se/sics/mspsim/util/NetworkConnection.java 2008-04-16 13:26:40 UTC (rev 238) +++ mspsim/se/sics/mspsim/util/NetworkConnection.java 2008-04-16 13:31:27 UTC (rev 239) @@ -103,7 +103,8 @@ } } - // Data incoming from the network!!! + // Data incoming from the network!!! - forward to radio and if server, to + // all other nodes private void dataReceived(byte[] data, int len, ConnectionThread source) { int[] buf = new int[len]; if (listener != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |