public class MQTTFrame extends Object implements ActionListener, MqttCallback, Runnable
Modifier and Type | Field and Description |
---|---|
protected static Dimension |
DROP_DOWN_DIMENSION
Constant controlling the display of JComboBoxes
|
protected static int |
FRAME_HEIGHT |
protected static int |
FRAME_WIDTH |
protected static Dimension |
TEXT_FIELD_DIMENSION
Constant controlling the display of JTextFields
|
protected static Insets |
TEXT_MARGINS |
Constructor and Description |
---|
MQTTFrame()
Constructor for MQTTFrame
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent e)
Implement the ActionListener interface and catch user interface events.
|
void |
connect(String connStr,
boolean usePersistence)
A wrapper for the MQTT connect method.
|
void |
connectionLost(Throwable cause)
The method is part of the MqttSimpleCallback interface
In the event of the MQTT connection being broken the LED is set to colour amber and made to flash. |
String |
constructPropertyValue(String prop)
For a given property key construct a value to associate with the key
The value can then be inserted in a properties object
|
void |
deliveryComplete(IMqttDeliveryToken token)
Called when delivery for a message has been completed, and all
acknowledgments have been received.
|
void |
disconnect()
A wrapper for the MQTT disconnect method.
|
void |
getProperties(Properties props,
JComboBox comp,
String key,
String defValue)
Add properties from a Properties object to a JComboBox.
|
protected void |
init(Container contentPane)
This method builds all the components to add to the
content pane of the JFrame window.
|
static void |
main(String[] args)
The main method for launching the GUI.
|
void |
messageArrived(String topic,
MqttMessage message)
The method is part of the MqttCallback interface
Pass the message as is to the SubPanel object which will display it. |
void |
publish(String topic,
byte[] message,
int qos,
boolean retained)
A simple wrapper for the MQTT publish method.
|
void |
run()
Invoked by actionPerformed when connect is pressed.
|
void |
setTitleText(String extraText)
This method accepts a string on text and displays it in the window's title bar.
|
void |
startTrace()
This method calls the MQTT startTrace method to produce trace of the protocol flows
|
void |
stopTrace()
This method calls the MQTT stopTrace method to stop trace of the protocol flows
|
void |
subscription(String topic,
int qos,
boolean sub)
This method is called when either the subscribe or unsubscribe buttons are pressed.
|
boolean |
updateComboBoxList(JComboBox list,
String itemName)
This method handles string items in JComboBox drop downs.
|
void |
updatePublishTopicList(String topicName)
If a new topic is typed into the subscribe topic box then the
publish topic box needs to be updated.
|
void |
updateSubscribeTopicList(String topicName)
If a new topic is typed into the publish topic box then the
subscribe topic box needs to be updated.
|
void |
writeLog(String logdata)
Write to the history dialog window
|
void |
writeLogln(String logdata)
Write to the history dialog window and append a newline character after the text
|
protected static final Dimension TEXT_FIELD_DIMENSION
protected static final Dimension DROP_DOWN_DIMENSION
protected static final Insets TEXT_MARGINS
protected static final int FRAME_WIDTH
protected static final int FRAME_HEIGHT
public static void main(String[] args)
args
- No arguments are required.protected void init(Container contentPane)
contentPane
- - The content pane of the JFrame window.public void publish(String topic, byte[] message, int qos, boolean retained) throws Exception
topic
- The topic on which the data will be published.message
- The data to be publishedqos
- The Quality of Service at which the publication should be delivered.retained
- Is this a retained publication or not?Exception
public void disconnect()
public void connect(String connStr, boolean usePersistence) throws MqttException
Check whether Last Will & Testament is required and call the appropriate connect method. The only persistence implementation supported at the moment is MqttFilePersistence.
ipAddr
- The IP address or hostname to connect to.port
- The IP port number to connect to.usePersistence
- Is persistence required?MqttException
public void subscription(String topic, int qos, boolean sub)
topic
- The topic to subscribe toqos
- The maximum Quality of Service at which to receive publicationssub
- Is this a subscribe or unsubscribe operation? (true if subscribe).public void run()
public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
e
- The action event to process.public void setTitleText(String extraText)
extraText
- The text to be appended to some default words and displayed.public void connectionLost(Throwable cause)
connectionLost
in interface MqttCallback
cause
- the reason behind the loss of connection.public void messageArrived(String topic, MqttMessage message)
messageArrived
in interface MqttCallback
topic
- name of the topic on the message was published tomessage
- the actual message.public void deliveryComplete(IMqttDeliveryToken token)
MqttCallback
deliveryComplete
in interface MqttCallback
token
- the delivery token associated with the message.public void updateSubscribeTopicList(String topicName)
topicName
- The topic name to add to the subscribe topic listpublic void updatePublishTopicList(String topicName)
topicName
- The topic name to add to the publish topic listpublic boolean updateComboBoxList(JComboBox list, String itemName)
list
- The JComboBox object to updateitemName
- The value to add into the list if it doesn't already existpublic void startTrace() throws MqttException
MqttException
public void stopTrace()
public void writeLogln(String logdata)
logdata
- The line of text to display in the history logpublic void writeLog(String logdata)
logdata
- The line of text to display in the history logpublic void getProperties(Properties props, JComboBox comp, String key, String defValue)
props
- The properties object from which to get the property value.comp
- The drop down box to which the tokens within the key must be added.key
- The key to identify the property to access.defValue
- The default value for the key if no value is found.public String constructPropertyValue(String prop)
prop
- The property to construct a string value for.Copyright © 2016 Eclipse Paho. All rights reserved.