- 追加された行はこの色です。
- 削除された行はこの色です。
**GUI
-[[Advanced Eclipse SWT Designer:http://www.swt-designer.com/]]
>Eclipse上で稼働するSWTのGUIビルダー
** SubFormのスニペット
public class SubForm {
private Shell subShell;
public Shell open(Shell shell) {
subShell = new Shell(shell);
subShell.setText("subShell");
// DESIGNER: Add controls before this line.
subShell.open();
return subShell;
}
}
** 上のSubFormを呼ぶ方のスニペット
button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
SubForm subform = new SubForm();
subform.open(shell);
}
});
**スニペット
package kino.swt;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Main {
/**
* Form上のコンポーネントを配置する
* @param display
* @return
*/
public Shell open(Display display) {
final Shell shell = new Shell(display);
// DESIGNER: Add controls before this line.
shell.setSize(500, 300);
shell.pack();
shell.open();
return shell;
}
public static void main(String[] args) {
Main main = new Main();
Display display = new Display();
Shell shell = main.open(display);
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
System.exit(0);
}
}
** 外部アプリケーションを起動する
:使用クラス|org.eclipse.swt.program.Program
Program program=Program.findProgram("html"); <- この拡張子のアプリケーションを探す
program.execute("http://などURL"); <- アプリケーション起動
とすると、デフォルトのブラウザが起動し、指定したURLが開きます。
** めいっぱい配置
final GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
** グリッドの列を何列にするか?
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
shell.setLayout(gridLayout);
** メニューバースニペット
Menu menubar = new Menu(shell, SWT.BAR);
shell.setMenuBar(menubar);
//ファイルメニュー表示
MenuItem file = new MenuItem(menubar, SWT.CASCADE);
file.setText("File");
Menu menu = new Menu(file);
file.setMenu(menu);
//オープンメニュー表示
MenuItem open = new MenuItem(menu, SWT.PUSH);
open.setText("Open");
//セーブメニュー表示
MenuItem save = new MenuItem(menu, SWT.PUSH);
save.setText("Save");
//セパレータ
MenuItem separator = new MenuItem(menu, SWT.SEPARATOR);
//終了メニュー表示
MenuItem quit = new MenuItem(menu, SWT.PUSH);
quit.setText("Quit");
quit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
MessageBox messageBox = new MessageBox(shell, SWT.OK);
messageBox.setMessage("文字列を入力してください。");
messageBox.open();
}
});
** CoolBar
CoolBar coolbar = new CoolBar(shell,SWT.NULL);
ToolBar toolbar1 = new ToolBar(coolbar,SWT.FLAT);
ToolItem tItem1_1 = new ToolItem(toolbar1,SWT.PUSH);
tItem1_1.setText("Item1");
ToolItem tItem1_2 = new ToolItem(toolbar1,SWT.PUSH);
tItem1_2.setText("Item2");
CoolItem item1 = new CoolItem(coolbar,SWT.PUSH);
item1.setControl(toolbar1);
Point pt1 = toolbar1.computeSize(SWT.DEFAULT,SWT.DEFAULT);
pt1 = item1.computeSize(pt1.x,pt1.y);
item1.setSize(pt1);
** ShellのCloseのイベントで何かしたい
shell.addListener(SWT.Close, new CloseCheck());
として内部クラスで
class CloseCheck implements Listener {
public void handleEvent(Event event) {
System.out.println("CloseCheck called");
MessageBox box =
new MessageBox(
shell,
SWT.APPLICATION_MODAL
| SWT.ICON_QUESTION
| SWT.YES
| SWT.NO);
box.setMessage("本当に終了する?");
box.setText("Application の終了");
int answer = box.open();
if (answer == SWT.NO) {
event.doit = false;
}
}
}
終了してよいかのダイアログを出す
*** LinuxでSWT
http://www-6.ibm.com/jp/developerworks/java/030711/j_j-nativegui2.html
cp -p *.so /usr/lib
export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH
java -cp .:lib/:lib/log4j-1.2.8.jar:lib/kino_javadocsearch.jar:lib/swt.jar:lib/swt-pi.jar kino.swt.JavaDocSearchForm
[[:Java]]~
[[:Eclipse]]~
[[:SWT]]