<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 28, comments - 27, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    首先是一個效果圖:

    login.JPG

    為了不違反保密協(xié)議,偶在這里把logo和相關的東西都涂掉了,希望不會讓人覺得難看....

    ok,下面就開始講述偶的coding過程:

    首先捏,Dialog是分為三部分的,Window Title Bar,Content Area和Button Bar

    這里的Window Title Bar素很難改動滴,偶也米改....而接下來的ContentArea和ButtonBar因為素分成兩截滴,所以就要把一張背景圖片拆成兩截,分別設置成ContentArea和ButtonBar的背景圖片鳥~~~
    ????protected?Control?createDialogArea(Composite?parent)?{
    ??????? Composite?composite?=?(Composite)?super.createDialogArea(parent);
    ????????composite.setBackgroundImage(backgroundImage);
    ??????? .......
    ??? }

    ??? protected?Control?createButtonBar(Composite?parent)?{
    ??????? Control?composite?
    =?super.createButtonBar(parent);
    ????????composite.setBackgroundImage(backgroundBtmImage);
    ??????? .......
    ???????
    return?composite;
    ????}

    當然,僅僅做到這些還是遠遠不夠滴,不信,你看~~~

    login2.JPG

    看到效果了咩....接下來偶們要做滴就是解決掉背景的問題,因為這個對話框里面沒有Table、Tree之類的控件,于是在createDialogArea()方法中加入一行:

    composite.setBackgroundMode(SWT.INHERIT_DEFAULT);

    我們再來看看改變后的效果:

    login3.JPG

    如上圖所示,介個ContentArea的背景問題已經(jīng)解決鳥,下面就素重中之重滴ButtonArea鳥~~~讓我們打開Dialog的源代碼,看一下createButtonBar()的部分,就可以發(fā)現(xiàn)里面有兩行:

    ????????GridData?data?=?new?GridData(GridData.HORIZONTAL_ALIGN_END
    ????????????????
    |?GridData.VERTICAL_ALIGN_CENTER);
    ????????composite.setLayoutData(data);

    介樣子怎么能行捏,偶們需要讓介個Composite填滿整個DialogArea,這樣子才可以顯示出整個背景圖片,所以偶們就要在重寫后的方法中加入下面一行代碼:

    composite.setLayoutData(new?GridData(SWT.FILL,?SWT.TOP,?false,?false));

    現(xiàn)在讓偶們再來看看運行后的結果:

    login4.JPG

    為什么會素介個樣子捏?即使素把layout改成SWT.RIGHT,也不會改變介個結果...偶快要郁悶滴抓狂鳥.....

    經(jīng)過漫長滴測試,偶終于發(fā)現(xiàn)鳥,如果控件滴layoutData不grabExcessSpace的話,那么現(xiàn)在滴DialogArea的Composite實際大小就素兩個Button加起來滴大小,所以無論如何也素不會居右對齊滴....介可怎么辦捏.....如果去重寫createButton方法滴話,那介個dialog滴代碼可就太丑陋鳥....

    在一個偶然滴機會下,偶終于發(fā)現(xiàn)鳥SWT.RIGHT_TO_LEFT !!!偶依稀見到鳥燦爛滴曙光!8過Composite的style素在創(chuàng)建時指定的,似乎米辦法在后面覆蓋,所以偶們只好整個滴把createButtonBar重寫掉鳥~~~

    ????protected?Control?createButtonBar(Composite?parent)?{
    ????????Composite?composite?
    =?new?Composite(parent,?SWT.RIGHT_TO_LEFT
    ????????????????
    |?SWT.NONE);
    ????????
    //?create?a?layout?with?spacing?and?margins?appropriate?for?the?font
    ????????
    //?size.
    ????????GridLayout?layout?=?new?GridLayout();
    ????????layout.makeColumnsEqualWidth?
    =?true;
    ????????layout.marginWidth?
    =?convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    ????????layout.marginHeight?
    =?convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    ????????layout.horizontalSpacing?
    =?convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    ????????layout.verticalSpacing?
    =?convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    ????????layout.marginLeft?
    =?10;
    ????????composite.setLayout(layout);
    ????????GridData?data?
    =?new?GridData(SWT.FILL,?SWT.TOP,?false,?false);
    ????????composite.setLayoutData(data);
    ????????composite.setFont(parent.getFont());

    ????????
    //?Add?the?buttons?to?the?button?bar.
    ????????createButtonsForButtonBar(composite);
    ??????? composite.setBackgroundImage(backgroundBtmImage);
    ????????
    return?composite;
    ????}

    在上面的代碼中,偶除了對偶所提到的地方進行了修改以外,還加上鳥一行: layout.marginLeft?=?10;

    介個素因為如果右邊距過小滴話,背景圖片就會被覆蓋掉一些,而因為偶們用到鳥
    SWT.RIGHT_TO_LEFT,所以應當設置marginLeft滴值 :-)

    還有一點素8能忘記滴,就素要重寫一下setButtonLayoutData(Button button)方法,因為偶們要把Button改成居右對齊:

    ????protected?void?setButtonLayoutData(Button?button)?{
    ????????GridData?data?
    =?new?GridData(SWT.RIGHT,?SWT.CENTER,?false,?false);
    ????????
    int?widthHint?=?convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    ????????Point?minSize?
    =?button.computeSize(SWT.DEFAULT,?SWT.DEFAULT,?true);
    ????????data.widthHint?
    =?Math.max(widthHint,?minSize.x);
    ????????button.setLayoutData(data);
    ????}

    然后再在createButtonsForButtonBar()方法中,把創(chuàng)建按鈕的順序改變一下,偶們就可以看到最開始滴那張美麗滴對話框鳥~~~雖然被偶涂改滴有些不美麗鳥~~~

    現(xiàn)在還有個小小滴問題就素按鈕距離底端滴黑框太近鳥~~介個素因為,介個Composite只有一行,所以要改變按鈕距離底端滴距離,那么DialogArea滴大小就要跟著改變,而現(xiàn)在偶們滴DialogArea所需要滴背景圖片還米改好,于是只有這樣鳥~~~大家應該知道在哪里設置底邊的邊距吧?就素createButtonBar方法中滴那個layout.marginHeight =xxx :)

    最后別忘了,整個對話框的高度,應該是Window Title Bar,Content Area和Button Bar三部分滴和。

    偶已經(jīng)說完鳥,如果覺得偶滴介篇文章對你有些幫助的朋友,請去支持一下偶們美麗可愛滴靚穎同學滴新專輯The One吧:)多謝!

    posted @ 2006-10-16 18:11 小小涼粉 閱讀(4198) | 評論 (12)編輯 收藏

    IWorkbenchPreferenceConstants中有很多常量,用來配置preference settings,諸如:

    OPEN_NEW_PERSPECTIVE——打開新視圖的方式
    DOCK_PERSPECTIVE_BAR——鎖定
    PerspectiveBar的位置
    INITIAL_FAST_VIEW_BAR_LOCATION——表示fast view bar在一個fresh workspace中鎖定的位置,This preference is meaningless after a workspace has been setup, since the fast view bar state is then persisted in the workbench
    SHOW_TRADITIONAL_STYLE_TABS——表示是否在editor和view上顯示傳統(tǒng)的tab style
    SHOW_PROGRESS_ON_STARTUP——是否在啟動時顯示progress
    SHOW_TEXT_ON_PERSPECTIVE_BAR——是否在PerspectiveBar上顯示文字

    等等......

    更改的時候
    在RCP中的plugin.xml里,使用preferenceCustomization屬性,例如:
    CODE:

    <extension
    id="someproduct"
    point="org.eclipse.core.runtime.products">
    <product
    ? application="com.example.someproduct.application"
    ? name="Some Product">
    ? <property
    ??? name="preferenceCustomization"
    ??? value="plugin_customization.ini"/>

    然后在ini文件中進行對應的設置

    或者,
    PlatformUI.getPreferenceStore().setDefault(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,false);

    posted @ 2006-10-08 10:04 小小涼粉 閱讀(1245) | 評論 (1)編輯 收藏

    先說一下AOSD的起源吧

    傳統(tǒng)的軟件工程有一個不變的主題:對關注點的分解和局部化。將系統(tǒng)分解成為主要的功能模塊,識別出關注點的其他問題,確保所有關注點的問題都能在代碼的適當位置得到解決。但是關注點的分散和混雜又給代碼編寫和后期維護帶來了很大的難度。
    因此,必須有一種方法可以把關注點集中在一起,讓系統(tǒng)開發(fā)者可以使用關注點自身的模塊來描述每個關注點的行為。
    AOSD,用以尋找軟件系統(tǒng)中新的模塊化特性,允許對系統(tǒng)中多個關注點進行獨立描述,同時又能自動統(tǒng)一到系統(tǒng)中。

    然后是一些常用的術語(from AOSD wiki):

    concern(關注點):A concern is an area of interest or focus in a system. Concerns are the primary criteria for decomposing software into smaller, more manageable and comprehensible parts that have meaning to a software engineer.

    crosscutting(橫切):Note that crosscutting is a relationship between representations of concerns. Note also that it is a symmetric relationship. Therefore, if:

    1. A is a representation of one a concern,
    2. B is a representation of another concern, and
    3. A crosscuts B,

    then B also crosscuts A.

    This means that the term "crosscutting concerns" is often misused in two ways: To talk about a single concern, and to talk about concerns rather than representations of concerns. Consider "synchronization is a crosscutting concern": we don't know that synchronization is crosscutting unless we know what it crosscuts. And there may be representations of the concerns involved that are not crosscutting.

    aspect(方面):Aspects are one kind of concern in software development.

    joint point(聯(lián)接點):Join points are those elements of the programming language semantics which the aspects coordinate with. Nowadays, there are various join point models around and still new under development. They heavily depend on the underlying programming language and AO language.

    In a number of presently available AOP languages, a join point is a region in the dynamic control flow of an application. Thus a join point can for instance represent

    * a call to a method,
    * execution of a method,
    * the event of setting a field,
    * the event of handling an exception ...

    Join points can be picked up by an AOP program by using pointcuts to match on them. Depending on the pointcut language the AOP language provides, it may be possible to pick up more or less of those join points. Since join points are dynamic, it may be possible to expose runtime information such as the caller or callee of a method from a join point to a matching pointcut.

    advice:In a number of AOP languages, advice consists of a pointcut and a body. The body executes at join points the pointcut matches. This pointcut may expose runtime information to the advice body.

    pointcut:

    (from Without EJB):A set of join points,defined to specify when an advice should fire.Pointcuts are often described using either regular expressions or another wildcard syntax.

    (from Wiki)In a number of AOP languages, a pointcut is a predicate over dynamic join points, meaning that given a certain dynamic join point, a pointcut can either match this join point or not (at runtime). Another view of pointcuts is often, that they represent sets of join points. A pointcut may expose runtime information to a piece of advice.

    Weaving:The process of coordinating aspects and non-aspects. Weaving can be done explicitly or implicitly, and can be done at a variety of times ranging from by-hand weaving when code is written, through compile-time, post-compile time and load time, up to runtime.

    Without EJB中有個例子很好的解釋了一下上面的術語:

    public class MyBusinessObject implements BusinessObject{
    public void businessMethod1() throws UnauthorizedException{
    doSecurityCheck();
    }
    public void businessMethod2() throws UnauthorizedException{
    doSecurityCheck();
    }
    public void requiresNoSecurityCheck() {
    }
    public void doSecurityCheck() throws UnauthorizedException{
    }
    }

    這里,安全檢查就是一個aspect,需要進行安全檢查的這幾個方法就是join point。而由于不是所有的方法都需要進行安全檢查,所以就需要用pointcut來進行匹配。

    下面使用了一個interceptor來將關注點模塊化:

    import org.aopalliance.intercept.MethodInterceptor;
    import org.aopalliance.intercept.MethodInvocation;

    public class SecurityInterceptor implements MethodInterceptor{
    public Object invoke(MethodInvocation invocation)throws Throwable{
    doSecurityCheck();
    return invocation.proceed();
    }
    public void doSecurityCheck{}
    }

    這里的interceptor就是advice

    posted @ 2006-09-27 23:51 小小涼粉 閱讀(266) | 評論 (0)編輯 收藏

    需要以下的對象:
    LoginDialog,用于展示狀態(tài),
    LoginListener,用于監(jiān)聽登錄狀態(tài),并根據(jù)不同的情況改變LoginDialog的顯示
    LoginAction,用于執(zhí)行登錄的業(yè)務邏輯,并且根據(jù)不同的結果來fire不同的動作。

    狀態(tài)一共有以下幾種:
    1。登錄中
    2。登錄成功
    3。登錄失敗
    ? 3.1 連接失敗
    ? 3.2 用戶名密碼錯誤
    ? 3.3 .....
    4。用戶取消登錄

    下面是代碼片段:

    Application;

    public?class?Application?implements?IPlatformRunnable?{
    ?
    ???
    ????
    /*
    ?????*?(non-Javadoc)
    ?????*?
    ?????*?@see?org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
    ?????
    */
    ????
    public?Object?run(Object?args)?throws?Exception?{

    ????????
    try?{

    ????????????TestLoginDialog?dialog?=?new?TestLoginDialog(Display.getCurrent()
    ????????????????????.getActiveShell());
    ????????????LoginListener?loginListener?
    =?new?LoginListenerImpl(dialog);
    ????????????LoginAction?action?
    =?new?LoginAction("login");
    ????????????action.addLoginListener(loginListener);
    ????????????dialog.setLoginAction(action);

    ????????????
    if?(dialog.open()?!=?Window.OK)?{
    ????????????????
    return?IPlatformRunnable.EXIT_OK;
    ????????????}
    ????????????
    int?returnCode?=?PlatformUI.createAndRunWorkbench(display,
    ????????????????????
    new?ApplicationWorkbenchAdvisor());

    ????????????
    if?(returnCode?==?PlatformUI.RETURN_RESTART)?{
    ????????????????
    return?IPlatformRunnable.EXIT_RESTART;
    ????????????}
    ????????????
    return?IPlatformRunnable.EXIT_OK;
    ????????}?
    finally?{
    ????????????display.dispose();
    ????????}
    ????}
    }


    LoginListener:

    public?interface?LoginListener?extends?EventListener{
    ????
    public?void?loginError(String?message);

    ????
    public?void?loginComplete();

    ????
    public?void?loginCanceled();
    ????
    ????
    public?void?loginStarted();
    ????
    }


    LoginAction:這里要用到Job,因為登錄的邏輯處理必須要在異步線程中來做,否則UI就會停住的。

    public?class?LoginAction?extends?Job?{
    ????
    private?LoginListener?loginListener;
    ????
    private?Session?session?=?Session.getInstance();

    ????
    public?LoginAction(String?name)?{
    ????????
    super(name);
    ????}

    ????
    public?void?addLoginListener(LoginListener?listener)?{
    ????????
    this.loginListener?=?listener;
    ????}

    ????
    public?void?fireLoginComplete()?{
    ????????loginListener.loginComplete();
    ????}

    ????
    public?void?fireLoginStarted()?{
    ????????loginListener.loginStarted();
    ????}

    ????
    public?void?fireLoginError(String?message)?{
    ????????loginListener.loginError(message);
    ????}

    ????
    public?void?fireLoginCanceled()?{
    ??? ??? //write cancel login logic here
    ????????loginListener.loginCanceled();
    ????}

    ????@Override
    ????
    protected?IStatus?run(IProgressMonitor?monitor)?{
    ????????login();
    ????????
    return?Status.OK_STATUS;
    ????}

    ????
    public?boolean?login()?{
    ????????fireLoginStarted();

    ????????if?(//網(wǎng)絡連接失敗)?{
    ???????????
    fireLoginError(Messages.getString("Session.connectionFailed"));
    ????????}?
    else?{
    ????????????
    if?(//登錄失敗)?{
    ???????????
    fireLoginError(Messages.getString("Session.loginFailed"));
    ????????????}?
    else?{
    ????????????????session.setAuthenticated(
    true);
    ????????????????fireLoginComplete();
    ??? ??? ??? ??? //處理登錄動作
    ????????????}
    ????????}
    ????????
    return?session.isAuthenticated();
    ????}

    }


    LoginDialog:

    這里用到了StackLayout,因為在登錄的過程中,需要在顯示用戶名/密碼的位置上,顯示gif動畫,所以在createDialogArea的時候,要創(chuàng)建一個主Composite,然后將其layout設置為StackLayout,然后創(chuàng)建兩個Composite,將其parent都設置為主Composite,新創(chuàng)建的兩個我將其命名為loginInfoComposite和loginAnimaComposite,顧名思義,一個用來顯示登錄信息,一個用來顯示登錄動畫。

    關于如何顯示gif,我在這里就不多說了,因為SWT Snippet和Eclipse的SWT Example里面都有對應的例子,我在這里推薦大家去參考一下SWT Example,因為那里面是用Canvas來繪圖的,這也是我們所需要的。

    在使用StackLayout的時候要注意,當我們使用stackLayout.topControl = xxx的時候,還要調(diào)用stackLayout.layout()方法,否則會不起作用。

    還有就是因為在登錄的過程中,按鈕欄應該是不可見的,但是Dialog的getButtonBar方法是protected的,所以就重寫了這個方法,聲明為public,返回super.getButtonBar(),雖然源碼的注釋中寫著這個方法不應該重寫,但是我想,這樣子應該沒問題吧。

    另外,在繪制gif的下方添加一個按鈕,并且addSelectionListener,當SelectionEvent發(fā)生的時候,就去觸發(fā)loginAction的fireCancel方法就可以了。

    細節(jié)就不描述了,下面是一些個人認為比較關鍵的代碼片段:

    ????/*
    ?????*?to?create?login?button?
    ?????
    */
    ????
    public?static?int?LOGIN_ID?=?9527;


    ????protected?void?createButtonsForButtonBar(Composite?parent)?{
    ????????createButton(parent,?LOGIN_ID,?Messages
    ????????????????.getString(
    "LoginDialog.loginbutton"),?true);?]
    ????????createButton(parent,?IDialogConstants.CANCEL_ID,?Messages
    ????????????????.getString(
    "LoginDialog.cancelbutton"),?false);
    ????}


    ????@Override
    ????
    protected?void?buttonPressed(int?buttonId)?{
    ????????
    if?(buttonId?==?LOGIN_ID)?{
    ????????????loginPressed();
    ????????}
    ????????
    super.buttonPressed(buttonId);
    ????}


    ??? protected?void?loginPressed()?{
    ??? ??? //...
    ????????loginAction.schedule();
    ????}

    然后是LoginListener的實現(xiàn)類:

    public?class?LoginListenerImpl?implements?LoginListener?{
    ????
    private?Display?display;
    ????
    //login?dialog
    ????private?TestLoginDialog?dialog;
    ????
    //image?to?show?on?login?failed
    ????private?Image?errorMessageImage?=?AbstractUIPlugin
    ????????????.imageDescriptorFromPlugin(Application.PLUGIN_ID,
    ????????????????????IImageKeys.crodoTitleImage).createImage();
    ????
    //error?message?area?background
    ????private?Color?errorMessageBackground?=?new?Color(null,?255,?255,?0);

    ????
    public?LoginListenerImpl(TestLoginDialog?dialog)?{
    ????????
    this.dialog?=?dialog;
    ????????display?
    =?Display.getCurrent();
    ????}

    ??? //因為這里需要在非UI線程中更新UI,所以要用display.syncExec()方法。
    ????public?void?loginCanceled()?{
    ????????display.syncExec(
    new?Runnable()?{
    ????????????
    public?void?run()?{
    ????????????????dialog.getStackLayout().topControl?
    =?dialog
    ????????????????????????.getLoginInfoComposite();
    ????????????????dialog.getStackLayoutComposite().layout();
    ????????????????dialog.animate();
    ????????????????dialog.getButtonBar().setVisible(
    true);
    ????????????}
    ????????});
    ????}

    ????
    public?void?loginComplete()?{
    ????????display.syncExec(
    new?Runnable()?{
    ????????????@SuppressWarnings(
    "deprecation")
    ????????????
    public?void?run()?{
    ??? ??? ??? ??? //我知道Thread.stop()方法已經(jīng)被廢棄,但是暫時沒想到什么方法來中止
    ??? ??? ??? ??? //就暫時這樣子用了,還請大家指教!
    ????????????????dialog.getAnimateThread().stop();
    ????????????????dialog.okPressed();
    ????????????}
    ????????});
    ????}

    ????
    public?void?loginError(final?String?message)?{
    ????????display.syncExec(
    new?Runnable()?{
    ????????????
    public?void?run()?{
    ????????????????dialog.getErrorMessageLabel().setText(message);
    ????????????????dialog.getErrorMessageLabel().setImage(errorMessageImage);
    ????????????????dialog.getErrorMessageLabel().setBackground(
    ????????????????????????errorMessageBackground);
    ????????????????dialog.getStackLayout().topControl?
    =?dialog
    ????????????????????????.getLoginInfoComposite();
    ????????????????dialog.getStackLayoutComposite().layout();
    ????????????????dialog.animate();
    ????????????????dialog.getButtonBar().setVisible(
    true);
    ????????????}
    ????????});
    ????}

    ????
    public?void?loginStarted()?{
    ????????display.syncExec(
    new?Runnable()?{
    ????????????
    public?void?run()?{
    ????????????????dialog.getStackLayout().topControl?
    =?dialog
    ????????????????????????.getLoginAnimaComposite();
    ????????????????dialog.getStackLayoutComposite().layout();
    ????????????????dialog.animate();
    ????????????????dialog.getButtonBar().setVisible(
    false);
    ????????????}
    ????????});
    ????}

    posted @ 2006-09-25 19:02 小小涼粉 閱讀(2129) | 評論 (1)編輯 收藏

    如果使用了Eclipse3.2提供的自繪制功能來在table或者tree里面繪制圖像或文字的時候,就必須在LabelProvider中,將對應column的返回值置空,同時需要記住的是,即使所有的column都使用自繪制功能的時候,也必須要給viewer提供一個LabelProvider,否則每一行的第一列上都會顯示出對應Object的toString()方法的結果。

    posted @ 2006-09-21 14:44 小小涼粉 閱讀(1307) | 評論 (2)編輯 收藏

    SMTP的連接和收發(fā)過程

    a.建立TCP連接。
    b.客戶端發(fā)送HELO命令以標識發(fā)件人自己的身份,然后客戶端發(fā)送MAIL命令服務器端正希望以OK作為響應,表明準備接收。
    c.客戶端發(fā)送RCPT命令,以標識該電子郵件的計劃接收人,可以有多個RCPT行
    d.協(xié)商結束,發(fā)送郵件,用命令DATA發(fā)送
    e.以.表示結束輸入內(nèi)容一起發(fā)送出去
    f.結束此次發(fā)送,用QUIT命令退出。

    SMTP的基本命令集

    HELO   向服務器標識用戶身份
    MAIL   初始化郵件傳輸mail from:
    RCPT   標識單個的郵件接收人;常在MAIL命令后面可有多個rcpt to:
    DATA   在單個或多個RCPT命令后,表示所有的郵件接收人已標識,初始化數(shù)據(jù)傳輸,以.結束。
    NOOP   無操作,服務器應響應OK
    RSET   重置會話,當前傳輸被取消
    QUIT   結束會話


    POP3簡介

    在POP3協(xié)議中有三種狀態(tài),認可狀態(tài),處理狀態(tài),和更新狀態(tài)。當客戶機與服務器建立聯(lián)系時,一旦客戶機提供了自己身份并成功確認,即由認可狀態(tài)轉入處理狀態(tài),在完成相應的操作后客戶機發(fā)出quit命令,則進入更新狀態(tài),更新之后最后重返認可狀態(tài)。

    POP3基本命令集
    USER username
    PASS password   
    STAT  請求服務器發(fā)回關于郵箱的統(tǒng)計資料,如郵件總數(shù)和總字節(jié)數(shù)
    LIST  返回郵件數(shù)量和每個郵件的大小
    RETR [Msg#] 返回由參數(shù)標識的郵件的全部文本
    DELE [Msg#] 服務器將由參數(shù)標識的郵件標記為刪除,由quit命令執(zhí)行
    RSET 服務器將重置所有標記為刪除的郵件,用于撤消DELE命令
    NOOP 服務器返回一個肯定的響應
    QUIT 更新


    class POP3Demo {
    ?? private static String POP3Server = "pop.126.com";
    ??? private static String USERNAME = "username";//實際應用中改成真實的用戶名
    ??? private static String PASSWORD = "password";//實際應用中改成真實的密碼
    ??? public static void main(String[] args) {
    ??????? int POP3Port = 110;
    ??????? Socket client = null;
    ??????? try {
    ??????????? // 向POP3服務程序建立一個套接字連接。
    ??????????? client = new Socket(POP3Demo.POP3Server, POP3Port);
    ??????????? // 創(chuàng)建一個BufferedReader對象,以便從套接字讀取輸出。
    ??????????? InputStream is = client.getInputStream();
    ??????????? BufferedReader sockin = new BufferedReader(new InputStreamReader(is));
    ??????????? // 創(chuàng)建一個PrintWriter對象,以便向套接字寫入內(nèi)容。
    ??????????? OutputStream os = client.getOutputStream();
    ??????????? PrintWriter sockout = new PrintWriter(os, true);
    ??????????? // 顯示同SMTP服務程序的握手過程。
    ??????????? System.out.println("S:" + sockin.readLine());
    ??????????? sockout.println("user " + POP3Demo.USERNAME);
    ??????????? System.out.println("S:" + sockin.readLine());
    ??????????? sockout.println("pass " + POP3Demo.PASSWORD);
    ??????????? System.out.println("S:" + sockin.readLine());
    ??????????? sockout.println("stat");
    ??????????? String temp[] = sockin.readLine().split(" ");
    ??????????? int count = Integer.parseInt(temp[1]);//得到信箱中共有多少封郵件
    ??????????? for (int i = 1; i < count + 1; i++) {//依次打印出郵件的內(nèi)容
    ??????????????? sockout.println("retr " + i);
    ??????????????? System.out.println("以下為第" + i + "封郵件的內(nèi)容");
    ??????????????? while (true) {
    ??????????????????? String reply = sockin.readLine();
    ??????????????????? System.out.println(reply);
    ??????????????????? if (reply.toLowerCase().equals(".")) {
    ??????????????????????? break;
    ??????????????????? }
    ??????????????? }
    ??????????? }

    ??????? } catch (IOException e) {
    ??????????? System.out.println(e.toString());
    ??????? } finally {
    ??????????? try {
    ??????????????? if (client != null) {
    ??????????????????? client.close();
    ??????????????? }
    ??????????? } catch (IOException e) {}
    ??????? }
    ??? }
    }

    ?class SMTPDemo {
    ??? //以下三項請在使用時改成真實的信箱地址
    ??? //并且注意,SMTPServer和receiver必須是同一個服務器
    ??? private static String sender = "sender";
    ??? private static String receiver = "receiver";
    ??? private static String SMTPServer = "smtpserver";
    ??? public static void main(String[] args) {
    ??????? int SMTPPort = 25;
    ??????? Socket client = null;
    ??????? try {
    ??????????? // 向SMTP服務程序建立一個套接字連接。
    ??????????? client = new Socket(SMTPDemo.SMTPServer, SMTPPort);
    ??????????? // 創(chuàng)建一個BufferedReader對象,以便從套接字讀取輸出。
    ??????????? InputStream is = client.getInputStream();
    ??????????? BufferedReader sockin = new BufferedReader(new InputStreamReader(is));
    ??????????? // 創(chuàng)建一個PrintWriter對象,以便向套接字寫入內(nèi)容。
    ??????????? OutputStream os = client.getOutputStream();
    ??????????? PrintWriter sockout = new PrintWriter(os, true);
    ??????????? // 顯示同SMTP服務程序的握手過程。
    ??????????? System.out.println("S:" + sockin.readLine());
    ??????????? sockout.println("helo");
    ??????????? System.out.println("S:" + sockin.readLine());
    ??????????? sockout.println("mail from: " + "<" + SMTPDemo.sender + ">");
    ??????????? System.out.println("S:" + sockin.readLine());
    ??????????? sockout.println("rcpt to: " + "<" + SMTPDemo.receiver + ">");
    ??????????? System.out.println("S:" + sockin.readLine());
    ??????????? sockout.println("data");
    ??????????? //發(fā)送郵件標題
    ??????????? sockout.println("subject: 你好");
    ??????????? //發(fā)送郵件內(nèi)容
    ??????????? sockout.println("ni hao");
    ??????????? sockout.println("wo shi li jian");
    ??????????? //此處的.為特殊標記,表示郵件結束
    ??????????? sockout.println(".");
    ??????????? sockout.println("rset");
    ??????????? sockout.println("quit");
    ??????? } catch (IOException e) {
    ??????????? System.out.println(e.toString());
    ??????? } finally {
    ??????????? try {
    ??????????????? if (client != null) {
    ??????????????????? client.close();
    ??????????????? }
    ??????????? } catch (IOException e) {}
    ??????? }
    ??? }
    }


    posted @ 2006-09-18 15:11 小小涼粉 閱讀(2644) | 評論 (5)編輯 收藏

    Design decisions:

    Most platforms require that widgets be created within the context of a specific parent, so SWT requires that a parent widget be supplied as one of its constructor arguments. Another requirement of many platforms is that certain style settings must be supplied at creation time (for example, buttons can be checkboxes, radio buttons, or simple buttons and text fields can be single- or multi-line).

    Style bits are represented by int constants defined in the SWT class. Styles are then OR'ed together and passed as another constructor argument to create the initial style of a widget.

    SWT works directly with the native underlying graphic resources, each SWT resource consumes a GUI resource, and timely release of that resource is essential not only for your SWT application's well-being, but also for the well-being of all other GUI programs currently running. Java's garbage collection carries no timeliness guarantees, and would make a poor manager of graphic resources for SWT. So, instead, you as programmer must assume the responsibility.

    Fortunately, a widget that is a child of another widget is automatically destroyed when its parent is destroyed. This means that if you properly dispose of a shell, you do not need to dispose of each of its children because they will be disposed of automatically.

    ----------------------------------------------------------------------------------------

    Top-level classes:

    Each SWT application needs a display and one or more shells (representing each window frame).

    Display: The Display object represents the connection between the application-level SWT classes and the underlying windowing system implementation.

    One of the most important tasks of this class is its event-handling mechanism. The Display class maintains a collection of registered event listeners, reads events from the lower-level operating-system event queue, and delivers these events to the appropriate implementations of registered listener logic.

    Shell: Every window has a shell representing the window frame with which the user interacts. The Shell object represents a window—either a top-level window or a dialog window. It contains the various controls that make up the application: buttons, text boxes, tables

    ----------------------------------------------------------------------------------------

    Control: The Control class is the abstract superclass of all the dialog and window component classes such as Button, Label, ProgressBar, Sash, Scrollable, and Slider

    Composite: Taking a bottom-up view of the world, every control has a parent that is an instance of the class Composite or one of its subclasses. The class Shell, which represents the top-level windows of your application, is a subclass of Composite.

    Stated another way, this time from the top down, a display contains a list of top-level shells, where each shell is the root of a tree composed of composites and controls. Composites can contain other composites, allowing the tree to have arbitrary depth. If the child of a shell is another shell, the child is commonly called a dialog shell. A dialog shell always stays in front of the parent shell.

    posted @ 2006-09-18 15:09 小小涼粉 閱讀(253) | 評論 (0)編輯 收藏

    ModalessDialog:

    public class ModalessDialog extends Dialog {
    ?public ModalessDialog(Shell arg0) {
    ??super(arg0);
    ??setShellStyle(SWT.SHELL_TRIM | SWT.MODELESS | SWT.RESIZE | SWT.MAX);
    ?}
    }


    程序中需要雙擊攝像頭,然后彈出的對話框中顯示攝像頭所捕捉的畫面,原來是這樣寫的:

    ??deviceTab.getViewer().addDoubleClickListener(
    ????new IDoubleClickListener() {
    ?????public void doubleClick(DoubleClickEvent event) {
    ??????StructuredSelection selection = (StructuredSelection) event
    ????????.getSelection();
    ??????DeviceDataDialog dialog = new DeviceDataDialog(event
    ????????.getViewer().getControl().getShell());
    ??????dialog.open();
    ?????}
    ????});

    但是這樣子出來的對話框,會始終保持在最前端顯示。后來改成

    DeviceDataDialog dialog = new DeviceDataDialog(null);

    就可以了
    也許是因為原先的程序中,對話框和主窗口使用同一個Shell所造成的吧

    posted @ 2006-09-18 15:09 小小涼粉 閱讀(989) | 評論 (0)編輯 收藏

    因為RCP的界面也是使用MVC模式的,于是想操作TableViewer、TreeViewer的時候,不應該直接對Viewer進行操作,而是應該操作viewer的input。修改以后,調(diào)用一下viewer.refresh()方法就可以了。

    今天碰到的問題是,在一個widget中,使用

    viewer.setInput(DisplayConst.publishingDevices.values());

    可以順利更新

    而在另外一個widget中,使用

    ??viewer.setInput(DisplayConst.locationTable.get(this.getUserName()));

    就不能正常更新了。

    測試了半天,又想了一下才明白,viewer.setInput以后,我們只能夠修改input的內(nèi)容,而不能修改input這個對象內(nèi)存地址的值。就和方法調(diào)用在java中只能傳值調(diào)用一樣了。

    posted @ 2006-09-18 15:08 小小涼粉 閱讀(719) | 評論 (0)編輯 收藏

    為了批量發(fā)布設備,需要在一個窗口中為設備命名,設定其類型等,要用到Combo,所以就用了CellEditor

    用CellEditor還是很方便的,有CheckboxCellEditor,ComboBoxCellEditor,LabelCellEditor,TextCellEditor等等。

    首先把TableColumn的名稱做成String數(shù)組,調(diào)用viewer.setColumnProperties()方法

    然后做一個CellEditor數(shù)組,數(shù)組中的每一個CellEditor都對應著每一個Column

    然后實現(xiàn)ICellModifier接口,做一個自己的CellModifier,并調(diào)用viewer.setCellModifier()方法

    接口中有三個方法:

    1.public boolean canModify(Object element, String property)
    用來判斷哪一個屬性可寫
    2.public Object getValue(Object element, String property)
    返回某個屬性的值
    3.public void modify(Object element, String property, Object value)
    為某個屬性賦值

    昨天碰到了很多異常,情況如下:

    1.ComboCellEditor 中對應的是Integer類型的值,如果用了String的話,就會有異常拋出。

    2.tableviewer的input中,對象的很多屬性沒有賦初始值,由此而導致了在CellModifier里面調(diào)用get或者set方法時,出現(xiàn)了空指針異常。

    3.update tableviewer。今天上午才找到table.addFocusListener方法,而且要在focusGained方法中進行更新。應該是由于編輯Cell的時候,focus從Table轉移到了Cell上,所以要用focusGained方法吧。

    posted @ 2006-09-18 15:08 小小涼粉 閱讀(1367) | 評論 (0)編輯 收藏

    僅列出標題
    共3頁: 上一頁 1 2 3 下一頁 
    主站蜘蛛池模板: 一级视频免费观看| 国产人成免费视频网站| 亚洲爆乳精品无码一区二区三区 | 在线综合亚洲欧洲综合网站| 国产极品美女高潮抽搐免费网站| 亚欧乱色国产精品免费视频| 久久亚洲国产精品成人AV秋霞| 国产极品粉嫩泬免费观看| 99爱在线观看免费完整版| 污网站免费在线观看| 亚洲色图.com| 亚洲国产综合人成综合网站| 18禁黄网站禁片免费观看不卡| 国产精品亚洲二区在线| 亚洲黄色片免费看| 亚洲真人日本在线| 最新仑乱免费视频| 久久精品视频免费看| 美女羞羞免费视频网站| 亚洲精品国产手机| 亚洲日韩在线观看免费视频| 曰批全过程免费视频在线观看| 在线视频网址免费播放| 亚洲精品GV天堂无码男同| 亚洲视频中文字幕| 亚洲午夜激情视频| 免费爱爱的视频太爽了| 1区2区3区产品乱码免费| 一级有奶水毛片免费看| 婷婷亚洲综合五月天小说在线| 亚洲日本香蕉视频观看视频| 亚洲无线码一区二区三区| 国产又大又黑又粗免费视频| 青娱分类视频精品免费2| 免费人成视频在线观看网站| jizz在线免费观看| 黄床大片30分钟免费看| 亚洲AV无码AV男人的天堂不卡| 亚洲卡一卡2卡三卡4麻豆| 久久亚洲精品国产精品| 亚洲AV午夜福利精品一区二区|