Code Examples
A repository of 155 code examples for BeepBeep
BitmapJFrame.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2017 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 plots;
19 
20 import java.util.Queue;
21 
22 import java.awt.FlowLayout;
23 import javax.swing.ImageIcon;
24 import javax.swing.JFrame;
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
27 
28 import ca.uqac.lif.cep.Processor;
29 import ca.uqac.lif.cep.ProcessorException;
30 import ca.uqac.lif.cep.tmf.Sink;
31 
32 /**
33  * Receives a byte array as an input, and shows it in a Swing
34  * window as a picture. This processor is a sink: it receives
35  * input events, but emits no output events. In the examples of this
36  * package, it is represented graphically as:
37  * <p>
38  * <img src="./doc-files/plots/BitmapJFrame.png" alt="Processor">
39  *
40  * @author Sylvain HallĂ©
41  */
42 public class BitmapJFrame extends Sink
43 {
44  protected transient JFrame m_frame;
45 
46  protected transient JLabel m_label;
47 
48  public BitmapJFrame()
49  {
50  super(1);
51  m_frame = new JFrame("My plot");
52  JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
53  m_frame.add(panel);
54  m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
55  m_label = new JLabel();
56  panel.add(m_label);
57  }
58 
59  @Override
60  public void start()
61  {
62  m_frame.setSize(800, 600);
63  m_frame.setVisible(true);
64  }
65 
66  @Override
67  protected boolean compute(Object[] inputs, Queue<Object[]> outputs) throws ProcessorException
68  {
69  byte[] bytes = (byte[]) inputs[0];
70  m_label.setIcon(new ImageIcon(bytes));
71  return false;
72  }
73 
74  /**
75  * Gets the frame associated to the object
76  * @return The frame
77  */
78  public JFrame getFrame()
79  {
80  return m_frame;
81  }
82 
83  @Override
84  public Processor duplicate(boolean with_state)
85  {
86  // Don't care
87  return null;
88  }
89 }
JFrame getFrame()
Gets the frame associated to the object.
Receives a byte array as an input, and shows it in a Swing window as a picture.