'SWT'에 해당되는 글 2건

  1. 2008/07/03 Eclipse3.4 [Ganymede] SWT Plugin 개발환경 구성 (2)
  2. 2008/07/03 Eclipse Plugin SWT 시작.
1. 기존에 사용하는 Eclipse에 SWT 개발 관련 Plugin을 설치해도 관계는 없지만 개인적으로 개발해야할 것에 따라 개발 IDE도 달리 가져가는 성격이라 Plugin개발 전용 Eclipse를 사용하는 걸 권장한다.

http://eclipse.org/downloads 로 가서 more package를 누르면 아래와 같은 화면이 나온다.
Eclipse for PRC/Plug-in Developers를 클릭해서 다운로드 받는다.

사용자 삽입 이미지

2. SWT관련 Plugin을 Update받는다.
 SWT개발을 위한 Eclipse를 받았다면 실행을 한 후 Help->Software Updates를 클릭하면 아래와 같은 패널이
 나온다. 2번째 탭을 선택한 후 Eclipse SDK Examples를 체크하고 Install한다.

사용자 삽입 이미지

3. SDK Examples를 설치 했다면 Eclipse를 restart하고 Plugin Project를 생성한다.
사용자 삽입 이미지

3-1 프로젝트명을 기입한 다음 Next
사용자 삽입 이미지

3-2 Plugin ID와 같은 proprty를 정의하고 Next
사용자 삽입 이미지

3-3  Plugin Template이 나오는데 시작이니 Hello World Template를 선택한다. 그리고 Finish
      - Template이 궁금하면 한번씩 만들어서 실행해 볼것을 권한다. :)
사용자 삽입 이미지

4. 위와 같이 진행 되었다면 플러그인 관련 소스들이 자동으로 생성 되었을 것이다. 자동으로 생성된 Plugin을
   실행해보자. 아래의 그림대로 Launch an Eclipse application을 클릭한다.

사용자 삽입 이미지

5.  새로운 Eclipse가 샐행된다. 결과를 확인하자. 새로뜬 Eclipse에는 새로운 매뉴가 생겼을 것이다 아래의 그림처럼 Sample Menu를 클릭하고 Action을 실행해보자.
 
사용자 삽입 이미지

6. Hello World가 보인다..
사용자 삽입 이미지

 Hello Eclipse World가 찍힌걸 볼 수 있다.

이제 시작은 했으니 반은 한 셈이다.
나머지 Template도 만들어서 실행해보고 차이점을 살펴본다면 Plugin 개발을 시작하는데 문안하게 출발 할 수 있을 것이라고 판단 된다.


부록

아까 설치한 SDK Example Plugin에 대해서
Example을 Eclipse의 SWT의 컴포넌트에 관해 쉽게 참고 할 수 있도록 한 view의 Plugin이다.
어떤 컴포넌트를 어떻게 활용해야 하는지 쉽게 간파 할 수 있으니 Plugin개발을 시작하는데 큰 도움이 될 것이다.
view에 SWT Controls를 추가해 보자.

1. 일단 window -> show view -> other 클릭

사용자 삽입 이미지

1-2
사용자 삽입 이미지

1-3 OK를 클릭하면 Eclipse의 view 팔레트 부분에 SWT Controls탭이 보일 것이다. 더블 클릭해서 보면 아래와
 같은 화면이 나온다.
사용자 삽입 이미지

SWT 컴포넌트들을 하나 하나 클릭하고 적용 해가며 속성을 알아보자..
이제 여기까지 하면 준비는 다 된듯 한다.

이젠 Java를 알고 커다란 삽만 준비한다면 개발을 당장이라도 할 수 있을 거라 생각한다. :)

이클립스 플러그인은 개발을 시작한 이유는 여러모로 개인적인 편의를 위해 개발하게 되었다..
이로써 SWT 개발 시작에 관해 적어 보았다.

-끝-

^^;; 시작 하는 분들에게 도움이 되었으면 좋겠습니다. SWT도 나름 재미있네요..
삽질도 많이 하고 있습니다. 그러면서 나름 개념도 머릿속에 넣고 있죠..
복잡함속에서 단순함을 찾으려고 노력중입니다~.
그럼 오늘도 좋은 하루 되시길 바라겠습니다.





크리에이티브 커먼즈 라이선스
Creative Commons License

'SWT' 카테고리의 다른 글

Eclipse3.4 [Ganymede] SWT Plugin 개발환경 구성  (2) 2008/07/03
Eclipse Plugin SWT 시작.  (0) 2008/07/03

Trackback Address :: http://lovedev.tistory.com/trackback/267

댓글을 달아 주세요

  1. 검쉰 2008/07/03 13:28 Address Modify/Delete Reply

    앗! 저 회사에 이클립스 플러그인 제작 관련 도서 신청했습니다. ㅎ
    저도 플러그인 하나 만들어보려고요 ㅎㅎ

    • ActionDev 2008/07/04 13:12 Address Modify/Delete

      전에 이야기 하셨던 플렉스빌더에 관련된 걸 만드시려나 보군요 ^^ 만들면 알려주세용~..^^ 제가 테스터가 되어 드리겠습니다 ^^

Eclipse Plugin SWT 시작.

SWT 2008/07/03 10:39 |

SWT Programming with Eclipse
By Koray Guclu

Go to page: 1  2  3  4  5  6  Next  

"The best way to predict the future is to invent it."—Alan Kay

1. Why SWT?

SWT is a cross platform GUI developed by IBM. Why has IBM created another GUI? Why have not they used existing Java GUI frameworks? To answer those questions, we need to go back to the early days of Java.

Sun has created a cross platform GUI framework AWT (Abstract Windowing Toolkit). The AWT framework uses native widgets but it was suffering from a LCD problem. The LCD problem causes loss of major platform features. In other words, if platform A has widgets 1–40 and platform B has widgets 20–25, the cross-platform AWT framework only offers the intersection of these two sets.

To solve this problem, Sun has created a new framework that uses emulated widgets instead of native widgets. This approach solved the LCD problem and provided a rich set of widgets but it has created other problems. For instance, Swing applications no longer look like native applications. Although they're the latest improvements in the JVM, Swing applications suffer performance problems that do not exist in their native counterparts. Moreover, Swing applications consume too much memory, which is not suitable for small devices such as PDAs and Mobile Phones.

IBM has decided that neither of the approaches fulfill their requirements. Consequently, IBM has created a new GUI library, called SWT,which solves the problems seen with the AWT and the Swing frameworks. The SWT framework accesses native widgets through JNI. If a widget is not available on the host platform, SWT emulates the unavailable widget.

2. Building Blocks of an SWT Application

Display, Shell, and Widgets are basic building blocks of an SWT application. Displays are responsible from managing event loops and controlling communication between the UI thread and other threads. Shell is the window in an application managed by the OS window manager. Every SWT application requires at least one Display and one or more Shell instances.

Figure 1. An SWT application from different perspectives.

Figure 1 shows an SWT application from different perspectives. The first diagram is the simplified inheritance diagram of the UI objects. The second diagram is the containment structure of the UI objects. The third diagram is the created UI.

If an application uses multiple threads, each thread uses its own instance of a Display object. You can get the current active instance of a Display object by using the static Display.getCurent() method.

A Shell represents a window in a particular operating system. A shell can be maximized, normal, or minimized. There are two types of shells. The first one is the top-level shell that is created as a child, main window of the Display. The second one is a dialog shell that depends on the other shells.

The type of a Shell depends on style bits passed to the Shell's constructor. The default value of a Shell is DialogShell. That is to say, if nothing is given to the parameter, it is by default a DialogShell. If a Display object is given to the parameter, it is a top-level shell.

Some widget properties must be set at creation time. Those widget properties are called style bits. Style bits are defined as constants in SWT class, for example, Button button = new Button( shell, <styleBits> ). It is possible to use more then one style bit by using the OR operation |. For instance, to use a bordered push button, you need to use SWT.PUSH | SWT.BORDER as style bit parameters.

3. Environment Set-Up

Developing an SWT application is different from developing a Swing application. To begin with an SWT application development, you need add SWT libraries to your classpath and set necessary environment variables accordingly.

The first library that you need is the swt.jar file that is under the ECLIPSE_HOME\eclipse\plugins\org.eclipse.swt.win32_2.1.0\ws\win32 directory. Depending on the version of the Eclipse that you are using, you might need to use a different directory. The swt.jar file must be added to your classpath to make this go to Project->Properies->JavaBuildPath->Libraries->Add Variable -> Eclipse Home ->Extend and select the swt.jar library under the director abovey and then click on OK.

Afterwards, you will be able to compile an SWT application but, because of a runtime exception shown below, it won't be able to run because the swt.jar library uses native libraries. You need to set the java.library.path environment variable to use native libraries in Java.

Console output
java.lang.UnsatisfiedLinkError: no swt-win32-2133 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
...
at org.eclipse.swt.widgets.Display.<init>(Display.java:287)
at Main.main(Main.java:25)
Exception in thread "main"

To set the java.library.path variable, go to Run-> Run...-> Java Applicaton-> New ->Arguments -> VM Arguments. Thereafter, if neccesary, modify the path below and paste it to the VM Arguments field.
-Djava.library.path=c:\eclipse\plugins\org.eclipse.swt.win32_2.1.0\os\win32\x86

Loading native libraries
If you need to load any native library that your application uses, you can use the Runtime.getPlatform.loadLibrary("libraryname") method.

Finishing these steps will enable you to run an SWT application within your eclipse environment.

4. Your First SWT Application

Creating a typical SWT application requires the following steps:

  • Create a Display
  • Create one or more Shells
  • Set a Layout manager of the Shell
  • Create widgets inside the Shells
  • Open the Shell window
  • Write an event dispatching loop
  • Dispose display

You can use the following code template to quickly run the code snippets in this article. You can copy and paste the code to the area, as shown in Source 1.

Source 1. SWT application template
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class SliderExample
{
  public static void main(String args[])
  {
 Display display = new Display();
 Shell shell = new Shell(display);
 shell.setLayout( new RowLayout());
    // ------------------------
    // Your code comes to here.
    // ------------------------
    shell.pack();
 shell.open();
 while( !shell.isDisposed())
    {
      if(!display.readAndDispatch()) 
      display.sleep();
    }
 display.dispose();
  }
}

This example displays an empty window. You can add your widgets to the template above. Every SWT application requires a Display and one or more Shells. The Shell is a composite object; it can contain other composite objects. If the layout of the shell is not set, added widgets to the Shell won't be visible. The Shell window must be opened to be displayed. The event handling loop reads and dispatches GUI events. If there is no event handling loop, the application window cannot be shown, even if the Shell window is opened by the open() method. Afterwards, you should dispose of the Display, when the Shell is discarded.

Importing required libraries
You can use the Source->Organize Imports menu or Ctrl+Shift+O to import the required libraries automatically.

Go to page: 1  2  3  4  5  6  Next  

Previous article: A First Look at Eclipse Plug-In Programming
Next article: Constructing SWT Layouts

크리에이티브 커먼즈 라이선스
Creative Commons License

'SWT' 카테고리의 다른 글

Eclipse3.4 [Ganymede] SWT Plugin 개발환경 구성  (2) 2008/07/03
Eclipse Plugin SWT 시작.  (0) 2008/07/03

Trackback Address :: http://lovedev.tistory.com/trackback/266

댓글을 달아 주세요