/**
* 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 LcdScreenScalaMock 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_LcdScreenScala_Display = null;
java.util.List<LcdScreenScalaListener> listeners = new java.util.LinkedList<LcdScreenScalaListener>();
public LcdScreenScalaMock(){
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("initDisplay", rec);
rec = new $colon$colon("refreshDisplay", rec);
rec = new $colon$colon("setDisplay", rec);
sent = new $colon$colon("currentDisplay", sent);
port_LcdScreenScala_Display = (Port) new Port("Display", 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_Display;
private JTextPane screen;
private JButton clearButton;
private StyledDocument doc;
//Attributes related to currentDisplay via Display
public JButton sendcurrentDisplay_via_Display;
private JTextField fieldcurrentDisplay_via_Display_Id;
public JButton getSendcurrentDisplay_via_Display() {
return sendcurrentDisplay_via_Display;
}
public JTextField getFieldcurrentDisplay_via_Display_Id() {
return fieldcurrentDisplay_via_Display_Id;
}
public void disableAll() {
sendcurrentDisplay_via_Display.setEnabled(false);
}
public void enableAll() {
sendcurrentDisplay_via_Display.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){
sendcurrentDisplay_via_Display.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("LcdScreenScala Mock Simulator");
frame.setLayout(new GridBagLayout());
frame.add(tabbedPane, c);
frame_Display = new JPanel();
frame_Display.setLayout(new GridBagLayout());
//GUI related to Display_via_Display => currentDisplay
c.gridy = 0;
c.gridx = 0;
frame_Display.add(createLabel("currentDisplay"), c);
c.gridy = 1;
c.gridx = 0;
frame_Display.add(createcurrentDisplay_via_DisplayPanel(), c);
c.gridy = 2;
c.gridx = 0;
sendcurrentDisplay_via_Display = createSendButton("Display => currentDisplay");
frame_Display.add(sendcurrentDisplay_via_Display, c);
tabbedPane.addTab("Display", frame_Display);
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 createcurrentDisplay_via_DisplayPanel(){
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
JPanel panel = new JPanel(new GridBagLayout());
JLabel labelid = new JLabel();
labelid.setText("id");
c.gridx = 0;
c.gridy = 0;
panel.add(labelid, c);
fieldcurrentDisplay_via_Display_Id = new JTextField();
fieldcurrentDisplay_via_Display_Id.setText("id");
c.gridx = 1;
c.gridy = 0
;panel.add(fieldcurrentDisplay_via_Display_Id, 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 receiveinitDisplay_via_DisplayStyle = doc.addStyle("receiveinitDisplay_via_LcdScreenScala_DisplayStyle", def);
StyleConstants.setForeground(receiveinitDisplay_via_DisplayStyle, new Color(141, 0, 93));
Style receiverefreshDisplay_via_DisplayStyle = doc.addStyle("receiverefreshDisplay_via_LcdScreenScala_DisplayStyle", def);
StyleConstants.setForeground(receiverefreshDisplay_via_DisplayStyle, new Color(3, 136, 170));
Style receivesetDisplay_via_DisplayStyle = doc.addStyle("receivesetDisplay_via_LcdScreenScala_DisplayStyle", def);
StyleConstants.setForeground(receivesetDisplay_via_DisplayStyle, new Color(82, 80, 39));
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() == getSendcurrentDisplay_via_Display()) {
port_LcdScreenScala_Display.send(new CurrentDisplay(new Integer(getFieldcurrentDisplay_via_Display_Id().getText()), CurrentDisplay$.MODULE$.getName()));
for(LcdScreenScalaListener l : listeners)
l.onCurrentDisplay_via_Display(new Integer(getFieldcurrentDisplay_via_Display_Id().getText()));
}
}
public static void main(String args[]){
LcdScreenScalaMock mock = new LcdScreenScalaMock();
LcdScreenScalaMockMirror mockMirror = new LcdScreenScalaMockMirror();
Channel c_Display_8845366 = new Channel();
c_Display_8845366.connect(mock.port_LcdScreenScala_Display, mockMirror.port_LcdScreenScala_Display);
c_Display_8845366.connect(mockMirror.port_LcdScreenScala_Display, mock.port_LcdScreenScala_Display);
c_Display_8845366.start();
}
}