Package org.thingml.generated

Source Code of org.thingml.generated.WeatherStationRPiMockMirror

/**
* 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 WeatherStationRPiMockMirror 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<WeatherStationRPiListenerMirror> listeners = new java.util.LinkedList<WeatherStationRPiListenerMirror>();

public WeatherStationRPiMockMirror(){
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();
sent = new $colon$colon("temperature", sent);
sent = new $colon$colon("light", sent);
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();
rec = 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 temperature via RemoteControlIn
public JButton sendtemperature_via_RemoteControlIn;
private JTextField fieldtemperature_via_RemoteControlIn_Temp;
public JButton getSendtemperature_via_RemoteControlIn() {
return sendtemperature_via_RemoteControlIn;
}

public JTextField getFieldtemperature_via_RemoteControlIn_Temp() {
return fieldtemperature_via_RemoteControlIn_Temp;
}

//Attributes related to light via RemoteControlIn
public JButton sendlight_via_RemoteControlIn;
private JTextField fieldlight_via_RemoteControlIn_Light;
public JButton getSendlight_via_RemoteControlIn() {
return sendlight_via_RemoteControlIn;
}

public JTextField getFieldlight_via_RemoteControlIn_Light() {
return fieldlight_via_RemoteControlIn_Light;
}

public void disableAll() {
sendtemperature_via_RemoteControlIn.setEnabled(false);
sendlight_via_RemoteControlIn.setEnabled(false);
}

public void enableAll() {
sendtemperature_via_RemoteControlIn.setEnabled(true);
sendlight_via_RemoteControlIn.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){
sendtemperature_via_RemoteControlIn.addActionListener(l);
sendlight_via_RemoteControlIn.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 RemoteControlIn_via_RemoteControlIn => temperature
c.gridy = 0;
c.gridx = 0;
frame_RemoteControlIn.add(createLabel("temperature"), c);
c.gridy = 1;
c.gridx = 0;
frame_RemoteControlIn.add(createtemperature_via_RemoteControlInPanel(), c);
c.gridy = 2;
c.gridx = 0;
sendtemperature_via_RemoteControlIn = createSendButton("RemoteControlIn => temperature");
frame_RemoteControlIn.add(sendtemperature_via_RemoteControlIn, c);
tabbedPane.addTab("RemoteControlIn", frame_RemoteControlIn);
//GUI related to RemoteControlIn_via_RemoteControlIn => light
c.gridy = 0;
c.gridx = 1;
frame_RemoteControlIn.add(createLabel("light"), c);
c.gridy = 1;
c.gridx = 1;
frame_RemoteControlIn.add(createlight_via_RemoteControlInPanel(), c);
c.gridy = 2;
c.gridx = 1;
sendlight_via_RemoteControlIn = createSendButton("RemoteControlIn => light");
frame_RemoteControlIn.add(sendlight_via_RemoteControlIn, c);
tabbedPane.addTab("RemoteControlIn", frame_RemoteControlIn);
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 createtemperature_via_RemoteControlInPanel(){
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
JPanel panel = new JPanel(new GridBagLayout());
JLabel labeltemp = new JLabel();
labeltemp.setText("temp");
c.gridx = 0;
c.gridy = 0;
panel.add(labeltemp, c);
fieldtemperature_via_RemoteControlIn_Temp = new JTextField();
fieldtemperature_via_RemoteControlIn_Temp.setText("temp");
c.gridx = 1;
c.gridy = 0
;panel.add(fieldtemperature_via_RemoteControlIn_Temp, c);
return panel;
}

public JPanel createlight_via_RemoteControlInPanel(){
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
JPanel panel = new JPanel(new GridBagLayout());
JLabel labellight = new JLabel();
labellight.setText("light");
c.gridx = 0;
c.gridy = 0;
panel.add(labellight, c);
fieldlight_via_RemoteControlIn_Light = new JTextField();
fieldlight_via_RemoteControlIn_Light.setText("light");
c.gridx = 1;
c.gridy = 0
;panel.add(fieldlight_via_RemoteControlIn_Light, c);
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 receivechangeDisplay_via_RemoteControlOutStyle = doc.addStyle("receivechangeDisplay_via_WeatherStationRPi_RemoteControlOutStyle", def);
StyleConstants.setForeground(receivechangeDisplay_via_RemoteControlOutStyle, new Color(83, 50, 51));
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() == getSendtemperature_via_RemoteControlIn()) {
port_WeatherStationRPi_RemoteControlIn.send(new Temperature(new Integer(getFieldtemperature_via_RemoteControlIn_Temp().getText()), Temperature$.MODULE$.getName()));
for(WeatherStationRPiListenerMirror l : listeners)
l.onTemperature_via_RemoteControlIn(new Integer(getFieldtemperature_via_RemoteControlIn_Temp().getText()));
}
else if ( ae.getSource() == getSendlight_via_RemoteControlIn()) {
port_WeatherStationRPi_RemoteControlIn.send(new Light(new Integer(getFieldlight_via_RemoteControlIn_Light().getText()), Light$.MODULE$.getName()));
for(WeatherStationRPiListenerMirror l : listeners)
l.onLight_via_RemoteControlIn(new Integer(getFieldlight_via_RemoteControlIn_Light().getText()));
}
}

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.WeatherStationRPiMockMirror

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.