Package org.thingml.generated

Source Code of org.thingml.generated.LightSensorScalaMockMirror

/**
* 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 LightSensorScalaMockMirror 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_LightSensorScala_LightSensor = null;

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

public LightSensorScalaMockMirror(){
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("read_light", sent);
rec = new $colon$colon("light_value", sent);
port_LightSensorScala_LightSensor = (Port) new Port("LightSensor", 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_LightSensor;
private JTextPane screen;
private JButton clearButton;
private StyledDocument doc;

//Attributes related to read_light via LightSensor
public JButton sendread_light_via_LightSensor;
public JButton getSendread_light_via_LightSensor() {
return sendread_light_via_LightSensor;
}

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

public void enableAll() {
sendread_light_via_LightSensor.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){
sendread_light_via_LightSensor.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("LightSensorScala Mock Simulator");
frame.setLayout(new GridBagLayout());
frame.add(tabbedPane, c);
frame_LightSensor = new JPanel();
frame_LightSensor.setLayout(new GridBagLayout());
//GUI related to LightSensor_via_LightSensor => read_light
c.gridy = 0;
c.gridx = 0;
frame_LightSensor.add(createLabel("read_light"), c);
c.gridy = 1;
c.gridx = 0;
frame_LightSensor.add(createread_light_via_LightSensorPanel(), c);
c.gridy = 2;
c.gridx = 0;
sendread_light_via_LightSensor = createSendButton("LightSensor => read_light");
frame_LightSensor.add(sendread_light_via_LightSensor, c);
tabbedPane.addTab("LightSensor", frame_LightSensor);
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 createread_light_via_LightSensorPanel(){
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 receivelight_value_via_LightSensorStyle = doc.addStyle("receivelight_value_via_LightSensorScala_LightSensorStyle", def);
StyleConstants.setForeground(receivelight_value_via_LightSensorStyle, new Color(38, 91, 32));
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() == getSendread_light_via_LightSensor()) {
port_LightSensorScala_LightSensor.send(new Read_light(Read_light$.MODULE$.getName()));
for(LightSensorScalaListenerMirror l : listeners)
l.onRead_light_via_LightSensor();
}
}

public static void main(String args[]){
LightSensorScalaMock mock = new LightSensorScalaMock();
LightSensorScalaMockMirror mockMirror = new LightSensorScalaMockMirror();
Channel c_LightSensor_17455829 = new Channel();
c_LightSensor_17455829.connect(mock.port_LightSensorScala_LightSensor, mockMirror.port_LightSensorScala_LightSensor);
c_LightSensor_17455829.connect(mockMirror.port_LightSensorScala_LightSensor, mock.port_LightSensorScala_LightSensor);
c_LightSensor_17455829.start();
}
}
TOP

Related Classes of org.thingml.generated.LightSensorScalaMockMirror

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.