OpenCores
URL https://opencores.org/ocsvn/present/present/trunk

Subversion Repositories present

[/] [present/] [trunk/] [JavaTests/] [PresentCommTesting/] [src/] [pl/] [com/] [kgajewski/] [serialcomm/] [gui/] [Window.java] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 gajos
package pl.com.kgajewski.serialcomm.gui;
2
 
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.events.MouseAdapter;
5
import org.eclipse.swt.events.MouseEvent;
6
import org.eclipse.swt.widgets.Button;
7
import org.eclipse.swt.widgets.Combo;
8
import org.eclipse.swt.widgets.Composite;
9
import org.eclipse.swt.widgets.Display;
10
import org.eclipse.swt.widgets.Label;
11
import org.eclipse.swt.widgets.Shell;
12
import org.eclipse.swt.widgets.Text;
13
 
14
public class Window {
15
 
16
        //Communicator object
17
    Communication communication = null;
18
        public Display display;
19
        protected Shell shell;
20
        public Text text;
21
        private Text data;
22
        private Text key;
23
        public Combo combo;
24
        private Button btnConnect;
25
        private Button btnDisconnect;
26
        private Button btnSendData;
27
 
28
        public void toggleControls()
29
    {
30
        if (communication.getConnected() == true)
31
        {
32
                btnDisconnect.setEnabled(true);
33
            btnConnect.setEnabled(false);
34
            btnSendData.setEnabled(true);
35
        }
36
        else
37
        {
38
                btnDisconnect.setEnabled(false);
39
            btnConnect.setEnabled(true);
40
            btnSendData.setEnabled(false);
41
        }
42
    }
43
 
44
        /**
45
         * Launch the application.
46
         *
47
         * @param args
48
         */
49
        public static void main(String[] args) {
50
                try {
51
                        Window window = new Window();
52
                        window.open();
53
                } catch (Exception e) {
54
                        e.printStackTrace();
55
                }
56
        }
57
 
58
        /**
59
         * Open the window.
60
         */
61
        public void open() {
62
                display = Display.getDefault();
63
                createContents();
64
                communication = new Communication(this);
65
                communication.searchForPorts();
66
                toggleControls();
67
                shell.open();
68
                shell.layout();
69
                while (!shell.isDisposed()) {
70
                        if (!display.readAndDispatch()) {
71
                                display.sleep();
72
                        }
73
                }
74
        }
75
 
76
        /**
77
         * Create contents of the window.
78
         */
79
        protected void createContents() {
80
                shell = new Shell();
81
                shell.setSize(470, 274);
82
                shell.setText("SWT Application");
83
                shell.setLayout(null);
84
 
85
                Composite composite = new Composite(shell, SWT.NONE);
86
                composite.setBounds(0, 0, 444, 236);
87
 
88
                text = new Text(composite, SWT.BORDER | SWT.MULTI);
89
                this.text.setBounds(107, 126, 327, 105);
90
 
91
                combo = new Combo(composite, SWT.NONE);
92
                combo.setBounds(10, 10, 91, 23);
93
 
94
                btnConnect = new Button(composite, SWT.NONE);
95
                btnConnect.addMouseListener(new MouseAdapter() {
96
                        @Override
97
                        public void mouseUp(MouseEvent arg0) {
98
                                communication.connect();
99
                        if (communication.getConnected() == true)
100
                        {
101
                            if (communication.initIOStream() == true)
102
                            {
103
                                communication.initListener();
104
                            }
105
                        }
106
                        }
107
                });
108
                btnConnect.setBounds(107, 10, 75, 25);
109
                btnConnect.setText("Connect");
110
 
111
                btnDisconnect = new Button(composite, SWT.NONE);
112
                btnDisconnect.addMouseListener(new MouseAdapter() {
113
                        @Override
114
                        public void mouseUp(MouseEvent arg0) {
115
                                communication.disconnect();
116
                        }
117
                });
118
                btnDisconnect.setBounds(188, 10, 75, 25);
119
                btnDisconnect.setText("Disconnect");
120
 
121
                Label lblLog = new Label(composite, SWT.NONE);
122
                lblLog.setBounds(107, 105, 186, 15);
123
                lblLog.setText("Log");
124
 
125
                data = new Text(composite, SWT.BORDER);
126
                data.setBounds(45, 39, 248, 21);
127
 
128
                key = new Text(composite, SWT.BORDER);
129
                key.setBounds(45, 66, 248, 21);
130
 
131
                btnSendData = new Button(composite, SWT.NONE);
132
                btnSendData.addMouseListener(new MouseAdapter() {
133
                        @Override
134
                        public void mouseUp(MouseEvent arg0) {
135
                                communication.writeData(data.getText());
136
                                communication.writeData(key.getText());
137
                        }
138
                });
139
                btnSendData.setBounds(10, 100, 75, 25);
140
                btnSendData.setText("Send");
141
 
142
                Label lblData = new Label(composite, SWT.NONE);
143
                lblData.setBounds(10, 39, 29, 15);
144
                lblData.setText("Data");
145
 
146
                Label lblKey = new Label(composite, SWT.NONE);
147
                lblKey.setBounds(10, 66, 55, 15);
148
                lblKey.setText("Key");
149
        }
150
 
151
        public void appendText(final String s) {
152
                display.syncExec(new Runnable() {
153
                        public void run() {
154
                                text.append(s);
155
                        }
156
                });
157
 
158
        }
159
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.