forked from archduke31/ADBLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidDeviceChoiceDlg.java
More file actions
137 lines (120 loc) · 4.46 KB
/
Copy pathAndroidDeviceChoiceDlg.java
File metadata and controls
137 lines (120 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package feiw;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class AndroidDeviceChoiceDlg extends Dialog {
private String message = "Select device:";
private String [] mDevices;
private int mSelection = 0;
private int mReturn;
public int getSelection() {
return mSelection;
}
public AndroidDeviceChoiceDlg(Shell parent, String [] devs, int defSel) {
this(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
mDevices = devs;
mSelection = defSel;
}
public AndroidDeviceChoiceDlg(Shell parent, int style) {
super(parent, style);
}
public int open() {
// Create the dialog window
Shell shell = new Shell(getParent(), getStyle());
shell.setText(getText());
createContents(shell);
shell.pack();
Rectangle shellBounds = getParent().getBounds();
Point dialogSize = shell.getSize();
shell.setLocation(shellBounds.x + (shellBounds.width - dialogSize.x) / 2,
shellBounds.y + (shellBounds.height - dialogSize.y) / 2);
shell.open();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
// Return the entered value, or null
return mReturn;
}
/**
* Creates the dialog's contents
*
* @param shell
* the dialog window
*/
private void createContents(final Shell shell) {
shell.setLayout(new GridLayout(2, true));
shell.setText("Select device");
// Show the message
Label label = new Label(shell, SWT.NONE);
label.setText(message);
label.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1));
final Combo combop = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
combop.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
for (String s : mDevices) {
combop.add(s);
}
combop.select(mSelection);
// Create the OK button and add a handler
// so that pressing it will set input
// to the entered value
Button ok = new Button(shell, SWT.PUSH);
ok.setText("OK");
GridData data = new GridData(GridData.FILL_HORIZONTAL);
ok.setLayoutData(data);
ok.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
mSelection = combop.getSelectionIndex();
mReturn = SWT.OK;
shell.close();
}
});
// Create the cancel button and add a handler
// so that pressing it will set input to null
Button cancel = new Button(shell, SWT.PUSH);
cancel.setText("Cancel");
data = new GridData(GridData.FILL_HORIZONTAL);
cancel.setLayoutData(data);
cancel.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
mReturn = SWT.CANCEL;
shell.close();
}
});
// Set the OK button as the default, so
// user can type input and press Enter
// to dismiss
shell.setDefaultButton(ok);
}
}