Package org.thingml.generated

Source Code of org.thingml.generated.WeatherStationRPiMock

/**
* File generated by the ThingML IDE
* /!\Do not edit this file/!\
* In case of a bug in the generated code,
* please submit an issue on our GitHub
**/

package org.thingml.generated;
import org.sintef.smac.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
import java.text.SimpleDateFormat;
import scala.collection.immutable.$colon$colon;

public class WeatherStationRPiMock extends ReactiveComponent implements ActionListener {

@Override
public void onIncomingMessage(SignedEvent e) {
print(e.event().name() + "_via_" + e.port().name(), dateFormat.format(new Date()) + ": " + e.event().toString());
}
Port port_WeatherStationRPi_RemoteControlIn = null;
Port port_WeatherStationRPi_RemoteControlOut = null;

java.util.List<WeatherStationRPiListener> listeners = new java.util.LinkedList<WeatherStationRPiListener>();

public WeatherStationRPiMock(){
scala.collection.immutable.List<String> rec = null;
scala.collection.immutable.List<String> sent = null;
rec = scala.collection.immutable.List$.MODULE$.empty();
sent = scala.collection.immutable.List$.MODULE$.empty();
rec = new $colon$colon("temperature", rec);
rec = new $colon$colon("light", rec);
port_WeatherStationRPi_RemoteControlIn = (Port) new Port("RemoteControlIn", rec, sent, this).start();
rec = scala.collection.immutable.List$.MODULE$.empty();
sent = scala.collection.immutable.List$.MODULE$.empty();
sent = new $colon$colon("changeDisplay", sent);
port_WeatherStationRPi_RemoteControlOut = (Port) new Port("RemoteControlOut", rec, sent, this).start();
init();}

private SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyy 'at' HH:mm:ss.SSS");private JTabbedPane tabbedPane = new JTabbedPane();
private JFrame frame;
private JPanel frame_RemoteControlIn;
private JPanel frame_RemoteControlOut;
private JTextPane screen;
private JButton clearButton;
private StyledDocument doc;

//Attributes related to changeDisplay via RemoteControlOut
public JButton sendchangeDisplay_via_RemoteControlOut;
public JButton getSendchangeDisplay_via_RemoteControlOut() {
return sendchangeDisplay_via_RemoteControlOut;
}

public void disableAll() {
sendchangeDisplay_via_RemoteControlOut.setEnabled(false);
}

public void enableAll() {
sendchangeDisplay_via_RemoteControlOut.setEnabled(true);
}

public void print(String id, String data){
try {
doc.insertString(doc.getLength(), formatForPrint(data), doc.getStyle("receive"+id+"Style"));
screen.setCaretPosition(doc.getLength());
} catch (BadLocationException ex) {
ex.printStackTrace();
}
}

public void addListener(ActionListener l){
sendchangeDisplay_via_RemoteControlOut.addActionListener(l);
}

private void init(){
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(0,3,0,3);
clearButton = new JButton("Clear Console");
c.gridy = 0;
c.gridx = 0;
frame = new JFrame("WeatherStationRPi Mock Simulator");
frame.setLayout(new GridBagLayout());
frame.add(tabbedPane, c);
frame_RemoteControlIn = new JPanel();
frame_RemoteControlIn.setLayout(new GridBagLayout());
frame_RemoteControlOut = new JPanel();
frame_RemoteControlOut.setLayout(new GridBagLayout());
//GUI related to RemoteControlOut_via_RemoteControlOut => changeDisplay
c.gridy = 0;
c.gridx = 0;
frame_RemoteControlOut.add(createLabel("changeDisplay"), c);
c.gridy = 1;
c.gridx = 0;
frame_RemoteControlOut.add(createchangeDisplay_via_RemoteControlOutPanel(), c);
c.gridy = 2;
c.gridx = 0;
sendchangeDisplay_via_RemoteControlOut = createSendButton("RemoteControlOut => changeDisplay");
frame_RemoteControlOut.add(sendchangeDisplay_via_RemoteControlOut, c);
tabbedPane.addTab("RemoteControlOut", frame_RemoteControlOut);
c.gridy = 1;
c.gridx = 0;
c.gridwidth = 1;
frame.add(createJTextPane(), c);
c.gridy = 2;
frame.add(clearButton, c);
frame.pack();
clearButton.addActionListener(this);
addListener(this);
frame.setVisible(true);
}

public static JLabel createLabel(String name){
return new JLabel(name);
}

public static JButton createSendButton(String name){
return new JButton("send");
}

public JPanel createchangeDisplay_via_RemoteControlOutPanel(){
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
JPanel panel = new JPanel(new GridBagLayout());
return panel;
}

public JScrollPane createJTextPane(){
screen = new JTextPane();
screen.setFocusable(false);
screen.setEditable(false);
screen.setAutoscrolls(true);
JScrollPane editorScrollPane = new JScrollPane(screen);
editorScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
editorScrollPane.setPreferredSize(new Dimension(480, 240));
editorScrollPane.setMinimumSize(new Dimension(320, 160));
doc = screen.getStyledDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style receivetemperature_via_RemoteControlInStyle = doc.addStyle("receivetemperature_via_WeatherStationRPi_RemoteControlInStyle", def);
StyleConstants.setForeground(receivetemperature_via_RemoteControlInStyle, new Color(17, 28, 59));
Style receivelight_via_RemoteControlInStyle = doc.addStyle("receivelight_via_WeatherStationRPi_RemoteControlInStyle", def);
StyleConstants.setForeground(receivelight_via_RemoteControlInStyle, new Color(67, 153, 139));
return editorScrollPane;
}

private String formatForPrint(String text) {
return (text.endsWith("\n") ? text : text + "\n");
}

@Override
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == clearButton){
screen.setText("");
}
else if ( ae.getSource() == getSendchangeDisplay_via_RemoteControlOut()) {
port_WeatherStationRPi_RemoteControlOut.send(new ChangeDisplay(ChangeDisplay$.MODULE$.getName()));
for(WeatherStationRPiListener l : listeners)
l.onChangeDisplay_via_RemoteControlOut();
}
}

public static void main(String args[]){
WeatherStationRPiMock mock = new WeatherStationRPiMock();
WeatherStationRPiMockMirror mockMirror = new WeatherStationRPiMockMirror();
Channel c_RemoteControlIn_13397307 = new Channel();
c_RemoteControlIn_13397307.connect(mock.port_WeatherStationRPi_RemoteControlIn, mockMirror.port_WeatherStationRPi_RemoteControlIn);
c_RemoteControlIn_13397307.connect(mockMirror.port_WeatherStationRPi_RemoteControlIn, mock.port_WeatherStationRPi_RemoteControlIn);
c_RemoteControlIn_13397307.start();
Channel c_RemoteControlOut_25563140 = new Channel();
c_RemoteControlOut_25563140.connect(mock.port_WeatherStationRPi_RemoteControlOut, mockMirror.port_WeatherStationRPi_RemoteControlOut);
c_RemoteControlOut_25563140.connect(mockMirror.port_WeatherStationRPi_RemoteControlOut, mock.port_WeatherStationRPi_RemoteControlOut);
c_RemoteControlOut_25563140.start();
}
}
TOP

Related Classes of org.thingml.generated.WeatherStationRPiMock

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.