Package com.chatmotorapi.api.listener
Class SwingResponseListener
java.lang.Object
com.chatmotorapi.api.listener.SwingResponseListener
- All Implemented Interfaces:
MotorResponseListener
public class SwingResponseListener extends Object implements MotorResponseListener
A Swing implementation of
MotorResponseListener
that updates a JTextArea with the received response chunks.
Includes an option to append a new line after each chunk.-
Constructor Summary
Constructors Constructor Description SwingResponseListener(JTextArea textArea, boolean appendNewLine)
Constructor. -
Method Summary
Modifier and Type Method Description void
onChunkReceived(MotorResponse motorResponse)
Called when a new chunk of response is received.void
onError(Throwable throwable)
Called when an error occurs during the response streaming.void
onResponseCompleted()
Called when the response streaming is successfully completed.
-
Constructor Details
-
SwingResponseListener
Constructor.- Parameters:
textArea
- the JTextArea to update with the received response chunksappendNewLine
- if true, a new line will be appended after each chunk
-
-
Method Details
-
onChunkReceived
Description copied from interface:MotorResponseListener
Called when a new chunk of response is received.- Specified by:
onChunkReceived
in interfaceMotorResponseListener
- Parameters:
motorResponse
- the ChatMotor response.
-
onResponseCompleted
public void onResponseCompleted()Description copied from interface:MotorResponseListener
Called when the response streaming is successfully completed. This method is only invoked if the entire process completes without encountering any errors.- Specified by:
onResponseCompleted
in interfaceMotorResponseListener
-
onError
Description copied from interface:MotorResponseListener
Called when an error occurs during the response streaming.- Specified by:
onError
in interfaceMotorResponseListener
- Parameters:
throwable
- the exception that occurred during streaming.
-