Search in sources :

Example 1 with SerialListener

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));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Serial(io.sloeber.core.api.Serial) SerialListener(io.sloeber.ui.monitor.internal.SerialListener)

Example 2 with SerialListener

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();
}
Also used : ITheme(org.eclipse.ui.themes.ITheme) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) SerialListener(io.sloeber.ui.monitor.internal.SerialListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FontRegistry(org.eclipse.jface.resource.FontRegistry) IThemeManager(org.eclipse.ui.themes.IThemeManager) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Serial(io.sloeber.core.api.Serial) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with SerialListener

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();
    }
}
Also used : Serial(io.sloeber.core.api.Serial) SerialListener(io.sloeber.ui.monitor.internal.SerialListener)

Aggregations

Serial (io.sloeber.core.api.Serial)3 SerialListener (io.sloeber.ui.monitor.internal.SerialListener)3 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 FontRegistry (org.eclipse.jface.resource.FontRegistry)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 Viewer (org.eclipse.jface.viewers.Viewer)1 StyledText (org.eclipse.swt.custom.StyledText)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1