2
* Copyright (C) 2005, 2006 Aelitis, All Rights Reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
* AELITIS, SAS au capital de 46,603.30 euros
17
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
19
package org.gudy.azureus2.ui.swt.components;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Listener;
30
import org.eclipse.swt.widgets.Shell;
31
import org.gudy.azureus2.core3.internat.MessageText;
32
import org.gudy.azureus2.core3.util.AERunnable;
33
import org.gudy.azureus2.core3.util.Constants;
34
import org.gudy.azureus2.core3.util.Debug;
35
import org.gudy.azureus2.ui.swt.ImageRepository;
36
import org.gudy.azureus2.ui.swt.Utils;
37
import org.gudy.azureus2.ui.swt.components.shell.ShellFactory;
39
public class StringListChooser {
41
private Display display;
46
private String result;
48
public StringListChooser(final Shell parentShell) {
51
display = parentShell.getDisplay();
52
if(display == null || display.isDisposed()) return;
53
display.syncExec(new Runnable() {
55
createShell(parentShell);
60
private void createShell(Shell parentShell) {
62
shell = ShellFactory.createShell(display,SWT.APPLICATION_MODAL | SWT.BORDER | SWT.TITLE | SWT.CLOSE);
63
if(!Constants.isOSX) {
64
shell.setImage(ImageRepository.getImage("azureus"));
67
GridLayout layout = new GridLayout();
68
layout.numColumns = 2;
69
shell.setLayout(layout);
72
label = new Label(shell,SWT.WRAP);
74
combo = new Combo(shell,SWT.READ_ONLY);
76
Button ok = new Button(shell,SWT.PUSH);
77
ok.addListener(SWT.Selection, new Listener() {
78
public void handleEvent(Event arg0) {
79
result = combo.getText();
83
ok.setText(MessageText.getString("Button.ok"));
85
Button cancel = new Button(shell,SWT.PUSH);
86
cancel.addListener(SWT.Selection, new Listener() {
87
public void handleEvent(Event arg0) {
94
cancel.setText(MessageText.getString("Button.cancel"));
97
shell.addListener(SWT.Dispose,new Listener() {
98
public void handleEvent(Event arg0) {
102
data = new GridData(GridData.FILL_HORIZONTAL);
103
data.horizontalSpan = 2;
104
data.heightHint = 30;
105
label.setLayoutData(data);
107
data = new GridData(GridData.FILL_HORIZONTAL);
108
data.horizontalSpan = 2;
109
combo.setLayoutData(data);
111
data = new GridData();
113
data.grabExcessHorizontalSpace = true;
114
data.grabExcessVerticalSpace = true;
115
data.verticalAlignment = SWT.END;
116
data.horizontalAlignment = SWT.END;
117
ok.setLayoutData(data);
119
data = new GridData();
120
data.grabExcessVerticalSpace = true;
121
data.verticalAlignment = SWT.END;
123
cancel.setLayoutData(data);
125
shell.setSize(300,150);
128
Utils.centerWindowRelativeTo(shell,parentShell);
132
public void setTitle(final String title) {
133
Utils.execSWTThread(new AERunnable() {
134
public void runSupport() {
135
if(display == null || display.isDisposed()) return;
136
shell.setText(title);
141
public void setText(final String text) {
142
Utils.execSWTThread(new AERunnable() {
143
public void runSupport() {
144
if(display == null || display.isDisposed()) return;
145
label.setText(text.replaceAll("&", "&&"));
150
public void addOption(final String option) {
151
Utils.execSWTThread(new AERunnable() {
152
public void runSupport() {
153
if(display == null || display.isDisposed()) return;
155
if(combo.getItemCount() == 1) {
156
combo.setText(option);
162
public String open() {
163
if(display == null || display.isDisposed()) return null;
164
Utils.execSWTThread(new AERunnable() {
168
if(display == null || display.isDisposed()) {
173
while (!shell.isDisposed())
174
if (!display.readAndDispatch()) display.sleep();
176
}catch( Throwable e ){
178
Debug.printStackTrace( e );
2
* Copyright (C) 2005, 2006 Aelitis, All Rights Reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
* AELITIS, SAS au capital de 46,603.30 euros
17
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
19
package org.gudy.azureus2.ui.swt.components;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Listener;
30
import org.eclipse.swt.widgets.Shell;
31
import org.gudy.azureus2.core3.internat.MessageText;
32
import org.gudy.azureus2.core3.util.AERunnable;
33
import org.gudy.azureus2.core3.util.Constants;
34
import org.gudy.azureus2.core3.util.Debug;
35
import org.gudy.azureus2.ui.swt.ImageRepository;
36
import org.gudy.azureus2.ui.swt.Utils;
37
import org.gudy.azureus2.ui.swt.components.shell.ShellFactory;
39
public class StringListChooser {
41
private Display display;
46
private String result;
48
public StringListChooser(final Shell parentShell) {
51
display = parentShell.getDisplay();
52
if(display == null || display.isDisposed()) return;
53
display.syncExec(new Runnable() {
55
createShell(parentShell);
60
private void createShell(Shell parentShell) {
62
shell = ShellFactory.createShell(display,SWT.APPLICATION_MODAL | SWT.BORDER | SWT.TITLE | SWT.CLOSE);
63
if(!Constants.isOSX) {
64
shell.setImage(ImageRepository.getImage("azureus"));
67
GridLayout layout = new GridLayout();
68
layout.numColumns = 2;
69
shell.setLayout(layout);
72
label = new Label(shell,SWT.WRAP);
74
combo = new Combo(shell,SWT.READ_ONLY);
76
Button ok = new Button(shell,SWT.PUSH);
77
ok.addListener(SWT.Selection, new Listener() {
78
public void handleEvent(Event arg0) {
79
result = combo.getText();
83
ok.setText(MessageText.getString("Button.ok"));
85
Button cancel = new Button(shell,SWT.PUSH);
86
cancel.addListener(SWT.Selection, new Listener() {
87
public void handleEvent(Event arg0) {
94
cancel.setText(MessageText.getString("Button.cancel"));
97
shell.addListener(SWT.Dispose,new Listener() {
98
public void handleEvent(Event arg0) {
102
data = new GridData(GridData.FILL_HORIZONTAL);
103
data.horizontalSpan = 2;
104
data.heightHint = 30;
105
label.setLayoutData(data);
107
data = new GridData(GridData.FILL_HORIZONTAL);
108
data.horizontalSpan = 2;
109
combo.setLayoutData(data);
111
data = new GridData();
113
data.grabExcessHorizontalSpace = true;
114
data.grabExcessVerticalSpace = true;
115
data.verticalAlignment = SWT.END;
116
data.horizontalAlignment = SWT.END;
117
ok.setLayoutData(data);
119
data = new GridData();
120
data.grabExcessVerticalSpace = true;
121
data.verticalAlignment = SWT.END;
123
cancel.setLayoutData(data);
125
shell.setSize(300,150);
128
Utils.centerWindowRelativeTo(shell,parentShell);
132
public void setTitle(final String title) {
133
Utils.execSWTThread(new AERunnable() {
134
public void runSupport() {
135
if(display == null || display.isDisposed()) return;
136
shell.setText(title);
141
public void setText(final String text) {
142
Utils.execSWTThread(new AERunnable() {
143
public void runSupport() {
144
if(display == null || display.isDisposed()) return;
145
label.setText(text.replaceAll("&", "&&"));
150
public void addOption(final String option) {
151
Utils.execSWTThread(new AERunnable() {
152
public void runSupport() {
153
if(display == null || display.isDisposed()) return;
155
if(combo.getItemCount() == 1) {
156
combo.setText(option);
162
public String open() {
163
if(display == null || display.isDisposed()) return null;
164
Utils.execSWTThread(new AERunnable() {
168
if(display == null || display.isDisposed()) {
173
while (!shell.isDisposed())
174
if (!display.readAndDispatch()) display.sleep();
176
}catch( Throwable e ){
178
Debug.printStackTrace( e );