use of io.sloeber.ui.monitor.internal.SerialListener in project arduino-eclipse-plugin by Sloeber.
the class SerialMonitor method connectSerial.
/**
* Connect to a serial port and sets the listener
*
* @param comPort
* the name of the com port to connect to
* @param baudRate
* the baud rate to connect to the com port
*/
public void connectSerial(String comPort, int baudRate) {
if (this.serialConnections.size() < MY_MAX_SERIAL_PORTS) {
int colorindex = this.serialConnections.size();
Serial newSerial = new Serial(comPort, baudRate);
if (newSerial.IsConnected()) {
newSerial.registerService();
SerialListener theListener = new SerialListener(this, colorindex);
newSerial.addListener(theListener);
theListener.event(// $NON-NLS-1$
System.getProperty("line.separator") + Messages.serialMonitorConnectedTo + comPort + Messages.serialMonitorAt + baudRate + // $NON-NLS-1$
System.getProperty("line.separator"));
this.serialConnections.put(newSerial, theListener);
SerialPortsUpdated();
return;
}
} else {
Activator.log(new Status(IStatus.ERROR, Activator.getId(), Messages.serialMonitorNoMoreSerialPortsSupported, null));
}
}
use of io.sloeber.ui.monitor.internal.SerialListener in project arduino-eclipse-plugin by Sloeber.
the class SerialMonitor method createPartControl.
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
@Override
public void createPartControl(Composite parent1) {
this.parent = parent1;
parent1.setLayout(new GridLayout());
GridLayout layout = new GridLayout(5, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
Composite top = new Composite(parent1, SWT.NONE);
top.setLayout(layout);
top.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.serialPorts = new ComboViewer(top, SWT.READ_ONLY | SWT.DROP_DOWN);
GridData minSizeGridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
minSizeGridData.widthHint = 150;
this.serialPorts.getControl().setLayoutData(minSizeGridData);
this.serialPorts.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
// no need to do something here
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// no need to do something here
}
@Override
public Object[] getElements(Object inputElement) {
@SuppressWarnings("unchecked") Map<Serial, SerialListener> items = (Map<Serial, SerialListener>) inputElement;
return items.keySet().toArray();
}
});
this.serialPorts.setLabelProvider(new LabelProvider());
this.serialPorts.setInput(this.serialConnections);
this.serialPorts.addSelectionChangedListener(new ComPortChanged(this));
this.sendString = new Text(top, SWT.SINGLE | SWT.BORDER);
this.sendString.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
this.lineTerminator = new ComboViewer(top, SWT.READ_ONLY | SWT.DROP_DOWN);
this.lineTerminator.setContentProvider(new ArrayContentProvider());
this.lineTerminator.setLabelProvider(new LabelProvider());
this.lineTerminator.setInput(SerialManager.listLineEndings());
this.lineTerminator.getCombo().select(MyPreferences.getLastUsedSerialLineEnd());
this.lineTerminator.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
MyPreferences.setLastUsedSerialLineEnd(SerialMonitor.this.lineTerminator.getCombo().getSelectionIndex());
}
});
this.send = new Button(top, SWT.BUTTON1);
this.send.setText(Messages.serialMonitorSend);
this.send.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
int index = SerialMonitor.this.lineTerminator.getCombo().getSelectionIndex();
GetSelectedSerial().write(SerialMonitor.this.sendString.getText(), SerialManager.getLineEnding(index));
// $NON-NLS-1$
SerialMonitor.this.sendString.setText("");
SerialMonitor.this.sendString.setFocus();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// nothing needs to be done here
}
});
this.send.setEnabled(false);
this.reset = new Button(top, SWT.BUTTON1);
this.reset.setText(Messages.serialMonitorReset);
this.reset.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
GetSelectedSerial().reset();
SerialMonitor.this.sendString.setFocus();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// nothing needs to be done here
}
});
this.reset.setEnabled(false);
// register the combo as a Selection Provider
getSite().setSelectionProvider(this.serialPorts);
this.monitorOutput = new StyledText(top, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
this.monitorOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
this.monitorOutput.setEditable(false);
IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
ITheme currentTheme = themeManager.getCurrentTheme();
FontRegistry fontRegistry = currentTheme.getFontRegistry();
// $NON-NLS-1$
this.monitorOutput.setFont(fontRegistry.get("io.sloeber.serial.fontDefinition"));
this.monitorOutput.setText(Messages.serialMonitorNoInput);
this.parent.getShell().setDefaultButton(this.send);
makeActions();
contributeToActionBars();
}
use of io.sloeber.ui.monitor.internal.SerialListener in project arduino-eclipse-plugin by Sloeber.
the class SerialMonitor method disConnectSerialPort.
public void disConnectSerialPort(String comPort) {
Serial newSerial = GetSerial(comPort);
if (newSerial != null) {
SerialListener theListener = SerialMonitor.this.serialConnections.get(newSerial);
SerialMonitor.this.serialConnections.remove(newSerial);
newSerial.removeListener(theListener);
newSerial.dispose();
theListener.dispose();
SerialPortsUpdated();
}
}
Aggregations