swt j face 1/3

43
SWT 에 에에 SWT/JFace 조조조 (V0.9, 14/05/11) http://cafe.naver.com/eclipse plugin http://hangumkj.blogspot.com/ [email protected]

Upload: cho-hyun-jong

Post on 12-Jan-2015

2.329 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Swt J Face 1/3

SWT 에 대해SWT/JFace

조현종 (V0.9, 14/05/11)http://cafe.naver.com/eclipsepluginhttp://hangumkj.blogspot.com/[email protected]

Page 2: Swt J Face 1/3

목 차

SWT 는 ? Hello World 예제 WindowBuilder 소개 SWT 주요 Package Dialog Widget Event Layout Nebulra project 팀 만들기 실습 참고자료

Page 3: Swt J Face 1/3

SWT 는 ?

SWT?(Standard Widget Toolkit)- IBM 의 Stephen Northover 에 의해 개발 .- SWT 버전 3.8.2(4.2.2) – 2013- OS 에 최적화 된 native library 제공

Windows, Linux, Unix, Mac OS- www.eclipse.org/swt

Page 4: Swt J Face 1/3

Hello World 예제 ?public static void main(String args[]) {

Display display = new Display(); // 1Shell shell = new Shell(display); // 2shell.setText("Hello World"); // 3shell.setSize(300, 300); // 4

shell.open(); // 5while (!shell.isDisposed()) // 6

if (!display.readAndDispatch()) // 7display.sleep(); // 8

display.dispose(); // 9

}

Page 5: Swt J Face 1/3

Hello World 예제 ?

1) Display? 1) GUI 상태를 유지해주고 OS 와 통신2) Event 에 대한 처리 및 관련된 곳에 전달3) System 상수 정의 .

2) Shell?1) GUI 의 최상의 윈도우2) 시각적인 부분을 구현 (Container, Widget,

event 와 GUI 를 연동하기 위한 연결고리 )

Widget/Control/Compos-ite

Shell Class

Display

SWT OS Class, JNI

System OS

Page 6: Swt J Face 1/3

Hello World 예제 ?

3) Shell 의 Title 를 ‘ Hello World’ 로 설정4) Shell Size 를 300, 300 으로 설정5) Shell 을 오픈한다 .6) Shell 이 종료 되지 않았으면 7) System event 를 읽어서 관련 event 전달8) Event 가 있을때까지 sleep9) Display 를 종료하고 프로그램을 종료한다 .

Page 7: Swt J Face 1/3

Hello World 예제 ?

작업환경 ?1. Eclipse 4.2 SR1 (SWT 3. 1)2. Java Project 생성

1. classpath 설정 (org.eclipse.swt.win32.win32.x86_3.100.1.v4234e.jar)

3. SWT DESIGNER

(http://www.instantiations.com/windowbuilder/swtdesigner/in-dex.html)

Page 8: Swt J Face 1/3

Window Builder

Java GUI designer

https://developers.google.com/java-dev-tools/wbpro/

Page 9: Swt J Face 1/3

SWT 주요 Package 소개Package 명 기능

org.eclipse.swt 상수와 예외값들이 정의SWT, SWTException, SWTError

org.eclipse.swt.widgets Wedget, Component 및 관련 Interface

org.eclipse.swt.events 이벤트 , 리스너 , 이벤트 타입정의org.eclipse.swt.dnd Drag and Drop 정의org.eclipse.swt.layout Layout 정의org.eclipse.swt.graph-ics

그래픽관련 정의

org.e-clipse.swt.browser

org.eclipse.swt.internal

org.eclipse.swt.opengl** Internal package 는 외부에서 클래스를 볼 수 (?) 없습니다 .

Page 10: Swt J Face 1/3

Widget 소개

Page 11: Swt J Face 1/3

Widget 소개

Page 12: Swt J Face 1/3

Widget 소개

Page 13: Swt J Face 1/3

Widget 소개

Page 14: Swt J Face 1/3

Widget 소개

Page 15: Swt J Face 1/3

Text Widget

Page 16: Swt J Face 1/3

Button Widget

Page 17: Swt J Face 1/3

Label Widget

Page 18: Swt J Face 1/3

Layout

( 만든 콘트롤을 어디다 놓을것인지 , 어떤 모양으로 ?)

Page 19: Swt J Face 1/3

Layout 소개

영역을 나누는 방식 FillLayout, RowLayout, Grid-Layout

콘트롤을 붙이는 방식 FormLayout

한번에 하나의 콘트롤 보여지는 방식

StackLayout

Page 20: Swt J Face 1/3

Layout 소개

FillLayout setLayout(new FillLayout(SWT.VERTICAL));

Label lblNewLabel_2 = new Label(this, SWT.BORDER);lblNewLabel_2.setTouchEnabled(true);lblNewLabel_2.setText("New Label");

Label lblNewLabel_1 = new Label(this, SWT.BORDER);lblNewLabel_1.setText("New Label");

Label lblNewLabel = new Label(this, SWT.BORDER);lblNewLabel.setText("New Label");

setLayout(new FillLayout(SWT.HORIZONTAL));

Page 21: Swt J Face 1/3

Layout 소개

RowLayout

shell.setLayout(new RowLayout());

- 주요 Property wrap : 기본값은 true 이며 , 한줄로 유지 하고 싶을 경우에 false pack : 기본값은 true 이며 , 기본 contorl 이 모두 justfy : 기본 값은 false 이며 , 부모 콘트롤 전반적으로 균등하게 배치

- RowData(Width, Height) 특정 Widget 의 width, height 를 정의 해 줄수 있습니다 .

Page 22: Swt J Face 1/3

Layout 소개

GridLayoutfinal Shell shell = new Shell();final GridLayout gridLayout = new GridLayout();gridLayout.numColumns = 3;shell.setLayout(gridLayout);

- GridData특정 Widget 의 정렬방식 및 영역 채우기 등의 방법을 지정합니다 .

Page 23: Swt J Face 1/3

Layout 소개 FormLayout

shell.setLayout (new FormLayout(););Button button1 = new Button(shell, SWT.PUSH);Button button2 = new Button(shell, SWT.PUSH);Button button3 = new Button(shell, SWT.PUSH);button1.setText("B1"); button2.setText("B2");button3.setText("B3");

FormData data1 = new FormData();data1.left = new FormAttachment(0,5);data1.right = new FormAttachment(25,0);button1.setLayoutData(data1);

FormData data2 = new FormData();data2.left = new FormAttachment(button1,5);data2.right = new FormAttachment(90,-5);button2.setLayoutData(data2);

FormData data3 = new FormData();data3.top = new FormAttachment(button2,5);data3.bottom = new FormAttachment(100,-5);data3.right = new FormAttachment(100,-5);data3.left = new FormAttachment(25,5);button3.setLayoutData(data3);

Page 24: Swt J Face 1/3

Layout 소개

StackLayout?

Page 25: Swt J Face 1/3

Event 소개Object

EventObject

SWTEventObject

DragSourceEvent

DragTargetEvent

FocusEvent

HelpEvent

KeyEvent

ModifyEvent

MouseEvent

SelectionEvent

TextChangedEvent

운영체제

Event Queue

Dis-play

최상위 Shell

WidjetListener

Inter-face

Event 호출

메소드

메시지

이벤트

이벤트

호출

http://www.informit.com/articles/article.aspx?p=354574&seqNum=3

Page 26: Swt J Face 1/3

Event 소개 Adapter & Listener

Adapter ListenerControlAdapter ControlListenerFocusAdapter FocusListenerKeyAdapter KeyListenerMenuAdapter MenuListenerMouseAdapter MouseListenerSelectionAdapter SelectionListenerShellAdapter ShellLIstenerTreeAdapter TreeListener

button.addMouseListener(new MouseLis-tener() {…………………..

button.addMouseListener(new Mouse-Adapter() {…………………..

Page 27: Swt J Face 1/3

Event 소개 Adapter

Listener

Page 28: Swt J Face 1/3

TabFolder

생성final TabFolder tabFolder = new TabFolder(this, SWT.NONE);

Item 생성final TabItem firsttabTabItem = new TabItem(tabFolder,

SWT.NONE);

firsttabTabItem.setText("firstTab");

데이터입력final Composite firstTabComposite = new Composite(tabFolder, SWT.NONE);

final GridLayout gridLayout = new GridLayout();

gridLayout.numColumns = 2;

firstTabComposite.setLayout(gridLayout);

firsttabTabItem.setControl(firstTabComposite);

Page 29: Swt J Face 1/3

Table생성table = new Table(this, SWT.FULL_SELECTION | SWT.VIRTUAL);

컬럼 생성final TableColumn newColumnTableColumn = new TableColumn(table,

SWT.NONE);

newColumnTableColumn.setWidth(130);

newColumnTableColumn.setText(" 이름 ");

데이터 입력TableItem ti = new TableItem(table, SWT.NONE);

ti.setText(j, "Row " + i + ", Column " + j);

Page 30: Swt J Face 1/3

Tree생성tree = new Tree(this, SWT.BORDER);

Item 생성TreeItem child1 = new TreeItem(tree, SWT.NONE, 0);

데이터 입력child1.setText("Shell");

Page 31: Swt J Face 1/3

TreeTable생성Tree tree = new Tree(shell, SWT.BORDER);

컬럼 생성TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);

column1.setText("Column 1");

column1.setWidth(200);

데이터 입력for (int i = 0; i < 4; i++) {

TreeItem item = new TreeItem(tree, SWT.NONE);

item.setText(new String[] { "item " + i, "abc", "defghi" });

for (int j = 0; j < 4; j++) {

TreeItem subItem = new TreeItem(item, SWT.NONE);

subItem.setText(new String[] { "subitem " + j, "jklmnop",

"qrs" });

Page 32: Swt J Face 1/3

Dialog 소개

Object Dialog

ColorDialog DirectoryDialog FileDialog FontDialog MessageDialog PrintDialog

Page 33: Swt J Face 1/3

Dialog 소개

ColorDialog?

DirectoryDialog?

DirectoryDialog dlg = new DirectoryDialog(shell);dlg.setFilterPath(text.getText());

dlg.setText("SWT's DirectoryDialog");dlg.setMessage("Select a directory");

String dir = dlg.open();if (dir != null)  { …}

ColorDialog dlg = new ColorDialog(shell);dlg.setRGB(colorLabel.getBackground().getRGB());dlg.setText("Choose a Color");

RGB rgb = dlg.open();if (rgb != null) { …… }

Page 34: Swt J Face 1/3

Dialog 소개

FileDialog?

FontDialog?

FontDialog fd = new FontDialog(s, SWT.NONE);fd.setText("Select Font");fd.setRGB(new RGB(0, 0, 255));FontData defaultFont = new FontData("Courier", 10, SWT.BOLD);fd.setFontData(defaultFont);FontData newFont = fd.open();if (newFont != null) {          ….}

FileDialog fd = new FileDialog(s, SWT.OPEN);fd.setText("Open");fd.setFilterPath("C:/");String[] filterExt = { "*.txt", "*.doc", ".rtf", "*.*" };fd.setFilterExtensions(filterExt);String selected = fd.open();

Page 35: Swt J Face 1/3

Dialog 소개

MessageDialog?

PrintDialog? PrintDialog printDialog = new PrintDialog(s, SWT.NONE);printDialog.setText("Print");PrinterData printerData = printDialog.open();

MessageBox messageBox = new Mes-sageBox(shell, SWT.OK | SWT.CANCEL | SWT.ICON_WARNING); messageBox.setText("Hello, World");messageBox.setMessage("Hello, World"); messageBox.open();

Page 36: Swt J Face 1/3

Integration AWT and Swing

http://www.eclipse.org/articles/arti-cle.php?file=Article-Swing-SWT-Inte-gration/index.html

Page 37: Swt J Face 1/3

Integration MS OLD

http://www.vogella.com/tutorials/EclipseMicrosoftIntegration/arti-cle.html

Page 38: Swt J Face 1/3

Nebulra Project

Page 39: Swt J Face 1/3

Nebulra Project

Page 40: Swt J Face 1/3

Nebulra Project

Page 41: Swt J Face 1/3

Nebulra Project

Page 42: Swt J Face 1/3

실습

예제데이터(cvs)

이름 , 나이 , 전화번호 , 주소톰 ,47,010-1234-1235,미국헐리우드제리 ,48,010-1234-1234, 한국놀부 ,500,02-1234-1231, 한국흥부 ,498,02-2345-3456, 한국

초기화면이 로드되면 아래의 예제 데이터가 로드 된다 .

이름에 값을 입력하고 검색 버튼을 누르면 이름으로 테이블에 있는 데이터를 검색하고 데이터가 있다면 선택한다

아래 선택 버튼을 클릭하면 선택팝업이 뜨면서 상세정보출력한다

Page 43: Swt J Face 1/3

참고자료http://www.eclipse.org/swthttp://www.cs.umanitoba.ca/~eclipse/http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/eclipse/documents/SWThttp://www.ibm.com/developerworks/kr/library/os-swingswt/http://www.developer.com/java/other/article.php/3340621http://www.developer.com/design/article.php/10925_3330861_1http://www.eclipse.org/nebula/http://www.java2s.com