Code Examples
A repository of 155 code examples for BeepBeep
PlotSignal.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2018 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package signal;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.GroupProcessor;
22 import ca.uqac.lif.cep.functions.ApplyFunction;
23 import ca.uqac.lif.cep.mtnp.DrawPlot;
24 import ca.uqac.lif.cep.mtnp.UpdateTableStream;
25 import ca.uqac.lif.cep.tmf.Pump;
26 import ca.uqac.lif.cep.widgets.ToImageIcon;
27 import ca.uqac.lif.cep.widgets.WidgetSink;
28 import ca.uqac.lif.mtnp.plot.gral.Scatterplot;
29 import java.awt.FlowLayout;
30 import javax.swing.JFrame;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 
34 public class PlotSignal extends GroupProcessor
35 {
36  protected Pump m_pump;
37 
38  protected JFrame m_frame;
39 
40  public PlotSignal(String ... col_names)
41  {
42  super(1, 0);
43  UpdateTableStream uts = new UpdateTableStream(col_names);
44  for (int i = 0; i < col_names.length; i++)
45  {
46  associateInput(i, uts, i);
47  }
48  DrawPlot plot = new DrawPlot(new Scatterplot());
49  Connector.connect(uts, plot);
50  ApplyFunction to_icon = new ApplyFunction(ToImageIcon.instance);
51  Connector.connect(plot, to_icon);
52  m_pump = new Pump();
53  Connector.connect(to_icon, m_pump);
54 
55  // Create a frame to display the plot
56  m_frame = new JFrame("My plot");
57  JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
58  m_frame.add(panel);
59  m_frame.setSize(800, 600);
60  m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
61  JLabel label = new JLabel();
62  panel.add(label);
63  WidgetSink sink = new WidgetSink(label);
64  Connector.connect(m_pump, sink);
65  addProcessors(uts, plot, to_icon, m_pump, sink);
66  }
67 
68  @Override
69  public void start()
70  {
71  m_frame.setVisible(true);
72  m_pump.start();
73  }
74 }